1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Fixed handling of connection failure on client

This commit is contained in:
Ivan Savenko 2023-12-26 18:30:57 +02:00
parent a50cdbda0c
commit a3639e77b1
2 changed files with 19 additions and 6 deletions

View File

@ -251,7 +251,7 @@ void CServerHandler::startLocalServerAndConnect()
while(!androidTestServerReadyFlag.load())
{
logNetwork->info("still waiting...");
boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
}
logNetwork->info("waiting for server finished...");
androidTestServerReadyFlag = false;
@ -285,6 +285,22 @@ void CServerHandler::justConnectToServer(const std::string & addr, const ui16 po
}
void CServerHandler::onConnectionFailed(const std::string & errorMessage)
{
if (isServerLocal())
{
// retry - local server might be still starting up
logNetwork->debug("\nCannot establish connection. %s Retrying...", errorMessage);
networkClient->setTimer(std::chrono::milliseconds(100));
}
else
{
// remote server refused connection - show error message
state = EClientState::CONNECTION_FAILED;
CInfoWindow::showInfoDialog(CGI->generaltexth->translate("vcmi.mainMenu.serverConnectionFailed"), {});
}
}
void CServerHandler::onTimer()
{
if(state == EClientState::CONNECTION_CANCELLED)
{
@ -292,11 +308,6 @@ void CServerHandler::onConnectionFailed(const std::string & errorMessage)
return;
}
logNetwork->warn("\nCannot establish connection. %s Retrying in 1 second", errorMessage);
//FIXME: replace with asio timer
boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
//FIXME: pass parameters from initial attempt
networkClient->start(getHostAddress(), getHostPort());
}
@ -1001,6 +1012,7 @@ void CServerHandler::threadRunServer()
}
else
{
state = EClientState::CONNECTION_CANCELLED; // stop attempts to reconnect
logNetwork->error("Error: server failed to close correctly or crashed!");
logNetwork->error("Check %s for more info", logName);
}

View File

@ -100,6 +100,7 @@ class CServerHandler : public IServerAPI, public LobbyInfo, public INetworkClien
void onConnectionFailed(const std::string & errorMessage) override;
void onConnectionEstablished(const std::shared_ptr<NetworkConnection> &) override;
void onDisconnected(const std::shared_ptr<NetworkConnection> &) override;
void onTimer() override;
void applyPackOnLobbyScreen(CPackForLobby & pack);
public: