Provides the core of the Steam Game Servers API.
Member Functions
Member functions for
ISteamGameServer
are called through the global accessor function
SteamGameServer()
.
AssociateWithClan
SteamAPICall_t AssociateWithClan( CSteamID steamIDClan );
Name | Type | Description |
steamIDClan | CSteamID | The Steam ID of the group you want to be associated with. |
associate this game server with this clan for the purposes of computing player compatibility.
Returns: SteamAPICall_t to be used with a
AssociateWithClanResult_t call result.
BeginAuthSession
EBeginAuthSessionResult BeginAuthSession( const void *pAuthTicket, int cbAuthTicket, CSteamID steamID );
Name | Type | Description |
pAuthTicket | const void * | The auth ticket to validate. |
cbAuthTicket | int | The size in bytes of the auth ticket. This must be the pcbTicket size provided by the call that created this ticket. |
steamID | CSteamID | The entity's Steam ID that sent this ticket. |
Authenticate the ticket from the entity Steam ID to be sure it is valid and isn't reused. Note that identity is not confirmed until the callback
ValidateAuthTicketResponse_t is received and the return value in that callback is checked for success.
The ticket is created on the entity with
ISteamUser::GetAuthSessionTicket or
GetAuthSessionTicket and then needs to be provided over the network for the other end to validate.
This registers for
ValidateAuthTicketResponse_t callbacks if the entity goes offline or cancels the ticket. See
EAuthSessionResponse for more information.
When the multiplayer session terminates you must call
EndAuthSession.
Returns: EBeginAuthSessionResultSee Also: User Authentication and OwnershipBLoggedOn
bool BLoggedOn();
Checks if the game server is logged on.
Returns: bool
true if the game server is logged on; otherwise,
false.
BSecure
bool BSecure();
Checks whether the game server is in "Secure" mode.
Returns: bool
true if the game server secure; otherwise,
false.
See Also: EServerMode,
GSPolicyResponse_tBUpdateUserData
bool BUpdateUserData( CSteamID steamIDUser, const char *pchPlayerName, uint32 uScore );
Name | Type | Description |
steamIDUser | CSteamID | The Steam ID of the user. |
pchPlayerName | const char * | The name of the user. |
uScore | uint32 | The current score of the user. |
Update the data to be displayed in the server browser and matchmaking interfaces for a user currently connected to the server.
NOTE: This is part of the old user authentication API and should not be mixed with the new API.
Returns: bool
true if the call was successful; otherwise
false if there was a failure (ie,
steamIDUser
is not a player on the current server.)
See Also: User Authentication and OwnershipCancelAuthTicket
void CancelAuthTicket( HAuthTicket hAuthTicket );
Name | Type | Description |
hAuthTicket | HAuthTicket | The active auth ticket to cancel. |
Cancels an auth ticket received from
ISteamUser::GetAuthSessionTicket. This should be called when no longer playing with the specified entity.
See Also: User Authentication and OwnershipClearAllKeyValues
void ClearAllKeyValues();
Clears the whole list of key/values that are sent in rules queries.
See Also: SetKeyValue,
ISteamMatchmakingServers::ServerRulesComputeNewPlayerCompatibility
SteamAPICall_t ComputeNewPlayerCompatibility( CSteamID steamIDNewPlayer );
Name | Type | Description |
steamIDNewPlayer | CSteamID | The Steam ID of the player that is attempting to join. |
Checks if any of the current players don't want to play with this new player that is attempting to join - or vice versa; based on the frenemy system.
Returns: SteamAPICall_t to be used with a
ComputeNewPlayerCompatibilityResult_t call result.
CreateUnauthenticatedUserConnection
CSteamID CreateUnauthenticatedUserConnection();
Creates a fake user (ie, a bot) which will be listed as playing on the server, but skips validation.
NOTE: This is part of the old user authentication API and should not be mixed with the new API.
Returns: CSteamIDReturns the Steam ID for the bot to be tracked with.
You should call
SendUserDisconnect when this user leaves the server just like you would for a real user.
EnableHeartbeats
void EnableHeartbeats( bool bActive );
Name | Type | Description |
bActive | bool | Enable (true) or disable (false) the master server updater. |
Tells the Steam master servers whether or not you want to be active.
If this is enabled then the server will talk to the master servers, if it's not then incoming messages are ignored and heartbeats will not be sent.
See Also: SetHeartbeatInterval,
ForceHeartbeatEndAuthSession
void EndAuthSession( CSteamID steamID );
Name | Type | Description |
steamID | CSteamID | The entity to end the active auth session with. |
Ends an auth session that was started with
BeginAuthSession. This should be called when no longer playing with the specified entity.
See Also: User Authentication and OwnershipForceHeartbeat
void ForceHeartbeat();
Force a heartbeat to the Steam master servers at the next opportunity.
You usually don't need to use this.
See Also: EnableHeartbeats,
SetHeartbeatIntervalGetAuthSessionTicket
HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket );
Name | Type | Description |
pTicket | void * | The buffer where the new auth ticket will be copied into if the call was successful. |
cbMaxTicket | int | The size of the buffer allocated for pTicket . This should be 1024. |
pcbTicket | uint32 * | Returns the length of the actual ticket. |
Retrieve a authentication ticket to be sent to the entity who wishes to authenticate you.
After calling this you can send the ticket to the entity where they can then call
ISteamUser::BeginAuthSession to verify this entities integrity.
When creating a ticket for use by the
ISteamUserAuth/AuthenticateUserTicket Web API, the calling application should wait for the
GetAuthSessionTicketResponse_t callback generated by the API call before attempting to use the ticket to ensure that the ticket has been communicated to the server. If this callback does not come in a timely fashion (10 - 20 seconds), then your client is not connected to Steam, and the AuthenticateUserTicket call will fail because it can not authenticate the user.
Returns: HAuthTicketTriggers a
GetAuthSessionTicketResponse_t callback.
A handle to the auth ticket. When you're done interacting with the entity you must call
CancelAuthTicket on the handle.
Returns
k_HAuthTicketInvalid if the call fails.
See Also: User Authentication and OwnershipGetGameplayStats
void GetGameplayStats();
Deprecated - Will be removed in a future release of the SDK.
Returns: void
Triggers a
GSGameplayStats_t callback.
GetNextOutgoingPacket
int GetNextOutgoingPacket( void *pOut, int cbMaxOut, uint32 *pNetAdr, uint16 *pPort );
Name | Type | Description |
pOut | void * | Returns the packet that needs to be sent by copying it into this buffer. The packet may be up to 16KiB so allocate accordingly. |
cbMaxOut | int | The size of the buffer provided to pOut , should be 16 * 1024. |
pNetAdr | uint32 * | Returns the The IP address that this packet needs to be sent to in host order, i.e 127.0.0.1 == 0x7f000001. |
pPort | uint16 * | Returns the port that this packet needs to be sent through, in host order. |
Gets a packet that the master server updater needs to send out on UDP when in GameSocketShare mode.
NOTE: This should only ever be called AFTER calling
HandleIncomingPacket for any packets that came in that frame!
NOTE: This MUST be called repeatedly each frame until it returns 0 when in GameSocketShare mode.
GameSocketShare mode can be enabled when calling
SteamGameServer_Init.
Returns: int
The length of the packet that needs to be to sent, or 0 if there are no more packets to send this frame.
GetPublicIP
uint32 GetPublicIP();
Gets the public IP of the server according to Steam.
This is useful when the server is behind NAT and you want to advertise its IP in a lobby for other clients to directly connect to.
Returns: uint32The public IP in host order, i.e 127.0.0.1 == 0x7f000001.
Returns
0 if the IP could not be determined.
GetServerReputation
SteamAPICall_t GetServerReputation();
Deprecated - Will be removed in a future release of the SDK.
Returns: SteamAPICall_t to be used with a
GSReputation_t call result.
GetSteamID
CSteamID GetSteamID();
Gets the Steam ID of the game server.
Returns: CSteamIDHandleIncomingPacket
bool HandleIncomingPacket( const void *pData, int cbData, uint32 srcIP, uint16 srcPort );
Name | Type | Description |
pData | const void * | The data from the incoming packet. |
cbData | int | The size of pData in bytes. |
srcIP | uint32 | The IP address that this packet was sent to in host order, i.e 127.0.0.1 == 0x7f000001. |
srcPort | uint16 | The port that this packet was sent through, in host order. |
Handles a Steam master server packet when in GameSocketShare mode.
When in GameSocketShare mode, instead of ISteamGameServer creating its own socket to talk to the master server on, it lets the game use its socket to forward messages
back and forth. This prevents us from requiring server ops to open up yet another port in their firewalls.
This should be called whenever a packet that starts with 0xFFFFFFFF comes in. That means it's for us.
The IP and port parameters are used when you've elected to multiplex the game server's UDP socket rather than having the master server updater use its own sockets.
Source engine games use this to simplify the job of the server admins, so they don't have to open up more ports on their firewalls.
Only
AFTER calling this, you should call
GetNextOutgoingPacket.
GameSocketShare mode can be enabled when calling
SteamGameServer_Init.
Returns: bool
InitGameServer
bool InitGameServer( uint32 unIP, uint16 usGamePort, uint16 usQueryPort, uint32 unFlags, AppId_t nGameAppId, const char *pchVersionString );
Name | Type | Description |
unIP | uint32 | The IP address you are going to bind to. (This should be in host order, i.e 127.0.0.1 == 0x7f000001). You can use INADDR_ANY to bind to all local IPv4 addresses. |
usGamePort | uint16 | The port that clients will connect to for gameplay. |
usQueryPort | uint16 | The port that will manage server browser related duties and info pings from clients. |
unFlags | uint32 | A union of one or more ServerFlags. |
nGameAppId | AppId_t | The app id of the game this server is for. |
pchVersionString | const char * | The version string is usually in the form x.x.x.x, and is used by the master server to detect when the server is out of date. (Only servers with the latest version will be listed.) |
Initializes the instance of ISteamGameServer. This is called by
SteamGameServer_Init, and you will usually not need to call it directly.
If you pass
MASTERSERVERUPDATERPORT_USEGAMESOCKETSHARE into
usQueryPort
, then it causes the game server API to use "GameSocketShare" mode, which means that the game is responsible for sending and receiving UDP packets for the master server updater.
If GameSocketShare mode is used then you must use
HandleIncomingPacket and
GetNextOutgoingPacket to interact with the Steam Master Server.
Returns: bool
true if the game server was successfully able to bind to the provided IP/Port; otherwise,
false indicating failure.
LogOff
void LogOff();
Begin process of logging the game server out of steam.
Returns: void
Triggers a
SteamServerConnectFailure_t callback.
Triggers a
SteamServersConnected_t callback.
Triggers a
SteamServersDisconnected_t callback.
LogOn
void LogOn( const char *pszToken );
Name | Type | Description |
pszToken | const char * | |
Begin process to login to a persistent game server account.
Returns: void
Triggers a
SteamServerConnectFailure_t callback.
Triggers a
SteamServersConnected_t callback.
Triggers a
SteamServersDisconnected_t callback.
See Also: LogOnAnonymousLogOnAnonymous
void LogOnAnonymous();
Login to a generic, anonymous account.
Returns: void
Triggers a
SteamServerConnectFailure_t callback.
Triggers a
SteamServersConnected_t callback.
Triggers a
SteamServersDisconnected_t callback.
See Also: LogOnRequestUserGroupStatus
bool RequestUserGroupStatus( CSteamID steamIDUser, CSteamID steamIDGroup );
Name | Type | Description |
steamIDUser | CSteamID | The user to check the group status of. |
steamIDGroup | CSteamID | The group to check. |
Checks if a user is in the specified Steam group.
Returns: bool
Triggers a
GSClientGroupStatus_t callback.
true if the call was successfully sent out to the Steam servers; otherwise,
false if we're not connected to the steam servers or an invalid user or group was provided.
SendUserConnectAndAuthenticate
bool SendUserConnectAndAuthenticate( uint32 unIPClient, const void *pvAuthBlob, uint32 cubAuthBlobSize, CSteamID *pSteamIDUser );
Name | Type | Description |
unIPClient | uint32 | The IP address of the connecting client. This should be in host order, i.e 127.0.0.1 == 0x7f000001. |
pvAuthBlob | const void * | The authentication data provided by the user from a call to ISteamUser::InitiateGameConnection. |
cubAuthBlobSize | uint32 | The size of pvAuthBlob in bytes. |
pSteamIDUser | CSteamID * | Returns the Steam ID of the user. This must not be NULL. |
Handles receiving a new connection from a Steam user. This will ask the Steam servers to validate the user's identity, app ownership, and VAC status.
If the Steam servers are off-line, then it will validate the cached ticket itself which will validate app ownership and identity.
NOTE: This is part of the old user authentication API and should not be mixed with the new API.
Returns: bool
true if the users ticket passes basic checks; otherwise,
false.
If this call is successful then you should expect a
GSClientApprove_t or
GSClientDeny_t callback which will tell you whether authentication for the user has succeeded or failed. The Steam ID in the callback will match the one returned by this call.
SendUserDisconnect
void SendUserDisconnect( CSteamID steamIDUser );
Name | Type | Description |
steamIDUser | CSteamID | The Steam ID of the user that has left the game server. |
This should be called whenever a user leaves the game server.
This lets Steam internally track which users are currently on which servers for the purposes of preventing a single account being logged into multiple servers and showing who is currently on the server, etc.
NOTE: This is part of the old user authentication API and should not be mixed with the new API.
SetBotPlayerCount
void SetBotPlayerCount( int cBotplayers );
Name | Type | Description |
cBotplayers | int | The number of bot/AI players currently playing on the server. |
Sets the number of bot/AI players on the game server. The default value is 0.
SetDedicatedServer
void SetDedicatedServer( bool bDedicated );
Name | Type | Description |
bDedicated | bool | Is this a dedicated server (true) or a listen server (false)? |
Sets the whether this is a dedicated server or a listen server. The default is listen server.
NOTE: This only be set before calling
LogOn or
LogOnAnonymous.
SetGameData
void SetGameData( const char *pchGameData );
Name | Type | Description |
pchGameData | const char * | The new "gamedata" value to set. Must not be NULL or an empty string (""). This can not be longer than k_cbMaxGameServerGameData. |
Sets a string defining the "gamedata" for this server, this is optional, but if set it allows users to filter in the matchmaking/server-browser interfaces based on the value.
This is usually formatted as a comma or semicolon separated list.
Don't set this unless it actually changes, its only uploaded to the master once; when acknowledged.
SetGameDescription
void SetGameDescription( const char *pszGameDescription );
Name | Type | Description |
pszGameDescription | const char * | The description of your game. Must not be NULL or an empty string (""). This can not be longer than k_cbMaxGameServerGameDescription. |
Sets the game description. Setting this to the full name of your game is recommended.
NOTE: This is required for all game servers and can only be set before calling
LogOn or
LogOnAnonymous.
SetGameTags
void SetGameTags( const char *pchGameTags );
Name | Type | Description |
pchGameTags | const char * | The new "gametags" value to set. Must not be NULL or an empty string (""). This can not be longer than k_cbMaxGameServerTags. |
Sets a string defining the "gametags" for this server, this is optional, but if set it allows users to filter in the matchmaking/server-browser interfaces based on the value.
This is usually formatted as a comma or semicolon separated list.
Don't set this unless it actually changes, its only uploaded to the master once; when acknowledged.
SetHeartbeatInterval
void SetHeartbeatInterval( int iHeartbeatInterval );
Name | Type | Description |
iHeartbeatInterval | int | The interval between sending heartbeats in milliseconds. Typically would range between 250-1000. Use -1 to use the default value. |
Changes how often heartbeats are sent to the Steam master servers.
You usually don't need to use this.
See Also: EnableHeartbeats,
ForceHeartbeatSetKeyValue
void SetKeyValue( const char *pKey, const char *pValue );
Name | Type | Description |
pKey | const char * | |
pValue | const char * | |
Add/update a rules key/value pair.
See Also: ClearAllKeyValues,
ISteamMatchmakingServers::ServerRulesSetMapName
void SetMapName( const char *pszMapName );
Name | Type | Description |
pszMapName | const char * | The new map name to set. Must not be NULL or an empty string (""). This can not be longer than k_cbMaxGameServerMapName. |
Sets the name of map to report in the server browser.
SetMaxPlayerCount
void SetMaxPlayerCount( int cPlayersMax );
Name | Type | Description |
cPlayersMax | int | The new maximum number of players allowed on this server. |
Sets the maximum number of players allowed on the server at once.
This value may be changed at any time.
SetModDir
void SetModDir( const char *pszModDir );
Name | Type | Description |
pszModDir | const char * | The game directory to set. Must not be NULL or an empty string (""). This can not be longer than k_cbMaxGameServerGameDir. |
Sets the game directory.
This should be the same directory game where gets installed into. Just the folder name, not the whole path. e.g. "Spacewar".
NOTE: This is required for all game servers and can only be set before calling
LogOn or
LogOnAnonymous.
SetPasswordProtected
void SetPasswordProtected( bool bPasswordProtected );
Name | Type | Description |
bPasswordProtected | bool | Enable (true) or disable (false) password protection. |
Set whether the game server will require a password once when the user tries to join.
SetProduct
void SetProduct( const char *pszProduct );
Name | Type | Description |
pszProduct | const char * | The unique identifier for your game. Must not be NULL or an empty string (""). |
Sets the game product identifier. This is currently used by the master server for version checking purposes.
Converting the games app ID to a string for this is recommended.
NOTE: This is required for all game servers and can only be set before calling
LogOn or
LogOnAnonymous.
SetRegion
void SetRegion( const char *pszRegion );
Name | Type | Description |
pszRegion | const char * | |
Region identifier. This is an optional field, the default value is an empty string, meaning the "world" region.
SetServerName
void SetServerName( const char *pszServerName );
Name | Type | Description |
pszServerName | const char * | The new server name to set. Must not be NULL or an empty string (""). This can not be longer than k_cbMaxGameServerName. |
Sets the name of server as it will appear in the server browser.
SetSpectatorPort
void SetSpectatorPort( uint16 unSpectatorPort );
Name | Type | Description |
unSpectatorPort | uint16 | The port for spectators to join. |
Set whether the game server allows spectators, and what port they should connect on. The default value is 0, meaning the service is not used.
SetSpectatorServerName
void SetSpectatorServerName( const char *pszSpectatorServerName );
Name | Type | Description |
pszSpectatorServerName | const char * | The spectator server name to set. Must not be NULL or an empty string (""). This can not be longer than k_cbMaxGameServerMapName. |
Sets the name of the spectator server. This is only used if spectator port is nonzero.
UserHasLicenseForApp
EUserHasLicenseForAppResult UserHasLicenseForApp( CSteamID steamID, AppId_t appID );
Name | Type | Description |
steamID | CSteamID | The Steam ID of the user that sent the auth ticket. |
appID | AppId_t | The DLC App ID to check if the user owns it. |
Checks if the user owns a specific piece of
Downloadable Content (DLC).
This can only be called after sending the users auth ticket to
BeginAuthSession/
Returns: EUserHasLicenseForAppResultSee Also: User Authentication and OwnershipWasRestartRequested
bool WasRestartRequested();
Checks if the master server has alerted us that we are out of date.
This reverts back to
false after calling this function.
Returns: bool
true if the master server wants this game server to update and restart; otherwise,
false.
Callbacks
These are callbacks which can be fired by calling
SteamAPI_RunCallbacks. Many of these will be fired directly in response to the member functions of
ISteamGameServer
.
AssociateWithClanResult_t
Sent when the game server attempted to be associated with a Steam Group.
Name | Type | Description |
m_eResult | EResult | The result of the operation. Possible values:
|
Associated Functions: AssociateWithClanComputeNewPlayerCompatibilityResult_t
Sent when the game server is checking if the new player is a good fit for the server based on the frenemy system.
Name | Type | Description |
m_eResult | EResult | The result of the operation. Possible values:
|
m_cPlayersThatDontLikeCandidate | int | The number of current players that don't like playing with the specified player. |
m_cPlayersThatCandidateDoesntLike | int | The number of players on the server that the specified player doesn't like playing with. |
m_cClanPlayersThatDontLikeCandidate | int | The number of players in the associated Steam group that don't like playing with the player. |
m_SteamIDCandidate | CSteamID | The Steam ID of the specified player. |
Associated Functions: ComputeNewPlayerCompatibilityGSClientAchievementStatus_t
Deprecated - Use
ISteamGameServerStats instead.
Name | Type | Description |
m_SteamID | uint64 | Deprecated |
m_pchAchievement | char[128] | Deprecated |
m_bUnlocked | bool | Deprecated |
GSClientApprove_t
A client has been approved to connect to this game server.
Name | Type | Description |
m_SteamID | CSteamID | The Steam ID of the user that is wanting to connect. |
m_OwnerSteamID | CSteamID | The Steam ID that owns the game, this will be different from m_SteamID if the game is accessed via Steam Family Sharing. |
GSClientDeny_t
Called when a user has been denied to connection to this game server.
Name | Type | Description |
m_SteamID | CSteamID | The Steam ID of the user that attempted to connect. |
m_eDenyReason | EDenyReason | The reason the player was denied. |
m_rgchOptionalText | char[128] | An optional text message explaining the deny reason. Typically unused except for logging. |
GSClientGroupStatus_t
Called when we have received the group status of a user.
Name | Type | Description |
m_SteamIDUser | CSteamID | The user whose group status we queried. |
m_SteamIDGroup | CSteamID | The group that we queried. |
m_bMember | bool | Is the user a member of the group (true) or not (false)? |
m_bOfficer | bool | Is the user an officer in the group (true) or not (false)? This will never be true if m_bMember is false. |
Associated Functions: RequestUserGroupStatusGSClientKick_t
Called when the game server should kick the user.
Name | Type | Description |
m_SteamID | CSteamID | The Steam ID of the player that should be kicked. |
m_eDenyReason | EDenyReason | The reason the player is being kicked. |
GSGameplayStats_t
Deprecated - Called when gameplay stats info has been queried using
GetGameplayStats.
Name | Type | Description |
m_eResult | EResult | The result of the operation. |
m_nRank | int32 | The overall rank of the server (0-based). |
m_unTotalConnects | uint32 | Total number of clients who have ever connected to the server. |
m_unTotalMinutesPlayed | uint32 | Total number of minutes ever played on the server. |
Associated Functions: GetGameplayStatsGSPolicyResponse_t
Received when the game server requests to be displayed as secure (VAC protected)
Name | Type | Description |
m_bSecure | uint8 | Is the server now set to secure (true) or unsecure (false)?. |
GSReputation_t
Deprecated - Called when the game server reputation has been queried.
Master server bans are by IP so it is possible to be banned even when the score is good if there is a bad server on another port.
This information can be used to determine which server is bad.
Name | Type | Description |
m_eResult | EResult | The result of the operation. |
m_unReputationScore | uint32 | The reputation score for the game server. |
m_bBanned | bool | Is the server is banned from the Steam master servers (true) or not (false)? |
m_unBannedIP | uint32 | The IP of the banned server. Only set if m_bBanned is true. |
m_usBannedPort | uint16 | The port of the banned server. Only set if m_bBanned is true. |
m_ulBannedGameID | uint64 | The game ID the banned server is serving. Only set if m_bBanned is true. |
m_unBanExpires | uint32 | The time when the ban expires, provided in Unix epoch format (seconds since Jan 1st 1970). Only set if m_bBanned is true. |
Associated Functions: GetServerReputationConstants
These are constants which are defined for use with ISteamGameServer.
Name | Type | Value | Description |
k_unServerFlagActive | uint32 | 0x01 | The game server has users playing. |
k_unServerFlagDedicated | uint32 | 0x04 | This game server is dedicated. |
k_unServerFlagLinux | uint32 | 0x08 | This game server is running on linux. |
k_unServerFlagNone | uint32 | 0x00 | This game server has no flags. |
k_unServerFlagPassworded | uint32 | 0x10 | This game server is password protected. |
k_unServerFlagPrivate | uint32 | 0x20 | This game server shouldn't be listed on master server and won't enforce authentication of users that connect to the server. This is useful when you run a server where the clients may not be connected to the internet but you want them to allow them to play (i.e LANs). |
k_unServerFlagSecure | uint32 | 0x02 | This game server wants to be VAC secure. |
MASTERSERVERUPDATERPORT_USEGAMESOCKETSHARE | int | ((uint16)-1) | Used with SteamGameServer_Init to enable GameSocketShare mode. |
STEAMGAMESERVER_INTERFACE_VERSION | const char * | "SteamGameServer012" | |