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.

213 lines
6.0 KiB

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