Permalink
Browse files

fixed a bug with the previous revision that didn't really fix the GPr…

…oxy++ desync issue when using load-in-game

git-svn-id: http://ghostplusplus.googlecode.com/svn/trunk@401 a7494f72-a4b0-11dd-a887-7ffe1a420f8d
  • Loading branch information...
1 parent 3fc9eb2 commit 83d05be9ed785ab1fad9d73cd10f9096a63c3b2b hogantp committed Mar 13, 2010
Showing with 33 additions and 44 deletions.
  1. +20 −28 ghost/game_base.cpp
  2. +4 −4 ghost/game_base.h
  3. +3 −5 ghost/gameplayer.cpp
  4. +6 −7 ghost/gameplayer.h
View
@@ -775,14 +775,10 @@ bool CBaseGame :: Update( void *fd, void *send_fd )
// empty actions are used to extend the time a player can use when reconnecting
for( unsigned char j = 0; j < m_GProxyEmptyActions; j++ )
- {
- UTIL_AppendByteArray( *(*i)->GetLoadInGameData( ), m_Protocol->SEND_W3GS_INCOMING_ACTION( queue<CIncomingAction *>( ), 0 ) );
- (*i)->SetLoadInGamePackets( (*i)->GetLoadInGamePackets( ) + 1 );
- }
+ (*i)->AddLoadInGameData( m_Protocol->SEND_W3GS_INCOMING_ACTION( queue<CIncomingAction *>( ), 0 ) );
}
- UTIL_AppendByteArray( *(*i)->GetLoadInGameData( ), m_Protocol->SEND_W3GS_INCOMING_ACTION( queue<CIncomingAction *>( ), 0 ) );
- (*i)->SetLoadInGamePackets( (*i)->GetLoadInGamePackets( ) + 1 );
+ (*i)->AddLoadInGameData( m_Protocol->SEND_W3GS_INCOMING_ACTION( queue<CIncomingAction *>( ), 0 ) );
}
}
@@ -1080,27 +1076,27 @@ void CBaseGame :: UpdatePost( void *send_fd )
}
}
-void CBaseGame :: Send( CGamePlayer *player, BYTEARRAY data, uint32_t numPackets )
+void CBaseGame :: Send( CGamePlayer *player, BYTEARRAY data )
{
if( player )
- player->Send( data, numPackets );
+ player->Send( data );
}
-void CBaseGame :: Send( unsigned char PID, BYTEARRAY data, uint32_t numPackets )
+void CBaseGame :: Send( unsigned char PID, BYTEARRAY data )
{
- Send( GetPlayerFromPID( PID ), data, numPackets );
+ Send( GetPlayerFromPID( PID ), data );
}
-void CBaseGame :: Send( BYTEARRAY PIDs, BYTEARRAY data, uint32_t numPackets )
+void CBaseGame :: Send( BYTEARRAY PIDs, BYTEARRAY data )
{
for( unsigned int i = 0; i < PIDs.size( ); i++ )
- Send( PIDs[i], data, numPackets );
+ Send( PIDs[i], data );
}
-void CBaseGame :: SendAll( BYTEARRAY data, uint32_t numPackets )
+void CBaseGame :: SendAll( BYTEARRAY data )
{
for( vector<CGamePlayer *> :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ )
- (*i)->Send( data, numPackets );
+ (*i)->Send( data );
}
void CBaseGame :: SendChat( unsigned char fromPID, CGamePlayer *player, string message )
@@ -1513,10 +1509,7 @@ void CBaseGame :: EventPlayerDeleted( CGamePlayer *player )
Send( *i, m_Protocol->SEND_W3GS_PLAYERLEAVE_OTHERS( player->GetPID( ), player->GetLeftCode( ) ) );
}
else
- {
- UTIL_AppendByteArray( *(*i)->GetLoadInGameData( ), m_Protocol->SEND_W3GS_PLAYERLEAVE_OTHERS( player->GetPID( ), player->GetLeftCode( ) ) );
- (*i)->SetLoadInGamePackets( (*i)->GetLoadInGamePackets( ) + 1 );
- }
+ (*i)->AddLoadInGameData( m_Protocol->SEND_W3GS_PLAYERLEAVE_OTHERS( player->GetPID( ), player->GetLeftCode( ) ) );
}
}
else
@@ -2571,9 +2564,13 @@ void CBaseGame :: EventPlayerLoaded( CGamePlayer *player )
// see the Update function for more information about why we do this
// this includes player loaded messages, game updates, and player leave messages
- Send( player, *player->GetLoadInGameData( ), player->GetLoadInGamePackets( ) );
- player->GetLoadInGameData( )->clear( );
- player->SetLoadInGamePackets( 0 );
+ queue<BYTEARRAY> *LoadInGameData = player->GetLoadInGameData( );
+
+ while( !LoadInGameData->empty( ) )
+ {
+ Send( player, LoadInGameData->front( ) );
+ LoadInGameData->pop( );
+ }
// start the lag screen for the new player
@@ -3349,15 +3346,10 @@ void CBaseGame :: EventGameStarted( )
// this ensures that every player receives the same set of player loaded messages in the same order, even if someone leaves during loading
// if someone leaves during loading we buffer the leave message to ensure it gets sent in the correct position but the player loaded message wouldn't get sent if we didn't buffer it now
- BYTEARRAY Buffer;
-
- for( vector<CGamePlayer *> :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ )
- UTIL_AppendByteArray( Buffer, m_Protocol->SEND_W3GS_GAMELOADED_OTHERS( (*i)->GetPID( ) ) );
-
for( vector<CGamePlayer *> :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ )
{
- UTIL_AppendByteArray( *(*i)->GetLoadInGameData( ), Buffer );
- (*i)->SetLoadInGamePackets( (*i)->GetLoadInGamePackets( ) + m_Players.size( ) );
+ for( vector<CGamePlayer *> :: iterator j = m_Players.begin( ); j != m_Players.end( ); j++ )
+ (*j)->AddLoadInGameData( m_Protocol->SEND_W3GS_GAMELOADED_OTHERS( (*i)->GetPID( ) ) );
}
}
View
@@ -176,10 +176,10 @@ class CBaseGame
// generic functions to send packets to players
- virtual void Send( CGamePlayer *player, BYTEARRAY data, uint32_t numPackets = 1 );
- virtual void Send( unsigned char PID, BYTEARRAY data, uint32_t numPackets = 1 );
- virtual void Send( BYTEARRAY PIDs, BYTEARRAY data, uint32_t numPackets = 1 );
- virtual void SendAll( BYTEARRAY data, uint32_t numPackets = 1 );
+ virtual void Send( CGamePlayer *player, BYTEARRAY data );
+ virtual void Send( unsigned char PID, BYTEARRAY data );
+ virtual void Send( BYTEARRAY PIDs, BYTEARRAY data );
+ virtual void SendAll( BYTEARRAY data );
// functions to send packets to players
@@ -179,7 +179,7 @@ void CPotentialPlayer :: ProcessPackets( )
}
}
-void CPotentialPlayer :: Send( BYTEARRAY data, uint32_t numPackets )
+void CPotentialPlayer :: Send( BYTEARRAY data )
{
if( m_Socket )
m_Socket->PutBytes( data );
@@ -210,7 +210,6 @@ CGamePlayer :: CGamePlayer( CGameProtocol *nProtocol, CBaseGame *nGame, CTCPSock
m_StatsSentTime = 0;
m_StatsDotASentTime = 0;
m_LastGProxyWaitNoticeSentTime = 0;
- m_LoadInGamePackets = 0;
m_Score = -100000.0;
m_LoggedIn = false;
m_Spoofed = false;
@@ -263,7 +262,6 @@ CGamePlayer :: CGamePlayer( CPotentialPlayer *potential, unsigned char nPID, str
m_StatsSentTime = 0;
m_StatsDotASentTime = 0;
m_LastGProxyWaitNoticeSentTime = 0;
- m_LoadInGamePackets = 0;
m_Score = -100000.0;
m_LoggedIn = false;
m_Spoofed = false;
@@ -620,13 +618,13 @@ void CGamePlayer :: ProcessPackets( )
}
}
-void CGamePlayer :: Send( BYTEARRAY data, uint32_t numPackets )
+void CGamePlayer :: Send( BYTEARRAY data )
{
// must start counting packet total from beginning of connection
// but we can avoid buffering packets until we know the client is using GProxy++ since that'll be determined before the game starts
// this prevents us from buffering packets for non-GProxy++ clients
- m_TotalPacketsSent += numPackets;
+ m_TotalPacketsSent++;
if( m_GProxy && m_Game->GetGameLoaded( ) )
m_GProxyBuffer.push( data );
View
@@ -72,7 +72,7 @@ class CPotentialPlayer
// other functions
- virtual void Send( BYTEARRAY data, uint32_t numPackets = 1 );
+ virtual void Send( BYTEARRAY data );
};
//
@@ -105,8 +105,7 @@ class CGamePlayer : public CPotentialPlayer
uint32_t m_StatsSentTime; // GetTime when we sent this player's stats to the chat (to prevent players from spamming !stats)
uint32_t m_StatsDotASentTime; // GetTime when we sent this player's dota stats to the chat (to prevent players from spamming !statsdota)
uint32_t m_LastGProxyWaitNoticeSentTime;
- BYTEARRAY m_LoadInGameData; // queued data to be sent when the player finishes loading when using "load in game"
- uint32_t m_LoadInGamePackets; // # of packets currently in the LoadInGameData buffer
+ queue<BYTEARRAY> m_LoadInGameData; // queued data to be sent when the player finishes loading when using "load in game"
double m_Score; // the player's generic "score" for the matchmaking algorithm
bool m_LoggedIn; // if the player has logged in or not (used with CAdminGame only)
bool m_Spoofed; // if the player has spoof checked or not
@@ -155,8 +154,7 @@ class CGamePlayer : public CPotentialPlayer
uint32_t GetStatsSentTime( ) { return m_StatsSentTime; }
uint32_t GetStatsDotASentTime( ) { return m_StatsDotASentTime; }
uint32_t GetLastGProxyWaitNoticeSentTime( ) { return m_LastGProxyWaitNoticeSentTime; }
- BYTEARRAY *GetLoadInGameData( ) { return &m_LoadInGameData; }
- uint32_t GetLoadInGamePackets( ) { return m_LoadInGamePackets; }
+ queue<BYTEARRAY> *GetLoadInGameData( ) { return &m_LoadInGameData; }
double GetScore( ) { return m_Score; }
bool GetLoggedIn( ) { return m_LoggedIn; }
bool GetSpoofed( ) { return m_Spoofed; }
@@ -189,7 +187,6 @@ class CGamePlayer : public CPotentialPlayer
void SetStatsSentTime( uint32_t nStatsSentTime ) { m_StatsSentTime = nStatsSentTime; }
void SetStatsDotASentTime( uint32_t nStatsDotASentTime ) { m_StatsDotASentTime = nStatsDotASentTime; }
void SetLastGProxyWaitNoticeSentTime( uint32_t nLastGProxyWaitNoticeSentTime ) { m_LastGProxyWaitNoticeSentTime = nLastGProxyWaitNoticeSentTime; }
- void SetLoadInGamePackets( uint32_t nLoadInGamePackets ) { m_LoadInGamePackets = nLoadInGamePackets; }
void SetScore( double nScore ) { m_Score = nScore; }
void SetLoggedIn( bool nLoggedIn ) { m_LoggedIn = nLoggedIn; }
void SetSpoofed( bool nSpoofed ) { m_Spoofed = nSpoofed; }
@@ -208,6 +205,8 @@ class CGamePlayer : public CPotentialPlayer
string GetNameTerminated( );
uint32_t GetPing( bool LCPing );
+ void AddLoadInGameData( BYTEARRAY nLoadInGameData ) { m_LoadInGameData.push( nLoadInGameData ); }
+
// processing functions
virtual bool Update( void *fd );
@@ -216,7 +215,7 @@ class CGamePlayer : public CPotentialPlayer
// other functions
- virtual void Send( BYTEARRAY data, uint32_t numPackets = 1 );
+ virtual void Send( BYTEARRAY data );
virtual void EventGProxyReconnect( CTCPSocket *NewSocket, uint32_t LastPacket );
};

0 comments on commit 83d05be

Please sign in to comment.