From 334890dbe7b8cc9f327996f13c953ebf8549dd55 Mon Sep 17 00:00:00 2001 From: gereon77 Date: Thu, 20 Jul 2023 09:51:23 +0200 Subject: [PATCH] Unload PBEM games after 1 minute of inactivity --- agot-bg-game-server/src/server/GlobalServer.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/agot-bg-game-server/src/server/GlobalServer.ts b/agot-bg-game-server/src/server/GlobalServer.ts index 091308c16..d59489350 100644 --- a/agot-bg-game-server/src/server/GlobalServer.ts +++ b/agot-bg-game-server/src/server/GlobalServer.ts @@ -597,14 +597,15 @@ export default class GlobalServer { async runBackgroundTasks(): Promise { while (true) { - await sleep(10 * 60 * 1000); + await sleep(3 * 60 * 1000); const now = new Date(); // Unload inactive games: this.loadedGames.values.filter(game => game.lastMessageReceivedAt != null).forEach(game => { const secondsSinceLastIncomingMessage = getTimeDeltaInSeconds(now, game.lastMessageReceivedAt as Date); - if (secondsSinceLastIncomingMessage >= (60 * 60)) { + if ((game.gameSettings.pbem && secondsSinceLastIncomingMessage >= 60) || + (!game.gameSettings.pbem && secondsSinceLastIncomingMessage >= (35 * 60))) { this.unloadGame(game); } });