Skip to content

Implement player session management

Objective

Create robust player session management system that handles authentication state, session persistence, and player lifecycle management.

Requirements

  • Session Tracking: Track authenticated players across connections
  • State Persistence: Maintain player state during reconnections
  • Session Security: Validate and refresh authentication tokens
  • Cleanup: Handle disconnection and session expiration gracefully

Technical Details

  • Integrate with Keycloak authentication system
  • Create session storage and retrieval mechanisms
  • Implement session timeout and cleanup policies
  • Handle WebSocket connection mapping to player sessions
  • Add session state synchronization
  • Implement graceful session migration on reconnect

Acceptance Criteria

  • Player sessions are created on successful authentication
  • Sessions persist across WebSocket reconnections
  • Session expiration is handled properly
  • Player state is maintained during brief disconnections
  • Session cleanup prevents memory leaks

Implementation Status - COMPLETED

Recent Updates (2025-07-02):

  • Session Creation: Automatic session creation on WebSocket authentication
  • Token Integration: JWT token validation with Keycloak integration
  • Session Persistence: localStorage-based token persistence with 7-day expiration
  • Connection Mapping: WebSocket connections properly mapped to user sessions
  • Reconnection Handling: Seamless session restoration on reconnection
  • Session Cleanup: Automatic cleanup on disconnection and timeout
  • State Management: Player state maintained across connection drops

Technical Implementation:

  • SessionManager.ts: Server-side session tracking and lifecycle management
  • AuthController.ts: Authentication endpoint with session creation
  • AuthManager.ts: Client-side token persistence and auto-login
  • ConnectionManager.ts: Session restoration on reconnection
  • ProtobufWebSocketHandler.ts: Session validation and connection mapping

Session Flow:

  1. User authenticates via Keycloak → Session created
  2. WebSocket connects → Session validated via JWT token
  3. Connection drops → Session maintained server-side
  4. Reconnection → Session restored automatically
  5. Session expiry/logout → Cleanup and disconnection

Milestone Relation

COMPLETED - Critical for MVP multiplayer functionality. Bridges authentication with game state management and enables persistent player experiences.

Edited by Adam Kunz