mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 09:31:20 -04:00
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
// 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();
|
|
}
|
|
});
|