Session Management handles the lifecycle of connections between the Dota2 client and the Game Coordinator (GC). This includes establishing sessions through the hello handshake, tracking connection status, managing context lifecycles, and synchronizing state changes.
The session lifecycle progresses through distinct states managed by the Dota2 client. A session begins when the client sends a hello message to the GC and transitions through various connection states until a session is established or lost.
Sources: client_session.go26-38 client_session.go58-79 state/state.go22-29
The Dota2 struct maintains session state through several key fields:
| Field | Type | Purpose |
|---|---|---|
connectionCtx | context.Context | Active session context, nil when no session client_session.go45 |
connectionCtxCancel | context.CancelFunc | Cancels the session context client_session.go120-121 |
connectionCtxMtx | sync.Mutex | Protects connection context fields client_session.go42-43 |
state | state.Dota2State | Current connection status and game state state/state.go8-19 |
The connection context is created when GCConnectionStatus_GCConnectionStatus_HAVE_SESSION is achieved and cancelled whenever the connection status changes away from that state client_session.go120-128
Sources: client_session.go41-56 client_session.go98-131 state/state.go8-19
The Dota2State struct tracks the status of the connection to the GC using the GCConnectionStatus enum state/state.go10
| Status | Value | Description |
|---|---|---|
GCConnectionStatus_HAVE_SESSION | 0 | Active session established client_session.go125 |
GCConnectionStatus_GC_GOING_DOWN | 1 | GC is shutting down |
GCConnectionStatus_NO_SESSION | 2 | No active session state/state.go23 |
GCConnectionStatus_NO_SESSION_IN_LOGON_QUEUE | 3 | Waiting in login queue |
Sources: state/state.go8-24 client_session.go125-127
The SetPlaying method informs Steam whether the client is playing Dota 2 client_session.go14-24 This affects the user's Steam presence and is separate from session establishment.
When SetPlaying(false) is called, it not only clears the playing status but also resets the entire Dota2 state through ClearState(), removing all cached lobbies, parties, and other game objects client_session.go19-22
Sources: client_session.go13-24 state/state.go21-24
The SayHello method initiates session establishment by sending a CMsgClientHello message to the Game Coordinator client_session.go27-38
The method accepts optional CMsgSOCacheHaveVersion parameters that inform the GC about cached object versions, allowing for efficient cache synchronization client_session.go27
Sources: client_session.go26-38 client_session.go58-79
The hello message contains client information and capabilities:
| Field | Type | Default | Purpose |
|---|---|---|---|
SocacheHaveVersions | []*CMsgSOCacheHaveVersion | - | Cached object versions client_session.go36 |
ClientSessionNeed | uint32 | 104 | Required session capabilities client_session.go31 |
ClientLauncher | PartnerAccountType | PARTNER_NONE | Account partner type client_session.go29 |
Engine | ESourceEngine | k_ESE_Source2 | Game engine version client_session.go30 |
Sources: client_session.go27-37
When the GC responds with CMsgClientWelcome, the client processes the welcome message and establishes the session client_session.go59-79
The distinction between UptodateSubscribedCaches and OutofdateSubscribedCaches determines whether a cache refresh is needed or if the existing cache data can be used client_session.go66-74
Sources: client_session.go58-79
The handleConnectionStatus method processes CMsgConnectionStatus messages that update the current connection state client_session.go82-94
Every connection status change clears the game state via ns.ClearState(), as lobbies, parties, and other cached objects are session-specific client_session.go117
Sources: client_session.go81-131 state/state.go21-24
Before accepting requests, the client validates that an active session context exists using validateConnectionContext client_session.go41-56
This method ensures operations only proceed when a valid session exists. If the session context is nil or has been cancelled, it returns ErrNotReady client_session.go47-52
Sources: client_session.go40-56
The Dota2State struct provides a snapshot of the client's current session and object state state/state.go8-19
| Field | Type | Description |
|---|---|---|
ConnectionStatus | GCConnectionStatus | Current GC connection status state/state.go10 |
Lobby | *CSODOTALobby | Current lobby object state/state.go12 |
Party | *CSODOTAParty | Current party object state/state.go14 |
PartyInvite | *CSODOTAPartyInvite | Active incoming party invite state/state.go16 |
LastConnectionStatusUpdate | *CMsgConnectionStatus | Last status update message state/state.go18 |
The IsReady() helper checks if the client currently has an active session state/state.go26-29
Sources: state/state.go7-30
Session establishment triggers SOCache subscription synchronization:
RequestCacheSubscriptionRefresh() requests version checks for caches the client already has client_session.go67d.cache.HandleSubscribed() processes full cache updates for stale data client_session.go71handleCacheSubscribed client_cache.go17This ensures the client's cached game objects (lobbies, parties) are synchronized with the GC's authoritative state after session establishment. The mapping of shared object types to their concrete protobuf messages is handled by NewSharedObject cso/cso_types.go94-101
Sources: client_session.go65-74 client_cache.go9-28 cso/cso_types.go57-91
Session management employs mutexes to ensure thread-safe operations:
| Mutex | Protects | Scope |
|---|---|---|
connectionCtxMtx | connectionCtx, connectionCtxCancel | Connection context lifecycle client_session.go42-43 |
stateMtx | state | Client state updates (via accessState) client_session.go102 |
The setConnectionStatus method uses accessState to atomically update the Dota2State and manage the lifecycle of the connectionCtx client_session.go102-130 This ensures that state transitions (like moving from NO_SESSION to HAVE_SESSION) are performed safely and result in consistent internal state.
Refresh this wiki