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.

228 lines
9.7 KiB

  1. //========= Copyright 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. class IReplayFactory;
  14. extern INetworkStringTable *g_pStringTableInfoPanel;
  15. extern INetworkStringTable *g_pStringTableServerMapCycle;
  16. #ifdef TF_DLL
  17. extern INetworkStringTable *g_pStringTableServerPopFiles;
  18. #endif
  19. // Player / Client related functions
  20. // Most of this is implemented in gameinterface.cpp, but some of it is per-mod in files like cs_gameinterface.cpp, etc.
  21. class CServerGameClients : public IServerGameClients
  22. {
  23. public:
  24. virtual bool ClientConnect( edict_t *pEntity, char const* pszName, char const* pszAddress, char *reject, int maxrejectlen ) OVERRIDE;
  25. virtual void ClientActive( edict_t *pEntity, bool bLoadGame ) OVERRIDE;
  26. virtual void ClientDisconnect( edict_t *pEntity ) OVERRIDE;
  27. virtual void ClientPutInServer( edict_t *pEntity, const char *playername ) OVERRIDE;
  28. virtual void ClientCommand( edict_t *pEntity, const CCommand &args ) OVERRIDE;
  29. virtual void ClientSettingsChanged( edict_t *pEntity ) OVERRIDE;
  30. virtual void ClientSetupVisibility( edict_t *pViewEntity, edict_t *pClient, unsigned char *pvs, int pvssize ) OVERRIDE;
  31. virtual float ProcessUsercmds( edict_t *player, bf_read *buf, int numcmds, int totalcmds,
  32. int dropped_packets, bool ignore, bool paused ) OVERRIDE;
  33. // Player is running a command
  34. virtual void PostClientMessagesSent_DEPRECIATED( void ) OVERRIDE;
  35. virtual void SetCommandClient( int index ) OVERRIDE;
  36. virtual CPlayerState *GetPlayerState( edict_t *player ) OVERRIDE;
  37. virtual void ClientEarPosition( edict_t *pEntity, Vector *pEarOrigin ) OVERRIDE;
  38. virtual void GetPlayerLimits( int& minplayers, int& maxplayers, int &defaultMaxPlayers ) const OVERRIDE;
  39. // returns number of delay ticks if player is in Replay mode (0 = no delay)
  40. virtual int GetReplayDelay( edict_t *player, int& entity ) OVERRIDE;
  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 ) OVERRIDE;
  44. virtual void NetworkIDValidated( const char *pszUserName, const char *pszNetworkID ) OVERRIDE;
  45. // The client has submitted a keyvalues command
  46. virtual void ClientCommandKeyValues( edict_t *pEntity, KeyValues *pKeyValues ) OVERRIDE;
  47. // Notify that the player is spawned
  48. virtual void ClientSpawned( edict_t *pPlayer ) OVERRIDE;
  49. };
  50. class CServerGameDLL : public IServerGameDLL
  51. {
  52. public:
  53. virtual bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory,
  54. CreateInterfaceFn fileSystemFactory, CGlobalVars *pGlobals) OVERRIDE;
  55. virtual void DLLShutdown( void ) OVERRIDE;
  56. // Get the simulation interval (must be compiled with identical values into both client and game .dll for MOD!!!)
  57. virtual bool ReplayInit( CreateInterfaceFn fnReplayFactory ) OVERRIDE;
  58. virtual float GetTickInterval( void ) const OVERRIDE;
  59. virtual bool GameInit( void ) OVERRIDE;
  60. virtual void GameShutdown( void ) OVERRIDE;
  61. virtual bool LevelInit( const char *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background ) OVERRIDE;
  62. virtual void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax ) OVERRIDE;
  63. virtual void LevelShutdown( void ) OVERRIDE;
  64. virtual void GameFrame( bool simulating ) OVERRIDE; // could be called multiple times before sending data to clients
  65. virtual void PreClientUpdate( bool simulating ) OVERRIDE; // called after all GameFrame() calls, before sending data to clients
  66. virtual ServerClass* GetAllServerClasses( void ) OVERRIDE;
  67. virtual const char *GetGameDescription( void ) OVERRIDE;
  68. virtual void CreateNetworkStringTables( void ) OVERRIDE;
  69. // Save/restore system hooks
  70. virtual CSaveRestoreData *SaveInit( int size ) OVERRIDE;
  71. virtual void SaveWriteFields( CSaveRestoreData *, char const* , void *, datamap_t *, typedescription_t *, int ) OVERRIDE;
  72. virtual void SaveReadFields( CSaveRestoreData *, char const* , void *, datamap_t *, typedescription_t *, int ) OVERRIDE;
  73. virtual void SaveGlobalState( CSaveRestoreData * ) OVERRIDE;
  74. virtual void RestoreGlobalState( CSaveRestoreData * ) OVERRIDE;
  75. virtual int CreateEntityTransitionList( CSaveRestoreData *, int ) OVERRIDE;
  76. virtual void BuildAdjacentMapList( void ) OVERRIDE;
  77. virtual void PreSave( CSaveRestoreData * ) OVERRIDE;
  78. virtual void Save( CSaveRestoreData * ) OVERRIDE;
  79. virtual void GetSaveComment( char *comment, int maxlength, float flMinutes, float flSeconds, bool bNoTime = false ) OVERRIDE;
  80. #ifdef _XBOX
  81. virtual void GetTitleName( const char *pMapName, char* pTitleBuff, int titleBuffSize ) OVERRIDE;
  82. #endif
  83. virtual void WriteSaveHeaders( CSaveRestoreData * ) OVERRIDE;
  84. virtual void ReadRestoreHeaders( CSaveRestoreData * ) OVERRIDE;
  85. virtual void Restore( CSaveRestoreData *, bool ) OVERRIDE;
  86. virtual bool IsRestoring() OVERRIDE;
  87. // Retrieve info needed for parsing the specified user message
  88. virtual bool GetUserMessageInfo( int msg_type, char *name, int maxnamelength, int& size ) OVERRIDE;
  89. virtual CStandardSendProxies* GetStandardSendProxies() OVERRIDE;
  90. virtual void PostInit() OVERRIDE;
  91. virtual void Think( bool finalTick ) OVERRIDE;
  92. virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue ) OVERRIDE;
  93. virtual void PreSaveGameLoaded( char const *pSaveName, bool bInGame ) OVERRIDE;
  94. // Returns true if the game DLL wants the server not to be made public.
  95. // Used by commentary system to hide multiplayer commentary servers from the master.
  96. virtual bool ShouldHideServer( void ) OVERRIDE;
  97. virtual void InvalidateMdlCache() OVERRIDE;
  98. virtual void SetServerHibernation( bool bHibernating ) OVERRIDE;
  99. float m_fAutoSaveDangerousTime;
  100. float m_fAutoSaveDangerousMinHealthToCommit;
  101. bool m_bIsHibernating;
  102. // Called after the steam API has been activated post-level startup
  103. virtual void GameServerSteamAPIActivated( void ) OVERRIDE;
  104. // Called after the steam API has been shutdown post-level startup
  105. virtual void GameServerSteamAPIShutdown( void ) OVERRIDE;
  106. // interface to the new GC based lobby system
  107. virtual IServerGCLobby *GetServerGCLobby() OVERRIDE;
  108. virtual const char *GetServerBrowserMapOverride() OVERRIDE;
  109. virtual const char *GetServerBrowserGameData() OVERRIDE;
  110. // Called to add output to the status command
  111. virtual void Status( void (*print) (const char *fmt, ...) ) OVERRIDE;
  112. virtual void PrepareLevelResources( /* in/out */ char *pszMapName, size_t nMapNameSize,
  113. /* in/out */ char *pszMapFile, size_t nMapFileSize ) OVERRIDE;
  114. virtual ePrepareLevelResourcesResult AsyncPrepareLevelResources( /* in/out */ char *pszMapName, size_t nMapNameSize,
  115. /* in/out */ char *pszMapFile, size_t nMapFileSize,
  116. float *flProgress = NULL ) OVERRIDE;
  117. virtual eCanProvideLevelResult CanProvideLevel( /* in/out */ char *pMapName, int nMapNameMax ) OVERRIDE;
  118. // Called to see if the game server is okay with a manual changelevel or map command
  119. virtual bool IsManualMapChangeOkay( const char **pszReason ) OVERRIDE;
  120. private:
  121. // This can just be a wrapper on MapEntity_ParseAllEntities, but CS does some tricks in here
  122. // with the entity list.
  123. void LevelInit_ParseAllEntities( const char *pMapEntities );
  124. void LoadMessageOfTheDay();
  125. void LoadSpecificMOTDMsg( const ConVar &convar, const char *pszStringName );
  126. };
  127. // Normally, when the engine calls ClientPutInServer, it calls a global function in the game DLL
  128. // by the same name. Use this to override the function that it calls. This is used for bots.
  129. typedef CBasePlayer* (*ClientPutInServerOverrideFn)( edict_t *pEdict, const char *playername );
  130. void ClientPutInServerOverride( ClientPutInServerOverrideFn fn );
  131. // -------------------------------------------------------------------------------------------- //
  132. // Entity list management stuff.
  133. // -------------------------------------------------------------------------------------------- //
  134. // These are created for map entities in order as the map entities are spawned.
  135. class CMapEntityRef
  136. {
  137. public:
  138. int m_iEdict; // Which edict slot this entity got. -1 if CreateEntityByName failed.
  139. int m_iSerialNumber; // The edict serial number. TODO used anywhere ?
  140. };
  141. extern CUtlLinkedList<CMapEntityRef, unsigned short> g_MapEntityRefs;
  142. //-----------------------------------------------------------------------------
  143. // Purpose:
  144. //-----------------------------------------------------------------------------
  145. class CMapLoadEntityFilter : public IMapEntityFilter
  146. {
  147. public:
  148. virtual bool ShouldCreateEntity( const char *pClassname )
  149. {
  150. // During map load, create all the entities.
  151. return true;
  152. }
  153. virtual CBaseEntity* CreateNextEntity( const char *pClassname )
  154. {
  155. CBaseEntity *pRet = CreateEntityByName( pClassname );
  156. CMapEntityRef ref;
  157. ref.m_iEdict = -1;
  158. ref.m_iSerialNumber = -1;
  159. if ( pRet )
  160. {
  161. ref.m_iEdict = pRet->entindex();
  162. if ( pRet->edict() )
  163. ref.m_iSerialNumber = pRet->edict()->m_NetworkSerialNumber;
  164. }
  165. g_MapEntityRefs.AddToTail( ref );
  166. return pRet;
  167. }
  168. };
  169. bool IsEngineThreaded();
  170. class CServerGameTags : public IServerGameTags
  171. {
  172. public:
  173. virtual void GetTaggedConVarList( KeyValues *pCvarTagList );
  174. };
  175. EXPOSE_SINGLE_INTERFACE( CServerGameTags, IServerGameTags, INTERFACEVERSION_SERVERGAMETAGS );
  176. #endif // GAMEINTERFACE_H