1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-29 21:56:54 +02:00

fix server crash on unexpected client disconnect

This commit is contained in:
Andrey Filipenkov 2021-03-20 17:04:47 +03:00
parent bc1d99431d
commit 7f3b06eb86

View File

@ -1195,11 +1195,11 @@ void CGameHandler::handleClientDisconnection(std::shared_ptr<CConnection> c)
{
for(auto playerConns : connections)
{
for(auto conn : playerConns.second)
for(auto i = playerConns.second.begin(); i != playerConns.second.end(); )
{
if(lobby->state != EServerState::SHUTDOWN && conn == c)
if(lobby->state != EServerState::SHUTDOWN && *i == c)
{
vstd::erase_if_present(playerConns.second, conn);
i = playerConns.second.erase(i);
if(playerConns.second.size())
continue;
PlayerCheated pc;
@ -1208,6 +1208,8 @@ void CGameHandler::handleClientDisconnection(std::shared_ptr<CConnection> c)
sendAndApply(&pc);
checkVictoryLossConditionsForPlayer(playerConns.first);
}
else
++i;
}
}
}
@ -5267,7 +5269,7 @@ void CGameHandler::checkVictoryLossConditionsForAll()
void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player)
{
const PlayerState * p = getPlayer(player);
if (p->status != EPlayerStatus::INGAME) return;
if (!p || p->status != EPlayerStatus::INGAME) return;
auto victoryLossCheckResult = gs->checkForVictoryAndLoss(player);