From 5c7ddd08e790376f24796491b30bcda8b2ca5a97 Mon Sep 17 00:00:00 2001 From: luqasn Date: Sat, 27 Mar 2010 22:55:50 +0000 Subject: [PATCH 1/7] added branch for "Genie", Mac OS ghost derivate From af88bb2fd045da6f25072c72424f47001a45f85d Mon Sep 17 00:00:00 2001 From: luqasn Date: Sat, 27 Mar 2010 23:01:47 +0000 Subject: [PATCH 2/7] added methods to enable ghost to be used as a library --- ghost/bncsutilinterface.cpp | 5 +++- ghost/bncsutilinterface.h | 7 +++-- ghost/bnet.cpp | 15 ++++++----- ghost/bnet.h | 4 ++- ghost/bnetprotocol.cpp | 4 ++- ghost/bnetprotocol.h | 7 +++-- ghost/bnlsclient.cpp | 8 +++--- ghost/bnlsclient.h | 6 +++-- ghost/bnlsprotocol.cpp | 4 ++- ghost/bnlsprotocol.h | 7 +++-- ghost/config.cpp | 3 ++- ghost/config.h | 6 +++-- ghost/game_admin.cpp | 6 ++--- ghost/game_base.cpp | 5 ++-- ghost/game_base.h | 3 ++- ghost/gameplayer.cpp | 1 + ghost/gameplayer.h | 4 ++- ghost/gameprotocol.cpp | 1 + ghost/gameprotocol.h | 4 ++- ghost/ghost.cpp | 38 +++++++++++++++------------ ghost/ghost.h | 5 ++-- ghost/ghostdb.cpp | 3 ++- ghost/ghostdb.h | 6 +++-- ghost/ghostdbmysql.cpp | 2 +- ghost/ghostdbmysql.h | 2 +- ghost/ghostdbsqlite.cpp | 2 +- ghost/ghostdbsqlite.h | 2 +- ghost/includes.h | 9 ++++--- ghost/language.cpp | 5 ++-- ghost/language.h | 6 +++-- ghost/map.cpp | 2 ++ ghost/map.h | 3 ++- ghost/messagelogger.cpp | 11 ++++++++ ghost/messagelogger.h | 52 +++++++++++++++++++++++++++++++++++++ ghost/packed.cpp | 3 ++- ghost/packed.h | 6 +++-- ghost/replay.cpp | 2 +- ghost/replay.h | 2 +- ghost/savegame.cpp | 2 +- ghost/savegame.h | 2 +- ghost/socket.cpp | 20 +++++++------- ghost/socket.h | 20 +++++++------- ghost/stats.cpp | 2 ++ ghost/stats.h | 4 ++- 44 files changed, 219 insertions(+), 92 deletions(-) create mode 100644 ghost/messagelogger.cpp create mode 100644 ghost/messagelogger.h diff --git a/ghost/bncsutilinterface.cpp b/ghost/bncsutilinterface.cpp index 637bc8d..eda0e53 100644 --- a/ghost/bncsutilinterface.cpp +++ b/ghost/bncsutilinterface.cpp @@ -24,11 +24,14 @@ #include +#include "bnet.h" + // // CBNCSUtilInterface // -CBNCSUtilInterface :: CBNCSUtilInterface( string userName, string userPassword ) +CBNCSUtilInterface :: CBNCSUtilInterface( CBNET *bnet, string userName, string userPassword ) + : MessageLogger( bnet ) { // m_nls = (void *)nls_init( userName.c_str( ), userPassword.c_str( ) ); m_NLS = new NLS( userName, userPassword ); diff --git a/ghost/bncsutilinterface.h b/ghost/bncsutilinterface.h index 76b5858..4c4fcd3 100644 --- a/ghost/bncsutilinterface.h +++ b/ghost/bncsutilinterface.h @@ -21,11 +21,14 @@ #ifndef BNCSUTIL_INTERFACE_H #define BNCSUTIL_INTERFACE_H +#include "messagelogger.h" +class CBNET; + // // CBNCSUtilInterface // -class CBNCSUtilInterface +class CBNCSUtilInterface : protected MessageLogger { private: void *m_NLS; @@ -39,7 +42,7 @@ class CBNCSUtilInterface BYTEARRAY m_PvPGNPasswordHash; // set in HELP_PvPGNPasswordHash public: - CBNCSUtilInterface( string userName, string userPassword ); + CBNCSUtilInterface( CBNET *bnet, string userName, string userPassword ); ~CBNCSUtilInterface( ); BYTEARRAY GetEXEVersion( ) { return m_EXEVersion; } diff --git a/ghost/bnet.cpp b/ghost/bnet.cpp index 8fe0ac5..662741d 100644 --- a/ghost/bnet.cpp +++ b/ghost/bnet.cpp @@ -45,14 +45,15 @@ using namespace boost :: filesystem; // CBNET :: CBNET( CGHost *nGHost, string nServer, string nServerAlias, string nBNLSServer, uint16_t nBNLSPort, uint32_t nBNLSWardenCookie, string nCDKeyROC, string nCDKeyTFT, string nCountryAbbrev, string nCountry, uint32_t nLocaleID, string nUserName, string nUserPassword, string nFirstChannel, string nRootAdmin, char nCommandTrigger, bool nHoldFriends, bool nHoldClan, bool nPublicCommands, unsigned char nWar3Version, BYTEARRAY nEXEVersion, BYTEARRAY nEXEVersionHash, string nPasswordHashType, string nPVPGNRealmName, uint32_t nMaxMessageLength, uint32_t nHostCounterID ) + : MessageLogger( nGHost ) { // todotodo: append path seperator to Warcraft3Path if needed m_GHost = nGHost; - m_Socket = new CTCPClient( ); - m_Protocol = new CBNETProtocol( ); + m_Socket = new CTCPClient( this ); + m_Protocol = new CBNETProtocol( this ); m_BNLSClient = NULL; - m_BNCSUtil = new CBNCSUtilInterface( nUserName, nUserPassword ); + m_BNCSUtil = new CBNCSUtilInterface( this, nUserName, nUserPassword ); m_CallableAdminList = m_GHost->m_DB->ThreadedAdminList( nServer ); m_CallableBanList = m_GHost->m_DB->ThreadedBanList( nServer ); m_Exiting = false; @@ -770,7 +771,7 @@ void CBNET :: ProcessPackets( ) { CONSOLE_Print( "[BNET: " + m_ServerAlias + "] creating BNLS client" ); delete m_BNLSClient; - m_BNLSClient = new CBNLSClient( m_BNLSServer, m_BNLSPort, m_BNLSWardenCookie ); + m_BNLSClient = new CBNLSClient( this, m_BNLSServer, m_BNLSPort, m_BNLSWardenCookie ); m_BNLSClient->QueueWardenSeed( UTIL_ByteArrayToUInt32( m_BNCSUtil->GetKeyInfoROC( ), false, 16 ) ); } } @@ -1512,7 +1513,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) if( UTIL_FileExists( File ) ) { QueueChatCommand( m_GHost->m_Language->LoadingReplay( File ), User, Whisper ); - CReplay *Replay = new CReplay( ); + CReplay *Replay = new CReplay( this ); Replay->Load( File, false ); Replay->ParseReplay( false ); m_GHost->m_EnforcePlayers = Replay->GetPlayers( ); @@ -1692,7 +1693,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) { string File = LastMatch.filename( ); QueueChatCommand( m_GHost->m_Language->LoadingConfigFile( m_GHost->m_MapCFGPath + File ), User, Whisper ); - CConfig MapCFG; + CConfig MapCFG( this ); MapCFG.Read( LastMatch.string( ) ); m_GHost->m_Map->Load( &MapCFG, m_GHost->m_MapCFGPath + File ); } @@ -1806,7 +1807,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // hackhack: create a config file in memory with the required information to load the map - CConfig MapCFG; + CConfig MapCFG( this ); MapCFG.Set( "map_path", "Maps\\Download\\" + File ); MapCFG.Set( "map_localpath", File ); m_GHost->m_Map->Load( &MapCFG, File ); diff --git a/ghost/bnet.h b/ghost/bnet.h index 488afbb..ff3ac81 100644 --- a/ghost/bnet.h +++ b/ghost/bnet.h @@ -21,6 +21,8 @@ #ifndef BNET_H #define BNET_H +#include "messagelogger.h" + // // CBNET // @@ -54,7 +56,7 @@ typedef pair PairedBanRemove; typedef pair PairedGPSCheck; typedef pair PairedDPSCheck; -class CBNET +class CBNET : protected MessageLogger { public: CGHost *m_GHost; diff --git a/ghost/bnetprotocol.cpp b/ghost/bnetprotocol.cpp index 3176405..79f0ca0 100644 --- a/ghost/bnetprotocol.cpp +++ b/ghost/bnetprotocol.cpp @@ -21,8 +21,10 @@ #include "ghost.h" #include "util.h" #include "bnetprotocol.h" +#include "bnet.h" -CBNETProtocol :: CBNETProtocol( ) +CBNETProtocol :: CBNETProtocol( CBNET* bnet ) + : MessageLogger( bnet ) { unsigned char ClientToken[] = { 220, 1, 203, 7 }; m_ClientToken = UTIL_CreateByteArray( ClientToken, 4 ); diff --git a/ghost/bnetprotocol.h b/ghost/bnetprotocol.h index 4d7cfb9..159ff0c 100644 --- a/ghost/bnetprotocol.h +++ b/ghost/bnetprotocol.h @@ -21,6 +21,9 @@ #ifndef BNETPROTOCOL_H #define BNETPROTOCOL_H +#include "messagelogger.h" +class CBNET; + // // CBNETProtocol // @@ -32,7 +35,7 @@ class CIncomingChatEvent; class CIncomingFriendList; class CIncomingClanList; -class CBNETProtocol +class CBNETProtocol : protected MessageLogger { public: enum Protocol { @@ -101,7 +104,7 @@ class CBNETProtocol BYTEARRAY m_UniqueName; // set in RECEIVE_SID_ENTERCHAT public: - CBNETProtocol( ); + CBNETProtocol( CBNET *bnet ); ~CBNETProtocol( ); BYTEARRAY GetClientToken( ) { return m_ClientToken; } diff --git a/ghost/bnlsclient.cpp b/ghost/bnlsclient.cpp index bce9bee..9437dc7 100644 --- a/ghost/bnlsclient.cpp +++ b/ghost/bnlsclient.cpp @@ -24,15 +24,17 @@ #include "commandpacket.h" #include "bnlsprotocol.h" #include "bnlsclient.h" +#include "bnet.h" // // CBNLSClient // -CBNLSClient :: CBNLSClient( string nServer, uint16_t nPort, uint32_t nWardenCookie ) +CBNLSClient :: CBNLSClient( CBNET *bnet, string nServer, uint16_t nPort, uint32_t nWardenCookie ) + : MessageLogger( bnet ) { - m_Socket = new CTCPClient( ); - m_Protocol = new CBNLSProtocol( ); + m_Socket = new CTCPClient( this ); + m_Protocol = new CBNLSProtocol( this ); m_WasConnected = false; m_Server = nServer; m_Port = nPort; diff --git a/ghost/bnlsclient.h b/ghost/bnlsclient.h index 0562c37..5113848 100644 --- a/ghost/bnlsclient.h +++ b/ghost/bnlsclient.h @@ -21,6 +21,8 @@ #ifndef BNLSCLIENT_H #define BNLSCLIENT_H +#include "messagelogger.h" + // // CBNLSClient // @@ -29,7 +31,7 @@ class CTCPClient; class CBNLSProtocol; class CCommandPacket; -class CBNLSClient +class CBNLSClient : protected MessageLogger { private: CTCPClient *m_Socket; // the connection to the BNLS server @@ -46,7 +48,7 @@ class CBNLSClient uint32_t m_TotalWardenOut; public: - CBNLSClient( string nServer, uint16_t nPort, uint32_t nWardenCookie ); + CBNLSClient( CBNET *bnet, string nServer, uint16_t nPort, uint32_t nWardenCookie ); ~CBNLSClient( ); BYTEARRAY GetWardenResponse( ); diff --git a/ghost/bnlsprotocol.cpp b/ghost/bnlsprotocol.cpp index 8929ef9..255129a 100644 --- a/ghost/bnlsprotocol.cpp +++ b/ghost/bnlsprotocol.cpp @@ -21,8 +21,10 @@ #include "ghost.h" #include "util.h" #include "bnlsprotocol.h" +#include "bnlsclient.h" -CBNLSProtocol :: CBNLSProtocol( ) +CBNLSProtocol :: CBNLSProtocol( CBNLSClient *parent ) + : MessageLogger( parent ) { } diff --git a/ghost/bnlsprotocol.h b/ghost/bnlsprotocol.h index d0f9f10..48eef8e 100644 --- a/ghost/bnlsprotocol.h +++ b/ghost/bnlsprotocol.h @@ -21,11 +21,14 @@ #ifndef BNLSPROTOCOL_H #define BNLSPROTOCOL_H +#include "messagelogger.h" +class CBNLSClient; + // // CBNLSProtocol // -class CBNLSProtocol +class CBNLSProtocol : protected MessageLogger { public: enum Protocol { @@ -60,7 +63,7 @@ class CBNLSProtocol }; public: - CBNLSProtocol( ); + CBNLSProtocol( CBNLSClient *parent ); ~CBNLSProtocol( ); // receive functions diff --git a/ghost/config.cpp b/ghost/config.cpp index 2a1276c..9da0bbe 100644 --- a/ghost/config.cpp +++ b/ghost/config.cpp @@ -27,7 +27,8 @@ // CConfig // -CConfig :: CConfig( ) +CConfig :: CConfig( MessageLogger *logger ) + : MessageLogger( logger ) { } diff --git a/ghost/config.h b/ghost/config.h index ccd3b7f..3a86a5d 100644 --- a/ghost/config.h +++ b/ghost/config.h @@ -21,17 +21,19 @@ #ifndef CONFIG_H #define CONFIG_H +#include "messagelogger.h" + // // CConfig // -class CConfig +class CConfig : protected MessageLogger { private: map m_CFG; public: - CConfig( ); + CConfig( MessageLogger* logger ); ~CConfig( ); void Read( string file ); diff --git a/ghost/game_admin.cpp b/ghost/game_admin.cpp index 547711e..13e5b8e 100644 --- a/ghost/game_admin.cpp +++ b/ghost/game_admin.cpp @@ -831,7 +831,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s if( UTIL_FileExists( File ) ) { SendChat( player, m_GHost->m_Language->LoadingReplay( File ) ); - CReplay *Replay = new CReplay( ); + CReplay *Replay = new CReplay( this ); Replay->Load( File, false ); Replay->ParseReplay( false ); m_GHost->m_EnforcePlayers = Replay->GetPlayers( ); @@ -957,7 +957,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s { string File = LastMatch.filename( ); SendChat( player, m_GHost->m_Language->LoadingConfigFile( m_GHost->m_MapCFGPath + File ) ); - CConfig MapCFG; + CConfig MapCFG( this ); MapCFG.Read( LastMatch.string( ) ); m_GHost->m_Map->Load( &MapCFG, m_GHost->m_MapCFGPath + File ); } @@ -1071,7 +1071,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // hackhack: create a config file in memory with the required information to load the map - CConfig MapCFG; + CConfig MapCFG( this ); MapCFG.Set( "map_path", "Maps\\Download\\" + File ); MapCFG.Set( "map_localpath", File ); m_GHost->m_Map->Load( &MapCFG, File ); diff --git a/ghost/game_base.cpp b/ghost/game_base.cpp index 42225cc..761fa34 100644 --- a/ghost/game_base.cpp +++ b/ghost/game_base.cpp @@ -44,15 +44,16 @@ // CBaseGame :: CBaseGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16_t nHostPort, unsigned char nGameState, string nGameName, string nOwnerName, string nCreatorName, string nCreatorServer ) + : MessageLogger( nGHost ) { m_GHost = nGHost; - m_Socket = new CTCPServer( ); + m_Socket = new CTCPServer( this ); m_Protocol = new CGameProtocol( m_GHost ); m_Map = new CMap( *nMap ); m_SaveGame = nSaveGame; if( m_GHost->m_SaveReplays && !m_SaveGame ) - m_Replay = new CReplay( ); + m_Replay = new CReplay( this ); else m_Replay = NULL; diff --git a/ghost/game_base.h b/ghost/game_base.h index 1868c2f..f0d36c3 100644 --- a/ghost/game_base.h +++ b/ghost/game_base.h @@ -22,6 +22,7 @@ #define GAME_BASE_H #include "gameslot.h" +#include "messagelogger.h" // // CBaseGame @@ -40,7 +41,7 @@ class CIncomingChatPlayer; class CIncomingMapSize; class CCallableScoreCheck; -class CBaseGame +class CBaseGame : protected MessageLogger { public: CGHost *m_GHost; diff --git a/ghost/gameplayer.cpp b/ghost/gameplayer.cpp index 0a78367..c0575b1 100644 --- a/ghost/gameplayer.cpp +++ b/ghost/gameplayer.cpp @@ -35,6 +35,7 @@ // CPotentialPlayer :: CPotentialPlayer( CGameProtocol *nProtocol, CBaseGame *nGame, CTCPSocket *nSocket ) + : MessageLogger( nGame ) { m_Protocol = nProtocol; m_Game = nGame; diff --git a/ghost/gameplayer.h b/ghost/gameplayer.h index 262d948..12fc457 100644 --- a/ghost/gameplayer.h +++ b/ghost/gameplayer.h @@ -21,6 +21,8 @@ #ifndef GAMEPLAYER_H #define GAMEPLAYER_H +#include "messagelogger.h" + class CTCPSocket; class CCommandPacket; class CGameProtocol; @@ -31,7 +33,7 @@ class CIncomingJoinPlayer; // CPotentialPlayer // -class CPotentialPlayer +class CPotentialPlayer : protected MessageLogger { public: CGameProtocol *m_Protocol; diff --git a/ghost/gameprotocol.cpp b/ghost/gameprotocol.cpp index 976e8f5..f22a31d 100644 --- a/ghost/gameprotocol.cpp +++ b/ghost/gameprotocol.cpp @@ -30,6 +30,7 @@ // CGameProtocol :: CGameProtocol( CGHost *nGHost ) + : MessageLogger( nGHost ) { m_GHost = nGHost; } diff --git a/ghost/gameprotocol.h b/ghost/gameprotocol.h index 2b976c1..638da41 100644 --- a/ghost/gameprotocol.h +++ b/ghost/gameprotocol.h @@ -21,6 +21,8 @@ #ifndef GAMEPROTOCOL_H #define GAMEPROTOCOL_H +#include "messagelogger.h" + // // CGameProtocol // @@ -56,7 +58,7 @@ class CIncomingAction; class CIncomingChatPlayer; class CIncomingMapSize; -class CGameProtocol +class CGameProtocol : protected MessageLogger { public: CGHost *m_GHost; diff --git a/ghost/ghost.cpp b/ghost/ghost.cpp index 26d5d30..82d3a94 100644 --- a/ghost/ghost.cpp +++ b/ghost/ghost.cpp @@ -140,6 +140,8 @@ uint32_t GetTicks( ) #endif } +#ifndef GHOST_LIB + void SignalCatcher2( int s ) { CONSOLE_Print( "[!!!] caught signal " + UTIL_ToString( s ) + ", exiting NOW" ); @@ -168,7 +170,7 @@ void SignalCatcher( int s ) exit( 1 ); } -void CONSOLE_Print( string message ) +void CONSOLE_Print( const string &message ) { cout << message << endl; @@ -210,7 +212,7 @@ void CONSOLE_Print( string message ) } } -void DEBUG_Print( string message ) +void DEBUG_Print( const string &message ) { cout << message << endl; } @@ -231,6 +233,7 @@ void DEBUG_Print( BYTEARRAY b ) int main( int argc, char **argv ) { + MessageLogger logger( *CONSOLE_Print ); gCFGFile = "ghost.cfg"; if( argc > 1 && argv[1] ) @@ -238,7 +241,7 @@ int main( int argc, char **argv ) // read config file - CConfig CFG; + CConfig CFG( &logger ); CFG.Read( gCFGFile ); gLogFile = CFG.GetString( "bot_log", string( ) ); gLogMethod = CFG.GetInt( "bot_logmethod", 1 ); @@ -345,7 +348,7 @@ int main( int argc, char **argv ) // initialize ghost - gGHost = new CGHost( &CFG ); + gGHost = new CGHost( &logger, &CFG ); while( 1 ) { @@ -384,13 +387,16 @@ int main( int argc, char **argv ) return 0; } +#endif //#ifdndef GHOST_LIB + // // CGHost // -CGHost :: CGHost( CConfig *CFG ) +CGHost :: CGHost( MessageLogger *logger, CConfig *CFG ) + : MessageLogger( logger ) { - m_UDPSocket = new CUDPSocket( ); + m_UDPSocket = new CUDPSocket( this ); m_UDPSocket->SetBroadcastTarget( CFG->GetString( "udp_broadcasttarget", string( ) ) ); m_UDPSocket->SetDontRoute( CFG->GetInt( "udp_dontroute", 0 ) == 0 ? false : true ); m_ReconnectSocket = NULL; @@ -405,17 +411,17 @@ CGHost :: CGHost( CConfig *CFG ) if( DBType == "mysql" ) { #ifdef GHOST_MYSQL - m_DB = new CGHostDBMySQL( CFG ); + m_DB = new CGHostDBMySQL( this, CFG ); #else CONSOLE_Print( "[GHOST] warning - this binary was not compiled with MySQL database support, using SQLite database instead" ); - m_DB = new CGHostDBSQLite( CFG ); + m_DB = new CGHostDBSQLite( this, CFG ); #endif } else - m_DB = new CGHostDBSQLite( CFG ); + m_DB = new CGHostDBSQLite( this, CFG ); CONSOLE_Print( "[GHOST] opening secondary (local) database" ); - m_DBLocal = new CGHostDBSQLite( CFG ); + m_DBLocal = new CGHostDBSQLite( this, CFG ); // get a list of local IP addresses // this list is used elsewhere to determine if a player connecting to the bot is local or not @@ -627,7 +633,7 @@ CGHost :: CGHost( CConfig *CFG ) CONSOLE_Print( "[GHOST] adding \".cfg\" to default map -> new default is [" + m_DefaultMap + "]" ); } - CConfig MapCFG; + CConfig MapCFG( this ); MapCFG.Read( m_MapCFGPath + m_DefaultMap ); m_Map = new CMap( this, &MapCFG, m_MapCFGPath + m_DefaultMap ); @@ -640,7 +646,7 @@ CGHost :: CGHost( CConfig *CFG ) } CONSOLE_Print( "[GHOST] trying to load default admin game map" ); - CConfig AdminMapCFG; + CConfig AdminMapCFG( this ); AdminMapCFG.Read( m_MapCFGPath + m_AdminGameMap ); m_AdminMap = new CMap( this, &AdminMapCFG, m_MapCFGPath + m_AdminGameMap ); @@ -658,7 +664,7 @@ CGHost :: CGHost( CConfig *CFG ) } m_AutoHostMap = new CMap( *m_Map ); - m_SaveGame = new CSaveGame( ); + m_SaveGame = new CSaveGame( this ); // load the iptocountry data @@ -815,7 +821,7 @@ bool CGHost :: Update( long usecBlock ) { if( !m_ReconnectSocket ) { - m_ReconnectSocket = new CTCPServer( ); + m_ReconnectSocket = new CTCPServer( this ); if( m_ReconnectSocket->Listen( m_BindAddress, m_ReconnectPort ) ) CONSOLE_Print( "[GHOST] listening for GProxy++ reconnects on port " + UTIL_ToString( m_ReconnectPort ) ); @@ -1310,7 +1316,7 @@ void CGHost :: EventGameDeleted( CBaseGame *game ) void CGHost :: ReloadConfigs( ) { - CConfig CFG; + CConfig CFG( this ); CFG.Read( gCFGFile ); SetConfigs( &CFG ); } @@ -1322,7 +1328,7 @@ void CGHost :: SetConfigs( CConfig *CFG ) m_LanguageFile = CFG->GetString( "bot_language", "language.cfg" ); delete m_Language; - m_Language = new CLanguage( m_LanguageFile ); + m_Language = new CLanguage( this, m_LanguageFile ); m_Warcraft3Path = UTIL_AddPathSeperator( CFG->GetString( "bot_war3path", "C:\\Program Files\\Warcraft III\\" ) ); m_BindAddress = CFG->GetString( "bot_bindaddress", string( ) ); m_ReconnectWaitTime = CFG->GetInt( "bot_reconnectwaittime", 3 ); diff --git a/ghost/ghost.h b/ghost/ghost.h index 7e84ce3..b1a132c 100644 --- a/ghost/ghost.h +++ b/ghost/ghost.h @@ -22,6 +22,7 @@ #define GHOST_H #include "includes.h" +#include "messagelogger.h" // // CGHost @@ -43,7 +44,7 @@ class CMap; class CSaveGame; class CConfig; -class CGHost +class CGHost : protected MessageLogger { public: CUDPSocket *m_UDPSocket; // a UDP socket for sending broadcasts and other junk (used with !sendlan) @@ -134,7 +135,7 @@ class CGHost bool m_TCPNoDelay; // config value: use Nagle's algorithm or not uint32_t m_MatchMakingMethod; // config value: the matchmaking method - CGHost( CConfig *CFG ); + CGHost( MessageLogger *logger, CConfig *CFG ); ~CGHost( ); // processing functions diff --git a/ghost/ghostdb.cpp b/ghost/ghostdb.cpp index 43ec7df..d38062e 100644 --- a/ghost/ghostdb.cpp +++ b/ghost/ghostdb.cpp @@ -27,7 +27,8 @@ // CGHostDB // -CGHostDB :: CGHostDB( CConfig *CFG ) +CGHostDB :: CGHostDB( MessageLogger *logger, CConfig *CFG ) + : MessageLogger( logger ) { m_HasError = false; } diff --git a/ghost/ghostdb.h b/ghost/ghostdb.h index 48934f9..252ac12 100644 --- a/ghost/ghostdb.h +++ b/ghost/ghostdb.h @@ -21,6 +21,8 @@ #ifndef GHOSTDB_H #define GHOSTDB_H +#include "messagelogger.h" + // // CGHostDB // @@ -54,14 +56,14 @@ class CDBDotAPlayerSummary; typedef pair VarP; -class CGHostDB +class CGHostDB : protected MessageLogger { protected: bool m_HasError; string m_Error; public: - CGHostDB( CConfig *CFG ); + CGHostDB( MessageLogger *logger, CConfig *CFG ); virtual ~CGHostDB( ); bool HasError( ) { return m_HasError; } diff --git a/ghost/ghostdbmysql.cpp b/ghost/ghostdbmysql.cpp index ae7b7bf..2c902f5 100644 --- a/ghost/ghostdbmysql.cpp +++ b/ghost/ghostdbmysql.cpp @@ -39,7 +39,7 @@ // CGHostDBMySQL // -CGHostDBMySQL :: CGHostDBMySQL( CConfig *CFG ) : CGHostDB( CFG ) +CGHostDBMySQL :: CGHostDBMySQL( MessageLogger *logger, CConfig *CFG ) : CGHostDB( logger, CFG ) { m_Server = CFG->GetString( "db_mysql_server", string( ) ); m_Database = CFG->GetString( "db_mysql_database", "ghost" ); diff --git a/ghost/ghostdbmysql.h b/ghost/ghostdbmysql.h index f074871..e52941d 100644 --- a/ghost/ghostdbmysql.h +++ b/ghost/ghostdbmysql.h @@ -178,7 +178,7 @@ class CGHostDBMySQL : public CGHostDB uint32_t m_OutstandingCallables; public: - CGHostDBMySQL( CConfig *CFG ); + CGHostDBMySQL( MessageLogger *logger, CConfig *CFG ); virtual ~CGHostDBMySQL( ); virtual string GetStatus( ); diff --git a/ghost/ghostdbsqlite.cpp b/ghost/ghostdbsqlite.cpp index 2c08443..5bdd8b6 100644 --- a/ghost/ghostdbsqlite.cpp +++ b/ghost/ghostdbsqlite.cpp @@ -103,7 +103,7 @@ uint32_t CSQLITE3 :: LastRowID( ) // CGHostDBSQLite // -CGHostDBSQLite :: CGHostDBSQLite( CConfig *CFG ) : CGHostDB( CFG ) +CGHostDBSQLite :: CGHostDBSQLite( MessageLogger *logger, CConfig *CFG ) : CGHostDB( logger, CFG ) { m_File = CFG->GetString( "db_sqlite3_file", "ghost.dbs" ); CONSOLE_Print( "[SQLITE3] version " + string( SQLITE_VERSION ) ); diff --git a/ghost/ghostdbsqlite.h b/ghost/ghostdbsqlite.h index fe0d03e..77576c9 100644 --- a/ghost/ghostdbsqlite.h +++ b/ghost/ghostdbsqlite.h @@ -199,7 +199,7 @@ class CGHostDBSQLite : public CGHostDB void *FromAddStmt; public: - CGHostDBSQLite( CConfig *CFG ); + CGHostDBSQLite( MessageLogger *logger, CConfig *CFG ); virtual ~CGHostDBSQLite( ); virtual void Upgrade1_2( ); diff --git a/ghost/includes.h b/ghost/includes.h index f2954bb..cdbbc61 100644 --- a/ghost/includes.h +++ b/ghost/includes.h @@ -64,9 +64,12 @@ uint32_t GetTicks( ); // milliseconds #define FD_SETSIZE 512 // output - -void CONSOLE_Print( string message ); -void DEBUG_Print( string message ); +#ifndef GHOST_LIB +void CONSOLE_Print( const string &message ); +#else +#define CONSOLE_Print(a) WriteLine(a) +#endif +void DEBUG_Print( const string &message ); void DEBUG_Print( BYTEARRAY b ); #endif diff --git a/ghost/language.cpp b/ghost/language.cpp index 7802ceb..54124d4 100644 --- a/ghost/language.cpp +++ b/ghost/language.cpp @@ -27,9 +27,10 @@ // CLanguage // -CLanguage :: CLanguage( string nCFGFile ) +CLanguage :: CLanguage( MessageLogger *logger, string nCFGFile ) + : MessageLogger( logger ) { - m_CFG = new CConfig( ); + m_CFG = new CConfig( this ); m_CFG->Read( nCFGFile ); } diff --git a/ghost/language.h b/ghost/language.h index 3d12a5c..f615771 100644 --- a/ghost/language.h +++ b/ghost/language.h @@ -21,17 +21,19 @@ #ifndef LANGUAGE_H #define LANGUAGE_H +#include "messagelogger.h" + // // CLanguage // -class CLanguage +class CLanguage : protected MessageLogger { private: CConfig *m_CFG; public: - CLanguage( string nCFGFile ); + CLanguage( MessageLogger *logger, string nCFGFile ); ~CLanguage( ); string UnableToCreateGameTryAnotherName( string server, string gamename ); diff --git a/ghost/map.cpp b/ghost/map.cpp index ea23f0e..97d2c5d 100644 --- a/ghost/map.cpp +++ b/ghost/map.cpp @@ -36,6 +36,7 @@ // CMap :: CMap( CGHost *nGHost ) + : MessageLogger( nGHost ) { CONSOLE_Print( "[MAP] using hardcoded Emerald Gardens map data for Warcraft 3 version 1.24 & 1.24b" ); m_GHost = nGHost; @@ -70,6 +71,7 @@ CMap :: CMap( CGHost *nGHost ) } CMap :: CMap( CGHost *nGHost, CConfig *CFG, string nCFGFile ) + : MessageLogger( nGHost ) { m_GHost = nGHost; Load( CFG, nCFGFile ); diff --git a/ghost/map.h b/ghost/map.h index d461a2d..b480229 100644 --- a/ghost/map.h +++ b/ghost/map.h @@ -42,12 +42,13 @@ #define MAPFLAG_RANDOMRACES 16 #include "gameslot.h" +#include "messagelogger.h" // // CMap // -class CMap +class CMap : protected MessageLogger { public: CGHost *m_GHost; diff --git a/ghost/messagelogger.cpp b/ghost/messagelogger.cpp new file mode 100644 index 0000000..32c6162 --- /dev/null +++ b/ghost/messagelogger.cpp @@ -0,0 +1,11 @@ +/* + * loggingclass.cpp + * Genie + * + * Created by Lucas on 27.03.10. + * Copyright 2010 Lucas Romero. All rights reserved. + * + */ + +#include "messagelogger.h" + diff --git a/ghost/messagelogger.h b/ghost/messagelogger.h new file mode 100644 index 0000000..cc1f5a7 --- /dev/null +++ b/ghost/messagelogger.h @@ -0,0 +1,52 @@ +/* + * loggingclass.h + * Genie + * + * Created by Lucas on 27.03.10. + * Copyright 2010 Lucas Romero. All rights reserved. + * + */ + +#ifndef LOGGINGCLASS_H +#define LOGGINGCLASS_H + +#include +#include +using namespace std; + +typedef void (*LogMessageHandler)( const string &message ); + +class MessageLogger +{ +public: + MessageLogger( MessageLogger *parentLogger ) : parent( parentLogger), messageHandler( NULL ) + { /* empty constructor */ } + MessageLogger( LogMessageHandler msgHandler ) : parent( NULL ), messageHandler( msgHandler ) + { /* empty constructor */ } + + void LogInfo( const string &msg ) + { + WriteLine( msg ); + } + + void WriteLine( const string &msg ) + { + if( parent != NULL ) { + // let the parent handle the message + parent->LogInfo( msg ); + } + else if ( messageHandler != NULL ) { + // call function provided by user + messageHandler( msg ); + } + else { + // got nowhere to log to, print to stdout + cout << msg << endl; + } + } +protected: + MessageLogger *parent; + LogMessageHandler messageHandler; +}; + +#endif \ No newline at end of file diff --git a/ghost/packed.cpp b/ghost/packed.cpp index f0a9f6a..d2d53b0 100644 --- a/ghost/packed.cpp +++ b/ghost/packed.cpp @@ -66,7 +66,8 @@ int tzuncompress( Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourc // CPacked // -CPacked :: CPacked( ) +CPacked :: CPacked( MessageLogger *logger ) + : MessageLogger( logger ) { m_CRC = new CCRC32( ); m_CRC->Initialize( ); diff --git a/ghost/packed.h b/ghost/packed.h index d33b839..1fe5633 100644 --- a/ghost/packed.h +++ b/ghost/packed.h @@ -21,13 +21,15 @@ #ifndef PACKED_H #define PACKED_H +#include "messagelogger.h" + // // CPacked // class CCRC32; -class CPacked +class CPacked : protected MessageLogger { public: CCRC32 *m_CRC; @@ -48,7 +50,7 @@ class CPacked uint32_t m_ReplayLength; public: - CPacked( ); + CPacked( MessageLogger *logger ); virtual ~CPacked( ); virtual bool GetValid( ) { return m_Valid; } diff --git a/ghost/replay.cpp b/ghost/replay.cpp index a409dad..d2cc767 100644 --- a/ghost/replay.cpp +++ b/ghost/replay.cpp @@ -28,7 +28,7 @@ // CReplay // -CReplay :: CReplay( ) : CPacked( ) +CReplay :: CReplay( MessageLogger *logger ) : CPacked( logger ) { m_HostPID = 0; m_PlayerCount = 0; diff --git a/ghost/replay.h b/ghost/replay.h index 0a059b1..1620d96 100644 --- a/ghost/replay.h +++ b/ghost/replay.h @@ -59,7 +59,7 @@ class CReplay : public CPacked queue m_CheckSums; public: - CReplay( ); + CReplay( MessageLogger *logger ); virtual ~CReplay( ); unsigned char GetHostPID( ) { return m_HostPID; } diff --git a/ghost/savegame.cpp b/ghost/savegame.cpp index 9c9ce6f..7dd8404 100644 --- a/ghost/savegame.cpp +++ b/ghost/savegame.cpp @@ -27,7 +27,7 @@ // CSaveGame // -CSaveGame :: CSaveGame( ) : CPacked( ) +CSaveGame :: CSaveGame( MessageLogger* logger ) : CPacked( logger ) { m_NumSlots = 0; m_RandomSeed = 0; diff --git a/ghost/savegame.h b/ghost/savegame.h index 326bcf5..44f5296 100644 --- a/ghost/savegame.h +++ b/ghost/savegame.h @@ -40,7 +40,7 @@ class CSaveGame : public CPacked BYTEARRAY m_MagicNumber; public: - CSaveGame( ); + CSaveGame( MessageLogger* logger ); virtual ~CSaveGame( ); string GetFileName( ) { return m_FileName; } diff --git a/ghost/socket.cpp b/ghost/socket.cpp index f25e915..976f7cd 100644 --- a/ghost/socket.cpp +++ b/ghost/socket.cpp @@ -32,7 +32,8 @@ // CSocket // -CSocket :: CSocket( ) +CSocket :: CSocket( MessageLogger* logger ) + : MessageLogger( logger ) { m_Socket = INVALID_SOCKET; memset( &m_SIN, 0, sizeof( m_SIN ) ); @@ -40,7 +41,8 @@ CSocket :: CSocket( ) m_Error = 0; } -CSocket :: CSocket( SOCKET nSocket, struct sockaddr_in nSIN ) +CSocket :: CSocket( MessageLogger* logger, SOCKET nSocket, struct sockaddr_in nSIN ) + : MessageLogger( logger ) { m_Socket = nSocket; m_SIN = nSIN; @@ -159,7 +161,7 @@ void CSocket :: Reset( ) // CTCPSocket // -CTCPSocket :: CTCPSocket( ) : CSocket( ) +CTCPSocket :: CTCPSocket( MessageLogger* logger ) : CSocket( logger ) { Allocate( SOCK_STREAM ); m_Connected = false; @@ -176,7 +178,7 @@ CTCPSocket :: CTCPSocket( ) : CSocket( ) #endif } -CTCPSocket :: CTCPSocket( SOCKET nSocket, struct sockaddr_in nSIN ) : CSocket( nSocket, nSIN ) +CTCPSocket :: CTCPSocket( MessageLogger* logger, SOCKET nSocket, struct sockaddr_in nSIN ) : CSocket( logger, nSocket, nSIN ) { m_Connected = true; m_LastRecv = GetTime( ); @@ -354,7 +356,7 @@ void CTCPSocket :: SetNoDelay( bool noDelay ) // CTCPClient // -CTCPClient :: CTCPClient( ) : CTCPSocket( ) +CTCPClient :: CTCPClient( MessageLogger* logger ) : CTCPSocket( logger ) { m_Connecting = false; } @@ -479,7 +481,7 @@ bool CTCPClient :: CheckConnect( ) // CTCPServer // -CTCPServer :: CTCPServer( ) : CTCPSocket( ) +CTCPServer :: CTCPServer( MessageLogger* logger ) : CTCPSocket( logger ) { // set the socket to reuse the address in case it hasn't been released yet @@ -560,7 +562,7 @@ CTCPSocket *CTCPServer :: Accept( fd_set *fd ) { // success! return the new socket - return new CTCPSocket( NewSocket, Addr ); + return new CTCPSocket( this, NewSocket, Addr ); } } @@ -571,7 +573,7 @@ CTCPSocket *CTCPServer :: Accept( fd_set *fd ) // CUDPSocket // -CUDPSocket :: CUDPSocket( ) : CSocket( ) +CUDPSocket :: CUDPSocket( MessageLogger* logger ) : CSocket( logger ) { Allocate( SOCK_DGRAM ); @@ -693,7 +695,7 @@ void CUDPSocket :: SetDontRoute( bool dontRoute ) // CUDPServer // -CUDPServer :: CUDPServer( ) : CUDPSocket( ) +CUDPServer :: CUDPServer( MessageLogger* logger ) : CUDPSocket( logger ) { // make socket non blocking diff --git a/ghost/socket.h b/ghost/socket.h index 8fa879b..7c8ab39 100644 --- a/ghost/socket.h +++ b/ghost/socket.h @@ -21,6 +21,8 @@ #ifndef SOCKET_H #define SOCKET_H +#include "messagelogger.h" + #ifdef WIN32 #include #include @@ -99,7 +101,7 @@ // CSocket // -class CSocket +class CSocket : protected MessageLogger { protected: SOCKET m_Socket; @@ -108,8 +110,8 @@ class CSocket int m_Error; public: - CSocket( ); - CSocket( SOCKET nSocket, struct sockaddr_in nSIN ); + CSocket( MessageLogger* logger ); + CSocket( MessageLogger* logger, SOCKET nSocket, struct sockaddr_in nSIN ); ~CSocket( ); virtual BYTEARRAY GetPort( ); @@ -140,8 +142,8 @@ class CTCPSocket : public CSocket uint32_t m_LastSend; public: - CTCPSocket( ); - CTCPSocket( SOCKET nSocket, struct sockaddr_in nSIN ); + CTCPSocket( MessageLogger* logger ); + CTCPSocket( MessageLogger* logger, SOCKET nSocket, struct sockaddr_in nSIN ); virtual ~CTCPSocket( ); virtual void Reset( ); @@ -170,7 +172,7 @@ class CTCPClient : public CTCPSocket bool m_Connecting; public: - CTCPClient( ); + CTCPClient( MessageLogger* logger ); virtual ~CTCPClient( ); virtual void Reset( ); @@ -187,7 +189,7 @@ class CTCPClient : public CTCPSocket class CTCPServer : public CTCPSocket { public: - CTCPServer( ); + CTCPServer( MessageLogger* logger ); virtual ~CTCPServer( ); virtual bool Listen( string address, uint16_t port ); @@ -203,7 +205,7 @@ class CUDPSocket : public CSocket protected: struct in_addr m_BroadcastTarget; public: - CUDPSocket( ); + CUDPSocket( MessageLogger* logger ); virtual ~CUDPSocket( ); virtual bool SendTo( struct sockaddr_in sin, BYTEARRAY message ); @@ -220,7 +222,7 @@ class CUDPSocket : public CSocket class CUDPServer : public CUDPSocket { public: - CUDPServer( ); + CUDPServer( MessageLogger* logger ); virtual ~CUDPServer( ); virtual bool Bind( struct sockaddr_in sin ); diff --git a/ghost/stats.cpp b/ghost/stats.cpp index 9dec048..7bf7757 100644 --- a/ghost/stats.cpp +++ b/ghost/stats.cpp @@ -20,12 +20,14 @@ #include "ghost.h" #include "stats.h" +#include "game_base.h" // // CStats // CStats :: CStats( CBaseGame *nGame ) + : MessageLogger( nGame ) { m_Game = nGame; } diff --git a/ghost/stats.h b/ghost/stats.h index bc02812..0cbe3ca 100644 --- a/ghost/stats.h +++ b/ghost/stats.h @@ -21,6 +21,8 @@ #ifndef STATS_H #define STATS_H +#include "messagelogger.h" + // // CStats // @@ -35,7 +37,7 @@ class CIncomingAction; class CGHostDB; -class CStats +class CStats : protected MessageLogger { protected: CBaseGame *m_Game; From 5db5c0ea290bbc4f19d155580b6a021f2100307e Mon Sep 17 00:00:00 2001 From: luqasn Date: Sat, 3 Apr 2010 23:54:35 +0000 Subject: [PATCH 3/7] Minor changes to improve GHost++'s usability as a library --- ghost/bncsutilinterface.h | 4 +-- ghost/bnet.cpp | 10 +++++-- ghost/bnet.h | 8 +++--- ghost/ghost.cpp | 6 +++- ghost/ghost.h | 28 +++++++++--------- ghost/messagelogger.cpp | 21 ++++++++++---- ghost/messagelogger.h | 60 ++++++++++++++++++++++++++++----------- ghost/util.cpp | 6 ++-- 8 files changed, 96 insertions(+), 47 deletions(-) diff --git a/ghost/bncsutilinterface.h b/ghost/bncsutilinterface.h index 4c4fcd3..592e534 100644 --- a/ghost/bncsutilinterface.h +++ b/ghost/bncsutilinterface.h @@ -30,7 +30,7 @@ class CBNET; class CBNCSUtilInterface : protected MessageLogger { -private: +protected: void *m_NLS; BYTEARRAY m_EXEVersion; // set in HELP_SID_AUTH_CHECK BYTEARRAY m_EXEVersionHash; // set in HELP_SID_AUTH_CHECK @@ -64,7 +64,7 @@ class CBNCSUtilInterface : protected MessageLogger bool HELP_SID_AUTH_ACCOUNTLOGONPROOF( BYTEARRAY salt, BYTEARRAY serverKey ); bool HELP_PvPGNPasswordHash( string userPassword ); -private: +protected: BYTEARRAY CreateKeyInfo( string key, uint32_t clientToken, uint32_t serverToken ); }; diff --git a/ghost/bnet.cpp b/ghost/bnet.cpp index 662741d..fd178eb 100644 --- a/ghost/bnet.cpp +++ b/ghost/bnet.cpp @@ -937,12 +937,18 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) if( Event == CBNETProtocol :: EID_WHISPER ) { CONSOLE_Print( "[WHISPER: " + m_ServerAlias + "] [" + User + "] " + Message ); - m_GHost->EventBNETWhisper( this, User, Message ); + // magic code, don't show these + // user sent those fake whispers + if( chatEvent->GetPing( ) != 13371337 ) + m_GHost->EventBNETWhisper( this, User, Message ); } else { CONSOLE_Print( "[LOCAL: " + m_ServerAlias + "] [" + User + "] " + Message ); - m_GHost->EventBNETChat( this, User, Message ); + // magic code, don't show these + // user sent those fake whispers + if( chatEvent->GetPing( ) != 13371337 ) + m_GHost->EventBNETChat( this, User, Message ); } // handle spoof checking for current game diff --git a/ghost/bnet.h b/ghost/bnet.h index ff3ac81..9cc7c83 100644 --- a/ghost/bnet.h +++ b/ghost/bnet.h @@ -61,7 +61,7 @@ class CBNET : protected MessageLogger public: CGHost *m_GHost; -private: +protected: CTCPClient *m_Socket; // the connection to battle.net CBNETProtocol *m_Protocol; // battle.net protocol CBNLSClient *m_BNLSClient; // the BNLS client (for external warden handling) @@ -154,9 +154,9 @@ class CBNET : protected MessageLogger unsigned int SetFD( void *fd, void *send_fd, int *nfds ); bool Update( void *fd, void *send_fd ); - void ExtractPackets( ); + virtual void ExtractPackets( ); void ProcessPackets( ); - void ProcessChatEvent( CIncomingChatEvent *chatEvent ); + virtual void ProcessChatEvent( CIncomingChatEvent *chatEvent ); // functions to send packets to battle.net @@ -166,7 +166,7 @@ class CBNET : protected MessageLogger void QueueEnterChat( ); void QueueChatCommand( string chatCommand ); void QueueChatCommand( string chatCommand, string user, bool whisper ); - void QueueGameCreate( unsigned char state, string gameName, string hostName, CMap *map, CSaveGame *saveGame, uint32_t hostCounter ); + virtual void QueueGameCreate( unsigned char state, string gameName, string hostName, CMap *map, CSaveGame *saveGame, uint32_t hostCounter ); void QueueGameRefresh( unsigned char state, string gameName, string hostName, CMap *map, CSaveGame *saveGame, uint32_t upTime, uint32_t hostCounter ); void QueueGameUncreate( ); diff --git a/ghost/ghost.cpp b/ghost/ghost.cpp index 82d3a94..50f5a43 100644 --- a/ghost/ghost.cpp +++ b/ghost/ghost.cpp @@ -625,6 +625,9 @@ CGHost :: CGHost( MessageLogger *logger, CConfig *CFG ) ExtractScripts( ); + if( m_DefaultMap.empty( ) ) + SetEnabled( false ); + // load the default maps (note: make sure to run ExtractScripts first) if( m_DefaultMap.size( ) < 4 || m_DefaultMap.substr( m_DefaultMap.size( ) - 4 ) != ".cfg" ) @@ -636,6 +639,7 @@ CGHost :: CGHost( MessageLogger *logger, CConfig *CFG ) CConfig MapCFG( this ); MapCFG.Read( m_MapCFGPath + m_DefaultMap ); m_Map = new CMap( this, &MapCFG, m_MapCFGPath + m_DefaultMap ); + SetEnabled( true ); if( !m_AdminGameMap.empty( ) ) { @@ -668,7 +672,7 @@ CGHost :: CGHost( MessageLogger *logger, CConfig *CFG ) // load the iptocountry data - LoadIPToCountryData( ); + //LoadIPToCountryData( ); // create the admin game diff --git a/ghost/ghost.h b/ghost/ghost.h index b1a132c..69f0537 100644 --- a/ghost/ghost.h +++ b/ghost/ghost.h @@ -44,7 +44,7 @@ class CMap; class CSaveGame; class CConfig; -class CGHost : protected MessageLogger +class CGHost : public MessageLogger { public: CUDPSocket *m_UDPSocket; // a UDP socket for sending broadcasts and other junk (used with !sendlan) @@ -144,25 +144,25 @@ class CGHost : protected MessageLogger // events - void EventBNETConnecting( CBNET *bnet ); - void EventBNETConnected( CBNET *bnet ); - void EventBNETDisconnected( CBNET *bnet ); - void EventBNETLoggedIn( CBNET *bnet ); - void EventBNETGameRefreshed( CBNET *bnet ); - void EventBNETGameRefreshFailed( CBNET *bnet ); - void EventBNETConnectTimedOut( CBNET *bnet ); - void EventBNETWhisper( CBNET *bnet, string user, string message ); - void EventBNETChat( CBNET *bnet, string user, string message ); - void EventBNETEmote( CBNET *bnet, string user, string message ); - void EventGameDeleted( CBaseGame *game ); + virtual void EventBNETConnecting( CBNET *bnet ); + virtual void EventBNETConnected( CBNET *bnet ); + virtual void EventBNETDisconnected( CBNET *bnet ); + virtual void EventBNETLoggedIn( CBNET *bnet ); + virtual void EventBNETGameRefreshed( CBNET *bnet ); + virtual void EventBNETGameRefreshFailed( CBNET *bnet ); + virtual void EventBNETConnectTimedOut( CBNET *bnet ); + virtual void EventBNETWhisper( CBNET *bnet, string user, string message ); + virtual void EventBNETChat( CBNET *bnet, string user, string message ); + virtual void EventBNETEmote( CBNET *bnet, string user, string message ); + virtual void EventGameDeleted( CBaseGame *game ); // other functions void ReloadConfigs( ); void SetConfigs( CConfig *CFG ); void ExtractScripts( ); - void LoadIPToCountryData( ); - void CreateGame( CMap *map, unsigned char gameState, bool saveGame, string gameName, string ownerName, string creatorName, string creatorServer, bool whisper ); + virtual void LoadIPToCountryData( ); + virtual void CreateGame( CMap *map, unsigned char gameState, bool saveGame, string gameName, string ownerName, string creatorName, string creatorServer, bool whisper ); }; #endif diff --git a/ghost/messagelogger.cpp b/ghost/messagelogger.cpp index 32c6162..e4efe07 100644 --- a/ghost/messagelogger.cpp +++ b/ghost/messagelogger.cpp @@ -1,10 +1,21 @@ -/* - * loggingclass.cpp - * Genie +/* messagelogger.cpp * - * Created by Lucas on 27.03.10. - * Copyright 2010 Lucas Romero. All rights reserved. + * This file is part of Genie + * Copyright (C) 2009-2010 Lucas Romero + * Created 27.03.10 * + * Genie is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Genie is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Genie. If not, see . */ #include "messagelogger.h" diff --git a/ghost/messagelogger.h b/ghost/messagelogger.h index cc1f5a7..9141683 100644 --- a/ghost/messagelogger.h +++ b/ghost/messagelogger.h @@ -1,10 +1,21 @@ -/* - * loggingclass.h - * Genie +/* messagelogger.h * - * Created by Lucas on 27.03.10. - * Copyright 2010 Lucas Romero. All rights reserved. + * This file is part of Genie + * Copyright (C) 2009-2010 Lucas Romero + * Created 27.03.10 * + * Genie is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Genie is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Genie. If not, see . */ #ifndef LOGGINGCLASS_H @@ -14,39 +25,56 @@ #include using namespace std; -typedef void (*LogMessageHandler)( const string &message ); +typedef void (*LogMessageHandler)( void *callbackObject, const string &message ); class MessageLogger { public: - MessageLogger( MessageLogger *parentLogger ) : parent( parentLogger), messageHandler( NULL ) + MessageLogger( MessageLogger *parentLogger ) : Parent( parentLogger), MessageHandler( NULL ), CallbackObject( NULL ), enabled( true ) { /* empty constructor */ } - MessageLogger( LogMessageHandler msgHandler ) : parent( NULL ), messageHandler( msgHandler ) + MessageLogger( LogMessageHandler msgHandler, void *callbackObject ) : Parent( NULL ), MessageHandler( msgHandler ), CallbackObject( callbackObject ), enabled( true ) { /* empty constructor */ } + bool Enabled( ) { return enabled; } + void SetEnabled( bool value ) { enabled = value; } + void LogInfo( const string &msg ) { WriteLine( msg ); } + void LogWarning( const string &msg ) + { + WriteLine( msg ); + } + + void LogError( const string &msg ) + { + WriteLine( msg ); + } + void WriteLine( const string &msg ) { - if( parent != NULL ) { + if( !enabled ) + return; + if( Parent != NULL ) { // let the parent handle the message - parent->LogInfo( msg ); + Parent->LogInfo( msg ); } - else if ( messageHandler != NULL ) { + else if ( MessageHandler != NULL ) { // call function provided by user - messageHandler( msg ); + MessageHandler( CallbackObject, msg ); } - else { + /*else { // got nowhere to log to, print to stdout cout << msg << endl; - } + }*/ } protected: - MessageLogger *parent; - LogMessageHandler messageHandler; + MessageLogger *Parent; + LogMessageHandler MessageHandler; + void *CallbackObject; + bool enabled; }; #endif \ No newline at end of file diff --git a/ghost/util.cpp b/ghost/util.cpp index 6f158c0..61325e6 100644 --- a/ghost/util.cpp +++ b/ghost/util.cpp @@ -413,7 +413,7 @@ string UTIL_FileRead( string file, uint32_t start, uint32_t length ) if( IS.fail( ) ) { - CONSOLE_Print( "[UTIL] warning - unable to read file part [" + file + "]" ); + //CONSOLE_Print( "[UTIL] warning - unable to read file part [" + file + "]" ); return string( ); } @@ -447,7 +447,7 @@ string UTIL_FileRead( string file ) if( IS.fail( ) ) { - CONSOLE_Print( "[UTIL] warning - unable to read file [" + file + "]" ); + //CONSOLE_Print( "[UTIL] warning - unable to read file [" + file + "]" ); return string( ); } @@ -478,7 +478,7 @@ bool UTIL_FileWrite( string file, unsigned char *data, uint32_t length ) if( OS.fail( ) ) { - CONSOLE_Print( "[UTIL] warning - unable to write file [" + file + "]" ); + //CONSOLE_Print( "[UTIL] warning - unable to write file [" + file + "]" ); return false; } From c7f5b5fbd33e86b296af3cd887eb66a851a89a93 Mon Sep 17 00:00:00 2001 From: "MyFakeAcc.4@googlemail.com" Date: Tue, 5 Oct 2010 12:56:04 +0000 Subject: [PATCH 4/7] Updating Genie's ghost to 17.1 (r555) Modified ghost.cpp to use only ghost.cfg --- ghost/bnet.cpp | 203 ++++++++-------- ghost/bnetprotocol.cpp | 33 +-- ghost/bnetprotocol.h | 6 +- ghost/commandpacket.cpp | 6 +- ghost/crc32.cpp | 4 +- ghost/csvparser.cpp | 15 +- ghost/game.cpp | 320 ++++++++++++------------- ghost/game_admin.cpp | 123 +++++----- ghost/game_base.cpp | 501 +++++++++++++++++++++------------------- ghost/game_base.h | 1 + ghost/gameplayer.cpp | 120 ++-------- ghost/gameprotocol.cpp | 72 +++--- ghost/gameprotocol.h | 12 +- ghost/gameslot.cpp | 11 +- ghost/gameslot.h | 4 +- ghost/ghost.cpp | 86 +++---- ghost/ghostdb.cpp | 115 ++------- ghost/ghostdbmysql.cpp | 104 ++++----- ghost/ghostdbsqlite.cpp | 8 +- ghost/map.cpp | 220 +++++++++++++----- ghost/map.h | 52 ++++- ghost/packed.cpp | 21 +- ghost/replay.cpp | 133 +++-------- ghost/replay.h | 18 +- ghost/savegame.cpp | 5 +- ghost/sha1.cpp | 8 +- ghost/socket.cpp | 25 +- ghost/stats.cpp | 5 +- ghost/statsdota.cpp | 26 +-- ghost/statsw3mmd.cpp | 23 +- ghost/util.cpp | 18 +- 31 files changed, 1113 insertions(+), 1185 deletions(-) diff --git a/ghost/bnet.cpp b/ghost/bnet.cpp index fd178eb..dd06846 100644 --- a/ghost/bnet.cpp +++ b/ghost/bnet.cpp @@ -88,10 +88,12 @@ CBNET :: CBNET( CGHost *nGHost, string nServer, string nServerAlias, string nBNL m_CDKeyROC = nCDKeyROC; m_CDKeyTFT = nCDKeyTFT; - // remove dashes from CD keys and convert to uppercase + // remove dashes and spaces from CD keys and convert to uppercase m_CDKeyROC.erase( remove( m_CDKeyROC.begin( ), m_CDKeyROC.end( ), '-' ), m_CDKeyROC.end( ) ); m_CDKeyTFT.erase( remove( m_CDKeyTFT.begin( ), m_CDKeyTFT.end( ), '-' ), m_CDKeyTFT.end( ) ); + m_CDKeyROC.erase( remove( m_CDKeyROC.begin( ), m_CDKeyROC.end( ), ' ' ), m_CDKeyROC.end( ) ); + m_CDKeyTFT.erase( remove( m_CDKeyTFT.begin( ), m_CDKeyTFT.end( ), ' ' ), m_CDKeyTFT.end( ) ); transform( m_CDKeyROC.begin( ), m_CDKeyROC.end( ), m_CDKeyROC.begin( ), (int(*)(int))toupper ); transform( m_CDKeyTFT.begin( ), m_CDKeyTFT.end( ), m_CDKeyTFT.begin( ), (int(*)(int))toupper ); @@ -147,34 +149,34 @@ CBNET :: ~CBNET( ) delete m_BNCSUtil; - for( vector :: iterator i = m_Friends.begin( ); i != m_Friends.end( ); i++ ) + for( vector :: iterator i = m_Friends.begin( ); i != m_Friends.end( ); ++i ) delete *i; - for( vector :: iterator i = m_Clans.begin( ); i != m_Clans.end( ); i++ ) + for( vector :: iterator i = m_Clans.begin( ); i != m_Clans.end( ); ++i ) delete *i; - for( vector :: iterator i = m_PairedAdminCounts.begin( ); i != m_PairedAdminCounts.end( ); i++ ) + for( vector :: iterator i = m_PairedAdminCounts.begin( ); i != m_PairedAdminCounts.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedAdminAdds.begin( ); i != m_PairedAdminAdds.end( ); i++ ) + for( vector :: iterator i = m_PairedAdminAdds.begin( ); i != m_PairedAdminAdds.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedAdminRemoves.begin( ); i != m_PairedAdminRemoves.end( ); i++ ) + for( vector :: iterator i = m_PairedAdminRemoves.begin( ); i != m_PairedAdminRemoves.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedBanCounts.begin( ); i != m_PairedBanCounts.end( ); i++ ) + for( vector :: iterator i = m_PairedBanCounts.begin( ); i != m_PairedBanCounts.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedBanAdds.begin( ); i != m_PairedBanAdds.end( ); i++ ) + for( vector :: iterator i = m_PairedBanAdds.begin( ); i != m_PairedBanAdds.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedBanRemoves.begin( ); i != m_PairedBanRemoves.end( ); i++ ) + for( vector :: iterator i = m_PairedBanRemoves.begin( ); i != m_PairedBanRemoves.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedGPSChecks.begin( ); i != m_PairedGPSChecks.end( ); i++ ) + for( vector :: iterator i = m_PairedGPSChecks.begin( ); i != m_PairedGPSChecks.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedDPSChecks.begin( ); i != m_PairedDPSChecks.end( ); i++ ) + for( vector :: iterator i = m_PairedDPSChecks.begin( ); i != m_PairedDPSChecks.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); if( m_CallableAdminList ) @@ -183,7 +185,7 @@ CBNET :: ~CBNET( ) if( m_CallableBanList ) m_GHost->m_Callables.push_back( m_CallableBanList ); - for( vector :: iterator i = m_Bans.begin( ); i != m_Bans.end( ); i++ ) + for( vector :: iterator i = m_Bans.begin( ); i != m_Bans.end( ); ++i ) delete *i; } @@ -199,7 +201,7 @@ unsigned int CBNET :: SetFD( void *fd, void *send_fd, int *nfds ) if( !m_Socket->HasError( ) && m_Socket->GetConnected( ) ) { m_Socket->SetFD( (fd_set *)fd, (fd_set *)send_fd, nfds ); - NumFDs++; + ++NumFDs; if( m_BNLSClient ) NumFDs += m_BNLSClient->SetFD( fd, send_fd, nfds ); @@ -232,7 +234,7 @@ bool CBNET :: Update( void *fd, void *send_fd ) i = m_PairedAdminCounts.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedAdminAdds.begin( ); i != m_PairedAdminAdds.end( ); ) @@ -252,7 +254,7 @@ bool CBNET :: Update( void *fd, void *send_fd ) i = m_PairedAdminAdds.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedAdminRemoves.begin( ); i != m_PairedAdminRemoves.end( ); ) @@ -272,7 +274,7 @@ bool CBNET :: Update( void *fd, void *send_fd ) i = m_PairedAdminRemoves.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedBanCounts.begin( ); i != m_PairedBanCounts.end( ); ) @@ -293,7 +295,7 @@ bool CBNET :: Update( void *fd, void *send_fd ) i = m_PairedBanCounts.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedBanAdds.begin( ); i != m_PairedBanAdds.end( ); ) @@ -313,7 +315,7 @@ bool CBNET :: Update( void *fd, void *send_fd ) i = m_PairedBanAdds.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedBanRemoves.begin( ); i != m_PairedBanRemoves.end( ); ) @@ -333,7 +335,7 @@ bool CBNET :: Update( void *fd, void *send_fd ) i = m_PairedBanRemoves.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedGPSChecks.begin( ); i != m_PairedGPSChecks.end( ); ) @@ -352,7 +354,7 @@ bool CBNET :: Update( void *fd, void *send_fd ) i = m_PairedGPSChecks.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedDPSChecks.begin( ); i != m_PairedDPSChecks.end( ); ) @@ -396,7 +398,7 @@ bool CBNET :: Update( void *fd, void *send_fd ) i = m_PairedDPSChecks.erase( i ); } else - i++; + ++i; } // refresh the admin list every 5 minutes @@ -423,7 +425,7 @@ bool CBNET :: Update( void *fd, void *send_fd ) { // CONSOLE_Print( "[BNET: " + m_ServerAlias + "] refreshed ban list (" + UTIL_ToString( m_Bans.size( ) ) + " -> " + UTIL_ToString( m_CallableBanList->GetResult( ).size( ) ) + " bans)" ); - for( vector :: iterator i = m_Bans.begin( ); i != m_Bans.end( ); i++ ) + for( vector :: iterator i = m_Bans.begin( ); i != m_Bans.end( ); ++i ) delete *i; m_Bans = m_CallableBanList->GetResult( ); @@ -904,7 +906,7 @@ void CBNET :: ProcessPackets( ) case CBNETProtocol :: SID_FRIENDSLIST: Friends = m_Protocol->RECEIVE_SID_FRIENDSLIST( Packet->GetData( ) ); - for( vector :: iterator i = m_Friends.begin( ); i != m_Friends.end( ); i++ ) + for( vector :: iterator i = m_Friends.begin( ); i != m_Friends.end( ); ++i ) delete *i; m_Friends = Friends; @@ -913,7 +915,7 @@ void CBNET :: ProcessPackets( ) case CBNETProtocol :: SID_CLANMEMBERLIST: vector Clans = m_Protocol->RECEIVE_SID_CLANMEMBERLIST( Packet->GetData( ) ); - for( vector :: iterator i = m_Clans.begin( ); i != m_Clans.end( ); i++ ) + for( vector :: iterator i = m_Clans.begin( ); i != m_Clans.end( ); ++i ) delete *i; m_Clans = Clans; @@ -1032,7 +1034,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !BAN // - if( ( Command == "addban" || Command == "ban" ) && !Payload.empty( ) ) + else if( ( Command == "addban" || Command == "ban" ) && !Payload.empty( ) ) { // extract the victim and the reason // e.g. "Varlock leaver after dying" -> victim: "Varlock", reason: "leaver after dying" @@ -1062,7 +1064,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !ANNOUNCE // - if( Command == "announce" && m_GHost->m_CurrentGame && !m_GHost->m_CurrentGame->GetCountDownStarted( ) ) + else if( Command == "announce" && m_GHost->m_CurrentGame && !m_GHost->m_CurrentGame->GetCountDownStarted( ) ) { if( Payload.empty( ) || Payload == "off" ) { @@ -1105,7 +1107,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !AUTOHOST // - if( Command == "autohost" ) + else if( Command == "autohost" ) { if( IsRootAdmin( User ) ) { @@ -1179,7 +1181,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !AUTOHOSTMM // - if( Command == "autohostmm" ) + else if( Command == "autohostmm" ) { if( IsRootAdmin( User ) ) { @@ -1269,7 +1271,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !AUTOSTART // - if( Command == "autostart" && m_GHost->m_CurrentGame && !m_GHost->m_CurrentGame->GetCountDownStarted( ) ) + else if( Command == "autostart" && m_GHost->m_CurrentGame && !m_GHost->m_CurrentGame->GetCountDownStarted( ) ) { if( Payload.empty( ) || Payload == "off" ) { @@ -1292,14 +1294,14 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !CHANNEL (change channel) // - if( Command == "channel" && !Payload.empty( ) ) + else if( Command == "channel" && !Payload.empty( ) ) QueueChatCommand( "/join " + Payload ); // // !CHECKADMIN // - if( Command == "checkadmin" && !Payload.empty( ) ) + else if( Command == "checkadmin" && !Payload.empty( ) ) { if( IsRootAdmin( User ) ) { @@ -1316,7 +1318,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !CHECKBAN // - if( Command == "checkban" && !Payload.empty( ) ) + else if( Command == "checkban" && !Payload.empty( ) ) { CDBBan *Ban = IsBannedName( Payload ); @@ -1330,7 +1332,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !CLOSE (close slot) // - if( Command == "close" && !Payload.empty( ) && m_GHost->m_CurrentGame ) + else if( Command == "close" && !Payload.empty( ) && m_GHost->m_CurrentGame ) { if( !m_GHost->m_CurrentGame->GetLocked( ) ) { @@ -1361,7 +1363,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !CLOSEALL // - if( Command == "closeall" && m_GHost->m_CurrentGame ) + else if( Command == "closeall" && m_GHost->m_CurrentGame ) { if( !m_GHost->m_CurrentGame->GetLocked( ) ) m_GHost->m_CurrentGame->CloseAllSlots( ); @@ -1373,7 +1375,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !COUNTADMINS // - if( Command == "countadmins" ) + else if( Command == "countadmins" ) { if( IsRootAdmin( User ) ) m_PairedAdminCounts.push_back( PairedAdminCount( Whisper ? User : string( ), m_GHost->m_DB->ThreadedAdminCount( m_Server ) ) ); @@ -1385,21 +1387,21 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !COUNTBANS // - if( Command == "countbans" ) + else if( Command == "countbans" ) m_PairedBanCounts.push_back( PairedBanCount( Whisper ? User : string( ), m_GHost->m_DB->ThreadedBanCount( m_Server ) ) ); // // !DBSTATUS // - if( Command == "dbstatus" ) + else if( Command == "dbstatus" ) QueueChatCommand( m_GHost->m_DB->GetStatus( ), User, Whisper ); // // !DELADMIN // - if( Command == "deladmin" && !Payload.empty( ) ) + else if( Command == "deladmin" && !Payload.empty( ) ) { if( IsRootAdmin( User ) ) { @@ -1417,14 +1419,14 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !UNBAN // - if( ( Command == "delban" || Command == "unban" ) && !Payload.empty( ) ) + else if( ( Command == "delban" || Command == "unban" ) && !Payload.empty( ) ) m_PairedBanRemoves.push_back( PairedBanRemove( Whisper ? User : string( ), m_GHost->m_DB->ThreadedBanRemove( Payload ) ) ); // // !DISABLE // - if( Command == "disable" ) + else if( Command == "disable" ) { if( IsRootAdmin( User ) ) { @@ -1439,7 +1441,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !DOWNLOADS // - if( Command == "downloads" && !Payload.empty( ) ) + else if( Command == "downloads" && !Payload.empty( ) ) { uint32_t Downloads = UTIL_ToUInt32( Payload ); @@ -1464,7 +1466,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !ENABLE // - if( Command == "enable" ) + else if( Command == "enable" ) { if( IsRootAdmin( User ) ) { @@ -1479,7 +1481,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !END // - if( Command == "end" && !Payload.empty( ) ) + else if( Command == "end" && !Payload.empty( ) ) { // todotodo: what if a game ends just as you're typing this command and the numbering changes? @@ -1506,7 +1508,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !ENFORCESG // - if( Command == "enforcesg" && !Payload.empty( ) ) + else if( Command == "enforcesg" && !Payload.empty( ) ) { // only load files in the current directory just to be safe @@ -1535,7 +1537,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !QUIT // - if( Command == "exit" || Command == "quit" ) + else if( Command == "exit" || Command == "quit" ) { if( IsRootAdmin( User ) ) { @@ -1559,7 +1561,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !GETCLAN // - if( Command == "getclan" ) + else if( Command == "getclan" ) { SendGetClanList( ); QueueChatCommand( m_GHost->m_Language->UpdatingClanList( ), User, Whisper ); @@ -1569,7 +1571,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !GETFRIENDS // - if( Command == "getfriends" ) + else if( Command == "getfriends" ) { SendGetFriendsList( ); QueueChatCommand( m_GHost->m_Language->UpdatingFriendsList( ), User, Whisper ); @@ -1579,7 +1581,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !GETGAME // - if( Command == "getgame" && !Payload.empty( ) ) + else if( Command == "getgame" && !Payload.empty( ) ) { uint32_t GameNumber = UTIL_ToUInt32( Payload ) - 1; @@ -1593,7 +1595,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !GETGAMES // - if( Command == "getgames" ) + else if( Command == "getgames" ) { if( m_GHost->m_CurrentGame ) QueueChatCommand( m_GHost->m_Language->GameIsInTheLobby( m_GHost->m_CurrentGame->GetDescription( ), UTIL_ToString( m_GHost->m_Games.size( ) ), UTIL_ToString( m_GHost->m_MaxGames ) ), User, Whisper ); @@ -1605,7 +1607,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !HOLD (hold a slot for someone) // - if( Command == "hold" && !Payload.empty( ) && m_GHost->m_CurrentGame ) + else if( Command == "hold" && !Payload.empty( ) && m_GHost->m_CurrentGame ) { // hold as many players as specified, e.g. "Varlock Kilranin" holds players "Varlock" and "Kilranin" @@ -1634,14 +1636,14 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !HOSTSG // - if( Command == "hostsg" && !Payload.empty( ) ) + else if( Command == "hostsg" && !Payload.empty( ) ) m_GHost->CreateGame( m_GHost->m_Map, GAME_PRIVATE, true, Payload, User, User, m_Server, Whisper ); // // !LOAD (load config file) // - if( Command == "load" ) + else if( Command == "load" ) { if( Payload.empty( ) ) QueueChatCommand( m_GHost->m_Language->CurrentlyLoadedMapCFGIs( m_GHost->m_Map->GetCFGFile( ) ), User, Whisper ); @@ -1666,7 +1668,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) path LastMatch; uint32_t Matches = 0; - for( directory_iterator i( MapCFGPath ); i != EndIterator; i++ ) + for( directory_iterator i( MapCFGPath ); i != EndIterator; ++i ) { string FileName = i->filename( ); string Stem = i->path( ).stem( ); @@ -1676,7 +1678,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) if( !is_directory( i->status( ) ) && i->path( ).extension( ) == ".cfg" && FileName.find( Pattern ) != string :: npos ) { LastMatch = i->path( ); - Matches++; + ++Matches; if( FoundMapConfigs.empty( ) ) FoundMapConfigs = i->filename( ); @@ -1719,7 +1721,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !LOADSG // - if( Command == "loadsg" && !Payload.empty( ) ) + else if( Command == "loadsg" && !Payload.empty( ) ) { // only load files in the current directory just to be safe @@ -1752,7 +1754,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !MAP (load map file) // - if( Command == "map" ) + else if( Command == "map" ) { if( Payload.empty( ) ) QueueChatCommand( m_GHost->m_Language->CurrentlyLoadedMapCFGIs( m_GHost->m_Map->GetCFGFile( ) ), User, Whisper ); @@ -1777,7 +1779,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) path LastMatch; uint32_t Matches = 0; - for( directory_iterator i( MapPath ); i != EndIterator; i++ ) + for( directory_iterator i( MapPath ); i != EndIterator; ++i ) { string FileName = i->filename( ); string Stem = i->path( ).stem( ); @@ -1787,7 +1789,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) if( !is_directory( i->status( ) ) && FileName.find( Pattern ) != string :: npos ) { LastMatch = i->path( ); - Matches++; + ++Matches; if( FoundMaps.empty( ) ) FoundMaps = i->filename( ); @@ -1834,7 +1836,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !OPEN (open slot) // - if( Command == "open" && !Payload.empty( ) && m_GHost->m_CurrentGame ) + else if( Command == "open" && !Payload.empty( ) && m_GHost->m_CurrentGame ) { if( !m_GHost->m_CurrentGame->GetLocked( ) ) { @@ -1865,7 +1867,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !OPENALL // - if( Command == "openall" && m_GHost->m_CurrentGame ) + else if( Command == "openall" && m_GHost->m_CurrentGame ) { if( !m_GHost->m_CurrentGame->GetLocked( ) ) m_GHost->m_CurrentGame->OpenAllSlots( ); @@ -1877,14 +1879,14 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !PRIV (host private game) // - if( Command == "priv" && !Payload.empty( ) ) + else if( Command == "priv" && !Payload.empty( ) ) m_GHost->CreateGame( m_GHost->m_Map, GAME_PRIVATE, false, Payload, User, User, m_Server, Whisper ); // // !PRIVBY (host private game by other player) // - if( Command == "privby" && !Payload.empty( ) ) + else if( Command == "privby" && !Payload.empty( ) ) { // extract the owner and the game name // e.g. "Varlock dota 6.54b arem ~~~" -> owner: "Varlock", game name: "dota 6.54b arem ~~~" @@ -1905,14 +1907,14 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !PUB (host public game) // - if( Command == "pub" && !Payload.empty( ) ) + else if( Command == "pub" && !Payload.empty( ) ) m_GHost->CreateGame( m_GHost->m_Map, GAME_PUBLIC, false, Payload, User, User, m_Server, Whisper ); // // !PUBBY (host public game by other player) // - if( Command == "pubby" && !Payload.empty( ) ) + else if( Command == "pubby" && !Payload.empty( ) ) { // extract the owner and the game name // e.g. "Varlock dota 6.54b arem ~~~" -> owner: "Varlock", game name: "dota 6.54b arem ~~~" @@ -1933,7 +1935,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !RELOAD // - if( Command == "reload" ) + else if( Command == "reload" ) { if( IsRootAdmin( User ) ) { @@ -1948,14 +1950,14 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !SAY // - if( Command == "say" && !Payload.empty( ) ) + else if( Command == "say" && !Payload.empty( ) ) QueueChatCommand( Payload ); // // !SAYGAME // - if( Command == "saygame" && !Payload.empty( ) ) + else if( Command == "saygame" && !Payload.empty( ) ) { if( IsRootAdmin( User ) ) { @@ -1997,14 +1999,14 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !SAYGAMES // - if( Command == "saygames" && !Payload.empty( ) ) + else if( Command == "saygames" && !Payload.empty( ) ) { if( IsRootAdmin( User ) ) { if( m_GHost->m_CurrentGame ) m_GHost->m_CurrentGame->SendAllChat( Payload ); - for( vector :: iterator i = m_GHost->m_Games.begin( ); i != m_GHost->m_Games.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_Games.begin( ); i != m_GHost->m_Games.end( ); ++i ) (*i)->SendAllChat( "ADMIN: " + Payload ); } else @@ -2015,7 +2017,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !SP // - if( Command == "sp" && m_GHost->m_CurrentGame && !m_GHost->m_CurrentGame->GetCountDownStarted( ) ) + else if( Command == "sp" && m_GHost->m_CurrentGame && !m_GHost->m_CurrentGame->GetCountDownStarted( ) ) { if( !m_GHost->m_CurrentGame->GetLocked( ) ) { @@ -2030,7 +2032,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !START // - if( Command == "start" && m_GHost->m_CurrentGame && !m_GHost->m_CurrentGame->GetCountDownStarted( ) && m_GHost->m_CurrentGame->GetNumHumanPlayers( ) > 0 ) + else if( Command == "start" && m_GHost->m_CurrentGame && !m_GHost->m_CurrentGame->GetCountDownStarted( ) && m_GHost->m_CurrentGame->GetNumHumanPlayers( ) > 0 ) { if( !m_GHost->m_CurrentGame->GetLocked( ) ) { @@ -2050,7 +2052,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !SWAP (swap slots) // - if( Command == "swap" && !Payload.empty( ) && m_GHost->m_CurrentGame ) + else if( Command == "swap" && !Payload.empty( ) && m_GHost->m_CurrentGame ) { if( !m_GHost->m_CurrentGame->GetLocked( ) ) { @@ -2085,7 +2087,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !UNHOST // - if( Command == "unhost" ) + else if( Command == "unhost" ) { if( m_GHost->m_CurrentGame ) { @@ -2110,7 +2112,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !WARDENSTATUS // - if( Command == "wardenstatus" ) + else if( Command == "wardenstatus" ) { if( m_BNLSClient ) QueueChatCommand( "WARDEN STATUS --- " + UTIL_ToString( m_BNLSClient->GetTotalWardenIn( ) ) + " requests received, " + UTIL_ToString( m_BNLSClient->GetTotalWardenOut( ) ) + " responses sent.", User, Whisper ); @@ -2153,7 +2155,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !STATSDOTA // - if( Command == "statsdota" ) + else if( Command == "statsdota" ) { string StatsUser = User; @@ -2170,7 +2172,7 @@ void CBNET :: ProcessChatEvent( CIncomingChatEvent *chatEvent ) // !VERSION // - if( Command == "version" ) + else if( Command == "version" ) { if( IsAdmin( User ) || IsRootAdmin( User ) ) QueueChatCommand( m_GHost->m_Language->VersionAdmin( m_GHost->m_Version ), User, Whisper ); @@ -2328,8 +2330,6 @@ void CBNET :: QueueGameRefresh( unsigned char state, string gameName, string hos if( m_LoggedIn && map ) { - BYTEARRAY MapGameType; - // construct a fixed host counter which will be used to identify players from this realm // the fixed host counter's 4 most significant bits will contain a 4 bit ID (0-15) // the rest of the fixed host counter will contain the 28 least significant bits of the actual host counter @@ -2339,14 +2339,14 @@ void CBNET :: QueueGameRefresh( unsigned char state, string gameName, string hos uint32_t FixedHostCounter = ( hostCounter & 0x0FFFFFFF ) | ( m_HostCounterID << 28 ); - // construct the correct SID_STARTADVEX3 packet - if( saveGame ) { - MapGameType.push_back( 0 ); - MapGameType.push_back( 10 ); - MapGameType.push_back( 0 ); - MapGameType.push_back( 0 ); + uint32_t MapGameType = MAPGAMETYPE_SAVEDGAME; + + // the state should always be private when creating a saved game + + if( state == GAME_PRIVATE ) + MapGameType |= MAPGAMETYPE_PRIVATEGAME; // use an invalid map width/height to indicate reconnectable games @@ -2358,16 +2358,17 @@ void CBNET :: QueueGameRefresh( unsigned char state, string gameName, string hos MapHeight.push_back( 7 ); if( m_GHost->m_Reconnect ) - m_OutPackets.push( m_Protocol->SEND_SID_STARTADVEX3( state, MapGameType, map->GetMapGameFlags( ), MapWidth, MapHeight, gameName, hostName, upTime, "Save\\Multiplayer\\" + saveGame->GetFileNameNoPath( ), saveGame->GetMagicNumber( ), map->GetMapSHA1( ), FixedHostCounter ) ); + m_OutPackets.push( m_Protocol->SEND_SID_STARTADVEX3( state, UTIL_CreateByteArray( MapGameType, false ), map->GetMapGameFlags( ), MapWidth, MapHeight, gameName, hostName, upTime, "Save\\Multiplayer\\" + saveGame->GetFileNameNoPath( ), saveGame->GetMagicNumber( ), map->GetMapSHA1( ), FixedHostCounter ) ); else - m_OutPackets.push( m_Protocol->SEND_SID_STARTADVEX3( state, MapGameType, map->GetMapGameFlags( ), UTIL_CreateByteArray( (uint16_t)0, false ), UTIL_CreateByteArray( (uint16_t)0, false ), gameName, hostName, upTime, "Save\\Multiplayer\\" + saveGame->GetFileNameNoPath( ), saveGame->GetMagicNumber( ), map->GetMapSHA1( ), FixedHostCounter ) ); + m_OutPackets.push( m_Protocol->SEND_SID_STARTADVEX3( state, UTIL_CreateByteArray( MapGameType, false ), map->GetMapGameFlags( ), UTIL_CreateByteArray( (uint16_t)0, false ), UTIL_CreateByteArray( (uint16_t)0, false ), gameName, hostName, upTime, "Save\\Multiplayer\\" + saveGame->GetFileNameNoPath( ), saveGame->GetMagicNumber( ), map->GetMapSHA1( ), FixedHostCounter ) ); } else { - MapGameType.push_back( map->GetMapGameType( ) ); - MapGameType.push_back( 32 ); - MapGameType.push_back( 73 ); - MapGameType.push_back( 0 ); + uint32_t MapGameType = map->GetMapGameType( ); + MapGameType |= MAPGAMETYPE_UNKNOWN0; + + if( state == GAME_PRIVATE ) + MapGameType |= MAPGAMETYPE_PRIVATEGAME; // use an invalid map width/height to indicate reconnectable games @@ -2379,9 +2380,9 @@ void CBNET :: QueueGameRefresh( unsigned char state, string gameName, string hos MapHeight.push_back( 7 ); if( m_GHost->m_Reconnect ) - m_OutPackets.push( m_Protocol->SEND_SID_STARTADVEX3( state, MapGameType, map->GetMapGameFlags( ), MapWidth, MapHeight, gameName, hostName, upTime, map->GetMapPath( ), map->GetMapCRC( ), map->GetMapSHA1( ), FixedHostCounter ) ); + m_OutPackets.push( m_Protocol->SEND_SID_STARTADVEX3( state, UTIL_CreateByteArray( MapGameType, false ), map->GetMapGameFlags( ), MapWidth, MapHeight, gameName, hostName, upTime, map->GetMapPath( ), map->GetMapCRC( ), map->GetMapSHA1( ), FixedHostCounter ) ); else - m_OutPackets.push( m_Protocol->SEND_SID_STARTADVEX3( state, MapGameType, map->GetMapGameFlags( ), map->GetMapWidth( ), map->GetMapHeight( ), gameName, hostName, upTime, map->GetMapPath( ), map->GetMapCRC( ), map->GetMapSHA1( ), FixedHostCounter ) ); + m_OutPackets.push( m_Protocol->SEND_SID_STARTADVEX3( state, UTIL_CreateByteArray( MapGameType, false ), map->GetMapGameFlags( ), map->GetMapWidth( ), map->GetMapHeight( ), gameName, hostName, upTime, map->GetMapPath( ), map->GetMapCRC( ), map->GetMapSHA1( ), FixedHostCounter ) ); } } } @@ -2405,7 +2406,7 @@ void CBNET :: UnqueuePackets( unsigned char type ) m_OutPackets.pop( ); if( Packet.size( ) >= 2 && Packet[1] == type ) - Unqueued++; + ++Unqueued; else Packets.push( Packet ); } @@ -2434,7 +2435,7 @@ void CBNET :: UnqueueChatCommand( string chatCommand ) m_OutPackets.pop( ); if( Packet == PacketToUnqueue ) - Unqueued++; + ++Unqueued; else Packets.push( Packet ); } @@ -2454,7 +2455,7 @@ bool CBNET :: IsAdmin( string name ) { transform( name.begin( ), name.end( ), name.begin( ), (int(*)(int))tolower ); - for( vector :: iterator i = m_Admins.begin( ); i != m_Admins.end( ); i++ ) + for( vector :: iterator i = m_Admins.begin( ); i != m_Admins.end( ); ++i ) { if( *i == name ) return true; @@ -2494,7 +2495,7 @@ CDBBan *CBNET :: IsBannedName( string name ) // todotodo: optimize this - maybe use a map? - for( vector :: iterator i = m_Bans.begin( ); i != m_Bans.end( ); i++ ) + for( vector :: iterator i = m_Bans.begin( ); i != m_Bans.end( ); ++i ) { if( (*i)->GetName( ) == name ) return *i; @@ -2507,7 +2508,7 @@ CDBBan *CBNET :: IsBannedIP( string ip ) { // todotodo: optimize this - maybe use a map? - for( vector :: iterator i = m_Bans.begin( ); i != m_Bans.end( ); i++ ) + for( vector :: iterator i = m_Bans.begin( ); i != m_Bans.end( ); ++i ) { if( (*i)->GetIP( ) == ip ) return *i; @@ -2537,7 +2538,7 @@ void CBNET :: RemoveAdmin( string name ) if( *i == name ) i = m_Admins.erase( i ); else - i++; + ++i; } } @@ -2550,7 +2551,7 @@ void CBNET :: RemoveBan( string name ) if( (*i)->GetName( ) == name ) i = m_Bans.erase( i ); else - i++; + ++i; } } @@ -2558,7 +2559,7 @@ void CBNET :: HoldFriends( CBaseGame *game ) { if( game ) { - for( vector :: iterator i = m_Friends.begin( ); i != m_Friends.end( ); i++ ) + for( vector :: iterator i = m_Friends.begin( ); i != m_Friends.end( ); ++i ) game->AddToReserved( (*i)->GetAccount( ) ); } } @@ -2567,7 +2568,7 @@ void CBNET :: HoldClan( CBaseGame *game ) { if( game ) { - for( vector :: iterator i = m_Clans.begin( ); i != m_Clans.end( ); i++ ) + for( vector :: iterator i = m_Clans.begin( ); i != m_Clans.end( ); ++i ) game->AddToReserved( (*i)->GetName( ) ); } } diff --git a/ghost/bnetprotocol.cpp b/ghost/bnetprotocol.cpp index 79f0ca0..ed58ecb 100644 --- a/ghost/bnetprotocol.cpp +++ b/ghost/bnetprotocol.cpp @@ -314,9 +314,9 @@ bool CBNETProtocol :: RECEIVE_SID_AUTH_ACCOUNTLOGONPROOF( BYTEARRAY data ) if( ValidateLength( data ) && data.size( ) >= 8 ) { - BYTEARRAY Status = BYTEARRAY( data.begin( ) + 4, data.begin( ) + 8 ); + uint32_t Status = UTIL_ByteArrayToUInt32( BYTEARRAY( data.begin( ) + 4, data.begin( ) + 8 ), false ); - if( UTIL_ByteArrayToUInt32( Status, false ) == 0 ) + if( Status == 0 || Status == 0xE ) return true; } @@ -976,12 +976,9 @@ bool CBNETProtocol :: ValidateLength( BYTEARRAY &content ) // CIncomingGameHost // -CIncomingGameHost :: CIncomingGameHost( BYTEARRAY &nIP, uint16_t nPort, string nGameName, BYTEARRAY &nHostCounter ) +CIncomingGameHost :: CIncomingGameHost( BYTEARRAY &nIP, uint16_t nPort, string nGameName, BYTEARRAY &nHostCounter ) : m_IP( nIP ), m_Port( nPort ), m_GameName( nGameName ), m_HostCounter( nHostCounter ) { - m_IP = nIP; - m_Port = nPort; - m_GameName = nGameName; - m_HostCounter = nHostCounter; + } CIncomingGameHost :: ~CIncomingGameHost( ) @@ -995,7 +992,7 @@ string CIncomingGameHost :: GetIPString( ) if( m_IP.size( ) >= 4 ) { - for( unsigned int i = 0; i < 4; i++ ) + for( unsigned int i = 0; i < 4; ++i ) { Result += UTIL_ToString( (unsigned int)m_IP[i] ); @@ -1011,12 +1008,9 @@ string CIncomingGameHost :: GetIPString( ) // CIncomingChatEvent // -CIncomingChatEvent :: CIncomingChatEvent( CBNETProtocol :: IncomingChatEvent nChatEvent, uint32_t nPing, string nUser, string nMessage ) +CIncomingChatEvent :: CIncomingChatEvent( CBNETProtocol :: IncomingChatEvent nChatEvent, int32_t nPing, string nUser, string nMessage ) : m_ChatEvent( nChatEvent ), m_Ping( nPing ), m_User( nUser ), m_Message( nMessage ) { - m_ChatEvent = nChatEvent; - m_Ping = nPing; - m_User = nUser; - m_Message = nMessage; + } CIncomingChatEvent :: ~CIncomingChatEvent( ) @@ -1028,12 +1022,9 @@ CIncomingChatEvent :: ~CIncomingChatEvent( ) // CIncomingFriendList // -CIncomingFriendList :: CIncomingFriendList( string nAccount, unsigned char nStatus, unsigned char nArea, string nLocation ) +CIncomingFriendList :: CIncomingFriendList( string nAccount, unsigned char nStatus, unsigned char nArea, string nLocation ) : m_Account( nAccount ), m_Status( nStatus ), m_Area( nArea ), m_Location( nLocation ) { - m_Account = nAccount; - m_Status = nStatus; - m_Area = nArea; - m_Location = nLocation; + } CIncomingFriendList :: ~CIncomingFriendList( ) @@ -1102,11 +1093,9 @@ string CIncomingFriendList :: ExtractLocation( string location ) // CIncomingClanList // -CIncomingClanList :: CIncomingClanList( string nName, unsigned char nRank, unsigned char nStatus ) +CIncomingClanList :: CIncomingClanList( string nName, unsigned char nRank, unsigned char nStatus ) : m_Name( nName ), m_Rank( nRank ), m_Status( nStatus ) { - m_Name = nName; - m_Rank = nRank; - m_Status = nStatus; + } CIncomingClanList :: ~CIncomingClanList( ) diff --git a/ghost/bnetprotocol.h b/ghost/bnetprotocol.h index 159ff0c..f899840 100644 --- a/ghost/bnetprotocol.h +++ b/ghost/bnetprotocol.h @@ -201,16 +201,16 @@ class CIncomingChatEvent { private: CBNETProtocol :: IncomingChatEvent m_ChatEvent; - uint32_t m_Ping; + int32_t m_Ping; string m_User; string m_Message; public: - CIncomingChatEvent( CBNETProtocol :: IncomingChatEvent nChatEvent, uint32_t nPing, string nUser, string nMessage ); + CIncomingChatEvent( CBNETProtocol :: IncomingChatEvent nChatEvent, int32_t nPing, string nUser, string nMessage ); ~CIncomingChatEvent( ); CBNETProtocol :: IncomingChatEvent GetChatEvent( ) { return m_ChatEvent; } - uint32_t GetPing( ) { return m_Ping; } + int32_t GetPing( ) { return m_Ping; } string GetUser( ) { return m_User; } string GetMessage( ) { return m_Message; } }; diff --git a/ghost/commandpacket.cpp b/ghost/commandpacket.cpp index 9c22f74..42cb974 100644 --- a/ghost/commandpacket.cpp +++ b/ghost/commandpacket.cpp @@ -25,11 +25,9 @@ // CCommandPacket // -CCommandPacket :: CCommandPacket( unsigned char nPacketType, int nID, BYTEARRAY nData ) +CCommandPacket :: CCommandPacket( unsigned char nPacketType, int nID, BYTEARRAY nData ) : m_PacketType( nPacketType ), m_ID( nID ), m_Data( nData ) { - m_PacketType = nPacketType; - m_ID = nID; - m_Data = nData; + } CCommandPacket :: ~CCommandPacket( ) diff --git a/ghost/crc32.cpp b/ghost/crc32.cpp index 510757c..285e48f 100644 --- a/ghost/crc32.cpp +++ b/ghost/crc32.cpp @@ -3,7 +3,7 @@ void CCRC32 :: Initialize( ) { - for( int iCodes = 0; iCodes <= 0xFF; iCodes++ ) + for( int iCodes = 0; iCodes <= 0xFF; ++iCodes ) { ulTable[iCodes] = Reflect( iCodes, 8 ) << 24; @@ -18,7 +18,7 @@ uint32_t CCRC32 :: Reflect( uint32_t ulReflect, char cChar ) { uint32_t ulValue = 0; - for( int iPos = 1; iPos < ( cChar + 1 ); iPos++ ) + for( int iPos = 1; iPos < ( cChar + 1 ); ++iPos ) { if( ulReflect & 1 ) ulValue |= 1 << ( cChar - iPos ); diff --git a/ghost/csvparser.cpp b/ghost/csvparser.cpp index 47a2be0..43a9924 100644 --- a/ghost/csvparser.cpp +++ b/ghost/csvparser.cpp @@ -36,10 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace std; -CSVParser::CSVParser() +CSVParser::CSVParser() : m_sData( "" ), m_nPos( 0 ) { - m_sData = ""; - m_nPos = 0; + } void CSVParser::SkipSpaces(void) @@ -69,7 +68,7 @@ CSVParser & CSVParser::operator >>(int & nOut) while (m_nPos < m_sData.length() && m_sData[m_nPos] != ',') sTmp += m_sData[m_nPos++]; - m_nPos++; // skip past comma + ++m_nPos; // skip past comma nOut = atoi(sTmp.c_str()); return *this; } @@ -81,7 +80,7 @@ CSVParser & CSVParser::operator >>(double & nOut) while (m_nPos < m_sData.length() && m_sData[m_nPos] != ',') sTmp += m_sData[m_nPos++]; - m_nPos++; // skip past comma + ++m_nPos; // skip past comma nOut = atof(sTmp.c_str()); return *this; } @@ -95,7 +94,7 @@ CSVParser & CSVParser::operator >>(string & sOut) // Jump past first " if necessary if (m_nPos < m_sData.length() && m_sData[m_nPos] == '"') { bQuotes = true; - m_nPos++; + ++m_nPos; } while (m_nPos < m_sData.length()) { @@ -112,11 +111,11 @@ CSVParser & CSVParser::operator >>(string & sOut) // Jump past last " if necessary if (bQuotes && m_nPos < m_sData.length() && m_sData[m_nPos] == '"') - m_nPos++; + ++m_nPos; // Jump past , if necessary if (m_nPos < m_sData.length() && m_sData[m_nPos] == ',') - m_nPos++; + ++m_nPos; return *this; } diff --git a/ghost/game.cpp b/ghost/game.cpp index 17742fc..ae80075 100644 --- a/ghost/game.cpp +++ b/ghost/game.cpp @@ -66,10 +66,9 @@ class CGamePlayerSortDescByPing // CGame // -CGame :: CGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16_t nHostPort, unsigned char nGameState, string nGameName, string nOwnerName, string nCreatorName, string nCreatorServer ) : CBaseGame( nGHost, nMap, nSaveGame, nHostPort, nGameState, nGameName, nOwnerName, nCreatorName, nCreatorServer ) +CGame :: CGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16_t nHostPort, unsigned char nGameState, string nGameName, string nOwnerName, string nCreatorName, string nCreatorServer ) : CBaseGame( nGHost, nMap, nSaveGame, nHostPort, nGameState, nGameName, nOwnerName, nCreatorName, nCreatorServer ), m_DBBanLast( NULL ), m_CallableGameAdd( NULL ) { - m_DBBanLast = NULL; - m_DBGame = new CDBGame( 0, string( ), m_Map->GetMapPath( ), string( ), string( ), string( ), 0 ); + m_DBGame = new CDBGame( 0, string( ), m_Map->GetMapPath( ), string( ), string( ), string( ), 0 ); if( m_Map->GetMapType( ) == "w3mmd" ) m_Stats = new CStatsW3MMD( this, m_Map->GetMapStatsW3MMDCategory( ) ); @@ -77,8 +76,6 @@ CGame :: CGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16_t nHost m_Stats = new CStatsDOTA( this ); else m_Stats = NULL; - - m_CallableGameAdd = NULL; } CGame :: ~CGame( ) @@ -91,7 +88,7 @@ CGame :: ~CGame( ) // store the CDBGamePlayers in the database - for( vector :: iterator i = m_DBGamePlayers.begin( ); i != m_DBGamePlayers.end( ); i++ ) + for( vector :: iterator i = m_DBGamePlayers.begin( ); i != m_DBGamePlayers.end( ); ++i ) m_GHost->m_Callables.push_back( m_GHost->m_DB->ThreadedGamePlayerAdd( m_CallableGameAdd->GetResult( ), (*i)->GetName( ), (*i)->GetIP( ), (*i)->GetSpoofed( ), (*i)->GetSpoofedRealm( ), (*i)->GetReserved( ), (*i)->GetLoadingTime( ), (*i)->GetLeft( ), (*i)->GetLeftReason( ), (*i)->GetTeam( ), (*i)->GetColour( ) ) ); // store the stats in the database @@ -107,24 +104,24 @@ CGame :: ~CGame( ) m_CallableGameAdd = NULL; } - for( vector :: iterator i = m_PairedBanChecks.begin( ); i != m_PairedBanChecks.end( ); i++ ) + for( vector :: iterator i = m_PairedBanChecks.begin( ); i != m_PairedBanChecks.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedBanAdds.begin( ); i != m_PairedBanAdds.end( ); i++ ) + for( vector :: iterator i = m_PairedBanAdds.begin( ); i != m_PairedBanAdds.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedGPSChecks.begin( ); i != m_PairedGPSChecks.end( ); i++ ) + for( vector :: iterator i = m_PairedGPSChecks.begin( ); i != m_PairedGPSChecks.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedDPSChecks.begin( ); i != m_PairedDPSChecks.end( ); i++ ) + for( vector :: iterator i = m_PairedDPSChecks.begin( ); i != m_PairedDPSChecks.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_DBBans.begin( ); i != m_DBBans.end( ); i++ ) + for( vector :: iterator i = m_DBBans.begin( ); i != m_DBBans.end( ); ++i ) delete *i; delete m_DBGame; - for( vector :: iterator i = m_DBGamePlayers.begin( ); i != m_DBGamePlayers.end( ); i++ ) + for( vector :: iterator i = m_DBGamePlayers.begin( ); i != m_DBGamePlayers.end( ); ++i ) delete *i; delete m_Stats; @@ -161,7 +158,7 @@ bool CGame :: Update( void *fd, void *send_fd ) i = m_PairedBanChecks.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedBanAdds.begin( ); i != m_PairedBanAdds.end( ); ) @@ -170,7 +167,7 @@ bool CGame :: Update( void *fd, void *send_fd ) { if( i->second->GetResult( ) ) { - for( vector :: iterator j = m_GHost->m_BNETs.begin( ); j != m_GHost->m_BNETs.end( ); j++ ) + for( vector :: iterator j = m_GHost->m_BNETs.begin( ); j != m_GHost->m_BNETs.end( ); ++j ) { if( (*j)->GetServer( ) == i->second->GetServer( ) ) (*j)->AddBan( i->second->GetUser( ), i->second->GetIP( ), i->second->GetGameName( ), i->second->GetAdmin( ), i->second->GetReason( ) ); @@ -184,7 +181,7 @@ bool CGame :: Update( void *fd, void *send_fd ) i = m_PairedBanAdds.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedGPSChecks.begin( ); i != m_PairedGPSChecks.end( ); ) @@ -223,7 +220,7 @@ bool CGame :: Update( void *fd, void *send_fd ) i = m_PairedGPSChecks.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedDPSChecks.begin( ); i != m_PairedDPSChecks.end( ); ) @@ -285,7 +282,7 @@ bool CGame :: Update( void *fd, void *send_fd ) i = m_PairedDPSChecks.erase( i ); } else - i++; + ++i; } return CBaseGame :: Update( fd, send_fd ); @@ -319,7 +316,7 @@ void CGame :: EventPlayerDeleted( CGamePlayer *player ) // also keep track of the last player to leave for the !banlast command - for( vector :: iterator i = m_DBBans.begin( ); i != m_DBBans.end( ); i++ ) + for( vector :: iterator i = m_DBBans.begin( ); i != m_DBBans.end( ); ++i ) { if( (*i)->GetName( ) == player->GetName( ) ) m_DBBanLast = *i; @@ -353,7 +350,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string bool AdminCheck = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == player->GetSpoofedRealm( ) && (*i)->IsAdmin( User ) ) { @@ -364,7 +361,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string bool RootAdminCheck = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == player->GetSpoofedRealm( ) && (*i)->IsRootAdmin( User ) ) { @@ -401,7 +398,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !BAN // - if( ( Command == "addban" || Command == "ban" ) && !Payload.empty( ) && !m_GHost->m_BNETs.empty( ) ) + else if( ( Command == "addban" || Command == "ban" ) && !Payload.empty( ) && !m_GHost->m_BNETs.empty( ) ) { // extract the victim and the reason // e.g. "Varlock leaver after dying" -> victim: "Varlock", reason: "leaver after dying" @@ -431,7 +428,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // try to match each player with the passed string (e.g. "Varlock" would be matched with "lock") // we use the m_DBBans vector for this in case the player already left and thus isn't in the m_Players vector anymore - for( vector :: iterator i = m_DBBans.begin( ); i != m_DBBans.end( ); i++ ) + for( vector :: iterator i = m_DBBans.begin( ); i != m_DBBans.end( ); ++i ) { string TestName = (*i)->GetName( ); transform( TestName.begin( ), TestName.end( ), TestName.begin( ), (int(*)(int))tolower ); @@ -476,7 +473,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !ANNOUNCE // - if( Command == "announce" && !m_CountDownStarted ) + else if( Command == "announce" && !m_CountDownStarted ) { if( Payload.empty( ) || Payload == "off" ) { @@ -519,7 +516,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !AUTOSAVE // - if( Command == "autosave" ) + else if( Command == "autosave" ) { if( Payload == "on" ) { @@ -537,7 +534,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !AUTOSTART // - if( Command == "autostart" && !m_CountDownStarted ) + else if( Command == "autostart" && !m_CountDownStarted ) { if( Payload.empty( ) || Payload == "off" ) { @@ -560,14 +557,14 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !BANLAST // - if( Command == "banlast" && m_GameLoaded && !m_GHost->m_BNETs.empty( ) && m_DBBanLast ) + else if( Command == "banlast" && m_GameLoaded && !m_GHost->m_BNETs.empty( ) && m_DBBanLast ) m_PairedBanAdds.push_back( PairedBanAdd( User, m_GHost->m_DB->ThreadedBanAdd( m_DBBanLast->GetServer( ), m_DBBanLast->GetName( ), m_DBBanLast->GetIP( ), m_GameName, User, Payload ) ) ); // // !CHECK // - if( Command == "check" ) + else if( Command == "check" ) { if( !Payload.empty( ) ) { @@ -580,7 +577,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string { bool LastMatchAdminCheck = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == LastMatch->GetSpoofedRealm( ) && (*i)->IsAdmin( LastMatch->GetName( ) ) ) { @@ -591,7 +588,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string bool LastMatchRootAdminCheck = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == LastMatch->GetSpoofedRealm( ) && (*i)->IsRootAdmin( LastMatch->GetName( ) ) ) { @@ -613,9 +610,9 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !CHECKBAN // - if( Command == "checkban" && !Payload.empty( ) && !m_GHost->m_BNETs.empty( ) ) + else if( Command == "checkban" && !Payload.empty( ) && !m_GHost->m_BNETs.empty( ) ) { - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) m_PairedBanChecks.push_back( PairedBanCheck( User, m_GHost->m_DB->ThreadedBanCheck( (*i)->GetServer( ), Payload, string( ) ) ) ); } @@ -623,7 +620,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !CLEARHCL // - if( Command == "clearhcl" && !m_CountDownStarted ) + else if( Command == "clearhcl" && !m_CountDownStarted ) { m_HCLCommandString.clear( ); SendAllChat( m_GHost->m_Language->ClearingHCL( ) ); @@ -633,7 +630,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !CLOSE (close slot) // - if( Command == "close" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded ) + else if( Command == "close" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded ) { // close as many slots as specified, e.g. "5 10" closes slots 5 and 10 @@ -659,14 +656,14 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !CLOSEALL // - if( Command == "closeall" && !m_GameLoading && !m_GameLoaded ) + else if( Command == "closeall" && !m_GameLoading && !m_GameLoaded ) CloseAllSlots( ); // // !COMP (computer slot) // - if( Command == "comp" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded && !m_SaveGame ) + else if( Command == "comp" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded && !m_SaveGame ) { // extract the slot and the skill // e.g. "1 2" -> slot: "1", skill: "2" @@ -695,7 +692,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !COMPCOLOUR (computer colour change) // - if( Command == "compcolour" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded && !m_SaveGame ) + else if( Command == "compcolour" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded && !m_SaveGame ) { // extract the slot and the colour // e.g. "1 2" -> slot: "1", colour: "2" @@ -722,7 +719,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string { unsigned char SID = (unsigned char)( Slot - 1 ); - if( m_Map->GetMapGameType( ) != GAMETYPE_CUSTOM && Colour < 12 && SID < m_Slots.size( ) ) + if( !( m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) && Colour < 12 && SID < m_Slots.size( ) ) { if( m_Slots[SID].GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && m_Slots[SID].GetComputer( ) == 1 ) ColourSlot( SID, Colour ); @@ -736,7 +733,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !COMPHANDICAP (computer handicap change) // - if( Command == "comphandicap" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded && !m_SaveGame ) + else if( Command == "comphandicap" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded && !m_SaveGame ) { // extract the slot and the handicap // e.g. "1 50" -> slot: "1", handicap: "50" @@ -763,7 +760,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string { unsigned char SID = (unsigned char)( Slot - 1 ); - if( m_Map->GetMapGameType( ) != GAMETYPE_CUSTOM && ( Handicap == 50 || Handicap == 60 || Handicap == 70 || Handicap == 80 || Handicap == 90 || Handicap == 100 ) && SID < m_Slots.size( ) ) + if( !( m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) && ( Handicap == 50 || Handicap == 60 || Handicap == 70 || Handicap == 80 || Handicap == 90 || Handicap == 100 ) && SID < m_Slots.size( ) ) { if( m_Slots[SID].GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && m_Slots[SID].GetComputer( ) == 1 ) { @@ -780,7 +777,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !COMPRACE (computer race change) // - if( Command == "comprace" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded && !m_SaveGame ) + else if( Command == "comprace" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded && !m_SaveGame ) { // extract the slot and the race // e.g. "1 human" -> slot: "1", race: "human" @@ -808,33 +805,33 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string transform( Race.begin( ), Race.end( ), Race.begin( ), (int(*)(int))tolower ); unsigned char SID = (unsigned char)( Slot - 1 ); - if( m_Map->GetMapGameType( ) != GAMETYPE_CUSTOM && !( m_Map->GetMapFlags( ) & MAPFLAG_RANDOMRACES ) && SID < m_Slots.size( ) ) + if( !( m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) && !( m_Map->GetMapFlags( ) & MAPFLAG_RANDOMRACES ) && SID < m_Slots.size( ) ) { if( m_Slots[SID].GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && m_Slots[SID].GetComputer( ) == 1 ) { if( Race == "human" ) { - m_Slots[SID].SetRace( SLOTRACE_HUMAN ); + m_Slots[SID].SetRace( SLOTRACE_HUMAN | SLOTRACE_SELECTABLE ); SendAllSlotInfo( ); } else if( Race == "orc" ) { - m_Slots[SID].SetRace( SLOTRACE_ORC ); + m_Slots[SID].SetRace( SLOTRACE_ORC | SLOTRACE_SELECTABLE ); SendAllSlotInfo( ); } else if( Race == "night elf" ) { - m_Slots[SID].SetRace( SLOTRACE_NIGHTELF ); + m_Slots[SID].SetRace( SLOTRACE_NIGHTELF | SLOTRACE_SELECTABLE ); SendAllSlotInfo( ); } else if( Race == "undead" ) { - m_Slots[SID].SetRace( SLOTRACE_UNDEAD ); + m_Slots[SID].SetRace( SLOTRACE_UNDEAD | SLOTRACE_SELECTABLE ); SendAllSlotInfo( ); } else if( Race == "random" ) { - m_Slots[SID].SetRace( SLOTRACE_RANDOM ); + m_Slots[SID].SetRace( SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ); SendAllSlotInfo( ); } else @@ -849,7 +846,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !COMPTEAM (computer team change) // - if( Command == "compteam" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded && !m_SaveGame ) + else if( Command == "compteam" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded && !m_SaveGame ) { // extract the slot and the team // e.g. "1 2" -> slot: "1", team: "2" @@ -876,7 +873,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string { unsigned char SID = (unsigned char)( Slot - 1 ); - if( m_Map->GetMapGameType( ) != GAMETYPE_CUSTOM && Team < 12 && SID < m_Slots.size( ) ) + if( !( m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) && Team < 12 && SID < m_Slots.size( ) ) { if( m_Slots[SID].GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && m_Slots[SID].GetComputer( ) == 1 ) { @@ -893,7 +890,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !DBSTATUS // - if( Command == "dbstatus" ) + else if( Command == "dbstatus" ) SendAllChat( m_GHost->m_DB->GetStatus( ) ); // @@ -901,7 +898,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !DL // - if( ( Command == "download" || Command == "dl" ) && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded ) + else if( ( Command == "download" || Command == "dl" ) && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded ) { CGamePlayer *LastMatch = NULL; uint32_t Matches = GetPlayerFromNamePartial( Payload, &LastMatch ); @@ -934,14 +931,14 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !DROP // - if( Command == "drop" && m_GameLoaded ) + else if( Command == "drop" && m_GameLoaded ) StopLaggers( "lagged out (dropped by admin)" ); // // !END // - if( Command == "end" && m_GameLoaded ) + else if( Command == "end" && m_GameLoaded ) { CONSOLE_Print( "[GAME: " + m_GameName + "] is over (admin ended game)" ); StopPlayers( "was disconnected (admin ended game)" ); @@ -951,7 +948,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !FAKEPLAYER // - if( Command == "fakeplayer" && !m_CountDownStarted ) + else if( Command == "fakeplayer" && !m_CountDownStarted ) { if( m_FakePlayerPID == 255 ) CreateFakePlayer( ); @@ -963,7 +960,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !FPPAUSE // - if( Command == "fppause" && m_FakePlayerPID != 255 && m_GameLoaded ) + else if( Command == "fppause" && m_FakePlayerPID != 255 && m_GameLoaded ) { BYTEARRAY CRC; BYTEARRAY Action; @@ -975,7 +972,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !FPRESUME // - if( Command == "fpresume" && m_FakePlayerPID != 255 && m_GameLoaded ) + else if( Command == "fpresume" && m_FakePlayerPID != 255 && m_GameLoaded ) { BYTEARRAY CRC; BYTEARRAY Action; @@ -987,11 +984,11 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !FROM // - if( Command == "from" ) + else if( Command == "from" ) { string Froms; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { // we reverse the byte order on the IP because it's stored in network byte order @@ -1020,7 +1017,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !HCL // - if( Command == "hcl" && !m_CountDownStarted ) + else if( Command == "hcl" && !m_CountDownStarted ) { if( !Payload.empty( ) ) { @@ -1047,7 +1044,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !HOLD (hold a slot for someone) // - if( Command == "hold" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded ) + else if( Command == "hold" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded ) { // hold as many players as specified, e.g. "Varlock Kilranin" holds players "Varlock" and "Kilranin" @@ -1076,7 +1073,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !KICK (kick a player) // - if( Command == "kick" && !Payload.empty( ) ) + else if( Command == "kick" && !Payload.empty( ) ) { CGamePlayer *LastMatch = NULL; uint32_t Matches = GetPlayerFromNamePartial( Payload, &LastMatch ); @@ -1104,7 +1101,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !LATENCY (set game latency) // - if( Command == "latency" ) + else if( Command == "latency" ) { if( Payload.empty( ) ) SendAllChat( m_GHost->m_Language->LatencyIs( UTIL_ToString( m_Latency ) ) ); @@ -1131,7 +1128,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !LOCK // - if( Command == "lock" && ( RootAdminCheck || IsOwner( User ) ) ) + else if( Command == "lock" && ( RootAdminCheck || IsOwner( User ) ) ) { SendAllChat( m_GHost->m_Language->GameLocked( ) ); m_Locked = true; @@ -1141,7 +1138,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !MESSAGES // - if( Command == "messages" ) + else if( Command == "messages" ) { if( Payload == "on" ) { @@ -1159,7 +1156,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !MUTE // - if( Command == "mute" ) + else if( Command == "mute" ) { CGamePlayer *LastMatch = NULL; uint32_t Matches = GetPlayerFromNamePartial( Payload, &LastMatch ); @@ -1179,7 +1176,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !MUTEALL // - if( Command == "muteall" && m_GameLoaded ) + else if( Command == "muteall" && m_GameLoaded ) { SendAllChat( m_GHost->m_Language->GlobalChatMuted( ) ); m_MuteAll = true; @@ -1189,7 +1186,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !OPEN (open slot) // - if( Command == "open" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded ) + else if( Command == "open" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded ) { // open as many slots as specified, e.g. "5 10" opens slots 5 and 10 @@ -1215,14 +1212,14 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !OPENALL // - if( Command == "openall" && !m_GameLoading && !m_GameLoaded ) + else if( Command == "openall" && !m_GameLoading && !m_GameLoaded ) OpenAllSlots( ); // // !OWNER (set game owner) // - if( Command == "owner" ) + else if( Command == "owner" ) { if( RootAdminCheck || IsOwner( User ) || !GetPlayerFromName( m_OwnerName, false ) ) { @@ -1245,7 +1242,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !PING // - if( Command == "ping" ) + else if( Command == "ping" ) { // kick players with ping higher than payload if payload isn't empty // we only do this if the game hasn't started since we don't want to kick players from a game in progress @@ -1262,7 +1259,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string sort( SortedPlayers.begin( ), SortedPlayers.end( ), CGamePlayerSortDescByPing( ) ); string Pings; - for( vector :: iterator i = SortedPlayers.begin( ); i != SortedPlayers.end( ); i++ ) + for( vector :: iterator i = SortedPlayers.begin( ); i != SortedPlayers.end( ); ++i ) { Pings += (*i)->GetNameTerminated( ); Pings += ": "; @@ -1308,76 +1305,85 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !PRIV (rehost as private game) // - if( Command == "priv" && !Payload.empty( ) && !m_CountDownStarted && !m_SaveGame ) + else if( Command == "priv" && !Payload.empty( ) && !m_CountDownStarted && !m_SaveGame ) { - CONSOLE_Print( "[GAME: " + m_GameName + "] trying to rehost as private game [" + Payload + "]" ); - SendAllChat( m_GHost->m_Language->TryingToRehostAsPrivateGame( Payload ) ); - m_GameState = GAME_PRIVATE; - m_LastGameName = m_GameName; - m_GameName = Payload; - m_HostCounter = m_GHost->m_HostCounter++; - m_RefreshError = false; - m_RefreshRehosted = true; - - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + if( Payload.length() < 31 ) { - // unqueue any existing game refreshes because we're going to assume the next successful game refresh indicates that the rehost worked - // this ignores the fact that it's possible a game refresh was just sent and no response has been received yet - // we assume this won't happen very often since the only downside is a potential false positive + CONSOLE_Print( "[GAME: " + m_GameName + "] trying to rehost as private game [" + Payload + "]" ); + SendAllChat( m_GHost->m_Language->TryingToRehostAsPrivateGame( Payload ) ); + m_GameState = GAME_PRIVATE; + m_LastGameName = m_GameName; + m_GameName = Payload; + m_HostCounter = m_GHost->m_HostCounter++; + m_RefreshError = false; + m_RefreshRehosted = true; + + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) + { + // unqueue any existing game refreshes because we're going to assume the next successful game refresh indicates that the rehost worked + // this ignores the fact that it's possible a game refresh was just sent and no response has been received yet + // we assume this won't happen very often since the only downside is a potential false positive - (*i)->UnqueueGameRefreshes( ); - (*i)->QueueGameUncreate( ); - (*i)->QueueEnterChat( ); + (*i)->UnqueueGameRefreshes( ); + (*i)->QueueGameUncreate( ); + (*i)->QueueEnterChat( ); - // we need to send the game creation message now because private games are not refreshed + // we need to send the game creation message now because private games are not refreshed - (*i)->QueueGameCreate( m_GameState, m_GameName, string( ), m_Map, NULL, m_HostCounter ); + (*i)->QueueGameCreate( m_GameState, m_GameName, string( ), m_Map, NULL, m_HostCounter ); - if( (*i)->GetPasswordHashType( ) != "pvpgn" ) - (*i)->QueueEnterChat( ); - } + if( (*i)->GetPasswordHashType( ) != "pvpgn" ) + (*i)->QueueEnterChat( ); + } - m_CreationTime = GetTime( ); - m_LastRefreshTime = GetTime( ); + m_CreationTime = GetTime( ); + m_LastRefreshTime = GetTime( ); + } + else + SendAllChat( m_GHost->m_Language->UnableToCreateGameNameTooLong( Payload ) ); } // // !PUB (rehost as public game) // - if( Command == "pub" && !Payload.empty( ) && !m_CountDownStarted && !m_SaveGame ) + else if( Command == "pub" && !Payload.empty( ) && !m_CountDownStarted && !m_SaveGame ) { - CONSOLE_Print( "[GAME: " + m_GameName + "] trying to rehost as public game [" + Payload + "]" ); - SendAllChat( m_GHost->m_Language->TryingToRehostAsPublicGame( Payload ) ); - m_GameState = GAME_PUBLIC; - m_LastGameName = m_GameName; - m_GameName = Payload; - m_HostCounter = m_GHost->m_HostCounter++; - m_RefreshError = false; - m_RefreshRehosted = true; - - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + if( Payload.length() < 31 ) { - // unqueue any existing game refreshes because we're going to assume the next successful game refresh indicates that the rehost worked - // this ignores the fact that it's possible a game refresh was just sent and no response has been received yet - // we assume this won't happen very often since the only downside is a potential false positive + CONSOLE_Print( "[GAME: " + m_GameName + "] trying to rehost as public game [" + Payload + "]" ); + SendAllChat( m_GHost->m_Language->TryingToRehostAsPublicGame( Payload ) ); + m_GameState = GAME_PUBLIC; + m_LastGameName = m_GameName; + m_GameName = Payload; + m_HostCounter = m_GHost->m_HostCounter++; + m_RefreshError = false; + m_RefreshRehosted = true; + + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) + { + // unqueue any existing game refreshes because we're going to assume the next successful game refresh indicates that the rehost worked + // this ignores the fact that it's possible a game refresh was just sent and no response has been received yet + // we assume this won't happen very often since the only downside is a potential false positive - (*i)->UnqueueGameRefreshes( ); - (*i)->QueueGameUncreate( ); - (*i)->QueueEnterChat( ); + (*i)->UnqueueGameRefreshes( ); + (*i)->QueueGameUncreate( ); + (*i)->QueueEnterChat( ); - // the game creation message will be sent on the next refresh - } + // the game creation message will be sent on the next refresh + } - m_CreationTime = GetTime( ); - m_LastRefreshTime = GetTime( ); + m_CreationTime = GetTime( ); + m_LastRefreshTime = GetTime( ); + } + else + SendAllChat( m_GHost->m_Language->UnableToCreateGameNameTooLong( Payload ) ); } - // // !REFRESH (turn on or off refresh messages) // - if( Command == "refresh" && !m_CountDownStarted ) + else if( Command == "refresh" && !m_CountDownStarted ) { if( Payload == "on" ) { @@ -1395,9 +1401,9 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !SAY // - if( Command == "say" && !Payload.empty( ) ) + else if( Command == "say" && !Payload.empty( ) ) { - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) (*i)->QueueChatCommand( Payload ); HideCommand = true; @@ -1407,7 +1413,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !SENDLAN // - if( Command == "sendlan" && !Payload.empty( ) && !m_CountDownStarted ) + else if( Command == "sendlan" && !Payload.empty( ) && !m_CountDownStarted ) { // extract the ip and the port // e.g. "1.2.3.4 6112" -> ip: "1.2.3.4", port: "6112" @@ -1425,6 +1431,15 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string CONSOLE_Print( "[GAME: " + m_GameName + "] bad inputs to sendlan command" ); else { + // construct a fixed host counter which will be used to identify players from this "realm" (i.e. LAN) + // the fixed host counter's 4 most significant bits will contain a 4 bit ID (0-15) + // the rest of the fixed host counter will contain the 28 least significant bits of the actual host counter + // since we're destroying 4 bits of information here the actual host counter should not be greater than 2^28 which is a reasonable assumption + // when a player joins a game we can obtain the ID from the received host counter + // note: LAN broadcasts use an ID of 0, battle.net refreshes use an ID of 1-10, the rest are unused + + uint32_t FixedHostCounter = m_HostCounter & 0x0FFFFFFF; + // we send 12 for SlotsTotal because this determines how many PID's Warcraft 3 allocates // we need to make sure Warcraft 3 allocates at least SlotsTotal + 1 but at most 12 PID's // this is because we need an extra PID for the virtual host player (but we always delete the virtual host player when the 12th person joins) @@ -1434,31 +1449,26 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // so if we try to send accurate numbers it'll always be off by one and results in Warcraft 3 assuming the game is full when it still needs one more player // the easiest solution is to simply send 12 for both so the game will always show up as (1/12) players - BYTEARRAY MapGameType; - - // construct the correct W3GS_GAMEINFO packet - if( m_SaveGame ) { - MapGameType.push_back( 0 ); - MapGameType.push_back( 2 ); - MapGameType.push_back( 0 ); - MapGameType.push_back( 0 ); + // note: the PrivateGame flag is not set when broadcasting to LAN (as you might expect) + + uint32_t MapGameType = MAPGAMETYPE_SAVEDGAME; BYTEARRAY MapWidth; MapWidth.push_back( 0 ); MapWidth.push_back( 0 ); BYTEARRAY MapHeight; MapHeight.push_back( 0 ); MapHeight.push_back( 0 ); - m_GHost->m_UDPSocket->SendTo( IP, Port, m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, MapGameType, m_Map->GetMapGameFlags( ), MapWidth, MapHeight, m_GameName, "Varlock", GetTime( ) - m_CreationTime, "Save\\Multiplayer\\" + m_SaveGame->GetFileNameNoPath( ), m_SaveGame->GetMagicNumber( ), 12, 12, m_HostPort, m_HostCounter ) ); + m_GHost->m_UDPSocket->SendTo( IP, Port, m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, UTIL_CreateByteArray( MapGameType, false ), m_Map->GetMapGameFlags( ), MapWidth, MapHeight, m_GameName, "Varlock", GetTime( ) - m_CreationTime, "Save\\Multiplayer\\" + m_SaveGame->GetFileNameNoPath( ), m_SaveGame->GetMagicNumber( ), 12, 12, m_HostPort, FixedHostCounter, m_EntryKey ) ); } else { - MapGameType.push_back( m_Map->GetMapGameType( ) ); - MapGameType.push_back( 0 ); - MapGameType.push_back( 0 ); - MapGameType.push_back( 0 ); - m_GHost->m_UDPSocket->SendTo( IP, Port, m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, MapGameType, m_Map->GetMapGameFlags( ), m_Map->GetMapWidth( ), m_Map->GetMapHeight( ), m_GameName, "Varlock", GetTime( ) - m_CreationTime, m_Map->GetMapPath( ), m_Map->GetMapCRC( ), 12, 12, m_HostPort, m_HostCounter ) ); + // note: the PrivateGame flag is not set when broadcasting to LAN (as you might expect) + // note: we do not use m_Map->GetMapGameType because none of the filters are set when broadcasting to LAN (also as you might expect) + + uint32_t MapGameType = MAPGAMETYPE_UNKNOWN0; + m_GHost->m_UDPSocket->SendTo( IP, Port, m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, UTIL_CreateByteArray( MapGameType, false ), m_Map->GetMapGameFlags( ), m_Map->GetMapWidth( ), m_Map->GetMapHeight( ), m_GameName, "Varlock", GetTime( ) - m_CreationTime, m_Map->GetMapPath( ), m_Map->GetMapCRC( ), 12, 12, m_HostPort, FixedHostCounter, m_EntryKey ) ); } } } @@ -1467,7 +1477,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !SP // - if( Command == "sp" && !m_CountDownStarted ) + else if( Command == "sp" && !m_CountDownStarted ) { SendAllChat( m_GHost->m_Language->ShufflingPlayers( ) ); ShuffleSlots( ); @@ -1477,7 +1487,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !START // - if( Command == "start" && !m_CountDownStarted ) + else if( Command == "start" && !m_CountDownStarted ) { // if the player sent "!start force" skip the checks and start the countdown // otherwise check that the game is ready to start @@ -1497,7 +1507,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !SWAP (swap slots) // - if( Command == "swap" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded ) + else if( Command == "swap" && !Payload.empty( ) && !m_GameLoading && !m_GameLoaded ) { uint32_t SID1; uint32_t SID2; @@ -1527,7 +1537,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !SYNCLIMIT // - if( Command == "synclimit" ) + else if( Command == "synclimit" ) { if( Payload.empty( ) ) SendAllChat( m_GHost->m_Language->SyncLimitIs( UTIL_ToString( m_SyncLimit ) ) ); @@ -1554,14 +1564,14 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !UNHOST // - if( Command == "unhost" && !m_CountDownStarted ) + else if( Command == "unhost" && !m_CountDownStarted ) m_Exiting = true; // // !UNLOCK // - if( Command == "unlock" && ( RootAdminCheck || IsOwner( User ) ) ) + else if( Command == "unlock" && ( RootAdminCheck || IsOwner( User ) ) ) { SendAllChat( m_GHost->m_Language->GameUnlocked( ) ); m_Locked = false; @@ -1571,7 +1581,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !UNMUTE // - if( Command == "unmute" ) + else if( Command == "unmute" ) { CGamePlayer *LastMatch = NULL; uint32_t Matches = GetPlayerFromNamePartial( Payload, &LastMatch ); @@ -1591,7 +1601,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !UNMUTEALL // - if( Command == "unmuteall" && m_GameLoaded ) + else if( Command == "unmuteall" && m_GameLoaded ) { SendAllChat( m_GHost->m_Language->GlobalChatUnmuted( ) ); m_MuteAll = false; @@ -1601,7 +1611,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !VIRTUALHOST // - if( Command == "virtualhost" && !Payload.empty( ) && Payload.size( ) <= 15 && !m_CountDownStarted ) + else if( Command == "virtualhost" && !Payload.empty( ) && Payload.size( ) <= 15 && !m_CountDownStarted ) { DeleteVirtualHost( ); m_VirtualHostName = Payload; @@ -1611,7 +1621,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !VOTECANCEL // - if( Command == "votecancel" && !m_KickVotePlayer.empty( ) ) + else if( Command == "votecancel" && !m_KickVotePlayer.empty( ) ) { SendAllChat( m_GHost->m_Language->VoteKickCancelled( m_KickVotePlayer ) ); m_KickVotePlayer.clear( ); @@ -1622,7 +1632,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !W // - if( Command == "w" && !Payload.empty( ) ) + else if( Command == "w" && !Payload.empty( ) ) { // extract the name and the message // e.g. "Varlock hello there!" -> name: "Varlock", message: "hello there!" @@ -1636,7 +1646,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string Name = Payload.substr( 0, MessageStart ); Message = Payload.substr( MessageStart + 1 ); - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) (*i)->QueueChatCommand( Message, Name, true ); } @@ -1672,7 +1682,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !STATS // - if( Command == "stats" && GetTime( ) - player->GetStatsSentTime( ) >= 5 ) + else if( Command == "stats" && GetTime( ) - player->GetStatsSentTime( ) >= 5 ) { string StatsUser = User; @@ -1691,7 +1701,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !STATSDOTA // - if( Command == "statsdota" && GetTime( ) - player->GetStatsDotASentTime( ) >= 5 ) + else if( Command == "statsdota" && GetTime( ) - player->GetStatsDotASentTime( ) >= 5 ) { string StatsUser = User; @@ -1710,7 +1720,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !VERSION // - if( Command == "version" ) + else if( Command == "version" ) { if( player->GetSpoofed( ) && ( AdminCheck || RootAdminCheck || IsOwner( User ) ) ) SendChat( player, m_GHost->m_Language->VersionAdmin( m_GHost->m_Version ) ); @@ -1722,7 +1732,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !VOTEKICK // - if( Command == "votekick" && m_GHost->m_VoteKickAllowed && !Payload.empty( ) ) + else if( Command == "votekick" && m_GHost->m_VoteKickAllowed && !Payload.empty( ) ) { if( !m_KickVotePlayer.empty( ) ) SendChat( player, m_GHost->m_Language->UnableToVoteKickAlreadyInProgress( ) ); @@ -1744,7 +1754,7 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string m_KickVotePlayer = LastMatch->GetName( ); m_StartedKickVoteTime = GetTime( ); - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) (*i)->SetKickVote( false ); player->SetKickVote( true ); @@ -1762,16 +1772,16 @@ bool CGame :: EventPlayerBotCommand( CGamePlayer *player, string command, string // !YES // - if( Command == "yes" && !m_KickVotePlayer.empty( ) && player->GetName( ) != m_KickVotePlayer && !player->GetKickVote( ) ) + else if( Command == "yes" && !m_KickVotePlayer.empty( ) && player->GetName( ) != m_KickVotePlayer && !player->GetKickVote( ) ) { player->SetKickVote( true ); uint32_t VotesNeeded = (uint32_t)ceil( ( GetNumHumanPlayers( ) - 1 ) * (float)m_GHost->m_VoteKickPercentage / 100 ); uint32_t Votes = 0; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetKickVote( ) ) - Votes++; + ++Votes; } if( Votes >= VotesNeeded ) @@ -1816,7 +1826,7 @@ void CGame :: EventGameStarted( ) // but since the player has already left the game we don't have access to their information anymore // so we create a "potential ban" for each player and only store it in the database if requested to by an admin - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) m_DBBans.push_back( new CDBBan( (*i)->GetJoinedRealm( ), (*i)->GetName( ), (*i)->GetExternalIPString( ), string( ), string( ), string( ), string( ) ) ); } diff --git a/ghost/game_admin.cpp b/ghost/game_admin.cpp index 13e5b8e..4e0a91f 100644 --- a/ghost/game_admin.cpp +++ b/ghost/game_admin.cpp @@ -46,33 +46,34 @@ using namespace boost :: filesystem; CAdminGame :: CAdminGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16_t nHostPort, unsigned char nGameState, string nGameName, string nPassword ) : CBaseGame( nGHost, nMap, nSaveGame, nHostPort, nGameState, nGameName, string( ), string( ), string( ) ) { - m_VirtualHostName = "|cFFC04040Admin"; - m_MuteLobby = true; - m_Password = nPassword; + m_VirtualHostName = "|cFFC04040Admin"; + m_MuteLobby = true; + m_Password = nPassword; + m_EntryKey = 0; } CAdminGame :: ~CAdminGame( ) { - for( vector :: iterator i = m_PairedAdminCounts.begin( ); i != m_PairedAdminCounts.end( ); i++ ) + for( vector :: iterator i = m_PairedAdminCounts.begin( ); i != m_PairedAdminCounts.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedAdminAdds.begin( ); i != m_PairedAdminAdds.end( ); i++ ) + for( vector :: iterator i = m_PairedAdminAdds.begin( ); i != m_PairedAdminAdds.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedAdminRemoves.begin( ); i != m_PairedAdminRemoves.end( ); i++ ) + for( vector :: iterator i = m_PairedAdminRemoves.begin( ); i != m_PairedAdminRemoves.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); - for( vector :: iterator i = m_PairedBanCounts.begin( ); i != m_PairedBanCounts.end( ); i++ ) + for( vector :: iterator i = m_PairedBanCounts.begin( ); i != m_PairedBanCounts.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); /* - for( vector :: iterator i = m_PairedBanAdds.begin( ); i != m_PairedBanAdds.end( ); i++ ) + for( vector :: iterator i = m_PairedBanAdds.begin( ); i != m_PairedBanAdds.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); */ - for( vector :: iterator i = m_PairedBanRemoves.begin( ); i != m_PairedBanRemoves.end( ); i++ ) + for( vector :: iterator i = m_PairedBanRemoves.begin( ); i != m_PairedBanRemoves.end( ); ++i ) m_GHost->m_Callables.push_back( i->second ); } @@ -105,7 +106,7 @@ bool CAdminGame :: Update( void *fd, void *send_fd ) i = m_PairedAdminCounts.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedAdminAdds.begin( ); i != m_PairedAdminAdds.end( ); ) @@ -114,7 +115,7 @@ bool CAdminGame :: Update( void *fd, void *send_fd ) { if( i->second->GetResult( ) ) { - for( vector :: iterator j = m_GHost->m_BNETs.begin( ); j != m_GHost->m_BNETs.end( ); j++ ) + for( vector :: iterator j = m_GHost->m_BNETs.begin( ); j != m_GHost->m_BNETs.end( ); ++j ) { if( (*j)->GetServer( ) == i->second->GetServer( ) ) (*j)->AddAdmin( i->second->GetUser( ) ); @@ -136,7 +137,7 @@ bool CAdminGame :: Update( void *fd, void *send_fd ) i = m_PairedAdminAdds.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedAdminRemoves.begin( ); i != m_PairedAdminRemoves.end( ); ) @@ -145,7 +146,7 @@ bool CAdminGame :: Update( void *fd, void *send_fd ) { if( i->second->GetResult( ) ) { - for( vector :: iterator j = m_GHost->m_BNETs.begin( ); j != m_GHost->m_BNETs.end( ); j++ ) + for( vector :: iterator j = m_GHost->m_BNETs.begin( ); j != m_GHost->m_BNETs.end( ); ++j ) { if( (*j)->GetServer( ) == i->second->GetServer( ) ) (*j)->RemoveAdmin( i->second->GetUser( ) ); @@ -167,7 +168,7 @@ bool CAdminGame :: Update( void *fd, void *send_fd ) i = m_PairedAdminRemoves.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_PairedBanCounts.begin( ); i != m_PairedBanCounts.end( ); ) @@ -193,7 +194,7 @@ bool CAdminGame :: Update( void *fd, void *send_fd ) i = m_PairedBanCounts.erase( i ); } else - i++; + ++i; } /* @@ -204,7 +205,7 @@ bool CAdminGame :: Update( void *fd, void *send_fd ) { if( i->second->GetResult( ) ) { - for( vector :: iterator j = m_GHost->m_BNETs.begin( ); j != m_GHost->m_BNETs.end( ); j++ ) + for( vector :: iterator j = m_GHost->m_BNETs.begin( ); j != m_GHost->m_BNETs.end( ); ++j ) { if( (*j)->GetServer( ) == i->second->GetServer( ) ) (*j)->AddBan( i->second->GetUser( ), i->second->GetIP( ), i->second->GetGameName( ), i->second->GetAdmin( ), i->second->GetReason( ) ); @@ -226,7 +227,7 @@ bool CAdminGame :: Update( void *fd, void *send_fd ) i = m_PairedBanAdds.erase( i ); } else - i++; + ++i; } */ @@ -237,7 +238,7 @@ bool CAdminGame :: Update( void *fd, void *send_fd ) { if( i->second->GetResult( ) ) { - for( vector :: iterator j = m_GHost->m_BNETs.begin( ); j != m_GHost->m_BNETs.end( ); j++ ) + for( vector :: iterator j = m_GHost->m_BNETs.begin( ); j != m_GHost->m_BNETs.end( ); ++j ) { if( (*j)->GetServer( ) == i->second->GetServer( ) ) (*j)->RemoveBan( i->second->GetUser( ) ); @@ -259,7 +260,7 @@ bool CAdminGame :: Update( void *fd, void *send_fd ) i = m_PairedBanRemoves.erase( i ); } else - i++; + ++i; } // reset the last reserved seen timer since the admin game should never be considered abandoned @@ -270,7 +271,7 @@ bool CAdminGame :: Update( void *fd, void *send_fd ) void CAdminGame :: SendAdminChat( string message ) { - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetLoggedIn( ) ) SendChat( *i, message ); @@ -311,7 +312,7 @@ void CAdminGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoin return; } - i++; + ++i; } } @@ -366,7 +367,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s string Servers; bool FoundServer = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( Servers.empty( ) ) Servers = (*i)->GetServer( ); @@ -395,7 +396,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !AUTOHOST // - if( Command == "autohost" ) + else if( Command == "autohost" ) { if( Payload.empty( ) || Payload == "off" ) { @@ -464,7 +465,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !AUTOHOSTMM // - if( Command == "autohostmm" ) + else if( Command == "autohostmm" ) { if( Payload.empty( ) || Payload == "off" ) { @@ -549,7 +550,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !CHECKADMIN // - if( Command == "checkadmin" && !Payload.empty( ) ) + else if( Command == "checkadmin" && !Payload.empty( ) ) { // extract the name and the server // e.g. "Varlock useast.battle.net" -> name: "Varlock", server: "useast.battle.net" @@ -575,7 +576,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s string Servers; bool FoundServer = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( Servers.empty( ) ) Servers = (*i)->GetServer( ); @@ -604,7 +605,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !CHECKBAN // - if( Command == "checkban" && !Payload.empty( ) ) + else if( Command == "checkban" && !Payload.empty( ) ) { // extract the name and the server // e.g. "Varlock useast.battle.net" -> name: "Varlock", server: "useast.battle.net" @@ -630,7 +631,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s string Servers; bool FoundServer = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( Servers.empty( ) ) Servers = (*i)->GetServer( ); @@ -660,7 +661,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !COUNTADMINS // - if( Command == "countadmins" ) + else if( Command == "countadmins" ) { string Server = Payload; @@ -675,7 +676,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !COUNTBANS // - if( Command == "countbans" ) + else if( Command == "countbans" ) { string Server = Payload; @@ -690,7 +691,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !DELADMIN // - if( Command == "deladmin" && !Payload.empty( ) ) + else if( Command == "deladmin" && !Payload.empty( ) ) { // extract the name and the server // e.g. "Varlock useast.battle.net" -> name: "Varlock", server: "useast.battle.net" @@ -716,7 +717,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s string Servers; bool FoundServer = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( Servers.empty( ) ) Servers = (*i)->GetServer( ); @@ -746,14 +747,14 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !UNBAN // - if( ( Command == "delban" || Command == "unban" ) && !Payload.empty( ) ) + else if( ( Command == "delban" || Command == "unban" ) && !Payload.empty( ) ) m_PairedBanRemoves.push_back( PairedBanRemove( player->GetName( ), m_GHost->m_DB->ThreadedBanRemove( Payload ) ) ); // // !DISABLE // - if( Command == "disable" ) + else if( Command == "disable" ) { SendChat( player, m_GHost->m_Language->BotDisabled( ) ); m_GHost->m_Enabled = false; @@ -763,7 +764,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !DOWNLOADS // - if( Command == "downloads" && !Payload.empty( ) ) + else if( Command == "downloads" && !Payload.empty( ) ) { uint32_t Downloads = UTIL_ToUInt32( Payload ); @@ -788,7 +789,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !ENABLE // - if( Command == "enable" ) + else if( Command == "enable" ) { SendChat( player, m_GHost->m_Language->BotEnabled( ) ); m_GHost->m_Enabled = true; @@ -798,7 +799,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !END // - if( Command == "end" && !Payload.empty( ) ) + else if( Command == "end" && !Payload.empty( ) ) { // todotodo: what if a game ends just as you're typing this command and the numbering changes? @@ -818,7 +819,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !ENFORCESG // - if( Command == "enforcesg" && !Payload.empty( ) ) + else if( Command == "enforcesg" && !Payload.empty( ) ) { // only load files in the current directory just to be safe @@ -847,7 +848,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !QUIT // - if( Command == "exit" || Command == "quit" ) + else if( Command == "exit" || Command == "quit" ) { if( Payload == "nice" ) m_GHost->m_ExitingNice = true; @@ -866,7 +867,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !GETGAME // - if( Command == "getgame" && !Payload.empty( ) ) + else if( Command == "getgame" && !Payload.empty( ) ) { uint32_t GameNumber = UTIL_ToUInt32( Payload ) - 1; @@ -880,7 +881,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !GETGAMES // - if( Command == "getgames" ) + else if( Command == "getgames" ) { if( m_GHost->m_CurrentGame ) SendChat( player, m_GHost->m_Language->GameIsInTheLobby( m_GHost->m_CurrentGame->GetDescription( ), UTIL_ToString( m_GHost->m_Games.size( ) ), UTIL_ToString( m_GHost->m_MaxGames ) ) ); @@ -892,14 +893,14 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !HOSTSG // - if( Command == "hostsg" && !Payload.empty( ) ) + else if( Command == "hostsg" && !Payload.empty( ) ) m_GHost->CreateGame( m_GHost->m_Map, GAME_PRIVATE, true, Payload, User, User, string( ), false ); // // !LOAD (load config file) // - if( Command == "load" ) + else if( Command == "load" ) { if( Payload.empty( ) ) SendChat( player, m_GHost->m_Language->CurrentlyLoadedMapCFGIs( m_GHost->m_Map->GetCFGFile( ) ) ); @@ -924,7 +925,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s path LastMatch; uint32_t Matches = 0; - for( directory_iterator i( MapCFGPath ); i != EndIterator; i++ ) + for( directory_iterator i( MapCFGPath ); i != EndIterator; ++i ) { string FileName = i->filename( ); string Stem = i->path( ).stem( ); @@ -934,7 +935,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s if( !is_directory( i->status( ) ) && i->path( ).extension( ) == ".cfg" && FileName.find( Pattern ) != string :: npos ) { LastMatch = i->path( ); - Matches++; + ++Matches; if( FoundMapConfigs.empty( ) ) FoundMapConfigs = i->filename( ); @@ -977,7 +978,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !LOADSG // - if( Command == "loadsg" && !Payload.empty( ) ) + else if( Command == "loadsg" && !Payload.empty( ) ) { // only load files in the current directory just to be safe @@ -1010,7 +1011,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !MAP (load map file) // - if( Command == "map" ) + else if( Command == "map" ) { if( Payload.empty( ) ) SendChat( player, m_GHost->m_Language->CurrentlyLoadedMapCFGIs( m_GHost->m_Map->GetCFGFile( ) ) ); @@ -1035,7 +1036,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s path LastMatch; uint32_t Matches = 0; - for( directory_iterator i( MapPath ); i != EndIterator; i++ ) + for( directory_iterator i( MapPath ); i != EndIterator; ++i ) { string FileName = i->filename( ); string Stem = i->path( ).stem( ); @@ -1045,7 +1046,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s if( !is_directory( i->status( ) ) && FileName.find( Pattern ) != string :: npos ) { LastMatch = i->path( ); - Matches++; + ++Matches; if( FoundMaps.empty( ) ) FoundMaps = i->filename( ); @@ -1092,14 +1093,14 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !PRIV (host private game) // - if( Command == "priv" && !Payload.empty( ) ) + else if( Command == "priv" && !Payload.empty( ) ) m_GHost->CreateGame( m_GHost->m_Map, GAME_PRIVATE, false, Payload, User, User, string( ), false ); // // !PRIVBY (host private game by other player) // - if( Command == "privby" && !Payload.empty( ) ) + else if( Command == "privby" && !Payload.empty( ) ) { // extract the owner and the game name // e.g. "Varlock dota 6.54b arem ~~~" -> owner: "Varlock", game name: "dota 6.54b arem ~~~" @@ -1120,7 +1121,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !PUB (host public game) // - if( Command == "pub" && !Payload.empty( ) ) + else if( Command == "pub" && !Payload.empty( ) ) m_GHost->CreateGame( m_GHost->m_Map, GAME_PUBLIC, false, Payload, User, User, string( ), false ); // @@ -1148,7 +1149,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !RELOAD // - if( Command == "reload" ) + else if( Command == "reload" ) { SendChat( player, m_GHost->m_Language->ReloadingConfigurationFiles( ) ); m_GHost->ReloadConfigs( ); @@ -1158,9 +1159,9 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !SAY // - if( Command == "say" && !Payload.empty( ) ) + else if( Command == "say" && !Payload.empty( ) ) { - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) (*i)->QueueChatCommand( Payload ); } @@ -1168,7 +1169,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !SAYGAME // - if( Command == "saygame" && !Payload.empty( ) ) + else if( Command == "saygame" && !Payload.empty( ) ) { // extract the game number and the message // e.g. "3 hello everyone" -> game number: "3", message: "hello everyone" @@ -1205,12 +1206,12 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !SAYGAMES // - if( Command == "saygames" && !Payload.empty( ) ) + else if( Command == "saygames" && !Payload.empty( ) ) { if( m_GHost->m_CurrentGame ) m_GHost->m_CurrentGame->SendAllChat( Payload ); - for( vector :: iterator i = m_GHost->m_Games.begin( ); i != m_GHost->m_Games.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_Games.begin( ); i != m_GHost->m_Games.end( ); ++i ) (*i)->SendAllChat( "ADMIN: " + Payload ); } @@ -1218,7 +1219,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !UNHOST // - if( Command == "unhost" ) + else if( Command == "unhost" ) { if( m_GHost->m_CurrentGame ) { @@ -1238,7 +1239,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s // !W // - if( Command == "w" && !Payload.empty( ) ) + else if( Command == "w" && !Payload.empty( ) ) { // extract the name and the message // e.g. "Varlock hello there!" -> name: "Varlock", message: "hello there!" @@ -1252,7 +1253,7 @@ bool CAdminGame :: EventPlayerBotCommand( CGamePlayer *player, string command, s Name = Payload.substr( 0, MessageStart ); Message = Payload.substr( MessageStart + 1 ); - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) (*i)->QueueChatCommand( Message, Name, true ); } } diff --git a/ghost/game_base.cpp b/ghost/game_base.cpp index 761fa34..4621ff4 100644 --- a/ghost/game_base.cpp +++ b/ghost/game_base.cpp @@ -89,6 +89,7 @@ CBaseGame :: CBaseGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16 m_HCLCommandString = m_Map->GetMapDefaultHCL( ); m_RandomSeed = GetTicks( ); m_HostCounter = m_GHost->m_HostCounter++; + m_EntryKey = rand( ); m_Latency = m_GHost->m_Latency; m_SyncLimit = m_GHost->m_SyncLimit; m_SyncCounter = 0; @@ -143,7 +144,7 @@ CBaseGame :: CBaseGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16 // we really just want the open/closed/computer entries // so open all the player slots - for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); i++ ) + for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); ++i ) { if( (*i).GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && (*i).GetComputer( ) == 0 ) { @@ -242,13 +243,13 @@ CBaseGame :: ~CBaseGame( ) delete m_Map; delete m_Replay; - for( vector :: iterator i = m_Potentials.begin( ); i != m_Potentials.end( ); i++ ) + for( vector :: iterator i = m_Potentials.begin( ); i != m_Potentials.end( ); ++i ) delete *i; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) delete *i; - for( vector :: iterator i = m_ScoreChecks.begin( ); i != m_ScoreChecks.end( ); i++ ) + for( vector :: iterator i = m_ScoreChecks.begin( ); i != m_ScoreChecks.end( ); ++i ) m_GHost->m_Callables.push_back( *i ); while( !m_Actions.empty( ) ) @@ -280,10 +281,10 @@ uint32_t CBaseGame :: GetSlotsOccupied( ) { uint32_t NumSlotsOccupied = 0; - for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); i++ ) + for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); ++i ) { if( (*i).GetSlotStatus( ) == SLOTSTATUS_OCCUPIED ) - NumSlotsOccupied++; + ++NumSlotsOccupied; } return NumSlotsOccupied; @@ -293,10 +294,10 @@ uint32_t CBaseGame :: GetSlotsOpen( ) { uint32_t NumSlotsOpen = 0; - for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); i++ ) + for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); ++i ) { if( (*i).GetSlotStatus( ) == SLOTSTATUS_OPEN ) - NumSlotsOpen++; + ++NumSlotsOpen; } return NumSlotsOpen; @@ -307,7 +308,7 @@ uint32_t CBaseGame :: GetNumPlayers( ) uint32_t NumPlayers = GetNumHumanPlayers( ); if( m_FakePlayerPID != 255 ) - NumPlayers++; + ++NumPlayers; return NumPlayers; } @@ -316,10 +317,10 @@ uint32_t CBaseGame :: GetNumHumanPlayers( ) { uint32_t NumHumanPlayers = 0; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) ) - NumHumanPlayers++; + ++NumHumanPlayers; } return NumHumanPlayers; @@ -351,24 +352,24 @@ unsigned int CBaseGame :: SetFD( void *fd, void *send_fd, int *nfds ) if( m_Socket ) { m_Socket->SetFD( (fd_set *)fd, (fd_set *)send_fd, nfds ); - NumFDs++; + ++NumFDs; } - for( vector :: iterator i = m_Potentials.begin( ); i != m_Potentials.end( ); i++ ) + for( vector :: iterator i = m_Potentials.begin( ); i != m_Potentials.end( ); ++i ) { if( (*i)->GetSocket( ) ) { (*i)->GetSocket( )->SetFD( (fd_set *)fd, (fd_set *)send_fd, nfds ); - NumFDs++; + ++NumFDs; } } - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetSocket( ) ) { (*i)->GetSocket( )->SetFD( (fd_set *)fd, (fd_set *)send_fd, nfds ); - NumFDs++; + ++NumFDs; } } @@ -385,7 +386,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) { double Score = (*i)->GetResult( ); - for( vector :: iterator j = m_Potentials.begin( ); j != m_Potentials.end( ); j++ ) + for( vector :: iterator j = m_Potentials.begin( ); j != m_Potentials.end( ); ++j ) { if( (*j)->GetJoinPlayer( ) && (*j)->GetJoinPlayer( )->GetName( ) == (*i)->GetName( ) ) EventPlayerJoinedWithScore( *j, (*j)->GetJoinPlayer( ), Score ); @@ -396,7 +397,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) i = m_ScoreChecks.erase( i ); } else - i++; + ++i; } // update players @@ -410,7 +411,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) i = m_Players.erase( i ); } else - i++; + ++i; } for( vector :: iterator i = m_Potentials.begin( ); i != m_Potentials.end( ); ) @@ -426,7 +427,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) i = m_Potentials.erase( i ); } else - i++; + ++i; } // create the virtual host player @@ -461,8 +462,6 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) if( !m_CountDownStarted ) { - BYTEARRAY MapGameType; - // construct a fixed host counter which will be used to identify players from this "realm" (i.e. LAN) // the fixed host counter's 4 most significant bits will contain a 4 bit ID (0-15) // the rest of the fixed host counter will contain the 28 least significant bits of the actual host counter @@ -472,29 +471,35 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) uint32_t FixedHostCounter = m_HostCounter & 0x0FFFFFFF; - // construct the correct W3GS_GAMEINFO packet + // we send 12 for SlotsTotal because this determines how many PID's Warcraft 3 allocates + // we need to make sure Warcraft 3 allocates at least SlotsTotal + 1 but at most 12 PID's + // this is because we need an extra PID for the virtual host player (but we always delete the virtual host player when the 12th person joins) + // however, we can't send 13 for SlotsTotal because this causes Warcraft 3 to crash when sharing control of units + // nor can we send SlotsTotal because then Warcraft 3 crashes when playing maps with less than 12 PID's (because of the virtual host player taking an extra PID) + // we also send 12 for SlotsOpen because Warcraft 3 assumes there's always at least one player in the game (the host) + // so if we try to send accurate numbers it'll always be off by one and results in Warcraft 3 assuming the game is full when it still needs one more player + // the easiest solution is to simply send 12 for both so the game will always show up as (1/12) players if( m_SaveGame ) { - MapGameType.push_back( 0 ); - MapGameType.push_back( 2 ); - MapGameType.push_back( 0 ); - MapGameType.push_back( 0 ); + // note: the PrivateGame flag is not set when broadcasting to LAN (as you might expect) + + uint32_t MapGameType = MAPGAMETYPE_SAVEDGAME; BYTEARRAY MapWidth; MapWidth.push_back( 0 ); MapWidth.push_back( 0 ); BYTEARRAY MapHeight; MapHeight.push_back( 0 ); MapHeight.push_back( 0 ); - m_GHost->m_UDPSocket->Broadcast( 6112, m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, MapGameType, m_Map->GetMapGameFlags( ), MapWidth, MapHeight, m_GameName, "Varlock", GetTime( ) - m_CreationTime, "Save\\Multiplayer\\" + m_SaveGame->GetFileNameNoPath( ), m_SaveGame->GetMagicNumber( ), 12, 12, m_HostPort, FixedHostCounter ) ); + m_GHost->m_UDPSocket->Broadcast( 6112, m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, UTIL_CreateByteArray( MapGameType, false ), m_Map->GetMapGameFlags( ), MapWidth, MapHeight, m_GameName, "Varlock", GetTime( ) - m_CreationTime, "Save\\Multiplayer\\" + m_SaveGame->GetFileNameNoPath( ), m_SaveGame->GetMagicNumber( ), 12, 12, m_HostPort, FixedHostCounter, m_EntryKey ) ); } else { - MapGameType.push_back( m_Map->GetMapGameType( ) ); - MapGameType.push_back( 0 ); - MapGameType.push_back( 0 ); - MapGameType.push_back( 0 ); - m_GHost->m_UDPSocket->Broadcast( 6112, m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, MapGameType, m_Map->GetMapGameFlags( ), m_Map->GetMapWidth( ), m_Map->GetMapHeight( ), m_GameName, "Varlock", GetTime( ) - m_CreationTime, m_Map->GetMapPath( ), m_Map->GetMapCRC( ), 12, 12, m_HostPort, FixedHostCounter ) ); + // note: the PrivateGame flag is not set when broadcasting to LAN (as you might expect) + // note: we do not use m_Map->GetMapGameType because none of the filters are set when broadcasting to LAN (also as you might expect) + + uint32_t MapGameType = MAPGAMETYPE_UNKNOWN0; + m_GHost->m_UDPSocket->Broadcast( 6112, m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, UTIL_CreateByteArray( MapGameType, false ), m_Map->GetMapGameFlags( ), m_Map->GetMapWidth( ), m_Map->GetMapHeight( ), m_GameName, "Varlock", GetTime( ) - m_CreationTime, m_Map->GetMapPath( ), m_Map->GetMapCRC( ), 12, 12, m_HostPort, FixedHostCounter, m_EntryKey ) ); } } @@ -516,7 +521,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) m_HostCounter = m_GHost->m_HostCounter++; m_RefreshError = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { (*i)->QueueGameUncreate( ); (*i)->QueueEnterChat( ); @@ -536,7 +541,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) bool Refreshed = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { // don't queue a game refresh message if the queue contains more than 1 packet because they're very low priority @@ -573,11 +578,11 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) { uint32_t Downloaders = 0; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetDownloadStarted( ) && !(*i)->GetDownloadFinished( ) ) { - Downloaders++; + ++Downloaders; if( m_GHost->m_MaxDownloaders > 0 && Downloaders > m_GHost->m_MaxDownloaders ) break; @@ -636,7 +641,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) if( !m_CountDownStarted && m_GHost->m_RequireSpoofChecks && m_GameState == GAME_PUBLIC && !m_GHost->m_AutoHostGameName.empty( ) && m_GHost->m_AutoHostMaximumGames != 0 && m_GHost->m_AutoHostAutoStartPlayers != 0 && m_AutoStartPlayers != 0 ) { - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetSpoofed( ) && GetTime( ) - (*i)->GetJoinTime( ) >= 20 ) { @@ -667,7 +672,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) // doing it this way ensures it's always "5 4 3 2 1" but each interval might not be *exactly* the same length SendAllChat( UTIL_ToString( m_CountDownCounter ) + ". . ." ); - m_CountDownCounter--; + --m_CountDownCounter; } else if( !m_GameLoading && !m_GameLoaded ) EventGameStarted( ); @@ -681,7 +686,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) { // check if there's a player with reserved status in the game - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetReserved( ) ) m_LastReservedSeen = GetTime( ); @@ -702,7 +707,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) { bool FinishedLoading = true; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { FinishedLoading = (*i)->GetFinishedLoading( ); @@ -725,19 +730,19 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) { bool UsingGProxy = false; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetGProxy( ) ) UsingGProxy = true; } - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetFinishedLoading( ) ) { // stop the lag screen - for( vector :: iterator j = m_Players.begin( ); j != m_Players.end( ); j++ ) + for( vector :: iterator j = m_Players.begin( ); j != m_Players.end( ); ++j ) { if( !(*j)->GetFinishedLoading( ) ) Send( *i, m_Protocol->SEND_W3GS_STOP_LAG( *j, true ) ); @@ -755,7 +760,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) // GProxy++ will insert these itself so we don't need to send them to GProxy++ players // empty actions are used to extend the time a player can use when reconnecting - for( unsigned char j = 0; j < m_GProxyEmptyActions; j++ ) + for( unsigned char j = 0; j < m_GProxyEmptyActions; ++j ) Send( *i, m_Protocol->SEND_W3GS_INCOMING_ACTION( queue( ), 0 ) ); } @@ -775,7 +780,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) // GProxy++ will insert these itself so we don't need to send them to GProxy++ players // empty actions are used to extend the time a player can use when reconnecting - for( unsigned char j = 0; j < m_GProxyEmptyActions; j++ ) + for( unsigned char j = 0; j < m_GProxyEmptyActions; ++j ) (*i)->AddLoadInGameData( m_Protocol->SEND_W3GS_INCOMING_ACTION( queue( ), 0 ) ); } @@ -789,7 +794,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) { if( UsingGProxy ) { - for( unsigned char i = 0; i < m_GProxyEmptyActions; i++ ) + for( unsigned char i = 0; i < m_GProxyEmptyActions; ++i ) m_Replay->AddTimeSlot( 0, queue( ) ); } @@ -819,7 +824,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) { string LaggingString; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( m_SyncCounter - (*i)->GetSyncCounter( ) > m_SyncLimit ) { @@ -844,7 +849,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) // reset everyone's drop vote - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) (*i)->SetDropVote( false ); m_LastLagScreenResetTime = GetTime( ); @@ -855,7 +860,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) { bool UsingGProxy = false; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetGProxy( ) ) UsingGProxy = true; @@ -876,11 +881,11 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) if( GetTime( ) - m_LastLagScreenResetTime >= 60 ) { - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { // stop the lag screen - for( vector :: iterator j = m_Players.begin( ); j != m_Players.end( ); j++ ) + for( vector :: iterator j = m_Players.begin( ); j != m_Players.end( ); ++j ) { if( (*j)->GetLagging( ) ) Send( *i, m_Protocol->SEND_W3GS_STOP_LAG( *j ) ); @@ -895,7 +900,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) // GProxy++ will insert these itself so we don't need to send them to GProxy++ players // empty actions are used to extend the time a player can use when reconnecting - for( unsigned char j = 0; j < m_GProxyEmptyActions; j++ ) + for( unsigned char j = 0; j < m_GProxyEmptyActions; ++j ) Send( *i, m_Protocol->SEND_W3GS_INCOMING_ACTION( queue( ), 0 ) ); } @@ -912,7 +917,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) { if( UsingGProxy ) { - for( unsigned char i = 0; i < m_GProxyEmptyActions; i++ ) + for( unsigned char i = 0; i < m_GProxyEmptyActions; ++i ) m_Replay->AddTimeSlot( 0, queue( ) ); } @@ -931,7 +936,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) // check if anyone has stopped lagging normally // we consider a player to have stopped lagging if they're less than half m_SyncLimit keepalives behind - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetLagging( ) && m_SyncCounter - (*i)->GetSyncCounter( ) < m_SyncLimit / 2 ) { @@ -948,7 +953,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) bool Lagging = false; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetLagging( ) ) Lagging = true; @@ -997,7 +1002,7 @@ bool CBaseGame :: Update( void *fd, void *send_fd ) { bool AlreadyStopped = true; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetDeleteMe( ) ) { @@ -1064,13 +1069,13 @@ void CBaseGame :: UpdatePost( void *send_fd ) // this is in case player 2 generates a packet for player 1 during the update but it doesn't get sent because player 1 already finished updating // in reality since we're queueing actions it might not make a big difference but oh well - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetSocket( ) ) (*i)->GetSocket( )->DoSend( (fd_set *)send_fd ); } - for( vector :: iterator i = m_Potentials.begin( ); i != m_Potentials.end( ); i++ ) + for( vector :: iterator i = m_Potentials.begin( ); i != m_Potentials.end( ); ++i ) { if( (*i)->GetSocket( ) ) (*i)->GetSocket( )->DoSend( (fd_set *)send_fd ); @@ -1090,13 +1095,13 @@ void CBaseGame :: Send( unsigned char PID, BYTEARRAY data ) void CBaseGame :: Send( BYTEARRAY PIDs, BYTEARRAY data ) { - for( unsigned int i = 0; i < PIDs.size( ); i++ ) + for( unsigned int i = 0; i < PIDs.size( ); ++i ) Send( PIDs[i], data ); } void CBaseGame :: SendAll( BYTEARRAY data ) { - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) (*i)->Send( data ); } @@ -1189,7 +1194,7 @@ void CBaseGame :: SendLocalAdminChat( string message ) // at the time of this writing it is only possible for the game owner to meet this criteria because being an admin requires spoof checking // this is mainly used for relaying battle.net whispers, chat messages, and emotes to these players - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetSpoofed( ) && IsOwner( (*i)->GetName( ) ) && ( UTIL_IsLanIP( (*i)->GetExternalIP( ) ) || UTIL_IsLocalIP( (*i)->GetExternalIP( ), m_GHost->m_LocalAddresses ) ) ) { @@ -1209,7 +1214,7 @@ void CBaseGame :: SendAllSlotInfo( ) { if( !m_GameLoading && !m_GameLoaded ) { - SendAll( m_Protocol->SEND_W3GS_SLOTINFO( m_Slots, m_RandomSeed, m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ? 3 : 0, m_Map->GetMapNumPlayers( ) ) ); + SendAll( m_Protocol->SEND_W3GS_SLOTINFO( m_Slots, m_RandomSeed, m_Map->GetMapLayoutStyle( ), m_Map->GetMapNumPlayers( ) ) ); m_SlotInfoChanged = false; } } @@ -1244,7 +1249,7 @@ void CBaseGame :: SendAllActions( ) { bool UsingGProxy = false; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetGProxy( ) ) UsingGProxy = true; @@ -1258,27 +1263,20 @@ void CBaseGame :: SendAllActions( ) // GProxy++ will insert these itself so we don't need to send them to GProxy++ players // empty actions are used to extend the time a player can use when reconnecting - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetGProxy( ) ) { - for( unsigned char j = 0; j < m_GProxyEmptyActions; j++ ) + for( unsigned char j = 0; j < m_GProxyEmptyActions; ++j ) Send( *i, m_Protocol->SEND_W3GS_INCOMING_ACTION( queue( ), 0 ) ); } } - } - - // add actions to replay - if( m_Replay ) - { - if( UsingGProxy ) + if( m_Replay ) { - for( unsigned char i = 0; i < m_GProxyEmptyActions; i++ ) + for( unsigned char i = 0; i < m_GProxyEmptyActions; ++i ) m_Replay->AddTimeSlot( 0, queue( ) ); } - - m_Replay->AddTimeSlot( m_Latency, m_Actions ); } // Warcraft III doesn't seem to respond to empty actions @@ -1286,7 +1284,7 @@ void CBaseGame :: SendAllActions( ) /* if( UsingGProxy ) m_SyncCounter += m_GProxyEmptyActions; */ - m_SyncCounter++; + ++m_SyncCounter; // we aren't allowed to send more than 1460 bytes in a single packet but it's possible we might have more than that many bytes waiting in the queue @@ -1316,6 +1314,9 @@ void CBaseGame :: SendAllActions( ) SendAll( m_Protocol->SEND_W3GS_INCOMING_ACTION2( SubActions ) ); + if( m_Replay ) + m_Replay->AddTimeSlot2( SubActions ); + while( !SubActions.empty( ) ) { delete SubActions.front( ); @@ -1331,6 +1332,9 @@ void CBaseGame :: SendAllActions( ) SendAll( m_Protocol->SEND_W3GS_INCOMING_ACTION( SubActions, m_Latency ) ); + if( m_Replay ) + m_Replay->AddTimeSlot( m_Latency, SubActions ); + while( !SubActions.empty( ) ) { delete SubActions.front( ); @@ -1338,8 +1342,13 @@ void CBaseGame :: SendAllActions( ) } } else + { SendAll( m_Protocol->SEND_W3GS_INCOMING_ACTION( m_Actions, m_Latency ) ); + if( m_Replay ) + m_Replay->AddTimeSlot( m_Latency, m_Actions ); + } + uint32_t ActualSendInterval = GetTicks( ) - m_LastActionSentTicks; uint32_t ExpectedSendInterval = m_Latency - m_LastActionLateBy; m_LastActionLateBy = ActualSendInterval - ExpectedSendInterval; @@ -1401,7 +1410,7 @@ void CBaseGame :: SendWelcomeMessage( CGamePlayer *player ) else SendChat( player, Line ); - Count++; + ++Count; } in.close( ); @@ -1434,7 +1443,7 @@ void CBaseGame :: SendEndMessage( ) else SendAllChat( Line ); - Count++; + ++Count; } in.close( ); @@ -1449,7 +1458,7 @@ void CBaseGame :: EventPlayerDeleted( CGamePlayer *player ) if( player->GetWhoisSent( ) && !player->GetJoinedRealm( ).empty( ) && player->GetSpoofedRealm( ).empty( ) ) { - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == player->GetJoinedRealm( ) ) { @@ -1500,7 +1509,7 @@ void CBaseGame :: EventPlayerDeleted( CGamePlayer *player ) // we must buffer player leave messages when using "load in game" to prevent desyncs // this ensures the player leave messages are correctly interleaved with the empty updates sent to each player - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetFinishedLoading( ) ) { @@ -1712,9 +1721,26 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP // we use an ID value of 0 to denote joining via LAN - if( HostCounterID != 0 ) + if( HostCounterID == 0 ) + { + // the player is pretending to join via LAN, which they might or might not be (i.e. it could be spoofed) + // however, we've been broadcasting a random entry key to the LAN + // if the player is really on the LAN they'll know the entry key, otherwise they won't + // or they're very lucky since it's a 32 bit number + + if( joinPlayer->GetEntryKey( ) != m_EntryKey ) + { + // oops! + + CONSOLE_Print( "[GAME: " + m_GameName + "] player [" + joinPlayer->GetName( ) + "|" + potential->GetExternalIPString( ) + "] is trying to join the game over LAN but used an incorrect entry key" ); + potential->Send( m_Protocol->SEND_W3GS_REJECTJOIN( REJECTJOIN_WRONGPASSWORD ) ); + potential->SetDeleteMe( true ); + return; + } + } + else { - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->GetHostCounterID( ) == HostCounterID ) JoinedRealm = (*i)->GetServer( ); @@ -1727,7 +1753,7 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP if( m_GHost->m_BanMethod != 0 ) { - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == JoinedRealm ) { @@ -1750,7 +1776,7 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP // this causes them to be kicked back to the chat channel on battle.net vector Slots = m_Map->GetSlots( ); - potential->Send( m_Protocol->SEND_W3GS_SLOTINFOJOIN( 1, potential->GetSocket( )->GetPort( ), potential->GetExternalIP( ), Slots, 0, m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ? 3 : 0, m_Map->GetMapNumPlayers( ) ) ); + potential->Send( m_Protocol->SEND_W3GS_SLOTINFOJOIN( 1, potential->GetSocket( )->GetPort( ), potential->GetExternalIP( ), Slots, 0, m_Map->GetMapLayoutStyle( ), m_Map->GetMapNumPlayers( ) ) ); potential->SetDeleteMe( true ); return; } @@ -1778,7 +1804,7 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP // this causes them to be kicked back to the chat channel on battle.net vector Slots = m_Map->GetSlots( ); - potential->Send( m_Protocol->SEND_W3GS_SLOTINFOJOIN( 1, potential->GetSocket( )->GetPort( ), potential->GetExternalIP( ), Slots, 0, m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ? 3 : 0, m_Map->GetMapNumPlayers( ) ) ); + potential->Send( m_Protocol->SEND_W3GS_SLOTINFOJOIN( 1, potential->GetSocket( )->GetPort( ), potential->GetExternalIP( ), Slots, 0, m_Map->GetMapLayoutStyle( ), m_Map->GetMapNumPlayers( ) ) ); potential->SetDeleteMe( true ); return; } @@ -1788,7 +1814,7 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP } } - if( m_MatchMaking && m_AutoStartPlayers != 0 && !m_Map->GetMapMatchMakingCategory( ).empty( ) && m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ) + if( m_MatchMaking && m_AutoStartPlayers != 0 && !m_Map->GetMapMatchMakingCategory( ).empty( ) && m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) { // matchmaking is enabled // start a database query to determine the player's score @@ -1803,7 +1829,7 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP bool AnyAdminCheck = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->IsAdmin( joinPlayer->GetName( ) ) || (*i)->IsRootAdmin( joinPlayer->GetName( ) ) ) { @@ -1827,13 +1853,13 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP // unfortunately we don't know how to extract the player layout from the saved game so we use the data from a replay instead // the !enforcesg command defines the player layout by parsing a replay - for( vector :: iterator i = m_EnforcePlayers.begin( ); i != m_EnforcePlayers.end( ); i++ ) + for( vector :: iterator i = m_EnforcePlayers.begin( ); i != m_EnforcePlayers.end( ); ++i ) { if( (*i).second == joinPlayer->GetName( ) ) EnforcePID = (*i).first; } - for( vector :: iterator i = m_EnforceSlots.begin( ); i != m_EnforceSlots.end( ); i++ ) + for( vector :: iterator i = m_EnforceSlots.begin( ); i != m_EnforceSlots.end( ); ++i ) { if( (*i).GetPID( ) == EnforcePID ) { @@ -1892,7 +1918,7 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP SID = 0; - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && m_Slots[i].GetComputer( ) == 0 ) { @@ -1931,7 +1957,7 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP if( m_GHost->m_BanMethod == 0 ) { - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == JoinedRealm ) { @@ -1986,18 +2012,21 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP m_Slots[SID] = EnforceSlot; else { - if( m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ) + if( m_Map->GetMapOptions( ) & MAPOPT_CUSTOMFORCES ) m_Slots[SID] = CGameSlot( Player->GetPID( ), 255, SLOTSTATUS_OCCUPIED, 0, m_Slots[SID].GetTeam( ), m_Slots[SID].GetColour( ), m_Slots[SID].GetRace( ) ); else { - m_Slots[SID] = CGameSlot( Player->GetPID( ), 255, SLOTSTATUS_OCCUPIED, 0, 12, 12, SLOTRACE_RANDOM ); + if( m_Map->GetMapFlags( ) & MAPFLAG_RANDOMRACES ) + m_Slots[SID] = CGameSlot( Player->GetPID( ), 255, SLOTSTATUS_OCCUPIED, 0, 12, 12, SLOTRACE_RANDOM ); + else + m_Slots[SID] = CGameSlot( Player->GetPID( ), 255, SLOTSTATUS_OCCUPIED, 0, 12, 12, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ); // try to pick a team and colour // make sure there aren't too many other players already unsigned char NumOtherPlayers = 0; - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && m_Slots[i].GetTeam( ) != 12 ) NumOtherPlayers++; @@ -2018,7 +2047,7 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP // send slot info to the new player // the SLOTINFOJOIN packet also tells the client their assigned PID and that the join was successful - Player->Send( m_Protocol->SEND_W3GS_SLOTINFOJOIN( Player->GetPID( ), Player->GetSocket( )->GetPort( ), Player->GetExternalIP( ), m_Slots, m_RandomSeed, m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ? 3 : 0, m_Map->GetMapNumPlayers( ) ) ); + Player->Send( m_Protocol->SEND_W3GS_SLOTINFOJOIN( Player->GetPID( ), Player->GetSocket( )->GetPort( ), Player->GetExternalIP( ), m_Slots, m_RandomSeed, m_Map->GetMapLayoutStyle( ), m_Map->GetMapNumPlayers( ) ) ); // send virtual host info and fake player info (if present) to the new player @@ -2031,7 +2060,7 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP BlankIP.push_back( 0 ); BlankIP.push_back( 0 ); - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) && *i != Player ) { @@ -2071,7 +2100,7 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP if( m_GHost->m_RequireSpoofChecks && !Player->GetWhoisShouldBeSent( ) ) { - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { // note: the following (commented out) line of code will crash because calling GetUniqueName( ) twice will result in two different return values // and unfortunately iterators are not valid if compared against different containers @@ -2091,7 +2120,7 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP { string Others; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( Player != *i && Player->GetExternalIPString( ) == (*i)->GetExternalIPString( ) ) { @@ -2170,7 +2199,7 @@ void CBaseGame :: EventPlayerJoinedWithScore( CPotentialPlayer *potential, CInco bool AnyAdminCheck = false; - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->IsAdmin( joinPlayer->GetName( ) ) || (*i)->IsRootAdmin( joinPlayer->GetName( ) ) ) { @@ -2205,7 +2234,7 @@ void CBaseGame :: EventPlayerJoinedWithScore( CPotentialPlayer *potential, CInco PlayersScored = 1; } - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetScore( ) > -99999.0 ) { @@ -2221,7 +2250,7 @@ void CBaseGame :: EventPlayerJoinedWithScore( CPotentialPlayer *potential, CInco CGamePlayer *FurthestPlayer = NULL; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !FurthestPlayer || (*i)->GetScore( ) < -99999.0 || abs( (*i)->GetScore( ) - AverageScore ) > abs( FurthestPlayer->GetScore( ) - AverageScore ) ) FurthestPlayer = *i; @@ -2281,7 +2310,7 @@ void CBaseGame :: EventPlayerJoinedWithScore( CPotentialPlayer *potential, CInco CGamePlayer *LowestPlayer = NULL; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !LowestPlayer || (*i)->GetScore( ) < -99999.0 || (*i)->GetScore( ) < LowestPlayer->GetScore( ) ) LowestPlayer = *i; @@ -2361,7 +2390,7 @@ void CBaseGame :: EventPlayerJoinedWithScore( CPotentialPlayer *potential, CInco if( HostCounterID != 0 ) { - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->GetHostCounterID( ) == HostCounterID ) JoinedRealm = (*i)->GetServer( ); @@ -2391,7 +2420,7 @@ void CBaseGame :: EventPlayerJoinedWithScore( CPotentialPlayer *potential, CInco // send slot info to the new player // the SLOTINFOJOIN packet also tells the client their assigned PID and that the join was successful - Player->Send( m_Protocol->SEND_W3GS_SLOTINFOJOIN( Player->GetPID( ), Player->GetSocket( )->GetPort( ), Player->GetExternalIP( ), m_Slots, m_RandomSeed, m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ? 3 : 0, m_Map->GetMapNumPlayers( ) ) ); + Player->Send( m_Protocol->SEND_W3GS_SLOTINFOJOIN( Player->GetPID( ), Player->GetSocket( )->GetPort( ), Player->GetExternalIP( ), m_Slots, m_RandomSeed, m_Map->GetMapLayoutStyle( ), m_Map->GetMapNumPlayers( ) ) ); // send virtual host info and fake player info (if present) to the new player @@ -2404,7 +2433,7 @@ void CBaseGame :: EventPlayerJoinedWithScore( CPotentialPlayer *potential, CInco BlankIP.push_back( 0 ); BlankIP.push_back( 0 ); - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) && *i != Player ) { @@ -2444,7 +2473,7 @@ void CBaseGame :: EventPlayerJoinedWithScore( CPotentialPlayer *potential, CInco if( m_GHost->m_RequireSpoofChecks && !Player->GetWhoisShouldBeSent( ) ) { - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { // note: the following (commented out) line of code will crash because calling GetUniqueName( ) twice will result in two different return values // and unfortunately iterators are not valid if compared against different containers @@ -2470,7 +2499,7 @@ void CBaseGame :: EventPlayerJoinedWithScore( CPotentialPlayer *potential, CInco double MaxScore = 0.0; bool Found = false; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) ) { @@ -2501,7 +2530,7 @@ void CBaseGame :: EventPlayerJoinedWithScore( CPotentialPlayer *potential, CInco { string Others; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( Player != *i && Player->GetExternalIPString( ) == (*i)->GetExternalIPString( ) ) { @@ -2577,7 +2606,7 @@ void CBaseGame :: EventPlayerLoaded( CGamePlayer *player ) bool FinishedLoading = true; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { FinishedLoading = (*i)->GetFinishedLoading( ); @@ -2590,7 +2619,7 @@ void CBaseGame :: EventPlayerLoaded( CGamePlayer *player ) // remove the new player from previously loaded players' lag screens - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( *i != player && (*i)->GetFinishedLoading( ) ) Send( *i, m_Protocol->SEND_W3GS_STOP_LAG( player ) ); @@ -2598,7 +2627,7 @@ void CBaseGame :: EventPlayerLoaded( CGamePlayer *player ) // send a chat message to previously loaded players - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( *i != player && (*i)->GetFinishedLoading( ) ) SendChat( *i, m_GHost->m_Language->PlayerFinishedLoading( player->GetName( ) ) ); @@ -2630,7 +2659,7 @@ void CBaseGame :: EventPlayerKeepAlive( CGamePlayer *player, uint32_t checkSum ) // however, it's possible that not every player has sent a checksum for this frame yet // first we verify that we have enough checksums to work with otherwise we won't know exactly who desynced - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetDeleteMe( ) && (*i)->GetCheckSums( )->empty( ) ) return; @@ -2641,7 +2670,7 @@ void CBaseGame :: EventPlayerKeepAlive( CGamePlayer *player, uint32_t checkSum ) bool FoundPlayer = false; uint32_t FirstCheckSum = 0; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetDeleteMe( ) ) { @@ -2656,7 +2685,7 @@ void CBaseGame :: EventPlayerKeepAlive( CGamePlayer *player, uint32_t checkSum ) bool AddToReplay = true; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetDeleteMe( ) && (*i)->GetCheckSums( )->front( ) != FirstCheckSum ) { @@ -2669,7 +2698,7 @@ void CBaseGame :: EventPlayerKeepAlive( CGamePlayer *player, uint32_t checkSum ) map > Bins; - for( vector :: iterator j = m_Players.begin( ); j != m_Players.end( ); j++ ) + for( vector :: iterator j = m_Players.begin( ); j != m_Players.end( ); ++j ) { if( !(*j)->GetDeleteMe( ) ) Bins[(*j)->GetCheckSums( )->front( )].push_back( (*j)->GetPID( ) ); @@ -2679,7 +2708,7 @@ void CBaseGame :: EventPlayerKeepAlive( CGamePlayer *player, uint32_t checkSum ) map > :: iterator LargestBin = Bins.begin( ); bool Tied = false; - for( map > :: iterator j = Bins.begin( ); j != Bins.end( ); j++ ) + for( map > :: iterator j = Bins.begin( ); j != Bins.end( ); ++j ) { if( (*j).second.size( ) > (*LargestBin).second.size( ) ) { @@ -2691,7 +2720,7 @@ void CBaseGame :: EventPlayerKeepAlive( CGamePlayer *player, uint32_t checkSum ) string Players; - for( vector :: iterator k = (*j).second.begin( ); k != (*j).second.end( ); k++ ) + for( vector :: iterator k = (*j).second.begin( ); k != (*j).second.end( ); ++k ) { CGamePlayer *Player = GetPlayerFromPID( *k ); @@ -2705,7 +2734,7 @@ void CBaseGame :: EventPlayerKeepAlive( CGamePlayer *player, uint32_t checkSum ) } SendAllChat( m_GHost->m_Language->PlayersInGameState( UTIL_ToString( StateNumber ), Players ) ); - StateNumber++; + ++StateNumber; } FirstCheckSum = (*LargestBin).first; @@ -2727,7 +2756,7 @@ void CBaseGame :: EventPlayerKeepAlive( CGamePlayer *player, uint32_t checkSum ) { CONSOLE_Print( "[GAME: " + m_GameName + "] kicking desynced players" ); - for( map > :: iterator j = Bins.begin( ); j != Bins.end( ); j++ ) + for( map > :: iterator j = Bins.begin( ); j != Bins.end( ); ++j ) { // kick players who are NOT in the largest bin // examples: suppose there are 10 players @@ -2736,7 +2765,7 @@ void CBaseGame :: EventPlayerKeepAlive( CGamePlayer *player, uint32_t checkSum ) if( (*j).first != (*LargestBin).first ) { - for( vector :: iterator k = (*j).second.begin( ); k != (*j).second.end( ); k++ ) + for( vector :: iterator k = (*j).second.begin( ); k != (*j).second.end( ); ++k ) { CGamePlayer *Player = GetPlayerFromPID( *k ); @@ -2757,7 +2786,7 @@ void CBaseGame :: EventPlayerKeepAlive( CGamePlayer *player, uint32_t checkSum ) } } - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetDeleteMe( ) ) (*i)->GetCheckSums( )->pop( ); @@ -2765,8 +2794,8 @@ void CBaseGame :: EventPlayerKeepAlive( CGamePlayer *player, uint32_t checkSum ) // add checksum to replay - if( m_Replay && AddToReplay ) - m_Replay->AddCheckSum( FirstCheckSum ); + /* if( m_Replay && AddToReplay ) + m_Replay->AddCheckSum( FirstCheckSum ); */ } void CBaseGame :: EventPlayerChatToHost( CGamePlayer *player, CIncomingChatPlayer *chatPlayer ) @@ -2805,6 +2834,12 @@ void CBaseGame :: EventPlayerChatToHost( CGamePlayer *player, CIncomingChatPlaye if( m_MuteAll ) Relay = false; } + else if( ExtraFlags[0] == 2 ) + { + // this is an ingame [Obs/Ref] message, print it to the console + + CONSOLE_Print( "[GAME: " + m_GameName + "] (" + MinString + ":" + SecString + ") [Obs/Ref] [" + player->GetName( ) + "]: " + chatPlayer->GetMessage( ) ); + } if( Relay ) { @@ -2885,7 +2920,7 @@ void CBaseGame :: EventPlayerChangeTeam( CGamePlayer *player, unsigned char team if( m_SaveGame ) return; - if( m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ) + if( m_Map->GetMapOptions( ) & MAPOPT_CUSTOMFORCES ) { unsigned char oldSID = GetSIDFromPID( player->GetPID( ) ); unsigned char newSID = GetEmptySlot( team, player->GetPID( ) ); @@ -2910,10 +2945,10 @@ void CBaseGame :: EventPlayerChangeTeam( CGamePlayer *player, unsigned char team unsigned char NumOtherPlayers = 0; - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && m_Slots[i].GetTeam( ) != 12 && m_Slots[i].GetPID( ) != player->GetPID( ) ) - NumOtherPlayers++; + ++NumOtherPlayers; } if( NumOtherPlayers >= m_Map->GetMapNumPlayers( ) ) @@ -2951,7 +2986,7 @@ void CBaseGame :: EventPlayerChangeColour( CGamePlayer *player, unsigned char co if( m_SaveGame ) return; - if( m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ) + if( m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) return; if( colour > 11 ) @@ -2977,7 +3012,7 @@ void CBaseGame :: EventPlayerChangeRace( CGamePlayer *player, unsigned char race if( m_SaveGame ) return; - if( m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ) + if( m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) return; if( m_Map->GetMapFlags( ) & MAPFLAG_RANDOMRACES ) @@ -2990,7 +3025,7 @@ void CBaseGame :: EventPlayerChangeRace( CGamePlayer *player, unsigned char race if( SID < m_Slots.size( ) ) { - m_Slots[SID].SetRace( race ); + m_Slots[SID].SetRace( race | SLOTRACE_SELECTABLE ); SendAllSlotInfo( ); } } @@ -3002,7 +3037,7 @@ void CBaseGame :: EventPlayerChangeHandicap( CGamePlayer *player, unsigned char if( m_SaveGame ) return; - if( m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ) + if( m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) return; if( handicap != 50 && handicap != 60 && handicap != 70 && handicap != 80 && handicap != 90 && handicap != 100 ) @@ -3030,10 +3065,10 @@ void CBaseGame :: EventPlayerDropRequest( CGamePlayer *player ) uint32_t Votes = 0; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetDropVote( ) ) - Votes++; + ++Votes; } if( (float)Votes / m_Players.size( ) > 0.49 ) @@ -3194,22 +3229,22 @@ void CBaseGame :: EventGameStarted( ) unsigned char EncodingMap[256]; unsigned char j = 0; - for( uint32_t i = 0; i < 256; i++ ) + for( uint32_t i = 0; i < 256; ++i ) { // the following 7 handicap values are forbidden if( j == 0 || j == 50 || j == 60 || j == 70 || j == 80 || j == 90 || j == 100 ) - j++; + ++j; - EncodingMap[i] = j++; + EncodingMap[i] = j++; } unsigned char CurrentSlot = 0; - for( string :: iterator si = m_HCLCommandString.begin( ); si != m_HCLCommandString.end( ); si++ ) + for( string :: iterator si = m_HCLCommandString.begin( ); si != m_HCLCommandString.end( ); ++si ) { while( m_Slots[CurrentSlot].GetSlotStatus( ) != SLOTSTATUS_OCCUPIED ) - CurrentSlot++; + ++CurrentSlot; unsigned char HandicapIndex = ( m_Slots[CurrentSlot].GetHandicap( ) - 50 ) / 10; unsigned char CharIndex = HCLChars.find( *si ); @@ -3268,7 +3303,7 @@ void CBaseGame :: EventGameStarted( ) // delete any potential players that are still hanging around - for( vector :: iterator i = m_Potentials.begin( ); i != m_Potentials.end( ); i++ ) + for( vector :: iterator i = m_Potentials.begin( ); i != m_Potentials.end( ); ++i ) delete *i; m_Potentials.clear( ); @@ -3277,7 +3312,7 @@ void CBaseGame :: EventGameStarted( ) if( m_Replay ) { - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) m_Replay->AddPlayer( (*i)->GetPID( ), (*i)->GetName( ) ); if( m_FakePlayerPID != 255 ) @@ -3285,31 +3320,28 @@ void CBaseGame :: EventGameStarted( ) m_Replay->SetSlots( m_Slots ); m_Replay->SetRandomSeed( m_RandomSeed ); - m_Replay->SetSelectMode( m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ? 3 : 0 ); + m_Replay->SetSelectMode( m_Map->GetMapLayoutStyle( ) ); m_Replay->SetStartSpotCount( m_Map->GetMapNumPlayers( ) ); - /* - - BYTEARRAY MapGameType; - if( m_SaveGame ) { - MapGameType.push_back( 0 ); - MapGameType.push_back( 2 ); - MapGameType.push_back( 0 ); - MapGameType.push_back( 0 ); + uint32_t MapGameType = MAPGAMETYPE_SAVEDGAME; + + if( m_GameState == GAME_PRIVATE ) + MapGameType |= MAPGAMETYPE_PRIVATEGAME; + + m_Replay->SetMapGameType( MapGameType ); } else { - MapGameType.push_back( m_Map->GetMapGameType( ) ); - MapGameType.push_back( 0 ); - MapGameType.push_back( 0 ); - MapGameType.push_back( 0 ); - } + uint32_t MapGameType = m_Map->GetMapGameType( ); + MapGameType |= MAPGAMETYPE_UNKNOWN0; - */ + if( m_GameState == GAME_PRIVATE ) + MapGameType |= MAPGAMETYPE_PRIVATEGAME; - m_Replay->SetMapGameType( m_Map->GetMapGameType( ) ); + m_Replay->SetMapGameType( MapGameType ); + } if( !m_Players.empty( ) ) { @@ -3347,9 +3379,9 @@ 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 - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { - for( vector :: iterator j = m_Players.begin( ); j != m_Players.end( ); j++ ) + for( vector :: iterator j = m_Players.begin( ); j != m_Players.end( ); ++j ) (*j)->AddLoadInGameData( m_Protocol->SEND_W3GS_GAMELOADED_OTHERS( (*i)->GetPID( ) ) ); } } @@ -3361,7 +3393,7 @@ void CBaseGame :: EventGameStarted( ) // and finally reenter battle.net chat - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) { (*i)->QueueGameUncreate( ); (*i)->QueueEnterChat( ); @@ -3377,7 +3409,7 @@ void CBaseGame :: EventGameLoaded( ) CGamePlayer *Shortest = NULL; CGamePlayer *Longest = NULL; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !Shortest || (*i)->GetFinishedLoadingTicks( ) < Shortest->GetFinishedLoadingTicks( ) ) Shortest = *i; @@ -3392,7 +3424,7 @@ void CBaseGame :: EventGameLoaded( ) SendAllChat( m_GHost->m_Language->LongestLoadByPlayer( Longest->GetName( ), UTIL_ToString( (float)( Longest->GetFinishedLoadingTicks( ) - m_StartedLoadingTicks ) / 1000, 2 ) ) ); } - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) SendChat( *i, m_GHost->m_Language->YourLoadingTimeWas( UTIL_ToString( (float)( (*i)->GetFinishedLoadingTicks( ) - m_StartedLoadingTicks ) / 1000, 2 ) ) ); // read from gameloaded.txt if available @@ -3419,7 +3451,7 @@ void CBaseGame :: EventGameLoaded( ) else SendAllChat( Line ); - Count++; + ++Count; } in.close( ); @@ -3431,7 +3463,7 @@ unsigned char CBaseGame :: GetSIDFromPID( unsigned char PID ) if( m_Slots.size( ) > 255 ) return 255; - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetPID( ) == PID ) return i; @@ -3442,7 +3474,7 @@ unsigned char CBaseGame :: GetSIDFromPID( unsigned char PID ) CGamePlayer *CBaseGame :: GetPlayerFromPID( unsigned char PID ) { - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) && (*i)->GetPID( ) == PID ) return *i; @@ -3464,7 +3496,7 @@ CGamePlayer *CBaseGame :: GetPlayerFromName( string name, bool sensitive ) if( !sensitive ) transform( name.begin( ), name.end( ), name.begin( ), (int(*)(int))tolower ); - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) ) { @@ -3489,7 +3521,7 @@ uint32_t CBaseGame :: GetPlayerFromNamePartial( string name, CGamePlayer **playe // try to match each player with the passed string (e.g. "Varlock" would be matched with "lock") - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) ) { @@ -3498,7 +3530,7 @@ uint32_t CBaseGame :: GetPlayerFromNamePartial( string name, CGamePlayer **playe if( TestName.find( name ) != string :: npos ) { - Matches++; + ++Matches; *player = *i; // if the name matches exactly stop any further matching @@ -3517,7 +3549,7 @@ uint32_t CBaseGame :: GetPlayerFromNamePartial( string name, CGamePlayer **playe CGamePlayer *CBaseGame :: GetPlayerFromColour( unsigned char colour ) { - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetColour( ) == colour ) return GetPlayerFromSID( i ); @@ -3530,14 +3562,14 @@ unsigned char CBaseGame :: GetNewPID( ) { // find an unused PID for a new player to use - for( unsigned char TestPID = 1; TestPID < 255; TestPID++ ) + for( unsigned char TestPID = 1; TestPID < 255; ++TestPID ) { if( TestPID == m_VirtualHostPID || TestPID == m_FakePlayerPID ) continue; bool InUse = false; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) && (*i)->GetPID( ) == TestPID ) { @@ -3559,11 +3591,11 @@ unsigned char CBaseGame :: GetNewColour( ) { // find an unused colour for a player to use - for( unsigned char TestColour = 0; TestColour < 12; TestColour++ ) + for( unsigned char TestColour = 0; TestColour < 12; ++TestColour ) { bool InUse = false; - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetColour( ) == TestColour ) { @@ -3585,7 +3617,7 @@ BYTEARRAY CBaseGame :: GetPIDs( ) { BYTEARRAY result; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) ) result.push_back( (*i)->GetPID( ) ); @@ -3598,7 +3630,7 @@ BYTEARRAY CBaseGame :: GetPIDs( unsigned char excludePID ) { BYTEARRAY result; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) && (*i)->GetPID( ) != excludePID ) result.push_back( (*i)->GetPID( ) ); @@ -3622,7 +3654,7 @@ unsigned char CBaseGame :: GetHostPID( ) // try to find the owner player next - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) && IsOwner( (*i)->GetName( ) ) ) return (*i)->GetPID( ); @@ -3630,7 +3662,7 @@ unsigned char CBaseGame :: GetHostPID( ) // okay then, just use the first available player - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetLeftMessageSent( ) ) return (*i)->GetPID( ); @@ -3651,7 +3683,7 @@ unsigned char CBaseGame :: GetEmptySlot( bool reserved ) vector SaveGameSlots = m_SaveGame->GetSlots( ); - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetSlotStatus( ) == SLOTSTATUS_OPEN && SaveGameSlots[i].GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && SaveGameSlots[i].GetComputer( ) == 0 ) return i; @@ -3664,7 +3696,7 @@ unsigned char CBaseGame :: GetEmptySlot( bool reserved ) // look for an empty slot for a new player to occupy // if reserved is true then we're willing to use closed or occupied slots as long as it wouldn't displace a player with a reserved slot - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetSlotStatus( ) == SLOTSTATUS_OPEN ) return i; @@ -3674,7 +3706,7 @@ unsigned char CBaseGame :: GetEmptySlot( bool reserved ) { // no empty slots, but since player is reserved give them a closed slot - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetSlotStatus( ) == SLOTSTATUS_CLOSED ) return i; @@ -3686,7 +3718,7 @@ unsigned char CBaseGame :: GetEmptySlot( bool reserved ) unsigned char LeastDownloaded = 100; unsigned char LeastSID = 255; - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { CGamePlayer *Player = GetPlayerFromSID( i ); @@ -3702,7 +3734,7 @@ unsigned char CBaseGame :: GetEmptySlot( bool reserved ) // nobody who isn't reserved is downloading the map, just choose the first player who isn't reserved - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { CGamePlayer *Player = GetPlayerFromSID( i ); @@ -3738,13 +3770,13 @@ unsigned char CBaseGame :: GetEmptySlot( unsigned char team, unsigned char PID ) { vector SaveGameSlots = m_SaveGame->GetSlots( ); - for( unsigned char i = StartSlot; i < m_Slots.size( ); i++ ) + for( unsigned char i = StartSlot; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetSlotStatus( ) == SLOTSTATUS_OPEN && m_Slots[i].GetTeam( ) == team && SaveGameSlots[i].GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && SaveGameSlots[i].GetComputer( ) == 0 ) return i; } - for( unsigned char i = 0; i < StartSlot; i++ ) + for( unsigned char i = 0; i < StartSlot; ++i ) { if( m_Slots[i].GetSlotStatus( ) == SLOTSTATUS_OPEN && m_Slots[i].GetTeam( ) == team && SaveGameSlots[i].GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && SaveGameSlots[i].GetComputer( ) == 0 ) return i; @@ -3754,7 +3786,7 @@ unsigned char CBaseGame :: GetEmptySlot( unsigned char team, unsigned char PID ) { // find an empty slot on the correct team starting from StartSlot - for( unsigned char i = StartSlot; i < m_Slots.size( ); i++ ) + for( unsigned char i = StartSlot; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetSlotStatus( ) == SLOTSTATUS_OPEN && m_Slots[i].GetTeam( ) == team ) return i; @@ -3763,7 +3795,7 @@ unsigned char CBaseGame :: GetEmptySlot( unsigned char team, unsigned char PID ) // didn't find an empty slot, but we could have missed one with SID < StartSlot // e.g. in the DotA case where I am in slot 4 (yellow), slot 5 (orange) is occupied, and slot 1 (blue) is open and I am trying to move to another slot - for( unsigned char i = 0; i < StartSlot; i++ ) + for( unsigned char i = 0; i < StartSlot; ++i ) { if( m_Slots[i].GetSlotStatus( ) == SLOTSTATUS_OPEN && m_Slots[i].GetTeam( ) == team ) return i; @@ -3781,19 +3813,25 @@ void CBaseGame :: SwapSlots( unsigned char SID1, unsigned char SID2 ) CGameSlot Slot1 = m_Slots[SID1]; CGameSlot Slot2 = m_Slots[SID2]; - if( m_Map->GetMapGameType( ) != GAMETYPE_CUSTOM ) + if( m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) { - // regular game - swap everything - - m_Slots[SID1] = Slot2; - m_Slots[SID2] = Slot1; + // don't swap the team, colour, race, or handicap + m_Slots[SID1] = CGameSlot( Slot2.GetPID( ), Slot2.GetDownloadStatus( ), Slot2.GetSlotStatus( ), Slot2.GetComputer( ), Slot1.GetTeam( ), Slot1.GetColour( ), Slot1.GetRace( ), Slot2.GetComputerType( ), Slot1.GetHandicap( ) ); + m_Slots[SID2] = CGameSlot( Slot1.GetPID( ), Slot1.GetDownloadStatus( ), Slot1.GetSlotStatus( ), Slot1.GetComputer( ), Slot2.GetTeam( ), Slot2.GetColour( ), Slot2.GetRace( ), Slot1.GetComputerType( ), Slot2.GetHandicap( ) ); } else { - // custom game - don't swap the team, colour, or race + // swap everything - m_Slots[SID1] = CGameSlot( Slot2.GetPID( ), Slot2.GetDownloadStatus( ), Slot2.GetSlotStatus( ), Slot2.GetComputer( ), Slot1.GetTeam( ), Slot1.GetColour( ), Slot1.GetRace( ), Slot2.GetComputerType( ), Slot2.GetHandicap( ) ); - m_Slots[SID2] = CGameSlot( Slot1.GetPID( ), Slot1.GetDownloadStatus( ), Slot1.GetSlotStatus( ), Slot1.GetComputer( ), Slot2.GetTeam( ), Slot2.GetColour( ), Slot2.GetRace( ), Slot1.GetComputerType( ), Slot1.GetHandicap( ) ); + if( m_Map->GetMapOptions( ) & MAPOPT_CUSTOMFORCES ) + { + // except if custom forces is set, then we don't swap teams... + Slot1.SetTeam( m_Slots[SID2].GetTeam( ) ); + Slot2.SetTeam( m_Slots[SID1].GetTeam( ) ); + } + + m_Slots[SID1] = Slot2; + m_Slots[SID2] = Slot1; } SendAllSlotInfo( ); @@ -3875,7 +3913,7 @@ void CBaseGame :: ColourSlot( unsigned char SID, unsigned char colour ) bool Taken = false; unsigned char TakenSID = 0; - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetColour( ) == colour ) { @@ -3909,7 +3947,7 @@ void CBaseGame :: OpenAllSlots( ) { bool Changed = false; - for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); i++ ) + for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); ++i ) { if( (*i).GetSlotStatus( ) == SLOTSTATUS_CLOSED ) { @@ -3926,7 +3964,7 @@ void CBaseGame :: CloseAllSlots( ) { bool Changed = false; - for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); i++ ) + for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); ++i ) { if( (*i).GetSlotStatus( ) == SLOTSTATUS_OPEN ) { @@ -3947,7 +3985,7 @@ void CBaseGame :: ShuffleSlots( ) vector PlayerSlots; - for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); i++ ) + for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); ++i ) { if( (*i).GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && (*i).GetComputer( ) == 0 && (*i).GetTeam( ) != 12 ) PlayerSlots.push_back( *i ); @@ -3955,9 +3993,8 @@ void CBaseGame :: ShuffleSlots( ) // now we shuffle PlayerSlots - if( m_Map->GetMapGameType( ) == GAMETYPE_CUSTOM ) + if( m_Map->GetMapOptions( ) & MAPOPT_CUSTOMFORCES ) { - // custom game // rather than rolling our own probably broken shuffle algorithm we use random_shuffle because it's guaranteed to do it properly // so in order to let random_shuffle do all the work we need a vector to operate on // unfortunately we can't just use PlayerSlots because the team/colour/race shouldn't be modified @@ -3965,7 +4002,7 @@ void CBaseGame :: ShuffleSlots( ) vector SIDs; - for( unsigned char i = 0; i < PlayerSlots.size( ); i++ ) + for( unsigned char i = 0; i < PlayerSlots.size( ); ++i ) SIDs.push_back( i ); random_shuffle( SIDs.begin( ), SIDs.end( ) ); @@ -3976,7 +4013,7 @@ void CBaseGame :: ShuffleSlots( ) // as usual don't modify the team/colour/race - for( unsigned char i = 0; i < SIDs.size( ); i++ ) + for( unsigned char i = 0; i < SIDs.size( ); ++i ) Slots.push_back( CGameSlot( PlayerSlots[SIDs[i]].GetPID( ), PlayerSlots[SIDs[i]].GetDownloadStatus( ), PlayerSlots[SIDs[i]].GetSlotStatus( ), PlayerSlots[SIDs[i]].GetComputer( ), PlayerSlots[i].GetTeam( ), PlayerSlots[i].GetColour( ), PlayerSlots[i].GetRace( ) ) ); PlayerSlots = Slots; @@ -3994,12 +4031,12 @@ void CBaseGame :: ShuffleSlots( ) vector :: iterator CurrentPlayer = PlayerSlots.begin( ); vector Slots; - for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); i++ ) + for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); ++i ) { if( (*i).GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && (*i).GetComputer( ) == 0 && (*i).GetTeam( ) != 12 ) { Slots.push_back( *CurrentPlayer ); - CurrentPlayer++; + ++CurrentPlayer; } else Slots.push_back( *i ); @@ -4024,7 +4061,7 @@ vector CBaseGame :: BalanceSlotsRecursive( vector vector BestOrdering = PlayerIDs; double BestDifference = -1.0; - for( unsigned char i = StartTeam; i < 12; i++ ) + for( unsigned char i = StartTeam; i < 12; ++i ) { if( TeamSizes[i] > 0 ) { @@ -4053,14 +4090,14 @@ vector CBaseGame :: BalanceSlotsRecursive( vector vector :: iterator CurrentPID = TestOrdering.begin( ); double TeamScores[12]; - for( unsigned char j = StartTeam; j < 12; j++ ) + for( unsigned char j = StartTeam; j < 12; ++j ) { TeamScores[j] = 0.0; - for( unsigned char k = 0; k < TeamSizes[j]; k++ ) + for( unsigned char k = 0; k < TeamSizes[j]; ++k ) { TeamScores[j] += PlayerScores[*CurrentPID]; - CurrentPID++; + ++CurrentPID; } } @@ -4068,11 +4105,11 @@ vector CBaseGame :: BalanceSlotsRecursive( vector double LargestDifference = 0.0; - for( unsigned char j = StartTeam; j < 12; j++ ) + for( unsigned char j = StartTeam; j < 12; ++j ) { if( TeamSizes[j] > 0 ) { - for( unsigned char k = j + 1; k < 12; k++ ) + for( unsigned char k = j + 1; k < 12; ++k ) { if( TeamSizes[k] > 0 ) { @@ -4101,9 +4138,9 @@ vector CBaseGame :: BalanceSlotsRecursive( vector void CBaseGame :: BalanceSlots( ) { - if( m_Map->GetMapGameType( ) != GAMETYPE_CUSTOM ) + if( !( m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) ) { - CONSOLE_Print( "[GAME: " + m_GameName + "] error balancing slots - can't balance slots in non custom games" ); + CONSOLE_Print( "[GAME: " + m_GameName + "] error balancing slots - can't balance slots without fixed player settings" ); return; } @@ -4115,7 +4152,7 @@ void CBaseGame :: BalanceSlots( ) double PlayerScores[13]; memset( TeamSizes, 0, sizeof( unsigned char ) * 12 ); - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { unsigned char PID = (*i)->GetPID( ); @@ -4162,7 +4199,7 @@ void CBaseGame :: BalanceSlots( ) uint32_t AlgorithmCost = 0; uint32_t PlayersLeft = PlayerIDs.size( ); - for( unsigned char i = 0; i < 12; i++ ) + for( unsigned char i = 0; i < 12; ++i ) { if( TeamSizes[i] > 0 ) { @@ -4195,14 +4232,14 @@ void CBaseGame :: BalanceSlots( ) vector :: iterator CurrentPID = BestOrdering.begin( ); - for( unsigned char i = 0; i < 12; i++ ) + for( unsigned char i = 0; i < 12; ++i ) { unsigned char CurrentSlot = 0; - for( unsigned char j = 0; j < TeamSizes[i]; j++ ) + for( unsigned char j = 0; j < TeamSizes[i]; ++j ) { while( CurrentSlot < m_Slots.size( ) && m_Slots[CurrentSlot].GetTeam( ) != i ) - CurrentSlot++; + ++CurrentSlot; // put the CurrentPID player on team i by swapping them into CurrentSlot @@ -4224,8 +4261,8 @@ void CBaseGame :: BalanceSlots( ) return; } - CurrentPID++; - CurrentSlot++; + ++CurrentPID; + ++CurrentSlot; } } @@ -4233,12 +4270,12 @@ void CBaseGame :: BalanceSlots( ) SendAllChat( m_GHost->m_Language->BalancingSlotsCompleted( ) ); SendAllSlotInfo( ); - for( unsigned char i = 0; i < 12; i++ ) + for( unsigned char i = 0; i < 12; ++i ) { bool TeamHasPlayers = false; double TeamScore = 0.0; - for( vector :: iterator j = m_Players.begin( ); j != m_Players.end( ); j++ ) + for( vector :: iterator j = m_Players.begin( ); j != m_Players.end( ); ++j ) { unsigned char SID = GetSIDFromPID( (*j)->GetPID( ) ); @@ -4279,7 +4316,7 @@ void CBaseGame :: AddToReserved( string name ) // check that the user is not already reserved - for( vector :: iterator i = m_Reserved.begin( ); i != m_Reserved.end( ); i++ ) + for( vector :: iterator i = m_Reserved.begin( ); i != m_Reserved.end( ); ++i ) { if( *i == name ) return; @@ -4289,7 +4326,7 @@ void CBaseGame :: AddToReserved( string name ) // upgrade the user if they're already in the game - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { string NameLower = (*i)->GetName( ); transform( NameLower.begin( ), NameLower.end( ), NameLower.begin( ), (int(*)(int))tolower ); @@ -4311,7 +4348,7 @@ bool CBaseGame :: IsReserved( string name ) { transform( name.begin( ), name.end( ), name.begin( ), (int(*)(int))tolower ); - for( vector :: iterator i = m_Reserved.begin( ); i != m_Reserved.end( ); i++ ) + for( vector :: iterator i = m_Reserved.begin( ); i != m_Reserved.end( ); ++i ) { if( *i == name ) return true; @@ -4324,7 +4361,7 @@ bool CBaseGame :: IsDownloading( ) { // returns true if at least one player is downloading the map - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetDownloadStarted( ) && !(*i)->GetDownloadFinished( ) ) return true; @@ -4366,7 +4403,7 @@ void CBaseGame :: StartCountDown( bool force ) string StillDownloading; - for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); i++ ) + for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); ++i ) { if( (*i).GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && (*i).GetComputer( ) == 0 && (*i).GetDownloadStatus( ) != 100 ) { @@ -4391,7 +4428,7 @@ void CBaseGame :: StartCountDown( bool force ) if( m_GHost->m_RequireSpoofChecks ) { - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetSpoofed( ) ) { @@ -4411,7 +4448,7 @@ void CBaseGame :: StartCountDown( bool force ) string NotPinged; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetReserved( ) && (*i)->GetNumPings( ) < 3 ) { @@ -4452,7 +4489,7 @@ void CBaseGame :: StartCountDownAuto( bool requireSpoofChecks ) string StillDownloading; - for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); i++ ) + for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); ++i ) { if( (*i).GetSlotStatus( ) == SLOTSTATUS_OCCUPIED && (*i).GetComputer( ) == 0 && (*i).GetDownloadStatus( ) != 100 ) { @@ -4480,7 +4517,7 @@ void CBaseGame :: StartCountDownAuto( bool requireSpoofChecks ) if( requireSpoofChecks ) { - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetSpoofed( ) ) { @@ -4500,7 +4537,7 @@ void CBaseGame :: StartCountDownAuto( bool requireSpoofChecks ) string NotPinged; - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( !(*i)->GetReserved( ) && (*i)->GetNumPings( ) < 3 ) { @@ -4534,7 +4571,7 @@ void CBaseGame :: StopPlayers( string reason ) // therefore calling this function when m_GameLoading || m_GameLoaded is roughly equivalent to setting m_Exiting = true // the only difference is whether the code in the Update function is executed or not - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { (*i)->SetDeleteMe( true ); (*i)->SetLeftReason( reason ); @@ -4544,7 +4581,7 @@ void CBaseGame :: StopPlayers( string reason ) void CBaseGame :: StopLaggers( string reason ) { - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i)->GetLagging( ) ) { @@ -4607,7 +4644,7 @@ void CBaseGame :: DeleteFakePlayer( ) if( m_FakePlayerPID == 255 ) return; - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) { if( m_Slots[i].GetPID( ) == m_FakePlayerPID ) m_Slots[i] = CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, m_Slots[i].GetTeam( ), m_Slots[i].GetColour( ), m_Slots[i].GetRace( ) ); diff --git a/ghost/game_base.h b/ghost/game_base.h index f0d36c3..757ead5 100644 --- a/ghost/game_base.h +++ b/ghost/game_base.h @@ -81,6 +81,7 @@ class CBaseGame : protected MessageLogger string m_HCLCommandString; // the "HostBot Command Library" command string, used to pass a limited amount of data to specially designed maps uint32_t m_RandomSeed; // the random seed sent to the Warcraft III clients uint32_t m_HostCounter; // a unique game number + uint32_t m_EntryKey; // random entry key for LAN, used to prove that a player is actually joining from LAN uint32_t m_Latency; // the number of ms to wait between sending action packets (we queue any received during this time) uint32_t m_SyncLimit; // the maximum number of packets a player can fall out of sync before starting the lag screen uint32_t m_SyncCounter; // the number of actions sent so far (for determining if anyone is lagging) diff --git a/ghost/gameplayer.cpp b/ghost/gameplayer.cpp index c0575b1..4a0779c 100644 --- a/ghost/gameplayer.cpp +++ b/ghost/gameplayer.cpp @@ -34,15 +34,9 @@ // CPotentialPlayer // -CPotentialPlayer :: CPotentialPlayer( CGameProtocol *nProtocol, CBaseGame *nGame, CTCPSocket *nSocket ) - : MessageLogger( nGame ) +CPotentialPlayer :: CPotentialPlayer( CGameProtocol *nProtocol, CBaseGame *nGame, CTCPSocket *nSocket ) : m_Protocol( nProtocol ), m_Game( nGame ), m_Socket( nSocket ), m_DeleteMe( false ), m_Error( false ), m_IncomingJoinPlayer( NULL ), MessageLogger( nGame ) { - m_Protocol = nProtocol; - m_Game = nGame; - m_Socket = nSocket; - m_DeleteMe = false; - m_Error = false; - m_IncomingJoinPlayer = NULL; + } CPotentialPlayer :: ~CPotentialPlayer( ) @@ -190,98 +184,30 @@ void CPotentialPlayer :: Send( BYTEARRAY data ) // CGamePlayer // -CGamePlayer :: CGamePlayer( CGameProtocol *nProtocol, CBaseGame *nGame, CTCPSocket *nSocket, unsigned char nPID, string nJoinedRealm, string nName, BYTEARRAY nInternalIP, bool nReserved ) : CPotentialPlayer( nProtocol, nGame, nSocket ) +CGamePlayer :: CGamePlayer( CGameProtocol *nProtocol, CBaseGame *nGame, CTCPSocket *nSocket, unsigned char nPID, string nJoinedRealm, string nName, BYTEARRAY nInternalIP, bool nReserved ) : CPotentialPlayer( nProtocol, nGame, nSocket ), +m_PID( nPID ), m_Name( nName ), m_InternalIP( nInternalIP ), m_JoinedRealm( nJoinedRealm ), m_TotalPacketsSent( 0 ), m_TotalPacketsReceived( 0 ), m_LeftCode( PLAYERLEAVE_LOBBY ), m_LoginAttempts( 0 ), m_SyncCounter( 0 ), m_JoinTime( GetTime( ) ), +m_LastMapPartSent( 0 ), m_LastMapPartAcked( 0 ), m_StartedDownloadingTicks( 0 ), m_FinishedLoadingTicks( 0 ), m_StartedLaggingTicks( 0 ), m_StatsSentTime( 0 ), m_StatsDotASentTime( 0 ), m_LastGProxyWaitNoticeSentTime( 0 ), m_Score( -100000.0 ), +m_LoggedIn( false ), m_Spoofed( false ), m_Reserved( nReserved ), m_WhoisShouldBeSent( false ), m_WhoisSent( false ), m_DownloadAllowed( false ), m_DownloadStarted( false ), m_DownloadFinished( false ), m_FinishedLoading( false ), m_Lagging( false ), +m_DropVote( false ), m_KickVote( false ), m_Muted( false ), m_LeftMessageSent( false ), m_GProxy( false ), m_GProxyDisconnectNoticeSent( false ), m_GProxyReconnectKey( GetTicks( ) ), m_LastGProxyAckTime( 0 ) { - m_PID = nPID; - m_Name = nName; - m_InternalIP = nInternalIP; - m_JoinedRealm = nJoinedRealm; - m_TotalPacketsSent = 0; - m_TotalPacketsReceived = 0; - m_LeftCode = PLAYERLEAVE_LOBBY; - m_LoginAttempts = 0; - m_SyncCounter = 0; - m_JoinTime = GetTime( ); - m_LastMapPartSent = 0; - m_LastMapPartAcked = 0; - m_StartedDownloadingTicks = 0; - m_FinishedDownloadingTime = 0; - m_FinishedLoadingTicks = 0; - m_StartedLaggingTicks = 0; - m_StatsSentTime = 0; - m_StatsDotASentTime = 0; - m_LastGProxyWaitNoticeSentTime = 0; - m_Score = -100000.0; - m_LoggedIn = false; - m_Spoofed = false; - m_Reserved = nReserved; - m_WhoisShouldBeSent = false; - m_WhoisSent = false; - m_DownloadAllowed = false; - m_DownloadStarted = false; - m_DownloadFinished = false; - m_FinishedLoading = false; - m_Lagging = false; - m_DropVote = false; - m_KickVote = false; - m_Muted = false; - m_LeftMessageSent = false; - m_GProxy = false; - m_GProxyDisconnectNoticeSent = false; - m_GProxyReconnectKey = GetTicks( ); - m_LastGProxyAckTime = 0; + } -CGamePlayer :: CGamePlayer( CPotentialPlayer *potential, unsigned char nPID, string nJoinedRealm, string nName, BYTEARRAY nInternalIP, bool nReserved ) : CPotentialPlayer( potential->m_Protocol, potential->m_Game, potential->GetSocket( ) ) +CGamePlayer :: CGamePlayer( CPotentialPlayer *potential, unsigned char nPID, string nJoinedRealm, string nName, BYTEARRAY nInternalIP, bool nReserved ) : CPotentialPlayer( potential->m_Protocol, potential->m_Game, potential->GetSocket( ) ), +m_PID( nPID ), m_Name( nName ), m_InternalIP( nInternalIP ), m_JoinedRealm( nJoinedRealm ), m_TotalPacketsSent( 0 ), m_TotalPacketsReceived( 1 ), m_LeftCode( PLAYERLEAVE_LOBBY ), m_LoginAttempts( 0 ), m_SyncCounter( 0 ), m_JoinTime( GetTime( ) ), +m_LastMapPartSent( 0 ), m_LastMapPartAcked( 0 ), m_StartedDownloadingTicks( 0 ), m_FinishedLoadingTicks( 0 ), m_StartedLaggingTicks( 0 ), m_StatsSentTime( 0 ), m_StatsDotASentTime( 0 ), m_LastGProxyWaitNoticeSentTime( 0 ), m_Score( -100000.0 ), +m_LoggedIn( false ), m_Spoofed( false ), m_Reserved( nReserved ), m_WhoisShouldBeSent( false ), m_WhoisSent( false ), m_DownloadAllowed( false ), m_DownloadStarted( false ), m_DownloadFinished( false ), m_FinishedLoading( false ), m_Lagging( false ), +m_DropVote( false ), m_KickVote( false ), m_Muted( false ), m_LeftMessageSent( false ), m_GProxy( false ), m_GProxyDisconnectNoticeSent( false ), m_GProxyReconnectKey( GetTicks( ) ), m_LastGProxyAckTime( 0 ) { // todotodo: properly copy queued packets to the new player, this just discards them // this isn't a big problem because official Warcraft III clients don't send any packets after the join request until they receive a response - // m_Packets = potential->GetPackets( ); - m_PID = nPID; - m_Name = nName; - m_InternalIP = nInternalIP; - m_JoinedRealm = nJoinedRealm; - m_TotalPacketsSent = 0; - // hackhack: we initialize this to 1 because the CPotentialPlayer must have received a W3GS_REQJOIN before this class was created + + // hackhack: we initialize m_TotalPacketsReceived to 1 because the CPotentialPlayer must have received a W3GS_REQJOIN before this class was created // to fix this we could move the packet counters to CPotentialPlayer and copy them here // note: we must make sure we never send a packet to a CPotentialPlayer otherwise the send counter will be incorrect too! what a mess this is... // that said, the packet counters are only used for managing GProxy++ reconnections - - m_TotalPacketsReceived = 1; - m_LeftCode = PLAYERLEAVE_LOBBY; - m_LoginAttempts = 0; - m_SyncCounter = 0; - m_JoinTime = GetTime( ); - m_LastMapPartSent = 0; - m_LastMapPartAcked = 0; - m_StartedDownloadingTicks = 0; - m_FinishedDownloadingTime = 0; - m_FinishedLoadingTicks = 0; - m_StartedLaggingTicks = 0; - m_StatsSentTime = 0; - m_StatsDotASentTime = 0; - m_LastGProxyWaitNoticeSentTime = 0; - m_Score = -100000.0; - m_LoggedIn = false; - m_Spoofed = false; - m_Reserved = nReserved; - m_WhoisShouldBeSent = false; - m_WhoisSent = false; - m_DownloadAllowed = false; - m_DownloadStarted = false; - m_DownloadFinished = false; - m_FinishedLoading = false; - m_Lagging = false; - m_DropVote = false; - m_KickVote = false; - m_Muted = false; - m_LeftMessageSent = false; - m_GProxy = false; - m_GProxyDisconnectNoticeSent = false; - m_GProxyReconnectKey = GetTicks( ); - m_LastGProxyAckTime = 0; } CGamePlayer :: ~CGamePlayer( ) @@ -314,7 +240,7 @@ uint32_t CGamePlayer :: GetPing( bool LCPing ) uint32_t AvgPing = 0; - for( unsigned int i = 0; i < m_Pings.size( ); i++ ) + for( unsigned int i = 0; i < m_Pings.size( ); ++i ) AvgPing += m_Pings[i]; AvgPing /= m_Pings.size( ); @@ -334,7 +260,7 @@ bool CGamePlayer :: Update( void *fd ) { // todotodo: we could get kicked from battle.net for sending a command with invalid characters, do some basic checking - for( vector :: iterator i = m_Game->m_GHost->m_BNETs.begin( ); i != m_Game->m_GHost->m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_Game->m_GHost->m_BNETs.begin( ); i != m_Game->m_GHost->m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == m_JoinedRealm ) { @@ -426,7 +352,7 @@ void CGamePlayer :: ExtractPackets( ) m_Packets.push( new CCommandPacket( Bytes[0], Bytes[1], BYTEARRAY( Bytes.begin( ), Bytes.begin( ) + Length ) ) ); if( Bytes[0] == W3GS_HEADER_CONSTANT ) - m_TotalPacketsReceived++; + ++m_TotalPacketsReceived; *RecvBuffer = RecvBuffer->substr( Length ); Bytes = BYTEARRAY( Bytes.begin( ) + Length, Bytes.end( ) ); @@ -507,7 +433,7 @@ void CGamePlayer :: ProcessPackets( ) case CGameProtocol :: W3GS_OUTGOING_KEEPALIVE: CheckSum = m_Protocol->RECEIVE_W3GS_OUTGOING_KEEPALIVE( Packet->GetData( ) ); m_CheckSums.push( CheckSum ); - m_SyncCounter++; + ++m_SyncCounter; m_Game->EventPlayerKeepAlive( this, CheckSum ); break; @@ -515,7 +441,9 @@ void CGamePlayer :: ProcessPackets( ) ChatPlayer = m_Protocol->RECEIVE_W3GS_CHAT_TO_HOST( Packet->GetData( ) ); if( ChatPlayer ) + { m_Game->EventPlayerChatToHost( this, ChatPlayer ); + } delete ChatPlayer; ChatPlayer = NULL; @@ -609,7 +537,7 @@ void CGamePlayer :: ProcessPackets( ) while( PacketsToUnqueue > 0 ) { m_GProxyBuffer.pop( ); - PacketsToUnqueue--; + --PacketsToUnqueue; } } } @@ -625,7 +553,7 @@ void CGamePlayer :: Send( BYTEARRAY data ) // 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++; + ++m_TotalPacketsSent; if( m_GProxy && m_Game->GetGameLoaded( ) ) m_GProxyBuffer.push( data ); @@ -651,7 +579,7 @@ void CGamePlayer :: EventGProxyReconnect( CTCPSocket *NewSocket, uint32_t LastPa while( PacketsToUnqueue > 0 ) { m_GProxyBuffer.pop( ); - PacketsToUnqueue--; + --PacketsToUnqueue; } } diff --git a/ghost/gameprotocol.cpp b/ghost/gameprotocol.cpp index f22a31d..bf0becb 100644 --- a/ghost/gameprotocol.cpp +++ b/ghost/gameprotocol.cpp @@ -29,10 +29,9 @@ // CGameProtocol // -CGameProtocol :: CGameProtocol( CGHost *nGHost ) - : MessageLogger( nGHost ) +CGameProtocol :: CGameProtocol( CGHost *nGHost ) : m_GHost( nGHost ), MessageLogger( nGHost ) { - m_GHost = nGHost; + } CGameProtocol :: ~CGameProtocol( ) @@ -64,12 +63,13 @@ CIncomingJoinPlayer *CGameProtocol :: RECEIVE_W3GS_REQJOIN( BYTEARRAY data ) if( ValidateLength( data ) && data.size( ) >= 20 ) { uint32_t HostCounter = UTIL_ByteArrayToUInt32( data, false, 4 ); + uint32_t EntryKey = UTIL_ByteArrayToUInt32( data, false, 8 ); BYTEARRAY Name = UTIL_ExtractCString( data, 19 ); if( !Name.empty( ) && data.size( ) >= Name.size( ) + 30 ) { BYTEARRAY InternalIP = BYTEARRAY( data.begin( ) + Name.size( ) + 26, data.begin( ) + Name.size( ) + 30 ); - return new CIncomingJoinPlayer( HostCounter, string( Name.begin( ), Name.end( ) ), InternalIP ); + return new CIncomingJoinPlayer( HostCounter, EntryKey, string( Name.begin( ), Name.end( ) ), InternalIP ); } } @@ -309,11 +309,11 @@ BYTEARRAY CGameProtocol :: SEND_W3GS_PING_FROM_HOST( ) return packet; } -BYTEARRAY CGameProtocol :: SEND_W3GS_SLOTINFOJOIN( unsigned char PID, BYTEARRAY port, BYTEARRAY externalIP, vector &slots, uint32_t randomSeed, unsigned char gameType, unsigned char playerSlots ) +BYTEARRAY CGameProtocol :: SEND_W3GS_SLOTINFOJOIN( unsigned char PID, BYTEARRAY port, BYTEARRAY externalIP, vector &slots, uint32_t randomSeed, unsigned char layoutStyle, unsigned char playerSlots ) { unsigned char Zeros[] = { 0, 0, 0, 0 }; - BYTEARRAY SlotInfo = EncodeSlotInfo( slots, randomSeed, gameType, playerSlots ); + BYTEARRAY SlotInfo = EncodeSlotInfo( slots, randomSeed, layoutStyle, playerSlots ); BYTEARRAY packet; if( port.size( ) == 2 && externalIP.size( ) == 4 ) @@ -440,9 +440,9 @@ BYTEARRAY CGameProtocol :: SEND_W3GS_GAMELOADED_OTHERS( unsigned char PID ) return packet; } -BYTEARRAY CGameProtocol :: SEND_W3GS_SLOTINFO( vector &slots, uint32_t randomSeed, unsigned char gameType, unsigned char playerSlots ) +BYTEARRAY CGameProtocol :: SEND_W3GS_SLOTINFO( vector &slots, uint32_t randomSeed, unsigned char layoutStyle, unsigned char playerSlots ) { - BYTEARRAY SlotInfo = EncodeSlotInfo( slots, randomSeed, gameType, playerSlots ); + BYTEARRAY SlotInfo = EncodeSlotInfo( slots, randomSeed, layoutStyle, playerSlots ); BYTEARRAY packet; packet.push_back( W3GS_HEADER_CONSTANT ); // W3GS header constant packet.push_back( W3GS_SLOTINFO ); // W3GS_SLOTINFO @@ -560,12 +560,12 @@ BYTEARRAY CGameProtocol :: SEND_W3GS_START_LAG( vector players, b if( loadInGame ) { if( !(*i)->GetFinishedLoading( ) ) - NumLaggers++; + ++NumLaggers; } else { if( (*i)->GetLagging( ) ) - NumLaggers++; + ++NumLaggers; } } @@ -653,12 +653,11 @@ BYTEARRAY CGameProtocol :: SEND_W3GS_SEARCHGAME( bool TFT, unsigned char war3Ver return packet; } -BYTEARRAY CGameProtocol :: SEND_W3GS_GAMEINFO( bool TFT, unsigned char war3Version, BYTEARRAY mapGameType, BYTEARRAY mapFlags, BYTEARRAY mapWidth, BYTEARRAY mapHeight, string gameName, string hostName, uint32_t upTime, string mapPath, BYTEARRAY mapCRC, uint32_t slotsTotal, uint32_t slotsOpen, uint16_t port, uint32_t hostCounter ) +BYTEARRAY CGameProtocol :: SEND_W3GS_GAMEINFO( bool TFT, unsigned char war3Version, BYTEARRAY mapGameType, BYTEARRAY mapFlags, BYTEARRAY mapWidth, BYTEARRAY mapHeight, string gameName, string hostName, uint32_t upTime, string mapPath, BYTEARRAY mapCRC, uint32_t slotsTotal, uint32_t slotsOpen, uint16_t port, uint32_t hostCounter, uint32_t entryKey ) { unsigned char ProductID_ROC[] = { 51, 82, 65, 87 }; // "WAR3" unsigned char ProductID_TFT[] = { 80, 88, 51, 87 }; // "W3XP" unsigned char Version[] = { war3Version, 0, 0, 0 }; - unsigned char Unknown1[] = { 1, 2, 3, 4 }; unsigned char Unknown2[] = { 1, 0, 0, 0 }; BYTEARRAY packet; @@ -692,7 +691,7 @@ BYTEARRAY CGameProtocol :: SEND_W3GS_GAMEINFO( bool TFT, unsigned char war3Versi UTIL_AppendByteArray( packet, Version, 4 ); // Version UTIL_AppendByteArray( packet, hostCounter, false ); // Host Counter - UTIL_AppendByteArray( packet, Unknown1, 4 ); // ??? (this varies wildly even between two identical games created one after another) + UTIL_AppendByteArray( packet, entryKey, false ); // Entry Key UTIL_AppendByteArrayFast( packet, gameName ); // Game Name packet.push_back( 0 ); // ??? (maybe game password) UTIL_AppendByteArrayFast( packet, StatString ); // Stat String @@ -944,16 +943,16 @@ bool CGameProtocol :: ValidateLength( BYTEARRAY &content ) return false; } -BYTEARRAY CGameProtocol :: EncodeSlotInfo( vector &slots, uint32_t randomSeed, unsigned char gameType, unsigned char playerSlots ) +BYTEARRAY CGameProtocol :: EncodeSlotInfo( vector &slots, uint32_t randomSeed, unsigned char layoutStyle, unsigned char playerSlots ) { BYTEARRAY SlotInfo; SlotInfo.push_back( (unsigned char)slots.size( ) ); // number of slots - for( unsigned int i = 0; i < slots.size( ); i++ ) + for( unsigned int i = 0; i < slots.size( ); ++i ) UTIL_AppendByteArray( SlotInfo, slots[i].GetByteArray( ) ); UTIL_AppendByteArray( SlotInfo, randomSeed, false ); // random seed - SlotInfo.push_back( gameType ); // GameType (seems to be 0 for regular game, 3 for custom game) + SlotInfo.push_back( layoutStyle ); // LayoutStyle (0 = melee, 1 = custom forces, 3 = custom forces + fixed player settings) SlotInfo.push_back( playerSlots ); // number of player slots (non observer) return SlotInfo; } @@ -962,11 +961,9 @@ BYTEARRAY CGameProtocol :: EncodeSlotInfo( vector &slots, uint32_t ra // CIncomingJoinPlayer // -CIncomingJoinPlayer :: CIncomingJoinPlayer( uint32_t nHostCounter, string nName, BYTEARRAY &nInternalIP ) +CIncomingJoinPlayer :: CIncomingJoinPlayer( uint32_t nHostCounter, uint32_t nEntryKey, string nName, BYTEARRAY &nInternalIP ) : m_HostCounter( nHostCounter ), m_EntryKey( nEntryKey ), m_Name( nName ), m_InternalIP( nInternalIP ) { - m_HostCounter = nHostCounter; - m_Name = nName; - m_InternalIP = nInternalIP; + } CIncomingJoinPlayer :: ~CIncomingJoinPlayer( ) @@ -978,11 +975,9 @@ CIncomingJoinPlayer :: ~CIncomingJoinPlayer( ) // CIncomingAction // -CIncomingAction :: CIncomingAction( unsigned char nPID, BYTEARRAY &nCRC, BYTEARRAY &nAction ) +CIncomingAction :: CIncomingAction( unsigned char nPID, BYTEARRAY &nCRC, BYTEARRAY &nAction ) : m_PID( nPID ), m_CRC( nCRC ), m_Action( nAction ) { - m_PID = nPID; - m_CRC = nCRC; - m_Action = nAction; + } CIncomingAction :: ~CIncomingAction( ) @@ -994,26 +989,17 @@ CIncomingAction :: ~CIncomingAction( ) // CIncomingChatPlayer // -CIncomingChatPlayer :: CIncomingChatPlayer( unsigned char nFromPID, BYTEARRAY &nToPIDs, unsigned char nFlag, string nMessage ) +CIncomingChatPlayer :: CIncomingChatPlayer( unsigned char nFromPID, BYTEARRAY &nToPIDs, unsigned char nFlag, string nMessage ) : m_Type( CTH_MESSAGE ), m_FromPID( nFromPID ), m_ToPIDs( nToPIDs ), m_Flag( nFlag ), m_Message( nMessage ) { - m_Type = CTH_MESSAGE; - m_FromPID = nFromPID; - m_ToPIDs = nToPIDs; - m_Flag = nFlag; - m_Message = nMessage; + } -CIncomingChatPlayer :: CIncomingChatPlayer( unsigned char nFromPID, BYTEARRAY &nToPIDs, unsigned char nFlag, string nMessage, BYTEARRAY &nExtraFlags ) +CIncomingChatPlayer :: CIncomingChatPlayer( unsigned char nFromPID, BYTEARRAY &nToPIDs, unsigned char nFlag, string nMessage, BYTEARRAY &nExtraFlags ) : m_Type( CTH_MESSAGEEXTRA ), m_FromPID( nFromPID ), m_ToPIDs( nToPIDs ), m_Flag( nFlag ), m_Message( nMessage ), m_ExtraFlags( nExtraFlags ) { - m_Type = CTH_MESSAGEEXTRA; - m_FromPID = nFromPID; - m_ToPIDs = nToPIDs; - m_Flag = nFlag; - m_Message = nMessage; - m_ExtraFlags = nExtraFlags; + } -CIncomingChatPlayer :: CIncomingChatPlayer( unsigned char nFromPID, BYTEARRAY &nToPIDs, unsigned char nFlag, unsigned char nByte ) +CIncomingChatPlayer :: CIncomingChatPlayer( unsigned char nFromPID, BYTEARRAY &nToPIDs, unsigned char nFlag, unsigned char nByte ) : m_FromPID( nFromPID ), m_ToPIDs( nToPIDs ), m_Flag( nFlag ), m_Byte( nByte ) { if( nFlag == 17 ) m_Type = CTH_TEAMCHANGE; @@ -1023,11 +1009,6 @@ CIncomingChatPlayer :: CIncomingChatPlayer( unsigned char nFromPID, BYTEARRAY &n m_Type = CTH_RACECHANGE; else if( nFlag == 20 ) m_Type = CTH_HANDICAPCHANGE; - - m_FromPID = nFromPID; - m_ToPIDs = nToPIDs; - m_Flag = nFlag; - m_Byte = nByte; } CIncomingChatPlayer :: ~CIncomingChatPlayer( ) @@ -1039,10 +1020,9 @@ CIncomingChatPlayer :: ~CIncomingChatPlayer( ) // CIncomingMapSize // -CIncomingMapSize :: CIncomingMapSize( unsigned char nSizeFlag, uint32_t nMapSize ) +CIncomingMapSize :: CIncomingMapSize( unsigned char nSizeFlag, uint32_t nMapSize ) : m_SizeFlag( nSizeFlag ), m_MapSize( nMapSize ) { - m_SizeFlag = nSizeFlag; - m_MapSize = nMapSize; + } CIncomingMapSize :: ~CIncomingMapSize( ) diff --git a/ghost/gameprotocol.h b/ghost/gameprotocol.h index 638da41..f3aebc5 100644 --- a/ghost/gameprotocol.h +++ b/ghost/gameprotocol.h @@ -122,12 +122,12 @@ class CGameProtocol : protected MessageLogger // send functions BYTEARRAY SEND_W3GS_PING_FROM_HOST( ); - BYTEARRAY SEND_W3GS_SLOTINFOJOIN( unsigned char PID, BYTEARRAY port, BYTEARRAY externalIP, vector &slots, uint32_t randomSeed, unsigned char gameType, unsigned char playerSlots ); + BYTEARRAY SEND_W3GS_SLOTINFOJOIN( unsigned char PID, BYTEARRAY port, BYTEARRAY externalIP, vector &slots, uint32_t randomSeed, unsigned char layoutStyle, unsigned char playerSlots ); BYTEARRAY SEND_W3GS_REJECTJOIN( uint32_t reason ); BYTEARRAY SEND_W3GS_PLAYERINFO( unsigned char PID, string name, BYTEARRAY externalIP, BYTEARRAY internalIP ); BYTEARRAY SEND_W3GS_PLAYERLEAVE_OTHERS( unsigned char PID, uint32_t leftCode ); BYTEARRAY SEND_W3GS_GAMELOADED_OTHERS( unsigned char PID ); - BYTEARRAY SEND_W3GS_SLOTINFO( vector &slots, uint32_t randomSeed, unsigned char gameType, unsigned char playerSlots ); + BYTEARRAY SEND_W3GS_SLOTINFO( vector &slots, uint32_t randomSeed, unsigned char layoutStyle, unsigned char playerSlots ); BYTEARRAY SEND_W3GS_COUNTDOWN_START( ); BYTEARRAY SEND_W3GS_COUNTDOWN_END( ); BYTEARRAY SEND_W3GS_INCOMING_ACTION( queue actions, uint16_t sendInterval ); @@ -135,7 +135,7 @@ class CGameProtocol : protected MessageLogger BYTEARRAY SEND_W3GS_START_LAG( vector players, bool loadInGame = false ); BYTEARRAY SEND_W3GS_STOP_LAG( CGamePlayer *player, bool loadInGame = false ); BYTEARRAY SEND_W3GS_SEARCHGAME( bool TFT, unsigned char war3Version ); - BYTEARRAY SEND_W3GS_GAMEINFO( bool TFT, unsigned char war3Version, BYTEARRAY mapGameType, BYTEARRAY mapFlags, BYTEARRAY mapWidth, BYTEARRAY mapHeight, string gameName, string hostName, uint32_t upTime, string mapPath, BYTEARRAY mapCRC, uint32_t slotsTotal, uint32_t slotsOpen, uint16_t port, uint32_t hostCounter ); + BYTEARRAY SEND_W3GS_GAMEINFO( bool TFT, unsigned char war3Version, BYTEARRAY mapGameType, BYTEARRAY mapFlags, BYTEARRAY mapWidth, BYTEARRAY mapHeight, string gameName, string hostName, uint32_t upTime, string mapPath, BYTEARRAY mapCRC, uint32_t slotsTotal, uint32_t slotsOpen, uint16_t port, uint32_t hostCounter, uint32_t entryKey ); BYTEARRAY SEND_W3GS_CREATEGAME( bool TFT, unsigned char war3Version ); BYTEARRAY SEND_W3GS_REFRESHGAME( uint32_t players, uint32_t playerSlots ); BYTEARRAY SEND_W3GS_DECREATEGAME( ); @@ -149,7 +149,7 @@ class CGameProtocol : protected MessageLogger private: bool AssignLength( BYTEARRAY &content ); bool ValidateLength( BYTEARRAY &content ); - BYTEARRAY EncodeSlotInfo( vector &slots, uint32_t randomSeed, unsigned char gameType, unsigned char playerSlots ); + BYTEARRAY EncodeSlotInfo( vector &slots, uint32_t randomSeed, unsigned char layoutStyle, unsigned char playerSlots ); }; // @@ -160,14 +160,16 @@ class CIncomingJoinPlayer { private: uint32_t m_HostCounter; + uint32_t m_EntryKey; string m_Name; BYTEARRAY m_InternalIP; public: - CIncomingJoinPlayer( uint32_t nHostCounter, string nName, BYTEARRAY &nInternalIP ); + CIncomingJoinPlayer( uint32_t nHostCounter, uint32_t nEntryKey, string nName, BYTEARRAY &nInternalIP ); ~CIncomingJoinPlayer( ); uint32_t GetHostCounter( ) { return m_HostCounter; } + uint32_t GetEntryKey( ) { return m_EntryKey; } string GetName( ) { return m_Name; } BYTEARRAY GetInternalIP( ) { return m_InternalIP; } }; diff --git a/ghost/gameslot.cpp b/ghost/gameslot.cpp index a04b203..31f3197 100644 --- a/ghost/gameslot.cpp +++ b/ghost/gameslot.cpp @@ -62,16 +62,9 @@ CGameSlot :: CGameSlot( BYTEARRAY &n ) } CGameSlot :: CGameSlot( unsigned char nPID, unsigned char nDownloadStatus, unsigned char nSlotStatus, unsigned char nComputer, unsigned char nTeam, unsigned char nColour, unsigned char nRace, unsigned char nComputerType, unsigned char nHandicap ) + : m_PID( nPID ), m_DownloadStatus( nDownloadStatus ), m_SlotStatus( nSlotStatus ), m_Computer( nComputer ), m_Team( nTeam ), m_Colour( nColour ), m_Race( nRace ), m_ComputerType( nComputerType ), m_Handicap( nHandicap ) { - m_PID = nPID; - m_DownloadStatus = nDownloadStatus; - m_SlotStatus = nSlotStatus; - m_Computer = nComputer; - m_Team = nTeam; - m_Colour = nColour; - m_Race = nRace; - m_ComputerType = nComputerType; - m_Handicap = nHandicap; + } CGameSlot :: ~CGameSlot( ) diff --git a/ghost/gameslot.h b/ghost/gameslot.h index 5b1fd61..476bfab 100644 --- a/ghost/gameslot.h +++ b/ghost/gameslot.h @@ -30,7 +30,7 @@ #define SLOTRACE_NIGHTELF 4 #define SLOTRACE_UNDEAD 8 #define SLOTRACE_RANDOM 32 -#define SLOTRACE_FIXED 64 +#define SLOTRACE_SELECTABLE 64 #define SLOTCOMP_EASY 0 #define SLOTCOMP_NORMAL 1 @@ -49,7 +49,7 @@ class CGameSlot unsigned char m_Computer; // computer (0 = no, 1 = yes) unsigned char m_Team; // team unsigned char m_Colour; // colour - unsigned char m_Race; // race (1 = human, 2 = orc, 4 = night elf, 8 = undead, 32 = random, 64 = fixed) + unsigned char m_Race; // race (1 = human, 2 = orc, 4 = night elf, 8 = undead, 32 = random, 64 = selectable) unsigned char m_ComputerType; // computer type (0 = easy, 1 = human or normal comp, 2 = hard comp) unsigned char m_Handicap; // handicap diff --git a/ghost/ghost.cpp b/ghost/ghost.cpp index 50f5a43..72a0f23 100644 --- a/ghost/ghost.cpp +++ b/ghost/ghost.cpp @@ -221,7 +221,7 @@ void DEBUG_Print( BYTEARRAY b ) { cout << "{ "; - for( unsigned int i = 0; i < b.size( ); i++ ) + for( unsigned int i = 0; i < b.size( ); ++i ) cout << hex << (int)b[i] << " "; cout << "}" << endl; @@ -233,6 +233,8 @@ void DEBUG_Print( BYTEARRAY b ) int main( int argc, char **argv ) { + srand( time( NULL ) ); + MessageLogger logger( *CONSOLE_Print ); gCFGFile = "ghost.cfg"; @@ -242,6 +244,7 @@ int main( int argc, char **argv ) // read config file CConfig CFG( &logger ); + CFG.Read( "ghost.cfg" ); CFG.Read( gCFGFile ); gLogFile = CFG.GetString( "bot_log", string( ) ); gLogMethod = CFG.GetInt( "bot_logmethod", 1 ); @@ -298,7 +301,7 @@ int main( int argc, char **argv ) unsigned int TimerResolution = 0; - for( unsigned int i = 1; i <= 5; i++ ) + for( unsigned int i = 1; i <= 5; ++i ) { if( timeBeginPeriod( i ) == TIMERR_NOERROR ) { @@ -447,7 +450,7 @@ CGHost :: CGHost( MessageLogger *logger, CConfig *CFG ) { int nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO); - for( int i = 0; i < nNumInterfaces; i++ ) + for( int i = 0; i < nNumInterfaces; ++i ) { sockaddr_in *pAddress; pAddress = (sockaddr_in *)&(InterfaceList[i].iiAddress); @@ -474,7 +477,7 @@ CGHost :: CGHost( MessageLogger *logger, CConfig *CFG ) CONSOLE_Print( "[GHOST] error finding local IP addresses - gethostbyname failed" ); else { - for( int i = 0; HostEnt->h_addr_list[i] != NULL; i++ ) + for( int i = 0; HostEnt->h_addr_list[i] != NULL; ++i ) { struct in_addr Address; memcpy( &Address, HostEnt->h_addr_list[i], sizeof(struct in_addr) ); @@ -489,7 +492,7 @@ CGHost :: CGHost( MessageLogger *logger, CConfig *CFG ) m_Exiting = false; m_ExitingNice = false; m_Enabled = true; - m_Version = "17.0"; + m_Version = "17.1"; m_HostCounter = 1; m_AutoHostMaximumGames = CFG->GetInt( "autohost_maxgames", 0 ); m_AutoHostAutoStartPlayers = CFG->GetInt( "autohost_startplayers", 0 ); @@ -524,7 +527,7 @@ CGHost :: CGHost( MessageLogger *logger, CConfig *CFG ) // load the battle.net connections // we're just loading the config data and creating the CBNET classes here, the connections are established later (in the Update function) - for( uint32_t i = 1; i < 10; i++ ) + for( uint32_t i = 1; i < 10; ++i ) { string Prefix; @@ -624,7 +627,7 @@ CGHost :: CGHost( MessageLogger *logger, CConfig *CFG ) // see CMap :: Load for more information ExtractScripts( ); - + if( m_DefaultMap.empty( ) ) SetEnabled( false ); @@ -702,20 +705,20 @@ CGHost :: ~CGHost( ) delete m_UDPSocket; delete m_ReconnectSocket; - for( vector :: iterator i = m_ReconnectSockets.begin( ); i != m_ReconnectSockets.end( ); i++ ) + for( vector :: iterator i = m_ReconnectSockets.begin( ); i != m_ReconnectSockets.end( ); ++i ) delete *i; delete m_GPSProtocol; delete m_CRC; delete m_SHA; - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) delete *i; delete m_CurrentGame; delete m_AdminGame; - for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); i++ ) + for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); ++i ) delete *i; delete m_DB; @@ -759,7 +762,7 @@ bool CGHost :: Update( long usecBlock ) { CONSOLE_Print( "[GHOST] deleting all battle.net connections in preparation for exiting nicely" ); - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) delete *i; m_BNETs.clear( ); @@ -816,7 +819,7 @@ bool CGHost :: Update( long usecBlock ) i = m_Callables.erase( i ); } else - i++; + ++i; } // create the GProxy++ reconnect listener @@ -858,7 +861,7 @@ bool CGHost :: Update( long usecBlock ) // 1. all battle.net sockets - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) NumFDs += (*i)->SetFD( &fd, &send_fd, &nfds ); // 2. the current game's server and player sockets @@ -873,7 +876,7 @@ bool CGHost :: Update( long usecBlock ) // 4. all running games' player sockets - for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); i++ ) + for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); ++i ) NumFDs += (*i)->SetFD( &fd, &send_fd, &nfds ); // 5. the GProxy++ reconnect socket(s) @@ -881,13 +884,13 @@ bool CGHost :: Update( long usecBlock ) if( m_Reconnect && m_ReconnectSocket ) { m_ReconnectSocket->SetFD( &fd, &send_fd, &nfds ); - NumFDs++; + ++NumFDs; } - for( vector :: iterator i = m_ReconnectSockets.begin( ); i != m_ReconnectSockets.end( ); i++ ) + for( vector :: iterator i = m_ReconnectSockets.begin( ); i != m_ReconnectSockets.end( ); ++i ) { (*i)->SetFD( &fd, &send_fd, &nfds ); - NumFDs++; + ++NumFDs; } // before we call select we need to determine how long to block for @@ -895,7 +898,7 @@ bool CGHost :: Update( long usecBlock ) // however, in an effort to make game updates happen closer to the desired latency setting we now use a dynamic block interval // note: we still use the passed usecBlock as a hard maximum - for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); i++ ) + for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); ++i ) { if( (*i)->GetNextTimedActionTicks( ) * 1000 < usecBlock ) usecBlock = (*i)->GetNextTimedActionTicks( ) * 1000; @@ -946,7 +949,7 @@ bool CGHost :: Update( long usecBlock ) delete m_CurrentGame; m_CurrentGame = NULL; - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { (*i)->QueueGameUncreate( ); (*i)->QueueEnterChat( ); @@ -985,13 +988,13 @@ bool CGHost :: Update( long usecBlock ) else { (*i)->UpdatePost( &send_fd ); - i++; + ++i; } } // update battle.net connections - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( (*i)->Update( &fd, &send_fd ) ) BNETExit = true; @@ -1044,7 +1047,7 @@ bool CGHost :: Update( long usecBlock ) CGamePlayer *Match = NULL; - for( vector :: iterator j = m_Games.begin( ); j != m_Games.end( ); j++ ) + for( vector :: iterator j = m_Games.begin( ); j != m_Games.end( ); ++j ) { if( (*j)->GetGameLoaded( ) ) { @@ -1106,7 +1109,7 @@ bool CGHost :: Update( long usecBlock ) } (*i)->DoSend( &send_fd ); - i++; + ++i; } // autohost @@ -1134,8 +1137,8 @@ bool CGHost :: Update( long usecBlock ) { if( !m_Map->GetMapMatchMakingCategory( ).empty( ) ) { - if( m_Map->GetMapGameType( ) != GAMETYPE_CUSTOM ) - CONSOLE_Print( "[GHOST] autohostmm - map_matchmakingcategory [" + m_Map->GetMapMatchMakingCategory( ) + "] found but matchmaking can only be used with custom maps, matchmaking disabled" ); + if( !( m_Map->GetMapOptions( ) & MAPOPT_FIXEDPLAYERSETTINGS ) ) + CONSOLE_Print( "[GHOST] autohostmm - map_matchmakingcategory [" + m_Map->GetMapMatchMakingCategory( ) + "] found but matchmaking can only be used with fixed player settings, matchmaking disabled" ); else { CONSOLE_Print( "[GHOST] autohostmm - map_matchmakingcategory [" + m_Map->GetMapMatchMakingCategory( ) + "] found, matchmaking enabled" ); @@ -1232,7 +1235,7 @@ void CGHost :: EventBNETGameRefreshFailed( CBNET *bnet ) { if( m_CurrentGame ) { - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { (*i)->QueueChatCommand( m_Language->UnableToCreateGameTryAnotherName( bnet->GetServer( ), m_CurrentGame->GetGameName( ) ) ); @@ -1274,7 +1277,7 @@ void CGHost :: EventBNETWhisper( CBNET *bnet, string user, string message ) if( m_CurrentGame ) m_CurrentGame->SendLocalAdminChat( "[W: " + bnet->GetServerAlias( ) + "] [" + user + "] " + message ); - for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); i++ ) + for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); ++i ) (*i)->SendLocalAdminChat( "[W: " + bnet->GetServerAlias( ) + "] [" + user + "] " + message ); } } @@ -1288,7 +1291,7 @@ void CGHost :: EventBNETChat( CBNET *bnet, string user, string message ) if( m_CurrentGame ) m_CurrentGame->SendLocalAdminChat( "[L: " + bnet->GetServerAlias( ) + "] [" + user + "] " + message ); - for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); i++ ) + for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); ++i ) (*i)->SendLocalAdminChat( "[L: " + bnet->GetServerAlias( ) + "] [" + user + "] " + message ); } } @@ -1302,14 +1305,14 @@ void CGHost :: EventBNETEmote( CBNET *bnet, string user, string message ) if( m_CurrentGame ) m_CurrentGame->SendLocalAdminChat( "[E: " + bnet->GetServerAlias( ) + "] [" + user + "] " + message ); - for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); i++ ) + for( vector :: iterator i = m_Games.begin( ); i != m_Games.end( ); ++i ) (*i)->SendLocalAdminChat( "[E: " + bnet->GetServerAlias( ) + "] [" + user + "] " + message ); } } void CGHost :: EventGameDeleted( CBaseGame *game ) { - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { (*i)->QueueChatCommand( m_Language->GameIsOver( game->GetDescription( ) ) ); @@ -1321,6 +1324,7 @@ void CGHost :: EventGameDeleted( CBaseGame *game ) void CGHost :: ReloadConfigs( ) { CConfig CFG( this ); + CFG.Read( "ghost.cfg" ); CFG.Read( gCFGFile ); SetConfigs( &CFG ); } @@ -1533,7 +1537,7 @@ void CGHost :: CreateGame( CMap *map, unsigned char gameState, bool saveGame, st { if( !m_Enabled ) { - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == creatorServer ) (*i)->QueueChatCommand( m_Language->UnableToCreateGameDisabled( gameName ), creatorName, whisper ); @@ -1547,7 +1551,7 @@ void CGHost :: CreateGame( CMap *map, unsigned char gameState, bool saveGame, st if( gameName.size( ) > 31 ) { - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == creatorServer ) (*i)->QueueChatCommand( m_Language->UnableToCreateGameNameTooLong( gameName ), creatorName, whisper ); @@ -1561,7 +1565,7 @@ void CGHost :: CreateGame( CMap *map, unsigned char gameState, bool saveGame, st if( !map->GetValid( ) ) { - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == creatorServer ) (*i)->QueueChatCommand( m_Language->UnableToCreateGameInvalidMap( gameName ), creatorName, whisper ); @@ -1577,7 +1581,7 @@ void CGHost :: CreateGame( CMap *map, unsigned char gameState, bool saveGame, st { if( !m_SaveGame->GetValid( ) ) { - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == creatorServer ) (*i)->QueueChatCommand( m_Language->UnableToCreateGameInvalidSaveGame( gameName ), creatorName, whisper ); @@ -1598,7 +1602,7 @@ void CGHost :: CreateGame( CMap *map, unsigned char gameState, bool saveGame, st { CONSOLE_Print( "[GHOST] path mismatch, saved game path is [" + MapPath1 + "] but map path is [" + MapPath2 + "]" ); - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == creatorServer ) (*i)->QueueChatCommand( m_Language->UnableToCreateGameSaveGameMapMismatch( gameName ), creatorName, whisper ); @@ -1612,7 +1616,7 @@ void CGHost :: CreateGame( CMap *map, unsigned char gameState, bool saveGame, st if( m_EnforcePlayers.empty( ) ) { - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == creatorServer ) (*i)->QueueChatCommand( m_Language->UnableToCreateGameMustEnforceFirst( gameName ), creatorName, whisper ); @@ -1627,7 +1631,7 @@ void CGHost :: CreateGame( CMap *map, unsigned char gameState, bool saveGame, st if( m_CurrentGame ) { - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == creatorServer ) (*i)->QueueChatCommand( m_Language->UnableToCreateGameAnotherGameInLobby( gameName, m_CurrentGame->GetDescription( ) ), creatorName, whisper ); @@ -1641,7 +1645,7 @@ void CGHost :: CreateGame( CMap *map, unsigned char gameState, bool saveGame, st if( m_Games.size( ) >= m_MaxGames ) { - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( (*i)->GetServer( ) == creatorServer ) (*i)->QueueChatCommand( m_Language->UnableToCreateGameMaxGamesReached( gameName, UTIL_ToString( m_MaxGames ) ), creatorName, whisper ); @@ -1668,7 +1672,7 @@ void CGHost :: CreateGame( CMap *map, unsigned char gameState, bool saveGame, st m_EnforcePlayers.clear( ); } - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( whisper && (*i)->GetServer( ) == creatorServer ) { @@ -1709,7 +1713,7 @@ void CGHost :: CreateGame( CMap *map, unsigned char gameState, bool saveGame, st if( gameState == GAME_PRIVATE ) { - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( (*i)->GetPasswordHashType( ) != "pvpgn" ) (*i)->QueueEnterChat( ); @@ -1718,7 +1722,7 @@ void CGHost :: CreateGame( CMap *map, unsigned char gameState, bool saveGame, st // hold friends and/or clan members - for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); i++ ) + for( vector :: iterator i = m_BNETs.begin( ); i != m_BNETs.end( ); ++i ) { if( (*i)->GetHoldFriends( ) ) (*i)->HoldFriends( m_CurrentGame ); diff --git a/ghost/ghostdb.cpp b/ghost/ghostdb.cpp index d38062e..96c8bea 100644 --- a/ghost/ghostdb.cpp +++ b/ghost/ghostdb.cpp @@ -27,10 +27,9 @@ // CGHostDB // -CGHostDB :: CGHostDB( MessageLogger *logger, CConfig *CFG ) - : MessageLogger( logger ) +CGHostDB :: CGHostDB( MessageLogger *logger, CConfig *CFG ) : m_HasError( false ), MessageLogger( logger ) { - m_HasError = false; + } CGHostDB :: ~CGHostDB( ) @@ -422,15 +421,9 @@ CCallableW3MMDVarAdd :: ~CCallableW3MMDVarAdd( ) // CDBBan // -CDBBan :: CDBBan( string nServer, string nName, string nIP, string nDate, string nGameName, string nAdmin, string nReason ) +CDBBan :: CDBBan( string nServer, string nName, string nIP, string nDate, string nGameName, string nAdmin, string nReason ) : m_Server( nServer ), m_Name( nName ), m_IP( nIP ), m_Date( nDate ), m_GameName( nGameName ), m_Admin( nAdmin ), m_Reason( nReason ) { - m_Server = nServer; - m_Name = nName; - m_IP = nIP; - m_Date = nDate; - m_GameName = nGameName; - m_Admin = nAdmin; - m_Reason = nReason; + } CDBBan :: ~CDBBan( ) @@ -442,15 +435,9 @@ CDBBan :: ~CDBBan( ) // CDBGame // -CDBGame :: CDBGame( uint32_t nID, string nServer, string nMap, string nDateTime, string nGameName, string nOwnerName, uint32_t nDuration ) +CDBGame :: CDBGame( uint32_t nID, string nServer, string nMap, string nDateTime, string nGameName, string nOwnerName, uint32_t nDuration ) : m_ID( nID ), m_Server( nServer ), m_Map( nMap ), m_DateTime( nDateTime ), m_GameName( nGameName ), m_OwnerName( nOwnerName ), m_Duration( nDuration ) { - m_ID = nID; - m_Server = nServer; - m_Map = nMap; - m_DateTime = nDateTime; - m_GameName = nGameName; - m_OwnerName = nOwnerName; - m_Duration = nDuration; + } CDBGame :: ~CDBGame( ) @@ -463,19 +450,9 @@ CDBGame :: ~CDBGame( ) // CDBGamePlayer :: CDBGamePlayer( uint32_t nID, uint32_t nGameID, string nName, string nIP, uint32_t nSpoofed, string nSpoofedRealm, uint32_t nReserved, uint32_t nLoadingTime, uint32_t nLeft, string nLeftReason, uint32_t nTeam, uint32_t nColour ) + : m_ID( nID ), m_GameID( nGameID ), m_Name( nName ), m_IP( nIP ), m_Spoofed( nSpoofed ), m_SpoofedRealm( nSpoofedRealm ), m_Reserved( nReserved ), m_LoadingTime( nLoadingTime ), m_Left( nLeft ), m_LeftReason( nLeftReason ), m_Team( nTeam ), m_Colour( nColour ) { - m_ID = nID; - m_GameID = nGameID; - m_Name = nName; - m_IP = nIP; - m_Spoofed = nSpoofed; - m_SpoofedRealm = nSpoofedRealm; - m_Reserved = nReserved; - m_LoadingTime = nLoadingTime; - m_Left = nLeft; - m_LeftReason = nLeftReason; - m_Team = nTeam; - m_Colour = nColour; + } CDBGamePlayer :: ~CDBGamePlayer( ) @@ -488,21 +465,9 @@ CDBGamePlayer :: ~CDBGamePlayer( ) // CDBGamePlayerSummary :: CDBGamePlayerSummary( string nServer, string nName, string nFirstGameDateTime, string nLastGameDateTime, uint32_t nTotalGames, uint32_t nMinLoadingTime, uint32_t nAvgLoadingTime, uint32_t nMaxLoadingTime, uint32_t nMinLeftPercent, uint32_t nAvgLeftPercent, uint32_t nMaxLeftPercent, uint32_t nMinDuration, uint32_t nAvgDuration, uint32_t nMaxDuration ) + : m_Server( nServer ), m_Name( nName ), m_FirstGameDateTime( nFirstGameDateTime ), m_LastGameDateTime( nLastGameDateTime ), m_TotalGames( nTotalGames ), m_MinLoadingTime( nMinLoadingTime ), m_AvgLoadingTime( nAvgLoadingTime ), m_MaxLoadingTime( nMaxLoadingTime ), m_MinLeftPercent( nMinLeftPercent ), m_AvgLeftPercent( nAvgLeftPercent ), m_MaxLeftPercent( nMaxLeftPercent ), m_MinDuration( nMinDuration ), m_AvgDuration( nAvgDuration ), m_MaxDuration( nMaxDuration ) { - m_Server = nServer; - m_Name = nName; - m_FirstGameDateTime = nFirstGameDateTime; - m_LastGameDateTime = nLastGameDateTime; - m_TotalGames = nTotalGames; - m_MinLoadingTime = nMinLoadingTime; - m_AvgLoadingTime = nAvgLoadingTime; - m_MaxLoadingTime = nMaxLoadingTime; - m_MinLeftPercent = nMinLeftPercent; - m_AvgLeftPercent = nAvgLeftPercent; - m_MaxLeftPercent = nMaxLeftPercent; - m_MinDuration = nMinDuration; - m_AvgDuration = nAvgDuration; - m_MaxDuration = nMaxDuration; + } CDBGamePlayerSummary :: ~CDBGamePlayerSummary( ) @@ -514,13 +479,9 @@ CDBGamePlayerSummary :: ~CDBGamePlayerSummary( ) // CDBDotAGame // -CDBDotAGame :: CDBDotAGame( uint32_t nID, uint32_t nGameID, uint32_t nWinner, uint32_t nMin, uint32_t nSec ) +CDBDotAGame :: CDBDotAGame( uint32_t nID, uint32_t nGameID, uint32_t nWinner, uint32_t nMin, uint32_t nSec ) : m_ID( nID ), m_GameID( nGameID ), m_Winner( nWinner ), m_Min( nMin ), m_Sec( nSec ) { - m_ID = nID; - m_GameID = nGameID; - m_Winner = nWinner; - m_Min = nMin; - m_Sec = nSec; + } CDBDotAGame :: ~CDBDotAGame( ) @@ -532,47 +493,20 @@ CDBDotAGame :: ~CDBDotAGame( ) // CDBDotAPlayer // -CDBDotAPlayer :: CDBDotAPlayer( ) +CDBDotAPlayer :: CDBDotAPlayer( ) : m_ID( 0 ), m_GameID( 0 ), m_Colour( 0 ), m_Kills( 0 ), m_Deaths( 0 ), m_CreepKills( 0 ), m_CreepDenies( 0 ), m_Assists( 0 ), m_Gold( 0 ), m_NeutralKills( 0 ), m_NewColour( 0 ), m_TowerKills( 0 ), m_RaxKills( 0 ), m_CourierKills( 0 ) { - m_ID = 0; - m_GameID = 0; - m_Colour = 0; - m_Kills = 0; - m_Deaths = 0; - m_CreepKills = 0; - m_CreepDenies = 0; - m_Assists = 0; - m_Gold = 0; - m_NeutralKills = 0; - m_NewColour = 0; - m_TowerKills = 0; - m_RaxKills = 0; - m_CourierKills = 0; + } CDBDotAPlayer :: CDBDotAPlayer( uint32_t nID, uint32_t nGameID, uint32_t nColour, uint32_t nKills, uint32_t nDeaths, uint32_t nCreepKills, uint32_t nCreepDenies, uint32_t nAssists, uint32_t nGold, uint32_t nNeutralKills, string nItem1, string nItem2, string nItem3, string nItem4, string nItem5, string nItem6, string nHero, uint32_t nNewColour, uint32_t nTowerKills, uint32_t nRaxKills, uint32_t nCourierKills ) + : m_ID( nID ), m_GameID( nGameID ), m_Colour( nColour ), m_Kills( nKills ), m_Deaths( nDeaths ), m_CreepKills( nCreepKills ), m_CreepDenies( nCreepDenies ), m_Assists( nAssists ), m_Gold( nGold ), m_NeutralKills( nNeutralKills ), m_Hero( nHero ), m_NewColour( nNewColour ), m_TowerKills( nTowerKills ), m_RaxKills( nRaxKills ), m_CourierKills( nCourierKills ) { - m_ID = nID; - m_GameID = nGameID; - m_Colour = nColour; - m_Kills = nKills; - m_Deaths = nDeaths; - m_CreepKills = nCreepKills; - m_CreepDenies = nCreepDenies; - m_Assists = nAssists; - m_Gold = nGold; - m_NeutralKills = nNeutralKills; m_Items[0] = nItem1; m_Items[1] = nItem2; m_Items[2] = nItem3; m_Items[3] = nItem4; m_Items[4] = nItem5; m_Items[5] = nItem6; - m_Hero = nHero; - m_NewColour = nNewColour; - m_TowerKills = nTowerKills; - m_RaxKills = nRaxKills; - m_CourierKills = nCourierKills; } CDBDotAPlayer :: ~CDBDotAPlayer( ) @@ -598,22 +532,9 @@ void CDBDotAPlayer :: SetItem( unsigned int i, string item ) // CDBDotAPlayerSummary // -CDBDotAPlayerSummary :: CDBDotAPlayerSummary( string nServer, string nName, uint32_t nTotalGames, uint32_t nTotalWins, uint32_t nTotalLosses, uint32_t nTotalKills, uint32_t nTotalDeaths, uint32_t nTotalCreepKills, uint32_t nTotalCreepDenies, uint32_t nTotalAssists, uint32_t nTotalNeutralKills, uint32_t nTotalTowerKills, uint32_t nTotalRaxKills, uint32_t nTotalCourierKills ) -{ - m_Server = nServer; - m_Name = nName; - m_TotalGames = nTotalGames; - m_TotalWins = nTotalWins; - m_TotalLosses = nTotalLosses; - m_TotalKills = nTotalKills; - m_TotalDeaths = nTotalDeaths; - m_TotalCreepKills = nTotalCreepKills; - m_TotalCreepDenies = nTotalCreepDenies; - m_TotalAssists = nTotalAssists; - m_TotalNeutralKills = nTotalNeutralKills; - m_TotalTowerKills = nTotalTowerKills; - m_TotalRaxKills = nTotalRaxKills; - m_TotalCourierKills = nTotalCourierKills; +CDBDotAPlayerSummary :: CDBDotAPlayerSummary( string nServer, string nName, uint32_t nTotalGames, uint32_t nTotalWins, uint32_t nTotalLosses, uint32_t nTotalKills, uint32_t nTotalDeaths, uint32_t nTotalCreepKills, uint32_t nTotalCreepDenies, uint32_t nTotalAssists, uint32_t nTotalNeutralKills, uint32_t nTotalTowerKills, uint32_t nTotalRaxKills, uint32_t nTotalCourierKills ) : m_Server( nServer ), m_Name( nName ), m_TotalGames( nTotalGames ), m_TotalWins( nTotalWins ), m_TotalLosses( nTotalLosses ), m_TotalKills( nTotalKills ), m_TotalDeaths( nTotalDeaths ), m_TotalCreepKills( nTotalCreepKills ), m_TotalCreepDenies( nTotalCreepDenies ), m_TotalAssists( nTotalAssists ), m_TotalNeutralKills( nTotalNeutralKills ), m_TotalTowerKills( nTotalTowerKills ), m_TotalRaxKills( nTotalRaxKills ), m_TotalCourierKills( nTotalCourierKills ) +{ + } CDBDotAPlayerSummary :: ~CDBDotAPlayerSummary( ) diff --git a/ghost/ghostdbmysql.cpp b/ghost/ghostdbmysql.cpp index 2c902f5..8c90b62 100644 --- a/ghost/ghostdbmysql.cpp +++ b/ghost/ghostdbmysql.cpp @@ -109,7 +109,7 @@ void CGHostDBMySQL :: RecoverCallable( CBaseCallable *callable ) if( m_IdleConnections.size( ) > 30 ) { mysql_close( (MYSQL *)MySQLCallable->GetConnection( ) ); - m_NumConnections--; + --m_NumConnections; } else m_IdleConnections.push( MySQLCallable->GetConnection( ) ); @@ -117,7 +117,7 @@ void CGHostDBMySQL :: RecoverCallable( CBaseCallable *callable ) if( m_OutstandingCallables == 0 ) CONSOLE_Print( "[MYSQL] recovered a mysql callable with zero outstanding" ); else - m_OutstandingCallables--; + --m_OutstandingCallables; if( !MySQLCallable->GetError( ).empty( ) ) CONSOLE_Print( "[MYSQL] error --- " + MySQLCallable->GetError( ) ); @@ -154,11 +154,11 @@ CCallableAdminCount *CGHostDBMySQL :: ThreadedAdminCount( string server ) void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableAdminCount *Callable = new CMySQLCallableAdminCount( server, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -167,11 +167,11 @@ CCallableAdminCheck *CGHostDBMySQL :: ThreadedAdminCheck( string server, string void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableAdminCheck *Callable = new CMySQLCallableAdminCheck( server, user, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -180,11 +180,11 @@ CCallableAdminAdd *CGHostDBMySQL :: ThreadedAdminAdd( string server, string user void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableAdminAdd *Callable = new CMySQLCallableAdminAdd( server, user, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -193,11 +193,11 @@ CCallableAdminRemove *CGHostDBMySQL :: ThreadedAdminRemove( string server, strin void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableAdminRemove *Callable = new CMySQLCallableAdminRemove( server, user, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -206,11 +206,11 @@ CCallableAdminList *CGHostDBMySQL :: ThreadedAdminList( string server ) void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableAdminList *Callable = new CMySQLCallableAdminList( server, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -219,11 +219,11 @@ CCallableBanCount *CGHostDBMySQL :: ThreadedBanCount( string server ) void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableBanCount *Callable = new CMySQLCallableBanCount( server, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -232,11 +232,11 @@ CCallableBanCheck *CGHostDBMySQL :: ThreadedBanCheck( string server, string user void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableBanCheck *Callable = new CMySQLCallableBanCheck( server, user, ip, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -245,11 +245,11 @@ CCallableBanAdd *CGHostDBMySQL :: ThreadedBanAdd( string server, string user, st void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableBanAdd *Callable = new CMySQLCallableBanAdd( server, user, ip, gamename, admin, reason, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -258,11 +258,11 @@ CCallableBanRemove *CGHostDBMySQL :: ThreadedBanRemove( string server, string us void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableBanRemove *Callable = new CMySQLCallableBanRemove( server, user, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -271,11 +271,11 @@ CCallableBanRemove *CGHostDBMySQL :: ThreadedBanRemove( string user ) void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableBanRemove *Callable = new CMySQLCallableBanRemove( string( ), user, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -284,11 +284,11 @@ CCallableBanList *CGHostDBMySQL :: ThreadedBanList( string server ) void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableBanList *Callable = new CMySQLCallableBanList( server, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -297,11 +297,11 @@ CCallableGameAdd *CGHostDBMySQL :: ThreadedGameAdd( string server, string map, s void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableGameAdd *Callable = new CMySQLCallableGameAdd( server, map, gamename, ownername, duration, gamestate, creatorname, creatorserver, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -310,11 +310,11 @@ CCallableGamePlayerAdd *CGHostDBMySQL :: ThreadedGamePlayerAdd( uint32_t gameid, void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableGamePlayerAdd *Callable = new CMySQLCallableGamePlayerAdd( gameid, name, ip, spoofed, spoofedrealm, reserved, loadingtime, left, leftreason, team, colour, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -323,11 +323,11 @@ CCallableGamePlayerSummaryCheck *CGHostDBMySQL :: ThreadedGamePlayerSummaryCheck void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableGamePlayerSummaryCheck *Callable = new CMySQLCallableGamePlayerSummaryCheck( name, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -336,11 +336,11 @@ CCallableDotAGameAdd *CGHostDBMySQL :: ThreadedDotAGameAdd( uint32_t gameid, uin void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableDotAGameAdd *Callable = new CMySQLCallableDotAGameAdd( gameid, winner, min, sec, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -349,11 +349,11 @@ CCallableDotAPlayerAdd *CGHostDBMySQL :: ThreadedDotAPlayerAdd( uint32_t gameid, void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableDotAPlayerAdd *Callable = new CMySQLCallableDotAPlayerAdd( gameid, colour, kills, deaths, creepkills, creepdenies, assists, gold, neutralkills, item1, item2, item3, item4, item5, item6, hero, newcolour, towerkills, raxkills, courierkills, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -362,11 +362,11 @@ CCallableDotAPlayerSummaryCheck *CGHostDBMySQL :: ThreadedDotAPlayerSummaryCheck void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableDotAPlayerSummaryCheck *Callable = new CMySQLCallableDotAPlayerSummaryCheck( name, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -375,11 +375,11 @@ CCallableDownloadAdd *CGHostDBMySQL :: ThreadedDownloadAdd( string map, uint32_t void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableDownloadAdd *Callable = new CMySQLCallableDownloadAdd( map, mapsize, name, ip, spoofed, spoofedrealm, downloadtime, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -388,11 +388,11 @@ CCallableScoreCheck *CGHostDBMySQL :: ThreadedScoreCheck( string category, strin void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableScoreCheck *Callable = new CMySQLCallableScoreCheck( category, name, server, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -401,11 +401,11 @@ CCallableW3MMDPlayerAdd *CGHostDBMySQL :: ThreadedW3MMDPlayerAdd( string categor void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableW3MMDPlayerAdd *Callable = new CMySQLCallableW3MMDPlayerAdd( category, gameid, pid, name, flag, leaver, practicing, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -414,11 +414,11 @@ CCallableW3MMDVarAdd *CGHostDBMySQL :: ThreadedW3MMDVarAdd( uint32_t gameid, map void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableW3MMDVarAdd *Callable = new CMySQLCallableW3MMDVarAdd( gameid, var_ints, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -427,11 +427,11 @@ CCallableW3MMDVarAdd *CGHostDBMySQL :: ThreadedW3MMDVarAdd( uint32_t gameid, map void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableW3MMDVarAdd *Callable = new CMySQLCallableW3MMDVarAdd( gameid, var_reals, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -440,11 +440,11 @@ CCallableW3MMDVarAdd *CGHostDBMySQL :: ThreadedW3MMDVarAdd( uint32_t gameid, map void *Connection = GetIdleConnection( ); if( !Connection ) - m_NumConnections++; + ++m_NumConnections; CCallableW3MMDVarAdd *Callable = new CMySQLCallableW3MMDVarAdd( gameid, var_strings, Connection, m_BotID, m_Server, m_Database, m_User, m_Password, m_Port ); CreateThread( Callable ); - m_OutstandingCallables++; + ++m_OutstandingCallables; return Callable; } @@ -485,7 +485,7 @@ vector MySQLFetchRow( MYSQL_RES *res ) unsigned long *Lengths; Lengths = mysql_fetch_lengths( res ); - for( unsigned int i = 0; i < mysql_num_fields( res ); i++ ) + for( unsigned int i = 0; i < mysql_num_fields( res ); ++i ) { if( Row[i] ) Result.push_back( string( Row[i], Lengths[i] ) ); @@ -1066,7 +1066,7 @@ bool MySQLW3MMDVarAdd( void *conn, string *error, uint32_t botid, uint32_t gamei bool Success = false; string Query; - for( map :: iterator i = var_ints.begin( ); i != var_ints.end( ); i++ ) + for( map :: iterator i = var_ints.begin( ); i != var_ints.end( ); ++i ) { string EscVarName = MySQLEscapeString( conn, i->first.second ); @@ -1092,7 +1092,7 @@ bool MySQLW3MMDVarAdd( void *conn, string *error, uint32_t botid, uint32_t gamei bool Success = false; string Query; - for( map :: iterator i = var_reals.begin( ); i != var_reals.end( ); i++ ) + for( map :: iterator i = var_reals.begin( ); i != var_reals.end( ); ++i ) { string EscVarName = MySQLEscapeString( conn, i->first.second ); @@ -1118,7 +1118,7 @@ bool MySQLW3MMDVarAdd( void *conn, string *error, uint32_t botid, uint32_t gamei bool Success = false; string Query; - for( map :: iterator i = var_strings.begin( ); i != var_strings.end( ); i++ ) + for( map :: iterator i = var_strings.begin( ); i != var_strings.end( ); ++i ) { string EscVarName = MySQLEscapeString( conn, i->first.second ); string EscValueString = MySQLEscapeString( conn, i->second ); diff --git a/ghost/ghostdbsqlite.cpp b/ghost/ghostdbsqlite.cpp index 5bdd8b6..97ea479 100644 --- a/ghost/ghostdbsqlite.cpp +++ b/ghost/ghostdbsqlite.cpp @@ -60,7 +60,7 @@ int CSQLITE3 :: Step( void *Statement ) { m_Row.clear( ); - for( int i = 0; i < sqlite3_column_count( (sqlite3_stmt *)Statement ); i++ ) + for( int i = 0; i < sqlite3_column_count( (sqlite3_stmt *)Statement ); ++i ) { char *ColumnText = (char *)sqlite3_column_text( (sqlite3_stmt *)Statement, i ); @@ -1344,7 +1344,7 @@ bool CGHostDBSQLite :: W3MMDVarAdd( uint32_t gameid, map var_ints bool Success = true; sqlite3_stmt *Statement = NULL; - for( map :: iterator i = var_ints.begin( ); i != var_ints.end( ); i++ ) + for( map :: iterator i = var_ints.begin( ); i != var_ints.end( ); ++i ) { if( !Statement ) m_DB->Prepare( "INSERT INTO w3mmdvars ( gameid, pid, varname, value_int ) VALUES ( ?, ?, ?, ? )", (void **)&Statement ); @@ -1389,7 +1389,7 @@ bool CGHostDBSQLite :: W3MMDVarAdd( uint32_t gameid, map var_reals bool Success = true; sqlite3_stmt *Statement = NULL; - for( map :: iterator i = var_reals.begin( ); i != var_reals.end( ); i++ ) + for( map :: iterator i = var_reals.begin( ); i != var_reals.end( ); ++i ) { if( !Statement ) m_DB->Prepare( "INSERT INTO w3mmdvars ( gameid, pid, varname, value_real ) VALUES ( ?, ?, ?, ? )", (void **)&Statement ); @@ -1434,7 +1434,7 @@ bool CGHostDBSQLite :: W3MMDVarAdd( uint32_t gameid, map var_string bool Success = true; sqlite3_stmt *Statement = NULL; - for( map :: iterator i = var_strings.begin( ); i != var_strings.end( ); i++ ) + for( map :: iterator i = var_strings.begin( ); i != var_strings.end( ); ++i ) { if( !Statement ) m_DB->Prepare( "INSERT INTO w3mmdvars ( gameid, pid, varname, value_string ) VALUES ( ?, ?, ?, ? )", (void **)&Statement ); diff --git a/ghost/map.cpp b/ghost/map.cpp index 97d2c5d..48d00df 100644 --- a/ghost/map.cpp +++ b/ghost/map.cpp @@ -35,45 +35,36 @@ // CMap // -CMap :: CMap( CGHost *nGHost ) - : MessageLogger( nGHost ) +CMap :: CMap( CGHost *nGHost ) + : m_GHost( nGHost ), m_Valid( true ), m_MapPath( "Maps\\FrozenThrone\\(12)EmeraldGardens.w3x" ), m_MapSpeed( MAPSPEED_FAST ), + m_MapVisibility( MAPVIS_DEFAULT ), m_MapObservers( MAPOBS_NONE ), m_MapFlags( MAPFLAG_TEAMSTOGETHER | MAPFLAG_FIXEDTEAMS ), + m_MapFilterMaker( MAPFILTER_MAKER_BLIZZARD ), m_MapFilterType( MAPFILTER_TYPE_MELEE ), m_MapFilterSize( MAPFILTER_SIZE_LARGE ), + m_MapFilterObs( MAPFILTER_OBS_NONE ), m_MapOptions( MAPOPT_MELEE ), m_MapLoadInGame( false ), m_MapNumPlayers( 12 ), m_MapNumTeams( 12 ), MessageLogger( nGHost ) { CONSOLE_Print( "[MAP] using hardcoded Emerald Gardens map data for Warcraft 3 version 1.24 & 1.24b" ); - m_GHost = nGHost; - m_Valid = true; - m_MapPath = "Maps\\FrozenThrone\\(12)EmeraldGardens.w3x"; m_MapSize = UTIL_ExtractNumbers( "174 221 4 0", 4 ); m_MapInfo = UTIL_ExtractNumbers( "251 57 68 98", 4 ); m_MapCRC = UTIL_ExtractNumbers( "108 250 204 59", 4 ); m_MapSHA1 = UTIL_ExtractNumbers( "35 81 104 182 223 63 204 215 1 17 87 234 220 66 3 185 82 99 6 13", 20 ); - m_MapSpeed = MAPSPEED_FAST; - m_MapVisibility = MAPVIS_DEFAULT; - m_MapObservers = MAPOBS_NONE; - m_MapFlags = MAPFLAG_TEAMSTOGETHER | MAPFLAG_FIXEDTEAMS; - m_MapGameType = 9; m_MapWidth = UTIL_ExtractNumbers( "172 0", 2 ); m_MapHeight = UTIL_ExtractNumbers( "172 0", 2 ); - m_MapLoadInGame = false; - m_MapNumPlayers = 12; - m_MapNumTeams = 12; - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 0, 0, SLOTRACE_RANDOM ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 1, 1, SLOTRACE_RANDOM ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 2, 2, SLOTRACE_RANDOM ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 3, 3, SLOTRACE_RANDOM ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 4, 4, SLOTRACE_RANDOM ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 5, 5, SLOTRACE_RANDOM ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 6, 6, SLOTRACE_RANDOM ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 7, 7, SLOTRACE_RANDOM ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 8, 8, SLOTRACE_RANDOM ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 9, 9, SLOTRACE_RANDOM ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 10, 10, SLOTRACE_RANDOM ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 11, 11, SLOTRACE_RANDOM ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 0, 0, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 1, 1, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 2, 2, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 3, 3, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 4, 4, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 5, 5, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 6, 6, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 7, 7, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 8, 8, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 9, 9, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 10, 10, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 11, 11, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); } -CMap :: CMap( CGHost *nGHost, CConfig *CFG, string nCFGFile ) - : MessageLogger( nGHost ) +CMap :: CMap( CGHost *nGHost, CConfig *CFG, string nCFGFile ) + : m_GHost( nGHost ), MessageLogger( nGHost ) { - m_GHost = nGHost; Load( CFG, nCFGFile ); } @@ -156,6 +147,97 @@ BYTEARRAY CMap :: GetMapGameFlags( ) return UTIL_CreateByteArray( GameFlags, false ); } +uint32_t CMap :: GetMapGameType( ) +{ + /* spec stolen from Strilanc as follows: + + Public Enum GameTypes As UInteger + None = 0 + Unknown0 = 1 << 0 '[always seems to be set?] + + '''Setting this bit causes wc3 to check the map and disc if it is not signed by Blizzard + AuthenticatedMakerBlizzard = 1 << 3 + OfficialMeleeGame = 1 << 5 + + SavedGame = 1 << 9 + PrivateGame = 1 << 11 + + MakerUser = 1 << 13 + MakerBlizzard = 1 << 14 + TypeMelee = 1 << 15 + TypeScenario = 1 << 16 + SizeSmall = 1 << 17 + SizeMedium = 1 << 18 + SizeLarge = 1 << 19 + ObsFull = 1 << 20 + ObsOnDeath = 1 << 21 + ObsNone = 1 << 22 + + MaskObs = ObsFull Or ObsOnDeath Or ObsNone + MaskMaker = MakerBlizzard Or MakerUser + MaskType = TypeMelee Or TypeScenario + MaskSize = SizeLarge Or SizeMedium Or SizeSmall + MaskFilterable = MaskObs Or MaskMaker Or MaskType Or MaskSize + End Enum + + */ + + // note: we allow "conflicting" flags to be set at the same time (who knows if this is a good idea) + // we also don't set any flags this class is unaware of such as Unknown0, SavedGame, and PrivateGame + + uint32_t GameType = 0; + + // maker + + if( m_MapFilterMaker & MAPFILTER_MAKER_USER ) + GameType |= MAPGAMETYPE_MAKERUSER; + if( m_MapFilterMaker & MAPFILTER_MAKER_BLIZZARD ) + GameType |= MAPGAMETYPE_MAKERBLIZZARD; + + // type + + if( m_MapFilterType & MAPFILTER_TYPE_MELEE ) + GameType |= MAPGAMETYPE_TYPEMELEE; + if( m_MapFilterType & MAPFILTER_TYPE_SCENARIO ) + GameType |= MAPGAMETYPE_TYPESCENARIO; + + // size + + if( m_MapFilterSize & MAPFILTER_SIZE_SMALL ) + GameType |= MAPGAMETYPE_SIZESMALL; + if( m_MapFilterSize & MAPFILTER_SIZE_MEDIUM ) + GameType |= MAPGAMETYPE_SIZEMEDIUM; + if( m_MapFilterSize & MAPFILTER_SIZE_LARGE ) + GameType |= MAPGAMETYPE_SIZELARGE; + + // obs + + if( m_MapFilterObs & MAPFILTER_OBS_FULL ) + GameType |= MAPGAMETYPE_OBSFULL; + if( m_MapFilterObs & MAPFILTER_OBS_ONDEATH ) + GameType |= MAPGAMETYPE_OBSONDEATH; + if( m_MapFilterObs & MAPFILTER_OBS_NONE ) + GameType |= MAPGAMETYPE_OBSNONE; + + return GameType; +} + +unsigned char CMap :: GetMapLayoutStyle( ) +{ + // 0 = melee + // 1 = custom forces + // 2 = fixed player settings (not possible with the Warcraft III map editor) + // 3 = custom forces + fixed player settings + + if( !( m_MapOptions & MAPOPT_CUSTOMFORCES ) ) + return 0; + + if( !( m_MapOptions & MAPOPT_FIXEDPLAYERSETTINGS ) ) + return 1; + + return 3; +} + void CMap :: Load( CConfig *CFG, string nCFGFile ) { m_Valid = true; @@ -318,7 +400,7 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) FileList.push_back( "war3map.w3q" ); bool FoundScript = false; - for( vector :: iterator i = FileList.begin( ); i != FileList.end( ); i++ ) + for( vector :: iterator i = FileList.begin( ); i != FileList.end( ); ++i ) { // don't use scripts\war3map.j if we've already used war3map.j (yes, some maps have both but only war3map.j is used) @@ -380,6 +462,7 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) // try to calculate map_width, map_height, map_slot, map_numplayers, map_numteams + uint32_t MapOptions = 0; BYTEARRAY MapWidth; BYTEARRAY MapHeight; uint32_t MapNumPlayers = 0; @@ -478,7 +561,7 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) ISS.read( (char *)&RawMapNumPlayers, 4 ); // number of players uint32_t ClosedSlots = 0; - for( uint32_t i = 0; i < RawMapNumPlayers; i++ ) + for( uint32_t i = 0; i < RawMapNumPlayers; ++i ) { CGameSlot Slot( 0, 255, SLOTSTATUS_OPEN, 0, 0, 1, SLOTRACE_RANDOM ); uint32_t Colour; @@ -500,7 +583,7 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) else { Slot.SetSlotStatus( SLOTSTATUS_CLOSED ); - ClosedSlots++; + ++ClosedSlots; } ISS.read( (char *)&Race, 4 ); // race @@ -529,7 +612,7 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) ISS.read( (char *)&RawMapNumTeams, 4 ); // number of teams - for( uint32_t i = 0; i < RawMapNumTeams; i++ ) + for( uint32_t i = 0; i < RawMapNumTeams; ++i ) { uint32_t Flags; uint32_t PlayerMask; @@ -537,11 +620,11 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) ISS.read( (char *)&Flags, 4 ); // flags ISS.read( (char *)&PlayerMask, 4 ); // player mask - for( unsigned char j = 0; j < 12; j++ ) + for( unsigned char j = 0; j < 12; ++j ) { if( PlayerMask & 1 ) { - for( vector :: iterator k = Slots.begin( ); k != Slots.end( ); k++ ) + for( vector :: iterator k = Slots.begin( ); k != Slots.end( ); ++k ) { if( (*k).GetColour( ) == j ) (*k).SetTeam( i ); @@ -554,6 +637,11 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) getline( ISS, GarbageString, '\0' ); // team name } + // the bot only cares about the following options: melee, fixed player settings, custom forces + // let's not confuse the user by displaying erroneous map options so zero them out now + + MapOptions = RawMapFlags & ( MAPOPT_MELEE | MAPOPT_FIXEDPLAYERSETTINGS | MAPOPT_CUSTOMFORCES ); + CONSOLE_Print( "[MAP] calculated map_options = " + UTIL_ToString( MapOptions ) ); MapWidth = UTIL_CreateByteArray( (uint16_t)RawMapWidth, false ); CONSOLE_Print( "[MAP] calculated map_width = " + UTIL_ByteArrayToDecString( MapWidth ) ); MapHeight = UTIL_CreateByteArray( (uint16_t)RawMapHeight, false ); @@ -565,15 +653,13 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) uint32_t SlotNum = 1; - for( vector :: iterator i = Slots.begin( ); i != Slots.end( ); i++ ) + for( vector :: iterator i = Slots.begin( ); i != Slots.end( ); ++i ) { CONSOLE_Print( "[MAP] calculated map_slot" + UTIL_ToString( SlotNum ) + " = " + UTIL_ByteArrayToDecString( (*i).GetByteArray( ) ) ); - SlotNum++; + ++SlotNum; } - // if it's a melee map... - - if( RawMapFlags & 4 ) + if( MapOptions & MAPOPT_MELEE ) { CONSOLE_Print( "[MAP] found melee map, initializing slots" ); @@ -581,16 +667,24 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) unsigned char Team = 0; - for( vector :: iterator i = Slots.begin( ); i != Slots.end( ); i++ ) + for( vector :: iterator i = Slots.begin( ); i != Slots.end( ); ++i ) { (*i).SetTeam( Team++ ); (*i).SetRace( SLOTRACE_RANDOM ); } } + + if( !( MapOptions & MAPOPT_FIXEDPLAYERSETTINGS ) ) + { + // make races selectable + + for( vector :: iterator i = Slots.begin( ); i != Slots.end( ); ++i ) + (*i).SetRace( (*i).GetRace( ) | SLOTRACE_SELECTABLE ); + } } } else - CONSOLE_Print( "[MAP] unable to calculate map_width, map_height, map_slot, map_numplayers, map_numteams - unable to extract war3map.w3i from MPQ file" ); + CONSOLE_Print( "[MAP] unable to calculate map_options, map_width, map_height, map_slot, map_numplayers, map_numteams - unable to extract war3map.w3i from MPQ file" ); delete [] SubFileData; } @@ -598,13 +692,13 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) SFileCloseFile( SubFile ); } else - CONSOLE_Print( "[MAP] unable to calculate map_width, map_height, map_slot, map_numplayers, map_numteams - couldn't find war3map.w3i in MPQ file" ); + CONSOLE_Print( "[MAP] unable to calculate map_options, map_width, map_height, map_slot, map_numplayers, map_numteams - couldn't find war3map.w3i in MPQ file" ); } else - CONSOLE_Print( "[MAP] unable to calculate map_width, map_height, map_slot, map_numplayers, map_numteams - map MPQ file not loaded" ); + CONSOLE_Print( "[MAP] unable to calculate map_options, map_width, map_height, map_slot, map_numplayers, map_numteams - map MPQ file not loaded" ); } else - CONSOLE_Print( "[MAP] no map data available, using config file for map_width, map_height, map_slot, map_numplayers, map_numteams" ); + CONSOLE_Print( "[MAP] no map data available, using config file for map_options, map_width, map_height, map_slot, map_numplayers, map_numteams" ); // close the map MPQ @@ -656,7 +750,22 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) m_MapVisibility = CFG->GetInt( "map_visibility", MAPVIS_DEFAULT ); m_MapObservers = CFG->GetInt( "map_observers", MAPOBS_NONE ); m_MapFlags = CFG->GetInt( "map_flags", MAPFLAG_TEAMSTOGETHER | MAPFLAG_FIXEDTEAMS ); - m_MapGameType = CFG->GetInt( "map_gametype", 1 ); + m_MapFilterMaker = CFG->GetInt( "map_filter_maker", MAPFILTER_MAKER_USER ); + m_MapFilterType = CFG->GetInt( "map_filter_type", 0 ); + m_MapFilterSize = CFG->GetInt( "map_filter_size", MAPFILTER_SIZE_LARGE ); + m_MapFilterObs = CFG->GetInt( "map_filter_obs", MAPFILTER_OBS_NONE ); + + // todotodo: it might be possible for MapOptions to legitimately be zero so this is not a valid way of checking if it wasn't parsed out earlier + + if( MapOptions == 0 ) + MapOptions = CFG->GetInt( "map_options", 0 ); + else if( CFG->Exists( "map_options" ) ) + { + CONSOLE_Print( "[MAP] overriding calculated map_options with config value map_options = " + CFG->GetString( "map_options", string( ) ) ); + MapOptions = CFG->GetInt( "map_options", 0 ); + } + + m_MapOptions = MapOptions; if( MapWidth.empty( ) ) MapWidth = UTIL_ExtractNumbers( CFG->GetString( "map_width", string( ) ), 2 ); @@ -706,7 +815,7 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) if( Slots.empty( ) ) { - for( uint32_t Slot = 1; Slot <= 12; Slot++ ) + for( uint32_t Slot = 1; Slot <= 12; ++Slot ) { string SlotString = CFG->GetString( "map_slot" + UTIL_ToString( Slot ), string( ) ); @@ -722,7 +831,7 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) CONSOLE_Print( "[MAP] overriding slots" ); Slots.clear( ); - for( uint32_t Slot = 1; Slot <= 12; Slot++ ) + for( uint32_t Slot = 1; Slot <= 12; ++Slot ) { string SlotString = CFG->GetString( "map_slot" + UTIL_ToString( Slot ), string( ) ); @@ -736,14 +845,14 @@ void CMap :: Load( CConfig *CFG, string nCFGFile ) m_Slots = Slots; - // if random races is set force every slot's race to random + fixed + // if random races is set force every slot's race to random if( m_MapFlags & MAPFLAG_RANDOMRACES ) { CONSOLE_Print( "[MAP] forcing races to random" ); - for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); i++ ) - (*i).SetRace( SLOTRACE_RANDOM | SLOTRACE_FIXED ); + for( vector :: iterator i = m_Slots.begin( ); i != m_Slots.end( ); ++i ) + (*i).SetRace( SLOTRACE_RANDOM ); } // add observer slots @@ -763,7 +872,7 @@ void CMap :: CheckValid( ) { // todotodo: should this code fix any errors it sees rather than just warning the user? - if( m_MapPath.empty( ) ) + if( m_MapPath.empty( ) || m_MapPath.length( ) > 53 ) { m_Valid = false; CONSOLE_Print( "[MAP] invalid map_path detected" ); @@ -822,12 +931,7 @@ void CMap :: CheckValid( ) } // todotodo: m_MapFlags - - if( m_MapGameType != 1 && m_MapGameType != 2 && m_MapGameType != 9 ) - { - m_Valid = false; - CONSOLE_Print( "[MAP] invalid map_gametype detected" ); - } + // todotodo: m_MapFilterMaker, m_MapFilterType, m_MapFilterSize, m_MapFilterObs if( m_MapWidth.size( ) != 2 ) { @@ -879,7 +983,7 @@ uint32_t CMap :: XORRotateLeft( unsigned char *data, uint32_t length ) while( i < length ) { Val = ROTL( Val ^ data[i], 3 ); - i++; + ++i; } return Val; diff --git a/ghost/map.h b/ghost/map.h index b480229..18a8cf8 100644 --- a/ghost/map.h +++ b/ghost/map.h @@ -41,6 +41,48 @@ #define MAPFLAG_RANDOMHERO 8 #define MAPFLAG_RANDOMRACES 16 +#define MAPOPT_HIDEMINIMAP 1 << 0 +#define MAPOPT_MODIFYALLYPRIORITIES 1 << 1 +#define MAPOPT_MELEE 1 << 2 // the bot cares about this one... +#define MAPOPT_REVEALTERRAIN 1 << 4 +#define MAPOPT_FIXEDPLAYERSETTINGS 1 << 5 // and this one... +#define MAPOPT_CUSTOMFORCES 1 << 6 // and this one, the rest don't affect the bot's logic +#define MAPOPT_CUSTOMTECHTREE 1 << 7 +#define MAPOPT_CUSTOMABILITIES 1 << 8 +#define MAPOPT_CUSTOMUPGRADES 1 << 9 +#define MAPOPT_WATERWAVESONCLIFFSHORES 1 << 11 +#define MAPOPT_WATERWAVESONSLOPESHORES 1 << 12 + +#define MAPFILTER_MAKER_USER 1 +#define MAPFILTER_MAKER_BLIZZARD 2 + +#define MAPFILTER_TYPE_MELEE 1 +#define MAPFILTER_TYPE_SCENARIO 2 + +#define MAPFILTER_SIZE_SMALL 1 +#define MAPFILTER_SIZE_MEDIUM 2 +#define MAPFILTER_SIZE_LARGE 4 + +#define MAPFILTER_OBS_FULL 1 +#define MAPFILTER_OBS_ONDEATH 2 +#define MAPFILTER_OBS_NONE 4 + +#define MAPGAMETYPE_UNKNOWN0 1 // always set except for saved games? +// AuthenticatedMakerBlizzard = 1 << 3 +// OfficialMeleeGame = 1 << 5 +#define MAPGAMETYPE_SAVEDGAME 1 << 9 +#define MAPGAMETYPE_PRIVATEGAME 1 << 11 +#define MAPGAMETYPE_MAKERUSER 1 << 13 +#define MAPGAMETYPE_MAKERBLIZZARD 1 << 14 +#define MAPGAMETYPE_TYPEMELEE 1 << 15 +#define MAPGAMETYPE_TYPESCENARIO 1 << 16 +#define MAPGAMETYPE_SIZESMALL 1 << 17 +#define MAPGAMETYPE_SIZEMEDIUM 1 << 18 +#define MAPGAMETYPE_SIZELARGE 1 << 19 +#define MAPGAMETYPE_OBSFULL 1 << 20 +#define MAPGAMETYPE_OBSONDEATH 1 << 21 +#define MAPGAMETYPE_OBSNONE 1 << 22 + #include "gameslot.h" #include "messagelogger.h" @@ -65,7 +107,11 @@ class CMap : protected MessageLogger unsigned char m_MapVisibility; unsigned char m_MapObservers; unsigned char m_MapFlags; - unsigned char m_MapGameType; + unsigned char m_MapFilterMaker; + unsigned char m_MapFilterType; + unsigned char m_MapFilterSize; + unsigned char m_MapFilterObs; + uint32_t m_MapOptions; BYTEARRAY m_MapWidth; // config value: map width (2 bytes) BYTEARRAY m_MapHeight; // config value: map height (2 bytes) string m_MapType; // config value: map type (for stats class) @@ -97,7 +143,9 @@ class CMap : protected MessageLogger unsigned char GetMapObservers( ) { return m_MapObservers; } unsigned char GetMapFlags( ) { return m_MapFlags; } BYTEARRAY GetMapGameFlags( ); - unsigned char GetMapGameType( ) { return m_MapGameType; } + uint32_t GetMapGameType( ); + uint32_t GetMapOptions( ) { return m_MapOptions; } + unsigned char GetMapLayoutStyle( ); BYTEARRAY GetMapWidth( ) { return m_MapWidth; } BYTEARRAY GetMapHeight( ) { return m_MapHeight; } string GetMapType( ) { return m_MapType; } diff --git a/ghost/packed.cpp b/ghost/packed.cpp index d2d53b0..9085b31 100644 --- a/ghost/packed.cpp +++ b/ghost/packed.cpp @@ -66,22 +66,12 @@ int tzuncompress( Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourc // CPacked // -CPacked :: CPacked( MessageLogger *logger ) - : MessageLogger( logger ) +CPacked :: CPacked( MessageLogger *logger ) + : m_Valid( true ), m_HeaderSize( 0 ), m_CompressedSize( 0 ), m_HeaderVersion( 0 ), m_DecompressedSize( 0 ), m_NumBlocks( 0 ), m_War3Identifier( 0 ), m_War3Version( 0 ), + m_BuildNumber( 0 ), m_Flags( 0 ), m_ReplayLength( 0 ), MessageLogger( logger ) { m_CRC = new CCRC32( ); m_CRC->Initialize( ); - m_Valid = true; - m_HeaderSize = 0; - m_CompressedSize = 0; - m_HeaderVersion = 0; - m_DecompressedSize = 0; - m_NumBlocks = 0; - m_War3Identifier = 0; - m_War3Version = 0; - m_BuildNumber = 0; - m_Flags = 0; - m_ReplayLength = 0; } CPacked :: ~CPacked( ) @@ -197,7 +187,7 @@ void CPacked :: Decompress( bool allBlocks ) // read blocks - for( uint32_t i = 0; i < m_NumBlocks; i++ ) + for( uint32_t i = 0; i < m_NumBlocks; ++i ) { uint16_t BlockCompressed; uint16_t BlockDecompressed; @@ -375,14 +365,13 @@ void CPacked :: Compress( bool TFT ) // append blocks - for( vector :: iterator i = CompressedBlocks.begin( ); i != CompressedBlocks.end( ); i++ ) + for( vector :: iterator i = CompressedBlocks.begin( ); i != CompressedBlocks.end( ); ++i ) { BYTEARRAY BlockHeader; UTIL_AppendByteArray( BlockHeader, (uint16_t)(*i).size( ), false ); UTIL_AppendByteArray( BlockHeader, (uint16_t)8192, false ); // append zero block header CRC - UTIL_AppendByteArray( BlockHeader, (uint32_t)0, false ); // calculate block header CRC diff --git a/ghost/replay.cpp b/ghost/replay.cpp index d2cc767..32583bd 100644 --- a/ghost/replay.cpp +++ b/ghost/replay.cpp @@ -28,14 +28,9 @@ // CReplay // -CReplay :: CReplay( MessageLogger *logger ) : CPacked( logger ) +CReplay :: CReplay( MessageLogger *logger ) : CPacked( logger ), m_HostPID( 0 ), m_PlayerCount( 0 ), m_MapGameType( 0 ), m_RandomSeed( 0 ), m_SelectMode( 0 ), m_StartSpotCount( 0 ) { - m_HostPID = 0; - m_PlayerCount = 0; - m_MapGameType = 1; - m_RandomSeed = 0; - m_SelectMode = 0; - m_StartSpotCount = 0; + m_CompiledBlocks.reserve( 262144 ); } CReplay :: ~CReplay( ) @@ -51,7 +46,7 @@ void CReplay :: AddLeaveGame( uint32_t reason, unsigned char PID, uint32_t resul Block.push_back( PID ); UTIL_AppendByteArray( Block, result, false ); UTIL_AppendByteArray( Block, (uint32_t)1, false ); - m_Blocks.push( Block ); + m_CompiledBlocks += string( Block.begin( ), Block.end( ) ); } void CReplay :: AddLeaveGameDuringLoading( uint32_t reason, unsigned char PID, uint32_t result ) @@ -65,6 +60,30 @@ void CReplay :: AddLeaveGameDuringLoading( uint32_t reason, unsigned char PID, u m_LoadingBlocks.push( Block ); } +void CReplay :: AddTimeSlot2( queue actions ) +{ + BYTEARRAY Block; + Block.push_back( REPLAY_TIMESLOT2 ); + UTIL_AppendByteArray( Block, (uint16_t)0, false ); + UTIL_AppendByteArray( Block, (uint16_t)0, false ); + + while( !actions.empty( ) ) + { + CIncomingAction *Action = actions.front( ); + actions.pop( ); + Block.push_back( Action->GetPID( ) ); + UTIL_AppendByteArray( Block, (uint16_t)Action->GetAction( )->size( ), false ); + UTIL_AppendByteArrayFast( Block, *Action->GetAction( ) ); + } + + // assign length + + BYTEARRAY LengthBytes = UTIL_CreateByteArray( (uint16_t)( Block.size( ) - 3 ), false ); + Block[1] = LengthBytes[0]; + Block[2] = LengthBytes[1]; + m_CompiledBlocks += string( Block.begin( ), Block.end( ) ); +} + void CReplay :: AddTimeSlot( uint16_t timeIncrement, queue actions ) { BYTEARRAY Block; @@ -86,7 +105,8 @@ void CReplay :: AddTimeSlot( uint16_t timeIncrement, queue ac BYTEARRAY LengthBytes = UTIL_CreateByteArray( (uint16_t)( Block.size( ) - 3 ), false ); Block[1] = LengthBytes[0]; Block[2] = LengthBytes[1]; - m_Blocks.push( Block ); + m_CompiledBlocks += string( Block.begin( ), Block.end( ) ); + m_ReplayLength += timeIncrement; } void CReplay :: AddChatMessage( unsigned char PID, unsigned char flags, uint32_t chatMode, string message ) @@ -104,17 +124,7 @@ void CReplay :: AddChatMessage( unsigned char PID, unsigned char flags, uint32_t BYTEARRAY LengthBytes = UTIL_CreateByteArray( (uint16_t)( Block.size( ) - 4 ), false ); Block[2] = LengthBytes[0]; Block[3] = LengthBytes[1]; - m_Blocks.push( Block ); -} - -void CReplay :: AddCheckSum( uint32_t checkSum ) -{ - m_CheckSums.push( checkSum ); -} - -void CReplay :: AddBlock( BYTEARRAY &block ) -{ - m_Blocks.push( block ); + m_CompiledBlocks += string( Block.begin( ), Block.end( ) ); } void CReplay :: AddLoadingBlock( BYTEARRAY &loadingBlock ) @@ -146,15 +156,12 @@ void CReplay :: BuildReplay( string gameName, string statString, uint32_t war3Ve Replay.push_back( 0 ); // Null (4.0) UTIL_AppendByteArrayFast( Replay, statString ); // StatString (4.3) UTIL_AppendByteArray( Replay, (uint32_t)m_Slots.size( ), false ); // PlayerCount (4.6) - Replay.push_back( m_MapGameType ); // GameType (4.7) - Replay.push_back( 32 ); // GameType (4.7) - Replay.push_back( 73 ); // GameType (4.7) - Replay.push_back( 0 ); // GameType (4.7) + UTIL_AppendByteArray( Replay, m_MapGameType, false ); // GameType (4.7) UTIL_AppendByteArray( Replay, LanguageID, false ); // LanguageID (4.8) // PlayerList (4.9) - for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); i++ ) + for( vector :: iterator i = m_Players.begin( ); i != m_Players.end( ); ++i ) { if( (*i).first != m_HostPID ) { @@ -173,7 +180,7 @@ void CReplay :: BuildReplay( string gameName, string statString, uint32_t war3Ve UTIL_AppendByteArray( Replay, (uint16_t)( 7 + m_Slots.size( ) * 9 ), false ); // Size (4.10) Replay.push_back( m_Slots.size( ) ); // NumSlots (4.10) - for( unsigned char i = 0; i < m_Slots.size( ); i++ ) + for( unsigned char i = 0; i < m_Slots.size( ); ++i ) UTIL_AppendByteArray( Replay, m_Slots[i].GetByteArray( ) ); UTIL_AppendByteArray( Replay, m_RandomSeed, false ); // RandomSeed (4.10) @@ -198,67 +205,10 @@ void CReplay :: BuildReplay( string gameName, string statString, uint32_t war3Ve Replay.push_back( REPLAY_THIRDSTARTBLOCK ); UTIL_AppendByteArray( Replay, (uint32_t)1, false ); - // initialize replay length to zero - // we'll accumulate the replay length as we iterate through the timeslots - // this is necessary because we might be discarding some timeslots due to not enough checksums and the replay length needs to be accurate - - m_ReplayLength = 0; - uint32_t TimeSlotsDiscarded = 0; - bool EndOfTimeSlots = false; - - while( !m_Blocks.empty( ) ) - { - BYTEARRAY Block = m_Blocks.front( ); - m_Blocks.pop( ); - - if( Block.size( ) >= 5 && Block[0] == REPLAY_TIMESLOT ) - { - uint16_t TimeIncrement = UTIL_ByteArrayToUInt16( Block, false, 3 ); - - if( TimeIncrement != 0 && m_CheckSums.empty( ) ) - EndOfTimeSlots = true; - - if( EndOfTimeSlots ) - { - TimeSlotsDiscarded++; - continue; - } - - // append timeslot - - UTIL_AppendByteArrayFast( Replay, Block ); - - // append checksum - // todotodo: after experimenting, Strilanc discovered that checksums are NOT required in replays - // we could optimize saving of replays by building a complete stream without waiting for checksums as the game progresses - // alternatively, we could build that stream as the checksums were added if we wanted to keep them - // rather than building it in one go right now, which might take a few hundred ms and cause a spike in other games - - if( TimeIncrement != 0 ) - { - BYTEARRAY CheckSum; - CheckSum.reserve( 6 ); - CheckSum.push_back( REPLAY_CHECKSUM ); - CheckSum.push_back( 4 ); - UTIL_AppendByteArray( CheckSum, m_CheckSums.front( ), false ); - m_CheckSums.pop( ); - UTIL_AppendByteArrayFast( Replay, CheckSum ); - } - - // accumulate replay length - - m_ReplayLength += TimeIncrement; - } - else - UTIL_AppendByteArrayFast( Replay, Block ); - } - - if( TimeSlotsDiscarded > 0 ) - CONSOLE_Print( "[REPLAY] ran out of checksums, discarded " + UTIL_ToString( TimeSlotsDiscarded ) + " timeslots" ); - // done m_Decompressed = string( Replay.begin( ), Replay.end( ) ); + m_Decompressed += m_CompiledBlocks; } #define READB( x, y, z ) (x).read( (char *)(y), (z) ) @@ -271,7 +221,7 @@ void CReplay :: ParseReplay( bool parseBlocks ) m_GameName.clear( ); m_StatString.clear( ); m_PlayerCount = 0; - m_MapGameType = 1; + m_MapGameType = 0; m_Players.clear( ); m_Slots.clear( ); m_RandomSeed = 0; @@ -354,16 +304,7 @@ void CReplay :: ParseReplay( bool parseBlocks ) return; } - READB( ISS, &Garbage4, 4 ); // GameType (4.7) - - /* if( (Garbage4 & 0xFFFFFF00) != 4792320 ) - { - CONSOLE_Print( "[REPLAY] invalid replay (4.7 GameType mismatch)" ); - m_Valid = false; - return; - } */ - - m_MapGameType = Garbage4 & 0x000000FF; + READB( ISS, &m_MapGameType, 4 ); // GameType (4.7) READB( ISS, &Garbage4, 4 ); // LanguageID (4.8) while( 1 ) @@ -442,7 +383,7 @@ void CReplay :: ParseReplay( bool parseBlocks ) return; } - for( int i = 0; i < NumSlots; i++ ) + for( int i = 0; i < NumSlots; ++i ) { unsigned char SlotData[9]; READB( ISS, SlotData, 9 ); diff --git a/ghost/replay.h b/ghost/replay.h index 1620d96..d2f12fe 100644 --- a/ghost/replay.h +++ b/ghost/replay.h @@ -37,9 +37,11 @@ class CReplay : public CPacked REPLAY_FIRSTSTARTBLOCK = 0x1A, REPLAY_SECONDSTARTBLOCK = 0x1B, REPLAY_THIRDSTARTBLOCK = 0x1C, - REPLAY_TIMESLOT = 0x1F, + REPLAY_TIMESLOT2 = 0x1E, // corresponds to W3GS_INCOMING_ACTION2 + REPLAY_TIMESLOT = 0x1F, // corresponds to W3GS_INCOMING_ACTION REPLAY_CHATMESSAGE = 0x20, - REPLAY_CHECKSUM = 0x22 + REPLAY_CHECKSUM = 0x22, // corresponds to W3GS_OUTGOING_KEEPALIVE + REPLAY_DESYNC = 0x23 }; private: @@ -48,15 +50,16 @@ class CReplay : public CPacked string m_GameName; string m_StatString; uint32_t m_PlayerCount; - unsigned char m_MapGameType; + uint32_t m_MapGameType; vector m_Players; vector m_Slots; uint32_t m_RandomSeed; - unsigned char m_SelectMode; + unsigned char m_SelectMode; // also known as the "layout style" elsewhere in this project unsigned char m_StartSpotCount; queue m_LoadingBlocks; queue m_Blocks; queue m_CheckSums; + string m_CompiledBlocks; public: CReplay( MessageLogger *logger ); @@ -67,7 +70,7 @@ class CReplay : public CPacked string GetGameName( ) { return m_GameName; } string GetStatString( ) { return m_StatString; } uint32_t GetPlayerCount( ) { return m_PlayerCount; } - unsigned char GetMapGameType( ) { return m_MapGameType; } + uint32_t GetMapGameType( ) { return m_MapGameType; } vector GetPlayers( ) { return m_Players; } vector GetSlots( ) { return m_Slots; } uint32_t GetRandomSeed( ) { return m_RandomSeed; } @@ -82,16 +85,15 @@ class CReplay : public CPacked void SetRandomSeed( uint32_t nRandomSeed ) { m_RandomSeed = nRandomSeed; } void SetSelectMode( unsigned char nSelectMode ) { m_SelectMode = nSelectMode; } void SetStartSpotCount( unsigned char nStartSpotCount ) { m_StartSpotCount = nStartSpotCount; } - void SetMapGameType( unsigned char nMapGameType ) { m_MapGameType = nMapGameType; } + void SetMapGameType( uint32_t nMapGameType ) { m_MapGameType = nMapGameType; } void SetHostPID( unsigned char nHostPID ) { m_HostPID = nHostPID; } void SetHostName( string nHostName ) { m_HostName = nHostName; } void AddLeaveGame( uint32_t reason, unsigned char PID, uint32_t result ); void AddLeaveGameDuringLoading( uint32_t reason, unsigned char PID, uint32_t result ); + void AddTimeSlot2( queue actions ); void AddTimeSlot( uint16_t timeIncrement, queue actions ); void AddChatMessage( unsigned char PID, unsigned char flags, uint32_t chatMode, string message ); - void AddCheckSum( uint32_t checkSum ); - void AddBlock( BYTEARRAY &block ); void AddLoadingBlock( BYTEARRAY &loadingBlock ); void BuildReplay( string gameName, string statString, uint32_t war3Version, uint16_t buildNumber ); diff --git a/ghost/savegame.cpp b/ghost/savegame.cpp index 7dd8404..f0ebce5 100644 --- a/ghost/savegame.cpp +++ b/ghost/savegame.cpp @@ -27,10 +27,9 @@ // CSaveGame // -CSaveGame :: CSaveGame( MessageLogger* logger ) : CPacked( logger ) +CSaveGame :: CSaveGame( MessageLogger* logger ) : CPacked( logger ), m_NumSlots( 0 ), m_RandomSeed( 0 ) { - m_NumSlots = 0; - m_RandomSeed = 0; + } CSaveGame :: ~CSaveGame( ) diff --git a/ghost/sha1.cpp b/ghost/sha1.cpp index 82fb7fa..6154586 100644 --- a/ghost/sha1.cpp +++ b/ghost/sha1.cpp @@ -126,7 +126,7 @@ void CSHA1::Final() uint32_t i = 0, j = 0; unsigned char finalcount[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - for (i = 0; i < 8; i++) + for (i = 0; i < 8; ++i) finalcount[i] = (unsigned char)((m_count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8) ) & 255); // Endian independent @@ -137,7 +137,7 @@ void CSHA1::Final() Update(finalcount, 8); // Cause a SHA1Transform() - for (i = 0; i < 20; i++) + for (i = 0; i < 20; ++i) { m_digest[i] = (unsigned char)((m_state[i >> 2] >> ((3 - (i & 3)) * 8) ) & 255); } @@ -165,7 +165,7 @@ void CSHA1::ReportHash(char *szReport, unsigned char uReportType) sprintf(szTemp, "%02x", m_digest[0]); strcat(szReport, szTemp); - for(i = 1; i < 20; i++) + for(i = 1; i < 20; ++i) { sprintf(szTemp, "%02x", m_digest[i]); strcat(szReport, szTemp); @@ -176,7 +176,7 @@ void CSHA1::ReportHash(char *szReport, unsigned char uReportType) sprintf(szTemp, "%u", m_digest[0]); strcat(szReport, szTemp); - for(i = 1; i < 20; i++) + for(i = 1; i < 20; ++i) { sprintf(szTemp, " %u", m_digest[i]); strcat(szReport, szTemp); diff --git a/ghost/socket.cpp b/ghost/socket.cpp index 976f7cd..93d0a90 100644 --- a/ghost/socket.cpp +++ b/ghost/socket.cpp @@ -32,22 +32,14 @@ // CSocket // -CSocket :: CSocket( MessageLogger* logger ) - : MessageLogger( logger ) +CSocket :: CSocket( MessageLogger* logger ) : m_Socket( INVALID_SOCKET ), m_HasError( false ), m_Error( 0 ), MessageLogger( logger ) { - m_Socket = INVALID_SOCKET; - memset( &m_SIN, 0, sizeof( m_SIN ) ); - m_HasError = false; - m_Error = 0; + memset( &m_SIN, 0, sizeof( m_SIN ) ); } -CSocket :: CSocket( MessageLogger* logger, SOCKET nSocket, struct sockaddr_in nSIN ) - : MessageLogger( logger ) +CSocket :: CSocket( MessageLogger* logger, SOCKET nSocket, struct sockaddr_in nSIN ) : m_Socket( nSocket ), m_SIN( nSIN ), m_HasError( false ), m_Error( 0 ), MessageLogger( logger ) { - m_Socket = nSocket; - m_SIN = nSIN; - m_HasError = false; - m_Error = 0; + } CSocket :: ~CSocket( ) @@ -161,12 +153,9 @@ void CSocket :: Reset( ) // CTCPSocket // -CTCPSocket :: CTCPSocket( MessageLogger* logger ) : CSocket( logger ) +CTCPSocket :: CTCPSocket( MessageLogger* logger ) : CSocket( logger ), m_Connected( false ), m_LastRecv( GetTime( ) ), m_LastSend( GetTime( ) ) { Allocate( SOCK_STREAM ); - m_Connected = false; - m_LastRecv = GetTime( ); - m_LastSend = GetTime( ); // make socket non blocking @@ -356,9 +345,9 @@ void CTCPSocket :: SetNoDelay( bool noDelay ) // CTCPClient // -CTCPClient :: CTCPClient( MessageLogger* logger ) : CTCPSocket( logger ) +CTCPClient :: CTCPClient( MessageLogger* logger ) : CTCPSocket( logger ), m_Connecting( false ) { - m_Connecting = false; + } CTCPClient :: ~CTCPClient( ) diff --git a/ghost/stats.cpp b/ghost/stats.cpp index 7bf7757..20d661c 100644 --- a/ghost/stats.cpp +++ b/ghost/stats.cpp @@ -26,10 +26,9 @@ // CStats // -CStats :: CStats( CBaseGame *nGame ) - : MessageLogger( nGame ) +CStats :: CStats( CBaseGame *nGame ) : m_Game( nGame ), MessageLogger( nGame ) { - m_Game = nGame; + } CStats :: ~CStats( ) diff --git a/ghost/statsdota.cpp b/ghost/statsdota.cpp index f7499a8..d90621b 100644 --- a/ghost/statsdota.cpp +++ b/ghost/statsdota.cpp @@ -31,21 +31,17 @@ // CStatsDOTA // -CStatsDOTA :: CStatsDOTA( CBaseGame *nGame ) : CStats( nGame ) +CStatsDOTA :: CStatsDOTA( CBaseGame *nGame ) : CStats( nGame ), m_Winner( 0 ), m_Min( 0 ), m_Sec( 0 ) { CONSOLE_Print( "[STATSDOTA] using dota stats" ); - for( unsigned int i = 0; i < 12; i++ ) + for( unsigned int i = 0; i < 12; ++i ) m_Players[i] = NULL; - - m_Winner = 0; - m_Min = 0; - m_Sec = 0; } CStatsDOTA :: ~CStatsDOTA( ) { - for( unsigned int i = 0; i < 12; i++ ) + for( unsigned int i = 0; i < 12; ++i ) { if( m_Players[i] ) delete m_Players[i]; @@ -359,16 +355,16 @@ bool CStatsDOTA :: ProcessAction( CIncomingAction *Action ) i += 12 + Data.size( ) + Key.size( ); } else - i++; + ++i; } else - i++; + ++i; } else - i++; + ++i; } else - i++; + ++i; } return m_Winner != 0; @@ -392,7 +388,7 @@ void CStatsDOTA :: Save( CGHost *GHost, CGHostDB *DB, uint32_t GameID ) // check for invalid colours and duplicates // this can only happen if DotA sends us garbage in the "id" value but we should check anyway - for( unsigned int i = 0; i < 12; i++ ) + for( unsigned int i = 0; i < 12; ++i ) { if( m_Players[i] ) { @@ -405,7 +401,7 @@ void CStatsDOTA :: Save( CGHost *GHost, CGHostDB *DB, uint32_t GameID ) return; } - for( unsigned int j = i + 1; j < 12; j++ ) + for( unsigned int j = i + 1; j < 12; ++j ) { if( m_Players[j] && Colour == m_Players[j]->GetNewColour( ) ) { @@ -419,12 +415,12 @@ void CStatsDOTA :: Save( CGHost *GHost, CGHostDB *DB, uint32_t GameID ) // save the dotaplayers - for( unsigned int i = 0; i < 12; i++ ) + for( unsigned int i = 0; i < 12; ++i ) { if( m_Players[i] ) { GHost->m_Callables.push_back( DB->ThreadedDotAPlayerAdd( GameID, m_Players[i]->GetColour( ), m_Players[i]->GetKills( ), m_Players[i]->GetDeaths( ), m_Players[i]->GetCreepKills( ), m_Players[i]->GetCreepDenies( ), m_Players[i]->GetAssists( ), m_Players[i]->GetGold( ), m_Players[i]->GetNeutralKills( ), m_Players[i]->GetItem( 0 ), m_Players[i]->GetItem( 1 ), m_Players[i]->GetItem( 2 ), m_Players[i]->GetItem( 3 ), m_Players[i]->GetItem( 4 ), m_Players[i]->GetItem( 5 ), m_Players[i]->GetHero( ), m_Players[i]->GetNewColour( ), m_Players[i]->GetTowerKills( ), m_Players[i]->GetRaxKills( ), m_Players[i]->GetCourierKills( ) ) ); - Players++; + ++Players; } } diff --git a/ghost/statsw3mmd.cpp b/ghost/statsw3mmd.cpp index 638f386..bac0008 100644 --- a/ghost/statsw3mmd.cpp +++ b/ghost/statsw3mmd.cpp @@ -30,13 +30,10 @@ // CStatsW3MMD // -CStatsW3MMD :: CStatsW3MMD( CBaseGame *nGame, string nCategory ) : CStats( nGame ) +CStatsW3MMD :: CStatsW3MMD( CBaseGame *nGame, string nCategory ) : CStats( nGame ), m_Category( nCategory ), m_NextValueID( 0 ), m_NextCheckID( 0 ) { CONSOLE_Print( "[STATSW3MMD] using Warcraft 3 Map Meta Data stats parser version 1" ); CONSOLE_Print( "[STATSW3MMD] using map_statsw3mmdcategory [" + nCategory + "]" ); - m_Category = nCategory; - m_NextValueID = 0; - m_NextCheckID = 0; } CStatsW3MMD :: ~CStatsW3MMD( ) @@ -276,7 +273,7 @@ bool CStatsW3MMD :: ProcessAction( CIncomingAction *Action ) { // replace the markers in the format string with the arguments - for( uint32_t i = 0; i < Tokens.size( ) - 2; i++ ) + for( uint32_t i = 0; i < Tokens.size( ) - 2; ++i ) { // check if the marker is a PID marker @@ -314,7 +311,7 @@ bool CStatsW3MMD :: ProcessAction( CIncomingAction *Action ) CONSOLE_Print( "[STATSW3MMD: " + m_Game->GetGameName( ) + "] unknown message type [" + Tokens[0] + "] found, ignoring" ); } - m_NextValueID++; + ++m_NextValueID; } else if( MissionKeyString.size( ) > 4 && MissionKeyString.substr( 0, 4 ) == "chk:" ) { @@ -323,7 +320,7 @@ bool CStatsW3MMD :: ProcessAction( CIncomingAction *Action ) // todotodo: cheat detection - m_NextCheckID++; + ++m_NextCheckID; } else CONSOLE_Print( "[STATSW3MMD: " + m_Game->GetGameName( ) + "] unknown mission key [" + MissionKeyString + "] found, ignoring" ); @@ -331,16 +328,16 @@ bool CStatsW3MMD :: ProcessAction( CIncomingAction *Action ) i += 15 + MissionKey.size( ) + Key.size( ); } else - i++; + ++i; } else - i++; + ++i; } else - i++; + ++i; } else - i++; + ++i; } return false; @@ -355,7 +352,7 @@ void CStatsW3MMD :: Save( CGHost *GHost, CGHostDB *DB, uint32_t GameID ) // todotodo: there's no reason to create a new callable for each entry in this map // rewrite ThreadedW3MMDPlayerAdd to act more like ThreadedW3MMDVarAdd - for( map :: iterator i = m_PIDToName.begin( ); i != m_PIDToName.end( ); i++ ) + for( map :: iterator i = m_PIDToName.begin( ); i != m_PIDToName.end( ); ++i ) { string Flags = m_Flags[i->first]; uint32_t Leaver = 0; @@ -409,7 +406,7 @@ vector CStatsW3MMD :: TokenizeKey( string key ) string Token; bool Escaping = false; - for( string :: iterator i = key.begin( ); i != key.end( ); i++ ) + for( string :: iterator i = key.begin( ); i != key.end( ); ++i ) { if( Escaping ) { diff --git a/ghost/util.cpp b/ghost/util.cpp index 61325e6..4312669 100644 --- a/ghost/util.cpp +++ b/ghost/util.cpp @@ -97,7 +97,7 @@ string UTIL_ByteArrayToDecString( BYTEARRAY b ) string result = UTIL_ToString( b[0] ); - for( BYTEARRAY :: iterator i = b.begin( ) + 1; i != b.end( ); i++ ) + for( BYTEARRAY :: iterator i = b.begin( ) + 1; i != b.end( ); ++i ) result += " " + UTIL_ToString( *i ); return result; @@ -110,7 +110,7 @@ string UTIL_ByteArrayToHexString( BYTEARRAY b ) string result = UTIL_ToHexString( b[0] ); - for( BYTEARRAY :: iterator i = b.begin( ) + 1; i != b.end( ); i++ ) + for( BYTEARRAY :: iterator i = b.begin( ) + 1; i != b.end( ); ++i ) { if( *i < 16 ) result += " 0" + UTIL_ToHexString( *i ); @@ -173,7 +173,7 @@ BYTEARRAY UTIL_ExtractCString( BYTEARRAY &b, unsigned int start ) if( start < b.size( ) ) { - for( unsigned int i = start; i < b.size( ); i++ ) + for( unsigned int i = start; i < b.size( ); ++i ) { if( b[i] == 0 ) return BYTEARRAY( b.begin( ) + start, b.begin( ) + i ); @@ -218,7 +218,7 @@ BYTEARRAY UTIL_ExtractNumbers( string s, unsigned int count ) stringstream SS; SS << s; - for( unsigned int i = 0; i < count; i++ ) + for( unsigned int i = 0; i < count; ++i ) { if( SS.eof( ) ) break; @@ -524,7 +524,7 @@ BYTEARRAY UTIL_EncodeStatString( BYTEARRAY &data ) unsigned char Mask = 1; BYTEARRAY Result; - for( unsigned int i = 0; i < data.size( ); i++ ) + for( unsigned int i = 0; i < data.size( ); ++i ) { if( ( data[i] % 2 ) == 0 ) Result.push_back( data[i] + 1 ); @@ -549,7 +549,7 @@ BYTEARRAY UTIL_DecodeStatString( BYTEARRAY &data ) unsigned char Mask; BYTEARRAY Result; - for( unsigned int i = 0; i < data.size( ); i++ ) + for( unsigned int i = 0; i < data.size( ); ++i ) { if( ( i % 8 ) == 0 ) Mask = data[i]; @@ -600,7 +600,7 @@ bool UTIL_IsLocalIP( BYTEARRAY ip, vector &localIPs ) if( ip.size( ) != 4 ) return false; - for( vector :: iterator i = localIPs.begin( ); i != localIPs.end( ); i++ ) + for( vector :: iterator i = localIPs.begin( ); i != localIPs.end( ); ++i ) { if( (*i).size( ) != 4 ) continue; @@ -633,7 +633,7 @@ vector UTIL_Tokenize( string s, char delim ) vector Tokens; string Token; - for( string :: iterator i = s.begin( ); i != s.end( ); i++ ) + for( string :: iterator i = s.begin( ); i != s.end( ); ++i ) { if( *i == delim ) { @@ -657,7 +657,7 @@ uint32_t UTIL_Factorial( uint32_t x ) { uint32_t Factorial = 1; - for( uint32_t i = 2; i <= x; i++ ) + for( uint32_t i = 2; i <= x; ++i ) Factorial *= i; return Factorial; From 3aca8d32f9c058bf213ee37b73498cb72f0a7bca Mon Sep 17 00:00:00 2001 From: "MyFakeAcc.4@googlemail.com" Date: Sun, 7 Nov 2010 17:36:29 +0000 Subject: [PATCH 5/7] [ghost-genie] Catching up to trunk (r557 & r558) --- ghost/bnlsclient.cpp | 13 ++----- ghost/game.cpp | 4 +- ghost/game_base.cpp | 91 ++++++++++---------------------------------- ghost/gameplayer.cpp | 16 ++++++-- ghost/gameslot.cpp | 19 +-------- ghost/map.cpp | 38 +++++++++--------- 6 files changed, 58 insertions(+), 123 deletions(-) diff --git a/ghost/bnlsclient.cpp b/ghost/bnlsclient.cpp index 9437dc7..85f2be5 100644 --- a/ghost/bnlsclient.cpp +++ b/ghost/bnlsclient.cpp @@ -31,17 +31,10 @@ // CBNLSClient :: CBNLSClient( CBNET *bnet, string nServer, uint16_t nPort, uint32_t nWardenCookie ) - : MessageLogger( bnet ) + : m_WasConnected( false ), m_Server( nServer ), m_Port( nPort ), m_LastNullTime( 0 ), m_WardenCookie( nWardenCookie ), m_TotalWardenIn( 0 ), m_TotalWardenOut( 0 ), MessageLogger( bnet ) { m_Socket = new CTCPClient( this ); m_Protocol = new CBNLSProtocol( this ); - m_WasConnected = false; - m_Server = nServer; - m_Port = nPort; - m_LastNullTime = 0; - m_WardenCookie = nWardenCookie; - m_TotalWardenIn = 0; - m_TotalWardenOut = 0; } CBNLSClient :: ~CBNLSClient( ) @@ -64,7 +57,7 @@ BYTEARRAY CBNLSClient :: GetWardenResponse( ) { WardenResponse = m_WardenResponses.front( ); m_WardenResponses.pop( ); - m_TotalWardenOut++; + ++m_TotalWardenOut; } return WardenResponse; @@ -191,5 +184,5 @@ void CBNLSClient :: QueueWardenSeed( uint32_t seed ) void CBNLSClient :: QueueWardenRaw( BYTEARRAY wardenRaw ) { m_OutPackets.push( m_Protocol->SEND_BNLS_WARDEN_RAW( m_WardenCookie, wardenRaw ) ); - m_TotalWardenIn++; + ++m_TotalWardenIn; } diff --git a/ghost/game.cpp b/ghost/game.cpp index ae80075..8df7124 100644 --- a/ghost/game.cpp +++ b/ghost/game.cpp @@ -66,7 +66,7 @@ class CGamePlayerSortDescByPing // CGame // -CGame :: CGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16_t nHostPort, unsigned char nGameState, string nGameName, string nOwnerName, string nCreatorName, string nCreatorServer ) : CBaseGame( nGHost, nMap, nSaveGame, nHostPort, nGameState, nGameName, nOwnerName, nCreatorName, nCreatorServer ), m_DBBanLast( NULL ), m_CallableGameAdd( NULL ) +CGame :: CGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16_t nHostPort, unsigned char nGameState, string nGameName, string nOwnerName, string nCreatorName, string nCreatorServer ) : CBaseGame( nGHost, nMap, nSaveGame, nHostPort, nGameState, nGameName, nOwnerName, nCreatorName, nCreatorServer ), m_DBBanLast( NULL ), m_Stats( NULL ), m_CallableGameAdd( NULL ) { m_DBGame = new CDBGame( 0, string( ), m_Map->GetMapPath( ), string( ), string( ), string( ), 0 ); @@ -74,8 +74,6 @@ CGame :: CGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16_t nHost m_Stats = new CStatsW3MMD( this, m_Map->GetMapStatsW3MMDCategory( ) ); else if( m_Map->GetMapType( ) == "dota" ) m_Stats = new CStatsDOTA( this ); - else - m_Stats = NULL; } CGame :: ~CGame( ) diff --git a/ghost/game_base.cpp b/ghost/game_base.cpp index 4621ff4..e5ef108 100644 --- a/ghost/game_base.cpp +++ b/ghost/game_base.cpp @@ -43,34 +43,39 @@ // CBaseGame // -CBaseGame :: CBaseGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16_t nHostPort, unsigned char nGameState, string nGameName, string nOwnerName, string nCreatorName, string nCreatorServer ) - : MessageLogger( nGHost ) +CBaseGame :: CBaseGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16_t nHostPort, unsigned char nGameState, string nGameName, + string nOwnerName, string nCreatorName, string nCreatorServer ) : m_GHost( nGHost ), m_SaveGame( nSaveGame ), + m_Replay( NULL ), m_Exiting( false ), m_Saving( false ), m_HostPort( nHostPort ), m_GameState( nGameState ), m_VirtualHostPID( 255 ), + m_FakePlayerPID( 255 ), m_GProxyEmptyActions( 0 ), m_GameName( nGameName ), m_LastGameName( nGameName ), + m_VirtualHostName( m_GHost->m_VirtualHostName ), m_OwnerName( nOwnerName ), m_CreatorName( nCreatorName ), + m_CreatorServer( nCreatorServer ), m_HCLCommandString( nMap->GetMapDefaultHCL( ) ), m_RandomSeed( GetTicks( ) ), + m_HostCounter( m_GHost->m_HostCounter++ ), m_EntryKey( rand( ) ), m_Latency( m_GHost->m_Latency ), + m_SyncLimit( m_GHost->m_SyncLimit ), m_SyncCounter( 0 ), m_GameTicks( 0 ), m_CreationTime( GetTime( ) ), + m_LastPingTime( GetTime( ) ), m_LastRefreshTime( GetTime( ) ), m_LastDownloadTicks( GetTime( ) ), m_DownloadCounter( 0 ), + m_LastDownloadCounterResetTicks( GetTime( ) ), m_LastAnnounceTime( 0 ), m_AnnounceInterval( 0 ), m_LastAutoStartTime( GetTime( ) ), + m_AutoStartPlayers( 0 ), m_LastCountDownTicks( 0 ), m_CountDownCounter( 0 ), m_StartedLoadingTicks( 0 ), m_StartPlayers( 0 ), + m_LastLagScreenResetTime( 0 ), m_LastActionSentTicks( 0 ), m_LastActionLateBy( 0 ), m_StartedLaggingTime( 0 ), + m_LastLagScreenTime( 0 ), m_LastReservedSeen( GetTime( ) ), m_StartedKickVoteTime( 0 ), m_GameOverTime( 0 ), + m_LastPlayerLeaveTicks( 0 ), m_MinimumScore( 0. ), m_MaximumScore( 0. ), m_SlotInfoChanged( false ), m_Locked( false ), + m_RefreshMessages( m_GHost->m_RefreshMessages ), m_RefreshError( false ), m_RefreshRehosted( false ), m_MuteAll( false ), + m_MuteLobby( false ), m_CountDownStarted( false ), m_GameLoading( false ), m_GameLoaded( false ), + m_LoadInGame( nMap->GetMapLoadInGame( ) ), m_Lagging( false ), m_AutoSave( m_GHost->m_AutoSave ), m_MatchMaking( false ), + m_LocalAdminMessages( m_GHost->m_LocalAdminMessages ), MessageLogger( nGHost ) + { - m_GHost = nGHost; m_Socket = new CTCPServer( this ); m_Protocol = new CGameProtocol( m_GHost ); m_Map = new CMap( *nMap ); - m_SaveGame = nSaveGame; if( m_GHost->m_SaveReplays && !m_SaveGame ) m_Replay = new CReplay( this ); - else - m_Replay = NULL; - - m_Exiting = false; - m_Saving = false; - m_HostPort = nHostPort; - m_GameState = nGameState; - m_VirtualHostPID = 255; - m_FakePlayerPID = 255; + // wait time of 1 minute = 0 empty actions required // wait time of 2 minutes = 1 empty action required // etc... - if( m_GHost->m_ReconnectWaitTime == 0 ) - m_GProxyEmptyActions = 0; - else + if( m_GHost->m_ReconnectWaitTime != 0 ) { m_GProxyEmptyActions = m_GHost->m_ReconnectWaitTime - 1; @@ -80,60 +85,6 @@ CBaseGame :: CBaseGame( CGHost *nGHost, CMap *nMap, CSaveGame *nSaveGame, uint16 m_GProxyEmptyActions = 9; } - m_GameName = nGameName; - m_LastGameName = nGameName; - m_VirtualHostName = m_GHost->m_VirtualHostName; - m_OwnerName = nOwnerName; - m_CreatorName = nCreatorName; - m_CreatorServer = nCreatorServer; - m_HCLCommandString = m_Map->GetMapDefaultHCL( ); - m_RandomSeed = GetTicks( ); - m_HostCounter = m_GHost->m_HostCounter++; - m_EntryKey = rand( ); - m_Latency = m_GHost->m_Latency; - m_SyncLimit = m_GHost->m_SyncLimit; - m_SyncCounter = 0; - m_GameTicks = 0; - m_CreationTime = GetTime( ); - m_LastPingTime = GetTime( ); - m_LastRefreshTime = GetTime( ); - m_LastDownloadTicks = GetTime( ); - m_DownloadCounter = 0; - m_LastDownloadCounterResetTicks = GetTicks( ); - m_LastAnnounceTime = 0; - m_AnnounceInterval = 0; - m_LastAutoStartTime = GetTime( ); - m_AutoStartPlayers = 0; - m_LastCountDownTicks = 0; - m_CountDownCounter = 0; - m_StartedLoadingTicks = 0; - m_StartPlayers = 0; - m_LastLagScreenResetTime = 0; - m_LastActionSentTicks = 0; - m_LastActionLateBy = 0; - m_StartedLaggingTime = 0; - m_LastLagScreenTime = 0; - m_LastReservedSeen = GetTime( ); - m_StartedKickVoteTime = 0; - m_GameOverTime = 0; - m_LastPlayerLeaveTicks = 0; - m_MinimumScore = 0.0; - m_MaximumScore = 0.0; - m_SlotInfoChanged = false; - m_Locked = false; - m_RefreshMessages = m_GHost->m_RefreshMessages; - m_RefreshError = false; - m_RefreshRehosted = false; - m_MuteAll = false; - m_MuteLobby = false; - m_CountDownStarted = false; - m_GameLoading = false; - m_GameLoaded = false; - m_LoadInGame = m_Map->GetMapLoadInGame( ); - m_Lagging = false; - m_AutoSave = m_GHost->m_AutoSave; - m_MatchMaking = false; - m_LocalAdminMessages = m_GHost->m_LocalAdminMessages; if( m_SaveGame ) { diff --git a/ghost/gameplayer.cpp b/ghost/gameplayer.cpp index 4a0779c..e6a8a95 100644 --- a/ghost/gameplayer.cpp +++ b/ghost/gameplayer.cpp @@ -311,20 +311,30 @@ bool CGamePlayer :: Update( void *fd ) // in cases other than the ones covered here m_LeftReason should have been set when m_DeleteMe was set if( m_Error ) + { m_Game->EventPlayerDisconnectPlayerError( this ); + m_Socket->Reset( ); + return Deleting; + } if( m_Socket ) { if( m_Socket->HasError( ) ) + { m_Game->EventPlayerDisconnectSocketError( this ); - - if( !m_Socket->GetConnected( ) ) + m_Socket->Reset( ); + } + else if( !m_Socket->GetConnected( ) ) + { m_Game->EventPlayerDisconnectConnectionClosed( this ); + m_Socket->Reset( ); + } } return Deleting; -} +} + void CGamePlayer :: ExtractPackets( ) { if( !m_Socket ) diff --git a/ghost/gameslot.cpp b/ghost/gameslot.cpp index 31f3197..dd47796 100644 --- a/ghost/gameslot.cpp +++ b/ghost/gameslot.cpp @@ -25,7 +25,8 @@ // CGameSlot // -CGameSlot :: CGameSlot( BYTEARRAY &n ) +CGameSlot :: CGameSlot( BYTEARRAY &n ) : m_PID( 0 ), m_DownloadStatus( 255 ), m_SlotStatus( SLOTSTATUS_OPEN ), m_Computer( 0 ), m_Team( 0 ), + m_Colour( 1 ), m_Race( SLOTRACE_RANDOM ), m_ComputerType( SLOTCOMP_NORMAL ), m_Handicap( 100 ) { if( n.size( ) >= 7 ) { @@ -39,25 +40,9 @@ CGameSlot :: CGameSlot( BYTEARRAY &n ) if( n.size( ) >= 8 ) m_ComputerType = n[7]; - else - m_ComputerType = SLOTCOMP_NORMAL; if( n.size( ) >= 9 ) m_Handicap = n[8]; - else - m_Handicap = 100; - } - else - { - m_PID = 0; - m_DownloadStatus = 255; - m_SlotStatus = SLOTSTATUS_OPEN; - m_Computer = 0; - m_Team = 0; - m_Colour = 1; - m_Race = SLOTRACE_RANDOM; - m_ComputerType = SLOTCOMP_NORMAL; - m_Handicap = 100; } } diff --git a/ghost/map.cpp b/ghost/map.cpp index 48d00df..b78c24f 100644 --- a/ghost/map.cpp +++ b/ghost/map.cpp @@ -36,28 +36,26 @@ // CMap :: CMap( CGHost *nGHost ) - : m_GHost( nGHost ), m_Valid( true ), m_MapPath( "Maps\\FrozenThrone\\(12)EmeraldGardens.w3x" ), m_MapSpeed( MAPSPEED_FAST ), - m_MapVisibility( MAPVIS_DEFAULT ), m_MapObservers( MAPOBS_NONE ), m_MapFlags( MAPFLAG_TEAMSTOGETHER | MAPFLAG_FIXEDTEAMS ), - m_MapFilterMaker( MAPFILTER_MAKER_BLIZZARD ), m_MapFilterType( MAPFILTER_TYPE_MELEE ), m_MapFilterSize( MAPFILTER_SIZE_LARGE ), - m_MapFilterObs( MAPFILTER_OBS_NONE ), m_MapOptions( MAPOPT_MELEE ), m_MapLoadInGame( false ), m_MapNumPlayers( 12 ), m_MapNumTeams( 12 ), MessageLogger( nGHost ) + : m_GHost( nGHost ), m_Valid( true ), m_MapPath( "Maps\\FrozenThrone\\(12)EmeraldGardens.w3x" ), m_MapSize( UTIL_ExtractNumbers( "174 221 4 0", 4 ) ), + m_MapInfo( UTIL_ExtractNumbers( "251 57 68 98", 4 ) ), m_MapCRC( UTIL_ExtractNumbers( "108 250 204 59", 4 ) ), + m_MapSHA1( UTIL_ExtractNumbers( "35 81 104 182 223 63 204 215 1 17 87 234 220 66 3 185 82 99 6 13", 20 ) ), m_MapSpeed( MAPSPEED_FAST ), + m_MapVisibility( MAPVIS_DEFAULT ), m_MapObservers( MAPOBS_NONE ), m_MapFlags( MAPFLAG_TEAMSTOGETHER | MAPFLAG_FIXEDTEAMS ), + m_MapFilterMaker( MAPFILTER_MAKER_BLIZZARD ), m_MapFilterType( MAPFILTER_TYPE_MELEE ), m_MapFilterSize( MAPFILTER_SIZE_LARGE ), + m_MapFilterObs( MAPFILTER_OBS_NONE ), m_MapOptions( MAPOPT_MELEE ), m_MapWidth( UTIL_ExtractNumbers( "172 0", 2 ) ), + m_MapHeight( UTIL_ExtractNumbers( "172 0", 2 ) ), m_MapLoadInGame( false ), m_MapNumPlayers( 12 ), m_MapNumTeams( 12 ), + MessageLogger( nGHost ) { CONSOLE_Print( "[MAP] using hardcoded Emerald Gardens map data for Warcraft 3 version 1.24 & 1.24b" ); - m_MapSize = UTIL_ExtractNumbers( "174 221 4 0", 4 ); - m_MapInfo = UTIL_ExtractNumbers( "251 57 68 98", 4 ); - m_MapCRC = UTIL_ExtractNumbers( "108 250 204 59", 4 ); - m_MapSHA1 = UTIL_ExtractNumbers( "35 81 104 182 223 63 204 215 1 17 87 234 220 66 3 185 82 99 6 13", 20 ); - m_MapWidth = UTIL_ExtractNumbers( "172 0", 2 ); - m_MapHeight = UTIL_ExtractNumbers( "172 0", 2 ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 0, 0, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 1, 1, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 2, 2, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 3, 3, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 4, 4, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 5, 5, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 6, 6, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 7, 7, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 8, 8, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); - m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 9, 9, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 0, 0, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 1, 1, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 2, 2, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 3, 3, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 4, 4, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 5, 5, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 6, 6, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 7, 7, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 8, 8, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); + m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 9, 9, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 10, 10, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); m_Slots.push_back( CGameSlot( 0, 255, SLOTSTATUS_OPEN, 0, 11, 11, SLOTRACE_RANDOM | SLOTRACE_SELECTABLE ) ); } From 61e79ea95653fe12d05242506b4f33351388b3d5 Mon Sep 17 00:00:00 2001 From: "MyFakeAcc.4@googlemail.com" Date: Tue, 5 Jul 2011 20:02:56 +0000 Subject: [PATCH 6/7] Default war3 patch version set to 26 --- ghost/ghost.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ghost/ghost.cpp b/ghost/ghost.cpp index 72a0f23..eae26eb 100644 --- a/ghost/ghost.cpp +++ b/ghost/ghost.cpp @@ -519,8 +519,8 @@ CGHost :: CGHost( MessageLogger *logger, CConfig *CFG ) m_AdminGamePort = CFG->GetInt( "admingame_port", 6113 ); m_AdminGamePassword = CFG->GetString( "admingame_password", string( ) ); m_AdminGameMap = CFG->GetString( "admingame_map", string( ) ); - m_LANWar3Version = CFG->GetInt( "lan_war3version", 24 ); - m_ReplayWar3Version = CFG->GetInt( "replay_war3version", 24 ); + m_LANWar3Version = CFG->GetInt( "lan_war3version", 26 ); + m_ReplayWar3Version = CFG->GetInt( "replay_war3version", 26 ); m_ReplayBuildNumber = CFG->GetInt( "replay_buildnumber", 6059 ); SetConfigs( CFG ); @@ -571,7 +571,7 @@ CGHost :: CGHost( MessageLogger *logger, CConfig *CFG ) string BNLSServer = CFG->GetString( Prefix + "bnlsserver", string( ) ); int BNLSPort = CFG->GetInt( Prefix + "bnlsport", 9367 ); int BNLSWardenCookie = CFG->GetInt( Prefix + "bnlswardencookie", 0 ); - unsigned char War3Version = CFG->GetInt( Prefix + "custom_war3version", 24 ); + unsigned char War3Version = CFG->GetInt( Prefix + "custom_war3version", 26 ); BYTEARRAY EXEVersion = UTIL_ExtractNumbers( CFG->GetString( Prefix + "custom_exeversion", string( ) ), 4 ); BYTEARRAY EXEVersionHash = UTIL_ExtractNumbers( CFG->GetString( Prefix + "custom_exeversionhash", string( ) ), 4 ); string PasswordHashType = CFG->GetString( Prefix + "custom_passwordhashtype", string( ) ); From 35725344546bb0c50d0941f6207ec59a662ecbe1 Mon Sep 17 00:00:00 2001 From: "MyFakeAcc.4@googlemail.com" Date: Tue, 19 Jul 2011 08:47:21 +0000 Subject: [PATCH 7/7] see: r571 --- ghost/game_base.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/ghost/game_base.cpp b/ghost/game_base.cpp index e5ef108..b6289f9 100644 --- a/ghost/game_base.cpp +++ b/ghost/game_base.cpp @@ -1670,34 +1670,32 @@ void CBaseGame :: EventPlayerJoined( CPotentialPlayer *potential, CIncomingJoinP uint32_t HostCounterID = joinPlayer->GetHostCounter( ) >> 28; string JoinedRealm; - // we use an ID value of 0 to denote joining via LAN - - if( HostCounterID == 0 ) + + for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) + { + if( (*i)->GetHostCounterID( ) == HostCounterID ) + JoinedRealm = (*i)->GetServer( ); + } + + if( JoinedRealm.empty( ) ) { // the player is pretending to join via LAN, which they might or might not be (i.e. it could be spoofed) // however, we've been broadcasting a random entry key to the LAN // if the player is really on the LAN they'll know the entry key, otherwise they won't // or they're very lucky since it's a 32 bit number - + if( joinPlayer->GetEntryKey( ) != m_EntryKey ) { // oops! - + CONSOLE_Print( "[GAME: " + m_GameName + "] player [" + joinPlayer->GetName( ) + "|" + potential->GetExternalIPString( ) + "] is trying to join the game over LAN but used an incorrect entry key" ); potential->Send( m_Protocol->SEND_W3GS_REJECTJOIN( REJECTJOIN_WRONGPASSWORD ) ); potential->SetDeleteMe( true ); return; } } - else - { - for( vector :: iterator i = m_GHost->m_BNETs.begin( ); i != m_GHost->m_BNETs.end( ); ++i ) - { - if( (*i)->GetHostCounterID( ) == HostCounterID ) - JoinedRealm = (*i)->GetServer( ); - } - } - + + // check if the new player's name is banned but only if bot_banmethod is not 0 // this is because if bot_banmethod is 0 and we announce the ban here it's possible for the player to be rejected later because the game is full // this would allow the player to spam the chat by attempting to join the game multiple times in a row