- 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
This commit is contained in:
Mark Vejvoda 2011-09-25 05:38:35 +00:00
parent ebc174be03
commit b6dd5e266b
3 changed files with 34 additions and 20 deletions

View File

@ -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);
}

View File

@ -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__);

View File

@ -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) {