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.

308 lines
12 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Expose things from GameInterface.cpp. Mostly the engine interfaces.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef GAMEINTERFACE_H
  8. #define GAMEINTERFACE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "mapentities.h"
  13. #ifndef NO_STEAM
  14. #include "steam/steam_gameserver.h"
  15. #endif
  16. extern INetworkStringTable *g_pStringTableInfoPanel;
  17. // Player / Client related functions
  18. // Most of this is implemented in gameinterface.cpp, but some of it is per-mod in files like cs_gameinterface.cpp, etc.
  19. class CServerGameClients : public IServerGameClients
  20. {
  21. public:
  22. virtual bool ClientConnect( edict_t *pEntity, char const* pszName, char const* pszAddress, char *reject, int maxrejectlen );
  23. virtual void ClientActive( edict_t *pEntity, bool bLoadGame );
  24. virtual void ClientFullyConnect( edict_t *pEntity );
  25. virtual void ClientDisconnect( edict_t *pEntity );
  26. virtual void ClientPutInServer( edict_t *pEntity, const char *playername );
  27. virtual void ClientCommand( edict_t *pEntity, const CCommand &args );
  28. virtual void ClientSettingsChanged( edict_t *pEntity );
  29. virtual void ClientSetupVisibility( edict_t *pViewEntity, edict_t *pClient, unsigned char *pvs, int pvssize );
  30. virtual float ProcessUsercmds( edict_t *player, bf_read *buf, int numcmds, int totalcmds,
  31. int dropped_packets, bool ignore, bool paused );
  32. // Player is running a command
  33. virtual void PostClientMessagesSent( void );
  34. virtual void SetCommandClient( int index );
  35. virtual CPlayerState *GetPlayerState( edict_t *player );
  36. virtual void ClientEarPosition( edict_t *pEntity, Vector *pEarOrigin );
  37. virtual bool ClientReplayEvent( edict_t *pEdict, const ClientReplayEventParams_t &params ) OVERRIDE;
  38. virtual void GetPlayerLimits( int& minplayers, int& maxplayers, int &defaultMaxPlayers ) const;
  39. // returns number of delay ticks if player is in Replay mode (0 = no delay)
  40. virtual int GetReplayDelay( edict_t *player, int& entity );
  41. // Anything this game .dll wants to add to the bug reporter text (e.g., the entity/model under the picker crosshair)
  42. // can be added here
  43. virtual void GetBugReportInfo( char *buf, int buflen );
  44. // A player sent a voice packet
  45. virtual void ClientVoice( edict_t *pEdict );
  46. virtual void NetworkIDValidated( const char *pszUserName, const char *pszNetworkID, CSteamID steamID ) OVERRIDE;
  47. virtual int GetMaxSplitscreenPlayers();
  48. virtual int GetMaxHumanPlayers();
  49. // The client has submitted a keyvalues command
  50. virtual void ClientCommandKeyValues( edict_t *pEntity, KeyValues *pKeyValues );
  51. // Server override for supplied client name
  52. virtual const char * ClientNameHandler( uint64 xuid, const char *pchName ) OVERRIDE;
  53. virtual void ClientSvcUserMessage( edict_t *pEntity, int nType, int nPassthrough, uint32 cbSize, const void *pvBuffer ) OVERRIDE;
  54. };
  55. class CServerGameDLL : public IServerGameDLL
  56. {
  57. public:
  58. virtual bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory,
  59. CreateInterfaceFn fileSystemFactory, CGlobalVars *pGlobals);
  60. virtual void DLLShutdown( void );
  61. // Get the simulation interval (must be compiled with identical values into both client and game .dll for MOD!!!)
  62. virtual float GetTickInterval( void ) const;
  63. virtual bool GameInit( void );
  64. virtual void GameShutdown( void );
  65. virtual bool LevelInit( const char *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background );
  66. virtual void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax );
  67. virtual void LevelShutdown( void );
  68. virtual void GameFrame( bool simulating ); // could be called multiple times before sending data to clients
  69. virtual void PreClientUpdate( bool simulating ); // called after all GameFrame() calls, before sending data to clients
  70. virtual ServerClass* GetAllServerClasses( void );
  71. virtual const char *GetGameDescription( void );
  72. virtual void CreateNetworkStringTables( void );
  73. // Save/restore system hooks
  74. virtual CSaveRestoreData *SaveInit( int size );
  75. virtual void SaveWriteFields( CSaveRestoreData *, char const* , void *, datamap_t *, typedescription_t *, int );
  76. virtual void SaveReadFields( CSaveRestoreData *, char const* , void *, datamap_t *, typedescription_t *, int );
  77. virtual void SaveGlobalState( CSaveRestoreData * );
  78. virtual void RestoreGlobalState( CSaveRestoreData * );
  79. virtual int CreateEntityTransitionList( CSaveRestoreData *, int );
  80. virtual void BuildAdjacentMapList( void );
  81. virtual void PreSave( CSaveRestoreData * );
  82. virtual void Save( CSaveRestoreData * );
  83. virtual void GetSaveComment( char *comment, int maxlength, float flMinutes, float flSeconds, bool bNoTime = false );
  84. virtual void WriteSaveHeaders( CSaveRestoreData * );
  85. virtual void ReadRestoreHeaders( CSaveRestoreData * );
  86. virtual void Restore( CSaveRestoreData *, bool );
  87. virtual bool IsRestoring();
  88. virtual bool SupportsSaveRestore();
  89. virtual CStandardSendProxies* GetStandardSendProxies();
  90. virtual void PostInit();
  91. virtual void PostToolsInit();
  92. virtual void Think( bool finalTick );
  93. virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue );
  94. virtual void PreSaveGameLoaded( char const *pSaveName, bool bInGame );
  95. // Returns true if the game DLL wants the server not to be made public.
  96. // Used by commentary system to hide multiplayer commentary servers from the master.
  97. virtual bool ShouldHideServer( void );
  98. virtual void InvalidateMdlCache();
  99. // Called to apply lobby settings to a dedicated server
  100. virtual void ApplyGameSettings( KeyValues *pKV );
  101. virtual void GetMatchmakingTags( char *buf, size_t bufSize );
  102. virtual void ServerHibernationUpdate( bool bHibernating );
  103. virtual bool ShouldPreferSteamAuth();
  104. virtual bool ShouldAllowDirectConnect( void );
  105. virtual bool FriendsReqdForDirectConnect( void );
  106. virtual bool IsLoadTestServer( void );
  107. virtual bool IsValveDS( void );
  108. // Builds extended server info for new connecting client
  109. virtual KeyValues* GetExtendedServerInfoForNewClient();
  110. virtual void UpdateGCInformation();
  111. // Marks the queue matchmaking game as starting
  112. virtual void ReportGCQueuedMatchStart( int32 iReservationStage, uint32 *puiConfirmedAccounts, int numConfirmedAccounts );
  113. // Given a path to a map (relative to the game dir) returns a publish file id if its a UGC file known by the server, or 0 otherwise.
  114. virtual PublishedFileId_t GetUGCMapFileID( const char* szMapPath );
  115. // Query steam for the latest file info, download new version if needed.
  116. virtual bool GetNewestSubscribedFiles( void );
  117. // Same as above but for a single ugc map
  118. virtual void UpdateUGCMap( PublishedFileId_t id );
  119. // Returns true if we are currently downloading a new version of the map, or if there is a query pending to check for a newer version.
  120. virtual bool HasPendingMapDownloads( void ) const;
  121. // Precaches particle systems defined in the specific file
  122. virtual void PrecacheParticleSystemFile( const char *pParticleSystemFile );
  123. // Matchmaking game data buffer to set into SteamGameServer()->SetGameData
  124. virtual void GetMatchmakingGameData( char *buf, size_t bufSize );
  125. float m_fAutoSaveDangerousTime;
  126. float m_fAutoSaveDangerousMinHealthToCommit;
  127. bool m_bIsHibernating;
  128. // Called after the steam API has been activated post-level startup
  129. virtual void GameServerSteamAPIActivated( bool bActive );
  130. // Returns which encryption key to use for messages to be encrypted for TV
  131. virtual EncryptedMessageKeyType_t GetMessageEncryptionKey( INetMessage *pMessage );
  132. // If server game dll needs more time before server process quits then
  133. // it should return true to hold game server reservation from this interface method.
  134. // If this method returns false then the server process will clear the reservation
  135. // and might shutdown to meet uptime or memory limit requirements.
  136. virtual bool ShouldHoldGameServerReservation( float flTimeElapsedWithoutClients );
  137. // Pure server validation failed for the given client, client supplied
  138. // data is included in the payload
  139. virtual void OnPureServerFileValidationFailure( edict_t *edictClient, const char *path, const char *fileName, uint32 crc, int32 hashType, int32 len, int packNumber, int packFileID );
  140. // Last chance validation on connect packet for the client, non-NULL return value
  141. // causes the client connect to be aborted with the provided error
  142. virtual char const * ClientConnectionValidatePreNetChan( bool bGameServer, char const *adr, int nAuthProtocol, uint64 ullSteamID );
  143. // validate if player is a caster and add them to the active caster list
  144. virtual bool ValidateAndAddActiveCaster( const CSteamID &steamID );
  145. // Network channel notification from engine to game server code
  146. virtual void OnEngineClientNetworkEvent( edict_t *edictClient, uint64 ullSteamID, int nEventType, void *pvParam ) OVERRIDE;
  147. virtual void EngineGotvSyncPacket( const CEngineGotvSyncPacket *pPkt ) OVERRIDE;
  148. // GOTV client attempt redirect over SDR
  149. virtual bool OnEngineClientProxiedRedirect( uint64 ullClient, const char *adrProxiedRedirect, const char *adrRegular ) OVERRIDE;
  150. // Tell server about a line we will write to the log file which may be sent to remote listeners
  151. bool LogForHTTPListeners( const char* szLogLine ) OVERRIDE;
  152. private:
  153. // This can just be a wrapper on MapEntity_ParseAllEntities, but CS does some tricks in here
  154. // with the entity list.
  155. void LevelInit_ParseAllEntities( const char *pMapEntities );
  156. void LoadMessageOfTheDay();
  157. };
  158. // Normally, when the engine calls ClientPutInServer, it calls a global function in the game DLL
  159. // by the same name. Use this to override the function that it calls. This is used for bots.
  160. typedef CBasePlayer* (*ClientPutInServerOverrideFn)( edict_t *pEdict, const char *playername );
  161. void ClientPutInServerOverride( ClientPutInServerOverrideFn fn );
  162. // -------------------------------------------------------------------------------------------- //
  163. // Entity list management stuff.
  164. // -------------------------------------------------------------------------------------------- //
  165. // These are created for map entities in order as the map entities are spawned.
  166. class CMapEntityRef
  167. {
  168. public:
  169. int m_iEdict; // Which edict slot this entity got. -1 if CreateEntityByName failed.
  170. int m_iSerialNumber; // The edict serial number. TODO used anywhere ?
  171. };
  172. extern CUtlLinkedList<CMapEntityRef, unsigned short> g_MapEntityRefs;
  173. //-----------------------------------------------------------------------------
  174. // Purpose:
  175. //-----------------------------------------------------------------------------
  176. class CMapLoadEntityFilter : public IMapEntityFilter
  177. {
  178. public:
  179. virtual bool ShouldCreateEntity( const char *pClassname )
  180. {
  181. // During map load, create all the entities.
  182. return true;
  183. }
  184. virtual CBaseEntity* CreateNextEntity( const char *pClassname )
  185. {
  186. CBaseEntity *pRet = CreateEntityByName( pClassname );
  187. CMapEntityRef ref;
  188. ref.m_iEdict = -1;
  189. ref.m_iSerialNumber = -1;
  190. if ( pRet )
  191. {
  192. ref.m_iEdict = pRet->entindex();
  193. if ( pRet->edict() )
  194. ref.m_iSerialNumber = pRet->edict()->m_NetworkSerialNumber;
  195. }
  196. g_MapEntityRefs.AddToTail( ref );
  197. return pRet;
  198. }
  199. };
  200. bool IsEngineThreaded();
  201. class CServerGameTags : public IServerGameTags
  202. {
  203. public:
  204. virtual void GetTaggedConVarList( KeyValues *pCvarTagList );
  205. };
  206. EXPOSE_SINGLE_INTERFACE( CServerGameTags, IServerGameTags, INTERFACEVERSION_SERVERGAMETAGS );
  207. #ifndef NO_STEAM
  208. //-----------------------------------------------------------------------------
  209. // Purpose:
  210. //-----------------------------------------------------------------------------
  211. class CSteam3Server : public CSteamGameServerAPIContext
  212. {
  213. public:
  214. CSteam3Server();
  215. void Shutdown( void )
  216. {
  217. Clear();
  218. m_bInitialized = false;
  219. }
  220. bool CheckInitialized( void )
  221. {
  222. if ( !m_bInitialized )
  223. {
  224. Init();
  225. m_bInitialized = true;
  226. return true;
  227. }
  228. return false;
  229. }
  230. private:
  231. bool m_bInitialized;
  232. };
  233. CSteam3Server &Steam3Server();
  234. #endif
  235. #endif // GAMEINTERFACE_H