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

@ -431,10 +431,28 @@ void CGameHandler::handleClientDisconnection(std::shared_ptr<CConnection> c)
continue;
auto playerConnection = vstd::find(playerConnections.second, c);
if(playerConnection != playerConnections.second.end())
if(playerConnection == playerConnections.second.end())
continue;
logGlobal->trace("Player %s disconnected. Notifying remaining players", playerId.toString());
// this player have left the game - broadcast infowindow to all in-game players
for (auto i = gs->players.cbegin(); i!=gs->players.cend(); i++)
{
std::string messageText = boost::str(boost::format("%s (cid %d) was disconnected") % playerSettings->name % c->connectionID);
playerMessages->broadcastMessage(playerId, messageText);
if (i->first == playerId)
continue;
if (getPlayerState(i->first)->status != EPlayerStatus::INGAME)
continue;
logGlobal->trace("Notifying player %s", i->first);
InfoWindow out;
out.player = i->first;
out.text.appendTextID("vcmi.server.errors.playerLeft");
out.text.replaceName(playerId);
out.components.emplace_back(ComponentType::FLAG, playerId);
sendAndApply(&out);
}
}
}