diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 726d3ab70..d85a0ef70 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -72,6 +72,9 @@ #endif #include + +//#include "network_message.h" +//#include "network_protocol.h" #include "leak_dumper.h" #ifdef WIN32 @@ -3076,15 +3079,65 @@ int glestMain(int argc, char** argv) { printf("%s %s",extractFileFromDirectoryPath(argv[0]).c_str(),getNetworkPlatformFreeVersionString().c_str()); printf("\nCompiled using: %s on: %s platform: %s endianness: %s",getCompilerNameString().c_str(),getCompileDateTime().c_str(),getPlatformNameString().c_str(),(Shared::PlatformByteOrder::isBigEndian() == true ? "big" : "little")); - int8 testVar = 111; - printf("\nEndian value = %d",testVar); - testVar = Shared::PlatformByteOrder::toCommonEndian(testVar); - printf("\nEndian to common value = %d",testVar); - testVar = Shared::PlatformByteOrder::fromCommonEndian(testVar); - printf("\nEndian from common value = %d",testVar); - printf("\nint8 sizeof = %zu",sizeof(int8)); - printf("\nSwitchSetupRequest sizeof = %zu",SwitchSetupRequest().getDataSize()); +// SwitchSetupRequest data("factionname", 3,-1,2,"softcoder",10, 11,"eng"); +// +// unsigned char *buf = data.packMessage(); +// printf("\nSend packet size = %u\n%s\nTeam = %d faction [%s] currentFactionIndex = %d toFactionIndex = %d [%s] [%s] %d %d\n",data.getPackedSize(),buf,data.getToTeam(),data.getSelectedFactionName().c_str(),data.getCurrentFactionIndex(),data.getToFactionIndex(),data.getNetworkPlayerLanguage().c_str(),data.getNetworkPlayerName().c_str(),data.getNetworkPlayerStatus(),data.getSwitchFlags()); +// //delete [] buf; +// +// data.unpackMessage(buf); +// printf("\nGot packet size = %u\n%s\nTeam = %d faction [%s] currentFactionIndex = %d toFactionIndex = %d [%s] [%s] %d %d\n",data.getPackedSize(),buf,data.getToTeam(),data.getSelectedFactionName().c_str(),data.getCurrentFactionIndex(),data.getToFactionIndex(),data.getNetworkPlayerLanguage().c_str(),data.getNetworkPlayerName().c_str(),data.getNetworkPlayerStatus(),data.getSwitchFlags()); +// delete [] buf; + +// int8 a = 1; +// uint8 b = 2; +// int16 c = 3; +// uint16 d = 4; +// int32 e = 5; +// uint32 f = 6; +// +// printf("\nPack test #1: [%d][%u][%d][%u][%d][%u]\n,",a,b,c,d,e,f); +// +// unsigned char *buf = new unsigned char[100]; +// unsigned int packedsize = pack(buf, "cChHlL", +// a, +// b, +// c, +// d, +// e, +// f); +// +// printf("Pack test #2: [%u][%s]\n,",packedsize,buf); +// +// int8 a1 = 0; +// uint8 b1 = 0; +// int16 c1 = 0; +// uint16 d1 = 0; +// int32 e1 = 0; +// uint32 f1 = 0; +// +// unpack(buf, "cChHlL", +// &a1, +// &b1, +// &c1, +// &d1, +// &e1, +// &f1); +// +// printf("UnPack test #3: [%d][%u][%d][%u][%d][%u]\n,",a1,b1,c1,d1,e1,f1); + + if(SystemFlags::VERBOSE_MODE_ENABLED == true) { + int8 testVar = 111; + printf("\nEndian value = %d",testVar); + testVar = Shared::PlatformByteOrder::toCommonEndian(testVar); + printf("\nEndian to common value = %d",testVar); + testVar = Shared::PlatformByteOrder::fromCommonEndian(testVar); + printf("\nEndian from common value = %d",testVar); + + printf("\nint8 sizeof = %zu",sizeof(int8)); + printf("\nSwitchSetupRequest sizeof = %zu",SwitchSetupRequest().getDataSize()); + } printf("\nSVN: [%s]",getSVNRevisionString().c_str()); @@ -3248,6 +3301,11 @@ int glestMain(int argc, char** argv) { config.setBool("DebugNetworkPackets",true,true); } + if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_ENABLE_NEW_PROTOCOL]) == true) { + printf("*NOTE: enabling new newtork protocol.\n"); + NetworkMessage::useOldProtocol = false; + } + Socket::setBroadCastPort(config.getInt("BroadcastPort",intToStr(Socket::getBroadCastPort()).c_str())); Socket::disableNagle = config.getBool("DisableNagle","false"); diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index b8d6faa0a..aee5f8c7f 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -46,7 +46,7 @@ const int ClientInterface::waitSleepTime= 10; const int ClientInterface::maxNetworkCommandListSendTimeWait = 4; ClientInterface::ClientInterface() : GameNetworkInterface() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] constructor for %p\n",__FILE__,__FUNCTION__,__LINE__,this); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] constructor for %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this); networkCommandListThreadAccessor = new Mutex(); networkCommandListThread = NULL; @@ -88,12 +88,12 @@ void ClientInterface::shutdownNetworkCommandListThread() { } ClientInterface::~ClientInterface() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] destructor for %p\n",__FILE__,__FUNCTION__,__LINE__,this); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] destructor for %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this); shutdownNetworkCommandListThread(); if(clientSocket != NULL && clientSocket->isConnected() == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); Lang &lang= Lang::getInstance(); const vector languageList = this->gameSettings.getUniqueNetworkPlayerLanguages(); @@ -106,9 +106,9 @@ ClientInterface::~ClientInterface() { } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); close(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); delete clientSocket; clientSocket = NULL; @@ -116,11 +116,11 @@ ClientInterface::~ClientInterface() { delete networkCommandListThreadAccessor; networkCommandListThreadAccessor = NULL; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ClientInterface::connect(const Ip &ip, int port) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); this->ip = ip; this->port = port; @@ -132,7 +132,7 @@ void ClientInterface::connect(const Ip &ip, int port) { connectedTime = time(NULL); clientSocket->setBlock(true); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END - socket = %d\n",__FILE__,__FUNCTION__,clientSocket->getSocketId()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END - socket = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,clientSocket->getSocketId()); } void ClientInterface::reset() { @@ -168,30 +168,30 @@ void ClientInterface::update() { double lastSendElapsed = difftime((long int)time(NULL),lastNetworkCommandListSendTime); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(networkMessageCommandList.getCommandCount() > 0 || (lastNetworkCommandListSendTime > 0 && lastSendElapsed >= ClientInterface::maxNetworkCommandListSendTimeWait)) { lastNetworkCommandListSendTime = time(NULL); sendMessage(&networkMessageCommandList); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } // Possible cause of out of synch since we have more commands that need // to be sent in this frame if(requestedCommands.empty() == false) { //char szBuf[4096]=""; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,requestedCommands.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,requestedCommands.size()); string sMsg = "may go out of synch: client requestedCommands.size() = " + intToStr(requestedCommands.size()); sendTextMessage(sMsg,-1, true,""); sleep(1); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } std::string ClientInterface::getServerIpAddress() { @@ -216,16 +216,16 @@ void ClientInterface::updateLobby() { serverName= networkMessageIntro.getName(); serverFTPPort = networkMessageIntro.getFtpPort(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got NetworkMessageIntro, networkMessageIntro.getGameState() = %d, versionString [%s], sessionKey = %d, playerIndex = %d, serverFTPPort = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageIntro.getGameState(),versionString.c_str(),sessionKey,playerIndex,serverFTPPort); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got NetworkMessageIntro, networkMessageIntro.getGameState() = %d, versionString [%s], sessionKey = %d, playerIndex = %d, serverFTPPort = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageIntro.getGameState(),versionString.c_str(),sessionKey,playerIndex,serverFTPPort); //check consistency bool compatible = checkVersionComptability(networkMessageIntro.getVersionString(), getNetworkVersionSVNString()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got NetworkMessageIntro, networkMessageIntro.getGameState() = %d, versionString [%s], sessionKey = %d, playerIndex = %d, serverFTPPort = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageIntro.getGameState(),versionString.c_str(),sessionKey,playerIndex,serverFTPPort); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got NetworkMessageIntro, networkMessageIntro.getGameState() = %d, versionString [%s], sessionKey = %d, playerIndex = %d, serverFTPPort = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageIntro.getGameState(),versionString.c_str(),sessionKey,playerIndex,serverFTPPort); if(compatible == false) { //if(networkMessageIntro.getVersionString() != getNetworkVersionString()) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); bool versionMatched = false; string platformFreeVersion = getNetworkPlatformFreeVersionString(); @@ -262,10 +262,10 @@ void ClientInterface::updateLobby() { } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(networkMessageIntro.getGameState() == nmgstOk) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); //send intro message Lang &lang= Lang::getInstance(); @@ -279,21 +279,21 @@ void ClientInterface::updateLobby() { lang.getLanguage()); sendMessage(&sendNetworkMessageIntro); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(clientSocket == NULL || clientSocket->isConnected() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); string sErr = "Disconnected from server during intro handshake."; DisplayErrorMessage(sErr); quit= true; close(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return; } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); assert(playerIndex>=0 && playerIndexsetNetworkGameDataSynchCheckOkTile((tilesetCRC == networkMessageSynchNetworkGameData.getTilesetCRC())); //if(this->getNetworkGameDataSynchCheckOkTile() == false) //{ - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] tilesetCRC info, local = %d, remote = %d, networkMessageSynchNetworkGameData.getTileset() = [%s]\n",__FILE__,__FUNCTION__,__LINE__,tilesetCRC,networkMessageSynchNetworkGameData.getTilesetCRC(),networkMessageSynchNetworkGameData.getTileset().c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] tilesetCRC info, local = %d, remote = %d, networkMessageSynchNetworkGameData.getTileset() = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,tilesetCRC,networkMessageSynchNetworkGameData.getTilesetCRC(),networkMessageSynchNetworkGameData.getTileset().c_str()); //} //tech, load before map because of resources @@ -377,12 +377,12 @@ void ClientInterface::updateLobby() { this->setNetworkGameDataSynchCheckOkTech((techCRC == networkMessageSynchNetworkGameData.getTechCRC())); if(this->getNetworkGameDataSynchCheckOkTech() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); string pathSearchString = "/" + networkMessageSynchNetworkGameData.getTech() + "/*"; vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),pathSearchString, ".xml", NULL); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); string report = networkMessageSynchNetworkGameData.getTechCRCFileMismatchReport(vctFileList); this->setNetworkGameDataSynchCheckTechMismatchReport(report); @@ -390,7 +390,7 @@ void ClientInterface::updateLobby() { } //if(this->getNetworkGameDataSynchCheckOkTech() == false) //{ - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] techCRC info, local = %d, remote = %d, networkMessageSynchNetworkGameData.getTech() = [%s]\n",__FILE__,__FUNCTION__,techCRC,networkMessageSynchNetworkGameData.getTechCRC(),networkMessageSynchNetworkGameData.getTech().c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] techCRC info, local = %d, remote = %d, networkMessageSynchNetworkGameData.getTech() = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,techCRC,networkMessageSynchNetworkGameData.getTechCRC(),networkMessageSynchNetworkGameData.getTech().c_str()); //} //map @@ -405,13 +405,13 @@ void ClientInterface::updateLobby() { //if(this->getNetworkGameDataSynchCheckOkMap() == false) //{ - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] mapCRC info, local = %d, remote = %d, file = [%s]\n",__FILE__,__FUNCTION__,__LINE__,mapCRC,networkMessageSynchNetworkGameData.getMapCRC(),file.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] mapCRC info, local = %d, remote = %d, file = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,mapCRC,networkMessageSynchNetworkGameData.getMapCRC(),file.c_str()); //} } catch(const runtime_error &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); string sErr = ex.what(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error during processing, sErr = [%s]\n",__FILE__,__FUNCTION__,__LINE__,sErr.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error during processing, sErr = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,sErr.c_str()); DisplayErrorMessage(sErr); } @@ -435,7 +435,7 @@ void ClientInterface::updateLobby() { if(fileCRC != networkMessageSynchNetworkGameDataFileCRCCheck.getFileCRC()) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileCRCCheck localCRC = %d, remoteCRC = %d, file [%s]\n", - __FILE__,__FUNCTION__,fileCRC, + extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,fileCRC, networkMessageSynchNetworkGameDataFileCRCCheck.getFileCRC(), networkMessageSynchNetworkGameDataFileCRCCheck.getFileName().c_str()); @@ -472,7 +472,7 @@ void ClientInterface::updateLobby() { NetworkMessageText networkMessageText; if(receiveMessage(&networkMessageText)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getTeamIndex(),networkMessageText.getPlayerIndex(),networkMessageText.getTargetLanguage()); this->addChatInfo(msg); @@ -484,7 +484,7 @@ void ClientInterface::updateLobby() { { NetworkMessageMarkCell networkMessageMarkCell; if(receiveMessage(&networkMessageMarkCell)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtMarkCell\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtMarkCell\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); MarkedCell msg(networkMessageMarkCell.getTarget(), networkMessageMarkCell.getFactionIndex(), @@ -498,7 +498,7 @@ void ClientInterface::updateLobby() { { NetworkMessageUnMarkCell networkMessageMarkCell; if(receiveMessage(&networkMessageMarkCell)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtMarkCell\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtMarkCell\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); UnMarkedCell msg(networkMessageMarkCell.getTarget(), networkMessageMarkCell.getFactionIndex()); @@ -510,7 +510,7 @@ void ClientInterface::updateLobby() { { NetworkMessageHighlightCell networkMessageHighlightCell; if(receiveMessage(&networkMessageHighlightCell)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtHighlightCell\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtHighlightCell\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); MarkedCell msg(networkMessageHighlightCell.getTarget(), networkMessageHighlightCell.getFactionIndex(), @@ -526,22 +526,22 @@ void ClientInterface::updateLobby() { NetworkMessageLaunch networkMessageLaunch; if(receiveMessage(&networkMessageLaunch)) { if(networkMessageLaunch.getMessageType() == nmtLaunch) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got nmtLaunch\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got nmtLaunch\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } else if(networkMessageLaunch.getMessageType() == nmtBroadCastSetup) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got nmtBroadCastSetup\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got nmtBroadCastSetup\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got networkMessageLaunch.getMessageType() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got networkMessageLaunch.getMessageType() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); char szBuf[1024]=""; - snprintf(szBuf,1023,"In [%s::%s Line: %d] Invalid networkMessageLaunch.getMessageType() = %d",__FILE__,__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); + snprintf(szBuf,1023,"In [%s::%s Line: %d] Invalid networkMessageLaunch.getMessageType() = %d",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); throw megaglest_runtime_error(szBuf); } networkMessageLaunch.buildGameSettings(&gameSettings); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got networkMessageLaunch.getMessageType() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got networkMessageLaunch.getMessageType() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); //replace server player by network for(int i= 0; iisConnected() == true && gotIntro == false && difftime((long int)time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %f\n",__FILE__,__FUNCTION__,__LINE__,difftime((long int)time(NULL),connectedTime)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %f\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,difftime((long int)time(NULL),connectedTime)); close(); } } @@ -640,7 +640,7 @@ void ClientInterface::updateFrame(int *checkFrame) { // waitCount++; // } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] receiveMessage took %lld msecs, waitCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitCount); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] receiveMessage took %lld msecs, waitCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),waitCount); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); //check that we are in the right frame if(checkFrame != NULL) { @@ -665,7 +665,7 @@ void ClientInterface::updateFrame(int *checkFrame) { //pendingCommands.push_back(*networkMessageCommandList.getCommand(i)); cachedPendingCommands[networkMessageCommandList.getFrameCount()].push_back(*networkMessageCommandList.getCommand(i)); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] transfer network commands took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] transfer network commands took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); done= true; } @@ -673,15 +673,15 @@ void ClientInterface::updateFrame(int *checkFrame) { case nmtPing: { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtPing\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtPing\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); NetworkMessagePing networkMessagePing; if(receiveMessage(&networkMessagePing)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); lastPingInfo = networkMessagePing; } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } break; @@ -712,12 +712,12 @@ void ClientInterface::updateFrame(int *checkFrame) { throw megaglest_runtime_error("error retrieving nmtText returned false!"); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getTeamIndex(),networkMessageText.getPlayerIndex(),networkMessageText.getTargetLanguage()); this->addChatInfo(msg); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } break; @@ -725,7 +725,7 @@ void ClientInterface::updateFrame(int *checkFrame) { { NetworkMessageMarkCell networkMessageMarkCell; if(receiveMessage(&networkMessageMarkCell)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtMarkCell\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtMarkCell\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); MarkedCell msg(networkMessageMarkCell.getTarget(), networkMessageMarkCell.getFactionIndex(), @@ -740,7 +740,7 @@ void ClientInterface::updateFrame(int *checkFrame) { { NetworkMessageUnMarkCell networkMessageMarkCell; if(receiveMessage(&networkMessageMarkCell)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtMarkCell\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtMarkCell\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); UnMarkedCell msg(networkMessageMarkCell.getTarget(), networkMessageMarkCell.getFactionIndex()); @@ -752,7 +752,7 @@ void ClientInterface::updateFrame(int *checkFrame) { { NetworkMessageHighlightCell networkMessageHighlightCell; if(receiveMessage(&networkMessageHighlightCell)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtHighlightCell\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtHighlightCell\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); MarkedCell msg(networkMessageHighlightCell.getTarget(), networkMessageHighlightCell.getFactionIndex(), @@ -769,22 +769,22 @@ void ClientInterface::updateFrame(int *checkFrame) { NetworkMessageLaunch networkMessageLaunch; if(receiveMessage(&networkMessageLaunch)) { if(networkMessageLaunch.getMessageType() == nmtLaunch) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got nmtLaunch\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got nmtLaunch\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } else if(networkMessageLaunch.getMessageType() == nmtBroadCastSetup) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got nmtBroadCastSetup\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got nmtBroadCastSetup\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got networkMessageLaunch.getMessageType() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got networkMessageLaunch.getMessageType() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); char szBuf[1024]=""; - snprintf(szBuf,1023,"In [%s::%s Line: %d] Invalid networkMessageLaunch.getMessageType() = %d",__FILE__,__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); + snprintf(szBuf,1023,"In [%s::%s Line: %d] Invalid networkMessageLaunch.getMessageType() = %d",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); throw megaglest_runtime_error(szBuf); } networkMessageLaunch.buildGameSettings(&gameSettings); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got networkMessageLaunch.getMessageType() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got networkMessageLaunch.getMessageType() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType()); //replace server player by network for(int i= 0; igetQuitStatus() == false && quit == false) { updateFrame(NULL); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } bool ClientInterface::getNetworkCommand(int frameCount, int currentCachedPendingCommandsIndex) { @@ -902,7 +902,7 @@ void ClientInterface::updateKeyframe(int frameCount) { else { if(networkCommandListThread == NULL) { networkCommandListThread = new SimpleTaskThread(this,0,0); - networkCommandListThread->setUniqueID(__FILE__); + networkCommandListThread->setUniqueID(extractFileFromDirectoryPath(__FILE__).c_str()); networkCommandListThread->start(); } @@ -910,8 +910,8 @@ void ClientInterface::updateKeyframe(int frameCount) { } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); - //printf("In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); + //printf("In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } bool ClientInterface::isMasterServerAdminOverride() { @@ -919,7 +919,7 @@ bool ClientInterface::isMasterServerAdminOverride() { } void ClientInterface::waitUntilReady(Checksum* checksum) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); Logger &logger= Logger::getInstance(); @@ -934,7 +934,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { NetworkMessageReady networkMessageReady; sendMessage(&networkMessageReady); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); NetworkMessageLoadingStatus networkMessageLoadingStatus(nmls_NONE); @@ -958,17 +958,17 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { } if(isConnected() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); string sErr = "Error, Server has disconnected!"; DisplayErrorMessage(sErr); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); quit= true; close(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return; } NetworkMessageType networkMessageType = getNextMessageType(); @@ -978,35 +978,35 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { if(discarded == false) { if(networkMessageType == nmtReady) { if(receiveMessage(&networkMessageReady)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); break; } } else if(networkMessageType == nmtLoadingStatusMessage) { if(receiveMessage(&networkMessageLoadingStatus)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } } else if(networkMessageType == nmtQuit) { NetworkMessageQuit networkMessageQuit; if(receiveMessage(&networkMessageQuit)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); DisplayErrorMessage(lang.get("GameCancelledByUser")); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); quit= true; close(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return; } } else if(networkMessageType == nmtInvalid) { if(chrono.getMillis() > readyWaitTimeout) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); Lang &lang= Lang::getInstance(); const vector languageList = this->gameSettings.getUniqueNetworkPlayerLanguages(); @@ -1023,13 +1023,13 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); sleep(1); quit= true; close(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return; } else { @@ -1128,20 +1128,20 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { } } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); sendTextMessage("Unexpected network message: " + intToStr(networkMessageType),-1, true,""); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - DisplayErrorMessage(string(__FILE__) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType)); + DisplayErrorMessage(string(extractFileFromDirectoryPath(__FILE__).c_str()) + "::" + string(__FUNCTION__) + " Unexpected network message: " + intToStr(networkMessageType)); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); sleep(1); quit= true; close(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return; } @@ -1151,11 +1151,11 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); //check checksum if(networkMessageReady.getChecksum() != checksum->getSum()) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); Lang &lang= Lang::getInstance(); const vector languageList = this->gameSettings.getUniqueNetworkPlayerLanguages(); @@ -1186,12 +1186,12 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { } sendTextMessage(sErr2,-1,echoLocal,languageList[i]); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d %s %s %s\n",__FILE__,__FUNCTION__,__LINE__,sErr.c_str(),sErr1.c_str(),sErr2.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d %s %s %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,sErr.c_str(),sErr1.c_str(),sErr2.c_str()); if(echoLocal == true) { if(Config::getInstance().getBool("NetworkConsistencyChecks")) { // error message and disconnect only if checked - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); string niceError = sErr + string("\n") + sErr1 + string("\n") + sErr2; DisplayErrorMessage(niceError); @@ -1212,11 +1212,11 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { // string sErr2 = "Server Checksum: " + intToStr(networkMessageReady.getChecksum()); // sendTextMessage(sErr2,-1, true); -// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d %s %s %s\n",__FILE__,__FUNCTION__,__LINE__,sErr.c_str(),sErr1.c_str(),sErr2.c_str()); +// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d %s %s %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,sErr.c_str(),sErr1.c_str(),sErr2.c_str()); if(Config::getInstance().getBool("NetworkConsistencyChecks")) { // error message and disconnect only if checked - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); //string niceError = sErr + string("\n") + sErr1 + string("\n") + sErr2; //DisplayErrorMessage(niceError); @@ -1224,7 +1224,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { sleep(1); quit= true; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); close(); } @@ -1239,14 +1239,14 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { // This triggers LAG update packets to begin as required lastNetworkCommandListSendTime = time(NULL); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); } void ClientInterface::sendTextMessage(const string &text, int teamIndex, bool echoLocal, string targetLanguage) { string humanPlayerName = getHumanPlayerName(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] humanPlayerName = [%s] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,humanPlayerName.c_str(),playerIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] humanPlayerName = [%s] playerIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,humanPlayerName.c_str(),playerIndex); NetworkMessageText networkMessageText(text, teamIndex,playerIndex,targetLanguage); sendMessage(&networkMessageText); @@ -1259,14 +1259,14 @@ void ClientInterface::sendTextMessage(const string &text, int teamIndex, bool ec void ClientInterface::sendMarkCellMessage(Vec2i targetPos, int factionIndex, string note,int playerIndex) { string humanPlayerName = getHumanPlayerName(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] humanPlayerName = [%s] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,humanPlayerName.c_str(),playerIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] humanPlayerName = [%s] playerIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,humanPlayerName.c_str(),playerIndex); NetworkMessageMarkCell networkMessageMarkCell(targetPos,factionIndex, note,playerIndex); sendMessage(&networkMessageMarkCell); } void ClientInterface::sendHighlightCellMessage(Vec2i targetPos, int factionIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex); NetworkMessageHighlightCell networkMessageHighlightCell(targetPos,factionIndex); sendMessage(&networkMessageHighlightCell); @@ -1274,7 +1274,7 @@ void ClientInterface::sendHighlightCellMessage(Vec2i targetPos, int factionIndex void ClientInterface::sendUnMarkCellMessage(Vec2i targetPos, int factionIndex) { string humanPlayerName = getHumanPlayerName(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] humanPlayerName = [%s] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,humanPlayerName.c_str(),playerIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] humanPlayerName = [%s] playerIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,humanPlayerName.c_str(),playerIndex); NetworkMessageUnMarkCell networkMessageMarkCell(targetPos,factionIndex); sendMessage(&networkMessageMarkCell); @@ -1328,7 +1328,7 @@ NetworkMessageType ClientInterface::waitForMessage() //if(1) { //throw megaglest_runtime_error("Timeout waiting for message"); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); Lang &lang= Lang::getInstance(); const vector languageList = this->gameSettings.getUniqueNetworkPlayerLanguages(); @@ -1358,19 +1358,19 @@ NetworkMessageType ClientInterface::waitForMessage() //waitLoopCount++; } - //if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %lld msecs, waitLoopCount = %ull, msg = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitLoopCount,msg); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %lld msecs, msg = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),msg); + //if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %lld msecs, waitLoopCount = %ull, msg = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),waitLoopCount,msg); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %lld msecs, msg = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),msg); return msg; } void ClientInterface::quitGame(bool userManuallyQuit) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] userManuallyQuit = %d\n",__FILE__,__FUNCTION__,__LINE__,userManuallyQuit); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] userManuallyQuit = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,userManuallyQuit); if(clientSocket != NULL && userManuallyQuit == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); Lang &lang= Lang::getInstance(); const vector languageList = this->gameSettings.getUniqueNetworkPlayerLanguages(); @@ -1386,12 +1386,12 @@ void ClientInterface::quitGame(bool userManuallyQuit) close(); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ClientInterface::close() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] START, clientSocket = %p\n",__FILE__,__FUNCTION__,__LINE__,clientSocket); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] START, clientSocket = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,clientSocket); delete clientSocket; clientSocket= NULL; @@ -1399,34 +1399,34 @@ void ClientInterface::close() connectedTime = 0; gotIntro = false; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] END\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ClientInterface::discoverServers(DiscoveredServersInterface *cb) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); ClientSocket::discoverServers(cb); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ClientInterface::stopServerDiscovery() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); ClientSocket::stopBroadCastClientThread(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ClientInterface::sendSwitchSetupRequest(string selectedFactionName, int8 currentFactionIndex, int8 toFactionIndex,int8 toTeam, string networkPlayerName, int8 networkPlayerStatus, int8 flags, string language) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] networkPlayerName [%s] flags = %d\n",__FILE__,__FUNCTION__,__LINE__,networkPlayerName.c_str(),flags); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] networkPlayerName [%s] flags = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkPlayerName.c_str(),flags); SwitchSetupRequest message=SwitchSetupRequest(selectedFactionName, currentFactionIndex, toFactionIndex,toTeam,networkPlayerName, networkPlayerStatus, flags,language); sendMessage(&message); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } bool ClientInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMessageType) { @@ -1457,7 +1457,7 @@ bool ClientInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess break; case nmtText: { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got nmtText\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got nmtText\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); discard = true; NetworkMessageText netMsg = NetworkMessageText(); this->receiveMessage(&netMsg); @@ -1580,31 +1580,31 @@ string ClientInterface::getHumanPlayerName(int index) { void ClientInterface::setGameSettings(GameSettings *serverGameSettings) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); - //MutexSafeWrapper safeMutex(&serverSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); + //MutexSafeWrapper safeMutex(&serverSynchAccessor,string(extractFileFromDirectoryPath(__FILE__).c_str()) + "_" + intToStr(__LINE__)); gameSettings = *serverGameSettings; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); } void ClientInterface::broadcastGameSetup(const GameSettings *gameSettings) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - //MutexSafeWrapper safeMutex(&serverSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + //MutexSafeWrapper safeMutex(&serverSynchAccessor,string(extractFileFromDirectoryPath(__FILE__).c_str()) + "_" + intToStr(__LINE__)); NetworkMessageLaunch networkMessageLaunch(gameSettings, nmtBroadCastSetup); //broadcastMessage(&networkMessageLaunch); sendMessage(&networkMessageLaunch); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ClientInterface::broadcastGameStart(const GameSettings *gameSettings) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - //MutexSafeWrapper safeMutex(&serverSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + //MutexSafeWrapper safeMutex(&serverSynchAccessor,string(extractFileFromDirectoryPath(__FILE__).c_str()) + "_" + intToStr(__LINE__)); NetworkMessageLaunch networkMessageLaunch(gameSettings, nmtLaunch); //broadcastMessage(&networkMessageLaunch); sendMessage(&networkMessageLaunch); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ClientInterface::setGameSettingsReceived(bool value) { - //printf("In [%s:%s] Line: %d gameSettingsReceived = %d value = %d, gameSettingsReceivedCount = %d\n",__FILE__,__FUNCTION__,__LINE__,gameSettingsReceived,value,gameSettingsReceivedCount); + //printf("In [%s:%s] Line: %d gameSettingsReceived = %d value = %d, gameSettingsReceivedCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,gameSettingsReceived,value,gameSettingsReceivedCount); gameSettingsReceived = value; gameSettingsReceivedCount++; } diff --git a/source/glest_game/network/network_interface.cpp b/source/glest_game/network/network_interface.cpp index ccc3cecc8..8164b98b6 100644 --- a/source/glest_game/network/network_interface.cpp +++ b/source/glest_game/network/network_interface.cpp @@ -19,7 +19,7 @@ #include "platform_util.h" #include #include "util.h" - +#include "network_protocol.h" #include "leak_dumper.h" using namespace Shared::Platform; @@ -54,16 +54,16 @@ NetworkMessageType NetworkInterface::getNextMessageType() if(socket != NULL && socket->hasDataToRead() == true) { //peek message type - int dataSize = socket->getDataToRead(); - if(dataSize >= sizeof(messageType)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,dataSize); + int dataSize = socket->getDataToRead(); + if(dataSize >= sizeof(messageType)) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() dataSize = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,dataSize); int iPeek = socket->peek(&messageType, sizeof(messageType)); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() iPeek = %d, messageType = %d [size = %d]\n",__FILE__,__FUNCTION__,__LINE__,iPeek,messageType,sizeof(messageType)); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() iPeek = %d, messageType = %d [size = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,iPeek,messageType,sizeof(messageType)); } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] PEEK WARNING, socket->getDataToRead() messageType = %d [size = %d], dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,messageType,sizeof(messageType),dataSize); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] PEEK WARNING, socket->getDataToRead() messageType = %d [size = %d], dataSize = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,messageType,sizeof(messageType),dataSize); } //sanity check new message type @@ -72,7 +72,7 @@ NetworkMessageType NetworkInterface::getNextMessageType() throw megaglest_runtime_error("Invalid message type: " + intToStr(messageType)); } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Invalid message type = %d (no packet handshake yet so ignored)\n",__FILE__,__FUNCTION__,__LINE__,messageType); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Invalid message type = %d (no packet handshake yet so ignored)\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,messageType); } } } @@ -82,7 +82,7 @@ NetworkMessageType NetworkInterface::getNextMessageType() bool NetworkInterface::receiveMessage(NetworkMessage* networkMessage){ - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s]\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); Socket* socket= getSocket(false); @@ -95,10 +95,10 @@ bool NetworkInterface::isConnected(){ } void NetworkInterface::DisplayErrorMessage(string sErr, bool closeSocket) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sErr [%s]\n",__FILE__,__FUNCTION__,__LINE__,sErr.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sErr [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,sErr.c_str()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] sErr [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,sErr.c_str()); - if(closeSocket == true && getSocket() != NULL) - { + if(closeSocket == true && getSocket() != NULL) { close(); } @@ -124,7 +124,7 @@ std::vector NetworkInterface::getChatTextList(bool clearList) { void NetworkInterface::clearChatInfo() { if(chatTextList.empty() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] chatTextList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,chatTextList.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] chatTextList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chatTextList.size()); chatTextList.clear(); } } @@ -143,7 +143,7 @@ std::vector NetworkInterface::getMarkedCellList(bool clearList) { void NetworkInterface::clearMarkedCellList() { if(markedCellList.empty() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] markedCellList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,markedCellList.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] markedCellList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,markedCellList.size()); markedCellList.clear(); } } @@ -162,7 +162,7 @@ std::vector NetworkInterface::getUnMarkedCellList(bool clearList) void NetworkInterface::clearUnMarkedCellList() { if(unmarkedCellList.empty() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unmarkedCellList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,unmarkedCellList.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unmarkedCellList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unmarkedCellList.size()); unmarkedCellList.clear(); } } @@ -181,7 +181,7 @@ std::vector NetworkInterface::getHighlightedCellList(bool clearList) void NetworkInterface::clearHighlightedCellList() { if(highlightedCellList.empty() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] markedCellList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,markedCellList.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] markedCellList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,markedCellList.size()); highlightedCellList.clear(); } } diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index c50240e9a..7fd12afe0 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -18,13 +18,14 @@ #include "util.h" #include "game_settings.h" -#include "leak_dumper.h" - #include "checksum.h" #include "map.h" #include "platform_util.h" #include "config.h" #include +#include "network_protocol.h" + +#include "leak_dumper.h" using namespace Shared::Platform; using namespace Shared::Util; @@ -33,6 +34,8 @@ using std::min; namespace Glest{ namespace Game{ +bool NetworkMessage::useOldProtocol = true; + // ===================================================== // class NetworkMessage // ===================================================== @@ -41,18 +44,18 @@ bool NetworkMessage::receive(Socket* socket, void* data, int dataSize, bool tryR if(socket != NULL) { int dataReceived = socket->receive(data, dataSize, tryReceiveUntilDataSizeMet); if(dataReceived != dataSize) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING, dataReceived = %d dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,dataReceived,dataSize); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nIn [%s::%s Line: %d] WARNING, dataReceived = %d dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,dataReceived,dataSize); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING, dataReceived = %d dataSize = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,dataReceived,dataSize); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nIn [%s::%s Line: %d] WARNING, dataReceived = %d dataSize = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,dataReceived,dataSize); if(socket != NULL && socket->getSocketId() > 0) { throw megaglest_runtime_error("Error receiving NetworkMessage, dataReceived = " + intToStr(dataReceived) + ", dataSize = " + intToStr(dataSize)); } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket has been disconnected\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket has been disconnected\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] dataSize = %d, dataReceived = %d\n",__FILE__,__FUNCTION__,__LINE__,dataSize,dataReceived); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] dataSize = %d, dataReceived = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,dataSize,dataReceived); dump_packet("\nINCOMING PACKET:\n",data, dataSize); return true; @@ -63,7 +66,7 @@ bool NetworkMessage::receive(Socket* socket, void* data, int dataSize, bool tryR } void NetworkMessage::send(Socket* socket, const void* data, int dataSize) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket = %p, data = %p, dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,socket,data,dataSize); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket = %p, data = %p, dataSize = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,socket,data,dataSize); if(socket != NULL) { dump_packet("\nOUTGOING PACKET:\n",data, dataSize); @@ -75,7 +78,7 @@ void NetworkMessage::send(Socket* socket, const void* data, int dataSize) { throw megaglest_runtime_error(szBuf); } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d socket has been disconnected\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d socket has been disconnected\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } } } @@ -126,22 +129,94 @@ NetworkMessageIntro::NetworkMessageIntro(int32 sessionId,const string &versionSt data.language = playerLanguage; } +const char * NetworkMessageIntro::getPackedMessageFormat() const { + return "cl128s32shcLL60s"; +} + +unsigned int NetworkMessageIntro::getPackedSize() { + static unsigned int result = 0; + if(result == 0) { + Data packedData; + unsigned char *buf = new unsigned char[sizeof(packedData)*3]; + result = pack(buf, getPackedMessageFormat(), + packedData.messageType, + packedData.sessionId, + packedData.versionString.getBuffer(), + packedData.name.getBuffer(), + packedData.playerIndex, + packedData.gameState, + packedData.externalIp, + packedData.ftpPort, + packedData.language.getBuffer()); + delete [] buf; + } + return result; +} +void NetworkMessageIntro::unpackMessage(unsigned char *buf) { + unpack(buf, getPackedMessageFormat(), + &data.messageType, + &data.sessionId, + data.versionString.getBuffer(), + data.name.getBuffer(), + &data.playerIndex, + &data.gameState, + &data.externalIp, + &data.ftpPort, + data.language.getBuffer()); +} + +unsigned char * NetworkMessageIntro::packMessage() { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + pack(buf, getPackedMessageFormat(), + data.messageType, + data.sessionId, + data.versionString.getBuffer(), + data.name.getBuffer(), + data.playerIndex, + data.gameState, + data.externalIp, + data.ftpPort, + data.language.getBuffer()); + return buf; +} + bool NetworkMessageIntro::receive(Socket* socket) { - bool result = NetworkMessage::receive(socket, &data, sizeof(data), true); + bool result = false; + if(useOldProtocol == true) { + result = NetworkMessage::receive(socket, &data, sizeof(data), true); + } + else { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + result = NetworkMessage::receive(socket, buf, getPackedSize(), true); + unpackMessage(buf); + //printf("Got packet size = %u data.messageType = %d\n%s\n",getPackedSize(),data.messageType,buf); + delete [] buf; + } fromEndian(); + data.name.nullTerminate(); data.versionString.nullTerminate(); data.language.nullTerminate(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] get nmtIntro, data.playerIndex = %d, data.sessionId = %d\n",__FILE__,__FUNCTION__,__LINE__,data.playerIndex,data.sessionId); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] get nmtIntro, data.playerIndex = %d, data.sessionId = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,data.playerIndex,data.sessionId); return result; } void NetworkMessageIntro::send(Socket* socket) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending nmtIntro, data.playerIndex = %d, data.sessionId = %d\n",__FILE__,__FUNCTION__,__LINE__,data.playerIndex,data.sessionId); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sending nmtIntro, data.playerIndex = %d, data.sessionId = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,data.playerIndex,data.sessionId); assert(data.messageType == nmtIntro); toEndian(); - NetworkMessage::send(socket, &data, sizeof(data)); + + if(useOldProtocol == true) { + NetworkMessage::send(socket, &data, sizeof(data)); + } + else { + unsigned char *buf = packMessage(); + //printf("Send packet size = %u data.messageType = %d\n[%s]\n",getPackedSize(),data.messageType,buf); + //NetworkMessage::send(socket, &data, sizeof(data)); + NetworkMessage::send(socket, buf, getPackedSize()); + delete [] buf; + } } void NetworkMessageIntro::toEndian() { @@ -183,18 +258,72 @@ NetworkMessagePing::NetworkMessagePing(int32 pingFrequency, int64 pingTime){ pingReceivedLocalTime=0; } +const char * NetworkMessagePing::getPackedMessageFormat() const { + return "clq"; +} + +unsigned int NetworkMessagePing::getPackedSize() { + static unsigned int result = 0; + if(result == 0) { + Data packedData; + unsigned char *buf = new unsigned char[sizeof(packedData)*3]; + result = pack(buf, getPackedMessageFormat(), + packedData.messageType, + packedData.pingFrequency, + packedData.pingTime); + delete [] buf; + } + return result; +} +void NetworkMessagePing::unpackMessage(unsigned char *buf) { + unpack(buf, getPackedMessageFormat(), + &data.messageType, + &data.pingFrequency, + &data.pingTime); +} + +unsigned char * NetworkMessagePing::packMessage() { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + pack(buf, getPackedMessageFormat(), + data.messageType, + data.pingFrequency, + data.pingTime); + return buf; +} + bool NetworkMessagePing::receive(Socket* socket){ - bool result = NetworkMessage::receive(socket, &data, sizeof(data), true); + bool result = false; + if(useOldProtocol == true) { + result = NetworkMessage::receive(socket, &data, sizeof(data), true); + } + else { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + result = NetworkMessage::receive(socket, buf, getPackedSize(), true); + unpackMessage(buf); + //printf("Got packet size = %u data.messageType = %d\n%s\n",getPackedSize(),data.messageType,buf); + delete [] buf; + } fromEndian(); + pingReceivedLocalTime = time(NULL); return result; } void NetworkMessagePing::send(Socket* socket) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtPing\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtPing\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); assert(data.messageType==nmtPing); toEndian(); - NetworkMessage::send(socket, &data, sizeof(data)); + + if(useOldProtocol == true) { + NetworkMessage::send(socket, &data, sizeof(data)); + } + else { + unsigned char *buf = packMessage(); + //printf("Send packet size = %u data.messageType = %d\n[%s]\n",getPackedSize(),data.messageType,buf); + //NetworkMessage::send(socket, &data, sizeof(data)); + NetworkMessage::send(socket, buf, getPackedSize()); + delete [] buf; + } } void NetworkMessagePing::toEndian() { @@ -227,17 +356,66 @@ NetworkMessageReady::NetworkMessageReady(uint32 checksum) { data.checksum= checksum; } +const char * NetworkMessageReady::getPackedMessageFormat() const { + return "cL"; +} + +unsigned int NetworkMessageReady::getPackedSize() { + static unsigned int result = 0; + if(result == 0) { + Data packedData; + unsigned char *buf = new unsigned char[sizeof(packedData)*3]; + result = pack(buf, getPackedMessageFormat(), + packedData.messageType, + packedData.checksum); + delete [] buf; + } + return result; +} +void NetworkMessageReady::unpackMessage(unsigned char *buf) { + unpack(buf, getPackedMessageFormat(), + &data.messageType, + &data.checksum); +} + +unsigned char * NetworkMessageReady::packMessage() { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + pack(buf, getPackedMessageFormat(), + data.messageType, + data.checksum); + return buf; +} + bool NetworkMessageReady::receive(Socket* socket){ - bool result = NetworkMessage::receive(socket, &data, sizeof(data), true); + bool result = false; + if(useOldProtocol == true) { + result = NetworkMessage::receive(socket, &data, sizeof(data), true); + } + else { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + bool result = NetworkMessage::receive(socket, buf, getPackedSize(), true); + unpackMessage(buf); + //printf("Got packet size = %u data.messageType = %d\n%s\n",getPackedSize(),data.messageType,buf); + delete [] buf; + } fromEndian(); return result; } void NetworkMessageReady::send(Socket* socket) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtReady\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtReady\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); assert(data.messageType==nmtReady); toEndian(); - NetworkMessage::send(socket, &data, sizeof(data)); + + if(useOldProtocol == true) { + NetworkMessage::send(socket, &data, sizeof(data)); + } + else { + unsigned char *buf = packMessage(); + //printf("Send packet size = %u data.messageType = %d\n[%s]\n",getPackedSize(),data.messageType,buf); + NetworkMessage::send(socket, buf, getPackedSize()); + delete [] buf; + } } void NetworkMessageReady::toEndian() { @@ -400,8 +578,432 @@ vector > NetworkMessageLaunch::getFactionCRCList() const { return factionCRCList; } +const char * NetworkMessageLaunch::getPackedMessageFormat() const { + return "c256s60s60s60s60s60s60s60s60s60s60s60s60s60s60s60s60s60s60s60sllllllll60s60s60s60s60s60s60s60sLLL60s60s60s60s60s60s60s60s60s60s60s60s60s60s60s60s60s60s60s60sLLLLLLLLLLLLLLLLLLLLcccccccccccccccccccccccccccccccccccccccccCccLccll256s"; +} + +unsigned int NetworkMessageLaunch::getPackedSize() { + static unsigned int result = 0; + if(result == 0) { + Data packedData; + unsigned char *buf = new unsigned char[sizeof(packedData)*3]; + result = pack(buf, getPackedMessageFormat(), + packedData.messageType, + packedData.description.getBuffer(), + packedData.map.getBuffer(), + packedData.tileset.getBuffer(), + packedData.tech.getBuffer(), + packedData.factionTypeNames[0].getBuffer(), + packedData.factionTypeNames[1].getBuffer(), + packedData.factionTypeNames[2].getBuffer(), + packedData.factionTypeNames[3].getBuffer(), + packedData.factionTypeNames[4].getBuffer(), + packedData.factionTypeNames[5].getBuffer(), + packedData.factionTypeNames[6].getBuffer(), + packedData.factionTypeNames[7].getBuffer(), + packedData.networkPlayerNames[0].getBuffer(), + packedData.networkPlayerNames[1].getBuffer(), + packedData.networkPlayerNames[2].getBuffer(), + packedData.networkPlayerNames[3].getBuffer(), + packedData.networkPlayerNames[4].getBuffer(), + packedData.networkPlayerNames[5].getBuffer(), + packedData.networkPlayerNames[6].getBuffer(), + packedData.networkPlayerNames[7].getBuffer(), + packedData.networkPlayerStatuses[0], + packedData.networkPlayerStatuses[1], + packedData.networkPlayerStatuses[2], + packedData.networkPlayerStatuses[3], + packedData.networkPlayerStatuses[4], + packedData.networkPlayerStatuses[5], + packedData.networkPlayerStatuses[6], + packedData.networkPlayerStatuses[7], + packedData.networkPlayerLanguages[0].getBuffer(), + packedData.networkPlayerLanguages[1].getBuffer(), + packedData.networkPlayerLanguages[2].getBuffer(), + packedData.networkPlayerLanguages[3].getBuffer(), + packedData.networkPlayerLanguages[4].getBuffer(), + packedData.networkPlayerLanguages[5].getBuffer(), + packedData.networkPlayerLanguages[6].getBuffer(), + packedData.networkPlayerLanguages[7].getBuffer(), + packedData.mapCRC, + packedData.tilesetCRC, + packedData.techCRC, + packedData.factionNameList[0].getBuffer(), + packedData.factionNameList[1].getBuffer(), + packedData.factionNameList[2].getBuffer(), + packedData.factionNameList[3].getBuffer(), + packedData.factionNameList[4].getBuffer(), + packedData.factionNameList[5].getBuffer(), + packedData.factionNameList[6].getBuffer(), + packedData.factionNameList[7].getBuffer(), + packedData.factionNameList[8].getBuffer(), + packedData.factionNameList[9].getBuffer(), + packedData.factionNameList[10].getBuffer(), + packedData.factionNameList[11].getBuffer(), + packedData.factionNameList[12].getBuffer(), + packedData.factionNameList[13].getBuffer(), + packedData.factionNameList[14].getBuffer(), + packedData.factionNameList[15].getBuffer(), + packedData.factionNameList[16].getBuffer(), + packedData.factionNameList[17].getBuffer(), + packedData.factionNameList[18].getBuffer(), + packedData.factionNameList[19].getBuffer(), + packedData.factionCRCList[0], + packedData.factionCRCList[1], + packedData.factionCRCList[2], + packedData.factionCRCList[3], + packedData.factionCRCList[4], + packedData.factionCRCList[5], + packedData.factionCRCList[6], + packedData.factionCRCList[7], + packedData.factionCRCList[8], + packedData.factionCRCList[9], + packedData.factionCRCList[10], + packedData.factionCRCList[11], + packedData.factionCRCList[12], + packedData.factionCRCList[13], + packedData.factionCRCList[14], + packedData.factionCRCList[15], + packedData.factionCRCList[16], + packedData.factionCRCList[17], + packedData.factionCRCList[18], + packedData.factionCRCList[19], + packedData.factionControls[0], + packedData.factionControls[1], + packedData.factionControls[2], + packedData.factionControls[3], + packedData.factionControls[4], + packedData.factionControls[5], + packedData.factionControls[6], + packedData.factionControls[7], + packedData.resourceMultiplierIndex[0], + packedData.resourceMultiplierIndex[1], + packedData.resourceMultiplierIndex[2], + packedData.resourceMultiplierIndex[3], + packedData.resourceMultiplierIndex[4], + packedData.resourceMultiplierIndex[5], + packedData.resourceMultiplierIndex[6], + packedData.resourceMultiplierIndex[7], + packedData.thisFactionIndex, + packedData.factionCount, + packedData.teams[0], + packedData.teams[1], + packedData.teams[2], + packedData.teams[3], + packedData.teams[4], + packedData.teams[5], + packedData.teams[6], + packedData.teams[7], + packedData.startLocationIndex[0], + packedData.startLocationIndex[1], + packedData.startLocationIndex[2], + packedData.startLocationIndex[3], + packedData.startLocationIndex[4], + packedData.startLocationIndex[5], + packedData.startLocationIndex[6], + packedData.startLocationIndex[7], + packedData.defaultResources, + packedData.defaultUnits, + packedData.defaultVictoryConditions, + packedData.fogOfWar, + packedData.allowObservers, + packedData.enableObserverModeAtEndGame, + packedData.enableServerControlledAI, + packedData.networkFramePeriod, + packedData.networkPauseGameForLaggedClients, + packedData.pathFinderType, + packedData.flagTypes1, + packedData.aiAcceptSwitchTeamPercentChance, + packedData.cpuReplacementMultiplier, + packedData.masterserver_admin, + packedData.masterserver_admin_factionIndex, + packedData.scenario.getBuffer()); + delete [] buf; + } + return result; +} +void NetworkMessageLaunch::unpackMessage(unsigned char *buf) { + unpack(buf, getPackedMessageFormat(), + &data.messageType, + data.description.getBuffer(), + data.map.getBuffer(), + data.tileset.getBuffer(), + data.tech.getBuffer(), + data.factionTypeNames[0].getBuffer(), + data.factionTypeNames[1].getBuffer(), + data.factionTypeNames[2].getBuffer(), + data.factionTypeNames[3].getBuffer(), + data.factionTypeNames[4].getBuffer(), + data.factionTypeNames[5].getBuffer(), + data.factionTypeNames[6].getBuffer(), + data.factionTypeNames[7].getBuffer(), + data.networkPlayerNames[0].getBuffer(), + data.networkPlayerNames[1].getBuffer(), + data.networkPlayerNames[2].getBuffer(), + data.networkPlayerNames[3].getBuffer(), + data.networkPlayerNames[4].getBuffer(), + data.networkPlayerNames[5].getBuffer(), + data.networkPlayerNames[6].getBuffer(), + data.networkPlayerNames[7].getBuffer(), + &data.networkPlayerStatuses[0], + &data.networkPlayerStatuses[1], + &data.networkPlayerStatuses[2], + &data.networkPlayerStatuses[3], + &data.networkPlayerStatuses[4], + &data.networkPlayerStatuses[5], + &data.networkPlayerStatuses[6], + &data.networkPlayerStatuses[7], + data.networkPlayerLanguages[0].getBuffer(), + data.networkPlayerLanguages[1].getBuffer(), + data.networkPlayerLanguages[2].getBuffer(), + data.networkPlayerLanguages[3].getBuffer(), + data.networkPlayerLanguages[4].getBuffer(), + data.networkPlayerLanguages[5].getBuffer(), + data.networkPlayerLanguages[6].getBuffer(), + data.networkPlayerLanguages[7].getBuffer(), + &data.mapCRC, + &data.tilesetCRC, + &data.techCRC, + data.factionNameList[0].getBuffer(), + data.factionNameList[1].getBuffer(), + data.factionNameList[2].getBuffer(), + data.factionNameList[3].getBuffer(), + data.factionNameList[4].getBuffer(), + data.factionNameList[5].getBuffer(), + data.factionNameList[6].getBuffer(), + data.factionNameList[7].getBuffer(), + data.factionNameList[8].getBuffer(), + data.factionNameList[9].getBuffer(), + data.factionNameList[10].getBuffer(), + data.factionNameList[11].getBuffer(), + data.factionNameList[12].getBuffer(), + data.factionNameList[13].getBuffer(), + data.factionNameList[14].getBuffer(), + data.factionNameList[15].getBuffer(), + data.factionNameList[16].getBuffer(), + data.factionNameList[17].getBuffer(), + data.factionNameList[18].getBuffer(), + data.factionNameList[19].getBuffer(), + &data.factionCRCList[0], + &data.factionCRCList[1], + &data.factionCRCList[2], + &data.factionCRCList[3], + &data.factionCRCList[4], + &data.factionCRCList[5], + &data.factionCRCList[6], + &data.factionCRCList[7], + &data.factionCRCList[8], + &data.factionCRCList[9], + &data.factionCRCList[10], + &data.factionCRCList[11], + &data.factionCRCList[12], + &data.factionCRCList[13], + &data.factionCRCList[14], + &data.factionCRCList[15], + &data.factionCRCList[16], + &data.factionCRCList[17], + &data.factionCRCList[18], + &data.factionCRCList[19], + &data.factionControls[0], + &data.factionControls[1], + &data.factionControls[2], + &data.factionControls[3], + &data.factionControls[4], + &data.factionControls[5], + &data.factionControls[6], + &data.factionControls[7], + &data.resourceMultiplierIndex[0], + &data.resourceMultiplierIndex[1], + &data.resourceMultiplierIndex[2], + &data.resourceMultiplierIndex[3], + &data.resourceMultiplierIndex[4], + &data.resourceMultiplierIndex[5], + &data.resourceMultiplierIndex[6], + &data.resourceMultiplierIndex[7], + &data.thisFactionIndex, + &data.factionCount, + &data.teams[0], + &data.teams[1], + &data.teams[2], + &data.teams[3], + &data.teams[4], + &data.teams[5], + &data.teams[6], + &data.teams[7], + &data.startLocationIndex[0], + &data.startLocationIndex[1], + &data.startLocationIndex[2], + &data.startLocationIndex[3], + &data.startLocationIndex[4], + &data.startLocationIndex[5], + &data.startLocationIndex[6], + &data.startLocationIndex[7], + &data.defaultResources, + &data.defaultUnits, + &data.defaultVictoryConditions, + &data.fogOfWar, + &data.allowObservers, + &data.enableObserverModeAtEndGame, + &data.enableServerControlledAI, + &data.networkFramePeriod, + &data.networkPauseGameForLaggedClients, + &data.pathFinderType, + &data.flagTypes1, + &data.aiAcceptSwitchTeamPercentChance, + &data.cpuReplacementMultiplier, + &data.masterserver_admin, + &data.masterserver_admin_factionIndex, + data.scenario.getBuffer()); +} + +unsigned char * NetworkMessageLaunch::packMessage() { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + pack(buf, getPackedMessageFormat(), + data.messageType, + data.description.getBuffer(), + data.map.getBuffer(), + data.tileset.getBuffer(), + data.tech.getBuffer(), + data.factionTypeNames[0].getBuffer(), + data.factionTypeNames[1].getBuffer(), + data.factionTypeNames[2].getBuffer(), + data.factionTypeNames[3].getBuffer(), + data.factionTypeNames[4].getBuffer(), + data.factionTypeNames[5].getBuffer(), + data.factionTypeNames[6].getBuffer(), + data.factionTypeNames[7].getBuffer(), + data.networkPlayerNames[0].getBuffer(), + data.networkPlayerNames[1].getBuffer(), + data.networkPlayerNames[2].getBuffer(), + data.networkPlayerNames[3].getBuffer(), + data.networkPlayerNames[4].getBuffer(), + data.networkPlayerNames[5].getBuffer(), + data.networkPlayerNames[6].getBuffer(), + data.networkPlayerNames[7].getBuffer(), + data.networkPlayerStatuses[0], + data.networkPlayerStatuses[1], + data.networkPlayerStatuses[2], + data.networkPlayerStatuses[3], + data.networkPlayerStatuses[4], + data.networkPlayerStatuses[5], + data.networkPlayerStatuses[6], + data.networkPlayerStatuses[7], + data.networkPlayerLanguages[0].getBuffer(), + data.networkPlayerLanguages[1].getBuffer(), + data.networkPlayerLanguages[2].getBuffer(), + data.networkPlayerLanguages[3].getBuffer(), + data.networkPlayerLanguages[4].getBuffer(), + data.networkPlayerLanguages[5].getBuffer(), + data.networkPlayerLanguages[6].getBuffer(), + data.networkPlayerLanguages[7].getBuffer(), + data.mapCRC, + data.tilesetCRC, + data.techCRC, + data.factionNameList[0].getBuffer(), + data.factionNameList[1].getBuffer(), + data.factionNameList[2].getBuffer(), + data.factionNameList[3].getBuffer(), + data.factionNameList[4].getBuffer(), + data.factionNameList[5].getBuffer(), + data.factionNameList[6].getBuffer(), + data.factionNameList[7].getBuffer(), + data.factionNameList[8].getBuffer(), + data.factionNameList[9].getBuffer(), + data.factionNameList[10].getBuffer(), + data.factionNameList[11].getBuffer(), + data.factionNameList[12].getBuffer(), + data.factionNameList[13].getBuffer(), + data.factionNameList[14].getBuffer(), + data.factionNameList[15].getBuffer(), + data.factionNameList[16].getBuffer(), + data.factionNameList[17].getBuffer(), + data.factionNameList[18].getBuffer(), + data.factionNameList[19].getBuffer(), + data.factionCRCList[0], + data.factionCRCList[1], + data.factionCRCList[2], + data.factionCRCList[3], + data.factionCRCList[4], + data.factionCRCList[5], + data.factionCRCList[6], + data.factionCRCList[7], + data.factionCRCList[8], + data.factionCRCList[9], + data.factionCRCList[10], + data.factionCRCList[11], + data.factionCRCList[12], + data.factionCRCList[13], + data.factionCRCList[14], + data.factionCRCList[15], + data.factionCRCList[16], + data.factionCRCList[17], + data.factionCRCList[18], + data.factionCRCList[19], + data.factionControls[0], + data.factionControls[1], + data.factionControls[2], + data.factionControls[3], + data.factionControls[4], + data.factionControls[5], + data.factionControls[6], + data.factionControls[7], + data.resourceMultiplierIndex[0], + data.resourceMultiplierIndex[1], + data.resourceMultiplierIndex[2], + data.resourceMultiplierIndex[3], + data.resourceMultiplierIndex[4], + data.resourceMultiplierIndex[5], + data.resourceMultiplierIndex[6], + data.resourceMultiplierIndex[7], + data.thisFactionIndex, + data.factionCount, + data.teams[0], + data.teams[1], + data.teams[2], + data.teams[3], + data.teams[4], + data.teams[5], + data.teams[6], + data.teams[7], + data.startLocationIndex[0], + data.startLocationIndex[1], + data.startLocationIndex[2], + data.startLocationIndex[3], + data.startLocationIndex[4], + data.startLocationIndex[5], + data.startLocationIndex[6], + data.startLocationIndex[7], + data.defaultResources, + data.defaultUnits, + data.defaultVictoryConditions, + data.fogOfWar, + data.allowObservers, + data.enableObserverModeAtEndGame, + data.enableServerControlledAI, + data.networkFramePeriod, + data.networkPauseGameForLaggedClients, + data.pathFinderType, + data.flagTypes1, + data.aiAcceptSwitchTeamPercentChance, + data.cpuReplacementMultiplier, + data.masterserver_admin, + data.masterserver_admin_factionIndex, + data.scenario.getBuffer()); + return buf; +} + bool NetworkMessageLaunch::receive(Socket* socket) { - bool result = NetworkMessage::receive(socket, &data, sizeof(data), true); + bool result = false; + if(useOldProtocol == true) { + result = NetworkMessage::receive(socket, &data, sizeof(data), true); + } + else { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + result = NetworkMessage::receive(socket, buf, getPackedSize(), true); + unpackMessage(buf); + //printf("Got packet size = %u data.messageType = %d\n%s\n",getPackedSize(),data.messageType,buf); + delete [] buf; + } fromEndian(); data.description.nullTerminate(); @@ -423,13 +1025,22 @@ bool NetworkMessageLaunch::receive(Socket* socket) { void NetworkMessageLaunch::send(Socket* socket) { if(data.messageType == nmtLaunch) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtLaunch\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtLaunch\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] messageType = %d\n",__FILE__,__FUNCTION__,__LINE__,data.messageType); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] messageType = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,data.messageType); } toEndian(); - NetworkMessage::send(socket, &data, sizeof(data)); + + if(useOldProtocol == true) { + NetworkMessage::send(socket, &data, sizeof(data)); + } + else { + unsigned char *buf = packMessage(); + //printf("Send packet size = %u data.messageType = %d\n[%s]\n",getPackedSize(),data.messageType,buf); + NetworkMessage::send(socket, buf, getPackedSize()); + delete [] buf; + } } void NetworkMessageLaunch::toEndian() { @@ -522,68 +1133,249 @@ bool NetworkMessageCommandList::addCommand(const NetworkCommand* networkCommand) return true; } +const char * NetworkMessageCommandList::getPackedMessageFormatHeader() const { + return "cHl"; +} + +unsigned int NetworkMessageCommandList::getPackedSizeHeader() { + static unsigned int result = 0; + if(result == 0) { + Data packedData; + unsigned char *buf = new unsigned char[sizeof(packedData)*3]; + result = pack(buf, getPackedMessageFormatHeader(), + packedData.header.messageType, + packedData.header.commandCount, + packedData.header.frameCount); + delete [] buf; + } + return result; +} +void NetworkMessageCommandList::unpackMessageHeader(unsigned char *buf) { + unpack(buf, getPackedMessageFormatHeader(), + &data.header.messageType, + &data.header.commandCount, + &data.header.frameCount); +} + +unsigned char * NetworkMessageCommandList::packMessageHeader() { + unsigned char *buf = new unsigned char[getPackedSizeHeader()+1]; + pack(buf, getPackedMessageFormatHeader(), + data.header.messageType, + data.header.commandCount, + data.header.frameCount); + return buf; +} + +const char * NetworkMessageCommandList::getPackedMessageFormatDetail() const { + return "hlhhhhlccHccll"; +} + +unsigned int NetworkMessageCommandList::getPackedSizeDetail(int count) { + unsigned int result = 0; + if(result == 0) { + for(unsigned int i = 0; i < count; ++i) { + NetworkCommand packedData; + unsigned char *buf = new unsigned char[sizeof(NetworkCommand)*3]; + result += pack(buf, getPackedMessageFormatDetail(), + packedData.networkCommandType, + packedData.unitId, + packedData.unitTypeId, + packedData.commandTypeId, + packedData.positionX, + packedData.positionY, + packedData.targetId, + packedData.wantQueue, + packedData.fromFactionIndex, + packedData.unitFactionUnitCount, + packedData.unitFactionIndex, + packedData.commandStateType, + packedData.commandStateValue, + packedData.unitCommandGroupId); + delete [] buf; + } + } + return result; +} +void NetworkMessageCommandList::unpackMessageDetail(unsigned char *buf,int count) { + data.commands.clear(); + data.commands.resize(count); + unsigned int bytes_processed_total = 0; + unsigned char *bufMove = buf; + for(unsigned int i = 0; i < count; ++i) { + unsigned int bytes_processed = unpack(bufMove, getPackedMessageFormatDetail(), + &data.commands[i].networkCommandType, + &data.commands[i].unitId, + &data.commands[i].unitTypeId, + &data.commands[i].commandTypeId, + &data.commands[i].positionX, + &data.commands[i].positionY, + &data.commands[i].targetId, + &data.commands[i].wantQueue, + &data.commands[i].fromFactionIndex, + &data.commands[i].unitFactionUnitCount, + &data.commands[i].unitFactionIndex, + &data.commands[i].commandStateType, + &data.commands[i].commandStateValue, + &data.commands[i].unitCommandGroupId); + bufMove += bytes_processed; + bytes_processed_total += bytes_processed; + } + //printf("\nUnPacked detail size = %u\n",bytes_processed_total); +} + +unsigned char * NetworkMessageCommandList::packMessageDetail(uint16 totalCommand) { + int packetSize = getPackedSizeDetail(totalCommand) +1; + unsigned char *buf = new unsigned char[packetSize]; + unsigned char *bufMove = buf; + unsigned int bytes_processed_total = 0; + for(unsigned int i = 0; i < totalCommand; ++i) { + unsigned int bytes_processed = pack(bufMove, getPackedMessageFormatDetail(), + data.commands[i].networkCommandType, + data.commands[i].unitId, + data.commands[i].unitTypeId, + data.commands[i].commandTypeId, + data.commands[i].positionX, + data.commands[i].positionY, + data.commands[i].targetId, + data.commands[i].wantQueue, + data.commands[i].fromFactionIndex, + data.commands[i].unitFactionUnitCount, + data.commands[i].unitFactionIndex, + data.commands[i].commandStateType, + data.commands[i].commandStateValue, + data.commands[i].unitCommandGroupId); + bufMove += bytes_processed; + bytes_processed_total += bytes_processed; + } + //printf("\nPacked detail size = %u, allocated = %d\n",bytes_processed_total,packetSize); + return buf; +} + bool NetworkMessageCommandList::receive(Socket* socket) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - bool result = NetworkMessage::receive(socket, &data.header, commandListHeaderSize, true); + unsigned char *buf = NULL; + bool result = false; + if(useOldProtocol == true) { + result = NetworkMessage::receive(socket, &data.header, commandListHeaderSize, true); + } + else { + //fromEndianHeader(); + buf = new unsigned char[getPackedSizeHeader()+1]; + result = NetworkMessage::receive(socket, buf, getPackedSizeHeader(), true); + unpackMessageHeader(buf); + //if(data.header.commandCount) printf("\n\nGot packet size = %u data.messageType = %d\n%s\ncommandcount [%u] framecount [%d]\n",getPackedSizeHeader(),data.header.messageType,buf,data.header.commandCount,data.header.frameCount); + delete [] buf; + } fromEndianHeader(); + if(result == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got header, messageType = %d, commandCount = %u, frameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.messageType,data.header.commandCount,data.header.frameCount); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got header, messageType = %d, commandCount = %u, frameCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,data.header.messageType,data.header.commandCount,data.header.frameCount); if(data.header.commandCount > 0) { data.commands.resize(data.header.commandCount); - int totalMsgSize = (sizeof(NetworkCommand) * data.header.commandCount); - result = NetworkMessage::receive(socket, &data.commands[0], totalMsgSize, true); + if(useOldProtocol == true) { + int totalMsgSize = (sizeof(NetworkCommand) * data.header.commandCount); + result = NetworkMessage::receive(socket, &data.commands[0], totalMsgSize, true); + } + else { + //int totalMsgSize = (sizeof(NetworkCommand) * data.header.commandCount); + //result = NetworkMessage::receive(socket, &data.commands[0], totalMsgSize, true); + buf = new unsigned char[getPackedSizeDetail(data.header.commandCount)+1]; + result = NetworkMessage::receive(socket, buf, getPackedSizeDetail(data.header.commandCount), true); + unpackMessageDetail(buf,data.header.commandCount); + //printf("Got packet size = %u data.messageType = %d\n%s\n",getPackedSize(),data.messageType,buf); + delete [] buf; + } + fromEndianDetail(); + +// for(int idx = 0 ; idx < data.header.commandCount; ++idx) { +// const NetworkCommand &cmd = data.commands[idx]; +// printf("========> Got index = %d / %u, got networkCommand [%s]\n",idx, data.header.commandCount,cmd.toString().c_str()); +// } + if(result == true) { - fromEndianDetail(); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled == true) { for(int idx = 0 ; idx < data.header.commandCount; ++idx) { const NetworkCommand &cmd = data.commands[idx]; SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] index = %d, received networkCommand [%s]\n", - __FILE__,__FUNCTION__,__LINE__,idx, cmd.toString().c_str()); + extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,idx, cmd.toString().c_str()); } } } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR Failed to get command data, totalMsgSize = %d.\n",__FILE__,__FUNCTION__,__LINE__,totalMsgSize); + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR Failed to get command data, totalMsgSize = %d.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,totalMsgSize); } } } else { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR header not received as expected\n",__FILE__,__FUNCTION__,__LINE__); - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] ERROR header not received as expected\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR header not received as expected\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] ERROR header not received as expected\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } return result; } void NetworkMessageCommandList::send(Socket* socket) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtCommandList, frameCount = %d, data.header.commandCount = %d, data.header.messageType = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.frameCount,data.header.commandCount,data.header.messageType); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtCommandList, frameCount = %d, data.header.commandCount = %d, data.header.messageType = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,data.header.frameCount,data.header.commandCount,data.header.messageType); assert(data.header.messageType==nmtCommandList); uint16 totalCommand = data.header.commandCount; toEndianHeader(); - NetworkMessage::send(socket, &data.header, commandListHeaderSize); + + unsigned char *buf = NULL; + bool result = false; + if(useOldProtocol == true) { + NetworkMessage::send(socket, &data.header, commandListHeaderSize); + } + else { + //NetworkMessage::send(socket, &data.header, commandListHeaderSize); + buf = packMessageHeader(); + //if(totalCommand) printf("\n\nSend packet size = %u data.messageType = %d\n%s\ncommandcount [%u] framecount [%d]\n",getPackedSizeHeader(),data.header.messageType,buf,totalCommand,data.header.frameCount); + NetworkMessage::send(socket, buf, getPackedSizeHeader()); + delete [] buf; + } + if(totalCommand > 0) { + //printf("\n#2 Send packet commandcount [%u] framecount [%d]\n",totalCommand,data.header.frameCount); toEndianDetail(totalCommand); - NetworkMessage::send(socket, &data.commands[0], (sizeof(NetworkCommand) * totalCommand)); + //printf("\n#3 Send packet commandcount [%u] framecount [%d]\n",totalCommand,data.header.frameCount); + + bool result = false; + if(useOldProtocol == true) { + NetworkMessage::send(socket, &data.commands[0], (sizeof(NetworkCommand) * totalCommand)); + } + else { + buf = packMessageDetail(totalCommand); + //printf("\n#4 Send packet commandcount [%u] framecount [%d]\n",totalCommand,data.header.frameCount); + //printf("Send packet size = %u data.messageType = %d\n[%s]\n",getPackedSize(),data.messageType,buf); + NetworkMessage::send(socket, buf, getPackedSizeDetail(totalCommand)); + //printf("\n#5 Send packet commandcount [%u] framecount [%d]\n",totalCommand,data.header.frameCount); + delete [] buf; + //printf("\n#6 Send packet commandcount [%u] framecount [%d]\n",totalCommand,data.header.frameCount); + + // for(int idx = 0 ; idx < totalCommand; ++idx) { + // const NetworkCommand &cmd = data.commands[idx]; + // printf("========> Send index = %d / %u, sent networkCommand [%s]\n",idx, totalCommand,cmd.toString().c_str()); + // } + } } if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled == true) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] messageType = %d, frameCount = %d, data.commandCount = %d\n", - __FILE__,__FUNCTION__,__LINE__,data.header.messageType,data.header.frameCount,data.header.commandCount); + extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,data.header.messageType,data.header.frameCount,data.header.commandCount); - if (data.header.commandCount > 0) { - for(int idx = 0 ; idx < data.header.commandCount; ++idx) { + if (totalCommand > 0) { + for(int idx = 0 ; idx < totalCommand; ++idx) { const NetworkCommand &cmd = data.commands[idx]; SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] index = %d, sent networkCommand [%s]\n", - __FILE__,__FUNCTION__,__LINE__,idx, cmd.toString().c_str()); + extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,idx, cmd.toString().c_str()); } - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] END of loop, nmtCommandList, frameCount = %d, data.header.commandCount = %d, data.header.messageType = %d\n",__FILE__,__FUNCTION__,__LINE__,data.header.frameCount,data.header.commandCount,data.header.messageType); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] END of loop, nmtCommandList, frameCount = %d, data.header.commandCount = %d, data.header.messageType = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,data.header.frameCount,totalCommand,data.header.messageType); } } } @@ -636,7 +1428,7 @@ void NetworkMessageCommandList::fromEndianDetail() { NetworkMessageText::NetworkMessageText(const string &text, int teamIndex, int playerIndex, const string targetLanguage) { if(text.length() >= maxTextStringSize) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR - text [%s] length = %d, max = %d\n",__FILE__,__FUNCTION__,__LINE__,text.c_str(),text.length(),maxTextStringSize); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR - text [%s] length = %d, max = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,text.c_str(),text.length(),maxTextStringSize); } data.messageType = nmtText; @@ -652,9 +1444,59 @@ NetworkMessageText * NetworkMessageText::getCopy() const { return copy; } -bool NetworkMessageText::receive(Socket* socket){ - bool result = NetworkMessage::receive(socket, &data, sizeof(data), true); +const char * NetworkMessageText::getPackedMessageFormat() const { + return "c500scc60s"; +} + +unsigned int NetworkMessageText::getPackedSize() { + static unsigned int result = 0; + if(result == 0) { + Data packedData; + unsigned char *buf = new unsigned char[sizeof(packedData)*3]; + result = pack(buf, getPackedMessageFormat(), + packedData.messageType, + packedData.text.getBuffer(), + packedData.teamIndex, + packedData.playerIndex, + packedData.targetLanguage.getBuffer()); + delete [] buf; + } + return result; +} +void NetworkMessageText::unpackMessage(unsigned char *buf) { + unpack(buf, getPackedMessageFormat(), + &data.messageType, + data.text.getBuffer(), + &data.teamIndex, + &data.playerIndex, + data.targetLanguage.getBuffer()); +} + +unsigned char * NetworkMessageText::packMessage() { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + pack(buf, getPackedMessageFormat(), + data.messageType, + data.text.getBuffer(), + data.teamIndex, + data.playerIndex, + data.targetLanguage.getBuffer()); + return buf; +} + +bool NetworkMessageText::receive(Socket* socket) { + bool result = false; + if(useOldProtocol == true) { + result = NetworkMessage::receive(socket, &data, sizeof(data), true); + } + else { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + result = NetworkMessage::receive(socket, buf, getPackedSize(), true); + unpackMessage(buf); + //printf("Got packet size = %u data.messageType = %d\n%s\n",getPackedSize(),data.messageType,buf); + delete [] buf; + } fromEndian(); + data.text.nullTerminate(); data.targetLanguage.nullTerminate(); @@ -662,11 +1504,20 @@ bool NetworkMessageText::receive(Socket* socket){ } void NetworkMessageText::send(Socket* socket) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtText\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtText\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); assert(data.messageType==nmtText); toEndian(); - NetworkMessage::send(socket, &data, sizeof(data)); + + if(useOldProtocol == true) { + NetworkMessage::send(socket, &data, sizeof(data)); + } + else { + unsigned char *buf = packMessage(); + //printf("Send packet size = %u data.messageType = %d\n[%s]\n",getPackedSize(),data.messageType,buf); + NetworkMessage::send(socket, buf, getPackedSize()); + delete [] buf; + } } void NetworkMessageText::toEndian() { @@ -694,18 +1545,66 @@ NetworkMessageQuit::NetworkMessageQuit(){ data.messageType= nmtQuit; } -bool NetworkMessageQuit::receive(Socket* socket){ - bool result = NetworkMessage::receive(socket, &data, sizeof(data),true); +const char * NetworkMessageQuit::getPackedMessageFormat() const { + return "c"; +} + +unsigned int NetworkMessageQuit::getPackedSize() { + static unsigned int result = 0; + if(result == 0) { + Data packedData; + unsigned char *buf = new unsigned char[sizeof(packedData)*3]; + result = pack(buf, getPackedMessageFormat(), + packedData.messageType); + delete [] buf; + } + return result; +} +void NetworkMessageQuit::unpackMessage(unsigned char *buf) { + unpack(buf, getPackedMessageFormat(), + &data.messageType); +} + +unsigned char * NetworkMessageQuit::packMessage() { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + pack(buf, getPackedMessageFormat(), + data.messageType); + return buf; +} + +bool NetworkMessageQuit::receive(Socket* socket) { + bool result = false; + if(useOldProtocol == true) { + result = NetworkMessage::receive(socket, &data, sizeof(data),true); + } + else { + //fromEndian(); + unsigned char *buf = new unsigned char[getPackedSize()+1]; + result = NetworkMessage::receive(socket, buf, getPackedSize(), true); + unpackMessage(buf); + //printf("Got packet size = %u data.messageType = %d\n%s\n",getPackedSize(),data.messageType,buf); + delete [] buf; + } fromEndian(); + return result; } void NetworkMessageQuit::send(Socket* socket) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtQuit\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtQuit\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); assert(data.messageType==nmtQuit); toEndian(); - NetworkMessage::send(socket, &data, sizeof(data)); + + if(useOldProtocol == true) { + NetworkMessage::send(socket, &data, sizeof(data)); + } + else { + unsigned char *buf = packMessage(); + //printf("Send packet size = %u data.messageType = %d\n[%s]\n",getPackedSize(),data.messageType,buf); + NetworkMessage::send(socket, buf, getPackedSize()); + delete [] buf; + } } void NetworkMessageQuit::toEndian() { @@ -745,25 +1644,25 @@ NetworkMessageSynchNetworkGameData::NetworkMessageSynchNetworkGameData(const Gam scenarioDir = scenarioDir.erase(scenarioDir.size() - gameSettings->getScenario().size(), gameSettings->getScenario().size() + 1); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameSettings->getScenarioDir().c_str(),gameSettings->getScenario().c_str(),scenarioDir.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,gameSettings->getScenarioDir().c_str(),gameSettings->getScenario().c_str(),scenarioDir.c_str()); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); data.header.tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] data.tilesetCRC = %d, [%s]\n",__FILE__,__FUNCTION__,__LINE__, data.header.tilesetCRC,gameSettings->getTileset().c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] data.tilesetCRC = %d, [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__, data.header.tilesetCRC,gameSettings->getTileset().c_str()); //tech, load before map because of resources data.header.techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,scenarioDir), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] data.techCRC = %d, [%s]\n",__FILE__,__FUNCTION__,__LINE__, data.header.techCRC,gameSettings->getTech().c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] data.techCRC = %d, [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__, data.header.techCRC,gameSettings->getTech().c_str()); vector > vctFileList; vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),string("/") + gameSettings->getTech() + string("/*"), ".xml",&vctFileList); data.header.techCRCFileCount = min((int)vctFileList.size(),(int)maxFileCRCCount); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] vctFileList.size() = %d, maxFileCRCCount = %d\n",__FILE__,__FUNCTION__,__LINE__, vctFileList.size(),maxFileCRCCount); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] vctFileList.size() = %d, maxFileCRCCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__, vctFileList.size(),maxFileCRCCount); for(int idx =0; idx < data.header.techCRCFileCount; ++idx) { const std::pair &fileInfo = vctFileList[idx]; @@ -777,7 +1676,7 @@ NetworkMessageSynchNetworkGameData::NetworkMessageSynchNetworkGameData(const Gam checksum.addFile(file); data.header.mapCRC = checksum.getSum(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] data.mapCRC = %d, [%s]\n",__FILE__,__FUNCTION__,__LINE__, data.header.mapCRC,gameSettings->getMap().c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] data.mapCRC = %d, [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__, data.header.mapCRC,gameSettings->getMap().c_str()); } string NetworkMessageSynchNetworkGameData::getTechCRCFileMismatchReport(vector > &vctFileList) { @@ -836,8 +1735,109 @@ string NetworkMessageSynchNetworkGameData::getTechCRCFileMismatchReport(vector= maxTextStringSize) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR - text [%s] length = %d, max = %d\n",__FILE__,__FUNCTION__,__LINE__,text.c_str(),text.length(),maxTextStringSize); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR - text [%s] length = %d, max = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,text.c_str(),text.length(),maxTextStringSize); } data.messageType = nmtMarkCell; @@ -1409,19 +2584,83 @@ NetworkMessageMarkCell * NetworkMessageMarkCell::getCopy() const { return copy; } +const char * NetworkMessageMarkCell::getPackedMessageFormat() const { + return "chhcc500s"; +} + +unsigned int NetworkMessageMarkCell::getPackedSize() { + static unsigned int result = 0; + if(result == 0) { + Data packedData; + unsigned char *buf = new unsigned char[sizeof(packedData)*3]; + result = pack(buf, getPackedMessageFormat(), + packedData.messageType, + packedData.targetX, + packedData.targetY, + packedData.factionIndex, + packedData.playerIndex, + packedData.text.getBuffer()); + delete [] buf; + } + return result; +} +void NetworkMessageMarkCell::unpackMessage(unsigned char *buf) { + unpack(buf, getPackedMessageFormat(), + &data.messageType, + &data.targetX, + &data.targetY, + &data.factionIndex, + &data.playerIndex, + data.text.getBuffer()); + +} + +unsigned char * NetworkMessageMarkCell::packMessage() { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + pack(buf, getPackedMessageFormat(), + data.messageType, + data.targetX, + data.targetY, + data.factionIndex, + data.playerIndex, + data.text.getBuffer()); + + return buf; +} + bool NetworkMessageMarkCell::receive(Socket* socket){ - bool result = NetworkMessage::receive(socket, &data, sizeof(data), true); + bool result = false; + if(useOldProtocol == true) { + result = NetworkMessage::receive(socket, &data, sizeof(data), true); + } + else { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + result = NetworkMessage::receive(socket, buf, getPackedSize(), true); + unpackMessage(buf); + //printf("Got packet size = %u data.messageType = %d\n%s\n",getPackedSize(),data.messageType,buf); + delete [] buf; + } fromEndian(); + data.text.nullTerminate(); return result; } void NetworkMessageMarkCell::send(Socket* socket) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtMarkCell\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtMarkCell\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); assert(data.messageType == nmtMarkCell); toEndian(); - NetworkMessage::send(socket, &data, sizeof(data)); + + if(useOldProtocol == true) { + NetworkMessage::send(socket, &data, sizeof(data)); + } + else { + unsigned char *buf = packMessage(); + //printf("Send packet size = %u data.messageType = %d\n[%s]\n",getPackedSize(),data.messageType,buf); + NetworkMessage::send(socket, buf, getPackedSize()); + delete [] buf; + } } void NetworkMessageMarkCell::toEndian() { @@ -1462,18 +2701,76 @@ NetworkMessageUnMarkCell * NetworkMessageUnMarkCell::getCopy() const { return copy; } +const char * NetworkMessageUnMarkCell::getPackedMessageFormat() const { + return "chhc"; +} + +unsigned int NetworkMessageUnMarkCell::getPackedSize() { + static unsigned int result = 0; + if(result == 0) { + Data packedData; + unsigned char *buf = new unsigned char[sizeof(packedData)*3]; + result = pack(buf, getPackedMessageFormat(), + packedData.messageType, + packedData.targetX, + packedData.targetY, + packedData.factionIndex); + delete [] buf; + } + return result; +} +void NetworkMessageUnMarkCell::unpackMessage(unsigned char *buf) { + unpack(buf, getPackedMessageFormat(), + &data.messageType, + &data.targetX, + &data.targetY, + &data.factionIndex); + +} + +unsigned char * NetworkMessageUnMarkCell::packMessage() { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + pack(buf, getPackedMessageFormat(), + data.messageType, + data.targetX, + data.targetY, + data.factionIndex); + + return buf; +} + bool NetworkMessageUnMarkCell::receive(Socket* socket){ - bool result = NetworkMessage::receive(socket, &data, sizeof(data), true); + bool result = false; + if(useOldProtocol == true) { + result = NetworkMessage::receive(socket, &data, sizeof(data), true); + } + else { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + result = NetworkMessage::receive(socket, buf, getPackedSize(), true); + unpackMessage(buf); + //printf("Got packet size = %u data.messageType = %d\n%s\n",getPackedSize(),data.messageType,buf); + delete [] buf; + } fromEndian(); + return result; } void NetworkMessageUnMarkCell::send(Socket* socket) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtUnMarkCell\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtUnMarkCell\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); assert(data.messageType == nmtUnMarkCell); toEndian(); - NetworkMessage::send(socket, &data, sizeof(data)); + + if(useOldProtocol == true) { + NetworkMessage::send(socket, &data, sizeof(data)); + } + else { + unsigned char *buf = packMessage(); + //printf("Send packet size = %u data.messageType = %d\n[%s]\n",getPackedSize(),data.messageType,buf); + NetworkMessage::send(socket, buf, getPackedSize()); + delete [] buf; + } } void NetworkMessageUnMarkCell::toEndian() { @@ -1507,18 +2804,75 @@ NetworkMessageHighlightCell::NetworkMessageHighlightCell(Vec2i target, int facti data.factionIndex = factionIndex; } -bool NetworkMessageHighlightCell::receive(Socket* socket){ - bool result = NetworkMessage::receive(socket, &data, sizeof(data), true); +const char * NetworkMessageHighlightCell::getPackedMessageFormat() const { + return "chhc"; +} + +unsigned int NetworkMessageHighlightCell::getPackedSize() { + static unsigned int result = 0; + if(result == 0) { + Data packedData; + unsigned char *buf = new unsigned char[sizeof(packedData)*3]; + result = pack(buf, getPackedMessageFormat(), + packedData.messageType, + packedData.targetX, + packedData.targetY, + packedData.factionIndex); + delete [] buf; + } + return result; +} +void NetworkMessageHighlightCell::unpackMessage(unsigned char *buf) { + unpack(buf, getPackedMessageFormat(), + &data.messageType, + &data.targetX, + &data.targetY, + &data.factionIndex); + +} + +unsigned char * NetworkMessageHighlightCell::packMessage() { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + pack(buf, getPackedMessageFormat(), + data.messageType, + data.targetX, + data.targetY, + data.factionIndex); + + return buf; +} + +bool NetworkMessageHighlightCell::receive(Socket* socket) { + bool result = false; + if(useOldProtocol == true) { + result = NetworkMessage::receive(socket, &data, sizeof(data), true); + } + else { + unsigned char *buf = new unsigned char[getPackedSize()+1]; + result = NetworkMessage::receive(socket, buf, getPackedSize(), true); + unpackMessage(buf); + //printf("Got packet size = %u data.messageType = %d\n%s\n",getPackedSize(),data.messageType,buf); + delete [] buf; + } fromEndian(); return result; } void NetworkMessageHighlightCell::send(Socket* socket) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtMarkCell\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] nmtMarkCell\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); assert(data.messageType == nmtHighlightCell); toEndian(); - NetworkMessage::send(socket, &data, sizeof(data)); + + if(useOldProtocol == true) { + NetworkMessage::send(socket, &data, sizeof(data)); + } + else { + unsigned char *buf = packMessage(); + //printf("Send packet size = %u data.messageType = %d\n[%s]\n",getPackedSize(),data.messageType,buf); + NetworkMessage::send(socket, buf, getPackedSize()); + delete [] buf; + } } void NetworkMessageHighlightCell::toEndian() { diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index b1307ab4c..a032bd7e2 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -67,6 +67,7 @@ static const int maxLanguageStringSize= 60; class NetworkMessage { public: + static bool useOldProtocol; virtual ~NetworkMessage(){} virtual bool receive(Socket* socket)= 0; virtual void send(Socket* socket) = 0; @@ -78,6 +79,11 @@ class NetworkMessage { void send(Socket* socket, const void* data, int dataSize); void dump_packet(string label, const void* data, int dataSize); + + virtual const char * getPackedMessageFormat() const = 0; + virtual unsigned int getPackedSize() = 0; + virtual void unpackMessage(unsigned char *buf) = 0; + virtual unsigned char * packMessage() = 0; }; // ===================================================== @@ -111,6 +117,12 @@ class NetworkMessageIntro: public NetworkMessage{ private: Data data; +protected: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: NetworkMessageIntro(); NetworkMessageIntro(int32 sessionId, const string &versionString, @@ -154,6 +166,12 @@ class NetworkMessagePing: public NetworkMessage{ Data data; int64 pingReceivedLocalTime; +protected: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: NetworkMessagePing(); NetworkMessagePing(int32 pingFrequency, int64 pingTime); @@ -188,6 +206,12 @@ class NetworkMessageReady: public NetworkMessage{ private: Data data; +protected: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: NetworkMessageReady(); NetworkMessageReady(uint32 checksum); @@ -265,6 +289,12 @@ class NetworkMessageLaunch: public NetworkMessage { private: Data data; +protected: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: NetworkMessageLaunch(); NetworkMessageLaunch(const GameSettings *gameSettings,int8 messageType); @@ -292,6 +322,7 @@ class NetworkMessageLaunch: public NetworkMessage { #pragma pack(push, 1) class NetworkMessageCommandList: public NetworkMessage { + private: //static const int maxCommandCount = 2496; // can be as large as 65535 @@ -317,6 +348,22 @@ class NetworkMessageCommandList: public NetworkMessage { private: Data data; +protected: + virtual const char * getPackedMessageFormat() const { return NULL; } + virtual unsigned int getPackedSize() { return 0; } + virtual void unpackMessage(unsigned char *buf) { }; + virtual unsigned char * packMessage() { return NULL; } + + const char * getPackedMessageFormatHeader() const; + unsigned int getPackedSizeHeader(); + void unpackMessageHeader(unsigned char *buf); + unsigned char * packMessageHeader(); + + const char * getPackedMessageFormatDetail() const; + unsigned int getPackedSizeDetail(int count); + void unpackMessageDetail(unsigned char *buf,int count); + unsigned char * packMessageDetail(uint16 totalCommand); + public: NetworkMessageCommandList(int32 frameCount= -1); @@ -359,6 +406,12 @@ class NetworkMessageText: public NetworkMessage { private: Data data; +protected: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: NetworkMessageText(){} NetworkMessageText(const string &text, int teamIndex, int playerIndex, @@ -395,6 +448,12 @@ class NetworkMessageQuit: public NetworkMessage{ private: Data data; +protected: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: NetworkMessageQuit(); @@ -458,6 +517,21 @@ static const int maxFileCRCPacketCount= 25; private: Data data; +protected: + virtual const char * getPackedMessageFormat() const { return NULL; } + virtual unsigned int getPackedSize() { return 0; } + virtual void unpackMessage(unsigned char *buf) { }; + virtual unsigned char * packMessage() { return NULL; } + + const char * getPackedMessageFormatHeader() const; + unsigned int getPackedSizeHeader(); + void unpackMessageHeader(unsigned char *buf); + unsigned char * packMessageHeader(); + + unsigned int getPackedSizeDetail(); + void unpackMessageDetail(unsigned char *buf); + unsigned char * packMessageDetail(); + public: NetworkMessageSynchNetworkGameData() {}; NetworkMessageSynchNetworkGameData(const GameSettings *gameSettings); @@ -531,6 +605,12 @@ static const int maxFileCRCPacketCount= 25; private: Data data; +protected: + virtual const char * getPackedMessageFormat() const { return NULL; } + virtual unsigned int getPackedSize() { return 0; } + virtual void unpackMessage(unsigned char *buf) { }; + virtual unsigned char * packMessage() { return NULL; } + public: NetworkMessageSynchNetworkGameDataStatus() {}; NetworkMessageSynchNetworkGameDataStatus(uint32 mapCRC, uint32 tilesetCRC, uint32 techCRC, vector > &vctFileList); @@ -581,6 +661,12 @@ static const int maxStringSize= 256; private: Data data; +protected: + virtual const char * getPackedMessageFormat() const { return NULL; } + virtual unsigned int getPackedSize() { return 0; } + virtual void unpackMessage(unsigned char *buf) { }; + virtual unsigned char * packMessage() { return NULL; } + public: NetworkMessageSynchNetworkGameDataFileCRCCheck() {}; NetworkMessageSynchNetworkGameDataFileCRCCheck(uint32 totalFileCount, uint32 fileIndex, uint32 fileCRC, const string fileName); @@ -622,6 +708,12 @@ static const int maxStringSize= 256; private: Data data; +protected: + virtual const char * getPackedMessageFormat() const { return NULL; } + virtual unsigned int getPackedSize() { return 0; } + virtual void unpackMessage(unsigned char *buf) { }; + virtual unsigned char * packMessage() { return NULL; } + public: NetworkMessageSynchNetworkGameDataFileGet() {}; NetworkMessageSynchNetworkGameDataFileGet(const string fileName); @@ -677,6 +769,12 @@ class SwitchSetupRequest: public NetworkMessage{ private: Data data; +public: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: SwitchSetupRequest(); SwitchSetupRequest( string selectedFactionName, int8 currentFactionIndex, @@ -724,6 +822,12 @@ class PlayerIndexMessage: public NetworkMessage{ private: Data data; +protected: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: PlayerIndexMessage( int16 playerIndex); @@ -777,6 +881,12 @@ class NetworkMessageLoadingStatus : public NetworkMessage { private: Data data; +protected: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: NetworkMessageLoadingStatus(); NetworkMessageLoadingStatus(uint32 status); @@ -818,6 +928,12 @@ class NetworkMessageMarkCell: public NetworkMessage { private: Data data; +protected: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: NetworkMessageMarkCell(){} NetworkMessageMarkCell(Vec2i target, int factionIndex, const string &text, int playerIndex); @@ -858,6 +974,12 @@ class NetworkMessageUnMarkCell: public NetworkMessage { private: Data data; +protected: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: NetworkMessageUnMarkCell(){} NetworkMessageUnMarkCell(Vec2i target, int factionIndex); @@ -899,6 +1021,12 @@ class NetworkMessageHighlightCell: public NetworkMessage { private: Data data; +protected: + virtual const char * getPackedMessageFormat() const; + virtual unsigned int getPackedSize(); + virtual void unpackMessage(unsigned char *buf); + virtual unsigned char * packMessage(); + public: NetworkMessageHighlightCell(){} NetworkMessageHighlightCell(Vec2i target, int factionIndex); diff --git a/source/glest_game/network/network_types.cpp b/source/glest_game/network/network_types.cpp index b595ef22f..94c31b6ee 100644 --- a/source/glest_game/network/network_types.cpp +++ b/source/glest_game/network/network_types.cpp @@ -16,7 +16,6 @@ #include "unit_type.h" #include "game.h" #include "gui.h" - #include "leak_dumper.h" using namespace Shared::Util; diff --git a/source/glest_game/network/network_types.h b/source/glest_game/network/network_types.h index 52f0daea1..224935821 100644 --- a/source/glest_game/network/network_types.h +++ b/source/glest_game/network/network_types.h @@ -35,7 +35,6 @@ using Shared::Graphics::Vec2i; namespace Glest{ namespace Game{ class World; - // ===================================================== // class NetworkString // ===================================================== @@ -62,6 +61,7 @@ class NetworkString{ buffer[maxBufferSize-1] = '\0'; } + char *getBuffer() { return &buffer[0]; } string getString() const { return (buffer[0] != '\0' ? buffer : ""); } }; #pragma pack(pop) @@ -88,21 +88,6 @@ enum NetworkCommandType { #pragma pack(push, 1) class NetworkCommand { -private: - int16 networkCommandType; - int32 unitId; - int16 unitTypeId; - int16 commandTypeId; - int16 positionX; - int16 positionY; - int32 targetId; - int8 wantQueue; - int8 fromFactionIndex; - uint16 unitFactionUnitCount; - int8 unitFactionIndex; - int8 commandStateType; - int32 commandStateValue; - int32 unitCommandGroupId; public: NetworkCommand() { @@ -136,6 +121,21 @@ class NetworkCommand { int commandTypeStateValue = -1, int unitCommandGroupId = -1); + int16 networkCommandType; + int32 unitId; + int16 unitTypeId; + int16 commandTypeId; + int16 positionX; + int16 positionY; + int32 targetId; + int8 wantQueue; + int8 fromFactionIndex; + uint16 unitFactionUnitCount; + int8 unitFactionIndex; + int8 commandStateType; + int32 commandStateValue; + int32 unitCommandGroupId; + NetworkCommandType getNetworkCommandType() const {return static_cast(networkCommandType);} int getUnitId() const {return unitId;} int getCommandTypeId() const {return commandTypeId;} diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 8be1d28e6..586c0f5dd 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -49,7 +49,7 @@ const int MAX_SLOT_THREAD_WAIT_TIME = 3; const int MASTERSERVER_HEARTBEAT_GAME_STATUS_SECONDS = 30; ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); serverSynchAccessor = new Mutex(); for(int i= 0; i < GameConstants::maxPlayers; ++i) { @@ -91,18 +91,18 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { maxClientLagTimeAllowed = Config::getInstance().getInt("MaxClientLagTimeAllowed", intToStr(maxClientLagTimeAllowed).c_str()); warnFrameCountLagPercent = Config::getInstance().getFloat("WarnFrameCountLagPercent", doubleToStr(warnFrameCountLagPercent).c_str()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] maxFrameCountLagAllowed = %f, maxFrameCountLagAllowedEver = %f, maxClientLagTimeAllowed = %f, maxClientLagTimeAllowedEver = %f\n",__FILE__,__FUNCTION__,__LINE__,maxFrameCountLagAllowed,maxFrameCountLagAllowedEver,maxClientLagTimeAllowed,maxClientLagTimeAllowedEver); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] maxFrameCountLagAllowed = %f, maxFrameCountLagAllowedEver = %f, maxClientLagTimeAllowed = %f, maxClientLagTimeAllowedEver = %f\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,maxFrameCountLagAllowed,maxFrameCountLagAllowedEver,maxClientLagTimeAllowed,maxClientLagTimeAllowedEver); for(int i= 0; i < GameConstants::maxPlayers; ++i) { slots[i] = NULL; switchSetupRequests[i] = NULL; } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); serverSocket.setBlock(false); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); serverSocket.setBindPort(Config::getInstance().getInt("PortServer", intToStr(GameConstants::serverPort).c_str())); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); /* Config &config = Config::getInstance(); @@ -180,10 +180,10 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); int portNumber = Config::getInstance().getInt("FTPServerPort",intToStr(ServerSocket::getFTPServerPort()).c_str()); ServerSocket::setFTPServerPort(portNumber); - //printf("In [%s::%s] portNumber = %d ServerSocket::getFTPServerPort() = %d\n",__FILE__,__FUNCTION__,__LINE__,portNumber,ServerSocket::getFTPServerPort()); + //printf("In [%s::%s] portNumber = %d ServerSocket::getFTPServerPort() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,portNumber,ServerSocket::getFTPServerPort()); bool allowInternetTilesetFileTransfers = Config::getInstance().getBool("EnableFTPServerInternetTilesetXfer","true"); bool allowInternetTechtreeFileTransfers = Config::getInstance().getBool("EnableFTPServerInternetTechtreeXfer","true"); @@ -198,14 +198,14 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { if(publishToMasterserverThread == NULL) { if(needToRepublishToMasterserver == true || GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { publishToMasterserverThread = new SimpleTaskThread(this,0,125); - publishToMasterserverThread->setUniqueID(__FILE__); + publishToMasterserverThread->setUniqueID(extractFileFromDirectoryPath(__FILE__).c_str()); publishToMasterserverThread->start(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,needToRepublishToMasterserver); } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ServerInterface::setPublishEnabled(bool value) { @@ -234,7 +234,7 @@ void ServerInterface::shutdownMasterserverPublishThread() { ServerInterface::~ServerInterface() { //printf("===> Destructor for ServerInterface\n"); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); exitServer = true; for(int i= 0; i < GameConstants::maxPlayers; ++i) { if(slots[i] != NULL) { @@ -249,7 +249,7 @@ ServerInterface::~ServerInterface() { } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); close(); if(ftpServer != NULL) { ftpServer->shutdownAndWait(); @@ -295,7 +295,7 @@ ServerInterface::~ServerInterface() { } broadcastMessageQueue.clear(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } int ServerInterface::isValidClientType(uint32 clientIp) { @@ -324,7 +324,7 @@ int ServerInterface::isClientAllowedToGetFile(uint32 clientIp, const char *usern string user = username; string file = filename; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d username [%s] file [%s]\n",__FILE__,__FUNCTION__,__LINE__,username,filename); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d username [%s] file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,username,filename); if(StartsWith(user,"tilesets") == true && EndsWith(file,"7z") == false) { if(Config::getInstance().getBool("DisableFTPServerXferUncompressedTilesets","false") == true) { @@ -341,7 +341,7 @@ int ServerInterface::isClientAllowedToGetFile(uint32 clientIp, const char *usern for(unsigned int i = 0; i < serverList.size(); ++i) { string serverIP = serverList[i]; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d clientIP [%s] serverIP [%s] %d / %d\n",__FILE__,__FUNCTION__,__LINE__,clientIP.c_str(),serverIP.c_str(),i,serverList.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d clientIP [%s] serverIP [%s] %d / %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,clientIP.c_str(),serverIP.c_str(),i,serverList.size()); vector clientTokens; Tokenize(clientIP,clientTokens,"."); @@ -355,7 +355,7 @@ int ServerInterface::isClientAllowedToGetFile(uint32 clientIp, const char *usern clientTokens[2] == serverTokens[2]) { result = 1; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d clientIP [%s] IS NOT BLOCKED\n",__FILE__,__FUNCTION__,__LINE__,clientIP.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d clientIP [%s] IS NOT BLOCKED\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,clientIP.c_str()); break; } @@ -372,11 +372,11 @@ void ServerInterface::addClientToServerIPAddress(uint32 clientIp, uint32 ServerI } void ServerInterface::addSlot(int playerIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); //assert(playerIndex >= 0 && playerIndex < GameConstants::maxPlayers); if(playerIndex < 0 || playerIndex >= GameConstants::maxPlayers) { char szBuf[8096]=""; - snprintf(szBuf,8096,"In [%s::%s %d] playerIndex is invalid = %d",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex); + snprintf(szBuf,8096,"In [%s::%s %d] playerIndex is invalid = %d",extractFileFromDirectoryPath(extractFileFromDirectoryPath(__FILE__).c_str()).c_str(),__FUNCTION__,__LINE__,playerIndex); throw megaglest_runtime_error(szBuf); } MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE); @@ -384,42 +384,42 @@ void ServerInterface::addSlot(int playerIndex) { serverSocketAdmin->listen(5); } if(serverSocket.isPortBound() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); serverSocket.bind(serverSocket.getBindPort()); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex)); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); ConnectionSlot *slot = slots[playerIndex]; if(slot != NULL) { slots[playerIndex]=NULL; } slots[playerIndex] = new ConnectionSlot(this, playerIndex); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); safeMutexSlot.ReleaseLock(); delete slot; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); safeMutex.ReleaseLock(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); updateListen(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } bool ServerInterface::switchSlot(int fromPlayerIndex, int toPlayerIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); bool result = false; //assert(fromPlayerIndex >= 0 && fromPlayerIndex < GameConstants::maxPlayers); if(fromPlayerIndex < 0 || fromPlayerIndex >= GameConstants::maxPlayers) { char szBuf[8096]=""; - snprintf(szBuf,8096,"In [%s::%s %d] fromPlayerIndex is invalid = %d",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,fromPlayerIndex); + snprintf(szBuf,8096,"In [%s::%s %d] fromPlayerIndex is invalid = %d",extractFileFromDirectoryPath(extractFileFromDirectoryPath(__FILE__).c_str()).c_str(),__FUNCTION__,__LINE__,fromPlayerIndex); throw megaglest_runtime_error(szBuf); } //assert(toPlayerIndex >= 0 && toPlayerIndex < GameConstants::maxPlayers); if(toPlayerIndex < 0 || toPlayerIndex >= GameConstants::maxPlayers) { char szBuf[8096]=""; - snprintf(szBuf,8096,"In [%s::%s %d] toPlayerIndex is invalid = %d",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,toPlayerIndex); + snprintf(szBuf,8096,"In [%s::%s %d] toPlayerIndex is invalid = %d",extractFileFromDirectoryPath(extractFileFromDirectoryPath(__FILE__).c_str()).c_str(),__FUNCTION__,__LINE__,toPlayerIndex); throw megaglest_runtime_error(szBuf); } @@ -450,17 +450,17 @@ bool ServerInterface::switchSlot(int fromPlayerIndex, int toPlayerIndex) { safeMutexSlot2.ReleaseLock(); safeMutex.ReleaseLock(); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return result; } void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) { Lang &lang= Lang::getInstance(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE); MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(playerIndex)); if(playerIndex != lockedSlotIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); safeMutexSlot.setMutex(slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex)); } ConnectionSlot *slot = slots[playerIndex]; @@ -468,7 +468,7 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) { vector msgList; const vector languageList = this->gameSettings.getUniqueNetworkPlayerLanguages(); if(slot != NULL) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); if(slot->getLastReceiveCommandListTime() > 0) { char szBuf[4096] = ""; @@ -483,7 +483,7 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) { #else snprintf(szBuf,4095,msgTemplate.c_str(),slot->getName().c_str()); #endif - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,szBuf); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,szBuf); msgList.push_back(szBuf); } @@ -491,18 +491,18 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) { notifyDisconnect = true; } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); slots[playerIndex]= NULL; safeMutexSlot.ReleaseLock(); safeMutex.ReleaseLock(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); delete slot; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); updateListen(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); if(notifyDisconnect == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); //string sMsg = szBuf; //sendTextMessage(sMsg,-1, true, lockedSlotIndex); //const vector languageList = this->gameSettings.getUniqueNetworkPlayerLanguages(); @@ -513,7 +513,7 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) { //printf("j = %d [%s] localEcho = %d [%s]\n",j,msgList[j].c_str(),localEcho,languageList[j].c_str()); } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); } ConnectionSlot *ServerInterface::getSlot(int playerIndex) { @@ -586,7 +586,7 @@ void ServerInterface::slotUpdateTask(ConnectionSlotEvent *event) { // } // } // else { -// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); +// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); // } // } } @@ -610,37 +610,37 @@ void ServerInterface::slotUpdateTask(ConnectionSlotEvent *event) { // connectionSlot = slots[event->triggerId]; // } // else { -// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR CONDITION, event->triggerId = %d\n",__FILE__,__FUNCTION__,__LINE__,event->triggerId); -// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] ERROR CONDITION, event->triggerId = %d\n",__FILE__,__FUNCTION__,__LINE__,event->triggerId); +// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR CONDITION, event->triggerId = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,event->triggerId); +// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] ERROR CONDITION, event->triggerId = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,event->triggerId); // } // -// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); +// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); // -// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); +// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); // // if(connectionSlot != NULL && // (gameHasBeenInitiated == false || // (connectionSlot->getSocket() != NULL && socketTriggered == true))) { // if(connectionSlot->isConnected() == false || socketTriggered == true) { -// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); +// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); // // //safeMutexSlot.ReleaseLock(true); // connectionSlot->update(checkForNewClients,event->triggerId); // -// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); +// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); // // //chrono.start(); // //safeMutexSlot.Lock(); // //connectionSlot = slots[event->triggerId]; // -// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); +// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); // // // This means no clients are trying to connect at the moment // if(connectionSlot != NULL && connectionSlot->getSocket() == NULL) { // checkForNewClients = false; // } // } -// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); +// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); // } // safeMutexSlot.ReleaseLock(); // @@ -648,8 +648,8 @@ void ServerInterface::slotUpdateTask(ConnectionSlotEvent *event) { // //printf("===> END slot %d - About to updateSlot\n",event->triggerId); // } // } -// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); -// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); +// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); +// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); //} std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionSlot, bool skipNetworkBroadCast) { @@ -685,11 +685,11 @@ std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionS double clientLagTime = difftime((long int)time(NULL),connectionSlot->getLastReceiveCommandListTime()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(this->getCurrentFrameCount() > 0) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, clientLag = %f, clientLagCount = %f, this->getCurrentFrameCount() = %d, connectionSlot->getCurrentFrameCount() = %d, clientLagTime = %f\n", - __FILE__,__FUNCTION__,__LINE__, + extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__, connectionSlot->getPlayerIndex(), clientLag,clientLagCount, this->getCurrentFrameCount(), @@ -740,9 +740,9 @@ std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionS #else snprintf(szBuf,4095,msgTemplate.c_str(),connectionSlot->getName().c_str(),maxFrameCountLagAllowed,maxClientLagTimeAllowed,clientLagCount,clientLagTime); #endif - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,szBuf); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,szBuf); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(skipNetworkBroadCast == false) { string sMsg = szBuf; @@ -757,7 +757,7 @@ std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionS connectionSlot->close(); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } // New lag check warning else if((maxFrameCountLagAllowed > 0 && warnFrameCountLagPercent > 0 && @@ -784,9 +784,9 @@ std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionS #else snprintf(szBuf,4095,msgTemplate.c_str(),connectionSlot->getName().c_str(),maxFrameCountLagAllowed,maxClientLagTimeAllowed,clientLagCount,clientLagTime); #endif - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,szBuf); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,szBuf); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(skipNetworkBroadCast == false) { string sMsg = szBuf; @@ -799,7 +799,7 @@ std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionS else if(connectionSlot->getLagCountWarning() == true) { connectionSlot->setLagCountWarning(false); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } } } @@ -807,12 +807,12 @@ std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionS catch(const exception &ex) { alreadyInLagCheck = false; - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); throw megaglest_runtime_error(ex.what()); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); alreadyInLagCheck = false; return clientLagExceededOrWarned; @@ -928,8 +928,8 @@ void ServerInterface::checkForCompletedClients(std::map & mapSlotSigna } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); errorMsgList.push_back(ex.what()); } @@ -985,7 +985,7 @@ void ServerInterface::checkForLaggingClients(std::map &mapSlotSignalle connectionSlot->isConnected() == true) { clientLagExceededOrWarned = clientLagCheck(connectionSlot,slotsWarnedList[i]); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, gameSettings.getNetworkPauseGameForLaggedClients() = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,gameSettings.getNetworkPauseGameForLaggedClients()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, gameSettings.getNetworkPauseGameForLaggedClients() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,gameSettings.getNetworkPauseGameForLaggedClients()); if(clientLagExceededOrWarned.first == true) { slotsWarnedList[i] = true; @@ -997,11 +997,11 @@ void ServerInterface::checkForLaggingClients(std::map &mapSlotSignalle if((clientLagExceededOrWarned.first == true && gameSettings.getNetworkPauseGameForLaggedClients() == true)) { // || //(clientLagExceededOrWarned.second == true && slotsWarnedAndRetried[i] == false)) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, difftime(time(NULL),waitForClientsElapsed) = %.2f, MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE = %.2f\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,difftime((long int)time(NULL),waitForClientsElapsed),MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, difftime(time(NULL),waitForClientsElapsed) = %.2f, MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE = %.2f\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,difftime((long int)time(NULL),waitForClientsElapsed),MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE); if(difftime((long int)time(NULL),waitForClientsElapsed) < MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE) { if(connectionSlot != NULL) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second); bool socketTriggered = false; PLATFORM_SOCKET clientSocket = connectionSlot->getSocketId(); @@ -1012,7 +1012,7 @@ void ServerInterface::checkForLaggingClients(std::map &mapSlotSignalle mapSlotSignalledList[i] = signalClientReceiveCommands(connectionSlot,i,socketTriggered,event); threadsDone = false; } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d, clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second); } } else { @@ -1021,8 +1021,8 @@ void ServerInterface::checkForLaggingClients(std::map &mapSlotSignalle } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); errorMsgList.push_back(ex.what()); } } @@ -1043,7 +1043,7 @@ void ServerInterface::checkForLaggingClients(std::map &mapSlotSignalle lastGlobalLagCheckTimeUpdate = true; clientLagExceededOrWarned = clientLagCheck(connectionSlot,slotsWarnedList[i]); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, gameSettings.getNetworkPauseGameForLaggedClients() = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,gameSettings.getNetworkPauseGameForLaggedClients()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, gameSettings.getNetworkPauseGameForLaggedClients() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,gameSettings.getNetworkPauseGameForLaggedClients()); if(clientLagExceededOrWarned.first == true) { slotsWarnedList[i] = true; @@ -1052,8 +1052,8 @@ void ServerInterface::checkForLaggingClients(std::map &mapSlotSignalle } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); errorMsgList.push_back(ex.what()); } } @@ -1104,18 +1104,18 @@ void ServerInterface::dispatchPendingChatMessages(std::vector &errorMsg int newChatPlayerIndex = msg.chatPlayerIndex; string newChatLanguage = msg.targetLanguage; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatTeamIndex = %d, newChatPlayerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatTeamIndex = %d, newChatPlayerIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex); if(newChatLanguage == "" || newChatLanguage == connectionSlot->getNetworkPlayerLanguage()) { NetworkMessageText networkMessageText(newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex,newChatLanguage); broadcastMessage(&networkMessageText, connectionSlot->getPlayerIndex(),i); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d\n",__FILE__,__FUNCTION__,__LINE__,i); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i); // Its possible that the slot is disconnected here // so check the original pointer again if(slots[i] != NULL) { @@ -1123,8 +1123,8 @@ void ServerInterface::dispatchPendingChatMessages(std::vector &errorMsg } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); errorMsgList.push_back(ex.what()); } } @@ -1150,11 +1150,11 @@ void ServerInterface::dispatchPendingMarkCellMessages(std::vector &erro NetworkMessageMarkCell networkMessageMarkCell(msg.getTargetPos(),msg.getFactionIndex(),msg.getNote(),msg.getPlayerIndex()); broadcastMessage(&networkMessageMarkCell, connectionSlot->getPlayerIndex(),i); - //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d\n",__FILE__,__FUNCTION__,__LINE__,i); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i); // Its possible that the slot is disconnected here // so check the original pointer again if(slots[i] != NULL) { @@ -1162,8 +1162,8 @@ void ServerInterface::dispatchPendingMarkCellMessages(std::vector &erro } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); errorMsgList.push_back(ex.what()); } } @@ -1190,7 +1190,7 @@ void ServerInterface::dispatchPendingHighlightCellMessages(std::vector } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d\n",__FILE__,__FUNCTION__,__LINE__,i); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i); // Its possible that the slot is disconnected here // so check the original pointer again if(slots[i] != NULL) { @@ -1198,8 +1198,8 @@ void ServerInterface::dispatchPendingHighlightCellMessages(std::vector } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); errorMsgList.push_back(ex.what()); } } @@ -1225,11 +1225,11 @@ void ServerInterface::dispatchPendingUnMarkCellMessages(std::vector &er NetworkMessageUnMarkCell networkMessageMarkCell(msg.getTargetPos(),msg.getFactionIndex()); broadcastMessage(&networkMessageMarkCell, connectionSlot->getPlayerIndex(),i); - //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d\n",__FILE__,__FUNCTION__,__LINE__,i); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i); // Its possible that the slot is disconnected here // so check the original pointer again if(slots[i] != NULL) { @@ -1237,8 +1237,8 @@ void ServerInterface::dispatchPendingUnMarkCellMessages(std::vector &er } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); errorMsgList.push_back(ex.what()); } } @@ -1259,14 +1259,14 @@ void ServerInterface::update() { //printf("\nServerInterface::update -- B\n"); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); processTextMessageQueue(); processBroadCastMessageQueue(); //printf("\nServerInterface::update -- C\n"); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); std::map socketTriggeredList; //update all slots @@ -1274,7 +1274,7 @@ void ServerInterface::update() { //printf("\nServerInterface::update -- D\n"); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(gameHasBeenInitiated == false || socketTriggeredList.empty() == false) { //printf("\nServerInterface::update -- E\n"); @@ -1282,47 +1282,47 @@ void ServerInterface::update() { std::map eventList; bool hasData = Socket::hasDataToRead(socketTriggeredList); - if(hasData) if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] hasData == true\n",__FILE__,__FUNCTION__); + if(hasData) if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] hasData == true\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); if(gameHasBeenInitiated == false || hasData == true) { std::map mapSlotSignalledList; // Step #1 tell all connection slot worker threads to receive socket data signalClientsToRecieveData(socketTriggeredList, eventList, mapSlotSignalledList); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #2\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #2\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); // Step #2 check all connection slot worker threads for completed status checkForCompletedClients(mapSlotSignalledList,errorMsgList, eventList); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #3\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #3\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); // Step #3 check clients for any lagging scenarios and try to deal with them checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #4\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #4\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); // Step #4 dispatch network commands to the pending list so that they are done in proper order executeNetworkCommandsFromClients(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #5\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #5\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); // Step #5 dispatch pending chat messages dispatchPendingChatMessages(errorMsgList); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); dispatchPendingMarkCellMessages(errorMsgList); dispatchPendingUnMarkCellMessages(errorMsgList); dispatchPendingHighlightCellMessages(errorMsgList); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } else if(gameHasBeenInitiated == true && difftime((long int)time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) { @@ -1334,7 +1334,7 @@ void ServerInterface::update() { checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } else if(gameHasBeenInitiated == true && difftime((long int)time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) { @@ -1381,8 +1381,8 @@ void ServerInterface::update() { catch(const exception &ex) { //printf("\nServerInterface::update -- H\n"); - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); errorMsgList.push_back(ex.what()); } if(errorMsgList.empty() == false){ @@ -1394,14 +1394,14 @@ void ServerInterface::update() { } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); } void ServerInterface::updateKeyframe(int frameCount) { Chrono chrono; if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); currentFrameCount = frameCount; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] currentFrameCount = %d, requestedCommands.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,currentFrameCount,requestedCommands.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] currentFrameCount = %d, requestedCommands.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,currentFrameCount,requestedCommands.size()); NetworkMessageCommandList networkMessageCommandList(frameCount); while(requestedCommands.empty() == false) { @@ -1419,24 +1419,24 @@ void ServerInterface::updateKeyframe(int frameCount) { // to be sent in this frame if(requestedCommands.empty() == false) { //char szBuf[1024]=""; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,requestedCommands.size()); - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,requestedCommands.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,requestedCommands.size()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] WARNING / ERROR, requestedCommands.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,requestedCommands.size()); string sMsg = "may go out of synch: server requestedCommands.size() = " + intToStr(requestedCommands.size()); sendTextMessage(sMsg,-1, true,""); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] build command list took %lld msecs, networkMessageCommandList.getCommandCount() = %d, frameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),networkMessageCommandList.getCommandCount(),frameCount); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] build command list took %lld msecs, networkMessageCommandList.getCommandCount() = %d, frameCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),networkMessageCommandList.getCommandCount(),frameCount); //broadcast commands broadcastMessage(&networkMessageCommandList); } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); DisplayErrorMessage(ex.what()); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] broadcastMessage took %lld msecs, networkMessageCommandList.getCommandCount() = %d, frameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),networkMessageCommandList.getCommandCount(),frameCount); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] broadcastMessage took %lld msecs, networkMessageCommandList.getCommandCount() = %d, frameCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),networkMessageCommandList.getCommandCount(),frameCount); } bool ServerInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMessageType, ConnectionSlot *connectionSlot) { @@ -1481,12 +1481,12 @@ bool ServerInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess int newChatPlayerIndex = msg.chatPlayerIndex; string newChatLanguage = msg.targetLanguage.c_str(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatTeamIndex = %d, newChatPlayerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatTeamIndex = %d, newChatPlayerIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex); NetworkMessageText networkMessageText(newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex,newChatLanguage); broadcastMessage(&networkMessageText, connectionSlot->getPlayerIndex()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtText chatText [%s] chatTeamIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); } break; @@ -1511,7 +1511,7 @@ bool ServerInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess networkMessageMarkCell.getPlayerIndex()); broadcastMessage(&networkMessageMarkCellBroadcast, connectionSlot->getPlayerIndex()); - //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtMarkCell chatText [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtMarkCell chatText [%s] chatTeamIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); } break; @@ -1532,7 +1532,7 @@ bool ServerInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess networkMessageMarkCell.getFactionIndex()); broadcastMessage(&networkMessageMarkCellBroadcast, connectionSlot->getPlayerIndex()); - //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtMarkCell chatText [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtMarkCell chatText [%s] chatTeamIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex); } break; @@ -1553,7 +1553,7 @@ bool ServerInterface::shouldDiscardNetworkMessage(NetworkMessageType networkMess networkMessageHighlightCell.getFactionIndex()); broadcastMessage(&networkMessageHighlightCellBroadcast, connectionSlot->getPlayerIndex()); - //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtMarkCell chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatTeamIndex); + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after broadcast nmtMarkCell chatTeamIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,newChatTeamIndex); } break; @@ -1819,8 +1819,8 @@ void ServerInterface::waitUntilReady(Checksum *checksum) { gameStartTime = time(NULL); } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); DisplayErrorMessage(ex.what()); } if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s] END\n",__FUNCTION__); @@ -1829,7 +1829,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) { void ServerInterface::processBroadCastMessageQueue() { MutexSafeWrapper safeMutexSlot(broadcastMessageQueueThreadAccessor,CODE_AT_LINE); if(broadcastMessageQueue.empty() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] broadcastMessageQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,broadcastMessageQueue.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] broadcastMessageQueue.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,broadcastMessageQueue.size()); for(int i = 0; i < broadcastMessageQueue.size(); ++i) { pair &item = broadcastMessageQueue[i]; if(item.first != NULL) { @@ -1853,7 +1853,7 @@ void ServerInterface::queueBroadcastMessage(NetworkMessage *networkMessage, int void ServerInterface::processTextMessageQueue() { MutexSafeWrapper safeMutexSlot(textMessageQueueThreadAccessor,CODE_AT_LINE); if(textMessageQueue.empty() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] textMessageQueue.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,textMessageQueue.size()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] textMessageQueue.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,textMessageQueue.size()); for(int i = 0; i < textMessageQueue.size(); ++i) { TextMessageQueue &item = textMessageQueue[i]; sendTextMessage(item.text, item.teamIndex, item.echoLocal, item.targetLanguage); @@ -1886,17 +1886,17 @@ void ServerInterface::sendTextMessage(const string& text, int teamIndex, bool ec //printf("Line: %d text [%s] echoLocal = %d\n",__LINE__,text.c_str(),echoLocal); //assert(text.length() > 0); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] text [%s] teamIndex = %d, echoLocal = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,text.c_str(),teamIndex,echoLocal,lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] text [%s] teamIndex = %d, echoLocal = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,text.c_str(),teamIndex,echoLocal,lockedSlotIndex); NetworkMessageText networkMessageText(text, teamIndex, getHumanPlayerIndex(), targetLanguage); broadcastMessage(&networkMessageText, -1, lockedSlotIndex); if(echoLocal == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); //ChatMsgInfo msg(text.c_str(),networkMessageText.getSender().c_str(),teamIndex,networkMessageText.getPlayerIndex()); ChatMsgInfo msg(text.c_str(),teamIndex,networkMessageText.getPlayerIndex(), targetLanguage); this->addChatInfo(msg); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ServerInterface::sendMarkCellMessage(Vec2i targetPos, int factionIndex, string note,int playerIndex) { @@ -1907,10 +1907,10 @@ void ServerInterface::sendMarkCellMessage(Vec2i targetPos, int factionIndex, str //printf("Line: %d text [%s] echoLocal = %d\n",__LINE__,text.c_str(),echoLocal); //assert(text.length() > 0); - //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] text [%s] teamIndex = %d, echoLocal = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,text.c_str(),teamIndex,echoLocal,lockedSlotIndex); + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] text [%s] teamIndex = %d, echoLocal = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,text.c_str(),teamIndex,echoLocal,lockedSlotIndex); NetworkMessageMarkCell networkMessageMarkCell(targetPos,factionIndex, note, playerIndex); broadcastMessage(&networkMessageMarkCell, -1, lockedSlotIndex); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ServerInterface::sendHighlightCellMessage(Vec2i targetPos, int factionIndex) { @@ -1920,10 +1920,10 @@ void ServerInterface::sendHighlightCellMessage(Vec2i targetPos, int factionIndex void ServerInterface::sendHighlightCellMessage(Vec2i targetPos, int factionIndex, int lockedSlotIndex) { //printf("Line: %d echoLocal = %d\n",__LINE__,echoLocal); - //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] teamIndex = %d, echoLocal = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,teamIndex,echoLocal,lockedSlotIndex); + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] teamIndex = %d, echoLocal = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,teamIndex,echoLocal,lockedSlotIndex); NetworkMessageHighlightCell networkMessageHighlightCell(targetPos,factionIndex); broadcastMessage(&networkMessageHighlightCell, -1, lockedSlotIndex); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } @@ -1935,17 +1935,17 @@ void ServerInterface::sendUnMarkCellMessage(Vec2i targetPos, int factionIndex, i //printf("Line: %d text [%s] echoLocal = %d\n",__LINE__,text.c_str(),echoLocal); //assert(text.length() > 0); - //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] text [%s] teamIndex = %d, echoLocal = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,text.c_str(),teamIndex,echoLocal,lockedSlotIndex); + //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] text [%s] teamIndex = %d, echoLocal = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,text.c_str(),teamIndex,echoLocal,lockedSlotIndex); NetworkMessageUnMarkCell networkMessageMarkCell(targetPos,factionIndex); broadcastMessage(&networkMessageMarkCell, -1, lockedSlotIndex); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ServerInterface::quitGame(bool userManuallyQuit) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); NetworkMessageQuit networkMessageQuit; broadcastMessage(&networkMessageQuit); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } string ServerInterface::getNetworkStatus() { @@ -1978,7 +1978,7 @@ string ServerInterface::getNetworkStatus() { bool ServerInterface::launchGame(const GameSettings *gameSettings) { bool bOkToStart = true; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); ConnectionSlot *connectionSlot= slots[i]; @@ -1986,8 +1986,8 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) { (connectionSlot->getAllowDownloadDataSynch() == true || connectionSlot->getAllowGameDataSynchCheck() == true) && connectionSlot->isConnected()) { if(connectionSlot->getNetworkGameDataSynchCheckOk() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] map [%d] tile [%d] techtree [%d]\n",__FILE__,__FUNCTION__,__LINE__,connectionSlot->getNetworkGameDataSynchCheckOkMap(),connectionSlot->getNetworkGameDataSynchCheckOkTile(),connectionSlot->getNetworkGameDataSynchCheckOkTech()); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] map [%d] tile [%d] techtree [%d]\n",__FILE__,__FUNCTION__,__LINE__,connectionSlot->getNetworkGameDataSynchCheckOkMap(),connectionSlot->getNetworkGameDataSynchCheckOkTile(),connectionSlot->getNetworkGameDataSynchCheckOkTech()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] map [%d] tile [%d] techtree [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,connectionSlot->getNetworkGameDataSynchCheckOkMap(),connectionSlot->getNetworkGameDataSynchCheckOkTile(),connectionSlot->getNetworkGameDataSynchCheckOkTech()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] map [%d] tile [%d] techtree [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,connectionSlot->getNetworkGameDataSynchCheckOkMap(),connectionSlot->getNetworkGameDataSynchCheckOkTile(),connectionSlot->getNetworkGameDataSynchCheckOkTech()); bOkToStart = false; break; @@ -1998,7 +1998,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) { bool useInGameBlockingClientSockets = Config::getInstance().getBool("EnableInGameBlockingSockets","true"); if(useInGameBlockingClientSockets == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); for(int i= 0; i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); ConnectionSlot *connectionSlot= slots[i]; @@ -2008,22 +2008,22 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) { } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,needToRepublishToMasterserver); serverSocket.stopBroadCastThread(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,needToRepublishToMasterserver); NetworkMessageLaunch networkMessageLaunch(gameSettings,nmtLaunch); broadcastMessage(&networkMessageLaunch); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,needToRepublishToMasterserver); shutdownMasterserverPublishThread(); MutexSafeWrapper safeMutex(masterServerThreadAccessor,CODE_AT_LINE); lastMasterserverHeartbeatTime = 0; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ftpServer = %p\n",__FILE__,__FUNCTION__,__LINE__,ftpServer); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ftpServer = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ftpServer); if(ftpServer != NULL) { ftpServer->shutdownAndWait(); @@ -2031,15 +2031,15 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) { ftpServer = NULL; } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,needToRepublishToMasterserver); if(publishToMasterserverThread == NULL) { if(needToRepublishToMasterserver == true || GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { publishToMasterserverThread = new SimpleTaskThread(this,0,125); - publishToMasterserverThread->setUniqueID(__FILE__); + publishToMasterserverThread->setUniqueID(extractFileFromDirectoryPath(__FILE__).c_str()); publishToMasterserverThread->start(); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,needToRepublishToMasterserver); } } @@ -2049,12 +2049,12 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) { ftpServer = NULL; } } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return bOkToStart; } void ServerInterface::broadcastGameSetup(GameSettings *gameSettingsBuffer, bool setGameSettingsBuffer) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(setGameSettingsBuffer == true) { validateGameSettings(gameSettingsBuffer); //setGameSettings(gameSettingsBuffer,false); @@ -2065,12 +2065,12 @@ void ServerInterface::broadcastGameSetup(GameSettings *gameSettingsBuffer, bool MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE); NetworkMessageLaunch networkMessageLaunch(gameSettingsBuffer, nmtBroadCastSetup); broadcastMessage(&networkMessageLaunch); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ServerInterface::broadcastMessage(NetworkMessage *networkMessage, int excludeSlot, int lockedSlotIndex) { try { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); MutexSafeWrapper safeMutexSlotBroadCastAccessor(inBroadcastMessageThreadAccessor,CODE_AT_LINE); if(inBroadcastMessage == true && dynamic_cast(networkMessage) != NULL) { @@ -2088,7 +2088,7 @@ void ServerInterface::broadcastMessage(NetworkMessage *networkMessage, int exclu for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(i)); if(i != lockedSlotIndex) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,i,lockedSlotIndex); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,lockedSlotIndex); safeMutexSlot.setMutex(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); } @@ -2096,23 +2096,23 @@ void ServerInterface::broadcastMessage(NetworkMessage *networkMessage, int exclu if(i != excludeSlot && connectionSlot != NULL) { if(connectionSlot->isConnected()) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] before sendMessage\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] before sendMessage\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); connectionSlot->sendMessage(networkMessage); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after sendMessage\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] after sendMessage\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } if(gameHasBeenInitiated == true && connectionSlot->isConnected() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,__LINE__,i); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 before removeSlot for slot# %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i); //safeMutexSlot.ReleaseLock(); removeSlot(i,i); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 after removeSlot for slot# %d\n",__FILE__,__FUNCTION__,__LINE__,i); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 after removeSlot for slot# %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i); } } else if(i == excludeSlot && gameHasBeenInitiated == true && connectionSlot != NULL && connectionSlot->isConnected() == false) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 before removeSlot for slot# %d\n",__FILE__,__FUNCTION__,__LINE__,i); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 before removeSlot for slot# %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i); //safeMutexSlot.ReleaseLock(); removeSlot(i,i); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 after removeSlot for slot# %d\n",__FILE__,__FUNCTION__,__LINE__,i); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 after removeSlot for slot# %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i); } } @@ -2121,8 +2121,8 @@ void ServerInterface::broadcastMessage(NetworkMessage *networkMessage, int exclu safeMutexSlotBroadCastAccessor.ReleaseLock(); } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); MutexSafeWrapper safeMutexSlotBroadCastAccessor(inBroadcastMessageThreadAccessor,CODE_AT_LINE); inBroadcastMessage = false; @@ -2134,7 +2134,7 @@ void ServerInterface::broadcastMessage(NetworkMessage *networkMessage, int exclu } void ServerInterface::broadcastMessageToConnectedClients(NetworkMessage *networkMessage, int excludeSlot) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); try { for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); @@ -2148,11 +2148,11 @@ void ServerInterface::broadcastMessageToConnectedClients(NetworkMessage *network } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); DisplayErrorMessage(ex.what()); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ServerInterface::updateListen() { @@ -2187,7 +2187,7 @@ int ServerInterface::getOpenSlotCount() { int ServerInterface::getGameSettingsUpdateCount() { MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START gameSettingsUpdateCount = %d\n",__FILE__,__FUNCTION__,gameSettingsUpdateCount); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START gameSettingsUpdateCount = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,gameSettingsUpdateCount); int result = gameSettingsUpdateCount; safeMutex.ReleaseLock(); @@ -2196,7 +2196,7 @@ int ServerInterface::getGameSettingsUpdateCount() { void ServerInterface::validateGameSettings(GameSettings *serverGameSettings) { MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s]\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); string mapFile = serverGameSettings->getMap(); //bool useNext=false; @@ -2287,7 +2287,7 @@ void ServerInterface::validateGameSettings(GameSettings *serverGameSettings) { void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck) { MutexSafeWrapper safeMutex(serverSynchAccessor,CODE_AT_LINE); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START gameSettingsUpdateCount = %d, waitForClientAck = %d\n",__FILE__,__FUNCTION__,gameSettingsUpdateCount,waitForClientAck); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START gameSettingsUpdateCount = %d, waitForClientAck = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,gameSettingsUpdateCount,waitForClientAck); if(serverGameSettings->getScenario() == "") { string mapFile = serverGameSettings->getMap(); @@ -2319,7 +2319,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai gameSettings = *serverGameSettings; if(getAllowGameDataSynchCheck() == true) { if(waitForClientAck == true && gameSettingsUpdateCount > 0) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Waiting for client acks #1\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Waiting for client acks #1\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); time_t tStart = time(NULL); bool gotAckFromAllClients = false; @@ -2355,7 +2355,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai broadcastMessageToConnectedClients(&networkMessageSynchNetworkGameData); if(waitForClientAck == true) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Waiting for client acks #2\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Waiting for client acks #2\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); time_t tStart = time(NULL); bool gotAckFromAllClients = false; @@ -2381,11 +2381,11 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai } gameSettingsUpdateCount++; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); } void ServerInterface::close() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); } string ServerInterface::getHumanPlayerName(int index) { @@ -2407,7 +2407,7 @@ int ServerInterface::getHumanPlayerIndex() const { } std::map ServerInterface::publishToMasterserver() { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); int slotCountUsed = 1; int slotCountHumans = 1; int slotCountConnectedPlayers = 1; @@ -2420,7 +2420,7 @@ std::map ServerInterface::publishToMasterserver() { Config & config = Config::getInstance(); std::map < string, string > publishToServerInfo; - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); if(slots[i] != NULL) { @@ -2452,7 +2452,7 @@ std::map ServerInterface::publishToMasterserver() { publishToServerInfo["gameCmd"]= "gameOver"; publishToServerInfo["gameStatus"] = intToStr(game_status_finished); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return publishToServerInfo; } @@ -2460,7 +2460,7 @@ void ServerInterface::simpleTask(BaseThread *callingThread) { MutexSafeWrapper safeMutex(masterServerThreadAccessor,CODE_AT_LINE); if(difftime((long int)time(NULL),lastMasterserverHeartbeatTime) >= MASTERSERVER_HEARTBEAT_GAME_STATUS_SECONDS) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); lastMasterserverHeartbeatTime = time(NULL); if(needToRepublishToMasterserver == true) { @@ -2481,20 +2481,20 @@ void ServerInterface::simpleTask(BaseThread *callingThread) { } //printf("the request is:\n%s\n",request.c_str()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d] the request is:\n%s\n",__FILE__,__FUNCTION__,__LINE__,request.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d] the request is:\n%s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,request.c_str()); std::string serverInfo = SystemFlags::getHTTP(request,handle); SystemFlags::cleanupHTTP(&handle); //printf("the result is:\n'%s'\n",serverInfo.c_str()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d] the result is:\n'%s'\n",__FILE__,__FUNCTION__,__LINE__,serverInfo.c_str()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d] the result is:\n'%s'\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,serverInfo.c_str()); } else { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line %d] error, no masterserver defined!\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line %d] error, no masterserver defined!\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } } catch(const exception &ex) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line %d] error during game status update: [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line %d] error during game status update: [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); } } if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { @@ -2606,11 +2606,11 @@ std::string ServerInterface::DumpStatsToLog(bool dumpToStringOnly) const { void ServerInterface::notifyBadClientConnectAttempt(string ipAddress) { - //printf("In [%s::%s Line: %d] ipAddress [%s]\n",__FILE__,__FUNCTION__,__LINE__,ipAddress.c_str()); + //printf("In [%s::%s Line: %d] ipAddress [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ipAddress.c_str()); if(badClientConnectIPList.find(ipAddress) == badClientConnectIPList.end()) { badClientConnectIPList[ipAddress] = make_pair(0,(long int)time(NULL)); - //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } pair &lastBadConnectionAttempt = badClientConnectIPList[ipAddress]; @@ -2620,30 +2620,30 @@ void ServerInterface::notifyBadClientConnectAttempt(string ipAddress) { bool addToBlockedClientsList = false; if(difftime((long int)time(NULL),lastBadConnectionAttempt.second) <= BLOCK_BAD_CLIENT_CONNECT_MAX_SECONDS) { - //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(lastBadConnectionAttempt.first+1 > BLOCK_BAD_CLIENT_CONNECT_MAX_ATTEMPTS) { addToBlockedClientsList = true; - //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } } else { // Reset after x seconds lastBadConnectionAttempt.first = 0; - //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } - //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(addToBlockedClientsList == true) { serverSocket.addIPAddressToBlockedList(ipAddress); - //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } lastBadConnectionAttempt.first++; lastBadConnectionAttempt.second = time(NULL); - //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } void ServerInterface::saveGame(XmlNode *rootNode) { diff --git a/source/shared_lib/include/platform/common/byte_order.h b/source/shared_lib/include/platform/common/byte_order.h index 4530b0001..1047c41c2 100644 --- a/source/shared_lib/include/platform/common/byte_order.h +++ b/source/shared_lib/include/platform/common/byte_order.h @@ -13,6 +13,7 @@ #define BYTE_ORDER_H #include +#include "leak_dumper.h" namespace Shared{ namespace PlatformByteOrder { diff --git a/source/shared_lib/include/platform/sdl/platform_main.h b/source/shared_lib/include/platform/sdl/platform_main.h index b2708bfc3..bb96df3c8 100644 --- a/source/shared_lib/include/platform/sdl/platform_main.h +++ b/source/shared_lib/include/platform/sdl/platform_main.h @@ -88,6 +88,7 @@ const char *GAME_ARGS[] = { "--disable-opengl-checks", "--disable-streflop-checks", "--debug-network-packets", + "--enable-new-protocol", "--verbose" @@ -162,6 +163,7 @@ enum GAME_ARG_TYPE { GAME_ARG_DISABLE_STREFLOP_CAPS_CHECK, GAME_ARG_DEBUG_NETWORK_PACKETS, + GAME_ARG_ENABLE_NEW_PROTOCOL, GAME_ARG_VERBOSE_MODE,