Skip to main content

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.

info

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:

StateDescription
OfflineInitial state before connecting to the server.
RecoveringInitial connection or session recovery after a network failure.
ActiveThe client is connected to the server and the session is ready.
BannedThe 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;
});
warning

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: