/lsteamclient/steamworks_sdk_141/steam_gameserver.h

https://github.com/GloriousEggroll/proton-ge-custom · C Header · 243 lines · 147 code · 43 blank · 53 comment · 12 complexity · 09bdea535cf1f6f93b435ad95c2f93f2 MD5 · raw file

  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. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  46. // Global accessors for game server C++ APIs. See individual isteam*.h files for details.
  47. // You should not cache the results of these accessors or pass the result pointers across
  48. // modules! Different modules may be compiled against different SDK header versions, and
  49. // the interface pointers could therefore be different across modules. Every line of code
  50. // which calls into a Steamworks API should retrieve the interface from a global accessor.
  51. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  52. #if !defined( STEAM_API_EXPORTS )
  53. inline ISteamClient *SteamGameServerClient();
  54. inline ISteamGameServer *SteamGameServer();
  55. inline ISteamUtils *SteamGameServerUtils();
  56. inline ISteamNetworking *SteamGameServerNetworking();
  57. inline ISteamGameServerStats *SteamGameServerStats();
  58. inline ISteamHTTP *SteamGameServerHTTP();
  59. inline ISteamInventory *SteamGameServerInventory();
  60. inline ISteamUGC *SteamGameServerUGC();
  61. inline ISteamApps *SteamGameServerApps();
  62. #endif
  63. class CSteamGameServerAPIContext
  64. {
  65. public:
  66. CSteamGameServerAPIContext() { Clear(); }
  67. inline void Clear();
  68. inline bool Init();
  69. ISteamClient *SteamClient() const { return m_pSteamClient; }
  70. ISteamGameServer *SteamGameServer() const { return m_pSteamGameServer; }
  71. ISteamUtils *SteamGameServerUtils() const { return m_pSteamGameServerUtils; }
  72. ISteamNetworking *SteamGameServerNetworking() const { return m_pSteamGameServerNetworking; }
  73. ISteamGameServerStats *SteamGameServerStats() const { return m_pSteamGameServerStats; }
  74. ISteamHTTP *SteamHTTP() const { return m_pSteamHTTP; }
  75. ISteamInventory *SteamInventory() const { return m_pSteamInventory; }
  76. ISteamUGC *SteamUGC() const { return m_pSteamUGC; }
  77. ISteamApps *SteamApps() const { return m_pSteamApps; }
  78. private:
  79. ISteamClient *m_pSteamClient;
  80. ISteamGameServer *m_pSteamGameServer;
  81. ISteamUtils *m_pSteamGameServerUtils;
  82. ISteamNetworking *m_pSteamGameServerNetworking;
  83. ISteamGameServerStats *m_pSteamGameServerStats;
  84. ISteamHTTP *m_pSteamHTTP;
  85. ISteamInventory *m_pSteamInventory;
  86. ISteamUGC *m_pSteamUGC;
  87. ISteamApps *m_pSteamApps;
  88. };
  89. // Older SDKs exported this global pointer, but it is no longer supported.
  90. // You should use SteamGameServerClient() or CSteamGameServerAPIContext to
  91. // safely access the ISteamClient APIs from your game server application.
  92. //S_API ISteamClient *g_pSteamClientGameServer;
  93. // SteamGameServer_InitSafe has been replaced with SteamGameServer_Init and
  94. // is no longer supported. Use SteamGameServer_Init instead.
  95. //S_API void S_CALLTYPE SteamGameServer_InitSafe();
  96. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  97. // These macros are similar to the STEAM_CALLBACK_* macros in steam_api.h, but only trigger for gameserver callbacks
  98. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  99. #define STEAM_GAMESERVER_CALLBACK( thisclass, func, /*callback_type, [deprecated] var*/... ) \
  100. _STEAM_CALLBACK_SELECT( ( __VA_ARGS__, GS, 3 ), ( this->SetGameserverFlag();, thisclass, func, __VA_ARGS__ ) )
  101. #define STEAM_GAMESERVER_CALLBACK_MANUAL( thisclass, func, callback_type, var ) \
  102. CCallbackManual< thisclass, callback_type, true > var; void func( callback_type *pParam )
  103. #define _STEAM_CALLBACK_GS( _, thisclass, func, param, var ) \
  104. CCallback< thisclass, param, true > var; void func( param *pParam )
  105. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  106. // steamclient.dll private wrapper functions
  107. //
  108. // The following functions are part of abstracting API access to the steamclient.dll, but should only be used in very specific cases
  109. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  110. S_API HSteamPipe S_CALLTYPE SteamGameServer_GetHSteamPipe();
  111. S_API HSteamUser S_CALLTYPE SteamGameServer_GetHSteamUser();
  112. S_API bool S_CALLTYPE SteamInternal_GameServer_Init( uint32 unIP, uint16 usPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString );
  113. #if !defined( STEAM_API_EXPORTS )
  114. inline void S_CALLTYPE SteamGameServerInternal_OnContextInit( void* p )
  115. {
  116. ((CSteamGameServerAPIContext*)p)->Clear();
  117. if ( SteamGameServer_GetHSteamPipe() )
  118. ((CSteamGameServerAPIContext*)p)->Init();
  119. }
  120. inline CSteamGameServerAPIContext& SteamGameServerInternal_ModuleContext()
  121. {
  122. // SteamInternal_ContextInit takes a base pointer for the equivalent of
  123. // struct { void (*pFn)(void* pCtx); uintp counter; CSteamAPIContext ctx; }
  124. // Do not change layout of 2 + sizeof... or add non-pointer aligned data!
  125. // NOTE: declaring "static CSteamAPIConext" creates a large function
  126. // which queries the initialization status of the object. We know that
  127. // it is pointer-aligned and fully memset with zeros, so just alias a
  128. // static buffer of the appropriate size and call it a CSteamAPIContext.
  129. static void* s_CallbackCounterAndContext[2 + sizeof( CSteamGameServerAPIContext ) / sizeof( void* )] = { (void*)&SteamGameServerInternal_OnContextInit, 0 };
  130. return *(CSteamGameServerAPIContext*)SteamInternal_ContextInit( s_CallbackCounterAndContext );
  131. }
  132. inline ISteamClient *SteamGameServerClient() { return SteamGameServerInternal_ModuleContext().SteamClient(); }
  133. inline ISteamGameServer *SteamGameServer() { return SteamGameServerInternal_ModuleContext().SteamGameServer(); }
  134. inline ISteamUtils *SteamGameServerUtils() { return SteamGameServerInternal_ModuleContext().SteamGameServerUtils(); }
  135. inline ISteamNetworking *SteamGameServerNetworking() { return SteamGameServerInternal_ModuleContext().SteamGameServerNetworking(); }
  136. inline ISteamGameServerStats *SteamGameServerStats() { return SteamGameServerInternal_ModuleContext().SteamGameServerStats(); }
  137. inline ISteamHTTP *SteamGameServerHTTP() { return SteamGameServerInternal_ModuleContext().SteamHTTP(); }
  138. inline ISteamInventory *SteamGameServerInventory() { return SteamGameServerInternal_ModuleContext().SteamInventory(); }
  139. inline ISteamUGC *SteamGameServerUGC() { return SteamGameServerInternal_ModuleContext().SteamUGC(); }
  140. inline ISteamApps *SteamGameServerApps() { return SteamGameServerInternal_ModuleContext().SteamApps(); }
  141. #endif // !defined( STEAM_API_EXPORTS )
  142. inline void CSteamGameServerAPIContext::Clear()
  143. {
  144. m_pSteamClient = NULL;
  145. m_pSteamGameServer = NULL;
  146. m_pSteamGameServerUtils = NULL;
  147. m_pSteamGameServerNetworking = NULL;
  148. m_pSteamGameServerStats = NULL;
  149. m_pSteamHTTP = NULL;
  150. m_pSteamInventory = NULL;
  151. m_pSteamUGC = NULL;
  152. m_pSteamApps = NULL;
  153. }
  154. // This function must be declared inline in the header so the module using steam_api.dll gets the version names they want.
  155. inline bool CSteamGameServerAPIContext::Init()
  156. {
  157. HSteamUser hSteamUser = SteamGameServer_GetHSteamUser();
  158. HSteamPipe hSteamPipe = SteamGameServer_GetHSteamPipe();
  159. if ( !hSteamPipe )
  160. return false;
  161. m_pSteamClient = (ISteamClient*) SteamInternal_CreateInterface( STEAMCLIENT_INTERFACE_VERSION );
  162. if ( !m_pSteamClient )
  163. return false;
  164. m_pSteamGameServer = m_pSteamClient->GetISteamGameServer( hSteamUser, hSteamPipe, STEAMGAMESERVER_INTERFACE_VERSION );
  165. if ( !m_pSteamGameServer )
  166. return false;
  167. m_pSteamGameServerUtils = m_pSteamClient->GetISteamUtils( hSteamPipe, STEAMUTILS_INTERFACE_VERSION );
  168. if ( !m_pSteamGameServerUtils )
  169. return false;
  170. m_pSteamGameServerNetworking = m_pSteamClient->GetISteamNetworking( hSteamUser, hSteamPipe, STEAMNETWORKING_INTERFACE_VERSION );
  171. if ( !m_pSteamGameServerNetworking )
  172. return false;
  173. m_pSteamGameServerStats = m_pSteamClient->GetISteamGameServerStats( hSteamUser, hSteamPipe, STEAMGAMESERVERSTATS_INTERFACE_VERSION );
  174. if ( !m_pSteamGameServerStats )
  175. return false;
  176. m_pSteamHTTP = m_pSteamClient->GetISteamHTTP( hSteamUser, hSteamPipe, STEAMHTTP_INTERFACE_VERSION );
  177. if ( !m_pSteamHTTP )
  178. return false;
  179. m_pSteamInventory = m_pSteamClient->GetISteamInventory( hSteamUser, hSteamPipe, STEAMINVENTORY_INTERFACE_VERSION );
  180. if ( !m_pSteamInventory )
  181. return false;
  182. m_pSteamUGC = m_pSteamClient->GetISteamUGC( hSteamUser, hSteamPipe, STEAMUGC_INTERFACE_VERSION );
  183. if ( !m_pSteamUGC )
  184. return false;
  185. m_pSteamApps = m_pSteamClient->GetISteamApps( hSteamUser, hSteamPipe, STEAMAPPS_INTERFACE_VERSION );
  186. if ( !m_pSteamApps )
  187. return false;
  188. return true;
  189. }
  190. inline bool SteamGameServer_Init( uint32 unIP, uint16 usSteamPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString )
  191. {
  192. if ( !SteamInternal_GameServer_Init( unIP, usSteamPort, usGamePort, usQueryPort, eServerMode, pchVersionString ) )
  193. return false;
  194. return true;
  195. }
  196. inline void SteamGameServer_ReleaseCurrentThreadMemory()
  197. {
  198. SteamAPI_ReleaseCurrentThreadMemory();
  199. }
  200. #endif // STEAM_GAMESERVER_H