Skip to content

Feat/reconnection - #1160

Merged
chinweobtagaz merged 11 commits into
OpenKnight-Foundation:mainfrom
nafsonig:feat/Reconnection
Aug 28, 2026
Merged

Feat/reconnection#1160
chinweobtagaz merged 11 commits into
OpenKnight-Foundation:mainfrom
nafsonig:feat/Reconnection

Conversation

@nafsonig

Copy link
Copy Markdown
Contributor

Key Implementations:

1. Connection State Tracking

Added in ws.rs:

  • ConnectionStatus enum: Tracks players as Connected, Reconnecting, or Disconnected
  • PlayerConnectionState: Manages individual player's connection status, disconnection time, and grace timer
  • GameSessionState: Tracks all players in a game session
  • ConnectionStateTracker: Central actor that manages all active game sessions

closes #1014

2. Grace Period & Reconnection Logic

  • 60-second grace period: When a WebSocket disconnects, a timer starts. If the player doesn't reconnect within 60s, the game is marked as abandoned.
  • Opponent notifications: When a player disconnects, their opponent receives OpponentDisconnected { grace_seconds_left: 60 }. When they reconnect, the opponent gets OpponentReconnected.
  • Full state sync: Reconnecting players receive a FullStateSync message with current FEN, move history, and clock times.

3. WebSocket Session Updates

  • Updated WsSession to hold a reference to the ConnectionStateTracker
  • When a WebSocket starts: Notify tracker with PlayerReconnected
  • When a WebSocket stops: Notify tracker with PlayerDisconnected (starts grace timer)
  • Reconnection token expiration updated to match 60s grace period

closes #1022

4. Server Integration

Updated server.rs:

  • Added ConnectionStateTracker as a shared actor initialized with the database pool
  • Added as app_data so WebSocket route can access it
  • Updated WebSocket route to receive the tracker

5. Tests Added

  • test_websocket_drop_and_reconnect: Simulates a 10-second disconnect and successful reconnection
  • test_grace_period_expiry: Verifies that when grace period expires, player is marked as permanently disconnected

closes #1023

Acceptance Criteria Met:

✅ Brief disconnects (<60s) reconnect cleanly without forfeiting
✅ Reconnecting players get full state sync (FEN, moves, clocks)
✅ Opponents receive OpponentDisconnected(grace_seconds_left) notification
✅ After 60s, abandonment is triggered, awarding win to connected player

The implementation follows all requirements: game clocks continue running for disconnected players who are on the move, and no infinite stalling is possible - the 60s grace period is strictly enforced.

closes #1018

@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@nafsonig Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@chinweobtagaz
chinweobtagaz merged commit 7b5f1d5 into OpenKnight-Foundation:main Aug 28, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants