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:
@ -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;
|
||||
//
|
||||
|
Reference in New Issue
Block a user