From fa22a07af8addf706a67b17654681677e4b3d66e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Jakse?= Date: Sun, 5 Apr 2020 18:13:13 +0200 Subject: [PATCH] fix stopped game count when stopping the server --- trivabble-server.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/trivabble-server.js b/trivabble-server.js index 25bfb3d..bd3005a 100644 --- a/trivabble-server.js +++ b/trivabble-server.js @@ -157,16 +157,21 @@ function stop() { console.log("Closing connections and saving the game state..."); let listeningPlayerCount = 0; + let gamesCount = 0; for (const gameID of Object.keys(games)) { const game = games[gameID]; for (const listeningPlayer of game.listeningPlayers) { writeResponse(listeningPlayer, '{"stopping": 2000}', true); } - listeningPlayerCount += game.listeningPlayers.length; + + if (game.listeningPlayers.length) { + listeningPlayerCount += game.listeningPlayers.length; + gamesCount++; + } } - console.log("Stopped", games.length, "games and ", listeningPlayerCount, " player connections."); + console.log("Stopped", gamesCount, "games and", listeningPlayerCount, "player connections."); saveGames(true); } -- 2.30.2