A match has phases
A game session is not just play. It moves through clear phases, and each has its own rules for joining, timing, and failure handling. Modeling these phases as a state machine keeps the server logic clean.
The typical phases
- Lobby: players are assigned, the server boots, and clients download the map and connect.
- Warmup: the server waits for everyone to load, with a timeout so one slow client cannot stall the rest.
- Active: the authoritative simulation runs and scores accumulate.
- Post match: results are computed, ratings updated, and stats persisted.
- Teardown: connections close and the server process exits.
Handling drop outs
If a player disconnects during active play the session continues, often holding a slot for a brief reconnect window. The session only ends when win conditions are met or a timeout fires, never because one client left. Persisting results happens in post match, before teardown, so a crash during cleanup does not lose the outcome.
Key idea
A session is a state machine from lobby through active play to post match persistence and teardown, with timeouts and reconnect windows guarding each transition.