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.

282 lines
8.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #if !defined( CLIENT_H )
  14. #define CLIENT_H
  15. #ifdef _WIN32
  16. #pragma once
  17. #endif
  18. #include <qlimits.h>
  19. #include <utllinkedlist.h>
  20. #include <convar.h>
  21. #include <checksum_crc.h>
  22. #include <protocol.h>
  23. #include <cdll_int.h>
  24. #include <globalvars_base.h>
  25. #include <soundflags.h>
  26. #include <utlvector.h>
  27. #include "host.h"
  28. #include "event_system.h"
  29. #include "precache.h"
  30. #include "baseclientstate.h"
  31. #include "clientframe.h"
  32. struct model_t;
  33. struct SoundInfo_t;
  34. class ClientClass;
  35. class CSfxTable;
  36. class CPureServerWhitelist;
  37. #define MAX_DEMOS 32
  38. struct AddAngle
  39. {
  40. float total;
  41. float starttime;
  42. };
  43. //-----------------------------------------------------------------------------
  44. // Purpose: CClientState should hold all pieces of the client state
  45. // The client_state_t structure is wiped completely at every server signon
  46. //-----------------------------------------------------------------------------
  47. class CClientState : public CBaseClientState, public CClientFrameManager
  48. {
  49. typedef struct CustomFile_s
  50. {
  51. CRC32_t crc; //file CRC
  52. unsigned int reqID; // download request ID
  53. } CustomFile_t;
  54. public:
  55. CClientState();
  56. ~CClientState();
  57. public: // IConnectionlessPacketHandler interface:
  58. bool ProcessConnectionlessPacket(struct netpacket_s *packet);
  59. public: // CBaseClientState overrides:
  60. void Disconnect( const char *pszReason, bool bShowMainMenu );
  61. void FullConnect( netadr_t &adr );
  62. bool SetSignonState ( int state, int count );
  63. void PacketStart(int incoming_sequence, int outgoing_acknowledged);
  64. void PacketEnd( void );
  65. void FileReceived( const char *fileName, unsigned int transferID );
  66. void FileRequested(const char *fileName, unsigned int transferID );
  67. void FileDenied(const char *fileName, unsigned int transferID );
  68. void FileSent( const char *fileName, unsigned int transferID );
  69. void ConnectionCrashed( const char * reason );
  70. void ConnectionClosing( const char * reason );
  71. const char *GetCDKeyHash( void );
  72. void SetFriendsID( uint friendsID, const char *friendsName );
  73. void SendClientInfo( void );
  74. void SendServerCmdKeyValues( KeyValues *pKeyValues );
  75. void InstallStringTableCallback( char const *tableName );
  76. bool HookClientStringTable( char const *tableName );
  77. bool InstallEngineStringTableCallback( char const *tableName );
  78. void StartUpdatingSteamResources();
  79. void CheckUpdatingSteamResources();
  80. void CheckFileCRCsWithServer();
  81. void FinishSignonState_New();
  82. void ConsistencyCheck(bool bForce);
  83. void RunFrame();
  84. void ReadEnterPVS( CEntityReadInfo &u );
  85. void ReadLeavePVS( CEntityReadInfo &u );
  86. void ReadDeltaEnt( CEntityReadInfo &u );
  87. void ReadPreserveEnt( CEntityReadInfo &u );
  88. void ReadDeletions( CEntityReadInfo &u );
  89. // In case the client DLL is using the old interface to set area bits,
  90. // copy what they've passed to us into the m_chAreaBits array (and 0xFF-out the m_chAreaPortalBits array).
  91. void UpdateAreaBits_BackwardsCompatible();
  92. // Used to be pAreaBits.
  93. unsigned char** GetAreaBits_BackwardCompatibility();
  94. public: // IServerMessageHandlers
  95. PROCESS_NET_MESSAGE( Tick );
  96. PROCESS_NET_MESSAGE( StringCmd );
  97. PROCESS_SVC_MESSAGE( ServerInfo );
  98. PROCESS_SVC_MESSAGE( ClassInfo );
  99. PROCESS_SVC_MESSAGE( SetPause );
  100. PROCESS_SVC_MESSAGE( VoiceInit );
  101. PROCESS_SVC_MESSAGE( VoiceData );
  102. PROCESS_SVC_MESSAGE( Sounds );
  103. PROCESS_SVC_MESSAGE( FixAngle );
  104. PROCESS_SVC_MESSAGE( CrosshairAngle );
  105. PROCESS_SVC_MESSAGE( BSPDecal );
  106. PROCESS_SVC_MESSAGE( GameEvent );
  107. PROCESS_SVC_MESSAGE( UserMessage );
  108. PROCESS_SVC_MESSAGE( EntityMessage );
  109. PROCESS_SVC_MESSAGE( PacketEntities );
  110. PROCESS_SVC_MESSAGE( TempEntities );
  111. PROCESS_SVC_MESSAGE( Prefetch );
  112. PROCESS_SVC_MESSAGE( SetPauseTimed );
  113. public:
  114. float m_flLastServerTickTime; // the timestamp of last message
  115. bool insimulation;
  116. int oldtickcount; // previous tick
  117. float m_tickRemainder; // client copy of tick remainder
  118. float m_frameTime; // dt of the current frame
  119. int lastoutgoingcommand;// Sequence number of last outgoing command
  120. int chokedcommands; // number of choked commands
  121. int last_command_ack; // last command sequence number acknowledged by server
  122. int command_ack; // current command sequence acknowledged by server
  123. int m_nSoundSequence; // current processed reliable sound sequence number
  124. //
  125. // information that is static for the entire time connected to a server
  126. //
  127. bool ishltv; // true if HLTV server/demo
  128. #if defined( REPLAY_ENABLED )
  129. bool isreplay; // true if Replay server/demo
  130. #endif
  131. MD5Value_t serverMD5; // To determine if client is playing hacked .map. (entities lump is skipped)
  132. unsigned char m_chAreaBits[MAX_AREA_STATE_BYTES];
  133. unsigned char m_chAreaPortalBits[MAX_AREA_PORTAL_STATE_BYTES];
  134. bool m_bAreaBitsValid; // Have the area bits been set for this level yet?
  135. // refresh related state
  136. QAngle viewangles;
  137. CUtlVector< AddAngle > addangle;
  138. float addangletotal;
  139. float prevaddangletotal;
  140. int cdtrack; // cd audio
  141. CustomFile_t m_nCustomFiles[MAX_CUSTOM_FILES]; // own custom files CRCs
  142. uint m_nFriendsID;
  143. char m_FriendsName[MAX_PLAYER_NAME_LENGTH];
  144. CUtlFixedLinkedList< CEventInfo > events; // list of received events
  145. // demo loop control
  146. int demonum; // -1 = don't play demos
  147. CUtlString demos[MAX_DEMOS]; // when not playing
  148. public:
  149. // If 'insimulation', returns the time (in seconds) at the client's current tick.
  150. // Otherwise, returns the exact client clock.
  151. float GetTime() const;
  152. bool IsPaused() const;
  153. float GetPausedExpireTime() const { return m_flPausedExpireTime; }
  154. float GetFrameTime( void ) const;
  155. void SetFrameTime( float dt ) { m_frameTime = dt; }
  156. float GetClientInterpAmount(); // Formerly cl_interp, now based on cl_interp_ratio and cl_updaterate.
  157. void Clear( void );
  158. void DumpPrecacheStats( const char * name );
  159. // Public API to models
  160. model_t *GetModel( int index );
  161. void SetModel( int tableIndex );
  162. int LookupModelIndex( char const *name );
  163. // Public API to generic
  164. char const *GetGeneric( int index );
  165. void SetGeneric( int tableIndex );
  166. int LookupGenericIndex( char const *name );
  167. // Public API to sounds
  168. CSfxTable *GetSound( int index );
  169. char const *GetSoundName( int index );
  170. void SetSound( int tableIndex );
  171. int LookupSoundIndex( char const *name );
  172. void ClearSounds();
  173. // Public API to decals
  174. char const *GetDecalName( int index );
  175. void SetDecal( int tableIndex );
  176. // customization files code
  177. void CheckOwnCustomFiles(); // load own custom file
  178. void CheckOthersCustomFile(CRC32_t crc); // check if we have to download custom files from server
  179. void AddCustomFile( int slot, const char *resourceFile);
  180. public:
  181. INetworkStringTable *m_pModelPrecacheTable;
  182. INetworkStringTable *m_pGenericPrecacheTable;
  183. INetworkStringTable *m_pSoundPrecacheTable;
  184. INetworkStringTable *m_pDecalPrecacheTable;
  185. INetworkStringTable *m_pInstanceBaselineTable;
  186. INetworkStringTable *m_pLightStyleTable;
  187. INetworkStringTable *m_pUserInfoTable;
  188. INetworkStringTable *m_pServerStartupTable;
  189. INetworkStringTable *m_pDownloadableFileTable;
  190. INetworkStringTable *m_pDynamicModelsTable;
  191. CPrecacheItem model_precache[ MAX_MODELS ];
  192. CPrecacheItem generic_precache[ MAX_GENERIC ];
  193. CPrecacheItem sound_precache[ MAX_SOUNDS ];
  194. CPrecacheItem decal_precache[ MAX_BASE_DECALS ];
  195. WaitForResourcesHandle_t m_hWaitForResourcesHandle;
  196. bool m_bUpdateSteamResources;
  197. bool m_bShownSteamResourceUpdateProgress;
  198. bool m_bDownloadResources;
  199. bool m_bPrepareClientDLL;
  200. bool m_bCheckCRCsWithServer;
  201. float m_flLastCRCBatchTime;
  202. // This is only kept around to print out the whitelist info if sv_pure is used.
  203. CPureServerWhitelist *m_pPureServerWhitelist;
  204. IFileList *m_pPendingPureFileReloads;
  205. private:
  206. void ProcessSoundsWithProtoVersion( SVC_Sounds *msg, CUtlVector< SoundInfo_t > &sounds, int nProtoVersion );
  207. private:
  208. // Note: This is only here for backwards compatibility. If it is set to something other than NULL,
  209. // then we'll copy its contents into m_chAreaBits in UpdateAreaBits_BackwardsCompatible.
  210. byte *m_pAreaBits;
  211. // Set to false when we first connect to a server and true later on before we
  212. // respond to a new whitelist.
  213. bool m_bMarkedCRCsUnverified;
  214. }; //CClientState
  215. extern CClientState cl;
  216. #ifndef SWDS
  217. extern CGlobalVarsBase g_ClientGlobalVariables;
  218. #endif
  219. extern bool g_bClientGameDLLGreaterThanV13;
  220. #endif // CLIENT_H