From 1b000376d4851fe649198a23ee0135c2d711b186 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 3 Jun 2010 06:03:41 +0000 Subject: [PATCH] - updated client connection screen to NOT crash if client does not have the tech selected on the server --- .../menu/menu_state_connected_game.cpp | 21 +++++++++++++----- .../menu/menu_state_connected_game.h | 2 +- source/glest_game/network/network_message.cpp | 22 ++++++++++--------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index ebb65d76b..44b1befa6 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -506,7 +506,7 @@ void MenuStateConnectedGame::update() if(currentFactionName != gameSettings->getTech()) { currentFactionName = gameSettings->getTech(); - hasFactions = loadFactions(gameSettings); + hasFactions = loadFactions(gameSettings,false); } //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] hasFactions = %d\n",__FILE__,__FUNCTION__,__LINE__,hasFactions); @@ -606,8 +606,7 @@ void MenuStateConnectedGame::update() } - -bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings){ +bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings, bool errorOnNoFactions){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); vector results; @@ -618,7 +617,7 @@ bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings){ for(int idx = 0; idx < techPaths.size(); idx++) { string &techPath = techPaths[idx]; - findAll(techPath + "/" + gameSettings->getTech() + "/factions/*.", results, false, false); + findAll(techPath + "/" + gameSettings->getTech() + "xx/factions/*.", results, false, false); if(results.size() > 0) { break; } @@ -630,8 +629,20 @@ bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings){ NetworkManager &networkManager= NetworkManager::getInstance(); ClientInterface* clientInterface= networkManager.getClientInterface(); if(clientInterface->getAllowGameDataSynchCheck() == false) { - throw runtime_error("(2)There are no factions for the tech tree [" + gameSettings->getTech() + "]"); + if(errorOnNoFactions == true) { + throw runtime_error("(2)There are no factions for the tech tree [" + gameSettings->getTech() + "]"); + } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] (2)There are no factions for the tech tree [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameSettings->getTech().c_str()); } + results.push_back("***missing***"); + factionFiles = results; + for(int i=0; igetTech().c_str()); + clientInterface->sendTextMessage(szMsg,-1); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index d6bd2dfc7..4541d8919 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -87,7 +87,7 @@ private: bool hasNetworkGameSettings(); void reloadFactions(); - bool loadFactions(const GameSettings *gameSettings); + bool loadFactions(const GameSettings *gameSettings,bool errorOnNoFactions); void returnToJoinMenu(); }; diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index 54650f654..86d0b4164 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -99,16 +99,18 @@ bool NetworkMessage::receive(Socket* socket, void* data, int dataSize) void NetworkMessage::send(Socket* socket, const void* data, int dataSize) const { - if(socket != NULL && socket->send(data, dataSize)!=dataSize) - { - if(socket != NULL && socket->getSocketId() > 0) - { - throw runtime_error("Error sending NetworkMessage"); - } - else - { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d socket has been disconnected\n",__FILE__,__FUNCTION__,__LINE__); - } + if(socket != NULL) { + int sendResult = socket->send(data, dataSize); + if(sendResult != dataSize) { + if(socket != NULL && socket->getSocketId() > 0) { + char szBuf[1024]=""; + sprintf(szBuf,"Error sending NetworkMessage, sendResult = %d, dataSize = %d",sendResult,dataSize); + throw runtime_error(szBuf); + } + else { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d socket has been disconnected\n",__FILE__,__FUNCTION__,__LINE__); + } + } } }