summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-01-11 18:23:15 +0100
committerTor Andersson <tor@ccxvii.net>2022-01-12 13:46:41 +0100
commit7abe96f4eb6dca922f6784f048050ddbdea975f3 (patch)
tree6abbc563f126c13776536a30b1dd2cf977e0a9f6
parente40d9af1a6e90d295191a9b1c6e320f789c58ecf (diff)
downloadserver-7abe96f4eb6dca922f6784f048050ddbdea975f3.tar.gz
Handle errors when following a rematch link to an already started game.
-rw-r--r--public/common/play.css1
-rw-r--r--server.js29
2 files changed, 17 insertions, 13 deletions
diff --git a/public/common/play.css b/public/common/play.css
index 64e9202..4a413fc 100644
--- a/public/common/play.css
+++ b/public/common/play.css
@@ -70,6 +70,7 @@ header {
display: flex;
align-items: center;
border-bottom: 1px solid black;
+ background-color: gainsboro;
}
header.disconnected {
diff --git a/server.js b/server.js
index 266c49c..9d2f4f8 100644
--- a/server.js
+++ b/server.js
@@ -1132,22 +1132,25 @@ app.get('/delete/:game_id', must_be_logged_in, function (req, res) {
});
function join_rematch(req, res, game_id, role) {
- let is_random = SQL_SELECT_GAME_RANDOM.get(game_id);
- if (is_random) {
- for (let i = 1; i <= 6; ++i) {
- let info = SQL_INSERT_PLAYER_ROLE.run(game_id, 'Random ' + i, req.user.user_id);
- if (info.changes === 1) {
- update_join_clients_players(game_id);
- break;
+ try {
+ let is_random = SQL_SELECT_GAME_RANDOM.get(game_id);
+ if (is_random) {
+ for (let i = 1; i <= 6; ++i) {
+ let info = SQL_INSERT_PLAYER_ROLE.run(game_id, 'Random ' + i, req.user.user_id);
+ if (info.changes === 1) {
+ update_join_clients_players(game_id);
+ break;
+ }
}
+ } else {
+ let info = SQL_INSERT_PLAYER_ROLE.run(game_id, role, req.user.user_id);
+ if (info.changes === 1)
+ update_join_clients_players(game_id);
}
- return res.redirect('/join/'+game_id);
- } else {
- let info = SQL_INSERT_PLAYER_ROLE.run(game_id, role, req.user.user_id);
- if (info.changes === 1)
- update_join_clients_players(game_id);
- return res.redirect('/join/'+game_id);
+ } catch (err) {
+ console.log(err);
}
+ return res.redirect('/join/'+game_id);
}
app.get('/rematch/:old_game_id/:role', must_be_logged_in, function (req, res) {