1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Fixes for player disconnection handling

- Fixed lack of notification if player disconnects via connection loss,
e.g. app crash / network going down
- Replaced notification via chat message with notification via info window
This commit is contained in:
Ivan Savenko
2024-10-04 12:48:50 +00:00
parent b79897f598
commit 371eac070f
4 changed files with 46 additions and 20 deletions

View File

@ -297,25 +297,19 @@ void CVCMIServer::onDisconnected(const std::shared_ptr<INetworkConnection> & con
logNetwork->error("Network error receiving a pack. Connection has been closed");
std::shared_ptr<CConnection> c = findConnection(connection);
if (!c)
return; // player have already disconnected via clientDisconnected call
vstd::erase(activeConnections, c);
if(activeConnections.empty() || hostClientId == c->connectionID)
// player may have already disconnected via clientDisconnected call
if (c)
{
setState(EServerState::SHUTDOWN);
return;
}
//clientDisconnected(c);
if(gh && getState() == EServerState::GAMEPLAY)
{
gh->handleClientDisconnection(c);
auto lcd = std::make_unique<LobbyClientDisconnected>();
lcd->c = c;
lcd->clientId = c->connectionID;
handleReceivedPack(std::move(lcd));
if(gh && getState() == EServerState::GAMEPLAY)
{
auto lcd = std::make_unique<LobbyClientDisconnected>();
lcd->c = c;
lcd->clientId = c->connectionID;
handleReceivedPack(std::move(lcd));
}
}
}
@ -434,9 +428,21 @@ void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<st
void CVCMIServer::clientDisconnected(std::shared_ptr<CConnection> connection)
{
connection->getConnection()->close();
assert(vstd::contains(activeConnections, connection));
logGlobal->trace("Received disconnection request");
vstd::erase(activeConnections, connection);
if(activeConnections.empty() || hostClientId == connection->connectionID)
{
setState(EServerState::SHUTDOWN);
return;
}
if(gh && getState() == EServerState::GAMEPLAY)
{
gh->handleClientDisconnection(connection);
}
// PlayerReinitInterface startAiPack;
// startAiPack.playerConnectionId = PlayerSettings::PLAYER_AI;
//