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.

237 lines
11 KiB

  1. //====== Copyright � 1996-2008, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef STEAM_GAMESERVER_H
  7. #define STEAM_GAMESERVER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "steam_api.h"
  12. #include "isteamgameserver.h"
  13. #include "isteamgameserverstats.h"
  14. enum EServerMode
  15. {
  16. eServerModeInvalid = 0, // DO NOT USE
  17. eServerModeNoAuthentication = 1, // Don't authenticate user logins and don't list on the server list
  18. eServerModeAuthentication = 2, // Authenticate users, list on the server list, don't run VAC on clients that connect
  19. eServerModeAuthenticationAndSecure = 3, // Authenticate users, list on the server list and VAC protect clients
  20. };
  21. // Initialize ISteamGameServer interface object, and set server properties which may not be changed.
  22. //
  23. // After calling this function, you should set any additional server parameters, and then
  24. // call ISteamGameServer::LogOnAnonymous() or ISteamGameServer::LogOn()
  25. //
  26. // - usSteamPort is the local port used to communicate with the steam servers.
  27. // - usGamePort is the port that clients will connect to for gameplay.
  28. // - usQueryPort is the port that will manage server browser related duties and info
  29. // pings from clients. If you pass MASTERSERVERUPDATERPORT_USEGAMESOCKETSHARE for usQueryPort, then it
  30. // will use "GameSocketShare" mode, which means that the game is responsible for sending and receiving
  31. // UDP packets for the master server updater. See references to GameSocketShare in isteamgameserver.h.
  32. // - The version string is usually in the form x.x.x.x, and is used by the master server to detect when the
  33. // server is out of date. (Only servers with the latest version will be listed.)
  34. inline bool SteamGameServer_Init( uint32 unIP, uint16 usSteamPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString );
  35. S_API void SteamGameServer_Shutdown();
  36. S_API void SteamGameServer_RunCallbacks();
  37. // Most Steam API functions allocate some amount of thread-local memory for
  38. // parameter storage. Calling SteamGameServer_ReleaseCurrentThreadMemory()
  39. // will free all API-related memory associated with the calling thread.
  40. // This memory is released automatically by SteamGameServer_RunCallbacks(),
  41. // so single-threaded servers do not need to explicitly call this function.
  42. inline void SteamGameServer_ReleaseCurrentThreadMemory();
  43. S_API bool SteamGameServer_BSecure();
  44. S_API uint64 SteamGameServer_GetSteamID();
  45. // If your application contains modules which could be built against different Steamworks SDK
  46. // versions, then you should define VERSION_SAFE_STEAM_API_INTERFACES to enforce that you cannot
  47. // use the version-less global accessors. Instead, create and use CSteamGameServerAPIContext
  48. // objects to retrieve interface pointers which are appropriate for your Steamworks SDK headers.
  49. #if !defined( VERSION_SAFE_STEAM_API_INTERFACES ) && !defined( STEAM_API_EXPORTS )
  50. inline ISteamClient *SteamGameServerClient();
  51. inline ISteamGameServer *SteamGameServer();
  52. inline ISteamUtils *SteamGameServerUtils();
  53. inline ISteamNetworking *SteamGameServerNetworking();
  54. inline ISteamGameServerStats *SteamGameServerStats();
  55. inline ISteamHTTP *SteamGameServerHTTP();
  56. inline ISteamInventory *SteamGameServerInventory();
  57. inline ISteamUGC *SteamGameServerUGC();
  58. inline ISteamApps *SteamGameServerApps();
  59. #endif
  60. class CSteamGameServerAPIContext
  61. {
  62. public:
  63. CSteamGameServerAPIContext() { Clear(); }
  64. inline void Clear();
  65. inline bool Init();
  66. ISteamClient *SteamClient() const { return m_pSteamClient; }
  67. ISteamGameServer *SteamGameServer() const { return m_pSteamGameServer; }
  68. ISteamUtils *SteamGameServerUtils() const { return m_pSteamGameServerUtils; }
  69. ISteamNetworking *SteamGameServerNetworking() const { return m_pSteamGameServerNetworking; }
  70. ISteamGameServerStats *SteamGameServerStats() const { return m_pSteamGameServerStats; }
  71. ISteamHTTP *SteamHTTP() const { return m_pSteamHTTP; }
  72. ISteamInventory *SteamInventory() const { return m_pSteamInventory; }
  73. ISteamUGC *SteamUGC() const { return m_pSteamUGC; }
  74. ISteamApps *SteamApps() const { return m_pSteamApps; }
  75. private:
  76. ISteamClient *m_pSteamClient;
  77. ISteamGameServer *m_pSteamGameServer;
  78. ISteamUtils *m_pSteamGameServerUtils;
  79. ISteamNetworking *m_pSteamGameServerNetworking;
  80. ISteamGameServerStats *m_pSteamGameServerStats;
  81. ISteamHTTP *m_pSteamHTTP;
  82. ISteamInventory *m_pSteamInventory;
  83. ISteamUGC *m_pSteamUGC;
  84. ISteamApps *m_pSteamApps;
  85. };
  86. // Older SDKs exported this global pointer, but it is no longer supported.
  87. // You should use SteamGameServerClient() or CSteamGameServerAPIContext to
  88. // safely access the ISteamClient APIs from your game server application.
  89. //S_API ISteamClient *g_pSteamClientGameServer;
  90. // SteamGameServer_InitSafe has been replaced with SteamGameServer_Init and
  91. // is no longer supported. Use SteamGameServer_Init instead.
  92. //S_API void S_CALLTYPE SteamGameServer_InitSafe();
  93. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  94. // These macros are similar to the STEAM_CALLBACK_* macros in steam_api.h, but only trigger for gameserver callbacks
  95. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  96. #define STEAM_GAMESERVER_CALLBACK( thisclass, func, /*callback_type, [deprecated] var*/... ) \
  97. _STEAM_CALLBACK_SELECT( ( __VA_ARGS__, GS, 3 ), ( this->SetGameserverFlag();, thisclass, func, __VA_ARGS__ ) )
  98. #define STEAM_GAMESERVER_CALLBACK_MANUAL( thisclass, func, callback_type, var ) \
  99. CCallbackManual< thisclass, callback_type, true > var; void func( callback_type *pParam )
  100. #define _STEAM_CALLBACK_GS( _, thisclass, func, param, var ) \
  101. CCallback< thisclass, param, true > var; void func( param *pParam )
  102. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  103. // steamclient.dll private wrapper functions
  104. //
  105. // The following functions are part of abstracting API access to the steamclient.dll, but should only be used in very specific cases
  106. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  107. S_API HSteamPipe S_CALLTYPE SteamGameServer_GetHSteamPipe();
  108. S_API HSteamUser S_CALLTYPE SteamGameServer_GetHSteamUser();
  109. S_API bool S_CALLTYPE SteamInternal_GameServer_Init( uint32 unIP, uint16 usPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString );
  110. #if defined( VERSION_SAFE_STEAM_API_INTERFACES )
  111. #define SteamGameServer_InitSafe SteamGameServer_Init
  112. #endif
  113. #if !defined( VERSION_SAFE_STEAM_API_INTERFACES ) && !defined( STEAM_API_EXPORTS )
  114. S_API CSteamGameServerAPIContext* S_CALLTYPE SteamInternal_GlobalContextGameServerPtr( uint32 size );
  115. inline CSteamGameServerAPIContext& SteamInternal_GlobalContextGameServer()
  116. {
  117. static CSteamGameServerAPIContext *context;
  118. if ( !context )
  119. context = SteamInternal_GlobalContextGameServerPtr( sizeof( CSteamGameServerAPIContext ) );
  120. return *context;
  121. }
  122. inline ISteamClient *SteamGameServerClient() { return SteamInternal_GlobalContextGameServer().SteamClient(); }
  123. inline ISteamGameServer *SteamGameServer() { return SteamInternal_GlobalContextGameServer().SteamGameServer(); }
  124. inline ISteamUtils *SteamGameServerUtils() { return SteamInternal_GlobalContextGameServer().SteamGameServerUtils(); }
  125. inline ISteamNetworking *SteamGameServerNetworking() { return SteamInternal_GlobalContextGameServer().SteamGameServerNetworking(); }
  126. inline ISteamGameServerStats *SteamGameServerStats() { return SteamInternal_GlobalContextGameServer().SteamGameServerStats(); }
  127. inline ISteamHTTP *SteamGameServerHTTP() { return SteamInternal_GlobalContextGameServer().SteamHTTP(); }
  128. inline ISteamInventory *SteamGameServerInventory() { return SteamInternal_GlobalContextGameServer().SteamInventory(); }
  129. inline ISteamUGC *SteamGameServerUGC() { return SteamInternal_GlobalContextGameServer().SteamUGC(); }
  130. inline ISteamApps *SteamGameServerApps() { return SteamInternal_GlobalContextGameServer().SteamApps(); }
  131. #endif
  132. inline void CSteamGameServerAPIContext::Clear()
  133. {
  134. m_pSteamClient = NULL;
  135. m_pSteamGameServer = NULL;
  136. m_pSteamGameServerUtils = NULL;
  137. m_pSteamGameServerNetworking = NULL;
  138. m_pSteamGameServerStats = NULL;
  139. m_pSteamHTTP = NULL;
  140. m_pSteamInventory = NULL;
  141. m_pSteamUGC = NULL;
  142. m_pSteamApps = NULL;
  143. }
  144. // This function must be declared inline in the header so the module using steam_api.dll gets the version names they want.
  145. inline bool CSteamGameServerAPIContext::Init()
  146. {
  147. HSteamUser hSteamUser = SteamGameServer_GetHSteamUser();
  148. HSteamPipe hSteamPipe = SteamGameServer_GetHSteamPipe();
  149. if ( !hSteamPipe )
  150. return false;
  151. m_pSteamClient = (ISteamClient*) SteamInternal_CreateInterface( STEAMCLIENT_INTERFACE_VERSION );
  152. if ( !m_pSteamClient )
  153. return false;
  154. m_pSteamGameServer = m_pSteamClient->GetISteamGameServer( hSteamUser, hSteamPipe, STEAMGAMESERVER_INTERFACE_VERSION );
  155. if ( !m_pSteamGameServer )
  156. return false;
  157. m_pSteamGameServerUtils = m_pSteamClient->GetISteamUtils( hSteamPipe, STEAMUTILS_INTERFACE_VERSION );
  158. if ( !m_pSteamGameServerUtils )
  159. return false;
  160. m_pSteamGameServerNetworking = m_pSteamClient->GetISteamNetworking( hSteamUser, hSteamPipe, STEAMNETWORKING_INTERFACE_VERSION );
  161. if ( !m_pSteamGameServerNetworking )
  162. return false;
  163. m_pSteamGameServerStats = m_pSteamClient->GetISteamGameServerStats( hSteamUser, hSteamPipe, STEAMGAMESERVERSTATS_INTERFACE_VERSION );
  164. if ( !m_pSteamGameServerStats )
  165. return false;
  166. m_pSteamHTTP = m_pSteamClient->GetISteamHTTP( hSteamUser, hSteamPipe, STEAMHTTP_INTERFACE_VERSION );
  167. if ( !m_pSteamHTTP )
  168. return false;
  169. m_pSteamInventory = m_pSteamClient->GetISteamInventory( hSteamUser, hSteamPipe, STEAMINVENTORY_INTERFACE_VERSION );
  170. if ( !m_pSteamInventory )
  171. return false;
  172. m_pSteamUGC = m_pSteamClient->GetISteamUGC( hSteamUser, hSteamPipe, STEAMUGC_INTERFACE_VERSION );
  173. if ( !m_pSteamUGC )
  174. return false;
  175. m_pSteamApps = m_pSteamClient->GetISteamApps( hSteamUser, hSteamPipe, STEAMAPPS_INTERFACE_VERSION );
  176. if ( !m_pSteamApps )
  177. return false;
  178. return true;
  179. }
  180. inline bool SteamGameServer_Init( uint32 unIP, uint16 usSteamPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString )
  181. {
  182. if ( !SteamInternal_GameServer_Init( unIP, usSteamPort, usGamePort, usQueryPort, eServerMode, pchVersionString ) )
  183. return false;
  184. #if !defined( VERSION_SAFE_STEAM_API_INTERFACES ) && !defined( STEAM_API_EXPORTS )
  185. if ( !SteamInternal_GlobalContextGameServer().Init() )
  186. return false;
  187. #endif
  188. return true;
  189. }
  190. inline void SteamGameServer_ReleaseCurrentThreadMemory()
  191. {
  192. SteamAPI_ReleaseCurrentThreadMemory();
  193. }
  194. #endif // STEAM_GAMESERVER_H