- protect lan search if not local ip's found and add a little more output

This commit is contained in:
SoftCoder 2017-09-21 17:04:56 -07:00
parent 9d12682fb5
commit 96bd937218
3 changed files with 15 additions and 4 deletions

@ -1 +1 @@
Subproject commit d1444655692f738552915fba55bf21424cdb8a7f
Subproject commit 32a8f459f095185bb503a876433ebefac77fd24e

View File

@ -285,7 +285,7 @@ void MenuStateJoinGame::DiscoveredServers(std::vector<string> 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<string> 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;
}
}

View File

@ -2953,10 +2953,12 @@ void BroadCastSocketThread::execute() {
std::vector<std::string> 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 ) {