diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-02-14 23:20:44 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-02-15 00:19:57 +0100 |
commit | c235a8239177d38117f3313d17b904b66a806378 (patch) | |
tree | c023351b009a10638f4936738e8c13a5fe5f37e8 /server.js | |
parent | 09cae5d2f687c7df4972f58860fbc3fb9a032c1c (diff) | |
download | server-c235a8239177d38117f3313d17b904b66a806378.tar.gz |
Add import-game and export-game scripts.
To bulk transfer all game state, replay, and snapshots into a new game.
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -1206,8 +1206,10 @@ const SQL_FINISH_GAME = SQL(` game_id = ? `) -const SQL_REOPEN_GAME = SQL("update games set status=1,active=? where game_id=?") +const SQL_REWIND_GAME = SQL("update games set status=1,moves=?,active=?,mtime=datetime() where game_id=?") + const SQL_UPDATE_GAME_ACTIVE = SQL("update games set active=?,mtime=datetime(),moves=moves+1 where game_id=?") +const SQL_UPDATE_GAME_MOVES = SQL("update games set moves=? where game_id=?") const SQL_UPDATE_GAME_SCENARIO = SQL("update games set scenario=? where game_id=?") const SQL_SELECT_GAME_STATE = SQL("select state from game_state where game_id=?").pluck() @@ -2094,10 +2096,7 @@ app.get("/admin/rewind/:game_id/:snap_id", must_be_administrator, function (req, SQL_DELETE_GAME_REPLAY.run(game_id, snap.replay_id) SQL_INSERT_GAME_STATE.run(game_id, JSON.stringify(snap_state)) - SQL_REOPEN_GAME.run(snap_state.active, game_id) - - if (snap_state.active !== game_state.active) - SQL_UPDATE_GAME_ACTIVE.run(snap_state.active, game_id) + SQL_REWIND_GAME.run(snap_id - 1, snap_state.active, game_id) update_join_clients_game(game_id) if (game_clients[game_id]) |