瀏覽代碼

Cleanup server connection code a bit

Ivan Savenko 2 年之前
父節點
當前提交
7f72f7a82c
共有 5 個文件被更改,包括 10 次插入12 次删除
  1. 1 1
      client/CMT.cpp
  2. 4 6
      client/CServerHandler.cpp
  3. 1 1
      client/CServerHandler.h
  4. 3 3
      lib/serializer/Connection.cpp
  5. 1 1
      server/CVCMIServer.cpp

+ 1 - 1
client/CMT.cpp

@@ -151,7 +151,7 @@ int main(int argc, char * argv[])
 		{
 			po::store(po::parse_command_line(argc, argv, opts, po_style::unix_style|po_style::case_insensitive), vm);
 		}
-		catch(std::exception &e)
+		catch(boost::program_options::error &e)
 		{
 			std::cerr << "Failure during parsing command-line options:\n" << e.what() << std::endl;
 		}

+ 4 - 6
client/CServerHandler.cpp

@@ -169,7 +169,7 @@ void CServerHandler::startLocalServerAndConnect()
 		CInfoWindow::showInfoDialog(errorMsg, {});
 		return;
 	}
-	catch(...)
+	catch(std::runtime_error & error)
 	{
 		//no connection means that port is not busy and we can start local server
 	}
@@ -236,9 +236,7 @@ void CServerHandler::startLocalServerAndConnect()
 
 	th->update(); //put breakpoint here to attach to server before it does something stupid
 
-	const ui16 port = 0;
-
-	justConnectToServer(localhostAddress, port);
+	justConnectToServer(localhostAddress, 0);
 
 	logNetwork->trace("\tConnecting to the server: %d ms", th->getDiff());
 }
@@ -256,9 +254,9 @@ void CServerHandler::justConnectToServer(const std::string & addr, const ui16 po
 					port ? port : getHostPort(),
 					NAME, uuid);
 		}
-		catch(...)
+		catch(std::runtime_error & error)
 		{
-			logNetwork->error("\nCannot establish connection! Retrying within 1 second");
+			logNetwork->warn("\nCannot establish connection. %s Retrying in 1 second", error.what());
 			boost::this_thread::sleep(boost::posix_time::seconds(1));
 		}
 	}

+ 1 - 1
client/CServerHandler.h

@@ -115,7 +115,7 @@ public:
 
 	void resetStateForLobby(const StartInfo::EMode mode, const std::vector<std::string> * names = nullptr);
 	void startLocalServerAndConnect();
-	void justConnectToServer(const std::string &addr = "", const ui16 port = 0);
+	void justConnectToServer(const std::string & addr, const ui16 port);
 	void applyPacksOnLobbyScreen();
 	void stopServerConnection();
 

+ 3 - 3
lib/serializer/Connection.cpp

@@ -82,7 +82,7 @@ CConnection::CConnection(const std::string & host, ui16 port, std::string Name,
 	if(error)
 	{
 		logNetwork->error("Problem with resolving: \n%s", error.message());
-		throw std::runtime_error("Can't establish connection: Problem with resolving");
+		throw std::runtime_error("Problem with resolving");
 	}
 	pom = endpoint_iterator;
 	if(pom != end)
@@ -90,7 +90,7 @@ CConnection::CConnection(const std::string & host, ui16 port, std::string Name,
 	else
 	{
 		logNetwork->error("Critical problem: No endpoints found!");
-		throw std::runtime_error("Can't establish connection: No endpoints found!");
+		throw std::runtime_error("No endpoints found!");
 	}
 	while(pom != end)
 	{
@@ -109,7 +109,7 @@ CConnection::CConnection(const std::string & host, ui16 port, std::string Name,
 		}
 		else
 		{
-			throw std::runtime_error("Can't establish connection: Failed to connect!");
+			throw std::runtime_error("Failed to connect!");
 		}
 		endpoint_iterator++;
 	}

+ 1 - 1
server/CVCMIServer.cpp

@@ -987,7 +987,7 @@ static void handleCommandOptions(int argc, const char * argv[], boost::program_o
 		{
 			po::store(po::parse_command_line(argc, argv, opts), options);
 		}
-		catch(po::error & e)
+		catch(boost::program_options::error & e)
 		{
 			std::cerr << "Failure during parsing command-line options:\n" << e.what() << std::endl;
 		}