Rooms: Only lockdown after restarts when battles crash (#9110)

This commit is contained in:
Mia 2022-12-04 11:45:31 -06:00 committed by GitHub
parent 2726d87170
commit 93a0a0f61c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -12,7 +12,6 @@ import * as fs from 'fs';
import * as path from 'path';
const CRASH_EMAIL_THROTTLE = 5 * 60 * 1000; // 5 minutes
const LOCKDOWN_PERIOD = 30 * 60 * 1000; // 30 minutes
const logPath = path.resolve(__dirname, '../logs/errors.txt');
let lastCrashLog = 0;
@ -85,10 +84,5 @@ export function crashlogger(
});
}
if (process.uptime() * 1000 < LOCKDOWN_PERIOD) {
// lock down the server
return 'lockdown';
}
return null;
}

View File

@ -50,6 +50,7 @@ const DISCONNECTION_BANK_TIME = 300;
// time after a player disabling the timer before they can re-enable it
const TIMER_COOLDOWN = 20 * SECONDS;
const LOCKDOWN_PERIOD = 30 * 60 * 1000; // 30 minutes
export class RoomBattlePlayer extends RoomGames.RoomGamePlayer<RoomBattle> {
readonly slot: SideID;
@ -841,6 +842,16 @@ export class RoomBattle extends RoomGames.RoomGame<RoomBattlePlayer> {
break;
}
case 'error': {
if (process.uptime() * 1000 < LOCKDOWN_PERIOD) {
const error = new Error();
error.stack = lines.slice(1).join('\n');
// lock down the server
Rooms.global.startLockdown(error);
}
break;
}
case 'end':
this.logData = JSON.parse(lines[1]);
this.score = this.logData!.score;
@ -1338,7 +1349,7 @@ export class RoomBattleStream extends BattleStream {
}
try {
this._writeLines(chunk);
} catch (err) {
} catch (err: any) {
const battle = this.battle;
Monitor.crashlog(err, 'A battle', {
chunk,
@ -1354,6 +1365,8 @@ export class RoomBattleStream extends BattleStream {
}
}
}
// public crashlogs only have the stack anyways
this.push(`error\n${err.stack}`);
}
if (this.battle) this.battle.sendUpdates();
const deltaTime = Date.now() - startTime;