Restore syncOnly to true and remove state changes from TIMER_EVENT/SOURCE_TIMER_EVENT

Co-authored-by: AlecM33 <24642328+AlecM33@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-24 01:55:05 +00:00
parent 639f181986
commit 31de1445bf
2 changed files with 13 additions and 49 deletions

View File

@@ -313,32 +313,14 @@ const Events = [
}, },
{ {
id: EVENT_IDS.TIMER_EVENT, id: EVENT_IDS.TIMER_EVENT,
stateChange: async (game, socketArgs, vars) => { stateChange: async (game, socketArgs, vars) => {},
const timer = vars.timerManager.timers[game.accessCode];
if (timer) {
// Update game state based on timer command
switch (vars.timerEventSubtype) {
case GAME_PROCESS_COMMANDS.PAUSE_TIMER:
timer.stopTimer();
game.timerParams.paused = true;
game.timerParams.timeRemaining = timer.currentTimeInMillis;
break;
case GAME_PROCESS_COMMANDS.RESUME_TIMER:
// resumeTimer() returns the timesUpPromise, but we don't await it here
// because timer completion is already handled by TimerManager.runTimer()
timer.resumeTimer();
game.timerParams.paused = false;
game.timerParams.timeRemaining = timer.currentTimeInMillis;
break;
}
}
},
communicate: async (game, socketArgs, vars) => { communicate: async (game, socketArgs, vars) => {
const timer = vars.timerManager.timers[game.accessCode]; const timer = vars.timerManager.timers[game.accessCode];
if (timer) { if (timer) {
// Communicate timer state to clients and other instances // Handle timer operations and communicate state to clients and other instances
switch (vars.timerEventSubtype) { switch (vars.timerEventSubtype) {
case GAME_PROCESS_COMMANDS.PAUSE_TIMER: case GAME_PROCESS_COMMANDS.PAUSE_TIMER:
timer.stopTimer();
vars.gameManager.namespace.in(game.accessCode).emit( vars.gameManager.namespace.in(game.accessCode).emit(
GAME_PROCESS_COMMANDS.PAUSE_TIMER, GAME_PROCESS_COMMANDS.PAUSE_TIMER,
timer.currentTimeInMillis timer.currentTimeInMillis
@@ -354,6 +336,9 @@ const Events = [
); );
break; break;
case GAME_PROCESS_COMMANDS.RESUME_TIMER: case GAME_PROCESS_COMMANDS.RESUME_TIMER:
// resumeTimer() returns the timesUpPromise, but we don't await it here
// because timer completion is already handled by TimerManager.runTimer()
timer.resumeTimer();
vars.gameManager.namespace.in(game.accessCode).emit( vars.gameManager.namespace.in(game.accessCode).emit(
GAME_PROCESS_COMMANDS.RESUME_TIMER, GAME_PROCESS_COMMANDS.RESUME_TIMER,
timer.currentTimeInMillis timer.currentTimeInMillis
@@ -397,32 +382,14 @@ const Events = [
/* This event is a request from another instance to consult its timer data. In response /* This event is a request from another instance to consult its timer data. In response
* to this event, this instance will check if it is home to a particular timer. */ * to this event, this instance will check if it is home to a particular timer. */
id: EVENT_IDS.SOURCE_TIMER_EVENT, id: EVENT_IDS.SOURCE_TIMER_EVENT,
stateChange: async (game, socketArgs, vars) => { stateChange: async (game, socketArgs, vars) => {},
const timer = vars.timerManager.timers[game.accessCode];
if (timer) {
// Update game state based on timer command
switch (socketArgs.timerEventSubtype) {
case GAME_PROCESS_COMMANDS.PAUSE_TIMER:
timer.stopTimer();
game.timerParams.paused = true;
game.timerParams.timeRemaining = timer.currentTimeInMillis;
break;
case GAME_PROCESS_COMMANDS.RESUME_TIMER:
// resumeTimer() returns the timesUpPromise, but we don't await it here
// because timer completion is already handled by TimerManager.runTimer()
timer.resumeTimer();
game.timerParams.paused = false;
game.timerParams.timeRemaining = timer.currentTimeInMillis;
break;
}
}
},
communicate: async (game, socketArgs, vars) => { communicate: async (game, socketArgs, vars) => {
const timer = vars.timerManager.timers[game.accessCode]; const timer = vars.timerManager.timers[game.accessCode];
if (timer) { if (timer) {
// Publish timer state to other instances // Handle timer operations and publish timer state to other instances
switch (socketArgs.timerEventSubtype) { switch (socketArgs.timerEventSubtype) {
case GAME_PROCESS_COMMANDS.PAUSE_TIMER: case GAME_PROCESS_COMMANDS.PAUSE_TIMER:
timer.stopTimer();
await vars.eventManager.publisher.publish( await vars.eventManager.publisher.publish(
REDIS_CHANNELS.ACTIVE_GAME_STREAM, REDIS_CHANNELS.ACTIVE_GAME_STREAM,
vars.eventManager.createMessageToPublish( vars.eventManager.createMessageToPublish(
@@ -434,6 +401,9 @@ const Events = [
); );
break; break;
case GAME_PROCESS_COMMANDS.RESUME_TIMER: case GAME_PROCESS_COMMANDS.RESUME_TIMER:
// resumeTimer() returns the timesUpPromise, but we don't await it here
// because timer completion is already handled by TimerManager.runTimer()
timer.resumeTimer();
await vars.eventManager.publisher.publish( await vars.eventManager.publisher.publish(
REDIS_CHANNELS.ACTIVE_GAME_STREAM, REDIS_CHANNELS.ACTIVE_GAME_STREAM,
vars.eventManager.createMessageToPublish( vars.eventManager.createMessageToPublish(

View File

@@ -146,15 +146,9 @@ class EventManager {
game.accessCode, game.accessCode,
args, args,
ackFn, ackFn,
false, true,
eventId eventId
); );
// Refresh and sync game state after timer events
await gameManager.refreshGame(game);
await this.publisher?.publish(
REDIS_CHANNELS.ACTIVE_GAME_STREAM,
this.createMessageToPublish(game.accessCode, EVENT_IDS.TIMER_EVENT, this.instanceId, JSON.stringify({ timerEventSubtype: eventId, socketId: socket.id }))
);
} else { } else {
await this.handleAndSyncSocketEvent(eventId, game, socket, args, ackFn); await this.handleAndSyncSocketEvent(eventId, game, socket, args, ackFn);
} }