# 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
1.  **Server: DraftManager.ts**
    *   Updated `DraftState` to include `pickExpiresAt` (timestamp) for each player and `isPaused` for the draft.
    *   Initialize `pickExpiresAt` to 60 seconds from now when a player receives a pack (initial or passed).
    *   Implemented `checkTimers()` method to iterate over all active drafts and players. If `Date.now() > pickExpiresAt`, it triggers `autoPick`.
    *   Implemented `setPaused()` to handle host disconnects. When resuming, timers are reset to 60s to prevent immediate timeout.

2.  **Server: index.ts**
    *   Removed ad-hoc `playerTimers` map and individual `setTimeout` logic associated with socket disconnect events.
    *   Added a global `setInterval` (1 second tick) that calls `draftManager.checkTimers()` and broadcasts updates.
    *   Updated `disconnect` handler to pause the draft if the host disconnects (`draftManager.setPaused(..., true)`).
    *   Updated `join_room` / `rejoin_room` handlers to resume the draft if the host reconnects.

3.  **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.

## 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.
