From fe9798bf46f6aba1c6516f89d28d8a211f80d3cc Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Mon, 13 Sep 2010 20:07:47 +0200 Subject: [PATCH] Fixed crash when leaving game as spectator --- cockatrice/src/tab_game.cpp | 31 +++++++++++++++---------------- cockatrice/src/tab_game.h | 4 ++-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index d1a978eb..78c686f1 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -272,7 +272,7 @@ void TabGame::actConcede() if (QMessageBox::question(this, tr("Concede"), tr("Are you sure you want to concede this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) return; - sendGameCommand(new Command_Concede, getActiveLocalPlayer()->getId()); + sendGameCommand(new Command_Concede); } void TabGame::actLeaveGame() @@ -280,14 +280,14 @@ void TabGame::actLeaveGame() if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) return; - sendGameCommand(new Command_LeaveGame, getActiveLocalPlayer()->getId()); + sendGameCommand(new Command_LeaveGame); deleteLater(); } void TabGame::actSay() { if (!sayEdit->text().isEmpty()) { - sendGameCommand(new Command_Say(-1, sayEdit->text()), getActiveLocalPlayer()->getId()); + sendGameCommand(new Command_Say(-1, sayEdit->text())); sayEdit->clear(); } } @@ -297,12 +297,12 @@ void TabGame::actNextPhase() int phase = currentPhase; if (++phase >= phasesToolbar->phaseCount()) phase = 0; - sendGameCommand(new Command_SetActivePhase(-1, phase), getActiveLocalPlayer()->getId()); + sendGameCommand(new Command_SetActivePhase(-1, phase)); } void TabGame::actNextTurn() { - sendGameCommand(new Command_NextTurn, getActiveLocalPlayer()->getId()); + sendGameCommand(new Command_NextTurn); } void TabGame::actRemoveLocalArrows() @@ -315,7 +315,7 @@ void TabGame::actRemoveLocalArrows() QMapIterator arrowIterator(player->getArrows()); while (arrowIterator.hasNext()) { ArrowItem *a = arrowIterator.next().value(); - sendGameCommand(new Command_DeleteArrow(-1, a->getId()), getActiveLocalPlayer()->getId()); + sendGameCommand(new Command_DeleteArrow(-1, a->getId())); } } } @@ -397,23 +397,20 @@ void TabGame::processGameEventContainer(GameEventContainer *cont, AbstractClient void TabGame::sendGameCommand(GameCommand *command, int playerId) { - if (playerId == -1) - playerId = getActiveLocalPlayer()->getId(); - command->setGameId(gameId); AbstractClient *client; - if (clients.size() > 1) + if (clients.size() > 1) { + if (playerId == -1) + playerId = getActiveLocalPlayer()->getId(); + client = clients.at(playerId); - else + } else client = clients.first(); client->sendCommand(command); } void TabGame::sendCommandContainer(CommandContainer *cont, int playerId) { - if (playerId == -1) - playerId = getActiveLocalPlayer()->getId(); - const QList &cmdList = cont->getCommandList(); for (int i = 0; i < cmdList.size(); ++i) { GameCommand *cmd = qobject_cast(cmdList[i]); @@ -422,9 +419,11 @@ void TabGame::sendCommandContainer(CommandContainer *cont, int playerId) } AbstractClient *client; - if (clients.size() > 1) + if (clients.size() > 1) { + if (playerId == -1) + playerId = getActiveLocalPlayer()->getId(); client = clients.at(playerId); - else + } else client = clients.first(); client->sendCommandContainer(cont); } diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index 8f2f831d..dd836f91 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -155,8 +155,8 @@ public: void processGameEventContainer(GameEventContainer *cont, AbstractClient *client); public slots: - void sendGameCommand(GameCommand *command, int playerId); - void sendCommandContainer(CommandContainer *cont, int playerId); + void sendGameCommand(GameCommand *command, int playerId = -1); + void sendCommandContainer(CommandContainer *cont, int playerId = -1); }; #endif