8 Commits

Author SHA1 Message Date
d0f72f01c8 Fix: syntax error in registerPlayer 2025-12-22 19:26:02 +11:00
69dc70ee06 Reliability: Fix disconnect logic, add game restoration, and prevent race conditions
- 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
2025-12-22 19:25:15 +11:00
f879050b0c Fix: Add missing socket listeners and fix database calls for surrender/rematch
- server.js: Added missing listeners for surrender, send_rematch, accept_rematch, decline_rematch events (previously missing, causing features to simple do nothing)
- gameManager.js: Removed invalid calls to non-existent incrementWins/incrementLosses methods (abandonGame already handles this internally)
2025-12-22 19:19:30 +11:00
04860c3e39 Fix: Re-add surrender and rematch methods that were accidentally removed
- 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
2025-12-22 19:15:22 +11:00
62b28beed3 Fix: Add opponentId to game_started events for surrender/rematch functionality
- 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)
2025-12-22 18:09:55 +11:00
0933644710 Fix gameManager.js syntax errors and add rematches Map to constructor 2025-12-22 17:46:46 +11:00
a9d1327d77 Add surrender and rematch functionality - Part 2 (Complete)
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
2025-12-22 17:42:14 +11:00
9465409b2f Add complete multiplayer system with real-time gameplay, challenge system, and 50x50 board option 2025-12-13 14:59:44 +11:00