- bugfixes for headless mode, map selection logic was broken for admin user

- during in game, if admin user disconnects, server re-assigns a new admin user so paused game can be unpaused by a new administrator
This commit is contained in:
Mark Vejvoda 2012-03-03 04:33:39 +00:00
parent 909b680836
commit 3eba87727c
8 changed files with 193 additions and 60 deletions

View File

@ -1024,47 +1024,7 @@ void Game::init(bool initForPreviewOnly) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled) SystemFlags::OutputDebug(SystemFlags::debugPathFinder,"================ STARTING GAME ================\n");
if(SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled) SystemFlags::OutputDebug(SystemFlags::debugPathFinder,"PathFinderType: %s\n", (getGameSettings()->getPathFinderType() ? "RoutePlanner" : "PathFinder"));
//PopupMenu popupMenu;
std::vector<string> menuItems;
menuItems.push_back(lang.get("ExitGame?"));
exitGamePopupMenuIndex = menuItems.size()-1;
if((gameSettings.getFlagTypes1() & ft1_allow_team_switching) == ft1_allow_team_switching &&
world.getThisFaction() != NULL && world.getThisFaction()->getType()->getPersonalityType() != fpt_Observer) {
menuItems.push_back(lang.get("JoinOtherTeam"));
joinTeamPopupMenuIndex = menuItems.size()-1;
}
bool allowAdminMenuItems = false;
if(role == nrServer) {
allowAdminMenuItems = true;
}
else if(role == nrClient) {
ClientInterface *clientInterface = dynamic_cast<ClientInterface *>(networkManager.getClientInterface());
if(clientInterface != NULL &&
gameSettings.getMasterserver_admin() == clientInterface->getSessionKey()) {
allowAdminMenuItems = true;
}
}
if(allowAdminMenuItems == true) {
menuItems.push_back(lang.get("PauseResumeGame"));
pauseGamePopupMenuIndex = menuItems.size()-1;
}
menuItems.push_back(lang.get("Keyboardsetup"));
keyboardSetupPopupMenuIndex = menuItems.size()-1;
menuItems.push_back(lang.get("Cancel"));
popupMenu.setW(100);
popupMenu.setH(100);
popupMenu.init(lang.get("GameMenuTitle"),menuItems);
popupMenu.setEnabled(false);
popupMenu.setVisible(false);
popupMenuSwitchTeams.setEnabled(false);
popupMenuSwitchTeams.setVisible(false);
setupPopupMenus(false);
gameStarted = true;
@ -1078,6 +1038,67 @@ void Game::init(bool initForPreviewOnly) {
// ==================== update ====================
void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) {
Lang &lang= Lang::getInstance();
//Logger &logger= Logger::getInstance();
//CoreData &coreData= CoreData::getInstance();
//Renderer &renderer= Renderer::getInstance();
//Map *map= world.getMap();
NetworkManager &networkManager= NetworkManager::getInstance();
NetworkRole role = networkManager.getNetworkRole();
ClientInterface *clientInterface = NULL;
bool allowAdminMenuItems = false;
if(role == nrServer) {
allowAdminMenuItems = true;
}
else if(role == nrClient) {
clientInterface = dynamic_cast<ClientInterface *>(networkManager.getClientInterface());
if(clientInterface != NULL &&
(gameSettings.getMasterserver_admin() == clientInterface->getSessionKey() ||
clientInterface->isMasterServerAdminOverride() == true)) {
allowAdminMenuItems = true;
}
}
if(checkClientAdminOverrideOnly == false ||
(clientInterface != NULL &&
(gameSettings.getMasterserver_admin() != clientInterface->getSessionKey() &&
clientInterface->isMasterServerAdminOverride() == true))) {
if(checkClientAdminOverrideOnly == true) {
gameSettings.setMasterserver_admin(clientInterface->getSessionKey());
}
//PopupMenu popupMenu;
std::vector<string> menuItems;
menuItems.push_back(lang.get("ExitGame?"));
exitGamePopupMenuIndex = menuItems.size()-1;
if((gameSettings.getFlagTypes1() & ft1_allow_team_switching) == ft1_allow_team_switching &&
world.getThisFaction() != NULL && world.getThisFaction()->getType()->getPersonalityType() != fpt_Observer) {
menuItems.push_back(lang.get("JoinOtherTeam"));
joinTeamPopupMenuIndex = menuItems.size()-1;
}
if(allowAdminMenuItems == true) {
menuItems.push_back(lang.get("PauseResumeGame"));
pauseGamePopupMenuIndex = menuItems.size()-1;
}
menuItems.push_back(lang.get("Keyboardsetup"));
keyboardSetupPopupMenuIndex = menuItems.size()-1;
menuItems.push_back(lang.get("Cancel"));
popupMenu.setW(100);
popupMenu.setH(100);
popupMenu.init(lang.get("GameMenuTitle"),menuItems);
popupMenu.setEnabled(false);
popupMenu.setVisible(false);
popupMenuSwitchTeams.setEnabled(false);
popupMenuSwitchTeams.setVisible(false);
}
}
//update
void Game::update() {
try {
@ -1144,6 +1165,7 @@ void Game::update() {
// Check to see if we are playing a network game and if any players
// have disconnected?
ReplaceDisconnectedNetworkPlayersWithAI(isNetworkGame, role);
setupPopupMenus(true);
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld [after ReplaceDisconnectedNetworkPlayersWithAI]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());

View File

@ -256,6 +256,8 @@ private:
int getFirstUnusedTeamNumber();
void updateWorldStats();
void setupPopupMenus(bool checkClientAdminOverrideOnly);
string getDebugStats(std::map<int,string> &factionDebugInfo);
};

View File

@ -639,7 +639,8 @@ void Intro::render() {
//printf("animTimer.deltaTime () = %f anim = %f animTimer.deltaTime() / 25.0 = %f\n",animTimer.deltaTime (),anim,animTimer.deltaTime() / 25.0);
//double anim = animTimer.deltaTime();
// Shared::Graphics::md5::renderMD5Object(md5Test, animTimer.deltaTime() / 30.0, &modelViewMatrix);
//Shared::Graphics::md5::renderMD5Object(md5Test, animTimer.deltaTime() / 30.0, &modelViewMatrix);
//Shared::Graphics::md5::renderMD5Object(md5Test, animTimer.deltaTime() / 30.0, NULL);
// if(test == NULL) {

View File

@ -497,16 +497,18 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
for(int i= 0; i < resultsScenarios.size(); ++i) {
string scenario = resultsScenarios[i];
string file = Scenario::getScenarioPath(dirList, scenario);
Scenario::loadScenarioInfo(file, &scenarioInfo);
if(file != "") {
Scenario::loadScenarioInfo(file, &scenarioInfo);
bool isNetworkScenario = false;
for(unsigned int j = 0; isNetworkScenario == false && j < GameConstants::maxPlayers; ++j) {
if(scenarioInfo.factionControls[j] == ctNetwork) {
isNetworkScenario = true;
bool isNetworkScenario = false;
for(unsigned int j = 0; isNetworkScenario == false && j < GameConstants::maxPlayers; ++j) {
if(scenarioInfo.factionControls[j] == ctNetwork) {
isNetworkScenario = true;
}
}
if(isNetworkScenario == true) {
scenarioFiles.push_back(scenario);
}
}
if(isNetworkScenario == true) {
scenarioFiles.push_back(scenario);
}
}
resultsScenarios.clear();
@ -1115,7 +1117,7 @@ void MenuStateConnectedGame::broadCastGameSettingsToMasterserver(bool forceNow)
GameSettings gameSettings = *clientInterface->getGameSettings();
loadGameSettings(&gameSettings);
//printf("broadcast settings:\n%s\n",gameSettings.toString().c_str());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("broadcast settings:\n%s\n",gameSettings.toString().c_str());
//printf("Client sending map [%s] admin key [%d]\n",gameSettings.getMap().c_str(),gameSettings.getMasterserver_admin());
@ -1161,15 +1163,18 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
//int oldListBoxMapfilterIndex=listBoxMapFilter.getSelectedItemIndex();
if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
PlayNow(true);
return;
}
else if(buttonRestoreLastSettings.mouseClick(x,y) && buttonRestoreLastSettings.getEnabled()) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
RestoreLastGameSettings();
}
else if(listBoxMap.mouseClick(x, y)){
else if(listBoxMap.mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", getCurrentMapFile().c_str());
//MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@ -1199,6 +1204,7 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
broadcastServerSettingsDelayTimer=time(NULL);
}
else if(listBoxFogOfWar.mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
// cleanupMapPreviewTexture();
@ -1216,6 +1222,7 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
broadcastServerSettingsDelayTimer=time(NULL);
}
else if(listBoxAllowObservers.mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
// MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
//
// if(listBoxPublishServer.getSelectedItemIndex() == 0) {
@ -1251,6 +1258,7 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// broadcastServerSettingsDelayTimer=time(NULL);
//}
else if (listBoxEnableSwitchTeamMode.mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
// if(listBoxPublishServer.getSelectedItemIndex() == 0) {
@ -1268,6 +1276,7 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
broadcastServerSettingsDelayTimer=time(NULL);
}
else if(listBoxAISwitchTeamAcceptPercent.getEnabled() && listBoxAISwitchTeamAcceptPercent.mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
// if(listBoxPublishServer.getSelectedItemIndex() == 0) {
@ -1301,6 +1310,7 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// //TODO
// }
else if(listBoxTileset.mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
// if(listBoxPublishServer.getSelectedItemIndex() == 0) {
@ -1340,6 +1350,7 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// }
// }
else if(listBoxTechTree.mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
reloadFactions(false,"");
//MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@ -1359,6 +1370,8 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
broadcastServerSettingsDelayTimer=time(NULL);
}
else {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
NetworkManager &networkManager= NetworkManager::getInstance();
ClientInterface* clientInterface= networkManager.getClientInterface();
@ -1368,6 +1381,7 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
//if (listBoxAdvanced.getSelectedItemIndex() == 1) {
// set multiplier
if(listBoxRMultiplier[i].mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
//broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
@ -1379,6 +1393,7 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
if(clientInterface != NULL && clientInterface->getGameSettings() != NULL &&
clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()) != i &&
listBoxControls[i].mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) {
@ -1393,10 +1408,12 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
}
else if(clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()) != i &&
listBoxFactions[i].mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
// Disallow CPU players to be observers
if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] == formatString(GameConstants::OBSERVER_SLOTNAME) &&
(listBoxControls[i].getSelectedItemIndex() == ctCpuEasy || listBoxControls[i].getSelectedItemIndex() == ctCpu ||
listBoxControls[i].getSelectedItemIndex() == ctCpuUltra || listBoxControls[i].getSelectedItemIndex() == ctCpuMega)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
listBoxFactions[i].setSelectedItemIndex(0);
}
@ -1406,6 +1423,7 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
}
else if(clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()) != i &&
listBoxTeams[i].mouseClick(x, y)) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(factionFiles[listBoxFactions[i].getSelectedItemIndex()] != formatString(GameConstants::OBSERVER_SLOTNAME)) {
if(listBoxTeams[i].getSelectedItemIndex() + 1 != (GameConstants::maxPlayers + fpt_Observer)) {
//lastSelectedTeamIndex[i] = listBoxTeams[i].getSelectedItemIndex();
@ -1565,6 +1583,8 @@ void MenuStateConnectedGame::loadGameSettings(GameSettings *gameSettings) {
gameSettings->setScenarioDir("");
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d] listBoxMap.getSelectedItemIndex() = %d, mapFiles.size() = %lu, getCurrentMapFile() [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,listBoxMap.getSelectedItemIndex(),mapFiles.size(),getCurrentMapFile().c_str());
if(listBoxMap.getSelectedItemIndex() >= 0 && listBoxMap.getSelectedItemIndex() < mapFiles.size()) {
gameSettings->setDescription(formatString(getCurrentMapFile()));
gameSettings->setMap(getCurrentMapFile());
@ -3780,6 +3800,8 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings,
mapFile = ITEM_MISSING;
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d] listBoxMap.getSelectedItemIndex() = %d, mapFiles.size() = %lu, maps.size() = %lu, getCurrentMapFile() [%s] mapFile [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,listBoxMap.getSelectedItemIndex(),mapFiles.size(),maps.size(),getCurrentMapFile().c_str(),mapFile.c_str());
listBoxMap.setItems(maps);
listBoxMap.setSelectedItem(mapFile);
@ -4034,6 +4056,7 @@ int MenuStateConnectedGame::setupMapList(string scenario) {
if(config.getString("InitialMap", "Conflict") == formattedPlayerSortedMaps[mapInfo.players].back()){
initialMapSelection= i;
}
formattedMapFiles.push_back(formatString(mapFiles.at(i)));
}
//printf("#6 scenario [%s] [%s]\n",scenario.c_str(),scenarioDir.c_str());
@ -4044,6 +4067,8 @@ int MenuStateConnectedGame::setupMapList(string scenario) {
//printf("#6.1 about to load map [%s]\n",scenarioInfo.mapName.c_str());
loadMapInfo(Map::getMapPath(scenarioInfo.mapName, scenarioDir, true), &mapInfo, false);
//printf("#6.2\n");
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d] listBoxMap.getSelectedItemIndex() = %d, mapFiles.size() = %lu, mapInfo.players = %d, formattedPlayerSortedMaps[mapInfo.players].size() = %lu, scenarioInfo.mapName [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,listBoxMap.getSelectedItemIndex(),mapFiles.size(),mapInfo.players,formattedPlayerSortedMaps[mapInfo.players].size(),scenarioInfo.mapName.c_str());
listBoxMap.setItems(formattedPlayerSortedMaps[mapInfo.players]);
}
//printf("#7\n");

View File

@ -606,16 +606,18 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
for(int i= 0; i < resultsScenarios.size(); ++i) {
string scenario = resultsScenarios[i];
string file = Scenario::getScenarioPath(dirList, scenario);
Scenario::loadScenarioInfo(file, &scenarioInfo);
if(file != "") {
Scenario::loadScenarioInfo(file, &scenarioInfo);
bool isNetworkScenario = false;
for(unsigned int j = 0; isNetworkScenario == false && j < GameConstants::maxPlayers; ++j) {
if(scenarioInfo.factionControls[j] == ctNetwork) {
isNetworkScenario = true;
bool isNetworkScenario = false;
for(unsigned int j = 0; isNetworkScenario == false && j < GameConstants::maxPlayers; ++j) {
if(scenarioInfo.factionControls[j] == ctNetwork) {
isNetworkScenario = true;
}
}
if(isNetworkScenario == true) {
scenarioFiles.push_back(scenario);
}
}
if(isNetworkScenario == true) {
scenarioFiles.push_back(scenario);
}
}
resultsScenarios.clear();

View File

@ -647,6 +647,54 @@ void ClientInterface::updateKeyframe(int frameCount) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
}
break;
case nmtLaunch:
case nmtBroadCastSetup:
{
NetworkMessageLaunch networkMessageLaunch;
if(receiveMessage(&networkMessageLaunch)) {
if(networkMessageLaunch.getMessageType() == nmtLaunch) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got nmtLaunch\n",__FILE__,__FUNCTION__,__LINE__);
}
else if(networkMessageLaunch.getMessageType() == nmtBroadCastSetup) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got nmtBroadCastSetup\n",__FILE__,__FUNCTION__,__LINE__);
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got networkMessageLaunch.getMessageType() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType());
char szBuf[1024]="";
snprintf(szBuf,1023,"In [%s::%s Line: %d] Invalid networkMessageLaunch.getMessageType() = %d",__FILE__,__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType());
throw runtime_error(szBuf);
}
networkMessageLaunch.buildGameSettings(&gameSettings);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Lined: %d] got networkMessageLaunch.getMessageType() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageLaunch.getMessageType());
//replace server player by network
for(int i= 0; i<gameSettings.getFactionCount(); ++i) {
//replace by network
if(gameSettings.getFactionControl(i)==ctHuman) {
gameSettings.setFactionControl(i, ctNetwork);
}
//set the faction index
if(gameSettings.getStartLocationIndex(i) == playerIndex) {
gameSettings.setThisFactionIndex(i);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] gameSettings.getThisFactionIndex(i) = %d, playerIndex = %d, i = %d\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getThisFactionIndex(),playerIndex,i);
}
}
//if(networkMessageLaunch.getMessageType() == nmtLaunch) {
//launchGame= true;
//}
//else if(networkMessageLaunch.getMessageType() == nmtBroadCastSetup) {
// setGameSettingsReceived(true);
//}
}
}
break;
case nmtLoadingStatusMessage:
break;
@ -672,6 +720,10 @@ void ClientInterface::updateKeyframe(int frameCount) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
}
bool ClientInterface::isMasterServerAdminOverride() {
return (gameSettings.getMasterserver_admin() == this->getSessionKey());
}
void ClientInterface::waitUntilReady(Checksum* checksum) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -114,6 +114,7 @@ public:
int getServerFTPPort() const { return serverFTPPort; }
int getSessionKey() const { return sessionKey; }
bool isMasterServerAdminOverride();
void setGameSettings(GameSettings *serverGameSettings);
void broadcastGameSetup(const GameSettings *gameSettings);

View File

@ -1144,6 +1144,34 @@ void ServerInterface::update() {
checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
}
// Check if we need to switch masterserver admin to a new player because original admin disconnected
if(gameHasBeenInitiated == true && this->gameSettings.getMasterserver_admin() > 0) {
//!!!
bool foundAdminSlot = false;
int iFirstConnectedSlot = -1;
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i));
if(slots[i] != NULL) {
if(iFirstConnectedSlot < 0) {
iFirstConnectedSlot = i;
}
if(this->gameSettings.getMasterserver_admin() == slots[i]->getSessionKey()) {
foundAdminSlot = true;
break;
}
}
}
if(foundAdminSlot == false && iFirstConnectedSlot >= 0) {
printf("Switching masterserver admin to slot#%d...\n",iFirstConnectedSlot);
string sMsg = "Switching player to admin mode: " + slots[iFirstConnectedSlot]->getName();
sendTextMessage(sMsg,-1, true,"");
this->gameSettings.setMasterserver_admin(slots[iFirstConnectedSlot]->getSessionKey());
this->broadcastGameSetup(&this->gameSettings);
}
}
//printf("\nServerInterface::update -- G\n");
}
catch(const exception &ex) {