From 07c2af4b99736ae68ab1ef3500692ef1e72a2c3e Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 15 Nov 2012 15:08:30 +0000 Subject: [PATCH] - no need to crash if admin port already in use, just output error to console --- source/glest_game/network/network_manager.cpp | 6 +++--- source/glest_game/network/server_interface.cpp | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/source/glest_game/network/network_manager.cpp b/source/glest_game/network/network_manager.cpp index fde83653..72ac57b0 100644 --- a/source/glest_game/network/network_manager.cpp +++ b/source/glest_game/network/network_manager.cpp @@ -84,7 +84,7 @@ bool NetworkManager::isNetworkGame() { GameNetworkInterface* NetworkManager::getGameNetworkInterface(bool throwErrorOnNull) { if(throwErrorOnNull) { - assert(gameNetworkInterface!=NULL); + //assert(gameNetworkInterface!=NULL); if(gameNetworkInterface==NULL) { throw megaglest_runtime_error("gameNetworkInterface==NULL"); @@ -95,7 +95,7 @@ GameNetworkInterface* NetworkManager::getGameNetworkInterface(bool throwErrorOnN ServerInterface* NetworkManager::getServerInterface(bool throwErrorOnNull) { if(throwErrorOnNull) { - assert(gameNetworkInterface!=NULL); + //assert(gameNetworkInterface!=NULL); if(gameNetworkInterface==NULL) { throw megaglest_runtime_error("gameNetworkInterface==NULL"); } @@ -112,7 +112,7 @@ ClientInterface* NetworkManager::getClientInterface(bool throwErrorOnNull) { //if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] this->networkRole = %d gameNetworkInterface [%p]\n",__FILE__,__FUNCTION__,__LINE__,this->networkRole,gameNetworkInterface); if(throwErrorOnNull) { - assert(gameNetworkInterface!=NULL); + //assert(gameNetworkInterface!=NULL); if(gameNetworkInterface==NULL) { throw megaglest_runtime_error("gameNetworkInterface==NULL"); } diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 586c0f5d..35629317 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -78,11 +78,19 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { // This is an admin port listening only on the localhost intended to // give current connection status info #ifndef __APPLE__ - serverSocketAdmin = new ServerSocket(true); - serverSocketAdmin->setBlock(false); - serverSocketAdmin->setBindPort(Config::getInstance().getInt("ServerAdminPort", intToStr(GameConstants::serverAdminPort).c_str())); - serverSocketAdmin->setBindSpecificAddress(Config::getInstance().getString("ServerAdminBindAddress", "127.0.0.1")); - serverSocketAdmin->listen(5); + try { + serverSocketAdmin = new ServerSocket(true); + serverSocketAdmin->setBlock(false); + serverSocketAdmin->setBindPort(Config::getInstance().getInt("ServerAdminPort", intToStr(GameConstants::serverAdminPort).c_str())); + serverSocketAdmin->setBindSpecificAddress(Config::getInstance().getString("ServerAdminBindAddress", "127.0.0.1")); + serverSocketAdmin->listen(5); + } + catch(const std::exception &ex) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"In [%s::%s Line: %d] Warning Server admin port bind/listen error:\n%s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); + } #endif maxFrameCountLagAllowed = Config::getInstance().getInt("MaxFrameCountLagAllowed", intToStr(maxFrameCountLagAllowed).c_str());