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.

200 lines
5.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #if !defined( SERVER_H )
  9. #define SERVER_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "basetypes.h"
  14. #include "filesystem.h"
  15. #include "packed_entity.h"
  16. #include "bitbuf.h"
  17. #include "netadr.h"
  18. #include "checksum_crc.h"
  19. #include "quakedef.h"
  20. #include "engine/IEngineSound.h"
  21. #include "precache.h"
  22. #include "sv_client.h"
  23. #include "baseserver.h"
  24. #include <ihltvdirector.h>
  25. class CGameTrace;
  26. class ITraceFilter;
  27. class CEventInfo;
  28. typedef CGameTrace trace_t;
  29. typedef int TABLEID;
  30. class IChangeInfoAccessor;
  31. class CPureServerWhitelist;
  32. // find a server class
  33. ServerClass* SV_FindServerClass( const char *pName );
  34. ServerClass* SV_FindServerClass( int index );
  35. //=============================================================================
  36. // Max # of master servers this server can be associated with
  37. class CGameServer : public CBaseServer
  38. {
  39. public:
  40. CGameServer();
  41. virtual ~CGameServer();
  42. public: // IServer implementation
  43. bool IsPausable( void ) const;
  44. void Init( bool isDedicated );
  45. void Clear( void );
  46. void Shutdown( void );
  47. void SetMaxClients(int number);
  48. public:
  49. void InitMaxClients( void );
  50. bool SpawnServer( const char *szMapName, const char *szMapFile, const char *startspot );
  51. void SetQueryPortFromSteamServer();
  52. void CopyPureServerWhitelistToStringTable();
  53. void RemoveClientFromGame( CBaseClient *client );
  54. void SendClientMessages ( bool bSendSnapshots );
  55. void FinishRestore();
  56. void BroadcastSound( SoundInfo_t &sound, IRecipientFilter &filter );
  57. bool IsLevelMainMenuBackground( void ) { return m_bIsLevelMainMenuBackground; }
  58. // This is true when we start a level and sv_pure is set to 1.
  59. bool IsInPureServerMode() const;
  60. CPureServerWhitelist * GetPureServerWhitelist() const;
  61. inline CGameClient *Client( int i ) { return static_cast<CGameClient*>(m_Clients[i]); };
  62. protected :
  63. // Reload the whitelist files for pure server mode.
  64. void ReloadWhitelist( const char *pMapName );
  65. CBaseClient *CreateNewClient( int slot );
  66. bool FinishCertificateCheck( netadr_t &adr, int nAuthProtocol, const char *szRawCertificate, int clientChallenge );
  67. void SendClientDatagrams ( int clientCount, CGameClient** clients, CFrameSnapshot* pSnapshot );
  68. void CopyTempEntities( CFrameSnapshot* pSnapshot );
  69. void AssignClassIds();
  70. virtual void UpdateMasterServerPlayers();
  71. // Data
  72. public:
  73. bool m_bLoadgame; // handle connections specially
  74. char m_szStartspot[64];
  75. int num_edicts;
  76. int max_edicts;
  77. int free_edicts; // how many edicts in num_edicts are free, in use is num_edicts - free_edicts
  78. edict_t *edicts; // Can array index now, edict_t is fixed
  79. IChangeInfoAccessor *edictchangeinfo; // HACK to allow backward compat since we can't change edict_t layout
  80. int m_nMaxClientsLimit; // Max allowed on server.
  81. bool allowsignonwrites;
  82. bool dll_initialized; // Have we loaded the game dll.
  83. bool m_bIsLevelMainMenuBackground; // true if the level running only as the background to the main menu
  84. CUtlVector<CEventInfo*> m_TempEntities; // temp entities
  85. bf_write m_FullSendTables;
  86. CUtlMemory<byte> m_FullSendTablesBuffer;
  87. bool m_bLoadedPlugins;
  88. public:
  89. // New style precache lists are done this way
  90. void CreateEngineStringTables( void );
  91. INetworkStringTable *GetModelPrecacheTable( void ) const;
  92. INetworkStringTable *GetGenericPrecacheTable( void ) const;
  93. INetworkStringTable *GetSoundPrecacheTable( void ) const;
  94. INetworkStringTable *GetDecalPrecacheTable( void ) const;
  95. INetworkStringTable *GetDynamicModelsTable( void ) const { return m_pDynamicModelsTable; }
  96. // Accessors to model precaching stuff
  97. int PrecacheModel( char const *name, int flags, model_t *model = NULL );
  98. model_t *GetModel( int index );
  99. int LookupModelIndex( char const *name );
  100. // Accessors to model precaching stuff
  101. int PrecacheSound( char const *name, int flags );
  102. char const *GetSound( int index );
  103. int LookupSoundIndex( char const *name );
  104. int PrecacheGeneric( char const *name, int flags );
  105. char const *GetGeneric( int index );
  106. int LookupGenericIndex( char const *name );
  107. int PrecacheDecal( char const *name, int flags );
  108. int LookupDecalIndex( char const *name );
  109. void DumpPrecacheStats( INetworkStringTable *table );
  110. bool IsHibernating() const;
  111. void UpdateHibernationState();
  112. private:
  113. void SetHibernating( bool bHibernating );
  114. CPrecacheItem model_precache[ MAX_MODELS ];
  115. CPrecacheItem generic_precache[ MAX_GENERIC ];
  116. CPrecacheItem sound_precache[ MAX_SOUNDS ];
  117. CPrecacheItem decal_precache[ MAX_BASE_DECALS ];
  118. INetworkStringTable *m_pModelPrecacheTable;
  119. INetworkStringTable *m_pSoundPrecacheTable;
  120. INetworkStringTable *m_pGenericPrecacheTable;
  121. INetworkStringTable *m_pDecalPrecacheTable;
  122. INetworkStringTable *m_pDynamicModelsTable;
  123. CPureServerWhitelist *m_pPureServerWhitelist;
  124. bool m_bHibernating; // Are we hibernating. Hibernation makes server process consume approx 0 CPU when no clients are connected
  125. };
  126. //============================================================================
  127. class IServerGameDLL;
  128. class IServerGameEnts;
  129. class IServerGameClients;
  130. class IServerGameTags;
  131. extern IServerGameDLL *serverGameDLL;
  132. extern int g_iServerGameDLLVersion;
  133. extern IServerGameEnts *serverGameEnts;
  134. extern IServerGameClients *serverGameClients;
  135. extern int g_iServerGameClientsVersion; // This matches the number at the end of the interface name (so for "ServerGameClients004", this would be 4).
  136. extern IHLTVDirector *serverGameDirector;
  137. extern IServerGameTags *serverGameTags;
  138. // Master server address struct for use in building heartbeats
  139. extern ConVar skill;
  140. extern ConVar deathmatch;
  141. extern ConVar coop;
  142. extern CGameServer sv; // local server
  143. extern CGameClient *host_client; // current processing client
  144. #endif // SERVER_H