+
+// Every 24 hours, scan games and remove if last move older than 24h
+const dayInMillisecs = 24 * 60 * 60 * 1000;
+const killOldGames = setInterval(() => {
+ const now = Date.now();
+ Object.keys(games).forEach(gid => {
+ if (now - games[gid].time >= dayInMillisecs) delete games[gid];
+ });
+}, dayInMillisecs);
+
+// TODO: useful code here?
+wss.on("close", () => {
+ clearInterval(heartbeat);
+ clearInterval(killOldGames);
+});