Session Lifecycle & States
In the PlayServ Client SDK, there is no explicit "server connection" or "disconnect" surface in the application API. The primary concept is a Session. The goal is that multiplayer code can be written in a way that feels closer to singleplayer logic, driven by session state and events.
Use session state to control when your game can:
- start gameplay logic safely
- react to network loss and recovery
- handle a forced server-side shutdown where reconnecting is not useful
Session states
Session state is available via PlayServ.Session.State. There are four reachable states:
| State | Description |
|---|---|
Offline | Initial state before connecting to the server. |
Recovering | Initial connection or session recovery after a network failure. |
Active | The client is connected to the server and the session is ready. |
Banned | The client was disconnected by the server forcibly. Reconnecting is not useful. |
Subscribing to session state
Subscribe to all state updates
PlayServ.Session
.Wait<Update>(event => {
// event = { State, Details }
// State = Active, Recovering, Offline, Banned
});
Subscribe to a specific state
PlayServ.Session.Wait<Active>(() => {
// Session is now Active
});
PlayServ.Session.Wait<Banned>((event) => {
event.Details;
});
On a forced disconnect, the event delivers the reasons and rules for further actions in event.Details.
Unauthenticated access
An unauthenticated session is the initial session state with the lowest privileges. All users who launch the game start in this mode. It allows access to public information inside the game. For anything beyond that, authentication is required.
See User Login & Authentication.
Next step
Continue with User Login & Authentication to understand how privileges increase inside a session.
For related topics:
- Proxy Module & Handshake — how the client enters the session flow and reaches readiness
- Data Subscriptions & Live Updates — subscriptions are expected to be restored after recovery when returning to
Active