switch to global cooldown, tracking per user is useless i realized lol

This commit is contained in:
legop3
2026-05-28 17:34:10 -04:00
parent 955b613527
commit 94ef97f5bb
2 changed files with 16 additions and 22 deletions
+8 -9
View File
@@ -1,14 +1,13 @@
1. FIX NO AUDIO DURING NOT YOUR TURN!!! 1. make sure audio forwarding doesnt stop when you switch tabs
2. make sure audio forwarding doesnt stop when you switch tabs 2. add "reboot your own rover" feature
3. add "reboot your own rover" feature
1. time delay and you can only do it if youre the only one on. server locks the rover then tells it to reboot 1. time delay and you can only do it if youre the only one on. server locks the rover then tells it to reboot
4. add a clear socket disconnection indicator in the web UI 3. add a clear socket disconnection indicator in the web UI
5. add votekicking 4. add votekicking
1. simply just disconnect the users socket. 1. simply just disconnect the users socket.
6. add faster way for admins to login, like an invisible button in top left or something 5. add faster way for admins to login, like an invisible button in top left or something
7. add discord bot typing thing for when someone requests a replay 6. add discord bot typing thing for when someone requests a replay
8. change replay title for ones requested from discord, something other than "requester driving rover" 7. change replay title for ones requested from discord, something other than "requester driving rover"
9. fix rover request spam queue cheat 8. fix rover request spam queue cheat
# relative pipe dreams: # relative pipe dreams:
@@ -10,16 +10,15 @@ const { stopRover } = require('../turnService/actions');
const { issueCommand } = require('../commandService'); const { issueCommand } = require('../commandService');
const { publishEvent } = require('../eventBus'); const { publishEvent } = require('../eventBus');
const USER_COOLDOWN_MS = 2 * 60 * 1000; const USER_COOLDOWN_MS = 6 * 60 * 1000;
const userCooldowns = new Map(); // socketId -> blockedUntil let globalCooldownUntil = 0;
function getCooldownLeftMs(socketId) { function getCooldownLeftMs() {
const blockedUntil = Number(userCooldowns.get(socketId) || 0); return Math.max(0, Number(globalCooldownUntil) - Date.now());
return Math.max(0, blockedUntil - Date.now());
} }
function setCooldown(socketId) { function setCooldown() {
userCooldowns.set(socketId, Date.now() + USER_COOLDOWN_MS); globalCooldownUntil = Date.now() + USER_COOLDOWN_MS;
} }
function canRequestReboot(socket) { function canRequestReboot(socket) {
@@ -34,7 +33,7 @@ function canRequestReboot(socket) {
if (!(record.drivers instanceof Set) || record.drivers.size !== 1 || !record.drivers.has(socket.id)) { if (!(record.drivers instanceof Set) || record.drivers.size !== 1 || !record.drivers.has(socket.id)) {
throw new Error('Reboot blocked while other drivers are connected'); throw new Error('Reboot blocked while other drivers are connected');
} }
const cooldownLeftMs = getCooldownLeftMs(socket.id); const cooldownLeftMs = getCooldownLeftMs();
if (cooldownLeftMs > 0) { if (cooldownLeftMs > 0) {
throw new Error(`Reboot cooldown active (${Math.ceil(cooldownLeftMs / 1000)}s)`); throw new Error(`Reboot cooldown active (${Math.ceil(cooldownLeftMs / 1000)}s)`);
} }
@@ -47,7 +46,7 @@ io.on('connection', (socket) => {
const { roverId, record } = canRequestReboot(socket); const { roverId, record } = canRequestReboot(socket);
stopRover(roverId); stopRover(roverId);
issueCommand(roverId, { type: 'reboot', reboot: { delayMs: 300 } }); issueCommand(roverId, { type: 'reboot', reboot: { delayMs: 300 } });
setCooldown(socket.id); setCooldown();
const requester = socket?.data?.user?.username || socket.id; const requester = socket?.data?.user?.username || socket.id;
publishEvent({ publishEvent({
source: 'roverRebootService', source: 'roverRebootService',
@@ -67,10 +66,6 @@ io.on('connection', (socket) => {
socket.on('session:rebootOwnRover', handleRebootOwnRover); socket.on('session:rebootOwnRover', handleRebootOwnRover);
socket.on('rebootOwnRover', handleRebootOwnRover); socket.on('rebootOwnRover', handleRebootOwnRover);
socket.on('disconnect', () => {
userCooldowns.delete(socket.id);
});
}); });
module.exports = {}; module.exports = {};