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

@@ -12,3 +12,4 @@
- [Fix Socket Mixed Content](./devlog/2025-12-16-183000_fix_socket_mixed_content.md): Completed. Resolved mixed content error in production by making socket connection URL environment-aware.
- [Draft Rules & Pick Logic](./devlog/2025-12-16-180000_draft_rules_implementation.md): Completed. Enforced 4-player minimum and "Pick 2" rule for 4-player drafts.
- [Fix Pack Duplication](./devlog/2025-12-16-184500_fix_pack_duplication.md): Completed. Enforced deep cloning and unique IDs for all draft packs to prevent opening identical packs.
- [Reconnection & Auto-Pick](./devlog/2025-12-16-191500_reconnection_and_autopick.md): Completed. Implemented session persistence, seamless reconnection, and 30s auto-pick on disconnect.

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