End-to-End Flow
This is the complete flow for a player, from authentication to state synchronization inside a room.
1. Authentication
What happens:
- The client presents credentials (username/password, social login, and so on)
- The IdP validates them and issues a JWT with the player's claims (id, username, email, and so on)
- The client stores the JWT in memory or in secure storage
2. Room Discovery
What happens:
- The client sends a GET request with a Bearer JWT.
- Discovery validates the JWT against the IdP's JWKS.
- Discovery filters rooms by query parameters (game_mode, language, and so on).
- Discovery returns masked rooms (real addresses hidden, only IDs exposed).
3. Resolution and Join Ticket
What happens:
- The client chooses a room and sends a POST request.
- Discovery validates the JWT again and checks that the room exists.
- Discovery issues a signed join ticket with:
- Room ID
- Player ID (taken from the JWT)
- TTL (300 seconds)
- HMAC signature
- Discovery returns the room's real address and the ticket.
4. ECDH Handshake
What happens:
- The client connects over WebSocket and sends the join ticket and JWT.
- The room validates:
- The ticket's TTL
- The ticket's signature
- The player's JWT
- The room and the client exchange ECDH public keys.
- Both sides derive the shared secret independently and identically.
- A KDF (Key Derivation Function) produces the session key from the shared secret.
- The handshake is verified with a cryptographic challenge.
- Handshake complete: the session is established.
5. Reactive State Sync
What happens:
- The client receives state in three dictionaries:
$.server: global state$.me: player data$.others: opponent data
- Every root-level attribute has
_idandttl_ms. - The client processes only changes (differences in
_id). - The client reprocesses an attribute when its
ttl_msexpires.
6. Input Loop
What happens:
- The client sends inputs (movement, actions), encrypted.
- The room validates and applies the inputs.
- The room simulates the state and produces updates.
- The room sends updates with updated
_idandttl_ms. - The client receives them, checks
_id, and reprocesses only what changed. - The loop continues until the match ends.
7. Admin Intervention (Optional)
What happens:
- The admin sends operations (kick, pause, inject events).
- The room validates the admin token (a JWT with
admin_scope). - The room executes the operation and notifies all affected clients.
Security Summary at Each Step
| Step | Protection |
|---|---|
| Authentication | JWT signed by the IdP |
| Discovery | JWT validated against JWKS |
| Resolution | Signed join ticket + TTL |
| Handshake | ECDH + challenge-response |
| State sync | AES-256-GCM / ChaCha20 |
| Admin | Admin token (JWT with scope) |
Each step ensures that only authorized players and administrators can join or control the room.
Continue to the detailed specifications: