summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-11-24 12:31:12 +0100
committerTor Andersson <tor@ccxvii.net>2024-11-24 13:06:18 +0100
commit0e50f39f33079de81c5da473473383d6956ef575 (patch)
tree81fe9a7aa4926496ad268179dd6e04a5a6c97ee5 /server.js
parenta9481cf40c87ef830833177bd1a368aa9b249e74 (diff)
downloadserver-0e50f39f33079de81c5da473473383d6956ef575.tar.gz
Add "dont snap" callback to prevent snapshot creation.HEADmaster
Use it for Columbia simultaneous card selection states to prevent the "duplicate" snapshot when going from both player selecting to the remaining player only.
Diffstat (limited to 'server.js')
-rw-r--r--server.js20
1 files changed, 15 insertions, 5 deletions
diff --git a/server.js b/server.js
index f813261..20915df 100644
--- a/server.js
+++ b/server.js
@@ -3468,6 +3468,16 @@ function put_replay(game_id, role, action, args) {
return SQL_INSERT_REPLAY.get(game_id, game_id, role, action, args)
}
+function dont_snap(rules, state, old_active) {
+ if (state.active === old_active)
+ return true
+ if (state.state === "game_over")
+ return true
+ if (rules.dont_snap && rules.dont_snap(state))
+ return true
+ return false
+}
+
function put_snap(game_id, replay_id, state) {
let snap_id = SQL_INSERT_SNAP.get(game_id, game_id, replay_id, snap_from_state(state))
if (game_clients[game_id])
@@ -3494,12 +3504,12 @@ function put_game_state(game_id, state, old_active, current_role) {
}
}
-function put_new_state(game_id, state, old_active, role, action, args) {
+function put_new_state(title_id, game_id, state, old_active, role, action, args) {
SQL_BEGIN.run()
try {
let replay_id = put_replay(game_id, role, action, args)
- if (state.active !== old_active)
+ if (!dont_snap(RULES[title_id], state, old_active))
put_snap(game_id, replay_id, state)
put_game_state(game_id, state, old_active, role)
@@ -3544,7 +3554,7 @@ function on_action(socket, action, args, cookie) {
game_cookies[socket.game_id] ++
state = RULES[socket.title_id].action(state, socket.role, action, args)
- put_new_state(socket.game_id, state, old_active, socket.role, action, args)
+ put_new_state(socket.title_id, socket.game_id, state, old_active, socket.role, action, args)
} catch (err) {
console.log(err)
return send_message(socket, "error", err.toString())
@@ -3584,7 +3594,7 @@ function do_resign(game_id, role, how) {
state.log.push("")
state.log.push(state.victory)
- put_new_state(game_id, state, old_active, role, ".resign", null)
+ put_new_state(game.title_id, game_id, state, old_active, role, ".resign", null)
}
function on_restore(socket, state_text) {
@@ -3601,7 +3611,7 @@ function on_restore(socket, state_text) {
for (let other of game_clients[socket.game_id])
other.seen = 0
- put_new_state(socket.game_id, state, null, null, "$restore", state)
+ put_new_state(socket.title_id, socket.game_id, state, null, null, "$restore", state)
} catch (err) {
console.log(err)
return send_message(socket, "error", err.toString())