From b6dd5e266bd210953e0df808b3aa282eb88b6912 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 25 Sep 2011 05:38:35 +0000 Subject: [PATCH] - hardening the masterserver mode: 1. missing maps, techs and tilesets should no longer crash the server and server will revert to last valid value for each (server must have the data) 2. clients now get truly unique session id's which fixes client admin mode when connecting to masterserver --- .../menu/menu_state_connected_game.cpp | 16 +++++++--- .../menu/menu_state_custom_game.cpp | 31 +++++++++++-------- source/glest_game/network/connection_slot.cpp | 7 +++-- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index b054ef4e..e97a3f10 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -1384,9 +1384,11 @@ void MenuStateConnectedGame::reloadFactions(bool keepExistingSelectedItem) { for(int idx = 0; idx < techPaths.size(); idx++) { string &techPath = techPaths[idx]; endPathWithSlash(techPath); - //findAll(techPath + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "/factions/*.", results, false, false); - findDirs(techPath + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "/factions/", results, false, false); + if(listBoxTechTree.getSelectedItemIndex() >= 0 && listBoxTechTree.getSelectedItemIndex() < techTreeFiles.size()) { + //findAll(techPath + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "/factions/*.", results, false, false); + findDirs(techPath + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + "/factions/", results, false, false); + } if(results.empty() == false) { break; } @@ -2560,6 +2562,9 @@ void MenuStateConnectedGame::update() { std::for_each(techtree.begin(), techtree.end(), FormatString()); if(std::find(techTreeFiles.begin(),techTreeFiles.end(),gameSettings->getTech()) != techTreeFiles.end()) { + + //printf("gameSettings->getTech() [%s]\n",gameSettings->getTech().c_str()); + lastMissingTechtree = ""; getMissingTechtreeFromFTPServer = ""; //techtree.push_back(formatString(gameSettings->getTech())); @@ -2631,6 +2636,9 @@ void MenuStateConnectedGame::update() { if(getMissingMapFromFTPServerInProgress == false && gameSettings->getMap() != "") { // map + string mapFile = gameSettings->getMap(); + mapFile = formatString(mapFile); + maps = formattedMapFiles; if(currentMap != gameSettings->getMap()) {// load the setup again @@ -2656,14 +2664,12 @@ void MenuStateConnectedGame::update() { } } maps.push_back(ITEM_MISSING); + mapFile = ITEM_MISSING; } listBoxMap.setItems(maps); - string mapFile = gameSettings->getMap(); - mapFile = formatString(mapFile); listBoxMap.setSelectedItem(mapFile); - labelMapInfo.setText(mapInfo.desc); } diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index cfab09b4..9a5b689c 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -2648,13 +2648,14 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings,bool force if( serverInterface->getSlot(i) != NULL && serverInterface->getSlot(i)->isConnected()) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); - //printf("slot = %d serverInterface->getSlot(i)->getConnectedTime() = %d\n",i,serverInterface->getSlot(i)->getConnectedTime()); + //printf("slot = %d serverInterface->getSlot(i)->getConnectedTime() = %d session key [%d]\n",i,serverInterface->getSlot(i)->getConnectedTime(),serverInterface->getSlot(i)->getSessionKey()); - if(clientConnectedTime == 0 || serverInterface->getSlot(i)->getConnectedTime() < clientConnectedTime) { + if(clientConnectedTime == 0 || + (serverInterface->getSlot(i)->getConnectedTime() > 0 && serverInterface->getSlot(i)->getConnectedTime() < clientConnectedTime)) { clientConnectedTime = serverInterface->getSlot(i)->getConnectedTime(); gameSettings->setMasterserver_admin(serverInterface->getSlot(i)->getSessionKey()); - //printf("slot = %d, admin key [%d]\n",i,gameSettings->getMasterserver_admin()); + //printf("slot = %d, admin key [%d] slot connected time[%lu] clientConnectedTime [%lu]\n",i,gameSettings->getMasterserver_admin(),serverInterface->getSlot(i)->getConnectedTime(),clientConnectedTime); } } } @@ -2836,21 +2837,25 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin //printf("In [%s::%s line %d] map [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getMap().c_str()); string mapFile = gameSettings.getMap(); - mapFile = formatString(mapFile); - listBoxMap.setSelectedItem(mapFile); + if(find(mapFiles.begin(),mapFiles.end(),mapFile) != mapFiles.end()) { + mapFile = formatString(mapFile); + listBoxMap.setSelectedItem(mapFile); - loadMapInfo(Map::getMapPath(getCurrentMapFile()), &mapInfo, true); - labelMapInfo.setText(mapInfo.desc); + loadMapInfo(Map::getMapPath(getCurrentMapFile()), &mapInfo, true); + labelMapInfo.setText(mapInfo.desc); + } string tilesetFile = gameSettings.getTileset(); - tilesetFile = formatString(tilesetFile); - - listBoxTileset.setSelectedItem(tilesetFile); + if(find(tilesetFiles.begin(),tilesetFiles.end(),tilesetFile) != tilesetFiles.end()) { + tilesetFile = formatString(tilesetFile); + listBoxTileset.setSelectedItem(tilesetFile); + } string techtreeFile = gameSettings.getTech(); - techtreeFile = formatString(techtreeFile); - - listBoxTechTree.setSelectedItem(techtreeFile); + if(find(techTreeFiles.begin(),techTreeFiles.end(),techtreeFile) != techTreeFiles.end()) { + techtreeFile = formatString(techtreeFile); + listBoxTechTree.setSelectedItem(techtreeFile); + } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 6ac15943..e20c3ad8 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -362,8 +362,11 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { //send intro message when connected if(socket != NULL) { - RandomGen random; - sessionKey = random.randRange(-100000, 100000); + //RandomGen random; + //sessionKey = random.randRange(-100000, 100000); + srand(time(NULL)); + sessionKey = rand() % 1000000; + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] accepted new client connection, serverInterface->getOpenSlotCount() = %d, sessionKey = %d\n",__FILE__,__FUNCTION__,__LINE__,serverInterface->getOpenSlotCount(),sessionKey); if(hasOpenSlots == false) {