diff --git a/cockatrice/src/abstractclient.cpp b/cockatrice/src/abstractclient.cpp index f8d6feb0..f1cce27d 100644 --- a/cockatrice/src/abstractclient.cpp +++ b/cockatrice/src/abstractclient.cpp @@ -98,6 +98,15 @@ PendingCommand *AbstractClient::prepareSessionCommand(const ::google::protobuf:: return new PendingCommand(cont); } +PendingCommand *AbstractClient::prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId) +{ + CommandContainer cont; + RoomCommand *c = cont.add_room_command(); + cont.set_room_id(roomId); + c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); + return new PendingCommand(cont); +} + PendingCommand *AbstractClient::prepareModeratorCommand(const ::google::protobuf::Message &cmd) { CommandContainer cont; diff --git a/cockatrice/src/abstractclient.h b/cockatrice/src/abstractclient.h index 182481d5..3076def3 100644 --- a/cockatrice/src/abstractclient.h +++ b/cockatrice/src/abstractclient.h @@ -77,6 +77,7 @@ public: void sendCommand(PendingCommand *pend); PendingCommand *prepareSessionCommand(const ::google::protobuf::Message &cmd); + PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId); PendingCommand *prepareModeratorCommand(const ::google::protobuf::Message &cmd); PendingCommand *prepareAdminCommand(const ::google::protobuf::Message &cmd); }; diff --git a/cockatrice/src/gameselector.cpp b/cockatrice/src/gameselector.cpp index 5da3790f..858f3e99 100644 --- a/cockatrice/src/gameselector.cpp +++ b/cockatrice/src/gameselector.cpp @@ -37,9 +37,10 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso filterLayout->addWidget(showFullGamesCheckBox); filterLayout->addWidget(showRunningGamesCheckBox); - if (room) + if (room) { createButton = new QPushButton; - else + connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate())); + } else createButton = 0; joinButton = new QPushButton; spectateButton = new QPushButton; @@ -68,7 +69,6 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso connect(showFullGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showFullGamesChanged(int))); connect(showRunningGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showRunningGamesChanged(int))); - connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate())); connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin())); connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin())); } @@ -132,9 +132,15 @@ void GameSelector::actJoin() cmd.set_spectator(spectator); cmd.set_override_restrictions(overrideRestrictions); - PendingCommand *pend = room->prepareRoomCommand(cmd); + TabRoom *r = tabSupervisor->getRoomTabs().value(game->getRoomId()); + if (!r) { + QMessageBox::critical(this, tr("Error"), tr("Please join the respective room first.")); + return; + } + + PendingCommand *pend = r->prepareRoomCommand(cmd); connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode))); - room->sendRoomCommand(pend); + r->sendRoomCommand(pend); if (createButton) createButton->setEnabled(false); diff --git a/cockatrice/src/localclient.cpp b/cockatrice/src/localclient.cpp index 0539cf09..30ee2cfa 100644 --- a/cockatrice/src/localclient.cpp +++ b/cockatrice/src/localclient.cpp @@ -24,9 +24,7 @@ LocalClient::~LocalClient() void LocalClient::sendCommandContainer(const CommandContainer &cont) { -// cont->setReceiverMayDelete(false); -// pendingCommands.insert(cont->getCmdId(), cont); -// lsi->itemFromClient(cont); + lsi->itemFromClient(cont); } void LocalClient::itemFromServer(ProtocolItem *item) diff --git a/cockatrice/src/localserverinterface.cpp b/cockatrice/src/localserverinterface.cpp index c68aa863..df1eeb36 100644 --- a/cockatrice/src/localserverinterface.cpp +++ b/cockatrice/src/localserverinterface.cpp @@ -19,8 +19,9 @@ void LocalServerInterface::sendProtocolItem(ProtocolItem *item, bool deleteItem) if (deleteItem) delete item; } - -void LocalServerInterface::itemFromClient(ProtocolItem *item) +#include "pb/commands.pb.h" +void LocalServerInterface::itemFromClient(const CommandContainer &item) { - //processCommandContainer(static_cast(item)); + qDebug() << "READ" << QString::fromStdString(item.ShortDebugString()); + processCommandContainer(item); } diff --git a/cockatrice/src/localserverinterface.h b/cockatrice/src/localserverinterface.h index ab2e61d0..19d2d58c 100644 --- a/cockatrice/src/localserverinterface.h +++ b/cockatrice/src/localserverinterface.h @@ -10,17 +10,17 @@ class LocalServerInterface : public Server_ProtocolHandler Q_OBJECT private: DeckList *getDeckFromDatabase(int /*deckId*/) { return 0; } - ResponseCode cmdAddToList(const Command_AddToList & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } - ResponseCode cmdRemoveFromList(const Command_RemoveFromList & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } - ResponseCode cmdDeckList(const Command_DeckList & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } - ResponseCode cmdDeckNewDir(const Command_DeckNewDir & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } - ResponseCode cmdDeckDelDir(const Command_DeckDelDir & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } - ResponseCode cmdDeckDel(const Command_DeckDel & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } - ResponseCode cmdDeckUpload(const Command_DeckUpload & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } - ResponseCode cmdDeckDownload(const Command_DeckDownload & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } - ResponseCode cmdBanFromServer(const Command_BanFromServer & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } - ResponseCode cmdShutdownServer(const Command_ShutdownServer & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } - ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } + ResponseCode cmdAddToList(const Command_AddToList & /*cmd*/, BlaContainer * /*bla*/) { return RespFunctionNotAllowed; } + ResponseCode cmdRemoveFromList(const Command_RemoveFromList & /*cmd*/, BlaContainer * /*bla*/) { return RespFunctionNotAllowed; } + ResponseCode cmdDeckList(const Command_DeckList & /*cmd*/, BlaContainer * /*bla*/) { return RespFunctionNotAllowed; } + ResponseCode cmdDeckNewDir(const Command_DeckNewDir & /*cmd*/, BlaContainer * /*bla*/) { return RespFunctionNotAllowed; } + ResponseCode cmdDeckDelDir(const Command_DeckDelDir & /*cmd*/, BlaContainer * /*bla*/) { return RespFunctionNotAllowed; } + ResponseCode cmdDeckDel(const Command_DeckDel & /*cmd*/, BlaContainer * /*bla*/) { return RespFunctionNotAllowed; } + ResponseCode cmdDeckUpload(const Command_DeckUpload & /*cmd*/, BlaContainer * /*bla*/) { return RespFunctionNotAllowed; } + ResponseCode cmdDeckDownload(const Command_DeckDownload & /*cmd*/, BlaContainer * /*bla*/) { return RespFunctionNotAllowed; } + ResponseCode cmdBanFromServer(const Command_BanFromServer & /*cmd*/, BlaContainer * /*bla*/) { return RespFunctionNotAllowed; } + ResponseCode cmdShutdownServer(const Command_ShutdownServer & /*cmd*/, BlaContainer * /*bla*/) { return RespFunctionNotAllowed; } + ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage & /*cmd*/, BlaContainer * /*bla*/) { return RespFunctionNotAllowed; } protected: bool getCompressionSupport() const { return false; } public: @@ -32,7 +32,7 @@ public: signals: void itemToClient(ProtocolItem *item); public slots: - void itemFromClient(ProtocolItem *item); + void itemFromClient(const CommandContainer &item); }; #endif \ No newline at end of file diff --git a/cockatrice/src/phasestoolbar.cpp b/cockatrice/src/phasestoolbar.cpp index 3895517f..35d2af08 100644 --- a/cockatrice/src/phasestoolbar.cpp +++ b/cockatrice/src/phasestoolbar.cpp @@ -105,22 +105,16 @@ PhasesToolbar::PhasesToolbar(QGraphicsItem *parent) connect(aDrawCard, SIGNAL(triggered()), this, SLOT(actDrawCard())); PhaseButton *untapButton = new PhaseButton("untap", this, aUntapAll); -// untapButton->setShortcut(QKeySequence("F5")); PhaseButton *upkeepButton = new PhaseButton("upkeep", this); PhaseButton *drawButton = new PhaseButton("draw", this, aDrawCard); -// drawButton->setShortcut(QKeySequence("F6")); PhaseButton *main1Button = new PhaseButton("main1", this); -// main1Button->setShortcut(QKeySequence("F7")); PhaseButton *combatStartButton = new PhaseButton("combat_start", this); -// combatStartButton->setShortcut(QKeySequence("F8")); PhaseButton *combatAttackersButton = new PhaseButton("combat_attackers", this); PhaseButton *combatBlockersButton = new PhaseButton("combat_blockers", this); PhaseButton *combatDamageButton = new PhaseButton("combat_damage", this); PhaseButton *combatEndButton = new PhaseButton("combat_end", this); PhaseButton *main2Button = new PhaseButton("main2", this); -// main2Button->setShortcut(QKeySequence("F9")); PhaseButton *cleanupButton = new PhaseButton("cleanup", this); -// cleanupButton->setShortcut(QKeySequence("F10")); buttonList << untapButton << upkeepButton << drawButton << main1Button << combatStartButton << combatAttackersButton << combatBlockersButton << combatDamageButton << combatEndButton diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 4e58d105..ac82c63f 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -1420,11 +1420,6 @@ void Player::sendGameCommand(const google::protobuf::Message &command) static_cast(parent())->sendGameCommand(command, id); } -void Player::sendCommandContainer(CommandContainer &cont) -{ - static_cast(parent())->sendCommandContainer(cont, id); -} - void Player::sendGameCommand(PendingCommand *pend) { static_cast(parent())->sendGameCommand(pend, id); diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index 3d93dbcc..af8aa9de 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -261,7 +261,6 @@ public: PendingCommand *prepareGameCommand(const QList< const ::google::protobuf::Message * > &cmdList); void sendGameCommand(PendingCommand *pend); void sendGameCommand(const google::protobuf::Message &command); - void sendCommandContainer(CommandContainer &cont); }; #endif diff --git a/cockatrice/src/tab_deck_storage.cpp b/cockatrice/src/tab_deck_storage.cpp index f870ad8f..5a027d7b 100644 --- a/cockatrice/src/tab_deck_storage.cpp +++ b/cockatrice/src/tab_deck_storage.cpp @@ -143,17 +143,17 @@ void TabDeckStorage::actUpload() QString filePath = localDirModel->filePath(curLeft); QFile deckFile(filePath); QFileInfo deckFileInfo(deckFile); - DeckList *deck = new DeckList; - if (!deck->loadFromFile(filePath, DeckList::CockatriceFormat)) + DeckList deck; + if (!deck.loadFromFile(filePath, DeckList::CockatriceFormat)) return; - if (deck->getName().isEmpty()) { + if (deck.getName().isEmpty()) { bool ok; QString deckName = QInputDialog::getText(this, tr("Enter deck name"), tr("This decklist does not have a name.\nPlease enter a name:"), QLineEdit::Normal, deckFileInfo.completeBaseName(), &ok); if (!ok) return; if (deckName.isEmpty()) deckName = tr("Unnamed deck"); - deck->setName(deckName); + deck.setName(deckName); } QString targetPath; @@ -163,10 +163,14 @@ void TabDeckStorage::actUpload() if (!dynamic_cast(curRight)) curRight = curRight->getParent(); targetPath = dynamic_cast(curRight)->getPath(); - -// Command_DeckUpload *command = new Command_DeckUpload(deck, targetPath); -// connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(uploadFinished(ProtocolResponse *))); -// client->sendCommand(command); + + Command_DeckUpload cmd; + cmd.set_path(targetPath.toStdString()); + cmd.set_deck_list(deck.writeToString_Native().toStdString()); + + PendingCommand *pend = client->prepareSessionCommand(cmd); + connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(uploadFinished(ProtocolResponse *))); + client->sendCommand(pend); } void TabDeckStorage::uploadFinished(ProtocolResponse *r) @@ -174,9 +178,9 @@ void TabDeckStorage::uploadFinished(ProtocolResponse *r) Response_DeckUpload *resp = qobject_cast(r); if (!resp) return; -// Command_DeckUpload *cmd = static_cast(sender()); -// -// serverDirView->addFileToTree(resp->getFile(), serverDirView->getNodeByPath(cmd->getPath())); + const Command_DeckUpload &cmd = static_cast(static_cast(sender())->getCommandContainer().session_command(0).GetExtension(Command_DeckUpload::ext)); + + serverDirView->addFileToTree(resp->getFile(), serverDirView->getNodeByPath(QString::fromStdString(cmd.path()))); } void TabDeckStorage::actOpenRemoteDeck() @@ -184,10 +188,13 @@ void TabDeckStorage::actOpenRemoteDeck() RemoteDeckList_TreeModel::FileNode *curRight = dynamic_cast(serverDirView->getCurrentItem()); if (!curRight) return; - -// Command_DeckDownload *command = new Command_DeckDownload(curRight->getId()); -// connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(openRemoteDeckFinished(ProtocolResponse *))); -// client->sendCommand(command); + + Command_DeckDownload cmd; + cmd.set_deck_id(curRight->getId()); + + PendingCommand *pend = client->prepareSessionCommand(cmd); + connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(openRemoteDeckFinished(ProtocolResponse *))); + client->sendCommand(pend); } void TabDeckStorage::openRemoteDeckFinished(ProtocolResponse *r) @@ -217,11 +224,14 @@ void TabDeckStorage::actDownload() if (!curRight) return; filePath += QString("/deck_%1.cod").arg(curRight->getId()); - -// Command_DeckDownload *command = new Command_DeckDownload(curRight->getId()); -// command->setExtraData(filePath); -// connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(downloadFinished(ProtocolResponse *))); -// client->sendCommand(command); + + Command_DeckDownload cmd; + cmd.set_deck_id(curRight->getId()); + + PendingCommand *pend = client->prepareSessionCommand(cmd); + pend->setExtraData(filePath); + connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(downloadFinished(ProtocolResponse *))); + client->sendCommand(pend); } void TabDeckStorage::downloadFinished(ProtocolResponse *r) @@ -229,10 +239,10 @@ void TabDeckStorage::downloadFinished(ProtocolResponse *r) Response_DeckDownload *resp = qobject_cast(r); if (!resp) return; -// Command_DeckDownload *cmd = static_cast(sender()); -// -// QString filePath = cmd->getExtraData().toString(); -// resp->getDeck()->saveToFile(filePath, DeckList::CockatriceFormat); + + PendingCommand *pend = static_cast(sender()); + QString filePath = pend->getExtraData().toString(); + resp->getDeck()->saveToFile(filePath, DeckList::CockatriceFormat); } void TabDeckStorage::actNewFolder() @@ -263,9 +273,9 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp) { if (resp != RespOk) return; - -// Command_DeckNewDir *cmd = static_cast(sender()); -// serverDirView->addFolderToTree(cmd->getDirName(), serverDirView->getNodeByPath(cmd->getPath())); + + const Command_DeckNewDir &cmd = static_cast(static_cast(sender())->getCommandContainer().session_command(0).GetExtension(Command_DeckNewDir::ext)); + serverDirView->addFolderToTree(QString::fromStdString(cmd.dir_name()), serverDirView->getNodeByPath(QString::fromStdString(cmd.path()))); } void TabDeckStorage::actDelete() @@ -282,28 +292,35 @@ void TabDeckStorage::actDelete() Command_DeckDelDir cmd; cmd.set_path(path.toStdString()); pend = client->prepareSessionCommand(cmd); + connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(deleteFolderFinished(ResponseCode))); } else { Command_DeckDel cmd; cmd.set_deck_id(dynamic_cast(curRight)->getId()); pend = client->prepareSessionCommand(cmd); + connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(deleteDeckFinished(ResponseCode))); } - connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(deleteFinished(ResponseCode))); client->sendCommand(pend); } -void TabDeckStorage::deleteFinished(ResponseCode resp) +void TabDeckStorage::deleteDeckFinished(ResponseCode resp) { if (resp != RespOk) return; - - RemoteDeckList_TreeModel::Node *toDelete = 0; -// Command_DeckDelDir *cmdDelDir = qobject_cast(sender()); -// if (cmdDelDir) -// toDelete = serverDirView->getNodeByPath(cmdDelDir->getPath()); -// else -// toDelete = serverDirView->getNodeById(static_cast(sender())->getDeckId()); + const Command_DeckDel &cmd = static_cast(static_cast(sender())->getCommandContainer().session_command(0).GetExtension(Command_DeckDel::ext)); + RemoteDeckList_TreeModel::Node *toDelete = serverDirView->getNodeById(cmd.deck_id()); + if (toDelete) + serverDirView->removeNode(toDelete); +} + +void TabDeckStorage::deleteFolderFinished(ResponseCode resp) +{ + if (resp != RespOk) + return; + + const Command_DeckDelDir &cmd = static_cast(static_cast(sender())->getCommandContainer().session_command(0).GetExtension(Command_DeckDelDir::ext)); + RemoteDeckList_TreeModel::Node *toDelete = serverDirView->getNodeByPath(QString::fromStdString(cmd.path())); if (toDelete) serverDirView->removeNode(toDelete); } diff --git a/cockatrice/src/tab_deck_storage.h b/cockatrice/src/tab_deck_storage.h index 758ed12b..ac579724 100644 --- a/cockatrice/src/tab_deck_storage.h +++ b/cockatrice/src/tab_deck_storage.h @@ -43,7 +43,8 @@ private slots: void newFolderFinished(ResponseCode resp); void actDelete(); - void deleteFinished(ResponseCode resp); + void deleteFolderFinished(ResponseCode resp); + void deleteDeckFinished(ResponseCode resp); public: TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client); void retranslateUi(); diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index ed3b046e..985f11f4 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -156,7 +156,7 @@ void DeckViewContainer::readyStart() { Command_ReadyStart cmd; cmd.set_ready(!readyStartButton->getReadyStart()); - static_cast(parent())->sendGameCommand(cmd); + static_cast(parent())->sendGameCommand(cmd, playerId); } void DeckViewContainer::sideboardPlanChanged() @@ -165,7 +165,7 @@ void DeckViewContainer::sideboardPlanChanged() QList newPlan = deckView->getSideboardPlan(); for (int i = 0; i < newPlan.size(); ++i) cmd.add_move_list()->CopyFrom(newPlan[i]->toPB()); - static_cast(parent())->sendGameCommand(cmd); + static_cast(parent())->sendGameCommand(cmd, playerId); } void DeckViewContainer::setReadyStart(bool ready) @@ -509,12 +509,6 @@ void TabGame::sendGameCommand(const google::protobuf::Message &command, int play client->sendCommand(prepareGameCommand(command)); } -void TabGame::sendCommandContainer(CommandContainer &cont, int playerId) -{ - cont.set_game_id(gameId); - getClientForPlayer(playerId)->sendCommand(cont); -} - PendingCommand *TabGame::prepareGameCommand(const ::google::protobuf::Message &cmd) { CommandContainer cont; diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index abd4913b..921ab821 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -183,7 +183,6 @@ public: public slots: void sendGameCommand(PendingCommand *pend, int playerId = -1); void sendGameCommand(const ::google::protobuf::Message &command, int playerId = -1); - void sendCommandContainer(CommandContainer &cont, int playerId = -1); }; #endif diff --git a/cockatrice/src/tab_room.cpp b/cockatrice/src/tab_room.cpp index 13768820..5fb15287 100644 --- a/cockatrice/src/tab_room.cpp +++ b/cockatrice/src/tab_room.cpp @@ -171,11 +171,7 @@ void TabRoom::processSayEvent(Event_RoomSay *event) PendingCommand *TabRoom::prepareRoomCommand(const ::google::protobuf::Message &cmd) { - CommandContainer cont; - RoomCommand *c = cont.add_room_command(); - cont.set_room_id(roomId); - c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); - return new PendingCommand(cont); + return client->prepareRoomCommand(cmd, roomId); } void TabRoom::sendRoomCommand(PendingCommand *pend) diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index 483e15c1..f290b47a 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -249,9 +249,9 @@ void TabSupervisor::localGameJoined(Event_GameJoined *event) setCurrentWidget(tab); for (int i = 1; i < localClients.size(); ++i) { -// Command_JoinGame *cmd = new Command_JoinGame(0, event->getGameId()); -// localClients[i]->sendCommand(cmd); - // XXX + Command_JoinGame cmd; + cmd.set_game_id(event->getGameId()); + localClients[i]->sendCommand(localClients[i]->prepareRoomCommand(cmd, 0)); } } diff --git a/cockatrice/src/tab_supervisor.h b/cockatrice/src/tab_supervisor.h index de05c58b..995ffe3c 100644 --- a/cockatrice/src/tab_supervisor.h +++ b/cockatrice/src/tab_supervisor.h @@ -60,6 +60,7 @@ public: int getGameCount() const { return gameTabs.size(); } TabUserLists *getUserListsTab() const { return tabUserLists; } ServerInfo_User *getUserInfo() const { return userInfo; } + const QMap &getRoomTabs() const { return roomTabs; } bool getAdminLocked() const; int getUserLevel() const; signals: diff --git a/cockatrice/src/userlist.cpp b/cockatrice/src/userlist.cpp index ddc760f0..89a09e47 100644 --- a/cockatrice/src/userlist.cpp +++ b/cockatrice/src/userlist.cpp @@ -296,10 +296,10 @@ void UserList::userClicked(QTreeWidgetItem *item, int /*column*/) void UserList::gamesOfUserReceived(ProtocolResponse *resp) { - //Command_GetGamesOfUser *command = static_cast(sender()); Response_GetGamesOfUser *response = qobject_cast(resp); if (!response) return; + const Command_GetGamesOfUser &cmd = static_cast(static_cast(sender())->getCommandContainer().session_command(0).GetExtension(Command_GetGamesOfUser::ext)); QMap gameTypeMap; QMap roomMap; @@ -318,7 +318,7 @@ void UserList::gamesOfUserReceived(ProtocolResponse *resp) for (int i = 0; i < gameList.size(); ++i) selector->processGameInfo(gameList[i]); -// selector->setWindowTitle(tr("%1's games").arg(command->getUserName())); + selector->setWindowTitle(tr("%1's games").arg(QString::fromStdString(cmd.user_name()))); selector->setAttribute(Qt::WA_DeleteOnClose); selector->show(); } diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 66c55d9b..7b53be12 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -36,6 +36,8 @@ #include "localserverinterface.h" #include "localclient.h" +#include "pb/room_commands.pb.h" + const QString MainWindow::appName = "Cockatrice"; void MainWindow::updateTabMenu(QMenu *menu) @@ -134,8 +136,9 @@ void MainWindow::actSinglePlayer() } tabSupervisor->startLocal(localClients); -// Command_CreateGame *createCommand = new Command_CreateGame(0, QString(), QString(), numberPlayers, QList(), false, false, false, false); -// mainClient->sendCommand(createCommand); + Command_CreateGame createCommand; + createCommand.set_max_players(numberPlayers); + mainClient->sendCommand(mainClient->prepareRoomCommand(createCommand, 0)); } void MainWindow::localGameEnded() diff --git a/common/protocol.cpp b/common/protocol.cpp index 716a1c30..03c663f6 100644 --- a/common/protocol.cpp +++ b/common/protocol.cpp @@ -28,18 +28,10 @@ void ProtocolItem::initializeHash() registerSerializableItem("player_ping", ServerInfo_PlayerPing::newItem); registerSerializableItem("file", DeckList_File::newItem); registerSerializableItem("directory", DeckList_Directory::newItem); -// registerSerializableItem("card_to_move", CardToMove::newItem); registerSerializableItem("game_type_id", GameTypeId::newItem); -// registerSerializableItem("containercmd", CommandContainer::newItem); registerSerializableItem("containergame_event", GameEventContainer::newItem); -/* - registerSerializableItem("cmdcreate_game", Command_CreateGame::newItem); - registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem); - registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem); - registerSerializableItem("cmdset_sideboard_plan", Command_SetSideboardPlan::newItem); - registerSerializableItem("cmdmove_card", Command_MoveCard::newItem); -*/ + registerSerializableItem("resp", ProtocolResponse::newItem); ProtocolResponse::initializeHash(); registerSerializableItem("respjoin_room", Response_JoinRoom::newItem); @@ -105,41 +97,6 @@ void TopLevelProtocolItem::writeElement(QXmlStreamWriter * /*xml*/) { } -/* -int CommandContainer::lastCmdId = 0; - -Command::Command(const QString &_itemName) - : ProtocolItem("cmd", _itemName) -{ -} - -void Command::processResponse(ProtocolResponse *response) -{ - emit finished(response); - emit finished(response->getResponseCode()); -} - -CommandContainer::CommandContainer(const QList &_commandList, int _cmdId) - : ProtocolItem("container", "cmd"), ticks(0), resp(0), gameEventQueuePublic(0), gameEventQueueOmniscient(0), gameEventQueuePrivate(0), privatePlayerId(-1) -{ - if (_cmdId == -1) - _cmdId = lastCmdId++; - insertItem(new SerializableItem_Int("cmd_id", _cmdId)); - - for (int i = 0; i < _commandList.size(); ++i) - itemList.append(_commandList[i]); -} - -void CommandContainer::processResponse(ProtocolResponse *response) -{ - emit finished(response); - emit finished(response->getResponseCode()); - - const QList &cmdList = getCommandList(); - for (int i = 0; i < cmdList.size(); ++i) - cmdList[i]->processResponse(response); -} -*/ BlaContainer::BlaContainer() : ProtocolItem("container", "cmd"), resp(0), gameEventQueuePublic(0), gameEventQueueOmniscient(0), gameEventQueuePrivate(0), privatePlayerId(-1) { @@ -178,77 +135,7 @@ void BlaContainer::enqueueGameEventPrivate(GameEvent *event, int gameId, int pla if (context) gameEventQueuePrivate->setContext(context); } -/* -Command_CreateGame::Command_CreateGame(int _roomId, const QString &_description, const QString &_password, int _maxPlayers, const QList &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything) - : RoomCommand("create_game", _roomId) -{ - insertItem(new SerializableItem_String("description", _description)); - insertItem(new SerializableItem_String("password", _password)); - insertItem(new SerializableItem_Int("max_players", _maxPlayers)); - insertItem(new SerializableItem_Bool("only_buddies", _onlyBuddies)); - insertItem(new SerializableItem_Bool("only_registered", _onlyRegistered)); - insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed)); - insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword)); - insertItem(new SerializableItem_Bool("spectators_can_talk", _spectatorsCanTalk)); - insertItem(new SerializableItem_Bool("spectators_see_everything", _spectatorsSeeEverything)); - - for (int i = 0; i < _gameTypes.size(); ++i) - itemList.append(_gameTypes[i]); -} -Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path) - : Command("deck_upload") -{ - insertItem(new SerializableItem_String("path", _path)); - if (!_deck) - _deck = new DeckList; - insertItem(_deck); -} - -DeckList *Command_DeckUpload::getDeck() const -{ - return static_cast(itemMap.value("cockatrice_deck")); -} - -Command_DeckSelect::Command_DeckSelect(int _gameId, DeckList *_deck, int _deckId) - : GameCommand("deck_select", _gameId) -{ - insertItem(new SerializableItem_Int("deck_id", _deckId)); - if (!_deck) - _deck = new DeckList; - insertItem(_deck); -} - -DeckList *Command_DeckSelect::getDeck() const -{ - return static_cast(itemMap.value("cockatrice_deck")); -} - -Command_SetSideboardPlan::Command_SetSideboardPlan(int _gameId, const QList &_moveList) - : GameCommand("set_sideboard_plan", _gameId) -{ - for (int i = 0; i < _moveList.size(); ++i) - itemList.append(_moveList[i]); -} - -QList Command_SetSideboardPlan::getMoveList() const -{ - return typecastItemList(); -} - -Command_MoveCard::Command_MoveCard(int _gameId, const QString &_startZone, const QList &_cards, int _targetPlayerId, const QString &_targetZone, int _x, int _y) - : GameCommand("move_card", _gameId) -{ - insertItem(new SerializableItem_String("start_zone", _startZone)); - insertItem(new SerializableItem_Int("target_player_id", _targetPlayerId)); - insertItem(new SerializableItem_String("target_zone", _targetZone)); - insertItem(new SerializableItem_Int("x", _x)); - insertItem(new SerializableItem_Int("y", _y)); - - for (int i = 0; i < _cards.size(); ++i) - itemList.append(_cards[i]); -} -*/ QHash ProtocolResponse::responseHash; ProtocolResponse::ProtocolResponse(int _cmdId, ResponseCode _responseCode, const QString &_itemName) diff --git a/common/protocol.h b/common/protocol.h index db9b3ae0..b7b9696a 100644 --- a/common/protocol.h +++ b/common/protocol.h @@ -91,21 +91,7 @@ public: // ---------------- // --- COMMANDS --- // ---------------- -/* -class Command : public ProtocolItem { - Q_OBJECT -signals: - void finished(ProtocolResponse *response); - void finished(ResponseCode response); -private: - QVariant extraData; -public: - Command(const QString &_itemName = QString()); - void setExtraData(const QVariant &_extraData) { extraData = _extraData; } - QVariant getExtraData() const { return extraData; } - void processResponse(ProtocolResponse *response); -}; -*/ + class BlaContainer : public ProtocolItem { Q_OBJECT private: @@ -132,91 +118,7 @@ public: void enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId = -1, GameEventContext *context = 0); int getPrivatePlayerId() const { return privatePlayerId; } }; -/* -class RoomCommand : public Command { - Q_OBJECT -public: - RoomCommand(const QString &_cmdName, int _roomId) - : Command(_cmdName) - { - insertItem(new SerializableItem_Int("room_id", _roomId)); - } - int getRoomId() const { return static_cast(itemMap.value("room_id"))->getData(); } -}; -class GameCommand : public Command { - Q_OBJECT -public: - GameCommand(const QString &_cmdName, int _gameId) - : Command(_cmdName) - { - insertItem(new SerializableItem_Int("game_id", _gameId)); - } - int getGameId() const { return static_cast(itemMap.value("game_id"))->getData(); } - void setGameId(int _gameId) { static_cast(itemMap.value("game_id"))->setData(_gameId); } -}; - -class ModeratorCommand : public Command { - Q_OBJECT -public: - ModeratorCommand(const QString &_cmdName) - : Command(_cmdName) - { - } -}; - -class AdminCommand : public Command { - Q_OBJECT -public: - AdminCommand(const QString &_cmdName) - : Command(_cmdName) - { - } -}; - -class Command_DeckUpload : public Command { - Q_OBJECT -public: - Command_DeckUpload(DeckList *_deck = 0, const QString &_path = QString()); - static SerializableItem *newItem() { return new Command_DeckUpload; } - int getItemId() const { return ItemId_Command_DeckUpload; } - DeckList *getDeck() const; - QString getPath() const { return static_cast(itemMap.value("path"))->getData(); } -}; - -class Command_DeckSelect : public GameCommand { - Q_OBJECT -public: - Command_DeckSelect(int _gameId = -1, DeckList *_deck = 0, int _deckId = -1); - static SerializableItem *newItem() { return new Command_DeckSelect; } - int getItemId() const { return ItemId_Command_DeckSelect; } - DeckList *getDeck() const; - int getDeckId() const { return static_cast(itemMap.value("deck_id"))->getData(); } -}; - -class Command_SetSideboardPlan : public GameCommand { - Q_OBJECT -public: - Command_SetSideboardPlan(int _gameId = -1, const QList &_moveList = QList()); - static SerializableItem *newItem() { return new Command_SetSideboardPlan; } - int getItemId() const { return ItemId_Command_SetSideboardPlan; } - QList getMoveList() const; -}; - -class Command_MoveCard : public GameCommand { - Q_OBJECT -public: - Command_MoveCard(int _gameId = -1, const QString &_startZone = QString(), const QList &_cards = QList(), int _targetPlayerId = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1); - QString getStartZone() const { return static_cast(itemMap.value("start_zone"))->getData(); } - QList getCards() const { return typecastItemList(); } - int getTargetPlayerId() const { return static_cast(itemMap.value("target_player_id"))->getData(); } - QString getTargetZone() const { return static_cast(itemMap.value("target_zone"))->getData(); } - int getX() const { return static_cast(itemMap.value("x"))->getData(); } - int getY() const { return static_cast(itemMap.value("y"))->getData(); } - static SerializableItem *newItem() { return new Command_MoveCard; } - int getItemId() const { return ItemId_Command_MoveCard; } -}; -*/ // ----------------- // --- RESPONSES --- // ----------------- @@ -231,6 +133,7 @@ public: static void initializeHash(); static SerializableItem *newItem() { return new ProtocolResponse; } int getCmdId() const { return static_cast(itemMap.value("cmd_id"))->getData(); } + void setCmdId(int _cmdId) { static_cast(itemMap.value("cmd_id"))->setData(_cmdId); } ResponseCode getResponseCode() const { return responseHash.value(static_cast(itemMap.value("response_code"))->getData(), RespOk); } }; diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 3c82ca68..9c6a6ebe 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -107,12 +107,12 @@ void Server_ProtocolHandler::playerRemovedFromGame(Server_Game *game) games.remove(game->getGameId()); } -ResponseCode Server_ProtocolHandler::processSessionCommandContainer(CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::processSessionCommandContainer(const CommandContainer &cont, BlaContainer *bla) { ResponseCode finalResponseCode = RespOk; - for (int i = cont->session_command_size() - 1; i >= 0; --i) { + for (int i = cont.session_command_size() - 1; i >= 0; --i) { ResponseCode resp = RespInvalidCommand; - const SessionCommand &sc = cont->session_command(i); + const SessionCommand &sc = cont.session_command(i); std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; sc.GetReflection()->ListFields(sc, &fieldList); int num = 0; @@ -122,22 +122,22 @@ ResponseCode Server_ProtocolHandler::processSessionCommandContainer(CommandConta break; } switch ((SessionCommand::SessionCommandType) num) { - case SessionCommand::PING: resp = cmdPing(sc.GetExtension(Command_Ping::ext), cont); break; - case SessionCommand::LOGIN: resp = cmdLogin(sc.GetExtension(Command_Login::ext), cont, bla); break; - case SessionCommand::MESSAGE: resp = cmdMessage(sc.GetExtension(Command_Message::ext), cont, bla); break; - case SessionCommand::ADD_TO_LIST: resp = cmdAddToList(sc.GetExtension(Command_AddToList::ext), cont); break; - case SessionCommand::REMOVE_FROM_LIST: resp = cmdRemoveFromList(sc.GetExtension(Command_RemoveFromList::ext), cont); break; - case SessionCommand::DECK_LIST: resp = cmdDeckList(sc.GetExtension(Command_DeckList::ext), cont); break; - case SessionCommand::DECK_NEW_DIR: resp = cmdDeckNewDir(sc.GetExtension(Command_DeckNewDir::ext), cont); break; - case SessionCommand::DECK_DEL_DIR: resp = cmdDeckDelDir(sc.GetExtension(Command_DeckDelDir::ext), cont); break; - case SessionCommand::DECK_DEL: resp = cmdDeckDel(sc.GetExtension(Command_DeckDel::ext), cont); break; - case SessionCommand::DECK_UPLOAD: resp = cmdDeckUpload(sc.GetExtension(Command_DeckUpload::ext), cont); break; - case SessionCommand::DECK_DOWNLOAD: resp = cmdDeckDownload(sc.GetExtension(Command_DeckDownload::ext), cont); break; - case SessionCommand::GET_GAMES_OF_USER: resp = cmdGetGamesOfUser(sc.GetExtension(Command_GetGamesOfUser::ext), cont, bla); break; - case SessionCommand::GET_USER_INFO: resp = cmdGetUserInfo(sc.GetExtension(Command_GetUserInfo::ext), cont, bla); break; - case SessionCommand::LIST_ROOMS: resp = cmdListRooms(sc.GetExtension(Command_ListRooms::ext), cont, bla); break; - case SessionCommand::JOIN_ROOM: resp = cmdJoinRoom(sc.GetExtension(Command_JoinRoom::ext), cont, bla); break; - case SessionCommand::LIST_USERS: resp = cmdListUsers(sc.GetExtension(Command_ListUsers::ext), cont, bla); break; + case SessionCommand::PING: resp = cmdPing(sc.GetExtension(Command_Ping::ext)); break; + case SessionCommand::LOGIN: resp = cmdLogin(sc.GetExtension(Command_Login::ext), bla); break; + case SessionCommand::MESSAGE: resp = cmdMessage(sc.GetExtension(Command_Message::ext), bla); break; + case SessionCommand::ADD_TO_LIST: resp = cmdAddToList(sc.GetExtension(Command_AddToList::ext), bla); break; + case SessionCommand::REMOVE_FROM_LIST: resp = cmdRemoveFromList(sc.GetExtension(Command_RemoveFromList::ext), bla); break; + case SessionCommand::DECK_LIST: resp = cmdDeckList(sc.GetExtension(Command_DeckList::ext), bla); break; + case SessionCommand::DECK_NEW_DIR: resp = cmdDeckNewDir(sc.GetExtension(Command_DeckNewDir::ext), bla); break; + case SessionCommand::DECK_DEL_DIR: resp = cmdDeckDelDir(sc.GetExtension(Command_DeckDelDir::ext), bla); break; + case SessionCommand::DECK_DEL: resp = cmdDeckDel(sc.GetExtension(Command_DeckDel::ext), bla); break; + case SessionCommand::DECK_UPLOAD: resp = cmdDeckUpload(sc.GetExtension(Command_DeckUpload::ext), bla); break; + case SessionCommand::DECK_DOWNLOAD: resp = cmdDeckDownload(sc.GetExtension(Command_DeckDownload::ext), bla); break; + case SessionCommand::GET_GAMES_OF_USER: resp = cmdGetGamesOfUser(sc.GetExtension(Command_GetGamesOfUser::ext), bla); break; + case SessionCommand::GET_USER_INFO: resp = cmdGetUserInfo(sc.GetExtension(Command_GetUserInfo::ext), bla); break; + case SessionCommand::LIST_ROOMS: resp = cmdListRooms(sc.GetExtension(Command_ListRooms::ext), bla); break; + case SessionCommand::JOIN_ROOM: resp = cmdJoinRoom(sc.GetExtension(Command_JoinRoom::ext), bla); break; + case SessionCommand::LIST_USERS: resp = cmdListUsers(sc.GetExtension(Command_ListUsers::ext), bla); break; } if ((resp != RespOk) && (resp != RespNothing)) finalResponseCode = resp; @@ -145,21 +145,21 @@ ResponseCode Server_ProtocolHandler::processSessionCommandContainer(CommandConta return finalResponseCode; } -ResponseCode Server_ProtocolHandler::processRoomCommandContainer(CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::processRoomCommandContainer(const CommandContainer &cont, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; - Server_Room *room = rooms.value(cont->room_id(), 0); + Server_Room *room = rooms.value(cont.room_id(), 0); if (!room) return RespNotInRoom; QMutexLocker locker(&room->roomMutex); ResponseCode finalResponseCode = RespOk; - for (int i = cont->room_command_size() - 1; i >= 0; --i) { + for (int i = cont.room_command_size() - 1; i >= 0; --i) { ResponseCode resp = RespInvalidCommand; - const RoomCommand &sc = cont->room_command(i); + const RoomCommand &sc = cont.room_command(i); std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; sc.GetReflection()->ListFields(sc, &fieldList); int num = 0; @@ -169,10 +169,10 @@ ResponseCode Server_ProtocolHandler::processRoomCommandContainer(CommandContaine break; } switch ((RoomCommand::RoomCommandType) num) { - case RoomCommand::LEAVE_ROOM: resp = cmdLeaveRoom(sc.GetExtension(Command_LeaveRoom::ext), cont, room); break; - case RoomCommand::ROOM_SAY: resp = cmdRoomSay(sc.GetExtension(Command_RoomSay::ext), cont, room); break; - case RoomCommand::CREATE_GAME: resp = cmdCreateGame(sc.GetExtension(Command_CreateGame::ext), cont, room); break; - case RoomCommand::JOIN_GAME: resp = cmdJoinGame(sc.GetExtension(Command_JoinGame::ext), cont, room); break; + case RoomCommand::LEAVE_ROOM: resp = cmdLeaveRoom(sc.GetExtension(Command_LeaveRoom::ext), room); break; + case RoomCommand::ROOM_SAY: resp = cmdRoomSay(sc.GetExtension(Command_RoomSay::ext), room); break; + case RoomCommand::CREATE_GAME: resp = cmdCreateGame(sc.GetExtension(Command_CreateGame::ext), room); break; + case RoomCommand::JOIN_GAME: resp = cmdJoinGame(sc.GetExtension(Command_JoinGame::ext), room); break; } if ((resp != RespOk) && (resp != RespNothing)) finalResponseCode = resp; @@ -180,17 +180,17 @@ ResponseCode Server_ProtocolHandler::processRoomCommandContainer(CommandContaine return finalResponseCode; } -ResponseCode Server_ProtocolHandler::processGameCommandContainer(CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::processGameCommandContainer(const CommandContainer &cont, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; gameListMutex.lock(); - if (!games.contains(cont->game_id())) { + if (!games.contains(cont.game_id())) { qDebug() << "invalid game"; return RespNotInRoom; } - QPair gamePair = games.value(cont->game_id()); + QPair gamePair = games.value(cont.game_id()); Server_Game *game = gamePair.first; Server_Player *player = gamePair.second; @@ -198,9 +198,9 @@ ResponseCode Server_ProtocolHandler::processGameCommandContainer(CommandContaine gameListMutex.unlock(); ResponseCode finalResponseCode = RespOk; - for (int i = cont->game_command_size() - 1; i >= 0; --i) { + for (int i = cont.game_command_size() - 1; i >= 0; --i) { ResponseCode resp = RespInvalidCommand; - const GameCommand &sc = cont->game_command(i); + const GameCommand &sc = cont.game_command(i); std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; sc.GetReflection()->ListFields(sc, &fieldList); int num = 0; @@ -210,36 +210,36 @@ ResponseCode Server_ProtocolHandler::processGameCommandContainer(CommandContaine break; } switch ((GameCommand::GameCommandType) num) { - case GameCommand::KICK_FROM_GAME: resp = cmdKickFromGame(sc.GetExtension(Command_KickFromGame::ext), cont, game, player, bla); break; - case GameCommand::LEAVE_GAME: resp = cmdLeaveGame(sc.GetExtension(Command_LeaveGame::ext), cont, game, player, bla); break; - case GameCommand::GAME_SAY: resp = cmdGameSay(sc.GetExtension(Command_GameSay::ext), cont, game, player, bla); break; - case GameCommand::SHUFFLE: resp = cmdShuffle(sc.GetExtension(Command_Shuffle::ext), cont, game, player, bla); break; - case GameCommand::MULLIGAN: resp = cmdMulligan(sc.GetExtension(Command_Mulligan::ext), cont, game, player, bla); break; - case GameCommand::ROLL_DIE: resp = cmdRollDie(sc.GetExtension(Command_RollDie::ext), cont, game, player, bla); break; - case GameCommand::DRAW_CARDS: resp = cmdDrawCards(sc.GetExtension(Command_DrawCards::ext), cont, game, player, bla); break; - case GameCommand::UNDO_DRAW: resp = cmdUndoDraw(sc.GetExtension(Command_UndoDraw::ext), cont, game, player, bla); break; - case GameCommand::FLIP_CARD: resp = cmdFlipCard(sc.GetExtension(Command_FlipCard::ext), cont, game, player, bla); break; - case GameCommand::ATTACH_CARD: resp = cmdAttachCard(sc.GetExtension(Command_AttachCard::ext), cont, game, player, bla); break; - case GameCommand::CREATE_TOKEN: resp = cmdCreateToken(sc.GetExtension(Command_CreateToken::ext), cont, game, player, bla); break; - case GameCommand::CREATE_ARROW: resp = cmdCreateArrow(sc.GetExtension(Command_CreateArrow::ext), cont, game, player, bla); break; - case GameCommand::DELETE_ARROW: resp = cmdDeleteArrow(sc.GetExtension(Command_DeleteArrow::ext), cont, game, player, bla); break; - case GameCommand::SET_CARD_ATTR: resp = cmdSetCardAttr(sc.GetExtension(Command_SetCardAttr::ext), cont, game, player, bla); break; - case GameCommand::SET_CARD_COUNTER: resp = cmdSetCardCounter(sc.GetExtension(Command_SetCardCounter::ext), cont, game, player, bla); break; - case GameCommand::INC_CARD_COUNTER: resp = cmdIncCardCounter(sc.GetExtension(Command_IncCardCounter::ext), cont, game, player, bla); break; - case GameCommand::READY_START: resp = cmdReadyStart(sc.GetExtension(Command_ReadyStart::ext), cont, game, player, bla); break; - case GameCommand::CONCEDE: resp = cmdConcede(sc.GetExtension(Command_Concede::ext), cont, game, player, bla); break; - case GameCommand::INC_COUNTER: resp = cmdIncCounter(sc.GetExtension(Command_IncCounter::ext), cont, game, player, bla); break; - case GameCommand::CREATE_COUNTER: resp = cmdCreateCounter(sc.GetExtension(Command_CreateCounter::ext), cont, game, player, bla); break; - case GameCommand::SET_COUNTER: resp = cmdSetCounter(sc.GetExtension(Command_SetCounter::ext), cont, game, player, bla); break; - case GameCommand::DEL_COUNTER: resp = cmdDelCounter(sc.GetExtension(Command_DelCounter::ext), cont, game, player, bla); break; - case GameCommand::NEXT_TURN: resp = cmdNextTurn(sc.GetExtension(Command_NextTurn::ext), cont, game, player, bla); break; - case GameCommand::SET_ACTIVE_PHASE: resp = cmdSetActivePhase(sc.GetExtension(Command_SetActivePhase::ext), cont, game, player, bla); break; - case GameCommand::DUMP_ZONE: resp = cmdDumpZone(sc.GetExtension(Command_DumpZone::ext), cont, game, player, bla); break; - case GameCommand::STOP_DUMP_ZONE: resp = cmdStopDumpZone(sc.GetExtension(Command_StopDumpZone::ext), cont, game, player, bla); break; - case GameCommand::REVEAL_CARDS: resp = cmdRevealCards(sc.GetExtension(Command_RevealCards::ext), cont, game, player, bla); break; - case GameCommand::MOVE_CARD: resp = cmdMoveCard(sc.GetExtension(Command_MoveCard::ext), cont, game, player, bla); break; - case GameCommand::SET_SIDEBOARD_PLAN: resp = cmdSetSideboardPlan(sc.GetExtension(Command_SetSideboardPlan::ext), cont, game, player, bla); break; - case GameCommand::DECK_SELECT: resp = cmdDeckSelect(sc.GetExtension(Command_DeckSelect::ext), cont, game, player, bla); break; + case GameCommand::KICK_FROM_GAME: resp = cmdKickFromGame(sc.GetExtension(Command_KickFromGame::ext), game, player, bla); break; + case GameCommand::LEAVE_GAME: resp = cmdLeaveGame(sc.GetExtension(Command_LeaveGame::ext), game, player, bla); break; + case GameCommand::GAME_SAY: resp = cmdGameSay(sc.GetExtension(Command_GameSay::ext), game, player, bla); break; + case GameCommand::SHUFFLE: resp = cmdShuffle(sc.GetExtension(Command_Shuffle::ext), game, player, bla); break; + case GameCommand::MULLIGAN: resp = cmdMulligan(sc.GetExtension(Command_Mulligan::ext), game, player, bla); break; + case GameCommand::ROLL_DIE: resp = cmdRollDie(sc.GetExtension(Command_RollDie::ext), game, player, bla); break; + case GameCommand::DRAW_CARDS: resp = cmdDrawCards(sc.GetExtension(Command_DrawCards::ext), game, player, bla); break; + case GameCommand::UNDO_DRAW: resp = cmdUndoDraw(sc.GetExtension(Command_UndoDraw::ext), game, player, bla); break; + case GameCommand::FLIP_CARD: resp = cmdFlipCard(sc.GetExtension(Command_FlipCard::ext), game, player, bla); break; + case GameCommand::ATTACH_CARD: resp = cmdAttachCard(sc.GetExtension(Command_AttachCard::ext), game, player, bla); break; + case GameCommand::CREATE_TOKEN: resp = cmdCreateToken(sc.GetExtension(Command_CreateToken::ext), game, player, bla); break; + case GameCommand::CREATE_ARROW: resp = cmdCreateArrow(sc.GetExtension(Command_CreateArrow::ext), game, player, bla); break; + case GameCommand::DELETE_ARROW: resp = cmdDeleteArrow(sc.GetExtension(Command_DeleteArrow::ext), game, player, bla); break; + case GameCommand::SET_CARD_ATTR: resp = cmdSetCardAttr(sc.GetExtension(Command_SetCardAttr::ext), game, player, bla); break; + case GameCommand::SET_CARD_COUNTER: resp = cmdSetCardCounter(sc.GetExtension(Command_SetCardCounter::ext), game, player, bla); break; + case GameCommand::INC_CARD_COUNTER: resp = cmdIncCardCounter(sc.GetExtension(Command_IncCardCounter::ext), game, player, bla); break; + case GameCommand::READY_START: resp = cmdReadyStart(sc.GetExtension(Command_ReadyStart::ext), game, player, bla); break; + case GameCommand::CONCEDE: resp = cmdConcede(sc.GetExtension(Command_Concede::ext), game, player, bla); break; + case GameCommand::INC_COUNTER: resp = cmdIncCounter(sc.GetExtension(Command_IncCounter::ext), game, player, bla); break; + case GameCommand::CREATE_COUNTER: resp = cmdCreateCounter(sc.GetExtension(Command_CreateCounter::ext), game, player, bla); break; + case GameCommand::SET_COUNTER: resp = cmdSetCounter(sc.GetExtension(Command_SetCounter::ext), game, player, bla); break; + case GameCommand::DEL_COUNTER: resp = cmdDelCounter(sc.GetExtension(Command_DelCounter::ext), game, player, bla); break; + case GameCommand::NEXT_TURN: resp = cmdNextTurn(sc.GetExtension(Command_NextTurn::ext), game, player, bla); break; + case GameCommand::SET_ACTIVE_PHASE: resp = cmdSetActivePhase(sc.GetExtension(Command_SetActivePhase::ext), game, player, bla); break; + case GameCommand::DUMP_ZONE: resp = cmdDumpZone(sc.GetExtension(Command_DumpZone::ext), game, player, bla); break; + case GameCommand::STOP_DUMP_ZONE: resp = cmdStopDumpZone(sc.GetExtension(Command_StopDumpZone::ext), game, player, bla); break; + case GameCommand::REVEAL_CARDS: resp = cmdRevealCards(sc.GetExtension(Command_RevealCards::ext), game, player, bla); break; + case GameCommand::MOVE_CARD: resp = cmdMoveCard(sc.GetExtension(Command_MoveCard::ext), game, player, bla); break; + case GameCommand::SET_SIDEBOARD_PLAN: resp = cmdSetSideboardPlan(sc.GetExtension(Command_SetSideboardPlan::ext), game, player, bla); break; + case GameCommand::DECK_SELECT: resp = cmdDeckSelect(sc.GetExtension(Command_DeckSelect::ext), game, player, bla); break; } if ((resp != RespOk) && (resp != RespNothing)) finalResponseCode = resp; @@ -247,7 +247,7 @@ ResponseCode Server_ProtocolHandler::processGameCommandContainer(CommandContaine return finalResponseCode; } -ResponseCode Server_ProtocolHandler::processModeratorCommandContainer(CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::processModeratorCommandContainer(const CommandContainer &cont, BlaContainer *bla) { if (!userInfo) return RespLoginNeeded; @@ -255,9 +255,9 @@ ResponseCode Server_ProtocolHandler::processModeratorCommandContainer(CommandCon return RespLoginNeeded; ResponseCode finalResponseCode = RespOk; - for (int i = cont->moderator_command_size() - 1; i >= 0; --i) { + for (int i = cont.moderator_command_size() - 1; i >= 0; --i) { ResponseCode resp = RespInvalidCommand; - const ModeratorCommand &sc = cont->moderator_command(i); + const ModeratorCommand &sc = cont.moderator_command(i); std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; sc.GetReflection()->ListFields(sc, &fieldList); int num = 0; @@ -267,7 +267,7 @@ ResponseCode Server_ProtocolHandler::processModeratorCommandContainer(CommandCon break; } switch ((ModeratorCommand::ModeratorCommandType) num) { - case ModeratorCommand::BAN_FROM_SERVER: resp = cmdBanFromServer(sc.GetExtension(Command_BanFromServer::ext), cont); break; + case ModeratorCommand::BAN_FROM_SERVER: resp = cmdBanFromServer(sc.GetExtension(Command_BanFromServer::ext), bla); break; } if ((resp != RespOk) && (resp != RespNothing)) finalResponseCode = resp; @@ -275,7 +275,7 @@ ResponseCode Server_ProtocolHandler::processModeratorCommandContainer(CommandCon return finalResponseCode; } -ResponseCode Server_ProtocolHandler::processAdminCommandContainer(CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::processAdminCommandContainer(const CommandContainer &cont, BlaContainer *bla) { if (!userInfo) return RespLoginNeeded; @@ -283,9 +283,9 @@ ResponseCode Server_ProtocolHandler::processAdminCommandContainer(CommandContain return RespLoginNeeded; ResponseCode finalResponseCode = RespOk; - for (int i = cont->admin_command_size() - 1; i >= 0; --i) { + for (int i = cont.admin_command_size() - 1; i >= 0; --i) { ResponseCode resp = RespInvalidCommand; - const AdminCommand &sc = cont->admin_command(i); + const AdminCommand &sc = cont.admin_command(i); std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; sc.GetReflection()->ListFields(sc, &fieldList); int num = 0; @@ -295,8 +295,8 @@ ResponseCode Server_ProtocolHandler::processAdminCommandContainer(CommandContain break; } switch ((AdminCommand::AdminCommandType) num) { - case AdminCommand::SHUTDOWN_SERVER: resp = cmdShutdownServer(sc.GetExtension(Command_ShutdownServer::ext), cont); break; - case AdminCommand::UPDATE_SERVER_MESSAGE: resp = cmdUpdateServerMessage(sc.GetExtension(Command_UpdateServerMessage::ext), cont); break; + case AdminCommand::SHUTDOWN_SERVER: resp = cmdShutdownServer(sc.GetExtension(Command_ShutdownServer::ext), bla); break; + case AdminCommand::UPDATE_SERVER_MESSAGE: resp = cmdUpdateServerMessage(sc.GetExtension(Command_UpdateServerMessage::ext), bla); break; } if ((resp != RespOk) && (resp != RespNothing)) finalResponseCode = resp; @@ -304,28 +304,31 @@ ResponseCode Server_ProtocolHandler::processAdminCommandContainer(CommandContain return finalResponseCode; } -void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont) +void Server_ProtocolHandler::processCommandContainer(const CommandContainer &cont) { lastDataReceived = timeRunning; BlaContainer *bla = new BlaContainer; ResponseCode finalResponseCode; - if (cont->game_command_size()) { + if (cont.game_command_size()) finalResponseCode = processGameCommandContainer(cont, bla); - } else if (cont->room_command_size()) { + else if (cont.room_command_size()) finalResponseCode = processRoomCommandContainer(cont, bla); - } else if (cont->session_command_size()) { + else if (cont.session_command_size()) finalResponseCode = processSessionCommandContainer(cont, bla); - } else if (cont->moderator_command_size()) { + else if (cont.moderator_command_size()) finalResponseCode = processModeratorCommandContainer(cont, bla); - } else if (cont->admin_command_size()) { + else if (cont.admin_command_size()) finalResponseCode = processAdminCommandContainer(cont, bla); - } + else + finalResponseCode = RespInvalidCommand; ProtocolResponse *pr = bla->getResponse(); if (!pr) - pr = new ProtocolResponse(cont->cmd_id(), finalResponseCode); + pr = new ProtocolResponse(cont.cmd_id(), finalResponseCode); + else + pr->setCmdId(cont.cmd_id()); gameListMutex.lock(); GameEventContainer *gQPublic = bla->getGameEventQueuePublic(); @@ -361,9 +364,6 @@ void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont) while (!itemQueue.isEmpty()) sendProtocolItem(itemQueue.takeFirst()); - -// if (cont->getReceiverMayDelete()) - delete cont; } void Server_ProtocolHandler::pingClockTimeout() @@ -395,12 +395,12 @@ QPair Server_ProtocolHandler::getGame(int gameId return QPair(0, 0); } -ResponseCode Server_ProtocolHandler::cmdPing(const Command_Ping & /*cmd*/, CommandContainer * /*cont*/) +ResponseCode Server_ProtocolHandler::cmdPing(const Command_Ping & /*cmd*/) { return RespOk; } -ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd, CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd, BlaContainer *bla) { QString userName = QString::fromStdString(cmd.user_name()).simplified(); if (userName.isEmpty() || (userInfo != 0)) @@ -460,14 +460,14 @@ ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd, CommandC } server->serverMutex.unlock(); - ProtocolResponse *resp = new Response_Login(cont->cmd_id(), RespOk, new ServerInfo_User(userInfo, true), _buddyList, _ignoreList); + ProtocolResponse *resp = new Response_Login(-1, RespOk, new ServerInfo_User(userInfo, true), _buddyList, _ignoreList); if (getCompressionSupport()) resp->setCompressed(true); bla->setResponse(resp); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdMessage(const Command_Message &cmd, CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdMessage(const Command_Message &cmd, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -486,7 +486,7 @@ ResponseCode Server_ProtocolHandler::cmdMessage(const Command_Message &cmd, Comm return RespOk; } -ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -507,14 +507,14 @@ ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(const Command_GetGamesOfU } server->serverMutex.unlock(); - ProtocolResponse *resp = new Response_GetGamesOfUser(cont->cmd_id(), RespOk, roomList, gameList); + ProtocolResponse *resp = new Response_GetGamesOfUser(-1, RespOk, roomList, gameList); if (getCompressionSupport()) resp->setCompressed(true); bla->setResponse(resp); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdGetUserInfo(const Command_GetUserInfo &cmd, CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdGetUserInfo(const Command_GetUserInfo &cmd, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -530,11 +530,11 @@ ResponseCode Server_ProtocolHandler::cmdGetUserInfo(const Command_GetUserInfo &c result = new ServerInfo_User(handler->getUserInfo(), true, userInfo->getUserLevel() & ServerInfo_User::IsModerator); } - bla->setResponse(new Response_GetUserInfo(cont->cmd_id(), RespOk, result)); + bla->setResponse(new Response_GetUserInfo(-1, RespOk, result)); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdListRooms(const Command_ListRooms & /*cmd*/, CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdListRooms(const Command_ListRooms & /*cmd*/, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -549,7 +549,7 @@ ResponseCode Server_ProtocolHandler::cmdListRooms(const Command_ListRooms & /*cm return RespOk; } -ResponseCode Server_ProtocolHandler::cmdJoinRoom(const Command_JoinRoom &cmd, CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdJoinRoom(const Command_JoinRoom &cmd, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -571,11 +571,11 @@ ResponseCode Server_ProtocolHandler::cmdJoinRoom(const Command_JoinRoom &cmd, Co ServerInfo_Room *info = r->getInfo(true); if (getCompressionSupport()) info->setCompressed(true); - bla->setResponse(new Response_JoinRoom(cont->cmd_id(), RespOk, info)); + bla->setResponse(new Response_JoinRoom(-1, RespOk, info)); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdListUsers(const Command_ListUsers & /*cmd*/, CommandContainer *cont, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdListUsers(const Command_ListUsers & /*cmd*/, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -587,21 +587,21 @@ ResponseCode Server_ProtocolHandler::cmdListUsers(const Command_ListUsers & /*cm acceptsUserListChanges = true; - ProtocolResponse *resp = new Response_ListUsers(cont->cmd_id(), RespOk, resultList); + ProtocolResponse *resp = new Response_ListUsers(-1, RespOk, resultList); if (getCompressionSupport()) resp->setCompressed(true); bla->setResponse(resp); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdLeaveRoom(const Command_LeaveRoom & /*cmd*/, CommandContainer * /*cont*/, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdLeaveRoom(const Command_LeaveRoom & /*cmd*/, Server_Room *room) { rooms.remove(room->getId()); room->removeClient(this); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdRoomSay(const Command_RoomSay &cmd, CommandContainer * /*cont*/, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdRoomSay(const Command_RoomSay &cmd, Server_Room *room) { QString msg = QString::fromStdString(cmd.message()); @@ -628,7 +628,7 @@ ResponseCode Server_ProtocolHandler::cmdRoomSay(const Command_RoomSay &cmd, Comm return RespOk; } -ResponseCode Server_ProtocolHandler::cmdCreateGame(const Command_CreateGame &cmd, CommandContainer * /*cont*/, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdCreateGame(const Command_CreateGame &cmd, Server_Room *room) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -659,7 +659,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(const Command_CreateGame &cmd return RespOk; } -ResponseCode Server_ProtocolHandler::cmdJoinGame(const Command_JoinGame &cmd, CommandContainer * /*cont*/, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdJoinGame(const Command_JoinGame &cmd, Server_Room *room) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -685,13 +685,13 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(const Command_JoinGame &cmd, Co return result; } -ResponseCode Server_ProtocolHandler::cmdLeaveGame(const Command_LeaveGame & /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdLeaveGame(const Command_LeaveGame & /*cmd*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { game->removePlayer(player); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdKickFromGame(const Command_KickFromGame &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdKickFromGame(const Command_KickFromGame &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if ((game->getHostId() != player->getPlayerId()) && !(userInfo->getUserLevel() & ServerInfo_User::IsModerator)) return RespFunctionNotAllowed; @@ -702,7 +702,7 @@ ResponseCode Server_ProtocolHandler::cmdKickFromGame(const Command_KickFromGame return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDeckSelect(const Command_DeckSelect &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdDeckSelect(const Command_DeckSelect &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -721,11 +721,11 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(const Command_DeckSelect &cmd game->sendGameEvent(new Event_PlayerPropertiesChanged(player->getPlayerId(), player->getProperties()), new Context_DeckSelect(deck->getDeckHash())); - bla->setResponse(new Response_DeckDownload(cont->cmd_id(), RespOk, new DeckList(deck))); + bla->setResponse(new Response_DeckDownload(-1, RespOk, new DeckList(deck))); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -748,7 +748,7 @@ ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(const Command_SetSidebo return RespOk; } -ResponseCode Server_ProtocolHandler::cmdConcede(const Command_Concede & /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdConcede(const Command_Concede & /*cmd*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -768,7 +768,7 @@ ResponseCode Server_ProtocolHandler::cmdConcede(const Command_Concede & /*cmd*/, return RespOk; } -ResponseCode Server_ProtocolHandler::cmdReadyStart(const Command_ReadyStart &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdReadyStart(const Command_ReadyStart &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -785,7 +785,7 @@ ResponseCode Server_ProtocolHandler::cmdReadyStart(const Command_ReadyStart &cmd return RespOk; } -ResponseCode Server_ProtocolHandler::cmdGameSay(const Command_GameSay &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdGameSay(const Command_GameSay &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator() && !game->getSpectatorsCanTalk() && !(userInfo->getUserLevel() & ServerInfo_User::IsModerator)) return RespFunctionNotAllowed; @@ -794,7 +794,7 @@ ResponseCode Server_ProtocolHandler::cmdGameSay(const Command_GameSay &cmd, Comm return RespOk; } -ResponseCode Server_ProtocolHandler::cmdShuffle(const Command_Shuffle & /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdShuffle(const Command_Shuffle & /*cmd*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -809,7 +809,7 @@ ResponseCode Server_ProtocolHandler::cmdShuffle(const Command_Shuffle & /*cmd*/, return RespOk; } -ResponseCode Server_ProtocolHandler::cmdMulligan(const Command_Mulligan & /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdMulligan(const Command_Mulligan & /*cmd*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -846,7 +846,7 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(const Command_Mulligan & /*cmd* return RespOk; } -ResponseCode Server_ProtocolHandler::cmdRollDie(const Command_RollDie &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdRollDie(const Command_RollDie &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -857,7 +857,7 @@ ResponseCode Server_ProtocolHandler::cmdRollDie(const Command_RollDie &cmd, Comm return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDrawCards(const Command_DrawCards &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdDrawCards(const Command_DrawCards &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -870,7 +870,7 @@ ResponseCode Server_ProtocolHandler::cmdDrawCards(const Command_DrawCards &cmd, return player->drawCards(bla, cmd.number()); } -ResponseCode Server_ProtocolHandler::cmdUndoDraw(const Command_UndoDraw & /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdUndoDraw(const Command_UndoDraw & /*cmd*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -883,7 +883,7 @@ ResponseCode Server_ProtocolHandler::cmdUndoDraw(const Command_UndoDraw & /*cmd* return player->undoDraw(bla); } -ResponseCode Server_ProtocolHandler::cmdMoveCard(const Command_MoveCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdMoveCard(const Command_MoveCard &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -900,7 +900,7 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(const Command_MoveCard &cmd, Co return player->moveCard(bla, QString::fromStdString(cmd.start_zone()), cardsToMove, cmd.target_player_id(), QString::fromStdString(cmd.target_zone()), cmd.x(), cmd.y()); } -ResponseCode Server_ProtocolHandler::cmdFlipCard(const Command_FlipCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdFlipCard(const Command_FlipCard &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -931,7 +931,7 @@ ResponseCode Server_ProtocolHandler::cmdFlipCard(const Command_FlipCard &cmd, Co return RespOk; } -ResponseCode Server_ProtocolHandler::cmdAttachCard(const Command_AttachCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdAttachCard(const Command_AttachCard &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -954,6 +954,7 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(const Command_AttachCard &cmd Server_CardZone *targetzone = 0; Server_Card *targetCard = 0; + qDebug() << "playerId="<getPlayer(cmd.target_player_id()); if (!targetPlayer) @@ -1019,7 +1020,7 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(const Command_AttachCard &cmd return RespOk; } -ResponseCode Server_ProtocolHandler::cmdCreateToken(const Command_CreateToken &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdCreateToken(const Command_CreateToken &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1056,7 +1057,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateToken(const Command_CreateToken &c return RespOk; } -ResponseCode Server_ProtocolHandler::cmdCreateArrow(const Command_CreateArrow &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdCreateArrow(const Command_CreateArrow &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1121,7 +1122,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(const Command_CreateArrow &c return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDeleteArrow(const Command_DeleteArrow &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdDeleteArrow(const Command_DeleteArrow &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1138,7 +1139,7 @@ ResponseCode Server_ProtocolHandler::cmdDeleteArrow(const Command_DeleteArrow &c return RespOk; } -ResponseCode Server_ProtocolHandler::cmdSetCardAttr(const Command_SetCardAttr &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdSetCardAttr(const Command_SetCardAttr &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1151,7 +1152,7 @@ ResponseCode Server_ProtocolHandler::cmdSetCardAttr(const Command_SetCardAttr &c return player->setCardAttrHelper(bla, QString::fromStdString(cmd.zone()), cmd.card_id(), QString::fromStdString(cmd.attr_name()), QString::fromStdString(cmd.attr_value())); } -ResponseCode Server_ProtocolHandler::cmdSetCardCounter(const Command_SetCardCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdSetCardCounter(const Command_SetCardCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1178,7 +1179,7 @@ ResponseCode Server_ProtocolHandler::cmdSetCardCounter(const Command_SetCardCoun return RespOk; } -ResponseCode Server_ProtocolHandler::cmdIncCardCounter(const Command_IncCardCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdIncCardCounter(const Command_IncCardCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1206,7 +1207,7 @@ ResponseCode Server_ProtocolHandler::cmdIncCardCounter(const Command_IncCardCoun return RespOk; } -ResponseCode Server_ProtocolHandler::cmdIncCounter(const Command_IncCounter &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdIncCounter(const Command_IncCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1226,7 +1227,7 @@ ResponseCode Server_ProtocolHandler::cmdIncCounter(const Command_IncCounter &cmd return RespOk; } -ResponseCode Server_ProtocolHandler::cmdCreateCounter(const Command_CreateCounter &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdCreateCounter(const Command_CreateCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1243,7 +1244,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateCounter(const Command_CreateCounte return RespOk; } -ResponseCode Server_ProtocolHandler::cmdSetCounter(const Command_SetCounter &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdSetCounter(const Command_SetCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1262,7 +1263,7 @@ ResponseCode Server_ProtocolHandler::cmdSetCounter(const Command_SetCounter &cmd return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDelCounter(const Command_DelCounter &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdDelCounter(const Command_DelCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1278,7 +1279,7 @@ ResponseCode Server_ProtocolHandler::cmdDelCounter(const Command_DelCounter &cmd return RespOk; } -ResponseCode Server_ProtocolHandler::cmdNextTurn(const Command_NextTurn & /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdNextTurn(const Command_NextTurn & /*cmd*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1292,7 +1293,7 @@ ResponseCode Server_ProtocolHandler::cmdNextTurn(const Command_NextTurn & /*cmd* return RespOk; } -ResponseCode Server_ProtocolHandler::cmdSetActivePhase(const Command_SetActivePhase &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdSetActivePhase(const Command_SetActivePhase &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1309,7 +1310,7 @@ ResponseCode Server_ProtocolHandler::cmdSetActivePhase(const Command_SetActivePh return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDumpZone(const Command_DumpZone &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdDumpZone(const Command_DumpZone &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (!game->getGameStarted()) return RespGameNotStarted; @@ -1354,11 +1355,11 @@ ResponseCode Server_ProtocolHandler::cmdDumpZone(const Command_DumpZone &cmd, Co zone->setCardsBeingLookedAt(numberCards); game->sendGameEvent(new Event_DumpZone(player->getPlayerId(), otherPlayer->getPlayerId(), zone->getName(), numberCards)); } - bla->setResponse(new Response_DumpZone(cont->cmd_id(), RespOk, new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), numberCards < zone->cards.size() ? zone->cards.size() : numberCards, respCardList))); + bla->setResponse(new Response_DumpZone(-1, RespOk, new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), numberCards < zone->cards.size() ? zone->cards.size() : numberCards, respCardList))); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdStopDumpZone(const Command_StopDumpZone &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdStopDumpZone(const Command_StopDumpZone &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (!game->getGameStarted()) return RespGameNotStarted; @@ -1379,7 +1380,7 @@ ResponseCode Server_ProtocolHandler::cmdStopDumpZone(const Command_StopDumpZone return RespOk; } -ResponseCode Server_ProtocolHandler::cmdRevealCards(const Command_RevealCards &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) +ResponseCode Server_ProtocolHandler::cmdRevealCards(const Command_RevealCards &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; diff --git a/common/server_protocolhandler.h b/common/server_protocolhandler.h index cfcfa94d..d01b4c26 100644 --- a/common/server_protocolhandler.h +++ b/common/server_protocolhandler.h @@ -97,65 +97,65 @@ private: virtual DeckList *getDeckFromDatabase(int deckId) = 0; - ResponseCode cmdPing(const Command_Ping &cmd, CommandContainer *cont); - ResponseCode cmdLogin(const Command_Login &cmd, CommandContainer *cont, BlaContainer *bla); - ResponseCode cmdMessage(const Command_Message &cmd, CommandContainer *cont, BlaContainer *bla); - virtual ResponseCode cmdAddToList(const Command_AddToList &cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckList(const Command_DeckList &cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckDelDir(const Command_DeckDelDir &cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckDel(const Command_DeckDel &cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckUpload(const Command_DeckUpload &cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckDownload(const Command_DeckDownload &cmd, CommandContainer *cont) = 0; - ResponseCode cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, CommandContainer *cont, BlaContainer *bla); - ResponseCode cmdGetUserInfo(const Command_GetUserInfo &cmd, CommandContainer *cont, BlaContainer *bla); - ResponseCode cmdListRooms(const Command_ListRooms &cmd, CommandContainer *cont, BlaContainer *bla); - ResponseCode cmdJoinRoom(const Command_JoinRoom &cmd, CommandContainer *cont, BlaContainer *bla); - ResponseCode cmdListUsers(const Command_ListUsers &cmd, CommandContainer *cont, BlaContainer *bla); - ResponseCode cmdLeaveRoom(const Command_LeaveRoom &cmd, CommandContainer *cont, Server_Room *room); - ResponseCode cmdRoomSay(const Command_RoomSay &cmd, CommandContainer *cont, Server_Room *room); - ResponseCode cmdCreateGame(const Command_CreateGame &cmd, CommandContainer *cont, Server_Room *room); - ResponseCode cmdJoinGame(const Command_JoinGame &cmd, CommandContainer *cont, Server_Room *room); - ResponseCode cmdLeaveGame(const Command_LeaveGame &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdKickFromGame(const Command_KickFromGame &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdConcede(const Command_Concede &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdReadyStart(const Command_ReadyStart &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdDeckSelect(const Command_DeckSelect &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdGameSay(const Command_GameSay &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdShuffle(const Command_Shuffle &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdMulligan(const Command_Mulligan &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdRollDie(const Command_RollDie &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdDrawCards(const Command_DrawCards &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdMoveCard(const Command_MoveCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdFlipCard(const Command_FlipCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdAttachCard(const Command_AttachCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdCreateToken(const Command_CreateToken &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdCreateArrow(const Command_CreateArrow &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdDeleteArrow(const Command_DeleteArrow &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdSetCardAttr(const Command_SetCardAttr &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdSetCardCounter(const Command_SetCardCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdIncCardCounter(const Command_IncCardCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdIncCounter(const Command_IncCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdCreateCounter(const Command_CreateCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdSetCounter(const Command_SetCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdDelCounter(const Command_DelCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdNextTurn(const Command_NextTurn &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdSetActivePhase(const Command_SetActivePhase &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdDumpZone(const Command_DumpZone &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdStopDumpZone(const Command_StopDumpZone &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - ResponseCode cmdRevealCards(const Command_RevealCards &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); - virtual ResponseCode cmdBanFromServer(const Command_BanFromServer &cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdShutdownServer(const Command_ShutdownServer &cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage &cmd, CommandContainer *cont) = 0; + ResponseCode cmdPing(const Command_Ping &cmd); + ResponseCode cmdLogin(const Command_Login &cmd, BlaContainer *bla); + ResponseCode cmdMessage(const Command_Message &cmd, BlaContainer *bla); + virtual ResponseCode cmdAddToList(const Command_AddToList &cmd, BlaContainer *bla) = 0; + virtual ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, BlaContainer *bla) = 0; + virtual ResponseCode cmdDeckList(const Command_DeckList &cmd, BlaContainer *bla) = 0; + virtual ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, BlaContainer *bla) = 0; + virtual ResponseCode cmdDeckDelDir(const Command_DeckDelDir &cmd, BlaContainer *bla) = 0; + virtual ResponseCode cmdDeckDel(const Command_DeckDel &cmd, BlaContainer *bla) = 0; + virtual ResponseCode cmdDeckUpload(const Command_DeckUpload &cmd, BlaContainer *bla) = 0; + virtual ResponseCode cmdDeckDownload(const Command_DeckDownload &cmd, BlaContainer *bla) = 0; + ResponseCode cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, BlaContainer *bla); + ResponseCode cmdGetUserInfo(const Command_GetUserInfo &cmd, BlaContainer *bla); + ResponseCode cmdListRooms(const Command_ListRooms &cmd, BlaContainer *bla); + ResponseCode cmdJoinRoom(const Command_JoinRoom &cmd, BlaContainer *bla); + ResponseCode cmdListUsers(const Command_ListUsers &cmd, BlaContainer *bla); + ResponseCode cmdLeaveRoom(const Command_LeaveRoom &cmd, Server_Room *room); + ResponseCode cmdRoomSay(const Command_RoomSay &cmd, Server_Room *room); + ResponseCode cmdCreateGame(const Command_CreateGame &cmd, Server_Room *room); + ResponseCode cmdJoinGame(const Command_JoinGame &cmd, Server_Room *room); + ResponseCode cmdLeaveGame(const Command_LeaveGame &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdKickFromGame(const Command_KickFromGame &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdConcede(const Command_Concede &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdReadyStart(const Command_ReadyStart &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdDeckSelect(const Command_DeckSelect &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdGameSay(const Command_GameSay &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdShuffle(const Command_Shuffle &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdMulligan(const Command_Mulligan &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdRollDie(const Command_RollDie &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdDrawCards(const Command_DrawCards &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdMoveCard(const Command_MoveCard &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdFlipCard(const Command_FlipCard &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdAttachCard(const Command_AttachCard &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdCreateToken(const Command_CreateToken &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdCreateArrow(const Command_CreateArrow &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdDeleteArrow(const Command_DeleteArrow &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdSetCardAttr(const Command_SetCardAttr &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdSetCardCounter(const Command_SetCardCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdIncCardCounter(const Command_IncCardCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdIncCounter(const Command_IncCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdCreateCounter(const Command_CreateCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdSetCounter(const Command_SetCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdDelCounter(const Command_DelCounter &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdNextTurn(const Command_NextTurn &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdSetActivePhase(const Command_SetActivePhase &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdDumpZone(const Command_DumpZone &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdStopDumpZone(const Command_StopDumpZone &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdRevealCards(const Command_RevealCards &cmd, Server_Game *game, Server_Player *player, BlaContainer *bla); + virtual ResponseCode cmdBanFromServer(const Command_BanFromServer &cmd, BlaContainer *bla) = 0; + virtual ResponseCode cmdShutdownServer(const Command_ShutdownServer &cmd, BlaContainer *bla) = 0; + virtual ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage &cmd, BlaContainer *bla) = 0; - ResponseCode processSessionCommandContainer(CommandContainer *cont, BlaContainer *bla); - ResponseCode processRoomCommandContainer(CommandContainer *cont, BlaContainer *bla); - ResponseCode processGameCommandContainer(CommandContainer *cont, BlaContainer *bla); - ResponseCode processModeratorCommandContainer(CommandContainer *cont, BlaContainer *bla); - ResponseCode processAdminCommandContainer(CommandContainer *cont, BlaContainer *bla); + ResponseCode processSessionCommandContainer(const CommandContainer &cont, BlaContainer *bla); + ResponseCode processRoomCommandContainer(const CommandContainer &cont, BlaContainer *bla); + ResponseCode processGameCommandContainer(const CommandContainer &cont, BlaContainer *bla); + ResponseCode processModeratorCommandContainer(const CommandContainer &cont, BlaContainer *bla); + ResponseCode processAdminCommandContainer(const CommandContainer &cont, BlaContainer *bla); private slots: void pingClockTimeout(); public: @@ -176,7 +176,7 @@ public: void setSessionId(int _sessionId) { sessionId = _sessionId; } int getLastCommandTime() const { return timeRunning - lastDataReceived; } - void processCommandContainer(CommandContainer *cont); + void processCommandContainer(const CommandContainer &cont); virtual void sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0; void enqueueProtocolItem(ProtocolItem *item); }; diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index 31602587..d3ff9468 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -114,31 +114,14 @@ void ServerSocketInterface::readClient() if (inputBuffer.size() < messageLength) return; - CommandContainer *newCommandContainer = new CommandContainer; - newCommandContainer->ParseFromArray(inputBuffer.data(), messageLength); - logger->logMessage(QString::fromStdString(newCommandContainer->ShortDebugString()), this); + CommandContainer newCommandContainer; + newCommandContainer.ParseFromArray(inputBuffer.data(), messageLength); + logger->logMessage(QString::fromStdString(newCommandContainer.ShortDebugString()), this); inputBuffer.remove(0, messageLength); messageInProgress = false; processCommandContainer(newCommandContainer); } while (!inputBuffer.isEmpty()); - -/* if (!data.contains("logMessage(QString(data), this); - xmlReader->addData(data); - - while (!xmlReader->atEnd()) { - xmlReader->readNext(); - if (topLevelItem) - topLevelItem->readElement(xmlReader); - else if (xmlReader->isStartElement() && (xmlReader->name().toString() == "cockatrice_client_stream")) { - if (xmlReader->attributes().value("comp").toString().toInt() == 1) - compressionSupport = true; - topLevelItem = new TopLevelProtocolItem; - connect(topLevelItem, SIGNAL(protocolItemReceived(ProtocolItem *)), this, SLOT(processProtocolItem(ProtocolItem *))); - } - } -*/ } void ServerSocketInterface::catchSocketError(QAbstractSocket::SocketError socketError) @@ -172,7 +155,7 @@ int ServerSocketInterface::getUserIdInDB(const QString &name) const return query.value(0).toInt(); } -ResponseCode ServerSocketInterface::cmdAddToList(const Command_AddToList &cmd, CommandContainer *cont) +ResponseCode ServerSocketInterface::cmdAddToList(const Command_AddToList &cmd, BlaContainer *bla) { if (authState != PasswordRight) return RespFunctionNotAllowed; @@ -209,11 +192,11 @@ ResponseCode ServerSocketInterface::cmdAddToList(const Command_AddToList &cmd, C else if (list == "ignore") ignoreList.insert(info->getName(), info); - //cont->enqueueItem(new Event_AddToList(list, new ServerInfo_User(info))); + bla->enqueueItem(new Event_AddToList(list, new ServerInfo_User(info))); return RespOk; } -ResponseCode ServerSocketInterface::cmdRemoveFromList(const Command_RemoveFromList &cmd, CommandContainer *cont) +ResponseCode ServerSocketInterface::cmdRemoveFromList(const Command_RemoveFromList &cmd, BlaContainer *bla) { if (authState != PasswordRight) return RespFunctionNotAllowed; @@ -250,7 +233,7 @@ ResponseCode ServerSocketInterface::cmdRemoveFromList(const Command_RemoveFromLi ignoreList.remove(user); } - //cont->enqueueItem(new Event_RemoveFromList(list, user)); + bla->enqueueItem(new Event_RemoveFromList(list, user)); return RespOk; } @@ -317,7 +300,7 @@ bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder) // CHECK AUTHENTICATION! // Also check for every function that data belonging to other users cannot be accessed. -ResponseCode ServerSocketInterface::cmdDeckList(const Command_DeckList & /*cmd*/, CommandContainer *cont) +ResponseCode ServerSocketInterface::cmdDeckList(const Command_DeckList & /*cmd*/, BlaContainer *bla) { if (authState != PasswordRight) return RespFunctionNotAllowed; @@ -329,15 +312,15 @@ ResponseCode ServerSocketInterface::cmdDeckList(const Command_DeckList & /*cmd*/ if (!deckListHelper(root)) return RespContextError; - ProtocolResponse *resp = new Response_DeckList(cont->cmd_id(), RespOk, root); + ProtocolResponse *resp = new Response_DeckList(-1, RespOk, root); if (getCompressionSupport()) resp->setCompressed(true); -// cont->setResponse(resp); + bla->setResponse(resp); return RespNothing; } -ResponseCode ServerSocketInterface::cmdDeckNewDir(const Command_DeckNewDir &cmd, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdDeckNewDir(const Command_DeckNewDir &cmd, BlaContainer * /*cont*/) { if (authState != PasswordRight) return RespFunctionNotAllowed; @@ -381,7 +364,7 @@ void ServerSocketInterface::deckDelDirHelper(int basePathId) servatrice->execSqlQuery(query); } -ResponseCode ServerSocketInterface::cmdDeckDelDir(const Command_DeckDelDir &cmd, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdDeckDelDir(const Command_DeckDelDir &cmd, BlaContainer * /*cont*/) { if (authState != PasswordRight) return RespFunctionNotAllowed; @@ -395,7 +378,7 @@ ResponseCode ServerSocketInterface::cmdDeckDelDir(const Command_DeckDelDir &cmd, return RespOk; } -ResponseCode ServerSocketInterface::cmdDeckDel(const Command_DeckDel &cmd, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdDeckDel(const Command_DeckDel &cmd, BlaContainer * /*cont*/) { if (authState != PasswordRight) return RespFunctionNotAllowed; @@ -419,26 +402,23 @@ ResponseCode ServerSocketInterface::cmdDeckDel(const Command_DeckDel &cmd, Comma return RespOk; } -ResponseCode ServerSocketInterface::cmdDeckUpload(const Command_DeckUpload &cmd, CommandContainer *cont) +ResponseCode ServerSocketInterface::cmdDeckUpload(const Command_DeckUpload &cmd, BlaContainer *bla) { if (authState != PasswordRight) return RespFunctionNotAllowed; servatrice->checkSql(); -/* - if (!cmd->getDeck()) + + if (!cmd.has_deck_list()) return RespInvalidData; - int folderId = getDeckPathId(cmd->getPath()); + int folderId = getDeckPathId(QString::fromStdString(cmd.path())); if (folderId == -1) return RespNameNotFound; - QString deckContents; - QXmlStreamWriter deckWriter(&deckContents); - deckWriter.writeStartDocument(); - cmd->getDeck()->write(&deckWriter); - deckWriter.writeEndDocument(); + QString deckStr = QString::fromStdString(cmd.deck_list()); + DeckList deck(deckStr); - QString deckName = cmd->getDeck()->getName(); + QString deckName = deck.getName(); if (deckName.isEmpty()) deckName = "Unnamed deck"; @@ -448,11 +428,11 @@ ResponseCode ServerSocketInterface::cmdDeckUpload(const Command_DeckUpload &cmd, query.bindValue(":id_folder", folderId); query.bindValue(":user", userInfo->getName()); query.bindValue(":name", deckName); - query.bindValue(":content", deckContents); + query.bindValue(":content", deckStr); servatrice->execSqlQuery(query); - cont->setResponse(new Response_DeckUpload(cont->cmd_id(), RespOk, new DeckList_File(deckName, query.lastInsertId().toInt(), QDateTime::currentDateTime()))); -*/ return RespNothing; + bla->setResponse(new Response_DeckUpload(-1, RespOk, new DeckList_File(deckName, query.lastInsertId().toInt(), QDateTime::currentDateTime()))); + return RespNothing; } DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId) @@ -476,7 +456,7 @@ DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId) return deck; } -ResponseCode ServerSocketInterface::cmdDeckDownload(const Command_DeckDownload &cmd, CommandContainer *cont) +ResponseCode ServerSocketInterface::cmdDeckDownload(const Command_DeckDownload &cmd, BlaContainer *bla) { if (authState != PasswordRight) return RespFunctionNotAllowed; @@ -487,14 +467,14 @@ ResponseCode ServerSocketInterface::cmdDeckDownload(const Command_DeckDownload & } catch(ResponseCode r) { return r; } - //cont->setResponse(new Response_DeckDownload(cont->cmd_id(), RespOk, deck)); + bla->setResponse(new Response_DeckDownload(-1, RespOk, deck)); return RespNothing; } // MODERATOR FUNCTIONS. // May be called by admins and moderators. Permission is checked by the calling function. -ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_BanFromServer &cmd, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_BanFromServer &cmd, BlaContainer * /*cont*/) { QString userName = QString::fromStdString(cmd.user_name()); QString address = QString::fromStdString(cmd.address()); @@ -523,13 +503,13 @@ ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_BanFromServer // ADMIN FUNCTIONS. // Permission is checked by the calling function. -ResponseCode ServerSocketInterface::cmdUpdateServerMessage(const Command_UpdateServerMessage & /*cmd*/, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdUpdateServerMessage(const Command_UpdateServerMessage & /*cmd*/, BlaContainer * /*cont*/) { servatrice->updateLoginMessage(); return RespOk; } -ResponseCode ServerSocketInterface::cmdShutdownServer(const Command_ShutdownServer &cmd, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdShutdownServer(const Command_ShutdownServer &cmd, BlaContainer * /*cont*/) { servatrice->scheduleShutdown(QString::fromStdString(cmd.reason()), cmd.minutes()); return RespOk; diff --git a/servatrice/src/serversocketinterface.h b/servatrice/src/serversocketinterface.h index 3580e868..82badaa0 100644 --- a/servatrice/src/serversocketinterface.h +++ b/servatrice/src/serversocketinterface.h @@ -59,22 +59,22 @@ private: int getUserIdInDB(const QString &name) const; - ResponseCode cmdAddToList(const Command_AddToList &cmd, CommandContainer *cont); - ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, CommandContainer *cont); + ResponseCode cmdAddToList(const Command_AddToList &cmd, BlaContainer *bla); + ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, BlaContainer *bla); int getDeckPathId(int basePathId, QStringList path); int getDeckPathId(const QString &path); bool deckListHelper(DeckList_Directory *folder); - ResponseCode cmdDeckList(const Command_DeckList &cmd, CommandContainer *cont); - ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, CommandContainer *cont); + ResponseCode cmdDeckList(const Command_DeckList &cmd, BlaContainer *bla); + ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, BlaContainer *bla); void deckDelDirHelper(int basePathId); - ResponseCode cmdDeckDelDir(const Command_DeckDelDir &cmd, CommandContainer *cont); - ResponseCode cmdDeckDel(const Command_DeckDel &cmd, CommandContainer *cont); - ResponseCode cmdDeckUpload(const Command_DeckUpload &cmd, CommandContainer *cont); + ResponseCode cmdDeckDelDir(const Command_DeckDelDir &cmd, BlaContainer *bla); + ResponseCode cmdDeckDel(const Command_DeckDel &cmd, BlaContainer *bla); + ResponseCode cmdDeckUpload(const Command_DeckUpload &cmd, BlaContainer *bla); DeckList *getDeckFromDatabase(int deckId); - ResponseCode cmdDeckDownload(const Command_DeckDownload &cmd, CommandContainer *cont); - ResponseCode cmdBanFromServer(const Command_BanFromServer &cmd, CommandContainer *cont); - ResponseCode cmdShutdownServer(const Command_ShutdownServer &cmd, CommandContainer *cont); - ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage &cmd, CommandContainer *cont); + ResponseCode cmdDeckDownload(const Command_DeckDownload &cmd, BlaContainer *bla); + ResponseCode cmdBanFromServer(const Command_BanFromServer &cmd, BlaContainer *bla); + ResponseCode cmdShutdownServer(const Command_ShutdownServer &cmd, BlaContainer *bla); + ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage &cmd, BlaContainer *bla); protected: bool getCompressionSupport() const { return compressionSupport; } public: