bugfixes for headless mode (when admin picks things that server doesn't have).. added a 2 second delay timer for sending out changes

This commit is contained in:
Mark Vejvoda
2011-10-22 00:19:38 +00:00
parent 5ee20018d8
commit bd2206f51b
4 changed files with 96 additions and 37 deletions

View File

@@ -56,6 +56,10 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
switchSetupRequestFlagType |= ssrft_NetworkPlayerName; switchSetupRequestFlagType |= ssrft_NetworkPlayerName;
updateDataSynchDetailText = false; updateDataSynchDetailText = false;
needToBroadcastServerSettings=false;
broadcastServerSettingsDelayTimer=0;
lastGameSettingsReceivedCount=0;
currentTechName_factionPreview=""; currentTechName_factionPreview="";
currentFactionName_factionPreview=""; currentFactionName_factionPreview="";
@@ -936,31 +940,42 @@ bool MenuStateConnectedGame::isMasterserverAdmin() {
return result; return result;
} }
void MenuStateConnectedGame::broadCastGameSettingsToMasterserver() { void MenuStateConnectedGame::broadCastGameSettingsToMasterserver(bool forceNow) {
NetworkManager &networkManager= NetworkManager::getInstance(); if(isMasterserverAdmin() == false) {
ClientInterface *clientInterface = networkManager.getClientInterface(); return;
for(int i = 0; i < mapInfo.players; ++i) {
if(listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) {
listBoxControls[i].setSelectedItemIndex(ctNetwork);
}
}
for(int i = mapInfo.players; i < GameConstants::maxPlayers; ++i) {
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
listBoxControls[i].setSelectedItemIndex(ctNetworkUnassigned);
}
} }
GameSettings gameSettings = *clientInterface->getGameSettings(); if(forceNow == true ||
loadGameSettings(&gameSettings); (needToBroadcastServerSettings == true && difftime(time(NULL),broadcastServerSettingsDelayTimer) >= 2)) {
//printf("In [%s:%s] Line: %d forceNow = %d broadcastServerSettingsDelayTimer = %lu, now =%lu\n",__FILE__,__FUNCTION__,__LINE__,forceNow,broadcastServerSettingsDelayTimer,time(NULL));
//printf("broadcast settings:\n%s\n",gameSettings.toString().c_str()); needToBroadcastServerSettings = false;
broadcastServerSettingsDelayTimer = time(NULL);
//printf("Client sending map [%s] admin key [%d]\n",gameSettings.getMap().c_str(),gameSettings.getMasterserver_admin()); NetworkManager &networkManager= NetworkManager::getInstance();
ClientInterface *clientInterface = networkManager.getClientInterface();
//clientInterface->setGameSettings(&gameSettings); for(int i = 0; i < mapInfo.players; ++i) {
clientInterface->broadcastGameSetup(&gameSettings); if(listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) {
listBoxControls[i].setSelectedItemIndex(ctNetwork);
}
}
for(int i = mapInfo.players; i < GameConstants::maxPlayers; ++i) {
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork) {
listBoxControls[i].setSelectedItemIndex(ctNetworkUnassigned);
}
}
GameSettings gameSettings = *clientInterface->getGameSettings();
loadGameSettings(&gameSettings);
//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());
//clientInterface->setGameSettings(&gameSettings);
clientInterface->broadcastGameSetup(&gameSettings);
}
} }
void MenuStateConnectedGame::updateResourceMultiplier(const int index) { void MenuStateConnectedGame::updateResourceMultiplier(const int index) {
@@ -1030,7 +1045,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// mapPublishingDelayTimer=time(NULL); // mapPublishingDelayTimer=time(NULL);
//} //}
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
else if(listBoxFogOfWar.mouseClick(x, y)) { else if(listBoxFogOfWar.mouseClick(x, y)) {
//MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); //MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@@ -1045,7 +1062,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// lastSetChangedGameSettings = time(NULL); // lastSetChangedGameSettings = time(NULL);
// } // }
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
else if(listBoxAllowObservers.mouseClick(x, y)) { else if(listBoxAllowObservers.mouseClick(x, y)) {
// MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); // MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@@ -1061,7 +1080,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// lastSetChangedGameSettings = time(NULL); // lastSetChangedGameSettings = time(NULL);
// } // }
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
else if(listBoxEnableObserverMode.mouseClick(x, y)) { else if(listBoxEnableObserverMode.mouseClick(x, y)) {
//MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); //MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@@ -1076,7 +1097,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// lastSetChangedGameSettings = time(NULL); // lastSetChangedGameSettings = time(NULL);
// } // }
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
else if (listBoxEnableSwitchTeamMode.mouseClick(x, y)) { else if (listBoxEnableSwitchTeamMode.mouseClick(x, y)) {
//MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); //MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@@ -1091,7 +1114,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// lastSetChangedGameSettings = time(NULL); // lastSetChangedGameSettings = time(NULL);
// } // }
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
else if(listBoxAISwitchTeamAcceptPercent.getEnabled() && listBoxAISwitchTeamAcceptPercent.mouseClick(x, y)) { else if(listBoxAISwitchTeamAcceptPercent.getEnabled() && listBoxAISwitchTeamAcceptPercent.mouseClick(x, y)) {
//MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); //MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@@ -1106,7 +1131,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// lastSetChangedGameSettings = time(NULL); // lastSetChangedGameSettings = time(NULL);
// } // }
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
// else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxPathFinderType.mouseClick(x, y)) { // else if (listBoxAdvanced.getSelectedItemIndex() == 1 && listBoxPathFinderType.mouseClick(x, y)) {
// MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); // MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@@ -1138,7 +1165,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// mapPublishingDelayTimer=time(NULL); // mapPublishingDelayTimer=time(NULL);
// } // }
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
// else if(listBoxMapFilter.mouseClick(x, y)){ // else if(listBoxMapFilter.mouseClick(x, y)){
// MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); // MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@@ -1176,7 +1205,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// lastSetChangedGameSettings = time(NULL); // lastSetChangedGameSettings = time(NULL);
//} //}
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
// else if(listBoxPublishServer.mouseClick(x, y) && listBoxPublishServer.getEditable()) { // else if(listBoxPublishServer.mouseClick(x, y) && listBoxPublishServer.getEditable()) {
// MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); // MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
@@ -1200,7 +1231,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
soundRenderer.playFx(coreData.getClickSoundC()); soundRenderer.playFx(coreData.getClickSoundC());
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
else { else {
NetworkManager &networkManager= NetworkManager::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance();
@@ -1212,7 +1245,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
//if (listBoxAdvanced.getSelectedItemIndex() == 1) { //if (listBoxAdvanced.getSelectedItemIndex() == 1) {
// set multiplier // set multiplier
if(listBoxRMultiplier[i].mouseClick(x, y)) { if(listBoxRMultiplier[i].mouseClick(x, y)) {
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
//} //}
@@ -1273,7 +1308,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// } // }
updateResourceMultiplier(i); updateResourceMultiplier(i);
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
// else if(buttonClearBlockedPlayers.mouseClick(x, y)) { // else if(buttonClearBlockedPlayers.mouseClick(x, y)) {
// ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); // ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
@@ -1333,7 +1370,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// lastSetChangedGameSettings = time(NULL); // lastSetChangedGameSettings = time(NULL);
// } // }
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
else if(clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()) != i && else if(clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()) != i &&
listBoxTeams[i].mouseClick(x, y)) { listBoxTeams[i].mouseClick(x, y)) {
@@ -1356,7 +1395,9 @@ void MenuStateConnectedGame::mouseClickAdmin(int x, int y, MouseButton mouseButt
// lastSetChangedGameSettings = time(NULL);; // lastSetChangedGameSettings = time(NULL);;
// } // }
broadCastGameSettingsToMasterserver(); //broadCastGameSettingsToMasterserver();
needToBroadcastServerSettings=true;
broadcastServerSettingsDelayTimer=time(NULL);
} }
// else if(labelPlayerNames[i].mouseClick(x, y)) { // else if(labelPlayerNames[i].mouseClick(x, y)) {
// SetActivePlayerNameEditor(); // SetActivePlayerNameEditor();
@@ -2039,6 +2080,7 @@ void MenuStateConnectedGame::update() {
if(clientInterface != NULL && clientInterface->isConnected()) { if(clientInterface != NULL && clientInterface->isConnected()) {
//printf("#2 admin key [%d] client key [%d]\n",settings->getMasterserver_admin(),clientInterface->getSessionKey()); //printf("#2 admin key [%d] client key [%d]\n",settings->getMasterserver_admin(),clientInterface->getSessionKey());
broadCastGameSettingsToMasterserver(false);
listBoxMap.setEditable(isMasterserverAdmin()); listBoxMap.setEditable(isMasterserverAdmin());
buttonPlayNow.setVisible(isMasterserverAdmin()); buttonPlayNow.setVisible(isMasterserverAdmin());
@@ -2553,7 +2595,11 @@ void MenuStateConnectedGame::update() {
try { try {
//bool mustSwitchPlayerName = false; //bool mustSwitchPlayerName = false;
if(clientInterface->getGameSettingsReceived()) { if(clientInterface->getGameSettingsReceived() &&
lastGameSettingsReceivedCount != clientInterface->getGameSettingsReceivedCount()) {
broadCastGameSettingsToMasterserver(needToBroadcastServerSettings);
lastGameSettingsReceivedCount = clientInterface->getGameSettingsReceivedCount();
updateDataSynchDetailText = true; updateDataSynchDetailText = true;
bool errorOnMissingData = (clientInterface->getAllowGameDataSynchCheck() == false); bool errorOnMissingData = (clientInterface->getAllowGameDataSynchCheck() == false);
vector<string> maps,tilesets,techtree; vector<string> maps,tilesets,techtree;

View File

@@ -180,6 +180,10 @@ private:
GraphicButton buttonPlayNow; GraphicButton buttonPlayNow;
bool needToBroadcastServerSettings;
time_t broadcastServerSettingsDelayTimer;
int lastGameSettingsReceivedCount;
public: public:
MenuStateConnectedGame(Program *program, MainMenu *mainMenu, JoinMenu joinMenuInfo=jmSimple, bool openNetworkSlots= false); MenuStateConnectedGame(Program *program, MainMenu *mainMenu, JoinMenu joinMenuInfo=jmSimple, bool openNetworkSlots= false);
@@ -221,7 +225,7 @@ private:
void reloadFactions(bool keepExistingSelectedItem); void reloadFactions(bool keepExistingSelectedItem);
void PlayNow(bool saveGame); void PlayNow(bool saveGame);
bool isMasterserverAdmin(); bool isMasterserverAdmin();
void broadCastGameSettingsToMasterserver(); void broadCastGameSettingsToMasterserver(bool forceNow);
void updateResourceMultiplier(const int index); void updateResourceMultiplier(const int index);
}; };

View File

@@ -53,7 +53,7 @@ ClientInterface::ClientInterface() : GameNetworkInterface() {
launchGame= false; launchGame= false;
introDone= false; introDone= false;
playerIndex= -1; playerIndex= -1;
gameSettingsReceived=false; setGameSettingsReceived(false);
gotIntro = false; gotIntro = false;
lastNetworkCommandListSendTime = 0; lastNetworkCommandListSendTime = 0;
currentFrameCount = 0; currentFrameCount = 0;
@@ -485,7 +485,7 @@ void ClientInterface::updateLobby() {
launchGame= true; launchGame= true;
} }
else if(networkMessageLaunch.getMessageType() == nmtBroadCastSetup) { else if(networkMessageLaunch.getMessageType() == nmtBroadCastSetup) {
gameSettingsReceived=true; setGameSettingsReceived(true);
} }
} }
} }
@@ -1272,5 +1272,10 @@ void ClientInterface::broadcastGameStart(const GameSettings *gameSettings) {
sendMessage(&networkMessageLaunch); sendMessage(&networkMessageLaunch);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
} }
void ClientInterface::setGameSettingsReceived(bool value) {
//printf("In [%s:%s] Line: %d gameSettingsReceived = %d value = %d, gameSettingsReceivedCount = %d\n",__FILE__,__FUNCTION__,__LINE__,gameSettingsReceived,value,gameSettingsReceivedCount);
gameSettingsReceived = value;
gameSettingsReceivedCount++;
}
}}//end namespace }}//end namespace

View File

@@ -42,6 +42,7 @@ private:
bool launchGame; bool launchGame;
int playerIndex; int playerIndex;
bool gameSettingsReceived; bool gameSettingsReceived;
int gameSettingsReceivedCount;
time_t connectedTime; time_t connectedTime;
bool gotIntro; bool gotIntro;
@@ -83,7 +84,10 @@ public:
bool getLaunchGame() const {return launchGame;} bool getLaunchGame() const {return launchGame;}
bool getIntroDone() const {return introDone;} bool getIntroDone() const {return introDone;}
bool getGameSettingsReceived() const {return gameSettingsReceived;} bool getGameSettingsReceived() const {return gameSettingsReceived;}
void setGameSettingsReceived(bool value) {gameSettingsReceived=value;} void setGameSettingsReceived(bool value);
int getGameSettingsReceivedCount() const { return gameSettingsReceivedCount; }
int getPlayerIndex() const {return playerIndex;} int getPlayerIndex() const {return playerIndex;}
//const GameSettings *getGameSettings() {return &gameSettings;} //const GameSettings *getGameSettings() {return &gameSettings;}