From edfb71ff2054ec41691ccc94237826011a3f9f13 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 6 May 2021 18:51:30 +0200 Subject: server: Don't crash when debug command to restart throws. --- server.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'server.js') 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); }); } -- cgit v1.2.3