1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Cleanup server connection code a bit

This commit is contained in:
Ivan Savenko 2023-07-28 14:17:06 +03:00
parent 593b82d178
commit 7f72f7a82c
5 changed files with 10 additions and 12 deletions

View File

@ -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;
}

View File

@ -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));
}
}

View File

@ -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();

View File

@ -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++;
}

View File

@ -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;
}