diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 8b4c69c4..5eb8bbd3 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -49,6 +49,7 @@ struct FormatString { MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots,bool parentMenuIsMasterserver): MenuState(program, mainMenu, "new-game") { + publishToMasterserverThread = NULL; Lang &lang= Lang::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance(); Config &config = Config::getInstance(); @@ -545,8 +546,11 @@ void MenuStateCustomGame::update() { if(switchSetupRequests[i]!=NULL) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //printf("switchSetupRequests[i]->getSelectedFactionName()=%s\n",switchSetupRequests[i]->getSelectedFactionName().c_str()); //printf("switchSetupRequests[i]->getToTeam()=%d\n",switchSetupRequests[i]->getToTeam()); @@ -602,6 +606,8 @@ void MenuStateCustomGame::update() if(connectionSlot->isConnected()) { + //printf("FYI we have at least 1 client connected, slot = %d'\n",i); + haveAtLeastOneNetworkClientConnected = true; currentConnectionCount++; //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] B - ctNetwork\n",__FILE__,__FUNCTION__); @@ -827,11 +833,16 @@ void MenuStateCustomGame::simpleTask() { if(needToBroadcastServerSettings) { needToBroadcastServerSettings=false; - GameSettings gameSettings; - loadGameSettings(&gameSettings); ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); - serverInterface->setGameSettings(&gameSettings); - serverInterface->broadcastGameSetup(&gameSettings); + if(serverInterface->hasClientConnection() == true) { + //printf("Sending game settings broadcast since we have at least 1 client connected'\n"); + + GameSettings gameSettings; + loadGameSettings(&gameSettings); + + serverInterface->setGameSettings(&gameSettings); + serverInterface->broadcastGameSetup(&gameSettings); + } } } diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 7bab4eb8..49951910 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -237,6 +237,18 @@ ConnectionSlot* ServerInterface::getSlot(int playerIndex){ return slots[playerIndex]; } +bool ServerInterface::hasClientConnection() { + bool result = false; + + for(int i= 0; iisConnected() == true) { + result = true; + break; + } + } + return result; +} + int ServerInterface::getConnectedSlotCount(){ int connectedSlotCount= 0; diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index 4219e043..95351eda 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -121,6 +121,7 @@ public: virtual bool getConnectHasHandshaked() const { return false; } virtual void slotUpdateTask(ConnectionSlotEvent *event); + bool hasClientConnection(); private: void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index fa91e490..998e2459 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1567,7 +1567,9 @@ void ServerSocket::listen(int connectionQueueSize) { Socket *ServerSocket::accept() { - PLATFORM_SOCKET newSock= ::accept(sock, NULL, NULL); + struct sockaddr_in cli_addr; + socklen_t clilen = sizeof(cli_addr); + PLATFORM_SOCKET newSock= ::accept(sock, (struct sockaddr *) &cli_addr, &clilen); if(isSocketValid(&newSock) == false) { char szBuf[1024]=""; @@ -1582,7 +1584,9 @@ Socket *ServerSocket::accept() } else { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got connection, newSock = %d\n",__FILE__,__FUNCTION__,__LINE__,newSock); + char client_host[100]=""; + sprintf(client_host, "%s",inet_ntoa(cli_addr.sin_addr)); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] got connection, newSock = %d client_host [%s]\n",__FILE__,__FUNCTION__,__LINE__,newSock,client_host); } return new Socket(newSock); }