From dcd1a5c758a3ba97f2ecbcda41e793ca475df15a Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 22 May 2022 16:46:17 +0200 Subject: Split out start_game function. --- server.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index 5882ba8..d28fb31 100644 --- a/server.js +++ b/server.js @@ -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"); }); -- cgit v1.2.3