1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Fix dead server

This commit is contained in:
nordsoft 2022-10-08 22:23:02 +04:00
parent 63b29cbaea
commit 2645843d4f

View File

@ -341,10 +341,13 @@ void CVCMIServer::threadHandleClient(std::shared_ptr<CConnection> c)
catch(boost::system::system_error & e)
{
logNetwork->error("Network error receiving a pack. Connection %s dies. What happened: %s", c->toString(), e.what());
if(state != EServerState::LOBBY)
hangingConnections.insert(c);
connections.erase(c);
if(connections.empty() || hostClient == c)
state = EServerState::SHUTDOWN;
if(gh && state == EServerState::GAMEPLAY)
{
hangingConnections.insert(c);
connections.erase(c);
gh->handleClientDisconnection(c);
}
break;
@ -494,12 +497,8 @@ void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<st
void CVCMIServer::clientDisconnected(std::shared_ptr<CConnection> c)
{
connections -= c;
if(connections.empty())
throw std::runtime_error("No more connections. Closing server.");
if(hostClient == c)
if(connections.empty() || hostClient == c)
{
//TODO: support host transfer role
state = EServerState::SHUTDOWN;
return;
}