diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-05-22 16:46:17 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-05-22 16:46:36 +0200 |
commit | dcd1a5c758a3ba97f2ecbcda41e793ca475df15a (patch) | |
tree | 74ce68eee3fffda8e8919f1deb79c33c9b0b8a1d | |
parent | d721c8755e5fd5c8398d4f965070f89dd549b258 (diff) | |
download | server-dcd1a5c758a3ba97f2ecbcda41e793ca475df15a.tar.gz |
Split out start_game function.
-rw-r--r-- | server.js | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -1362,13 +1362,7 @@ function assign_random_roles(game, players) { } } -app.get('/start/:game_id', must_be_logged_in, function (req, res) { - let game_id = req.params.game_id | 0; - let game = SQL_SELECT_GAME.get(game_id); - if (game.owner_id !== req.user.user_id) - return res.send("Not authorized to start that game ID."); - if (game.status !== 0) - return res.send("The game is already started."); +function start_game(game_id, game) { let players = SQL_SELECT_PLAYERS.all(game_id); if (!RULES[game.title_id].ready(game.scenario, game.options, players)) return res.send("Invalid scenario/options/player configuration!"); @@ -1386,6 +1380,16 @@ app.get('/start/:game_id', must_be_logged_in, function (req, res) { if (is_solo(players)) SQL_UPDATE_GAME_PRIVATE.run(game_id); update_join_clients_game(game_id); +} + +app.get('/start/:game_id', must_be_logged_in, function (req, res) { + let game_id = req.params.game_id | 0; + let game = SQL_SELECT_GAME.get(game_id); + if (game.owner_id !== req.user.user_id) + return res.send("Not authorized to start that game ID."); + if (game.status !== 0) + return res.send("The game is already started."); + start_game(game_id, game); res.send("SUCCESS"); }); |