/ghost/gameplayer.h

http://ghostcb.googlecode.com/ · C Header · 222 lines · 166 code · 25 blank · 31 comment · 0 complexity · e3315bf1270d87cc885d662057276ef3 MD5 · raw file

  1. /*
  2. Copyright [2008] [Trevor Hogan]
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. CODE PORTED FROM THE ORIGINAL GHOST PROJECT: http://ghost.pwner.org/
  13. */
  14. #ifndef GAMEPLAYER_H
  15. #define GAMEPLAYER_H
  16. class CTCPSocket;
  17. class CCommandPacket;
  18. class CGameProtocol;
  19. class CGame;
  20. class CIncomingJoinPlayer;
  21. //
  22. // CPotentialPlayer
  23. //
  24. class CPotentialPlayer
  25. {
  26. public:
  27. CGameProtocol *m_Protocol;
  28. CBaseGame *m_Game;
  29. protected:
  30. // note: we permit m_Socket to be NULL in this class to allow for the virtual host player which doesn't really exist
  31. // it also allows us to convert CPotentialPlayers to CGamePlayers without the CPotentialPlayer's destructor closing the socket
  32. CTCPSocket *m_Socket;
  33. queue<CCommandPacket *> m_Packets;
  34. bool m_DeleteMe;
  35. bool m_Error;
  36. string m_ErrorString;
  37. CIncomingJoinPlayer *m_IncomingJoinPlayer;
  38. public:
  39. CPotentialPlayer( CGameProtocol *nProtocol, CBaseGame *nGame, CTCPSocket *nSocket );
  40. virtual ~CPotentialPlayer( );
  41. virtual CTCPSocket *GetSocket( ) { return m_Socket; }
  42. virtual BYTEARRAY GetExternalIP( );
  43. virtual string GetExternalIPString( );
  44. virtual queue<CCommandPacket *> GetPackets( ) { return m_Packets; }
  45. virtual bool GetDeleteMe( ) { return m_DeleteMe; }
  46. virtual bool GetError( ) { return m_Error; }
  47. virtual string GetErrorString( ) { return m_ErrorString; }
  48. virtual CIncomingJoinPlayer *GetJoinPlayer( ) { return m_IncomingJoinPlayer; }
  49. virtual void SetSocket( CTCPSocket *nSocket ) { m_Socket = nSocket; }
  50. virtual void SetDeleteMe( bool nDeleteMe ) { m_DeleteMe = nDeleteMe; }
  51. // processing functions
  52. virtual bool Update( void *fd );
  53. virtual void ExtractPackets( );
  54. virtual void ProcessPackets( );
  55. // other functions
  56. virtual void Send( BYTEARRAY data );
  57. };
  58. //
  59. // CGamePlayer
  60. //
  61. class CGamePlayer : public CPotentialPlayer
  62. {
  63. private:
  64. unsigned char m_PID;
  65. string m_Name; // the player's name
  66. BYTEARRAY m_InternalIP; // the player's internal IP address as reported by the player when connecting
  67. vector<uint32_t> m_Pings; // store the last few (20) pings received so we can take an average
  68. queue<uint32_t> m_CheckSums; // the last few checksums the player has sent (for detecting desyncs)
  69. string m_LeftReason; // the reason the player left the game
  70. string m_SpoofedRealm; // the realm the player last spoof checked on
  71. string m_JoinedRealm; // the realm the player joined on (probable, can be spoofed)
  72. uint32_t m_TotalPacketsSent;
  73. uint32_t m_TotalPacketsReceived;
  74. uint32_t m_LeftCode; // the code to be sent in W3GS_PLAYERLEAVE_OTHERS for why this player left the game
  75. uint32_t m_LoginAttempts; // the number of attempts to login (used with CAdminGame only)
  76. uint32_t m_SyncCounter; // the number of keepalive packets received from this player
  77. uint32_t m_JoinTime; // GetTime when the player joined the game (used to delay sending the /whois a few seconds to allow for some lag)
  78. uint32_t m_LastMapPartSent; // the last mappart sent to the player (for sending more than one part at a time)
  79. uint32_t m_LastMapPartAcked; // the last mappart acknowledged by the player
  80. uint32_t m_StartedDownloadingTicks; // GetTicks when the player started downloading the map
  81. uint32_t m_FinishedDownloadingTime; // GetTime when the player finished downloading the map
  82. uint32_t m_FinishedLoadingTicks; // GetTicks when the player finished loading the game
  83. uint32_t m_StartedLaggingTicks; // GetTicks when the player started lagging
  84. uint32_t m_StatsSentTime; // GetTime when we sent this player's stats to the chat (to prevent players from spamming !stats)
  85. uint32_t m_StatsDotASentTime; // GetTime when we sent this player's dota stats to the chat (to prevent players from spamming !statsdota)
  86. uint32_t m_LastGProxyWaitNoticeSentTime;
  87. queue<BYTEARRAY> m_LoadInGameData; // queued data to be sent when the player finishes loading when using "load in game"
  88. double m_Score; // the player's generic "score" for the matchmaking algorithm
  89. bool m_LoggedIn; // if the player has logged in or not (used with CAdminGame only)
  90. bool m_Spoofed; // if the player has spoof checked or not
  91. bool m_Reserved; // if the player is reserved (VIP) or not
  92. bool m_WhoisShouldBeSent; // if a battle.net /whois should be sent for this player or not
  93. bool m_WhoisSent; // if we've sent a battle.net /whois for this player yet (for spoof checking)
  94. bool m_DownloadAllowed; // if we're allowed to download the map or not (used with permission based map downloads)
  95. bool m_DownloadStarted; // if we've started downloading the map or not
  96. bool m_DownloadFinished; // if we've finished downloading the map or not
  97. bool m_FinishedLoading; // if the player has finished loading or not
  98. bool m_Lagging; // if the player is lagging or not (on the lag screen)
  99. bool m_DropVote; // if the player voted to drop the laggers or not (on the lag screen)
  100. bool m_KickVote; // if the player voted to kick a player or not
  101. bool m_Muted; // if the player is muted or not
  102. bool m_LeftMessageSent; // if the playerleave message has been sent or not
  103. bool m_GProxy; // if the player is using GProxy++
  104. bool m_GProxyDisconnectNoticeSent; // if a disconnection notice has been sent or not when using GProxy++
  105. queue<BYTEARRAY> m_GProxyBuffer;
  106. uint32_t m_GProxyReconnectKey;
  107. uint32_t m_LastGProxyAckTime;
  108. public:
  109. CGamePlayer( CGameProtocol *nProtocol, CBaseGame *nGame, CTCPSocket *nSocket, unsigned char nPID, string nJoinedRealm, string nName, BYTEARRAY nInternalIP, bool nReserved );
  110. CGamePlayer( CPotentialPlayer *potential, unsigned char nPID, string nJoinedRealm, string nName, BYTEARRAY nInternalIP, bool nReserved );
  111. virtual ~CGamePlayer( );
  112. unsigned char GetPID( ) { return m_PID; }
  113. string GetName( ) { return m_Name; }
  114. BYTEARRAY GetInternalIP( ) { return m_InternalIP; }
  115. unsigned int GetNumPings( ) { return m_Pings.size( ); }
  116. unsigned int GetNumCheckSums( ) { return m_CheckSums.size( ); }
  117. queue<uint32_t> *GetCheckSums( ) { return &m_CheckSums; }
  118. string GetLeftReason( ) { return m_LeftReason; }
  119. string GetSpoofedRealm( ) { return m_SpoofedRealm; }
  120. string GetJoinedRealm( ) { return m_JoinedRealm; }
  121. uint32_t GetLeftCode( ) { return m_LeftCode; }
  122. uint32_t GetLoginAttempts( ) { return m_LoginAttempts; }
  123. uint32_t GetSyncCounter( ) { return m_SyncCounter; }
  124. uint32_t GetJoinTime( ) { return m_JoinTime; }
  125. uint32_t GetLastMapPartSent( ) { return m_LastMapPartSent; }
  126. uint32_t GetLastMapPartAcked( ) { return m_LastMapPartAcked; }
  127. uint32_t GetStartedDownloadingTicks( ) { return m_StartedDownloadingTicks; }
  128. uint32_t GetFinishedDownloadingTime( ) { return m_FinishedDownloadingTime; }
  129. uint32_t GetFinishedLoadingTicks( ) { return m_FinishedLoadingTicks; }
  130. uint32_t GetStartedLaggingTicks( ) { return m_StartedLaggingTicks; }
  131. uint32_t GetStatsSentTime( ) { return m_StatsSentTime; }
  132. uint32_t GetStatsDotASentTime( ) { return m_StatsDotASentTime; }
  133. uint32_t GetLastGProxyWaitNoticeSentTime( ) { return m_LastGProxyWaitNoticeSentTime; }
  134. queue<BYTEARRAY> *GetLoadInGameData( ) { return &m_LoadInGameData; }
  135. double GetScore( ) { return m_Score; }
  136. bool GetLoggedIn( ) { return m_LoggedIn; }
  137. bool GetSpoofed( ) { return m_Spoofed; }
  138. bool GetReserved( ) { return m_Reserved; }
  139. bool GetWhoisShouldBeSent( ) { return m_WhoisShouldBeSent; }
  140. bool GetWhoisSent( ) { return m_WhoisSent; }
  141. bool GetDownloadAllowed( ) { return m_DownloadAllowed; }
  142. bool GetDownloadStarted( ) { return m_DownloadStarted; }
  143. bool GetDownloadFinished( ) { return m_DownloadFinished; }
  144. bool GetFinishedLoading( ) { return m_FinishedLoading; }
  145. bool GetLagging( ) { return m_Lagging; }
  146. bool GetDropVote( ) { return m_DropVote; }
  147. bool GetKickVote( ) { return m_KickVote; }
  148. bool GetMuted( ) { return m_Muted; }
  149. bool GetLeftMessageSent( ) { return m_LeftMessageSent; }
  150. bool GetGProxy( ) { return m_GProxy; }
  151. bool GetGProxyDisconnectNoticeSent( ) { return m_GProxyDisconnectNoticeSent; }
  152. uint32_t GetGProxyReconnectKey( ) { return m_GProxyReconnectKey; }
  153. void SetLeftReason( string nLeftReason ) { m_LeftReason = nLeftReason; }
  154. void SetSpoofedRealm( string nSpoofedRealm ) { m_SpoofedRealm = nSpoofedRealm; }
  155. void SetLeftCode( uint32_t nLeftCode ) { m_LeftCode = nLeftCode; }
  156. void SetLoginAttempts( uint32_t nLoginAttempts ) { m_LoginAttempts = nLoginAttempts; }
  157. void SetSyncCounter( uint32_t nSyncCounter ) { m_SyncCounter = nSyncCounter; }
  158. void SetLastMapPartSent( uint32_t nLastMapPartSent ) { m_LastMapPartSent = nLastMapPartSent; }
  159. void SetLastMapPartAcked( uint32_t nLastMapPartAcked ) { m_LastMapPartAcked = nLastMapPartAcked; }
  160. void SetStartedDownloadingTicks( uint32_t nStartedDownloadingTicks ) { m_StartedDownloadingTicks = nStartedDownloadingTicks; }
  161. void SetFinishedDownloadingTime( uint32_t nFinishedDownloadingTime ) { m_FinishedDownloadingTime = nFinishedDownloadingTime; }
  162. void SetStartedLaggingTicks( uint32_t nStartedLaggingTicks ) { m_StartedLaggingTicks = nStartedLaggingTicks; }
  163. void SetStatsSentTime( uint32_t nStatsSentTime ) { m_StatsSentTime = nStatsSentTime; }
  164. void SetStatsDotASentTime( uint32_t nStatsDotASentTime ) { m_StatsDotASentTime = nStatsDotASentTime; }
  165. void SetLastGProxyWaitNoticeSentTime( uint32_t nLastGProxyWaitNoticeSentTime ) { m_LastGProxyWaitNoticeSentTime = nLastGProxyWaitNoticeSentTime; }
  166. void SetScore( double nScore ) { m_Score = nScore; }
  167. void SetLoggedIn( bool nLoggedIn ) { m_LoggedIn = nLoggedIn; }
  168. void SetSpoofed( bool nSpoofed ) { m_Spoofed = nSpoofed; }
  169. void SetReserved( bool nReserved ) { m_Reserved = nReserved; }
  170. void SetWhoisShouldBeSent( bool nWhoisShouldBeSent ) { m_WhoisShouldBeSent = nWhoisShouldBeSent; }
  171. void SetDownloadAllowed( bool nDownloadAllowed ) { m_DownloadAllowed = nDownloadAllowed; }
  172. void SetDownloadStarted( bool nDownloadStarted ) { m_DownloadStarted = nDownloadStarted; }
  173. void SetDownloadFinished( bool nDownloadFinished ) { m_DownloadFinished = nDownloadFinished; }
  174. void SetLagging( bool nLagging ) { m_Lagging = nLagging; }
  175. void SetDropVote( bool nDropVote ) { m_DropVote = nDropVote; }
  176. void SetKickVote( bool nKickVote ) { m_KickVote = nKickVote; }
  177. void SetMuted( bool nMuted ) { m_Muted = nMuted; }
  178. void SetLeftMessageSent( bool nLeftMessageSent ) { m_LeftMessageSent = nLeftMessageSent; }
  179. void SetGProxyDisconnectNoticeSent( bool nGProxyDisconnectNoticeSent ) { m_GProxyDisconnectNoticeSent = nGProxyDisconnectNoticeSent; }
  180. string GetNameTerminated( );
  181. uint32_t GetPing( bool LCPing );
  182. void AddLoadInGameData( BYTEARRAY nLoadInGameData ) { m_LoadInGameData.push( nLoadInGameData ); }
  183. // processing functions
  184. virtual bool Update( void *fd );
  185. virtual void ExtractPackets( );
  186. virtual void ProcessPackets( );
  187. // other functions
  188. virtual void Send( BYTEARRAY data );
  189. virtual void EventGProxyReconnect( CTCPSocket *NewSocket, uint32_t LastPacket );
  190. };
  191. #endif