fix stopped game count when stopping the server
authorRaphaël Jakse <raphael.jakse@univ-grenoble-alpes.fr>
Sun, 5 Apr 2020 16:13:13 +0000 (18:13 +0200)
committerRaphaël Jakse <raphael.jakse@univ-grenoble-alpes.fr>
Sun, 5 Apr 2020 16:13:13 +0000 (18:13 +0200)
trivabble-server.js

index 25bfb3d05a5c41311389eeda97a5b0482c59402e..bd3005a1d619f2f2588b5e790353a9001178be86 100644 (file)
@@ -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);
 }