Skip to content

Commit

Permalink
Unload PBEM games after 1 minute of inactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
gereon77 committed Jul 20, 2023
1 parent e301f4d commit 334890d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions agot-bg-game-server/src/server/GlobalServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,14 +597,15 @@ export default class GlobalServer {

async runBackgroundTasks(): Promise<void> {
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);
}
});
Expand Down

0 comments on commit 334890d

Please sign in to comment.