- more bug fixes found during menu navigation and testing

This commit is contained in:
Mark Vejvoda 2010-06-11 04:55:49 +00:00
parent b40a9d58c4
commit 4debe015ce
3 changed files with 98 additions and 31 deletions

View File

@ -51,6 +51,9 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
showGeneralError = false;
generalErrorToShow = "---";
publishToMasterserverThread = NULL;
Lang &lang= Lang::getInstance();
NetworkManager &networkManager= NetworkManager::getInstance();
@ -58,9 +61,31 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
showFullConsole=false;
mainMessageBox.init(lang.get("Ok"));
mainMessageBox.setEnabled(false);
mainMessageBoxState=0;
//initialize network interface
NetworkManager::getInstance().end();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
serverInitError = false;
try {
networkManager.init(nrServer);
}
catch(const std::exception &ex) {
serverInitError = true;
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);!!!
showGeneralError=true;
generalErrorToShow = ex.what();
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
parentMenuIsMs=parentMenuIsMasterserver;
@ -73,10 +98,6 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
lastMasterserverPublishing = 0;
soundConnectionCount=0;
mainMessageBox.init(lang.get("Ok"));
mainMessageBox.setEnabled(false);
mainMessageBoxState=0;
vector<string> teamItems, controlItems, results;
//create
@ -265,6 +286,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//init controllers
if(serverInitError == false) {
listBoxControls[0].setSelectedItemIndex(ctHuman);
if(openNetworkSlots){
for(int i= 1; i<mapInfo.players; ++i){
@ -284,7 +306,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
loadGameSettings(&gameSettings);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
serverInterface->setGameSettings(&gameSettings,false);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
//chatManager.init(&console, world.getThisTeamIndex());
@ -317,28 +339,35 @@ MenuStateCustomGame::~MenuStateCustomGame() {
}
void MenuStateCustomGame::returnToParentMenu(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
needToBroadcastServerSettings = false;
needToRepublishToMasterserver = false;
BaseThread::shutdownAndWait(publishToMasterserverThread);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
bool returnToMasterServerMenu = parentMenuIsMs;
safeMutex.ReleaseLock();
if(returnToMasterServerMenu) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
mainMenu->setState(new MenuStateMasterserver(program, mainMenu));
}
else {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
mainMenu->setState(new MenuStateNewGame(program, mainMenu));
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
CoreData &coreData= CoreData::getInstance();
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
if(mainMessageBox.getEnabled()){
int button= 1;
@ -351,7 +380,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
}
}
}
else if(buttonReturn.mouseClick(x,y)){
else if(buttonReturn.mouseClick(x,y) || serverInitError == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
soundRenderer.playFx(coreData.getClickSoundA());
@ -372,6 +401,8 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
BaseThread::shutdownAndWait(publishToMasterserverThread);
safeMutex.ReleaseLock();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
returnToParentMenu();
}
else if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) {
@ -390,6 +421,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
loadGameSettings(&gameSettings);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
// Send the game settings to each client if we have at least one networked client
safeMutex.Lock();
@ -702,6 +734,17 @@ void MenuStateCustomGame::update()
try {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(serverInitError == true) {
if(showGeneralError) {
MutexSafeWrapper safeMutex(&masterServerThreadAccessor);
showGeneralError=false;
mainMessageBoxState=1;
showMessageBox( generalErrorToShow, "Error", false);
safeMutex.ReleaseLock();
}
return;
}
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
Lang& lang= Lang::getInstance();
@ -726,6 +769,13 @@ void MenuStateCustomGame::update()
showMessageBox( masterServererErrorToShow, lang.get("ErrorFromMasterserver"), false);
safeMutex.ReleaseLock(true);
}
else if(showGeneralError) {
safeMutex.Lock();
showGeneralError=false;
mainMessageBoxState=1;
showMessageBox( generalErrorToShow, "Error", false);
safeMutex.ReleaseLock(true);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -992,7 +1042,10 @@ void MenuStateCustomGame::update()
catch(const std::exception &ex) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
throw runtime_error(szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);
showGeneralError=true;
generalErrorToShow = szBuf;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
@ -1370,7 +1423,10 @@ bool MenuStateCustomGame::hasNetworkGameSettings()
catch(const std::exception &ex) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
throw runtime_error(szBuf);
//throw runtime_error(szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
showGeneralError=true;
generalErrorToShow = ex.what();
}
return hasNetworkSlot;
@ -1510,7 +1566,11 @@ void MenuStateCustomGame::updateNetworkSlots()
catch(const std::exception &ex) {
char szBuf[1024]="";
sprintf(szBuf,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
throw runtime_error(szBuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf);
//throw runtime_error(szBuf);!!!
showGeneralError=true;
generalErrorToShow = ex.what();
}
}

View File

@ -81,6 +81,10 @@ private:
bool showMasterserverError;
string masterServererErrorToShow;
bool showGeneralError;
string generalErrorToShow;
bool serverInitError;
Console console;
ChatManager chatManager;
bool showFullConsole;

View File

@ -1539,7 +1539,10 @@ void ServerSocket::bind(int port)
{
char szBuf[1024]="";
sprintf(szBuf, "In [%s::%s] Error binding socket sock = %d, err = %d, error = %s\n",__FILE__,__FUNCTION__,sock,err,getLastSocketErrorFormattedText().c_str());
throwException(szBuf);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"%s",szBuf);
sprintf(szBuf, "Error binding socket sock = %d, err = %d, error = %s\n",sock,err,getLastSocketErrorFormattedText().c_str());
throw runtime_error(szBuf);
}
}