This commit is contained in:
legop3
2026-04-28 19:53:10 -04:00
parent f13b85109e
commit 49f801330f
59 changed files with 686 additions and 401 deletions
@@ -0,0 +1,38 @@
// lockdown Guard
// Purpose: Defines the lockdown Guard module and the helpers/state used by this service unit.
// Scope: Keeps runtime behavior unchanged while isolating responsibilities into a clear module boundary.
const io = require('../../globals/io');
const { MODES, getMode, modeEvents } = require('../modeManager');
const { isLockdownAdmin } = require('../roleService');
function disconnectForLockdown(socket) {
socket.emit('lockdown', { message: 'Server is in lockdown mode' });
socket.disconnect(true);
}
function clearLockdownTimer(socket) {
if (socket?.data?.lockdownTimer) {
clearTimeout(socket.data.lockdownTimer);
socket.data.lockdownTimer = null;
}
}
function enforceLockdown() {
for (const socket of io.sockets.sockets.values()) {
if (!isLockdownAdmin(socket)) {
disconnectForLockdown(socket);
}
}
}
module.exports = {
enforceLockdown,
disconnectForLockdown,
clearLockdownTimer,
};
modeEvents.on('change', (mode) => {
if (mode === MODES.LOCKDOWN) {
enforceLockdown();
}
});