mirror of
https://github.com/AlecM33/Werewolf.git
synced 2026-02-10 04:03:33 +01:00
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:
@@ -313,32 +313,14 @@ const Events = [
|
||||
},
|
||||
{
|
||||
id: EVENT_IDS.TIMER_EVENT,
|
||||
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;
|
||||
}
|
||||
}
|
||||
},
|
||||
stateChange: async (game, socketArgs, vars) => {},
|
||||
communicate: async (game, socketArgs, vars) => {
|
||||
const timer = vars.timerManager.timers[game.accessCode];
|
||||
if (timer) {
|
||||
// Communicate timer state to clients and other instances
|
||||
// Handle timer operations and communicate state to clients and other instances
|
||||
switch (vars.timerEventSubtype) {
|
||||
case GAME_PROCESS_COMMANDS.PAUSE_TIMER:
|
||||
timer.stopTimer();
|
||||
vars.gameManager.namespace.in(game.accessCode).emit(
|
||||
GAME_PROCESS_COMMANDS.PAUSE_TIMER,
|
||||
timer.currentTimeInMillis
|
||||
@@ -354,6 +336,9 @@ const Events = [
|
||||
);
|
||||
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();
|
||||
vars.gameManager.namespace.in(game.accessCode).emit(
|
||||
GAME_PROCESS_COMMANDS.RESUME_TIMER,
|
||||
timer.currentTimeInMillis
|
||||
@@ -397,32 +382,14 @@ const Events = [
|
||||
/* 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. */
|
||||
id: EVENT_IDS.SOURCE_TIMER_EVENT,
|
||||
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;
|
||||
}
|
||||
}
|
||||
},
|
||||
stateChange: async (game, socketArgs, vars) => {},
|
||||
communicate: async (game, socketArgs, vars) => {
|
||||
const timer = vars.timerManager.timers[game.accessCode];
|
||||
if (timer) {
|
||||
// Publish timer state to other instances
|
||||
// Handle timer operations and publish timer state to other instances
|
||||
switch (socketArgs.timerEventSubtype) {
|
||||
case GAME_PROCESS_COMMANDS.PAUSE_TIMER:
|
||||
timer.stopTimer();
|
||||
await vars.eventManager.publisher.publish(
|
||||
REDIS_CHANNELS.ACTIVE_GAME_STREAM,
|
||||
vars.eventManager.createMessageToPublish(
|
||||
@@ -434,6 +401,9 @@ const Events = [
|
||||
);
|
||||
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();
|
||||
await vars.eventManager.publisher.publish(
|
||||
REDIS_CHANNELS.ACTIVE_GAME_STREAM,
|
||||
vars.eventManager.createMessageToPublish(
|
||||
|
||||
@@ -146,15 +146,9 @@ class EventManager {
|
||||
game.accessCode,
|
||||
args,
|
||||
ackFn,
|
||||
false,
|
||||
true,
|
||||
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 {
|
||||
await this.handleAndSyncSocketEvent(eventId, game, socket, args, ackFn);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user