From 96bd93721828881eb9c3483b6d629c66aa337ccd Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Thu, 21 Sep 2017 17:04:56 -0700 Subject: [PATCH] - protect lan search if not local ip's found and add a little more output --- data/glest_game | 2 +- source/glest_game/menu/menu_state_join_game.cpp | 9 +++++++-- source/shared_lib/sources/platform/posix/socket.cpp | 8 +++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/data/glest_game b/data/glest_game index d14446556..32a8f459f 160000 --- a/data/glest_game +++ b/data/glest_game @@ -1 +1 @@ -Subproject commit d1444655692f738552915fba55bf21424cdb8a7f +Subproject commit 32a8f459f095185bb503a876433ebefac77fd24e diff --git a/source/glest_game/menu/menu_state_join_game.cpp b/source/glest_game/menu/menu_state_join_game.cpp index bc9105b29..dda936bf0 100644 --- a/source/glest_game/menu/menu_state_join_game.cpp +++ b/source/glest_game/menu/menu_state_join_game.cpp @@ -285,7 +285,7 @@ void MenuStateJoinGame::DiscoveredServers(std::vector serverList) { //serverList.push_back("test2"); // - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] serverList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,(int)serverList.size()); autoConnectToServer = false; buttonAutoFindServers.setEnabled(true); @@ -308,9 +308,14 @@ void MenuStateJoinGame::DiscoveredServers(std::vector serverList) { bestIPMatch = serverList[idx]; + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] bestIPMatch = [%s]\n",__FILE__,__FUNCTION__,__LINE__,bestIPMatch.c_str()); + if(localIPList.empty() == true) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + break; + } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] bestIPMatch = [%s] localIPList[0] = [%s]\n",__FILE__,__FUNCTION__,__LINE__,bestIPMatch.c_str(),localIPList[0].c_str()); - if(strncmp(localIPList[0].c_str(),serverList[idx].c_str(),4) == 0) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); break; } } diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index b77f29363..b070955e7 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -2953,10 +2953,12 @@ void BroadCastSocketThread::execute() { std::vector ipSubnetMaskList; for(unsigned int idx = 0; idx < (unsigned int)ipList.size() && idx < (unsigned int)MAX_NIC_COUNT; idx++) { string broadCastAddress = getNetworkInterfaceBroadcastAddress(ipList[idx]); - //printf("idx = %d broadCastAddress [%s]\n",idx,broadCastAddress.c_str()); + printf("idx = %d broadCastAddress [%s]\n",idx,broadCastAddress.c_str()); //strcpy(subnetmask[idx], broadCastAddress.c_str()); if(broadCastAddress != "" && std::find(ipSubnetMaskList.begin(),ipSubnetMaskList.end(),broadCastAddress) == ipSubnetMaskList.end()) { + //printf("Adding index [%d] address to list ...\n",idx); + ipSubnetMaskList.push_back(broadCastAddress); } } @@ -2980,11 +2982,13 @@ void BroadCastSocketThread::execute() { if( bcfd[idx] <= 0 ) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Unable to allocate broadcast socket [%s]: %s\n", ipSubnetMaskList[idx].c_str(), Socket::getLastSocketErrorFormattedText().c_str()); + //printf("Unable to allocate broadcast socket [%s]: %s\n", ipSubnetMaskList[idx].c_str(), Socket::getLastSocketErrorFormattedText().c_str()); //exit(-1); } // Mark the socket for broadcast. else if( setsockopt( bcfd[idx], SOL_SOCKET, SO_BROADCAST, (const char *) &one, sizeof( int ) ) < 0 ) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Could not set socket to broadcast [%s]: %s\n", ipSubnetMaskList[idx].c_str(), Socket::getLastSocketErrorFormattedText().c_str()); + //printf("Could not set socket to broadcast [%s]: %s\n", ipSubnetMaskList[idx].c_str(), Socket::getLastSocketErrorFormattedText().c_str()); //exit(-1); } //} @@ -3013,6 +3017,7 @@ void BroadCastSocketThread::execute() { //#endif string buffCopy = buff; snprintf(buff,1024,"%s:%s:%d",buffCopy.c_str(),ipList[idx1].c_str(),this->boundPort); + //printf("About to broadcast index [%d] host info [%s]\n", idx1,buff); } if(difftime((long int)time(NULL),elapsed) >= 1 && getQuitStatus() == false) { @@ -3024,6 +3029,7 @@ void BroadCastSocketThread::execute() { //if( sendto( bcfd, buff, sizeof(buff) + 1, 0 , (struct sockaddr *)&bcaddr, sizeof(struct sockaddr_in) ) != sizeof(buff) + 1 ) if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Server is sending broadcast data [%s]\n",buff); + //printf("Broadcasting index host info [%s]\n", buff); ssize_t send_res = sendto( bcfd[idx], buff, buffMaxSize, 0 , (struct sockaddr *)&bcLocal[idx], sizeof(struct sockaddr_in) ); if( send_res != buffMaxSize ) {