The Client API is the primary interface for interacting with the Dota 2 Game Coordinator (GC) through the Dota2 client struct. The API consists of over 170 auto-generated methods in client_generated.go plus core client functionality for session management, state tracking, and event handling.
The Client API provides two main categories of functionality:
Auto-generated from Protocol Buffer definitions, these methods handle specific Dota 2 operations:
| Category | Examples | Pattern |
|---|---|---|
| Lobby Management | AbandonLobby(), DestroyLobby(), FlipLobbyTeams() | Fire-and-forget |
| Player Data | GetEventPoints(), GetAllHeroProgress(), GetBattleReport() | Request-response |
| Guild Operations | CreateGuild(), CancelInviteToGuild() | Request-response |
| Party Management | CancelPartyInvites(), AckPartyReadyCheck() | Fire-and-forget |
| Item/Inventory | ApplyGemCombiner(), CreatePlayerCardPack() | Mixed patterns |
Foundation methods in client.go and client_session.go:
SetPlaying(), SayHello(), connection tracking client_session.go14-38write(), MakeRequest(), HandleGCPacket() client.go115-118 client.go156-177accessState(), connection context handling client.go126-142 client_session.go41-56events/generated.go client.go185-196Sources: client_generated.go1-300 client.go31-66 client_session.go13-38
Detailed documentation is split across child pages:
| Child Page | Coverage |
|---|---|
| Core Client Methods | New, GetCache, Close, SetPlaying, SayHello, HandleGCPacket, accessState, connection state machine |
| Generated API Methods | How write() and MakeRequest() calls are generated; discovering available methods |
| Lobby Management | Hand-written lobby methods; SOCache-driven lobby state flow |
| Party Management | Party state via SOCache; invite and ready-check flow |
| Session Management | Connection status, hello handshake, and state synchronization |
Dota2 Client Entity Map
| Field | Type | Purpose |
|---|---|---|
client | *steam.Client | Underlying Steam connection client.go34 |
cache | *socache.SOCache | Shared object cache management client.go35 |
state | state.Dota2State | Current connection and session state client.go42 |
handlers | handlerMap | Message type to handler function mapping client.go44 |
pendReq | Request tracking map | Tracks pending request-response pairs client.go48 |
connectionCtx | context.Context | Session lifecycle management client.go38 |
Sources: client.go32-49 client_generated.go1-50 client_session.go1-25
The Dota2 struct provided by the package contains several key components:
Dota2 Class Relationships
The client maintains a connectionCtx that ensures all operations are performed within a valid session client_session.go41-56 This context is created when a connection is established and canceled when the connection is lost client_session.go119-128
Sources: client.go31-66 client_session.go40-56
buildHandlerMap — static handler wiring in client.go client.go83-113
Handler Mapping Flow
The Dota2 client implements three distinct communication patterns:
write() method for simple actions client.go115-118MakeRequest() with context and response tracking client_generated.go65-71HandleGCPacket() with registered message handlers client.go156-177Sources: client.go115-118 client_generated.go50-72 client.go82-113
The client_generated.go file contains over 170 auto-generated methods following two distinct patterns based on message type analysis.
Methods that send a message without expecting a specific response. Generated for messages with no corresponding response message.
| Method Signature | Message ID | Protocol Type |
|---|---|---|
AbandonLobby() | k_EMsgGCAbandonCurrentGame | CMsgAbandonCurrentGame |
FlipLobbyTeams() | k_EMsgGCFlipLobbyTeams | CMsgFlipLobbyTeams |
CancelWatchGame() | k_EMsgGCCancelWatchGame | CMsgCancelWatchGame |
KickLobbyMember(accountID uint32) | k_EMsgGCPracticeLobbyKick | CMsgPracticeLobbyKick |
Each such method constructs a typed request protobuf and calls write() with the corresponding EDOTAGCMsg integer. The complete pattern is visible at client_generated.go14-17 (AbandonLobby).
Methods that send a request and wait for a specific response, identified by matching request/response message pairs.
| Method Signature | Request ID | Response ID |
|---|---|---|
AutographReward(ctx, badgeID) | k_EMsgGameAutographReward | k_EMsgGameAutographRewardResponse |
ApplyModerationShowcaseModeration(ctx, ...) | k_EMsgClientToGCShowcaseModerationApplyModeration | k_EMsgClientToGCShowcaseModerationApplyModerationResponse |
ClaimBingoRow(ctx, ...) | k_EMsgClientToGCBingoClaimRow | k_EMsgClientToGCBingoClaimRowResponse |
Each such method accepts a context.Context as first argument, builds the request protobuf, allocates the response struct, and delegates to MakeRequest() client_generated.go65-71
Sources: client_generated.go10-16 client_generated.go50-72
The client_session.go file implements the connection lifecycle through specific methods that manage GC session state.
| Method | Purpose | Location |
|---|---|---|
SetPlaying(playing bool) | Enable/disable Dota 2 game state | client_session.go14-24 |
SayHello(haveCacheVersions...) | Initiate GC session handshake | client_session.go27-38 |
handleClientWelcome(packet) | Process GC welcome response | client_session.go59-79 |
setConnectionStatus(status, update) | Update connection state + emit events | client_session.go98-131 |
validateConnectionContext() | Check if session is ready for API calls | client_session.go41-56 |
Sources: client_session.go14-38 client_session.go58-131 client.go25-27
The events/generated.go file contains auto-generated event types that implement the Event interface.
Events are emitted through the getEventEmitter() function client.go186-196 which:
unmarshalBody() client.go145-153emit() client.go121-123Event type hierarchy in events/generated.go
Event Type Structure
Sources: client.go98-112 client.go185-196
The Client API follows these guarantees:
context.Context for cancellation client_generated.go51ClientStateChanged events client.go136-139ErrNotReady if the session is not established client.go25-27Sources: client.go25-27 client_generated.go50-72 client_session.go41-56
Refresh this wiki