diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-05-06 18:51:30 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2021-05-06 18:51:30 +0200 |
commit | edfb71ff2054ec41691ccc94237826011a3f9f13 (patch) | |
tree | 446504f142af70b7374d55591e921469a4f4f597 /server.js | |
parent | f1a23fed2467b6680e4498a6f0207ac8ee348cce (diff) | |
download | server-edfb71ff2054ec41691ccc94237826011a3f9f13.tar.gz |
server: Don't crash when debug command to restart throws.
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -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); }); } |