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.

236 lines
7.8 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // CGameClient: represents a player client in a game server
  4. //
  5. //===========================================================================//
  6. #ifndef SV_CLIENT_H
  7. #define SV_CLIENT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "const.h"
  12. #include "bitbuf.h"
  13. #include "net.h"
  14. #include "checksum_crc.h"
  15. #include "event_system.h"
  16. #include "utlvector.h"
  17. #include "bitvec.h"
  18. #include "protocol.h"
  19. #include <inetmsghandler.h>
  20. #include "baseclient.h"
  21. #include "clientframe.h"
  22. #include <soundinfo.h>
  23. struct HltvReplayStats_t
  24. {
  25. enum FailEnum_t
  26. {
  27. FAILURE_ALREADY_IN_REPLAY,
  28. FAILURE_TOO_FREQUENT,
  29. FAILURE_NO_FRAME,
  30. FAILURE_NO_FRAME2,
  31. FAILURE_CANNOT_MATCH_DELAY,
  32. FAILURE_FRAME_NOT_READY,
  33. NUM_FAILURES
  34. };
  35. uint nClients;
  36. uint nStartRequests;
  37. uint nSuccessfulStarts;
  38. uint nStopRequests;
  39. uint nAbortStopRequests;
  40. uint nUserCancels;
  41. uint nFullReplays;
  42. uint nNetAbortReplays;
  43. uint nFailedReplays[NUM_FAILURES];
  44. HltvReplayStats_t()
  45. {
  46. Reset();
  47. }
  48. void Reset()
  49. {
  50. V_memset( this, 0, sizeof( *this ) );
  51. nClients = 1;
  52. }
  53. void operator += ( const HltvReplayStats_t &other )
  54. {
  55. this->nClients += other.nClients;
  56. this->nStartRequests += other.nStartRequests;
  57. this->nSuccessfulStarts += other.nSuccessfulStarts;
  58. this->nStopRequests += other.nStopRequests;
  59. this->nUserCancels += other.nUserCancels;
  60. this->nAbortStopRequests += other.nAbortStopRequests;
  61. this->nFullReplays += other.nFullReplays;
  62. this->nNetAbortReplays += other.nNetAbortReplays;
  63. for ( int i = 0; i < NUM_FAILURES; ++i )
  64. this->nFailedReplays[i] += other.nFailedReplays[i];
  65. }
  66. const char *AsString()const;
  67. };
  68. //-----------------------------------------------------------------------------
  69. // Forward declarations
  70. //-----------------------------------------------------------------------------
  71. class INetChannel;
  72. class CClientFrame;
  73. class CFrameSnapshot;
  74. class CClientMsgHandler;
  75. struct edict_t;
  76. struct SoundInfo_t;
  77. class KeyValues;
  78. class CHLTVServer;
  79. class CReplayServer;
  80. class CPerClientLogoInfo;
  81. class CCommand;
  82. class CSVCMsg_Sounds;
  83. class CHLTVClient;
  84. //-----------------------------------------------------------------------------
  85. // CGameClient: represents a player client in a game server
  86. //-----------------------------------------------------------------------------
  87. class CGameClient : public CBaseClient, public CClientFrameManager
  88. {
  89. typedef CBaseClient BaseClass;
  90. public:
  91. CGameClient(int slot, CBaseServer *pServer);
  92. ~CGameClient();
  93. // INetMsgHandler interface
  94. void ConnectionClosing( const char *reason );
  95. void ConnectionCrashed(const char *reason);
  96. void PacketStart (int incoming_sequence, int outgoing_acknowledged);
  97. void PacketEnd( void );
  98. void FileReceived( const char *fileName, unsigned int transferID, bool bIsReplayDemoFile = false );
  99. void FileRequested(const char *fileName, unsigned int transferID, bool bIsReplayDemoFile = false );
  100. void FileDenied( const char *fileName, unsigned int transferID, bool bIsReplayDemoFile = false );
  101. void FileSent( const char *fileName, unsigned int transferID, bool bIsReplayDemoFile = false );
  102. bool ProcessConnectionlessPacket( netpacket_t *packet );
  103. // IClient interface
  104. void Connect(const char * szName, int nUserID, INetChannel *pNetChannel, bool bFakePlayer, CrossPlayPlatform_t clientPlatform, const CMsg_CVars *pVecCvars ) OVERRIDE;
  105. void Inactivate( void );
  106. void Reconnect( void );
  107. void Disconnect( const char *reason ) OVERRIDE;
  108. bool CheckConnect( void );
  109. void SetRate( int nRate, bool bForce );
  110. void SetUpdateRate( float fUpdateRate, bool bForce ); // override;
  111. virtual bool IsHearingClient( int index ) const;
  112. virtual bool IsProximityHearingClient( int index ) const;
  113. void Clear( void );
  114. bool SendNetMsg( INetMessage &msg, bool bForceReliable = false, bool bVoice = false );
  115. bool ExecuteStringCommand( const char *s );
  116. // IGameEventListener
  117. void FireGameEvent( IGameEvent *event ) OVERRIDE;
  118. public: // IClientMessageHandlers
  119. virtual bool CLCMsg_ClientInfo( const CCLCMsg_ClientInfo& msg ) OVERRIDE;
  120. virtual bool CLCMsg_Move( const CCLCMsg_Move& msg ) OVERRIDE;
  121. virtual bool CLCMsg_VoiceData( const CCLCMsg_VoiceData& msg ) OVERRIDE;
  122. virtual bool CLCMsg_RespondCvarValue( const CCLCMsg_RespondCvarValue& msg ) OVERRIDE;
  123. virtual bool CLCMsg_FileCRCCheck( const CCLCMsg_FileCRCCheck& msg ) OVERRIDE;
  124. virtual bool CLCMsg_CmdKeyValues( const CCLCMsg_CmdKeyValues& msg ) OVERRIDE;
  125. virtual bool CLCMsg_HltvReplay( const CCLCMsg_HltvReplay &msg ) OVERRIDE;
  126. virtual bool SVCMsg_UserMessage( const CSVCMsg_UserMessage &msg ) OVERRIDE;
  127. public:
  128. void UpdateUserSettings( void );
  129. bool UpdateAcknowledgedFramecount(int tick);
  130. void WriteGameSounds( bf_write &buf, int nMaxSounds );
  131. virtual bool ProcessSignonStateMsg(int state, int spawncount);
  132. bool SendSnapshot( CClientFrame *pFrame ) OVERRIDE;
  133. bool SendHltvReplaySnapshot( CClientFrame * pFrame );
  134. bool ShouldSendMessages( void );
  135. void SpawnPlayer( void );
  136. bool SendSignonData( void );
  137. void ActivatePlayer( void );
  138. void SetupHltvFrame( int nServerTick );
  139. void SetupPackInfo( CFrameSnapshot *pSnapshot );
  140. void SetupPrevPackInfo();
  141. void DownloadCustomizations();
  142. void WriteViewAngleUpdate( void );
  143. CClientFrame *GetDeltaFrame( int nTick );
  144. CClientFrame *GetSendFrame();
  145. void SendSound( SoundInfo_t &sound, bool isReliable );
  146. void GetReplayData( int& ticks, int& entity);
  147. bool IgnoreTempEntity( CEventInfo *event );
  148. const CCheckTransmitInfo* GetPrevPackInfo();
  149. virtual bool StartHltvReplay( const HltvReplayParams_t &params ) OVERRIDE;
  150. virtual bool CanStartHltvReplay() OVERRIDE;
  151. virtual void ResetReplayRequestTime() OVERRIDE;
  152. void StepHltvReplayStatus( int nServerTick );
  153. virtual int GetHltvReplayDelay() OVERRIDE { return m_nHltvReplayDelay; }
  154. virtual const char * GetHltvReplayStatus()const OVERRIDE { return m_HltvReplayStats.AsString(); }
  155. virtual void StopHltvReplay() OVERRIDE;
  156. bool IsHltvReplay() { return m_nHltvReplayDelay > 0; }
  157. //CHLTVServer *GetCurrentHltvReplayServerSource() { return IsHltvReplay() ? m_pHltvReplayServer : NULL; }
  158. virtual CBaseClient *GetPropCullClient() OVERRIDE;
  159. protected:
  160. virtual void PerformDisconnection( const char *pReason );
  161. private:
  162. bool IsEngineClientCommand( const CCommand &args ) const;
  163. int FillSoundsMessage( CSVCMsg_Sounds &msg, int nMaxSounds );
  164. public:
  165. bool m_bVoiceLoopback; // if true, client wants own voice loopback
  166. CPlayerBitVec m_VoiceStreams; // Which other clients does this guy's voice stream go to?
  167. CPlayerBitVec m_VoiceProximity; // Should we use proximity for this guy?
  168. int m_LastMovementTick; // for move commands
  169. int m_nSoundSequence; // increases with each reliable sound
  170. // Identity information.
  171. edict_t *edict; // EDICT_NUM(clientnum+1)
  172. CUtlVector<SoundInfo_t> m_Sounds; // game sounds
  173. const edict_t *m_pViewEntity; // View Entity (camera or the client itself)
  174. CClientFrame *m_pCurrentFrame; // last added frame
  175. CCheckTransmitInfo m_PackInfo;
  176. bool m_bIsInReplayMode;
  177. CCheckTransmitInfo m_PrevPackInfo; // Used to speed up CheckTransmit.
  178. CBitVec<MAX_EDICTS> m_PrevTransmitEdict;
  179. float m_flTimeClientBecameFullyConnected;
  180. double m_flLastClientCommandQuotaStart;
  181. int m_numClientCommandsInQuota;
  182. int m_nHltvReplayDelay;
  183. CHLTVServer *m_pHltvReplayServer;
  184. int m_nHltvReplayStopAt;
  185. int m_nHltvReplayStartAt;
  186. int m_nHltvReplaySlowdownBeginAt;
  187. int m_nHltvReplaySlowdownEndAt;
  188. float m_flHltvReplaySlowdownRate;
  189. int m_nHltvLastSendTick; // last send tick, don't send ticks twice
  190. float m_flHltvLastReplayRequestTime; // tick at which the last time replay was requested
  191. CUtlVector< INetMessage * > m_HltvQueuedMessages; // it'd probably be more optimal, memory-wise, to make a linked list, but a vector is more readable and debuggable
  192. HltvReplayStats_t m_HltvReplayStats;
  193. };
  194. #endif // SV_CLIENT_H