1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +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) catch(boost::system::system_error & e)
{ {
logNetwork->error("Network error receiving a pack. Connection %s dies. What happened: %s", c->toString(), e.what()); logNetwork->error("Network error receiving a pack. Connection %s dies. What happened: %s", c->toString(), e.what());
if(state != EServerState::LOBBY)
{
hangingConnections.insert(c); hangingConnections.insert(c);
connections.erase(c); connections.erase(c);
if(connections.empty() || hostClient == c)
state = EServerState::SHUTDOWN;
if(gh && state == EServerState::GAMEPLAY)
{
gh->handleClientDisconnection(c); gh->handleClientDisconnection(c);
} }
break; break;
@@ -494,12 +497,8 @@ void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<st
void CVCMIServer::clientDisconnected(std::shared_ptr<CConnection> c) void CVCMIServer::clientDisconnected(std::shared_ptr<CConnection> c)
{ {
connections -= c; connections -= c;
if(connections.empty()) if(connections.empty() || hostClient == c)
throw std::runtime_error("No more connections. Closing server.");
if(hostClient == c)
{ {
//TODO: support host transfer role
state = EServerState::SHUTDOWN; state = EServerState::SHUTDOWN;
return; return;
} }