diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index c56ebd88..2171d206 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -92,6 +92,11 @@ void MessageLogWidget::logReadyStart(Player *player) append(tr("%1 is ready to start the game.").arg(sanitizeHtml(player->getName()))); } +void MessageLogWidget::logConcede(Player *player) +{ + append(tr("%1 has conceded the game.").arg(sanitizeHtml(player->getName()))); +} + void MessageLogWidget::logGameStart() { append(tr("The game has started.")); @@ -283,6 +288,7 @@ void MessageLogWidget::connectToPlayer(Player *player) connect(player, SIGNAL(logSay(Player *, QString)), this, SLOT(logSay(Player *, QString))); connect(player, SIGNAL(logDeckSelect(Player *, int)), this, SLOT(logDeckSelect(Player *, int))); connect(player, SIGNAL(logReadyStart(Player *)), this, SLOT(logReadyStart(Player *))); + connect(player, SIGNAL(logConcede(Player *)), this, SLOT(logConcede(Player *))); connect(player, SIGNAL(logShuffle(Player *)), this, SLOT(logShuffle(Player *))); connect(player, SIGNAL(logRollDie(Player *, int, int)), this, SLOT(logRollDie(Player *, int, int))); connect(player, SIGNAL(logCreateArrow(Player *, Player *, QString, Player *, QString)), this, SLOT(logCreateArrow(Player *, Player *, QString, Player *, QString))); diff --git a/cockatrice/src/messagelogwidget.h b/cockatrice/src/messagelogwidget.h index 22972e85..72ff7fc8 100644 --- a/cockatrice/src/messagelogwidget.h +++ b/cockatrice/src/messagelogwidget.h @@ -30,6 +30,7 @@ public slots: void logLeaveSpectator(QString name); void logDeckSelect(Player *player, int deckId); void logReadyStart(Player *player); + void logConcede(Player *player); void logGameStart(); void logSay(Player *player, QString message); void logShuffle(Player *player); diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 8c26d063..0c0103bf 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -438,6 +438,11 @@ void Player::eventReadyStart(Event_ReadyStart * /*event*/) emit logReadyStart(this); } +void Player::eventConcede(Event_Concede * /*event*/) +{ + emit logConcede(this); +} + void Player::eventShuffle(Event_Shuffle * /*event*/) { emit logShuffle(this); @@ -619,6 +624,7 @@ void Player::processGameEvent(GameEvent *event) case ItemId_Event_DeckSelect: eventDeckSelect(qobject_cast(event)); break; case ItemId_Event_Say: eventSay(qobject_cast(event)); break; case ItemId_Event_ReadyStart: eventReadyStart(qobject_cast(event)); break; + case ItemId_Event_Concede: eventConcede(qobject_cast(event)); break; case ItemId_Event_Shuffle: eventShuffle(qobject_cast(event)); break; case ItemId_Event_RollDie: eventRollDie(qobject_cast(event)); break; case ItemId_Event_CreateArrows: eventCreateArrows(qobject_cast(event)); break; diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index 48412b08..3127ca52 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -25,6 +25,7 @@ class GameEvent; class Event_DeckSelect; class Event_Say; class Event_ReadyStart; +class Event_Concede; class Event_Shuffle; class Event_RollDie; class Event_CreateArrows; @@ -50,6 +51,7 @@ signals: void logDeckSelect(Player *player, int deckId); void logSay(Player *player, QString message); void logReadyStart(Player *player); + void logConcede(Player *player); void logShuffle(Player *player); void logRollDie(Player *player, int sides, int roll); void logCreateArrow(Player *player, Player *startPlayer, QString startCard, Player *targetPlayer, QString targetCard); @@ -116,6 +118,7 @@ private: void eventDeckSelect(Event_DeckSelect *event); void eventSay(Event_Say *event); void eventReadyStart(Event_ReadyStart *event); + void eventConcede(Event_Concede *event); void eventShuffle(Event_Shuffle *event); void eventRollDie(Event_RollDie *event); void eventCreateArrows(Event_CreateArrows *event); diff --git a/cockatrice/src/remotedecklist_treewidget.cpp b/cockatrice/src/remotedecklist_treewidget.cpp index 58f2188b..3846e29f 100644 --- a/cockatrice/src/remotedecklist_treewidget.cpp +++ b/cockatrice/src/remotedecklist_treewidget.cpp @@ -9,7 +9,7 @@ RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(Client *_client, QWidget *p { header()->setResizeMode(QHeaderView::ResizeToContents); setColumnCount(3); - + refreshTree(); retranslateUi(); } @@ -33,6 +33,7 @@ void RemoteDeckList_TreeWidget::addFileToTree(DeckList_File *file, QTreeWidgetIt newDeck->setData(2, Qt::DisplayRole, file->getUploadTime()); parent->addChild(newDeck); + sortItems(0, Qt::AscendingOrder); } void RemoteDeckList_TreeWidget::addFolderToTree(DeckList_Directory *folder, QTreeWidgetItem *parent) @@ -62,6 +63,7 @@ void RemoteDeckList_TreeWidget::addFolderToTree(DeckList_Directory *folder, QTre else addFileToTree(dynamic_cast(folderItems[i]), newItem); } + sortItems(0, Qt::AscendingOrder); } void RemoteDeckList_TreeWidget::refreshTree() diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 8cdcc89d..1e17eeaa 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -88,6 +88,8 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn())); aRemoveLocalArrows = new QAction(this); connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows())); + aConcede = new QAction(this); + connect(aConcede, SIGNAL(triggered()), this, SLOT(actConcede())); aLeaveGame = new QAction(this); connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame())); @@ -98,6 +100,7 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat tabMenu->addSeparator(); tabMenu->addAction(aRemoveLocalArrows); tabMenu->addSeparator(); + tabMenu->addAction(aConcede); tabMenu->addAction(aLeaveGame); retranslateUi(); @@ -120,6 +123,8 @@ void TabGame::retranslateUi() aNextTurn->setShortcuts(QList() << QKeySequence(tr("Ctrl+Return")) << QKeySequence(tr("Ctrl+Enter"))); aRemoveLocalArrows->setText(tr("&Remove all local arrows")); aRemoveLocalArrows->setShortcut(tr("Ctrl+R")); + aConcede->setText(tr("&Concede")); + aConcede->setShortcut(tr("F2")); aLeaveGame->setText(tr("&Leave game")); loadLocalButton->setText(tr("Load &local deck")); @@ -136,6 +141,14 @@ void TabGame::retranslateUi() i.next().value()->retranslateUi(); } +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); +} + 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) @@ -235,6 +248,15 @@ void TabGame::startGame() phasesToolbar->show(); } +void TabGame::stopGame() +{ + currentPhase = -1; + started = false; + gameView->hide(); + phasesToolbar->hide(); + deckViewContainer->show(); +} + void TabGame::eventGameStart(Event_GameStart * /*event*/) { startGame(); @@ -256,11 +278,18 @@ void TabGame::eventGameStateChanged(Event_GameStateChanged *event) playerListWidget->addPlayer(pl); } player->processPlayerInfo(pl); + if (player->getLocal() && pl->getDeck()) { + Deck_PictureCacher::cachePictures(pl->getDeck(), this); + deckView->setDeck(new DeckList(pl->getDeck())); + } } if (event->getGameStarted() && !started) { startGame(); setActivePlayer(event->getActivePlayer()); setActivePhase(event->getActivePhase()); + } else if (!event->getGameStarted() && started) { + stopGame(); + zoneLayout->clear(); } } diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index a6fef256..8cace4ce 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -61,11 +61,13 @@ private: QAction *playersSeparator; QMenu *playersMenu; QAction *aCloseMostRecentZoneView, - *aLeaveGame, *aNextPhase, *aNextTurn, *aRemoveLocalArrows; + *aConcede, *aLeaveGame, *aNextPhase, *aNextTurn, *aRemoveLocalArrows; Player *addPlayer(int playerId, const QString &playerName); void startGame(); + void stopGame(); + void eventGameStart(Event_GameStart *event); void eventGameStateChanged(Event_GameStateChanged *event); void eventJoin(Event_Join *event); @@ -84,6 +86,7 @@ private slots: void deckSelectFinished(ProtocolResponse *r); void newCardAdded(CardItem *card); + void actConcede(); void actLeaveGame(); void actRemoveLocalArrows(); void actSay(); diff --git a/common/protocol_datastructures.cpp b/common/protocol_datastructures.cpp index 42455d54..0185f8e6 100644 --- a/common/protocol_datastructures.cpp +++ b/common/protocol_datastructures.cpp @@ -108,12 +108,13 @@ ServerInfo_Arrow::ServerInfo_Arrow(int _id, int _startPlayerId, const QString &_ insertItem(new SerializableItem_Color("color", _color)); } -ServerInfo_Player::ServerInfo_Player(int _playerId, const QString &_name, bool _spectator, DeckList *_deck, const QList &_zoneList, const QList &_counterList, const QList &_arrowList) +ServerInfo_Player::ServerInfo_Player(int _playerId, const QString &_name, bool _spectator, bool _conceded, DeckList *_deck, const QList &_zoneList, const QList &_counterList, const QList &_arrowList) : SerializableItem_Map("player"), zoneList(_zoneList), counterList(_counterList), arrowList(_arrowList) { insertItem(new SerializableItem_Int("player_id", _playerId)); insertItem(new SerializableItem_String("name", _name)); insertItem(new SerializableItem_Bool("spectator", _spectator)); + insertItem(new SerializableItem_Bool("conceded", _conceded)); if (!_deck) insertItem(new DeckList); else diff --git a/common/protocol_datastructures.h b/common/protocol_datastructures.h index 6c4bb074..9038d5dc 100644 --- a/common/protocol_datastructures.h +++ b/common/protocol_datastructures.h @@ -112,11 +112,12 @@ private: protected: void extractData(); public: - ServerInfo_Player(int _playerId = -1, const QString &_name = QString(), bool _spectator = false, DeckList *_deck = 0, const QList &_zoneList = QList(), const QList &_counterList = QList(), const QList &_arrowList = QList()); + ServerInfo_Player(int _playerId = -1, const QString &_name = QString(), bool _spectator = false, bool _conceded = false, DeckList *_deck = 0, const QList &_zoneList = QList(), const QList &_counterList = QList(), const QList &_arrowList = QList()); static SerializableItem *newItem() { return new ServerInfo_Player; } int getPlayerId() const { return static_cast(itemMap.value("player_id"))->getData(); } QString getName() const { return static_cast(itemMap.value("name"))->getData(); } bool getSpectator() const { return static_cast(itemMap.value("spectator"))->getData(); } + bool getConceded() const { return static_cast(itemMap.value("conceded"))->getData(); } DeckList *getDeck() const; const QList &getZoneList() const { return zoneList; } const QList &getCounterList() const { return counterList; } diff --git a/common/protocol_item_ids.h b/common/protocol_item_ids.h index 3989eedf..40dd12f0 100644 --- a/common/protocol_item_ids.h +++ b/common/protocol_item_ids.h @@ -24,36 +24,38 @@ ItemId_Command_CreateArrow = 1022, ItemId_Command_DeleteArrow = 1023, ItemId_Command_SetCardAttr = 1024, ItemId_Command_ReadyStart = 1025, -ItemId_Command_IncCounter = 1026, -ItemId_Command_CreateCounter = 1027, -ItemId_Command_SetCounter = 1028, -ItemId_Command_DelCounter = 1029, -ItemId_Command_NextTurn = 1030, -ItemId_Command_SetActivePhase = 1031, -ItemId_Command_DumpZone = 1032, -ItemId_Command_StopDumpZone = 1033, -ItemId_Event_Say = 1034, -ItemId_Event_Leave = 1035, -ItemId_Event_DeckSelect = 1036, -ItemId_Event_GameClosed = 1037, -ItemId_Event_ReadyStart = 1038, -ItemId_Event_GameStart = 1039, -ItemId_Event_Shuffle = 1040, -ItemId_Event_RollDie = 1041, -ItemId_Event_MoveCard = 1042, -ItemId_Event_CreateToken = 1043, -ItemId_Event_DeleteArrow = 1044, -ItemId_Event_SetCardAttr = 1045, -ItemId_Event_SetCounter = 1046, -ItemId_Event_DelCounter = 1047, -ItemId_Event_SetActivePlayer = 1048, -ItemId_Event_SetActivePhase = 1049, -ItemId_Event_DumpZone = 1050, -ItemId_Event_StopDumpZone = 1051, -ItemId_Event_ServerMessage = 1052, -ItemId_Event_GameJoined = 1053, -ItemId_Event_ChatJoinChannel = 1054, -ItemId_Event_ChatLeaveChannel = 1055, -ItemId_Event_ChatSay = 1056, -ItemId_Other = 1057 +ItemId_Command_Concede = 1026, +ItemId_Command_IncCounter = 1027, +ItemId_Command_CreateCounter = 1028, +ItemId_Command_SetCounter = 1029, +ItemId_Command_DelCounter = 1030, +ItemId_Command_NextTurn = 1031, +ItemId_Command_SetActivePhase = 1032, +ItemId_Command_DumpZone = 1033, +ItemId_Command_StopDumpZone = 1034, +ItemId_Event_Say = 1035, +ItemId_Event_Leave = 1036, +ItemId_Event_DeckSelect = 1037, +ItemId_Event_GameClosed = 1038, +ItemId_Event_ReadyStart = 1039, +ItemId_Event_Concede = 1040, +ItemId_Event_GameStart = 1041, +ItemId_Event_Shuffle = 1042, +ItemId_Event_RollDie = 1043, +ItemId_Event_MoveCard = 1044, +ItemId_Event_CreateToken = 1045, +ItemId_Event_DeleteArrow = 1046, +ItemId_Event_SetCardAttr = 1047, +ItemId_Event_SetCounter = 1048, +ItemId_Event_DelCounter = 1049, +ItemId_Event_SetActivePlayer = 1050, +ItemId_Event_SetActivePhase = 1051, +ItemId_Event_DumpZone = 1052, +ItemId_Event_StopDumpZone = 1053, +ItemId_Event_ServerMessage = 1054, +ItemId_Event_GameJoined = 1055, +ItemId_Event_ChatJoinChannel = 1056, +ItemId_Event_ChatLeaveChannel = 1057, +ItemId_Event_ChatSay = 1058, +ItemId_Other = 1059 }; diff --git a/common/protocol_items.cpp b/common/protocol_items.cpp index d2f7072d..5bb3bf78 100644 --- a/common/protocol_items.cpp +++ b/common/protocol_items.cpp @@ -143,6 +143,10 @@ Command_ReadyStart::Command_ReadyStart(int _gameId) : GameCommand("ready_start", _gameId) { } +Command_Concede::Command_Concede(int _gameId) + : GameCommand("concede", _gameId) +{ +} Command_IncCounter::Command_IncCounter(int _gameId, int _counterId, int _delta) : GameCommand("inc_counter", _gameId) { @@ -212,6 +216,10 @@ Event_ReadyStart::Event_ReadyStart(int _gameId, int _playerId) : GameEvent("ready_start", _gameId, _playerId) { } +Event_Concede::Event_Concede(int _gameId, int _playerId) + : GameEvent("concede", _gameId, _playerId) +{ +} Event_GameStart::Event_GameStart(int _gameId, int _playerId) : GameEvent("game_start", _gameId, _playerId) { @@ -350,6 +358,7 @@ void ProtocolItem::initializeHashAuto() itemNameHash.insert("cmddelete_arrow", Command_DeleteArrow::newItem); itemNameHash.insert("cmdset_card_attr", Command_SetCardAttr::newItem); itemNameHash.insert("cmdready_start", Command_ReadyStart::newItem); + itemNameHash.insert("cmdconcede", Command_Concede::newItem); itemNameHash.insert("cmdinc_counter", Command_IncCounter::newItem); itemNameHash.insert("cmdcreate_counter", Command_CreateCounter::newItem); itemNameHash.insert("cmdset_counter", Command_SetCounter::newItem); @@ -363,6 +372,7 @@ void ProtocolItem::initializeHashAuto() itemNameHash.insert("game_eventdeck_select", Event_DeckSelect::newItem); itemNameHash.insert("game_eventgame_closed", Event_GameClosed::newItem); itemNameHash.insert("game_eventready_start", Event_ReadyStart::newItem); + itemNameHash.insert("game_eventconcede", Event_Concede::newItem); itemNameHash.insert("game_eventgame_start", Event_GameStart::newItem); itemNameHash.insert("game_eventshuffle", Event_Shuffle::newItem); itemNameHash.insert("game_eventroll_die", Event_RollDie::newItem); diff --git a/common/protocol_items.dat b/common/protocol_items.dat index 7749de20..57518d9b 100644 --- a/common/protocol_items.dat +++ b/common/protocol_items.dat @@ -23,6 +23,7 @@ 2:delete_arrow:i,arrow_id 2:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value 2:ready_start +2:concede 2:inc_counter:i,counter_id:i,delta 2:create_counter:s,counter_name:c,color:i,radius:i,value 2:set_counter:i,counter_id:i,value @@ -36,6 +37,7 @@ 3:deck_select:i,deck_id 3:game_closed 3:ready_start +3:concede 3:game_start 3:shuffle 3:roll_die:i,sides:i,value @@ -53,4 +55,4 @@ 4:game_joined:i,game_id:i,player_id:b,spectator 5:chat_join_channel:s,player_name 5:chat_leave_channel:s,player_name -5:chat_say:s,player_name:s,message \ No newline at end of file +5:chat_say:s,player_name:s,message diff --git a/common/protocol_items.h b/common/protocol_items.h index 47bbcbb9..0177920d 100644 --- a/common/protocol_items.h +++ b/common/protocol_items.h @@ -220,6 +220,13 @@ public: static SerializableItem *newItem() { return new Command_ReadyStart; } int getItemId() const { return ItemId_Command_ReadyStart; } }; +class Command_Concede : public GameCommand { + Q_OBJECT +public: + Command_Concede(int _gameId = -1); + static SerializableItem *newItem() { return new Command_Concede; } + int getItemId() const { return ItemId_Command_Concede; } +}; class Command_IncCounter : public GameCommand { Q_OBJECT public: @@ -328,6 +335,13 @@ public: static SerializableItem *newItem() { return new Event_ReadyStart; } int getItemId() const { return ItemId_Event_ReadyStart; } }; +class Event_Concede : public GameEvent { + Q_OBJECT +public: + Event_Concede(int _gameId = -1, int _playerId = -1); + static SerializableItem *newItem() { return new Event_Concede; } + int getItemId() const { return ItemId_Event_Concede; } +}; class Event_GameStart : public GameEvent { Q_OBJECT public: diff --git a/common/server_game.cpp b/common/server_game.cpp index 01882a77..7ae84a22 100644 --- a/common/server_game.cpp +++ b/common/server_game.cpp @@ -64,6 +64,8 @@ void Server_Game::startGameIfReady() playerIterator.toFront(); while (playerIterator.hasNext()) { Server_Player *player = playerIterator.next().value(); + player->setConceded(false); + player->setReadyStart(false); player->sendProtocolItem(new Event_GameStateChanged(gameId, gameStarted, 0, 0, getGameState(player))); } @@ -87,6 +89,27 @@ void Server_Game::startGameIfReady() setActivePlayer(0); } +void Server_Game::stopGameIfFinished() +{ + QMapIterator playerIterator(players); + int playing = 0; + while (playerIterator.hasNext()) { + Server_Player *p = playerIterator.next().value(); + if (!p->getConceded() && !p->getSpectator()) + ++playing; + } + if (playing > 1) + return; + + gameStarted = false; + playerIterator.toFront(); + while (playerIterator.hasNext()) { + Server_Player *player = playerIterator.next().value(); + player->sendProtocolItem(new Event_GameStateChanged(gameId, gameStarted, -1, -1, getGameState(player))); + } + +} + ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator) { if (_password != password) @@ -215,7 +238,7 @@ QList Server_Game::getGameState(Server_Player *playerWhosAs zoneList.append(new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), zone->cards.size(), cardList)); } - result.append(new ServerInfo_Player(player->getPlayerId(), player->getPlayerName(), player->getSpectator(), player->getDeck(), zoneList, counterList, arrowList)); + result.append(new ServerInfo_Player(player->getPlayerId(), player->getPlayerName(), player->getSpectator(), player->getConceded(), player == playerWhosAsking ? player->getDeck() : 0, zoneList, counterList, arrowList)); } return result; } diff --git a/common/server_game.h b/common/server_game.h index d8f4fb4d..24291b37 100644 --- a/common/server_game.h +++ b/common/server_game.h @@ -60,6 +60,7 @@ public: Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate = true); void removePlayer(Server_Player *player); void startGameIfReady(); + void stopGameIfFinished(); int getActivePlayer() const { return activePlayer; } int getActivePhase() const { return activePhase; } void setActivePlayer(int _activePlayer); diff --git a/common/server_player.h b/common/server_player.h index df14c131..5f33dab0 100644 --- a/common/server_player.h +++ b/common/server_player.h @@ -29,6 +29,7 @@ private: int nextCardId; void clearZones(); bool readyStart; + bool conceded; public: Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler); void setProtocolHandler(Server_ProtocolHandler *_handler) { handler = _handler; } @@ -38,6 +39,8 @@ public: void setReadyStart(bool _readyStart) { readyStart = _readyStart; } int getPlayerId() const { return playerId; } bool getSpectator() const { return spectator; } + bool getConceded() const { return conceded; } + void setConceded(bool _conceded) { conceded = _conceded; } QString getPlayerName() const { return playerName; } void setDeck(DeckList *_deck); DeckList *getDeck() const { return deck; } diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index b7f2a20e..87f6fd85 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -80,6 +80,8 @@ void Server_ProtocolHandler::processCommand(Command *command) switch (command->getItemId()) { case ItemId_Command_DeckSelect: response = cmdDeckSelect(qobject_cast(command), game, player); break; case ItemId_Command_LeaveGame: response = cmdLeaveGame(qobject_cast(command), game, player); break; + case ItemId_Command_ReadyStart: response = cmdReadyStart(qobject_cast(command), game, player); break; + case ItemId_Command_Concede: response = cmdConcede(qobject_cast(command), game, player); break; case ItemId_Command_Say: response = cmdSay(qobject_cast(command), game, player); break; case ItemId_Command_Shuffle: response = cmdShuffle(qobject_cast(command), game, player); break; case ItemId_Command_RollDie: response = cmdRollDie(qobject_cast(command), game, player); break; @@ -89,7 +91,6 @@ void Server_ProtocolHandler::processCommand(Command *command) case ItemId_Command_CreateArrow: response = cmdCreateArrow(qobject_cast(command), game, player); break; case ItemId_Command_DeleteArrow: response = cmdDeleteArrow(qobject_cast(command), game, player); break; case ItemId_Command_SetCardAttr: response = cmdSetCardAttr(qobject_cast(command), game, player); break; - case ItemId_Command_ReadyStart: response = cmdReadyStart(qobject_cast(command), game, player); break; case ItemId_Command_IncCounter: response = cmdIncCounter(qobject_cast(command), game, player); break; case ItemId_Command_CreateCounter: response = cmdCreateCounter(qobject_cast(command), game, player); break; case ItemId_Command_SetCounter: response = cmdSetCounter(qobject_cast(command), game, player); break; @@ -297,6 +298,25 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Serv return RespNothing; } +ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, Server_Game *game, Server_Player *player) +{ + player->setConceded(true); + game->sendGameEvent(new Event_Concede(-1, player->getPlayerId())); + game->stopGameIfFinished(); + return RespOk; +} + +ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, Server_Game *game, Server_Player *player) +{ + if (!player->getDeck()) + return RespContextError; + + player->setReadyStart(true); + game->sendGameEvent(new Event_ReadyStart(-1, player->getPlayerId())); + game->startGameIfReady(); + return RespOk; +} + ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player) { game->sendGameEvent(new Event_Say(-1, player->getPlayerId(), cmd->getMessage())); @@ -504,17 +524,6 @@ ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Se return RespOk; } -ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, Server_Game *game, Server_Player *player) -{ - if (!player->getDeck()) - return RespContextError; - - player->setReadyStart(true); - game->sendGameEvent(new Event_ReadyStart(-1, player->getPlayerId())); - game->startGameIfReady(); - return RespOk; -} - ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player) { const QMap counters = player->getCounters(); diff --git a/common/server_protocolhandler.h b/common/server_protocolhandler.h index 48898966..71126d13 100644 --- a/common/server_protocolhandler.h +++ b/common/server_protocolhandler.h @@ -45,6 +45,8 @@ private: ResponseCode cmdCreateGame(Command_CreateGame *cmd); ResponseCode cmdJoinGame(Command_JoinGame *cmd); ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player); + ResponseCode cmdConcede(Command_Concede *cmd, Server_Game *game, Server_Player *player); + ResponseCode cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdDeckSelect(Command_DeckSelect *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player); @@ -55,7 +57,6 @@ private: ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player); - ResponseCode cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdCreateCounter(Command_CreateCounter *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player);