Skip to content

Commit

Permalink
Merge pull request #1792 from gereon77/unload-pbem-games-after-one-mi…
Browse files Browse the repository at this point in the history
…nute

Unload PBEM games after 1 minute of inactivity
  • Loading branch information
gereon77 authored Jul 20, 2023
2 parents e301f4d + 334890d commit 29eac2c
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 29eac2c

Please sign in to comment.