Team Fortress 2 Source Code as on 22/4/2020
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.

191 lines
8.1 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. #ifndef _PS3
  35. #ifdef VERSION_SAFE_STEAM_API_INTERFACES
  36. S_API bool SteamGameServer_InitSafe( uint32 unIP, uint16 usSteamPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString );
  37. #else
  38. S_API bool SteamGameServer_Init( uint32 unIP, uint16 usSteamPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString );
  39. #endif
  40. #else
  41. #ifdef VERSION_SAFE_STEAM_API_INTERFACES
  42. S_API bool SteamGameServer_InitSafe( const SteamPS3Params_t *ps3Params, uint32 unIP, uint16 usSteamPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString );
  43. #else
  44. S_API bool SteamGameServer_Init( const SteamPS3Params_t *ps3Params, uint32 unIP, uint16 usSteamPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString );
  45. #endif
  46. #endif
  47. #ifndef VERSION_SAFE_STEAM_API_INTERFACES
  48. S_API ISteamGameServer *SteamGameServer();
  49. S_API ISteamUtils *SteamGameServerUtils();
  50. S_API ISteamNetworking *SteamGameServerNetworking();
  51. S_API ISteamGameServerStats *SteamGameServerStats();
  52. S_API ISteamHTTP *SteamGameServerHTTP();
  53. S_API ISteamInventory *SteamGameServerInventory();
  54. S_API ISteamUGC *SteamGameServerUGC();
  55. #endif
  56. S_API void SteamGameServer_Shutdown();
  57. S_API void SteamGameServer_RunCallbacks();
  58. S_API bool SteamGameServer_BSecure();
  59. S_API uint64 SteamGameServer_GetSteamID();
  60. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  61. // These macros are similar to the STEAM_CALLBACK_* macros in steam_api.h, but only trigger for gameserver callbacks
  62. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  63. #define STEAM_GAMESERVER_CALLBACK( thisclass, func, /*callback_type, [deprecated] var*/... ) \
  64. _STEAM_CALLBACK_SELECT( ( __VA_ARGS__, GS, 3 ), ( this->SetGameserverFlag();, thisclass, func, __VA_ARGS__ ) )
  65. #define STEAM_GAMESERVER_CALLBACK_MANUAL( thisclass, func, callback_type, var ) \
  66. CCallbackManual< thisclass, callback_type, true > var; void func( callback_type *pParam )
  67. #define _STEAM_CALLBACK_GS( _, thisclass, func, param, var ) \
  68. CCallback< thisclass, param, true > var; void func( param *pParam )
  69. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  70. // steamclient.dll private wrapper functions
  71. //
  72. // The following functions are part of abstracting API access to the steamclient.dll, but should only be used in very specific cases
  73. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  74. S_API HSteamPipe SteamGameServer_GetHSteamPipe();
  75. #ifdef VERSION_SAFE_STEAM_API_INTERFACES
  76. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  77. // VERSION_SAFE_STEAM_API_INTERFACES uses CSteamAPIContext to provide interfaces to each module in a way that
  78. // lets them each specify the interface versions they are compiled with.
  79. //
  80. // It's important that these stay inlined in the header so the calling module specifies the interface versions
  81. // for whatever Steam API version it has.
  82. //----------------------------------------------------------------------------------------------------------------------------------------------------------//
  83. S_API HSteamUser SteamGameServer_GetHSteamUser();
  84. class CSteamGameServerAPIContext
  85. {
  86. public:
  87. CSteamGameServerAPIContext();
  88. void Clear();
  89. bool Init();
  90. ISteamGameServer *SteamGameServer() { return m_pSteamGameServer; }
  91. ISteamUtils *SteamGameServerUtils() { return m_pSteamGameServerUtils; }
  92. ISteamNetworking *SteamGameServerNetworking() { return m_pSteamGameServerNetworking; }
  93. ISteamGameServerStats *SteamGameServerStats() { return m_pSteamGameServerStats; }
  94. ISteamHTTP *SteamHTTP() { return m_pSteamHTTP; }
  95. ISteamInventory *SteamInventory() { return m_pSteamInventory; }
  96. ISteamUGC *SteamUGC() { return m_pSteamUGC; }
  97. private:
  98. ISteamGameServer *m_pSteamGameServer;
  99. ISteamUtils *m_pSteamGameServerUtils;
  100. ISteamNetworking *m_pSteamGameServerNetworking;
  101. ISteamGameServerStats *m_pSteamGameServerStats;
  102. ISteamHTTP *m_pSteamHTTP;
  103. ISteamInventory *m_pSteamInventory;
  104. ISteamUGC *m_pSteamUGC;
  105. };
  106. inline CSteamGameServerAPIContext::CSteamGameServerAPIContext()
  107. {
  108. Clear();
  109. }
  110. inline void CSteamGameServerAPIContext::Clear()
  111. {
  112. m_pSteamGameServer = NULL;
  113. m_pSteamGameServerUtils = NULL;
  114. m_pSteamGameServerNetworking = NULL;
  115. m_pSteamGameServerStats = NULL;
  116. m_pSteamHTTP = NULL;
  117. m_pSteamInventory = NULL;
  118. m_pSteamUGC = NULL;
  119. }
  120. S_API ISteamClient *g_pSteamClientGameServer;
  121. // This function must be inlined so the module using steam_api.dll gets the version names they want.
  122. inline bool CSteamGameServerAPIContext::Init()
  123. {
  124. if ( !g_pSteamClientGameServer )
  125. return false;
  126. HSteamUser hSteamUser = SteamGameServer_GetHSteamUser();
  127. HSteamPipe hSteamPipe = SteamGameServer_GetHSteamPipe();
  128. m_pSteamGameServer = g_pSteamClientGameServer->GetISteamGameServer( hSteamUser, hSteamPipe, STEAMGAMESERVER_INTERFACE_VERSION );
  129. if ( !m_pSteamGameServer )
  130. return false;
  131. m_pSteamGameServerUtils = g_pSteamClientGameServer->GetISteamUtils( hSteamPipe, STEAMUTILS_INTERFACE_VERSION );
  132. if ( !m_pSteamGameServerUtils )
  133. return false;
  134. m_pSteamGameServerNetworking = g_pSteamClientGameServer->GetISteamNetworking( hSteamUser, hSteamPipe, STEAMNETWORKING_INTERFACE_VERSION );
  135. if ( !m_pSteamGameServerNetworking )
  136. return false;
  137. m_pSteamGameServerStats = g_pSteamClientGameServer->GetISteamGameServerStats( hSteamUser, hSteamPipe, STEAMGAMESERVERSTATS_INTERFACE_VERSION );
  138. if ( !m_pSteamGameServerStats )
  139. return false;
  140. m_pSteamHTTP = g_pSteamClientGameServer->GetISteamHTTP( hSteamUser, hSteamPipe, STEAMHTTP_INTERFACE_VERSION );
  141. if ( !m_pSteamHTTP )
  142. return false;
  143. m_pSteamInventory = g_pSteamClientGameServer->GetISteamInventory( hSteamUser, hSteamPipe, STEAMINVENTORY_INTERFACE_VERSION );
  144. if ( !m_pSteamInventory )
  145. return false;
  146. m_pSteamUGC = g_pSteamClientGameServer->GetISteamUGC( hSteamUser, hSteamPipe, STEAMUGC_INTERFACE_VERSION );
  147. if ( !m_pSteamUGC )
  148. return false;
  149. return true;
  150. }
  151. #endif // VERSION_SAFE_STEAM_API_INTERFACES
  152. #endif // STEAM_GAMESERVER_H