feat: Implement player reconnection logic and auto-pick functionality for disconnected players during draft.
All checks were successful
Build and Deploy / build (push) Successful in 1m18s

This commit is contained in:
2025-12-16 18:46:55 +01:00
parent 6163869a17
commit 4663c968ee
6 changed files with 186 additions and 39 deletions

View File

@@ -0,0 +1,21 @@
# 2025-12-16 - Reconnection and Auto-Pick
## Reconnection Logic
- Use `localStorage.setItem('active_room_id', roomId)` in `LobbyManager` to persist connection state.
- Upon page load, if a saved room ID exists, attempted to automatically reconnect via `rejoin_room` socket event.
- Updated `socket.on('join_room')` and `rejoin_room` on the server to update the player's socket ID mapping, canceling any pending "disconnect" timers.
## Disconnection Handling
- Updated `RoomManager` to track `socketId` and `isOffline` status for each player.
- In `index.ts`, `socket.on('disconnect')`:
- Marks player as offline.
- Starts a **30-second timer**.
- If timer expires (user did not reconnect):
- Triggers `draftManager.autoPick(roomId, playerId)`.
- `autoPick` selects a random card from the active pack to unblock the draft flow.
## Auto-Pick Implementation
- Added `autoPick` to `DraftManager`:
- Checks if player has an active pack.
- Selects random index.
- Calls `pickCard` internally to process the pick (add to pool, pass pack, etc.).