diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-03-14 15:30:49 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-03-14 15:31:04 +0100 |
commit | 16c60c721208e8cc971b2f84defb4ccc74e9ffe2 (patch) | |
tree | ecf00c945d7012a059964647f04fd72867679f31 /tools | |
parent | f9124f6e077d0bc01c0158f2554ac9605cdfc746 (diff) | |
download | server-16c60c721208e8cc971b2f84defb4ccc74e9ffe2.tar.gz |
Keep user assignment if possible when importing games.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/import-game.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tools/import-game.js b/tools/import-game.js index 8413b2f..87b93ab 100755 --- a/tools/import-game.js +++ b/tools/import-game.js @@ -39,16 +39,22 @@ game.setup.moves = game.snaps && game.snaps.length > 0 ? game.snaps.length - 1 : let db = new sqlite3("db") let insert_game = db.prepare("insert into games(status,owner_id,title_id,scenario,options,player_count,active,moves,notice) values (1,1,:title_id,:scenario,:options,:player_count,:active,:moves,:notice) returning game_id").pluck() -let insert_player = db.prepare("insert into players(game_id,role,user_id) values (?,?,1)") +let insert_player = db.prepare("insert into players(game_id,role,user_id) values (?,?,?)") let insert_state = db.prepare("insert into game_state(game_id,state) values (?,?)") +let select_user = db.prepare("select user_id from users where name=?").pluck() + db.exec("begin") game.setup.options = JSON.stringify(game.setup.options) +function find_user(name) { + return select_user.get(name) || 1 +} + let game_id = insert_game.get(game.setup) for (let p of game.players) - insert_player.run(game_id, p.role) + insert_player.run(game_id, p.role, find_user(p.name)) insert_state.run(game_id, JSON.stringify(game.state)) if (game.replay) { |