- gameManager.js:
- Added disconnectTimeouts Map to track/clear pending timeouts correctly
- Updated handleDisconnect to not abandon game if player reconnects
- Updated registerPlayer to clear timeouts and restore active game state
- Added race condition checks to handleSurrender and acceptRematch
- multiplayer.js:
- Updated handleRegistration to resume active game if data provided
- Updated startMultiplayerGame to restore board state from server data
- Re-added handleSurrender, sendRematch, acceptRematch, declineRematch methods
- Fixed to use activeGames instead of games Map
- Fixed to use correct property names (player1Id not player1_id)
- This fixes the issue where surrender would hang indefinitely
- Added opponentId field to both game_started socket emissions in acceptChallenge
- This allows client to properly track opponent for rematch requests
- Fixes surrender button not showing issue (client needs opponentId to enable features)
Client-side (multiplayer.js):
- Add socket listeners for rematch events
- Update startMultiplayerGame to show surrender button and track opponent ID
- Update handleGameEnded to show game-over modal with stats
- Add handleRematchRequest method
- Add global helper functions for rematch acceptance/decline
Server-side (gameManager.js):
- Add rematches Map to track rematch requests
- Add handleSurrender method
- Add sendRematch, acceptRematch, declineRematch methods
- Handle surrender stats updates and game cleanup
Server (server.js):
- Add socket listeners for: surrender, send_rematch, accept_rematch, decline_rematch
Features now fully functional:
- Players can surrender during active games
- Players can request rematches after games end
- Opponents receive rematch notifications
- Game-over modal shows stats and rematch option