PageRenderTime 44ms CodeModel.GetById 12ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

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