diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-01-17 12:25:02 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-01-17 12:49:02 +0100 |
commit | f1d3a4b36cd0b170333b274906de44e1b23461fb (patch) | |
tree | 8961ccf0b2a8ec7b30f4e34fd7c5566193e3bec3 /tools | |
parent | 4cfbe0019331c8fb2d381606806e6bea253ca14a (diff) | |
download | server-f1d3a4b36cd0b170333b274906de44e1b23461fb.tar.gz |
Fix tools.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/editgame.sh | 2 | ||||
-rw-r--r-- | tools/patchgame.js | 32 |
2 files changed, 23 insertions, 11 deletions
diff --git a/tools/editgame.sh b/tools/editgame.sh index 7f21fcb..2638f45 100644 --- a/tools/editgame.sh +++ b/tools/editgame.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ -n "$1" -a -n "$VISUAL" ] then - sqlite3 db "update games set state=edit(state) where game_id = $1" + sqlite3 db "update game_state set state=edit(state) where game_id = $1" else echo "usage: bash tools/editgame.sh GAME" echo "note: \$VISUAL must be set to your preferred editor" diff --git a/tools/patchgame.js b/tools/patchgame.js index 467a45f..1eeaf9c 100644 --- a/tools/patchgame.js +++ b/tools/patchgame.js @@ -13,20 +13,32 @@ let db = new sqlite3("./db"); let game_id = process.argv[2]; let title_id = db.prepare("select title_id from games where game_id=?").pluck().get(game_id); let rules = require("../public/" + title_id + "/rules.js"); -let log = db.prepare("select * from game_replay where game_id=?").all(game_id); +let log = db.prepare("select rowid,* from game_replay where game_id=?").all(game_id); let save = db.prepare("select state from game_state where game_id=?").pluck().get(game_id); fs.writeFileSync("backup-" + game_id + ".txt", save); let game = { state: null, active: null } -log.forEach(item => { - let args = JSON.parse(item.arguments); - if (item.action === 'setup') - game = rules.setup(args[0], args[1], args[2]); - else if (item.action === 'resign') - game = rules.resign(game, item.role); - else - game = rules.action(game, item.role, item.action, args); -}); +let i = 0; +try { + log.forEach(item => { + let args = JSON.parse(item.arguments); + if (item.action === 'setup') + game = rules.setup(args[0], args[1], args[2]); + else if (item.action === 'resign') + game = rules.resign(game, item.role); + else + game = rules.action(game, item.role, item.action, args); + ++i; + }); +} catch (err) { + console.log("FAILED %d/%d", i+1, log.length); + console.log(err); +} db.prepare("update game_state set active=?, state=? where game_id=?").run(game.active, JSON.stringify(game), game_id); + +if (i < log.length) { + console.log("BROKEN ENTRIES: %d", log.length-i); + console.log(`sqlite3 db "delete from game_replay where game_id=${game_id} and rowid>=${log[i].rowid}"`); +} |