diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index eabec37d4..5929ffcc9 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -166,6 +166,7 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex this->ready = false; this->gotIntro = false; + this->connectedTime = 0; networkGameDataSynchCheckOkMap = false; networkGameDataSynchCheckOkTile = false; @@ -222,9 +223,20 @@ void ConnectionSlot::update(bool checkForNewClients) { //send intro message when connected if(socket != NULL) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] accepted new client connection, serverInterface->getOpenSlotCount() = %d\n",__FILE__,__FUNCTION__,serverInterface->getOpenSlotCount()); - connectedTime = time(NULL); - + this->connectedTime = time(NULL); this->clearChatInfo(); + this->name = ""; + this->ready = false; + this->vctFileList.clear(); + this->receivedNetworkGameStatus = false; + this->gotIntro = false; + this->vctPendingNetworkCommandList.clear(); + this->currentFrameCount = 0; + this->currentLagCount = 0; + this->lastReceiveCommandListTime = 0; + this->gotLagCountWarning = false; + this->versionString = ""; + if(hasOpenSlots == false) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] no open slots, disconnecting client\n",__FILE__,__FUNCTION__); @@ -269,11 +281,15 @@ void ConnectionSlot::update(bool checkForNewClients) { { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtPing\n",__FILE__,__FUNCTION__); - NetworkMessagePing networkMessagePing; - if(receiveMessage(&networkMessagePing)) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - lastPingInfo = networkMessagePing; - } + // client REQUIRES a ping before completing intro + // authentication + //if(gotIntro == true) { + NetworkMessagePing networkMessagePing; + if(receiveMessage(&networkMessagePing)) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + lastPingInfo = networkMessagePing; + } + //} } break; @@ -281,13 +297,15 @@ void ConnectionSlot::update(bool checkForNewClients) { { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtText\n",__FILE__,__FUNCTION__); - NetworkMessageText networkMessageText; - if(receiveMessage(&networkMessageText)) { - ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex()); - this->addChatInfo(msg); - gotTextMsg = true; + if(gotIntro == true) { + NetworkMessageText networkMessageText; + if(receiveMessage(&networkMessageText)) { + ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getSender().c_str(),networkMessageText.getTeamIndex()); + this->addChatInfo(msg); + gotTextMsg = true; - //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] chatText [%s] chatSender [%s] chatTeamIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,chatText.c_str(),chatSender.c_str(),chatTeamIndex); + } } } break; @@ -299,15 +317,17 @@ void ConnectionSlot::update(bool checkForNewClients) { //throw runtime_error("test"); - NetworkMessageCommandList networkMessageCommandList; - if(receiveMessage(&networkMessageCommandList)) { - currentFrameCount = networkMessageCommandList.getFrameCount(); - lastReceiveCommandListTime = time(NULL); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] currentFrameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,currentFrameCount); + if(gotIntro == true) { + NetworkMessageCommandList networkMessageCommandList; + if(receiveMessage(&networkMessageCommandList)) { + currentFrameCount = networkMessageCommandList.getFrameCount(); + lastReceiveCommandListTime = time(NULL); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] currentFrameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,currentFrameCount); - for(int i= 0; irequestCommand(networkMessageCommandList.getCommand(i)); - vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i)); + for(int i= 0; irequestCommand(networkMessageCommandList.getCommand(i)); + vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i)); + } } } } @@ -343,93 +363,95 @@ void ConnectionSlot::update(bool checkForNewClients) { { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataStatus\n",__FILE__,__FUNCTION__); - NetworkMessageSynchNetworkGameDataStatus networkMessageSynchNetworkGameDataStatus; - if(receiveMessage(&networkMessageSynchNetworkGameDataStatus)) - { - receivedNetworkGameStatus = true; + if(gotIntro == true) { + NetworkMessageSynchNetworkGameDataStatus networkMessageSynchNetworkGameDataStatus; + if(receiveMessage(&networkMessageSynchNetworkGameDataStatus)) + { + receivedNetworkGameStatus = true; - Config &config = Config::getInstance(); - string scenarioDir = ""; - if(serverInterface->getGameSettings()->getScenarioDir() != "") { - scenarioDir = serverInterface->getGameSettings()->getScenarioDir(); - if(EndsWith(scenarioDir, ".xml") == true) { - scenarioDir = scenarioDir.erase(scenarioDir.size() - 4, 4); - scenarioDir = scenarioDir.erase(scenarioDir.size() - serverInterface->getGameSettings()->getScenario().size(), serverInterface->getGameSettings()->getScenario().size() + 1); + Config &config = Config::getInstance(); + string scenarioDir = ""; + if(serverInterface->getGameSettings()->getScenarioDir() != "") { + scenarioDir = serverInterface->getGameSettings()->getScenarioDir(); + if(EndsWith(scenarioDir, ".xml") == true) { + scenarioDir = scenarioDir.erase(scenarioDir.size() - 4, 4); + scenarioDir = scenarioDir.erase(scenarioDir.size() - serverInterface->getGameSettings()->getScenario().size(), serverInterface->getGameSettings()->getScenario().size() + 1); + } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s]\n",__FILE__,__FUNCTION__,__LINE__,serverInterface->getGameSettings()->getScenarioDir().c_str(),serverInterface->getGameSettings()->getScenario().c_str(),scenarioDir.c_str()); } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s]\n",__FILE__,__FUNCTION__,__LINE__,serverInterface->getGameSettings()->getScenarioDir().c_str(),serverInterface->getGameSettings()->getScenario().c_str(),scenarioDir.c_str()); - } + //tileset + int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + serverInterface->getGameSettings()->getTileset() + string("/*"), ".xml", NULL); + int32 techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,scenarioDir), "/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", NULL); + Checksum checksum; + string file = Map::getMapPath(serverInterface->getGameSettings()->getMap(),scenarioDir); + checksum.addFile(file); + int32 mapCRC = checksum.getSum(); - //tileset - int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + serverInterface->getGameSettings()->getTileset() + string("/*"), ".xml", NULL); - int32 techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,scenarioDir), "/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", NULL); - Checksum checksum; - string file = Map::getMapPath(serverInterface->getGameSettings()->getMap(),scenarioDir); - checksum.addFile(file); - int32 mapCRC = checksum.getSum(); + networkGameDataSynchCheckOkMap = (networkMessageSynchNetworkGameDataStatus.getMapCRC() == mapCRC); + networkGameDataSynchCheckOkTile = (networkMessageSynchNetworkGameDataStatus.getTilesetCRC() == tilesetCRC); + networkGameDataSynchCheckOkTech = (networkMessageSynchNetworkGameDataStatus.getTechCRC() == techCRC); - networkGameDataSynchCheckOkMap = (networkMessageSynchNetworkGameDataStatus.getMapCRC() == mapCRC); - networkGameDataSynchCheckOkTile = (networkMessageSynchNetworkGameDataStatus.getTilesetCRC() == tilesetCRC); - networkGameDataSynchCheckOkTech = (networkMessageSynchNetworkGameDataStatus.getTechCRC() == techCRC); + // For testing + //techCRC++; - // For testing - //techCRC++; + if( networkGameDataSynchCheckOkMap == true && + networkGameDataSynchCheckOkTile == true && + networkGameDataSynchCheckOkTech == true) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] client data synch ok\n",__FILE__,__FUNCTION__); + } + else { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] mapCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,mapCRC,networkMessageSynchNetworkGameDataStatus.getMapCRC()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] tilesetCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,tilesetCRC,networkMessageSynchNetworkGameDataStatus.getTilesetCRC()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] techCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,techCRC,networkMessageSynchNetworkGameDataStatus.getTechCRC()); - if( networkGameDataSynchCheckOkMap == true && - networkGameDataSynchCheckOkTile == true && - networkGameDataSynchCheckOkTech == true) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] client data synch ok\n",__FILE__,__FUNCTION__); - } - else { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] mapCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,mapCRC,networkMessageSynchNetworkGameDataStatus.getMapCRC()); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] tilesetCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,tilesetCRC,networkMessageSynchNetworkGameDataStatus.getTilesetCRC()); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] techCRC = %d, remote = %d\n",__FILE__,__FUNCTION__,techCRC,networkMessageSynchNetworkGameDataStatus.getTechCRC()); + if(allowDownloadDataSynch == true) { + // Now get all filenames with their CRC values and send to the client + vctFileList.clear(); - if(allowDownloadDataSynch == true) { - // Now get all filenames with their CRC values and send to the client - vctFileList.clear(); + Config &config = Config::getInstance(); + string scenarioDir = ""; + if(serverInterface->getGameSettings()->getScenarioDir() != "") { + scenarioDir = serverInterface->getGameSettings()->getScenarioDir(); + if(EndsWith(scenarioDir, ".xml") == true) { + scenarioDir = scenarioDir.erase(scenarioDir.size() - 4, 4); + scenarioDir = scenarioDir.erase(scenarioDir.size() - serverInterface->getGameSettings()->getScenario().size(), serverInterface->getGameSettings()->getScenario().size() + 1); + } - Config &config = Config::getInstance(); - string scenarioDir = ""; - if(serverInterface->getGameSettings()->getScenarioDir() != "") { - scenarioDir = serverInterface->getGameSettings()->getScenarioDir(); - if(EndsWith(scenarioDir, ".xml") == true) { - scenarioDir = scenarioDir.erase(scenarioDir.size() - 4, 4); - scenarioDir = scenarioDir.erase(scenarioDir.size() - serverInterface->getGameSettings()->getScenario().size(), serverInterface->getGameSettings()->getScenario().size() + 1); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s]\n",__FILE__,__FUNCTION__,__LINE__,serverInterface->getGameSettings()->getScenarioDir().c_str(),serverInterface->getGameSettings()->getScenario().c_str(),scenarioDir.c_str()); } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameSettings.getScenarioDir() = [%s] gameSettings.getScenario() = [%s] scenarioDir = [%s]\n",__FILE__,__FUNCTION__,__LINE__,serverInterface->getGameSettings()->getScenarioDir().c_str(),serverInterface->getGameSettings()->getScenario().c_str(),scenarioDir.c_str()); + if(networkGameDataSynchCheckOkTile == false) { + if(tilesetCRC == 0) { + //vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_tilesets) + "/" + serverInterface->getGameSettings()->getTileset() + "/*", "", &vctFileList); + vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + serverInterface->getGameSettings()->getTileset() + string("/*"), "", &vctFileList); + } + else { + //vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_tilesets) + "/" + serverInterface->getGameSettings()->getTileset() + "/*", ".xml", &vctFileList); + vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTilesets,scenarioDir), "/" + serverInterface->getGameSettings()->getTileset() + "/*", ".xml", &vctFileList); + } + } + if(networkGameDataSynchCheckOkTech == false) { + if(techCRC == 0) { + //vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_techs) + "/" + serverInterface->getGameSettings()->getTech() + "/*", "", &vctFileList); + vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", "", &vctFileList); + } + else { + //vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_techs) + "/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", &vctFileList); + vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", &vctFileList); + } + } + if(networkGameDataSynchCheckOkMap == false) { + vctFileList.push_back(std::pair(Map::getMapPath(serverInterface->getGameSettings()->getMap(),scenarioDir),mapCRC)); + } + + //for(int i = 0; i < vctFileList.size(); i++) + //{ + NetworkMessageSynchNetworkGameDataFileCRCCheck networkMessageSynchNetworkGameDataFileCRCCheck(vctFileList.size(), 1, vctFileList[0].second, vctFileList[0].first); + sendMessage(&networkMessageSynchNetworkGameDataFileCRCCheck); + //} } - - if(networkGameDataSynchCheckOkTile == false) { - if(tilesetCRC == 0) { - //vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_tilesets) + "/" + serverInterface->getGameSettings()->getTileset() + "/*", "", &vctFileList); - vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + serverInterface->getGameSettings()->getTileset() + string("/*"), "", &vctFileList); - } - else { - //vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_tilesets) + "/" + serverInterface->getGameSettings()->getTileset() + "/*", ".xml", &vctFileList); - vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTilesets,scenarioDir), "/" + serverInterface->getGameSettings()->getTileset() + "/*", ".xml", &vctFileList); - } - } - if(networkGameDataSynchCheckOkTech == false) { - if(techCRC == 0) { - //vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_techs) + "/" + serverInterface->getGameSettings()->getTech() + "/*", "", &vctFileList); - vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", "", &vctFileList); - } - else { - //vctFileList = getFolderTreeContentsCheckSumListRecursively(string(GameConstants::folder_path_techs) + "/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", &vctFileList); - vctFileList = getFolderTreeContentsCheckSumListRecursively(config.getPathListForType(ptTechs,scenarioDir),"/" + serverInterface->getGameSettings()->getTech() + "/*", ".xml", &vctFileList); - } - } - if(networkGameDataSynchCheckOkMap == false) { - vctFileList.push_back(std::pair(Map::getMapPath(serverInterface->getGameSettings()->getMap(),scenarioDir),mapCRC)); - } - - //for(int i = 0; i < vctFileList.size(); i++) - //{ - NetworkMessageSynchNetworkGameDataFileCRCCheck networkMessageSynchNetworkGameDataFileCRCCheck(vctFileList.size(), 1, vctFileList[0].second, vctFileList[0].first); - sendMessage(&networkMessageSynchNetworkGameDataFileCRCCheck); - //} } } } @@ -441,12 +463,14 @@ void ConnectionSlot::update(bool checkForNewClients) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileCRCCheck\n",__FILE__,__FUNCTION__); - NetworkMessageSynchNetworkGameDataFileCRCCheck networkMessageSynchNetworkGameDataFileCRCCheck; - if(receiveMessage(&networkMessageSynchNetworkGameDataFileCRCCheck)) - { - int fileIndex = networkMessageSynchNetworkGameDataFileCRCCheck.getFileIndex(); - NetworkMessageSynchNetworkGameDataFileCRCCheck networkMessageSynchNetworkGameDataFileCRCCheck(vctFileList.size(), fileIndex, vctFileList[fileIndex-1].second, vctFileList[fileIndex-1].first); - sendMessage(&networkMessageSynchNetworkGameDataFileCRCCheck); + if(gotIntro == true) { + NetworkMessageSynchNetworkGameDataFileCRCCheck networkMessageSynchNetworkGameDataFileCRCCheck; + if(receiveMessage(&networkMessageSynchNetworkGameDataFileCRCCheck)) + { + int fileIndex = networkMessageSynchNetworkGameDataFileCRCCheck.getFileIndex(); + NetworkMessageSynchNetworkGameDataFileCRCCheck networkMessageSynchNetworkGameDataFileCRCCheck(vctFileList.size(), fileIndex, vctFileList[fileIndex-1].second, vctFileList[fileIndex-1].first); + sendMessage(&networkMessageSynchNetworkGameDataFileCRCCheck); + } } } break; @@ -456,33 +480,37 @@ void ConnectionSlot::update(bool checkForNewClients) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got nmtSynchNetworkGameDataFileGet\n",__FILE__,__FUNCTION__); - NetworkMessageSynchNetworkGameDataFileGet networkMessageSynchNetworkGameDataFileGet; - if(receiveMessage(&networkMessageSynchNetworkGameDataFileGet)) { - FileTransferInfo fileInfo; - fileInfo.hostType = eServer; - //fileInfo.serverIP = this->ip.getString(); - fileInfo.serverPort = Config::getInstance().getInt("ServerPort",intToStr(GameConstants::serverPort).c_str()); - fileInfo.fileName = networkMessageSynchNetworkGameDataFileGet.getFileName(); + if(gotIntro == true) { + NetworkMessageSynchNetworkGameDataFileGet networkMessageSynchNetworkGameDataFileGet; + if(receiveMessage(&networkMessageSynchNetworkGameDataFileGet)) { + FileTransferInfo fileInfo; + fileInfo.hostType = eServer; + //fileInfo.serverIP = this->ip.getString(); + fileInfo.serverPort = Config::getInstance().getInt("ServerPort",intToStr(GameConstants::serverPort).c_str()); + fileInfo.fileName = networkMessageSynchNetworkGameDataFileGet.getFileName(); - FileTransferSocketThread *fileXferThread = new FileTransferSocketThread(fileInfo); - fileXferThread->start(); + FileTransferSocketThread *fileXferThread = new FileTransferSocketThread(fileInfo); + fileXferThread->start(); + } } } break; case nmtSwitchSetupRequest: { - SwitchSetupRequest switchSetupRequest; - if(receiveMessage(&switchSetupRequest)) { - Mutex *mutex = getServerSynchAccessor(); - if(mutex != NULL) mutex->p(); + if(gotIntro == true) { + SwitchSetupRequest switchSetupRequest; + if(receiveMessage(&switchSetupRequest)) { + Mutex *mutex = getServerSynchAccessor(); + if(mutex != NULL) mutex->p(); - if(serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()]==NULL) { - serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()]= new SwitchSetupRequest(); + if(serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()]==NULL) { + serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()]= new SwitchSetupRequest(); + } + *(serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()])=switchSetupRequest; + + if(mutex != NULL) mutex->v(); } - *(serverInterface->getSwitchSetupRequests()[switchSetupRequest.getCurrentFactionIndex()])=switchSetupRequest; - - if(mutex != NULL) mutex->v(); } break; } @@ -511,10 +539,7 @@ void ConnectionSlot::update(bool checkForNewClients) { } } - if(gotIntro == false && difftime(time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %f\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime)); - close(); - } + validateConnection(); } else { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] calling close...\n",__FILE__,__FUNCTION__,__LINE__); @@ -532,6 +557,14 @@ void ConnectionSlot::update(bool checkForNewClients) { } } +void ConnectionSlot::validateConnection() { + if(gotIntro == false && connectedTime > 0 && + difftime(time(NULL),connectedTime) > GameConstants::maxClientConnectHandshakeSecs) { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] difftime(time(NULL),connectedTime) = %f\n",__FILE__,__FUNCTION__,__LINE__,difftime(time(NULL),connectedTime)); + close(); + } +} + void ConnectionSlot::close() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s LINE: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/network/connection_slot.h b/source/glest_game/network/connection_slot.h index 2c00e6ee7..451e15533 100644 --- a/source/glest_game/network/connection_slot.h +++ b/source/glest_game/network/connection_slot.h @@ -157,6 +157,8 @@ public: const string &getVersionString() const {return versionString;} + void validateConnection(); + protected: Mutex * getServerSynchAccessor(); diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index cf0070d65..462d0e0b7 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -415,11 +415,27 @@ void ServerInterface::updateSocketTriggeredList(std::map & } } +void ServerInterface::validateConnectedClients() { + for(int i= 0; ivalidateConnection(); + } + } +} + void ServerInterface::update() { //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); std::vector errorMsgList; try { + // The first thing we will do is check all clients to ensure they have + // properly identified themselves within the alloted time period + validateConnectedClients(); + std::map socketTriggeredList; //update all slots updateSocketTriggeredList(socketTriggeredList); diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index abbaab189..1fdf797ea 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -105,6 +105,7 @@ private: void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1); bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot); void updateSlot(ConnectionSlotEvent *event); + void validateConnectedClients(); }; }}//end namespace