2.1 KiB
2.1 KiB
2025-12-16 - Draft Timer Enforcement
Status
Completed
Description
Implemented server-side timer enforcement for the draft phase to ensure the game progresses even if players are AFK or disconnected.
Changes
-
Server: DraftManager.ts
- Updated
DraftStateto includepickExpiresAt(timestamp) for each player andisPausedfor the draft. - Initialize
pickExpiresAtto 60 seconds from now when a player receives a pack (initial or passed). - Implemented
checkTimers()method to iterate over all active drafts and players. IfDate.now() > pickExpiresAt, it triggersautoPick. - Implemented
setPaused()to handle host disconnects. When resuming, timers are reset to 60s to prevent immediate timeout.
- Updated
-
Server: index.ts
- Removed ad-hoc
playerTimersmap and individualsetTimeoutlogic associated with socket disconnect events. - Added a global
setInterval(1 second tick) that callsdraftManager.checkTimers()and broadcasts updates. - Updated
disconnecthandler to pause the draft if the host disconnects (draftManager.setPaused(..., true)). - Updated
join_room/rejoin_roomhandlers to resume the draft if the host reconnects.
- Removed ad-hoc
-
Client: DraftView.tsx
- Updated the timer display logic to calculate remaining time based on
draftState.players[id].pickExpiresAt-Date.now(). - The timer now accurately reflects the server-enforced deadline.
- Updated the timer display logic to calculate remaining time based on
Behavior
- Drafting: Each pick has a 60-second limit.
- Deck Building: 120-second limit. If time runs out, the game forces start. Any unready players have their entire draft pool submitted as their deck automatically.
- Timeout: If time runs out, a random card is automatically picked, and the next pack (if available) is loaded with a fresh 60s timer.
- AFK: If a user is AFK, the system continues to auto-pick for them until the draft concludes.
- Host Disconnect: If the host leaves, the draft pauses for everyone. Timer stops.
- Host Reconnect: Draft resumes, and all active pick timers are reset to 60s.