diff --git a/client/src/Winner.js b/client/src/Winner.js
index 8a8436d..feac1b4 100644
--- a/client/src/Winner.js
+++ b/client/src/Winner.js
@@ -175,7 +175,8 @@ const Winner = ({ winnerDismissed, setWinnerDismissed }) => {
The game took {totalTime}.
{ robber }
{ max !== 0 && <>
- Player{ playerStolen.length === 1 ? '' : 's'} that had the most ({max}) resources stolen by the thief or other players:
+ The thief (and other players) stole the most resources
+ from:
{ playerStolen }
diff --git a/server/routes/games.js b/server/routes/games.js
index 8b2eaeb..584ebab 100755
--- a/server/routes/games.js
+++ b/server/routes/games.js
@@ -3082,13 +3082,23 @@ const departLobby = (game, session, color) => {
if (session.name) {
if (session.color) {
- addChatMessage(game, null, `${session.name} has disconnected from the game.`);
+ addChatMessage(game, null, `${session.name} has disconnected ` +
+ `from the game.`);
} else {
addChatMessage(game, null, `${session.name} has left the lobby.`);
}
update.chat = game.chat;
+ } else {
+ console.log(`${session.id}: departLobby - ${getName(session)} is ` +
+ `being removed from ${game.id}'s sessions.`);
+ for (let id in game.sessions) {
+ if (game.sessions[id] === session) {
+ delete game.sessions[id];
+ break;
+ }
+ }
}
-
+
sendUpdateToPlayers(game, update);
}
@@ -3154,11 +3164,13 @@ const sendUpdateToPlayers = async (game, update) => {
const _session = game.sessions[key];
/* Only send player and game data to named players */
if (!_session.name) {
- console.log(`${session.id}: -> sendUpdateToPlayers:${getName(_session)} - only sending empty name`);
+ console.log(`${session.id}: -> sendUpdateToPlayers:` +
+ `${getName(_session)} - only sending empty name`);
message = JSON.stringify({ name: "" });
}
if (!_session.ws) {
- console.log(`${_session.id}: -> sendUpdateToPlayers: Currently no connection.`);
+ console.log(`${_session.id}: -> sendUpdateToPlayers: ` +
+ `Currently no connection.`);
} else {
_session.ws.send(message);
}
@@ -3435,6 +3447,8 @@ router.ws("/ws/:id", async (ws, req) => {
});
ws.on('close', async (event) => {
+ console.log(`${short} - closed connection`);
+
const game = await loadGame(gameId);
if (!game) {
return;
@@ -3455,8 +3469,38 @@ router.ws("/ws/:id", async (ws, req) => {
}
departLobby(game, session);
-
- console.log(`${short} - closed connection`);
+
+ /* Check for a game in the Winner state with no more connections
+ * and remove it */
+ if (game.state === 'winner' || game.state === 'lobby') {
+ let dead = true;
+ for (let id in game.sessions) {
+ if (game.sessions[id].live && game.sessions[id].color) {
+ dead = false;
+ }
+ }
+ if (dead) {
+ console.log(`${session.id}: No more players in ${game.id}. Removing.`);
+ addChatMessage(game, null, `No more active players in game. ` +
+ `It is being removed from the server.`);
+ sendUpdateToPlayers(game, {
+ chat: game.chat
+ });
+ for (let id in game.sessions) {
+ if (game.sessions[id].ws) {
+ game.sessions[id].ws.close();
+ delete game.sessions[id];
+ }
+ }
+ delete audio[id];
+ delete games[id];
+ try {
+ fs.unlinkSync(`games/${id}`);
+ } catch (error) {
+ console.error(`${session.id}: Unable to remove games/${id}`);
+ }
+ }
+ }
});
ws.on('message', async (message) => {