1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00

Merge pull request #687 from kambala-decapitator/fix-server-crash-client-disconnect

fix server crash on unexpected client disconnect
This commit is contained in:
Alexander Shishkin 2021-04-29 16:03:07 +03:00 committed by GitHub
commit b310f2e61e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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);