From d4f600393fd9e361e9637aa860ac774f29968f9d Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Tue, 15 Feb 2011 22:50:16 +0100 Subject: [PATCH] minor visual change, server crash fix, multiplayer leave/concede fixes --- cockatrice/src/abstractcarditem.cpp | 7 +- cockatrice/src/carddatabase.cpp | 1 - cockatrice/src/gamescene.cpp | 7 +- cockatrice/src/player.cpp | 35 ++++++-- cockatrice/src/player.h | 9 ++- cockatrice/src/tab_game.cpp | 37 +++++++-- common/server_card.cpp | 1 - common/server_game.cpp | 8 +- common/server_player.cpp | 2 + common/server_protocolhandler.cpp | 120 ++++++++++++++++++++-------- 10 files changed, 169 insertions(+), 58 deletions(-) diff --git a/cockatrice/src/abstractcarditem.cpp b/cockatrice/src/abstractcarditem.cpp index 12ad3a8b..a1ae0df1 100644 --- a/cockatrice/src/abstractcarditem.cpp +++ b/cockatrice/src/abstractcarditem.cpp @@ -69,12 +69,13 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla painter->setTransform(pixmapTransform); QFont f; - int fontSize = translatedSize.height() / 8; + int fontSize = round(translatedSize.height() / 8); if (fontSize < 9) fontSize = 9; - if (fontSize > 12) - fontSize = 12; + if (fontSize > 10) + fontSize = 10; f.setPixelSize(fontSize); + painter->setFont(f); } diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 65c39f78..93886046 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -330,7 +330,6 @@ void CardInfo::imageLoaded(const QImage &image) QPixmap *CardInfo::getPixmap(QSize size) { - qDebug() << "CardInfo::getPixmap(" << size.width() << size.height() << ") for" << getName(); QPixmap *cachedPixmap = scaledPixmapCache.value(size.width()); if (cachedPixmap) return cachedPixmap; diff --git a/cockatrice/src/gamescene.cpp b/cockatrice/src/gamescene.cpp index 6266b011..d65a0df7 100644 --- a/cockatrice/src/gamescene.cpp +++ b/cockatrice/src/gamescene.cpp @@ -26,6 +26,7 @@ void GameScene::addPlayer(Player *player) addItem(player); rearrange(); connect(player, SIGNAL(sizeChanged()), this, SLOT(rearrange())); + connect(player, SIGNAL(gameConceded()), this, SLOT(rearrange())); } void GameScene::removePlayer(Player *player) @@ -41,6 +42,9 @@ void GameScene::rearrange() struct PlayerProcessor { static void processPlayer(Player *p, qreal &w, QPointF &b, bool singlePlayer) { + if (p->getConceded()) + return; + const QRectF br = p->boundingRect(); if (br.width() > w) w = br.width(); @@ -52,7 +56,8 @@ void GameScene::rearrange() qreal sceneHeight = -playerAreaSpacing; for (int i = 0; i < players.size(); ++i) - sceneHeight += players[i]->boundingRect().height() + playerAreaSpacing; + if (!players[i]->getConceded()) + sceneHeight += players[i]->boundingRect().height() + playerAreaSpacing; phasesToolbar->setHeight(sceneHeight); qreal phasesWidth = phasesToolbar->getWidth(); diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 13da1d23..43829366 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -23,7 +23,7 @@ #include Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent) - : QObject(_parent), shortcutsActive(false), defaultNumberTopCards(3), lastTokenDestroy(true), userInfo(new ServerInfo_User(info)), id(_id), active(false), local(_local), mirrored(false), dialogSemaphore(false) + : QObject(_parent), shortcutsActive(false), defaultNumberTopCards(3), lastTokenDestroy(true), userInfo(new ServerInfo_User(info)), id(_id), active(false), local(_local), mirrored(false), conceded(false), dialogSemaphore(false) { setCacheMode(DeviceCoordinateCache); @@ -264,17 +264,27 @@ Player::~Player() static_cast(scene())->removePlayer(this); - clearArrows(); - + clear(); QMapIterator i(zones); while (i.hasNext()) delete i.next().value(); - - clearCounters(); + zones.clear(); + delete playerMenu; delete userInfo; } +void Player::clear() +{ + clearArrows(); + + QMapIterator i(zones); + while (i.hasNext()) + i.next().value()->clearContents(); + + clearCounters(); +} + void Player::addPlayer(Player *player) { if (player == this) @@ -362,6 +372,11 @@ void Player::rearrangeZones() rearrangeCounters(); } +void Player::updateZones() +{ + table->reorganizeCards(); +} + void Player::updateBgPixmap() { QString bgPath = settingsCache->getPlayerBgPath(); @@ -1485,6 +1500,16 @@ qreal Player::getMinimumWidth() const return result; } +void Player::setConceded(bool _conceded) +{ + conceded = _conceded; + setVisible(!conceded); + if (conceded) { + clear(); + emit gameConceded(); + } +} + void Player::setMirrored(bool _mirrored) { if (mirrored != _mirrored) { diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index 5516f2f5..578f0105 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -74,6 +74,7 @@ signals: void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer); void sizeChanged(); + void gameConceded(); public slots: void actUntapAll(); void actRollDie(); @@ -102,7 +103,6 @@ public slots: void actSetAnnotation(QAction *action); void cardMenuAction(QAction *action); void actCardCounterTrigger(QAction *action); - private slots: void addPlayer(Player *player); void removePlayer(Player *player); @@ -134,6 +134,7 @@ private: bool active; bool local; bool mirrored; + bool conceded; bool dialogSemaphore; bool clearCardsToDelete(); @@ -203,6 +204,7 @@ public: Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent); ~Player(); void retranslateUi(); + void clear(); QMenu *getPlayerMenu() const { return playerMenu; } int getId() const { return id; } QString getName() const; @@ -211,13 +213,16 @@ public: bool getMirrored() const { return mirrored; } const QMap &getZones() const { return zones; } const QMap &getArrows() const { return arrows; } - TableZone *getTable() const { return table; } void setCardMenu(QMenu *menu); QMenu *getCardMenu() const; bool getActive() const { return active; } void setActive(bool _active); void setShortcutsActive(); void setShortcutsInactive(); + void updateZones(); + + void setConceded(bool _conceded); + bool getConceded() const { return conceded; } qreal getMinimumWidth() const; void setMirrored(bool _mirrored); diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 7cd58c9e..215a50d5 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -477,6 +477,10 @@ void TabGame::startGame() } mainLayout->removeItem(deckViewContainerLayout); + QMapIterator playerIterator(players); + while (playerIterator.hasNext()) + playerIterator.next().value()->setConceded(false); + playerListWidget->setGameStarted(true); started = true; gameView->show(); @@ -581,7 +585,16 @@ void TabGame::eventPlayerPropertiesChanged(Event_PlayerPropertiesChanged *event, messageLog->logNotReadyStart(player); break; } - case ItemId_Context_Concede: messageLog->logConcede(player); break; + case ItemId_Context_Concede: { + messageLog->logConcede(player); + player->setConceded(true); + + QMapIterator playerIterator(players); + while (playerIterator.hasNext()) + playerIterator.next().value()->updateZones(); + + break; + } case ItemId_Context_DeckSelect: messageLog->logDeckSelect(player, static_cast(context)->getDeckId()); break; default: ; } @@ -609,13 +622,21 @@ void TabGame::eventLeave(Event_Leave *event, GameEventContext * /*context*/) int playerId = event->getPlayerId(); Player *player = players.value(playerId, 0); - if (player) { - messageLog->logLeave(player); - playerListWidget->removePlayer(playerId); - players.remove(playerId); - emit playerRemoved(player); - player->deleteLater(); - } + if (!player) + return; + + messageLog->logLeave(player); + playerListWidget->removePlayer(playerId); + players.remove(playerId); + emit playerRemoved(player); + player->clear(); + player->deleteLater(); + + // Rearrange all remaining zones so that attachment relationship updates take place + QMapIterator playerIterator(players); + while (playerIterator.hasNext()) + playerIterator.next().value()->updateZones(); + emit userEvent(); } diff --git a/common/server_card.cpp b/common/server_card.cpp index 792ec0db..53ba1684 100644 --- a/common/server_card.cpp +++ b/common/server_card.cpp @@ -24,7 +24,6 @@ Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y) { } - Server_Card::~Server_Card() { // setParentCard(0) leads to the item being removed from our list, so we can't iterate properly diff --git a/common/server_game.cpp b/common/server_game.cpp index 92234d45..e85ddc7f 100644 --- a/common/server_game.cpp +++ b/common/server_game.cpp @@ -227,13 +227,17 @@ void Server_Game::removePlayer(Server_Player *player) } sendGameEvent(new Event_Leave(player->getPlayerId())); + bool playerActive = activePlayer == player->getPlayerId(); bool spectator = player->getSpectator(); delete player; if (!getPlayerCount()) deleteLater(); - else if (!spectator) + else if (!spectator) { stopGameIfFinished(); + if (gameStarted && playerActive) + nextTurn(); + } qobject_cast(parent())->broadcastGameListUpdate(this); } @@ -271,7 +275,7 @@ void Server_Game::nextTurn() ++listPos; if (listPos == keys.size()) listPos = 0; - } while (players.value(keys[listPos])->getSpectator()); + } while (players.value(keys[listPos])->getSpectator() || players.value(keys[listPos])->getConceded()); setActivePlayer(keys[listPos]); } diff --git a/common/server_player.cpp b/common/server_player.cpp index 2981269d..feddceae 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -22,6 +22,8 @@ Server_Player::~Server_Player() if (handler) handler->playerRemovedFromGame(game); delete userInfo; + + clearZones(); } int Server_Player::newCardId() diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index db9348f5..0541da43 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -322,14 +322,14 @@ ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandC return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdLeaveRoom(Command_LeaveRoom * /*cmd*/, CommandContainer *cont, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdLeaveRoom(Command_LeaveRoom * /*cmd*/, CommandContainer * /*cont*/, Server_Room *room) { rooms.remove(room->getId()); room->removeClient(this); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdRoomSay(Command_RoomSay *cmd, CommandContainer *cont, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdRoomSay(Command_RoomSay *cmd, CommandContainer * /*cont*/, Server_Room *room) { room->say(this, cmd->getMessage()); return RespOk; @@ -351,7 +351,7 @@ ResponseCode Server_ProtocolHandler::cmdListUsers(Command_ListUsers * /*cmd*/, C return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer * /*cont*/, Server_Room *room) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -370,7 +370,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm return RespOk; } -ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer * /*cont*/, Server_Room *room) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -392,7 +392,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandC return result; } -ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { game->removePlayer(player); return RespOk; @@ -423,7 +423,7 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Comm return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(Command_SetSideboardPlan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(Command_SetSideboardPlan *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -438,18 +438,24 @@ ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(Command_SetSideboardPla return RespOk; } -ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; + if (player->getConceded()) + return RespContextError; player->setConceded(true); + player->clearZones(); game->sendGameEvent(new Event_PlayerPropertiesChanged(player->getPlayerId(), player->getProperties()), new Context_Concede); game->stopGameIfFinished(); + if (game->getGameStarted() && (game->getActivePlayer() == player->getPlayerId())) + game->nextTurn(); + return RespOk; } -ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -466,7 +472,7 @@ ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart *cmd, Comm return RespOk; } -ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator() && !game->getSpectatorsCanTalk()) return RespFunctionNotAllowed; @@ -475,13 +481,15 @@ ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, CommandContainer * return RespOk; } -ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; if (!game->getGameStarted()) return RespGameNotStarted; + if (player->getConceded()) + return RespContextError; player->getZones().value("deck")->shuffle(); game->sendGameEvent(new Event_Shuffle(player->getPlayerId())); @@ -495,6 +503,8 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com if (!game->getGameStarted()) return RespGameNotStarted; + if (player->getConceded()) + return RespContextError; Server_CardZone *hand = player->getZones().value("hand"); int number = (hand->cards.size() <= 1) ? player->getInitialCards() : hand->cards.size() - 1; @@ -512,10 +522,12 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com return RespOk; } -ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; + if (player->getConceded()) + return RespContextError; game->sendGameEvent(new Event_RollDie(player->getPlayerId(), cmd->getSides(), rng->getNumber(1, cmd->getSides()))); return RespOk; @@ -528,17 +540,21 @@ ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, Comman if (!game->getGameStarted()) return RespGameNotStarted; + if (player->getConceded()) + return RespContextError; return player->drawCards(cont, cmd->getNumber()); } -ResponseCode Server_ProtocolHandler::cmdUndoDraw(Command_UndoDraw *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdUndoDraw(Command_UndoDraw * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; if (!game->getGameStarted()) return RespGameNotStarted; + if (player->getConceded()) + return RespContextError; return player->undoDraw(cont); } @@ -550,6 +566,8 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandC if (!game->getGameStarted()) return RespGameNotStarted; + if (player->getConceded()) + return RespContextError; QList cardIds; const QList &temp = cmd->getCardIds(); @@ -566,7 +584,9 @@ ResponseCode Server_ProtocolHandler::cmdFlipCard(Command_FlipCard *cmd, CommandC if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + Server_CardZone *zone = player->getZones().value(cmd->getZone()); if (!zone) return RespNameNotFound; @@ -595,6 +615,8 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm if (!game->getGameStarted()) return RespGameNotStarted; + if (player->getConceded()) + return RespContextError; Server_CardZone *startzone = player->getZones().value(cmd->getStartZone()); if (!startzone) @@ -670,13 +692,15 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm return RespOk; } -ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; if (!game->getGameStarted()) return RespGameNotStarted; + if (player->getConceded()) + return RespContextError; Server_CardZone *zone = player->getZones().value(cmd->getZone()); if (!zone) @@ -703,14 +727,16 @@ ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Co return RespOk; } -ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + Server_Player *startPlayer = game->getPlayer(cmd->getStartPlayerId()); Server_Player *targetPlayer = game->getPlayer(cmd->getTargetPlayerId()); if (!startPlayer || !targetPlayer) @@ -764,14 +790,16 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Co return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + if (!player->deleteArrow(cmd->getArrowId())) return RespNameNotFound; @@ -786,7 +814,9 @@ ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Co if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + return player->setCardAttrHelper(cont, cmd->getZone(), cmd->getCardId(), cmd->getAttrName(), cmd->getAttrValue()); } @@ -797,7 +827,9 @@ ResponseCode Server_ProtocolHandler::cmdSetCardCounter(Command_SetCardCounter *c if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + Server_CardZone *zone = player->getZones().value(cmd->getZone()); if (!zone) return RespNameNotFound; @@ -822,7 +854,9 @@ ResponseCode Server_ProtocolHandler::cmdIncCardCounter(Command_IncCardCounter *c if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + Server_CardZone *zone = player->getZones().value(cmd->getZone()); if (!zone) return RespNameNotFound; @@ -841,14 +875,16 @@ ResponseCode Server_ProtocolHandler::cmdIncCardCounter(Command_IncCardCounter *c return RespOk; } -ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + const QMap counters = player->getCounters(); Server_Counter *c = counters.value(cmd->getCounterId(), 0); if (!c) @@ -859,14 +895,16 @@ ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Comm return RespOk; } -ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + Server_Counter *c = new Server_Counter(player->newCounterId(), cmd->getCounterName(), cmd->getColor(), cmd->getRadius(), cmd->getValue()); player->addCounter(c); game->sendGameEvent(new Event_CreateCounters(player->getPlayerId(), QList() << new ServerInfo_Counter(c->getId(), c->getName(), c->getColor(), c->getRadius(), c->getCount()))); @@ -874,14 +912,16 @@ ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd return RespOk; } -ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + Server_Counter *c = player->getCounters().value(cmd->getCounterId(), 0);; if (!c) return RespNameNotFound; @@ -891,40 +931,46 @@ ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, Comm return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + if (!player->deleteCounter(cmd->getCounterId())) return RespNameNotFound; game->sendGameEvent(new Event_DelCounter(player->getPlayerId(), cmd->getCounterId())); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; if (!game->getGameStarted()) return RespGameNotStarted; + if (player->getConceded()) + return RespContextError; game->nextTurn(); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (player->getSpectator()) return RespFunctionNotAllowed; if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + if (game->getActivePlayer() != player->getPlayerId()) return RespContextError; game->setActivePhase(cmd->getPhase()); @@ -936,7 +982,7 @@ ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, CommandC { if (!game->getGameStarted()) return RespGameNotStarted; - + Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId()); if (!otherPlayer) return RespNameNotFound; @@ -981,11 +1027,13 @@ ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, CommandC return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) { if (!game->getGameStarted()) return RespGameNotStarted; - + if (player->getConceded()) + return RespContextError; + Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId()); if (!otherPlayer) return RespNameNotFound; @@ -1007,6 +1055,8 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, Co if (!game->getGameStarted()) return RespGameNotStarted; + if (player->getConceded()) + return RespContextError; Server_Player *otherPlayer = 0; if (cmd->getPlayerId() != -1) {