summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2021-05-06 18:51:30 +0200
committerTor Andersson <tor@ccxvii.net>2021-05-06 18:51:30 +0200
commitedfb71ff2054ec41691ccc94237826011a3f9f13 (patch)
tree446504f142af70b7374d55591e921469a4f4f597 /server.js
parentf1a23fed2467b6680e4498a6f0207ac8ee348cce (diff)
downloadserver-edfb71ff2054ec41691ccc94237826011a3f9f13.tar.gz
server: Don't crash when debug command to restart throws.
Diffstat (limited to 'server.js')
-rw-r--r--server.js17
1 files changed, 11 insertions, 6 deletions
diff --git a/server.js b/server.js
index f3af3d7..f980f49 100644
--- a/server.js
+++ b/server.js
@@ -919,13 +919,18 @@ io.on('connection', (socket) => {
socket.on('save', () => on_save(socket));
socket.on('restore', (state) => on_restore(socket, state));
socket.on('restart', (scenario) => {
- let state = socket.rules.setup(scenario, players);
- for (let other of clients[socket.game_id]) {
- other.log_length = 0;
- send_state(other, state);
+ try {
+ let state = socket.rules.setup(scenario, players);
+ for (let other of clients[socket.game_id]) {
+ other.log_length = 0;
+ send_state(other, state);
+ }
+ let state_text = JSON.stringify(state);
+ QUERY_RESTART_GAME.run(state_text, socket.game_id);
+ } catch (err) {
+ console.log(err);
+ return socket.emit('error', err.toString());
}
- let state_text = JSON.stringify(state);
- QUERY_RESTART_GAME.run(state_text, socket.game_id);
});
}