summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-09-15 18:17:19 +0200
committerTor Andersson <tor@ccxvii.net>2023-09-15 18:59:25 +0200
commite94ef87d23f1ea8ffe74390e95f6dedad1fc515d (patch)
tree21114eba1df52a47fdf1959c8660b4cb7db999e1
parentb1b753e317daa10e03a6a3b210d185539fac176b (diff)
downloadserver-e94ef87d23f1ea8ffe74390e95f6dedad1fc515d.tar.gz
Improve sync error handling.
1) Show warning during one second then resume game. 2) Don't update cookie during simultaneous turns. When playing SoT live, discarding cards at the same time leads to many harmless in-flight action collision errors, which don't really matter. If we stop updating the cookie during simultaneous turns, we can avoid this.
-rw-r--r--public/common/play.js9
-rw-r--r--server.js17
2 files changed, 21 insertions, 5 deletions
diff --git a/public/common/play.js b/public/common/play.js
index cf4bcad..e34f42c 100644
--- a/public/common/play.js
+++ b/public/common/play.js
@@ -442,6 +442,15 @@ function connect_play() {
let arg = msg_data[1]
console.log("MESSAGE", cmd)
switch (cmd) {
+ case "warning":
+ document.getElementById("prompt").textContent = arg
+ document.querySelector("header").classList.add("disconnected")
+ setTimeout(() => {
+ document.querySelector("header").classList.remove("disconnected")
+ on_update_header()
+ }, 1000)
+ break
+
case "error":
document.getElementById("prompt").textContent = arg
if (view) {
diff --git a/server.js b/server.js
index d0b55cf..c3487e1 100644
--- a/server.js
+++ b/server.js
@@ -2211,19 +2211,26 @@ function on_action(socket, action, args, cookie) {
else
SLOG(socket, "ACTION", action)
- if (typeof cookie === "number") // TODO: for backwards compatibility only, remove later!
- if (game_cookies[socket.game_id] !== cookie)
- return send_message(socket, 'error', "Synchronization error!")
- game_cookies[socket.game_id] ++
+ if (game_cookies[socket.game_id] !== cookie) {
+ send_state(socket, get_game_state(socket.game_id))
+ send_message(socket, "warning", "Synchronization error!")
+ return
+ }
try {
let state = get_game_state(socket.game_id)
let old_active = state.active
+
+ // Don't update cookie during simultaneous turns, as it results
+ // in many in-flight collisions.
+ if (old_active !== "Both")
+ game_cookies[socket.game_id] ++
+
state = socket.rules.action(state, socket.role, action, args)
put_new_state(socket.game_id, state, old_active, socket.role, action, args)
} catch (err) {
console.log(err)
- return send_message(socket, 'error', err.toString())
+ return send_message(socket, "error", err.toString())
}
}