Skip to content
This repository was archived by the owner on Aug 22, 2022. It is now read-only.

Commit b310f2e

Browse files
authored
Merge pull request vcmi#687 from kambala-decapitator/fix-server-crash-client-disconnect
fix server crash on unexpected client disconnect
2 parents 2b4a999 + 7f3b06e commit b310f2e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

server/CGameHandler.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,11 +1195,11 @@ void CGameHandler::handleClientDisconnection(std::shared_ptr<CConnection> c)
11951195
{
11961196
for(auto playerConns : connections)
11971197
{
1198-
for(auto conn : playerConns.second)
1198+
for(auto i = playerConns.second.begin(); i != playerConns.second.end(); )
11991199
{
1200-
if(lobby->state != EServerState::SHUTDOWN && conn == c)
1200+
if(lobby->state != EServerState::SHUTDOWN && *i == c)
12011201
{
1202-
vstd::erase_if_present(playerConns.second, conn);
1202+
i = playerConns.second.erase(i);
12031203
if(playerConns.second.size())
12041204
continue;
12051205
PlayerCheated pc;
@@ -1208,6 +1208,8 @@ void CGameHandler::handleClientDisconnection(std::shared_ptr<CConnection> c)
12081208
sendAndApply(&pc);
12091209
checkVictoryLossConditionsForPlayer(playerConns.first);
12101210
}
1211+
else
1212+
++i;
12111213
}
12121214
}
12131215
}
@@ -5267,7 +5269,7 @@ void CGameHandler::checkVictoryLossConditionsForAll()
52675269
void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player)
52685270
{
52695271
const PlayerState * p = getPlayer(player);
5270-
if (p->status != EPlayerStatus::INGAME) return;
5272+
if (!p || p->status != EPlayerStatus::INGAME) return;
52715273

52725274
auto victoryLossCheckResult = gs->checkForVictoryAndLoss(player);
52735275

0 commit comments

Comments
 (0)