Offene Lobbys nach 3 Stunden samt Server löschen (LOBBY_MAX_HOURS)
Der Aufräum-Lauf löscht Lobbys, deren Veto nie gestartet wurde, nach LOBBY_MAX_HOURS (Standard 3, 0 = nie) seit dem Erstellen und stoppt ihren Server. Matches im Veto, im Spiel oder abgeschlossen bleiben unberührt.
This commit is contained in:
1 parent
5503995791
commit
bd022e043e
5 files changed
+49
-2
No files matched your search
@@ -132,12 +132,13 @@ export class ServerManager {
|
||||
}
|
||||
|
||||
/** Löscht ein Match samt Server-Datensatz. Ein laufender Server wird vorher freigegeben. */
|
||||
async deleteMatch(matchId) {
|
||||
async deleteMatch(matchId, reason = 'Match vom Admin gelöscht') {
|
||||
this.service.getMatch(matchId);
|
||||
clearTimeout(this.autoAdvance.get(matchId));
|
||||
this.autoAdvance.delete(matchId);
|
||||
this.simulator.stop(matchId);
|
||||
await this.stop(matchId, 'Match vom Admin gelöscht');
|
||||
this.knifeAttempts.delete(matchId);
|
||||
await this.stop(matchId, reason);
|
||||
this.db.prepare('DELETE FROM matches WHERE id = ?').run(matchId);
|
||||
this.service.emit('changed', matchId);
|
||||
}
|
||||
@@ -687,8 +688,22 @@ export class ServerManager {
|
||||
|
||||
// ---------- Automatisches Herunterfahren ----------
|
||||
|
||||
/** Lobbys, die länger als LOBBY_MAX_HOURS offen sind (Veto nie gestartet), samt Server löschen. */
|
||||
async deleteStaleLobbies(now = Date.now()) {
|
||||
const hours = this.config.lobbyMaxHours;
|
||||
if (!hours) return 0;
|
||||
const stale = this.db.prepare("SELECT id FROM matches WHERE status = 'lobby' AND created_at < ?").all(now - hours * 3_600_000);
|
||||
for (const { id } of stale) {
|
||||
if (this.busy.has(id)) continue;
|
||||
this.logger.log?.(`[aufräumen] Lobby ${id} gelöscht (länger als ${hours} h offen)`);
|
||||
await this.deleteMatch(id, `Lobby länger als ${hours} h offen`).catch((err) => this.logger.error(err));
|
||||
}
|
||||
return stale.length;
|
||||
}
|
||||
|
||||
async reap(now = Date.now()) {
|
||||
this.service.archiveClosed(now);
|
||||
await this.deleteStaleLobbies(now);
|
||||
const timeoutMs = this.config.idleTimeoutMinutes * 60_000;
|
||||
const rows = this.db.prepare(`SELECT * FROM servers WHERE status IN (${ACTIVE.map(() => '?').join(',')})`).all(...ACTIVE);
|
||||
for (const row of rows) {
|
||||
|
||||
Reference in new issue
Block a user