Steamworks Documentation
ISteamGameServer Interface
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 );
NameTypeDescription
steamIDClanCSteamIDThe 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 );
NameTypeDescription
pAuthTicketconst void *The auth ticket to validate.
cbAuthTicketintThe size in bytes of the auth ticket. This must be the pcbTicket size provided by the call that created this ticket.
steamIDCSteamIDThe 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: EBeginAuthSessionResult


See Also: User Authentication and Ownership

BLoggedOn

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_t

BUpdateUserData

bool BUpdateUserData( CSteamID steamIDUser, const char *pchPlayerName, uint32 uScore );
NameTypeDescription
steamIDUserCSteamIDThe Steam ID of the user.
pchPlayerNameconst char *The name of the user.
uScoreuint32The 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 Ownership

CancelAuthTicket

void CancelAuthTicket( HAuthTicket hAuthTicket );
NameTypeDescription
hAuthTicketHAuthTicketThe 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 Ownership

ClearAllKeyValues

void ClearAllKeyValues();
Clears the whole list of key/values that are sent in rules queries.

See Also: SetKeyValue, ISteamMatchmakingServers::ServerRules

ComputeNewPlayerCompatibility

SteamAPICall_t ComputeNewPlayerCompatibility( CSteamID steamIDNewPlayer );
NameTypeDescription
steamIDNewPlayerCSteamIDThe 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: CSteamID
Returns 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 );
NameTypeDescription
bActiveboolEnable (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, ForceHeartbeat

EndAuthSession

void EndAuthSession( CSteamID steamID );
NameTypeDescription
steamIDCSteamIDThe 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 Ownership

ForceHeartbeat

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, SetHeartbeatInterval

GetAuthSessionTicket

HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket );
NameTypeDescription
pTicketvoid *The buffer where the new auth ticket will be copied into if the call was successful.
cbMaxTicketintThe size of the buffer allocated for pTicket. This should be 1024.
pcbTicketuint32 *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: HAuthTicket
Triggers 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 Ownership

GetGameplayStats

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 );
NameTypeDescription
pOutvoid *Returns the packet that needs to be sent by copying it into this buffer. The packet may be up to 16KiB so allocate accordingly.
cbMaxOutintThe size of the buffer provided to pOut, should be 16 * 1024.
pNetAdruint32 *Returns the The IP address that this packet needs to be sent to in host order, i.e 127.0.0.1 == 0x7f000001.
pPortuint16 *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: uint32
The 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: CSteamID

HandleIncomingPacket

bool HandleIncomingPacket( const void *pData, int cbData, uint32 srcIP, uint16 srcPort );
NameTypeDescription
pDataconst void *The data from the incoming packet.
cbDataintThe size of pData in bytes.
srcIPuint32The IP address that this packet was sent to in host order, i.e 127.0.0.1 == 0x7f000001.
srcPortuint16The 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 );
NameTypeDescription
unIPuint32The 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.
usGamePortuint16The port that clients will connect to for gameplay.
usQueryPortuint16The port that will manage server browser related duties and info pings from clients.
unFlagsuint32A union of one or more ServerFlags.
nGameAppIdAppId_tThe app id of the game this server is for.
pchVersionStringconst 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 );
NameTypeDescription
pszTokenconst 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: LogOnAnonymous

LogOnAnonymous

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: LogOn

RequestUserGroupStatus

bool RequestUserGroupStatus( CSteamID steamIDUser, CSteamID steamIDGroup );
NameTypeDescription
steamIDUserCSteamIDThe user to check the group status of.
steamIDGroupCSteamIDThe 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 );
NameTypeDescription
unIPClientuint32The IP address of the connecting client. This should be in host order, i.e 127.0.0.1 == 0x7f000001.
pvAuthBlobconst void *The authentication data provided by the user from a call to ISteamUser::InitiateGameConnection.
cubAuthBlobSizeuint32The size of pvAuthBlob in bytes.
pSteamIDUserCSteamID *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 );
NameTypeDescription
steamIDUserCSteamIDThe 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 );
NameTypeDescription
cBotplayersintThe 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 );
NameTypeDescription
bDedicatedboolIs 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 );
NameTypeDescription
pchGameDataconst 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 );
NameTypeDescription
pszGameDescriptionconst 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 );
NameTypeDescription
pchGameTagsconst 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 );
NameTypeDescription
iHeartbeatIntervalintThe 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, ForceHeartbeat

SetKeyValue

void SetKeyValue( const char *pKey, const char *pValue );
NameTypeDescription
pKeyconst char *
pValueconst char *

Add/update a rules key/value pair.

See Also: ClearAllKeyValues, ISteamMatchmakingServers::ServerRules

SetMapName

void SetMapName( const char *pszMapName );
NameTypeDescription
pszMapNameconst 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 );
NameTypeDescription
cPlayersMaxintThe 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 );
NameTypeDescription
pszModDirconst 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 );
NameTypeDescription
bPasswordProtectedboolEnable (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 );
NameTypeDescription
pszProductconst 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 );
NameTypeDescription
pszRegionconst 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 );
NameTypeDescription
pszServerNameconst 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 );
NameTypeDescription
unSpectatorPortuint16The 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 );
NameTypeDescription
pszSpectatorServerNameconst 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 );
NameTypeDescription
steamIDCSteamIDThe Steam ID of the user that sent the auth ticket.
appIDAppId_tThe 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: EUserHasLicenseForAppResult


See Also: User Authentication and Ownership

WasRestartRequested

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.

NameTypeDescription
m_eResultEResultThe result of the operation. Possible values:

Associated Functions: AssociateWithClan

ComputeNewPlayerCompatibilityResult_t

Sent when the game server is checking if the new player is a good fit for the server based on the frenemy system.

NameTypeDescription
m_eResultEResultThe result of the operation. Possible values:
m_cPlayersThatDontLikeCandidateintThe number of current players that don't like playing with the specified player.
m_cPlayersThatCandidateDoesntLikeintThe number of players on the server that the specified player doesn't like playing with.
m_cClanPlayersThatDontLikeCandidateintThe number of players in the associated Steam group that don't like playing with the player.
m_SteamIDCandidateCSteamIDThe Steam ID of the specified player.

Associated Functions: ComputeNewPlayerCompatibility

GSClientAchievementStatus_t

Deprecated - Use ISteamGameServerStats instead.

NameTypeDescription
m_SteamIDuint64Deprecated
m_pchAchievementchar[128]Deprecated
m_bUnlockedboolDeprecated

GSClientApprove_t

A client has been approved to connect to this game server.

NameTypeDescription
m_SteamIDCSteamIDThe Steam ID of the user that is wanting to connect.
m_OwnerSteamIDCSteamIDThe 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.

NameTypeDescription
m_SteamIDCSteamIDThe Steam ID of the user that attempted to connect.
m_eDenyReasonEDenyReasonThe reason the player was denied.
m_rgchOptionalTextchar[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.

NameTypeDescription
m_SteamIDUserCSteamIDThe user whose group status we queried.
m_SteamIDGroupCSteamIDThe group that we queried.
m_bMemberboolIs the user a member of the group (true) or not (false)?
m_bOfficerboolIs the user an officer in the group (true) or not (false)? This will never be true if m_bMember is false.

Associated Functions: RequestUserGroupStatus

GSClientKick_t

Called when the game server should kick the user.

NameTypeDescription
m_SteamIDCSteamIDThe Steam ID of the player that should be kicked.
m_eDenyReasonEDenyReasonThe reason the player is being kicked.

GSGameplayStats_t

Deprecated - Called when gameplay stats info has been queried using GetGameplayStats.

NameTypeDescription
m_eResultEResultThe result of the operation.
m_nRankint32The overall rank of the server (0-based).
m_unTotalConnectsuint32Total number of clients who have ever connected to the server.
m_unTotalMinutesPlayeduint32Total number of minutes ever played on the server.

Associated Functions: GetGameplayStats

GSPolicyResponse_t

Received when the game server requests to be displayed as secure (VAC protected)

NameTypeDescription
m_bSecureuint8Is 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.

NameTypeDescription
m_eResultEResultThe result of the operation.
m_unReputationScoreuint32The reputation score for the game server.
m_bBannedboolIs the server is banned from the Steam master servers (true) or not (false)?
m_unBannedIPuint32The IP of the banned server. Only set if m_bBanned is true.
m_usBannedPortuint16The port of the banned server. Only set if m_bBanned is true.
m_ulBannedGameIDuint64The game ID the banned server is serving. Only set if m_bBanned is true.
m_unBanExpiresuint32The time when the ban expires, provided in Unix epoch format (seconds since Jan 1st 1970). Only set if m_bBanned is true.

Associated Functions: GetServerReputation

Constants

These are constants which are defined for use with ISteamGameServer.

NameTypeValueDescription
k_unServerFlagActiveuint320x01The game server has users playing.
k_unServerFlagDedicateduint320x04This game server is dedicated.
k_unServerFlagLinuxuint320x08This game server is running on linux.
k_unServerFlagNoneuint320x00This game server has no flags.
k_unServerFlagPasswordeduint320x10This game server is password protected.
k_unServerFlagPrivateuint320x20This 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_unServerFlagSecureuint320x02This game server wants to be VAC secure.
MASTERSERVERUPDATERPORT_USEGAMESOCKETSHAREint((uint16)-1)Used with SteamGameServer_Init to enable GameSocketShare mode.
STEAMGAMESERVER_INTERFACE_VERSIONconst char *"SteamGameServer012"