Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

387 lines
16 KiB

  1. //====== Copyright (c) 1996-2008, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: interface to steam for game servers
  4. //
  5. //=============================================================================
  6. #ifndef ISTEAMGAMESERVER_H
  7. #define ISTEAMGAMESERVER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "isteamclient.h"
  12. #define MASTERSERVERUPDATERPORT_USEGAMESOCKETSHARE ((uint16)-1)
  13. //-----------------------------------------------------------------------------
  14. // Purpose: Functions for authenticating users via Steam to play on a game server
  15. //-----------------------------------------------------------------------------
  16. class ISteamGameServer
  17. {
  18. public:
  19. //
  20. // Basic server data. These properties, if set, must be set before before calling LogOn. They
  21. // may not be changed after logged in.
  22. //
  23. /// This is called by SteamGameServer_Init, and you will usually not need to call it directly
  24. virtual bool InitGameServer( uint32 unIP, uint16 usGamePort, uint16 usQueryPort, uint32 unFlags, AppId_t nGameAppId, const char *pchVersionString ) = 0;
  25. /// Game product identifier. This is currently used by the master server for version checking purposes.
  26. /// It's a required field, but will eventually will go away, and the AppID will be used for this purpose.
  27. virtual void SetProduct( const char *pszProduct ) = 0;
  28. /// Description of the game. This is a required field and is displayed in the steam server browser....for now.
  29. /// This is a required field, but it will go away eventually, as the data should be determined from the AppID.
  30. virtual void SetGameDescription( const char *pszGameDescription ) = 0;
  31. /// If your game is a "mod," pass the string that identifies it. The default is an empty string, meaning
  32. /// this application is the original game, not a mod.
  33. ///
  34. /// @see k_cbMaxGameServerGameDir
  35. virtual void SetModDir( const char *pszModDir ) = 0;
  36. /// Is this is a dedicated server? The default value is false.
  37. virtual void SetDedicatedServer( bool bDedicated ) = 0;
  38. //
  39. // Login
  40. //
  41. /// Begin process to login to a persistent game server account
  42. ///
  43. /// You need to register for callbacks to determine the result of this operation.
  44. /// @see SteamServersConnected_t
  45. /// @see SteamServerConnectFailure_t
  46. /// @see SteamServersDisconnected_t
  47. virtual void LogOn( const char *pszToken ) = 0;
  48. /// Login to a generic, anonymous account.
  49. ///
  50. /// Note: in previous versions of the SDK, this was automatically called within SteamGameServer_Init,
  51. /// but this is no longer the case.
  52. virtual void LogOnAnonymous() = 0;
  53. /// Begin process of logging game server out of steam
  54. virtual void LogOff() = 0;
  55. // status functions
  56. virtual bool BLoggedOn() = 0;
  57. virtual bool BSecure() = 0;
  58. virtual CSteamID GetSteamID() = 0;
  59. /// Returns true if the master server has requested a restart.
  60. /// Only returns true once per request.
  61. virtual bool WasRestartRequested() = 0;
  62. //
  63. // Server state. These properties may be changed at any time.
  64. //
  65. /// Max player count that will be reported to server browser and client queries
  66. virtual void SetMaxPlayerCount( int cPlayersMax ) = 0;
  67. /// Number of bots. Default value is zero
  68. virtual void SetBotPlayerCount( int cBotplayers ) = 0;
  69. /// Set the name of server as it will appear in the server browser
  70. ///
  71. /// @see k_cbMaxGameServerName
  72. virtual void SetServerName( const char *pszServerName ) = 0;
  73. /// Set name of map to report in the server browser
  74. ///
  75. /// @see k_cbMaxGameServerName
  76. virtual void SetMapName( const char *pszMapName ) = 0;
  77. /// Let people know if your server will require a password
  78. virtual void SetPasswordProtected( bool bPasswordProtected ) = 0;
  79. /// Spectator server. The default value is zero, meaning the service
  80. /// is not used.
  81. virtual void SetSpectatorPort( uint16 unSpectatorPort ) = 0;
  82. /// Name of the spectator server. (Only used if spectator port is nonzero.)
  83. ///
  84. /// @see k_cbMaxGameServerMapName
  85. virtual void SetSpectatorServerName( const char *pszSpectatorServerName ) = 0;
  86. /// Call this to clear the whole list of key/values that are sent in rules queries.
  87. virtual void ClearAllKeyValues() = 0;
  88. /// Call this to add/update a key/value pair.
  89. virtual void SetKeyValue( const char *pKey, const char *pValue ) = 0;
  90. /// Sets a string defining the "gametags" for this server, this is optional, but if it is set
  91. /// it allows users to filter in the matchmaking/server-browser interfaces based on the value
  92. ///
  93. /// @see k_cbMaxGameServerTags
  94. virtual void SetGameTags( const char *pchGameTags ) = 0;
  95. /// Sets a string defining the "gamedata" for this server, this is optional, but if it is set
  96. /// it allows users to filter in the matchmaking/server-browser interfaces based on the value
  97. /// don't set this unless it actually changes, its only uploaded to the master once (when
  98. /// acknowledged)
  99. ///
  100. /// @see k_cbMaxGameServerGameData
  101. virtual void SetGameData( const char *pchGameData ) = 0;
  102. /// Region identifier. This is an optional field, the default value is empty, meaning the "world" region
  103. virtual void SetRegion( const char *pszRegion ) = 0;
  104. //
  105. // Player list management / authentication
  106. //
  107. // Handles receiving a new connection from a Steam user. This call will ask the Steam
  108. // servers to validate the users identity, app ownership, and VAC status. If the Steam servers
  109. // are off-line, then it will validate the cached ticket itself which will validate app ownership
  110. // and identity. The AuthBlob here should be acquired on the game client using SteamUser()->InitiateGameConnection()
  111. // and must then be sent up to the game server for authentication.
  112. //
  113. // Return Value: returns true if the users ticket passes basic checks. pSteamIDUser will contain the Steam ID of this user. pSteamIDUser must NOT be NULL
  114. // If the call succeeds then you should expect a GSClientApprove_t or GSClientDeny_t callback which will tell you whether authentication
  115. // for the user has succeeded or failed (the steamid in the callback will match the one returned by this call)
  116. virtual bool SendUserConnectAndAuthenticate( uint32 unIPClient, const void *pvAuthBlob, uint32 cubAuthBlobSize, CSteamID *pSteamIDUser ) = 0;
  117. // Creates a fake user (ie, a bot) which will be listed as playing on the server, but skips validation.
  118. //
  119. // Return Value: Returns a SteamID for the user to be tracked with, you should call HandleUserDisconnect()
  120. // when this user leaves the server just like you would for a real user.
  121. virtual CSteamID CreateUnauthenticatedUserConnection() = 0;
  122. // Should be called whenever a user leaves our game server, this lets Steam internally
  123. // track which users are currently on which servers for the purposes of preventing a single
  124. // account being logged into multiple servers, showing who is currently on a server, etc.
  125. virtual void SendUserDisconnect( CSteamID steamIDUser ) = 0;
  126. // Update the data to be displayed in the server browser and matchmaking interfaces for a user
  127. // currently connected to the server. For regular users you must call this after you receive a
  128. // GSUserValidationSuccess callback.
  129. //
  130. // Return Value: true if successful, false if failure (ie, steamIDUser wasn't for an active player)
  131. virtual bool BUpdateUserData( CSteamID steamIDUser, const char *pchPlayerName, uint32 uScore ) = 0;
  132. // New auth system APIs - do not mix with the old auth system APIs.
  133. // ----------------------------------------------------------------
  134. // Retrieve ticket to be sent to the entity who wishes to authenticate you ( using BeginAuthSession API ).
  135. // pcbTicket retrieves the length of the actual ticket.
  136. virtual HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) = 0;
  137. // Authenticate ticket ( from GetAuthSessionTicket ) from entity steamID to be sure it is valid and isnt reused
  138. // Registers for callbacks if the entity goes offline or cancels the ticket ( see ValidateAuthTicketResponse_t callback and EAuthSessionResponse )
  139. virtual EBeginAuthSessionResult BeginAuthSession( const void *pAuthTicket, int cbAuthTicket, CSteamID steamID ) = 0;
  140. // Stop tracking started by BeginAuthSession - called when no longer playing game with this entity
  141. virtual void EndAuthSession( CSteamID steamID ) = 0;
  142. // Cancel auth ticket from GetAuthSessionTicket, called when no longer playing game with the entity you gave the ticket to
  143. virtual void CancelAuthTicket( HAuthTicket hAuthTicket ) = 0;
  144. // After receiving a user's authentication data, and passing it to SendUserConnectAndAuthenticate, use this function
  145. // to determine if the user owns downloadable content specified by the provided AppID.
  146. virtual EUserHasLicenseForAppResult UserHasLicenseForApp( CSteamID steamID, AppId_t appID ) = 0;
  147. // Ask if a user in in the specified group, results returns async by GSUserGroupStatus_t
  148. // returns false if we're not connected to the steam servers and thus cannot ask
  149. virtual bool RequestUserGroupStatus( CSteamID steamIDUser, CSteamID steamIDGroup ) = 0;
  150. // these two functions s are deprecated, and will not return results
  151. // they will be removed in a future version of the SDK
  152. virtual void GetGameplayStats( ) = 0;
  153. CALL_RESULT( GSReputation_t )
  154. virtual SteamAPICall_t GetServerReputation() = 0;
  155. // Returns the public IP of the server according to Steam, useful when the server is
  156. // behind NAT and you want to advertise its IP in a lobby for other clients to directly
  157. // connect to
  158. virtual uint32 GetPublicIP() = 0;
  159. // These are in GameSocketShare mode, where instead of ISteamGameServer creating its own
  160. // socket to talk to the master server on, it lets the game use its socket to forward messages
  161. // back and forth. This prevents us from requiring server ops to open up yet another port
  162. // in their firewalls.
  163. //
  164. // the IP address and port should be in host order, i.e 127.0.0.1 == 0x7f000001
  165. // These are used when you've elected to multiplex the game server's UDP socket
  166. // rather than having the master server updater use its own sockets.
  167. //
  168. // Source games use this to simplify the job of the server admins, so they
  169. // don't have to open up more ports on their firewalls.
  170. // Call this when a packet that starts with 0xFFFFFFFF comes in. That means
  171. // it's for us.
  172. virtual bool HandleIncomingPacket( const void *pData, int cbData, uint32 srcIP, uint16 srcPort ) = 0;
  173. // AFTER calling HandleIncomingPacket for any packets that came in that frame, call this.
  174. // This gets a packet that the master server updater needs to send out on UDP.
  175. // It returns the length of the packet it wants to send, or 0 if there are no more packets to send.
  176. // Call this each frame until it returns 0.
  177. virtual int GetNextOutgoingPacket( void *pOut, int cbMaxOut, uint32 *pNetAdr, uint16 *pPort ) = 0;
  178. //
  179. // Control heartbeats / advertisement with master server
  180. //
  181. // Call this as often as you like to tell the master server updater whether or not
  182. // you want it to be active (default: off).
  183. virtual void EnableHeartbeats( bool bActive ) = 0;
  184. // You usually don't need to modify this.
  185. // Pass -1 to use the default value for iHeartbeatInterval.
  186. // Some mods change this.
  187. virtual void SetHeartbeatInterval( int iHeartbeatInterval ) = 0;
  188. // Force a heartbeat to steam at the next opportunity
  189. virtual void ForceHeartbeat() = 0;
  190. // associate this game server with this clan for the purposes of computing player compat
  191. CALL_RESULT( AssociateWithClanResult_t )
  192. virtual SteamAPICall_t AssociateWithClan( CSteamID steamIDClan ) = 0;
  193. // ask if any of the current players dont want to play with this new player - or vice versa
  194. CALL_RESULT( ComputeNewPlayerCompatibilityResult_t )
  195. virtual SteamAPICall_t ComputeNewPlayerCompatibility( CSteamID steamIDNewPlayer ) = 0;
  196. };
  197. #define STEAMGAMESERVER_INTERFACE_VERSION "SteamGameServer012"
  198. // game server flags
  199. const uint32 k_unServerFlagNone = 0x00;
  200. const uint32 k_unServerFlagActive = 0x01; // server has users playing
  201. const uint32 k_unServerFlagSecure = 0x02; // server wants to be secure
  202. const uint32 k_unServerFlagDedicated = 0x04; // server is dedicated
  203. const uint32 k_unServerFlagLinux = 0x08; // linux build
  204. const uint32 k_unServerFlagPassworded = 0x10; // password protected
  205. const uint32 k_unServerFlagPrivate = 0x20; // server shouldn't list on master server and
  206. // won't enforce authentication of users that connect to the server.
  207. // Useful when you run a server where the clients may not
  208. // be connected to the internet but you want them to play (i.e LANs)
  209. // callbacks
  210. #if defined( VALVE_CALLBACK_PACK_SMALL )
  211. #pragma pack( push, 4 )
  212. #elif defined( VALVE_CALLBACK_PACK_LARGE )
  213. #pragma pack( push, 8 )
  214. #else
  215. #error isteamclient.h must be included
  216. #endif
  217. // client has been approved to connect to this game server
  218. struct GSClientApprove_t
  219. {
  220. enum { k_iCallback = k_iSteamGameServerCallbacks + 1 };
  221. CSteamID m_SteamID; // SteamID of approved player
  222. CSteamID m_OwnerSteamID; // SteamID of original owner for game license
  223. };
  224. // client has been denied to connection to this game server
  225. struct GSClientDeny_t
  226. {
  227. enum { k_iCallback = k_iSteamGameServerCallbacks + 2 };
  228. CSteamID m_SteamID;
  229. EDenyReason m_eDenyReason;
  230. char m_rgchOptionalText[128];
  231. };
  232. // request the game server should kick the user
  233. struct GSClientKick_t
  234. {
  235. enum { k_iCallback = k_iSteamGameServerCallbacks + 3 };
  236. CSteamID m_SteamID;
  237. EDenyReason m_eDenyReason;
  238. };
  239. // NOTE: callback values 4 and 5 are skipped because they are used for old deprecated callbacks,
  240. // do not reuse them here.
  241. // client achievement info
  242. struct GSClientAchievementStatus_t
  243. {
  244. enum { k_iCallback = k_iSteamGameServerCallbacks + 6 };
  245. uint64 m_SteamID;
  246. char m_pchAchievement[128];
  247. bool m_bUnlocked;
  248. };
  249. // received when the game server requests to be displayed as secure (VAC protected)
  250. // m_bSecure is true if the game server should display itself as secure to users, false otherwise
  251. struct GSPolicyResponse_t
  252. {
  253. enum { k_iCallback = k_iSteamUserCallbacks + 15 };
  254. uint8 m_bSecure;
  255. };
  256. // GS gameplay stats info
  257. struct GSGameplayStats_t
  258. {
  259. enum { k_iCallback = k_iSteamGameServerCallbacks + 7 };
  260. EResult m_eResult; // Result of the call
  261. int32 m_nRank; // Overall rank of the server (0-based)
  262. uint32 m_unTotalConnects; // Total number of clients who have ever connected to the server
  263. uint32 m_unTotalMinutesPlayed; // Total number of minutes ever played on the server
  264. };
  265. // send as a reply to RequestUserGroupStatus()
  266. struct GSClientGroupStatus_t
  267. {
  268. enum { k_iCallback = k_iSteamGameServerCallbacks + 8 };
  269. CSteamID m_SteamIDUser;
  270. CSteamID m_SteamIDGroup;
  271. bool m_bMember;
  272. bool m_bOfficer;
  273. };
  274. // Sent as a reply to GetServerReputation()
  275. struct GSReputation_t
  276. {
  277. enum { k_iCallback = k_iSteamGameServerCallbacks + 9 };
  278. EResult m_eResult; // Result of the call;
  279. uint32 m_unReputationScore; // The reputation score for the game server
  280. bool m_bBanned; // True if the server is banned from the Steam
  281. // master servers
  282. // The following members are only filled out if m_bBanned is true. They will all
  283. // be set to zero otherwise. Master server bans are by IP so it is possible to be
  284. // banned even when the score is good high if there is a bad server on another port.
  285. // This information can be used to determine which server is bad.
  286. uint32 m_unBannedIP; // The IP of the banned server
  287. uint16 m_usBannedPort; // The port of the banned server
  288. uint64 m_ulBannedGameID; // The game ID the banned server is serving
  289. uint32 m_unBanExpires; // Time the ban expires, expressed in the Unix epoch (seconds since 1/1/1970)
  290. };
  291. // Sent as a reply to AssociateWithClan()
  292. struct AssociateWithClanResult_t
  293. {
  294. enum { k_iCallback = k_iSteamGameServerCallbacks + 10 };
  295. EResult m_eResult; // Result of the call;
  296. };
  297. // Sent as a reply to ComputeNewPlayerCompatibility()
  298. struct ComputeNewPlayerCompatibilityResult_t
  299. {
  300. enum { k_iCallback = k_iSteamGameServerCallbacks + 11 };
  301. EResult m_eResult; // Result of the call;
  302. int m_cPlayersThatDontLikeCandidate;
  303. int m_cPlayersThatCandidateDoesntLike;
  304. int m_cClanPlayersThatDontLikeCandidate;
  305. CSteamID m_SteamIDCandidate;
  306. };
  307. #pragma pack( pop )
  308. #endif // ISTEAMGAMESERVER_H