server crash fix
This commit is contained in:
parent
712aa9768f
commit
29c4c80ddf
3 changed files with 20 additions and 14 deletions
|
@ -210,7 +210,25 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec
|
|||
void Server_Game::removePlayer(Server_Player *player)
|
||||
{
|
||||
players.remove(player->getPlayerId());
|
||||
removeArrowsToPlayer(player);
|
||||
|
||||
sendGameEvent(new Event_Leave(player->getPlayerId()));
|
||||
bool playerActive = activePlayer == player->getPlayerId();
|
||||
bool spectator = player->getSpectator();
|
||||
delete player;
|
||||
|
||||
if (!getPlayerCount())
|
||||
deleteLater();
|
||||
else if (!spectator) {
|
||||
stopGameIfFinished();
|
||||
if (gameStarted && playerActive)
|
||||
nextTurn();
|
||||
}
|
||||
qobject_cast<Server_Room *>(parent())->broadcastGameListUpdate(this);
|
||||
}
|
||||
|
||||
void Server_Game::removeArrowsToPlayer(Server_Player *player)
|
||||
{
|
||||
// Remove all arrows of other players pointing to the player being removed or to one of his cards.
|
||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||
while (playerIterator.hasNext()) {
|
||||
|
@ -231,20 +249,6 @@ void Server_Game::removePlayer(Server_Player *player)
|
|||
p->deleteArrow(toDelete[i]->getId());
|
||||
}
|
||||
}
|
||||
|
||||
sendGameEvent(new Event_Leave(player->getPlayerId()));
|
||||
bool playerActive = activePlayer == player->getPlayerId();
|
||||
bool spectator = player->getSpectator();
|
||||
delete player;
|
||||
|
||||
if (!getPlayerCount())
|
||||
deleteLater();
|
||||
else if (!spectator) {
|
||||
stopGameIfFinished();
|
||||
if (gameStarted && playerActive)
|
||||
nextTurn();
|
||||
}
|
||||
qobject_cast<Server_Room *>(parent())->broadcastGameListUpdate(this);
|
||||
}
|
||||
|
||||
bool Server_Game::kickPlayer(int playerId)
|
||||
|
|
|
@ -75,6 +75,7 @@ public:
|
|||
ResponseCode checkJoin(ServerInfo_User *user, const QString &_password, bool spectator);
|
||||
Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate = true);
|
||||
void removePlayer(Server_Player *player);
|
||||
void removeArrowsToPlayer(Server_Player *player);
|
||||
bool kickPlayer(int playerId);
|
||||
void startGameIfReady();
|
||||
void stopGameIfFinished();
|
||||
|
|
|
@ -518,6 +518,7 @@ ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, Comma
|
|||
return RespContextError;
|
||||
|
||||
player->setConceded(true);
|
||||
game->removeArrowsToPlayer(player);
|
||||
player->clearZones();
|
||||
game->sendGameEvent(new Event_PlayerPropertiesChanged(player->getPlayerId(), player->getProperties()), new Context_Concede);
|
||||
game->stopGameIfFinished();
|
||||
|
|
Loading…
Reference in a new issue