Gameplay Networking Documentation

This section covers the networking aspects specific to gameplay in the MTG Commander game engine. While the lobby system handles pre-game setup, the gameplay networking components manage the actual game session, including state synchronization, player actions, and handling departures.

Overview

The gameplay networking implementation focuses on several key areas:

  1. State Management: Maintaining and synchronizing the game state across all clients
  2. Action Processing: Handling player actions and their effects on the game state
  3. Synchronization: Ensuring all clients have a consistent view of the game
  4. Departure Handling: Managing player disconnections and reconnections

Gameplay Components

State Management

The State Management system handles the representation and replication of game state:

  • Core game state structure and components
  • State replication with bevy_replicon
  • Hidden information management
  • State consistency and verification
  • Rollback and Recovery for handling network disruptions

Synchronization

The Synchronization system ensures all clients maintain a consistent view of the game:

  • Server-authoritative model
  • Command-based synchronization
  • Incremental state updates
  • Tick-based processing
  • Handling network issues

Departure Handling

The Departure Handling system manages player disconnections and reconnections:

  • Detecting disconnections
  • Preserving game state for disconnected players
  • Handling reconnections
  • Game continuation policies
  • Timeout and abandonment handling

Implementation Principles

Our gameplay networking implementation follows these core principles:

  1. Server Authority: The server is the single source of truth for game state
  2. Minimal Network Usage: Only necessary information is transmitted
  3. Resilience: The system can handle network disruptions gracefully through deterministic rollbacks
  4. Security: Hidden information remains protected
  5. Fairness: All players have equal opportunity regardless of network conditions
  6. Determinism: Game actions produce identical results when replayed with the same RNG state

Integration with Other Systems

The gameplay networking components integrate with several other systems:

  • Lobby System: For transitioning from lobby to game
  • Security: For protecting hidden information and preventing cheating
  • Testing: For validating network behavior and performance

Future Enhancements

Planned gameplay networking enhancements include:

  • Spectator Mode: Allow non-players to watch games in progress
  • Replay System: Record and replay games for analysis
  • Enhanced Reconnection: More sophisticated state recovery for long disconnections
  • Optimized Synchronization: Improved performance for complex game states
  • Cross-Platform Play: Ensure consistent experience across different platforms

This documentation will evolve as the gameplay networking implementation progresses.