diff --git a/cockatrice/src/dlg_creategame.cpp b/cockatrice/src/dlg_creategame.cpp index 5d71ed46..d998d6e6 100644 --- a/cockatrice/src/dlg_creategame.cpp +++ b/cockatrice/src/dlg_creategame.cpp @@ -8,14 +8,15 @@ #include #include #include +#include #include "dlg_creategame.h" #include "tab_room.h" #include "pending_command.h" #include "pb/room_commands.pb.h" +#include "pb/serverinfo_game.pb.h" -DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap &_gameTypes, QWidget *parent) - : QDialog(parent), room(_room), gameTypes(_gameTypes) +void DlgCreateGame::sharedCtor() { descriptionLabel = new QLabel(tr("&Description:")); descriptionEdit = new QLineEdit; @@ -98,13 +99,63 @@ DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap &_gameType setLayout(mainLayout); - setWindowTitle(tr("Create game")); setFixedHeight(sizeHint().height()); +} +DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap &_gameTypes, QWidget *parent) + : QDialog(parent), room(_room), gameTypes(_gameTypes) +{ + sharedCtor(); + + setWindowTitle(tr("Create game")); + connect(okButton, SIGNAL(clicked()), this, SLOT(actOK())); connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); } +DlgCreateGame::DlgCreateGame(const ServerInfo_Game &gameInfo, const QMap &_gameTypes, QWidget *parent) + : QDialog(parent), room(0), gameTypes(_gameTypes) +{ + sharedCtor(); + + descriptionEdit->setEnabled(false); + maxPlayersEdit->setEnabled(false); + passwordEdit->setEnabled(false); + onlyBuddiesCheckBox->setEnabled(false); + onlyRegisteredCheckBox->setEnabled(false); + spectatorsAllowedCheckBox->setEnabled(false); + spectatorsNeedPasswordCheckBox->setEnabled(false); + spectatorsCanTalkCheckBox->setEnabled(false); + spectatorsSeeEverythingCheckBox->setEnabled(false); + + descriptionEdit->setText(QString::fromStdString(gameInfo.description())); + maxPlayersEdit->setValue(gameInfo.max_players()); + onlyBuddiesCheckBox->setChecked(gameInfo.only_buddies()); + onlyRegisteredCheckBox->setChecked(gameInfo.only_registered()); + spectatorsAllowedCheckBox->setChecked(gameInfo.spectators_allowed()); + spectatorsNeedPasswordCheckBox->setChecked(gameInfo.spectators_need_password()); + spectatorsCanTalkCheckBox->setChecked(gameInfo.spectators_can_chat()); + spectatorsSeeEverythingCheckBox->setChecked(gameInfo.spectators_omniscient()); + + QSet types; + for (int i = 0; i < gameInfo.game_types_size(); ++i) + types.insert(gameInfo.game_types(i)); + + QMapIterator gameTypeIterator(gameTypes); + while (gameTypeIterator.hasNext()) { + gameTypeIterator.next(); + + QCheckBox *gameTypeCheckBox = gameTypeCheckBoxes.value(gameTypeIterator.key()); + gameTypeCheckBox->setEnabled(false); + gameTypeCheckBox->setChecked(types.contains(gameTypeIterator.key())); + } + + setWindowTitle(tr("Game information")); + okButton->setAutoDefault(true); + cancelButton->hide(); + connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); +} + void DlgCreateGame::actOK() { Command_CreateGame cmd; diff --git a/cockatrice/src/dlg_creategame.h b/cockatrice/src/dlg_creategame.h index 556afc9c..21595563 100644 --- a/cockatrice/src/dlg_creategame.h +++ b/cockatrice/src/dlg_creategame.h @@ -13,10 +13,13 @@ class QGroupBox; class QSpinBox; class TabRoom; +class ServerInfo_Game; + class DlgCreateGame : public QDialog { Q_OBJECT public: DlgCreateGame(TabRoom *_room, const QMap &_gameTypes, QWidget *parent = 0); + DlgCreateGame(const ServerInfo_Game &game, const QMap &_gameTypes, QWidget *parent = 0); private slots: void actOK(); void checkResponse(Response::ResponseCode response); @@ -33,6 +36,8 @@ private: QCheckBox *onlyBuddiesCheckBox, *onlyRegisteredCheckBox; QCheckBox *spectatorsAllowedCheckBox, *spectatorsNeedPasswordCheckBox, *spectatorsCanTalkCheckBox, *spectatorsSeeEverythingCheckBox; QPushButton *okButton, *cancelButton; + + void sharedCtor(); }; #endif diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 29ecd731..dae1456a 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -8,6 +8,7 @@ #include #include +#include "dlg_creategame.h" #include "tab_game.h" #include "tab_supervisor.h" #include "cardinfowidget.h" @@ -204,10 +205,7 @@ TabGame::TabGame(GameReplay *_replay) hostId(-1), localPlayerId(-1), spectator(true), - spectatorsCanTalk(false), - spectatorsSeeEverything(true), gameStateKnown(false), - started(false), resuming(false), currentPhase(-1), activeCard(0), @@ -216,8 +214,8 @@ TabGame::TabGame(GameReplay *_replay) { setAttribute(Qt::WA_DeleteOnClose); - gameId = replay->game_info().game_id(); - gameDescription = QString::fromStdString(replay->game_info().description()); + gameInfo.CopyFrom(replay->game_info()); + gameInfo.set_spectators_omniscient(true); // Create list: event number -> time [ms] // Distribute simultaneous events evenly across 1 second. @@ -325,6 +323,7 @@ TabGame::TabGame(GameReplay *_replay) aNextPhase = 0; aNextTurn = 0; aRemoveLocalArrows = 0; + aGameInfo = 0; aConcede = 0; aLeaveGame = 0; aCloseReplay = new QAction(this); @@ -339,26 +338,25 @@ TabGame::TabGame(GameReplay *_replay) splitter->restoreState(settingsCache->getTabGameSplitterSizes()); - messageLog->logReplayStarted(gameId); + messageLog->logReplayStarted(gameInfo.game_id()); } -TabGame::TabGame(TabSupervisor *_tabSupervisor, QList &_clients, const Event_GameJoined &event) +TabGame::TabGame(TabSupervisor *_tabSupervisor, QList &_clients, const Event_GameJoined &event, const QMap &_roomGameTypes) : Tab(_tabSupervisor), clients(_clients), - gameId(event.game_id()), - gameDescription(QString::fromStdString(event.game_description())), + gameInfo(event.game_info()), + roomGameTypes(_roomGameTypes), hostId(event.host_id()), localPlayerId(event.player_id()), spectator(event.spectator()), - spectatorsCanTalk(event.spectators_can_talk()), - spectatorsSeeEverything(event.spectators_see_everything()), gameStateKnown(true), - started(false), resuming(event.resuming()), currentPhase(-1), activeCard(0), replay(0) { + gameInfo.set_started(false); + gameTimer = new QTimer(this); gameTimer->setInterval(1000); connect(gameTimer, SIGNAL(timeout()), this, SLOT(incrementGameTime())); @@ -411,7 +409,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList &_client mainLayout->addLayout(deckViewContainerLayout, 10); mainLayout->addWidget(splitter); - if (spectator && !spectatorsCanTalk && tabSupervisor->getAdminLocked()) { + if (spectator && !gameInfo.spectators_can_chat() && tabSupervisor->getAdminLocked()) { sayLabel->hide(); sayEdit->hide(); } @@ -425,6 +423,8 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList &_client connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn())); aRemoveLocalArrows = new QAction(this); connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows())); + aGameInfo = new QAction(this); + connect(aGameInfo, SIGNAL(triggered()), this, SLOT(actGameInfo())); aConcede = new QAction(this); connect(aConcede, SIGNAL(triggered()), this, SLOT(actConcede())); aLeaveGame = new QAction(this); @@ -457,6 +457,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList &_client tabMenu->addSeparator(); tabMenu->addAction(aRemoveLocalArrows); tabMenu->addSeparator(); + tabMenu->addAction(aGameInfo); tabMenu->addAction(aConcede); tabMenu->addAction(aLeaveGame); @@ -465,7 +466,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList &_client splitter->restoreState(settingsCache->getTabGameSplitterSizes()); - messageLog->logGameJoined(gameId); + messageLog->logGameJoined(gameInfo.game_id()); } TabGame::~TabGame() @@ -504,6 +505,8 @@ void TabGame::retranslateUi() aRemoveLocalArrows->setText(tr("&Remove all local arrows")); aRemoveLocalArrows->setShortcut(tr("Ctrl+R")); } + if (aGameInfo) + aGameInfo->setText(tr("Game &information")); if (aConcede) { aConcede->setText(tr("&Concede")); aConcede->setShortcut(tr("F2")); @@ -607,11 +610,17 @@ void TabGame::incrementGameTime() void TabGame::adminLockChanged(bool lock) { - bool v = !(spectator && !spectatorsCanTalk && lock); + bool v = !(spectator && !gameInfo.spectators_can_chat() && lock); sayLabel->setVisible(v); sayEdit->setVisible(v); } +void TabGame::actGameInfo() +{ + DlgCreateGame dlg(gameInfo, roomGameTypes); + dlg.exec(); +} + void TabGame::actConcede() { if (QMessageBox::question(this, tr("Concede"), tr("Are you sure you want to concede this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) @@ -782,7 +791,7 @@ void TabGame::sendGameCommand(const google::protobuf::Message &command, int play PendingCommand *TabGame::prepareGameCommand(const ::google::protobuf::Message &cmd) { CommandContainer cont; - cont.set_game_id(gameId); + cont.set_game_id(gameInfo.game_id()); GameCommand *c = cont.add_game_command(); c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); return new PendingCommand(cont); @@ -791,7 +800,7 @@ PendingCommand *TabGame::prepareGameCommand(const ::google::protobuf::Message &c PendingCommand *TabGame::prepareGameCommand(const QList< const ::google::protobuf::Message * > &cmdList) { CommandContainer cont; - cont.set_game_id(gameId); + cont.set_game_id(gameInfo.game_id()); for (int i = 0; i < cmdList.size(); ++i) { GameCommand *c = cont.add_game_command(); c->GetReflection()->MutableMessage(c, cmdList[i]->GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(*cmdList[i]); @@ -819,7 +828,7 @@ void TabGame::startGame(bool resuming) } playerListWidget->setGameStarted(true, resuming); - started = true; + gameInfo.set_started(true); static_cast(gameView->scene())->rearrange(); gameView->show(); phasesToolbar->show(); @@ -839,7 +848,7 @@ void TabGame::stopGame() playerListWidget->setActivePlayer(-1); playerListWidget->setGameStarted(false, false); - started = false; + gameInfo.set_started(false); gameView->hide(); phasesToolbar->hide(); } @@ -897,13 +906,13 @@ void TabGame::eventGameStateChanged(const Event_GameStateChanged &event, int /*e secondsElapsed = event.seconds_elapsed(); - if (event.game_started() && !started) { + if (event.game_started() && !gameInfo.started()) { startGame(!gameStateKnown); if (gameStateKnown) messageLog->logGameStart(); setActivePlayer(event.active_player_id()); setActivePhase(event.active_phase()); - } else if (!event.game_started() && started) { + } else if (!event.game_started() && gameInfo.started()) { stopGame(); scene->clearViews(); } @@ -1004,7 +1013,7 @@ void TabGame::eventGameHostChanged(const Event_GameHostChanged & /*event*/, int void TabGame::eventGameClosed(const Event_GameClosed & /*event*/, int /*eventPlayerId*/, const GameEventContext & /*context*/) { - started = false; + gameInfo.set_started(false); messageLog->logGameClosed(); emit userEvent(); } @@ -1084,9 +1093,9 @@ CardItem *TabGame::getCard(int playerId, const QString &zoneName, int cardId) co QString TabGame::getTabText() const { if (replay) - return tr("Replay %1: %2").arg(gameId).arg(gameDescription); + return tr("Replay %1: %2").arg(gameInfo.game_id()).arg(QString::fromStdString(gameInfo.description())); else - return tr("Game %1: %2").arg(gameId).arg(gameDescription); + return tr("Game %1: %2").arg(gameInfo.game_id()).arg(QString::fromStdString(gameInfo.description())); } Player *TabGame::getActiveLocalPlayer() const diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index b9687563..a0b58588 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -4,8 +4,8 @@ #include #include #include "tab.h" +#include "pb/serverinfo_game.pb.h" -namespace google { namespace protobuf { class Message; } } class AbstractClient; class CardDatabase; class GameView; @@ -96,16 +96,14 @@ private: QTimer *gameTimer; int secondsElapsed; QList clients; - int gameId; - QString gameDescription; + ServerInfo_Game gameInfo; + QMap roomGameTypes; int hostId; int localPlayerId; bool spectator; - bool spectatorsCanTalk, spectatorsSeeEverything; QMap players; QMap spectators; bool gameStateKnown; - bool started; bool resuming; QStringList phasesList; int currentPhase; @@ -135,7 +133,7 @@ private: ZoneViewLayout *zoneLayout; QAction *playersSeparator; QMenu *phasesMenu; - QAction *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows; + QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows; QList phaseActions; Player *addPlayer(int playerId, const ServerInfo_User &info); @@ -180,6 +178,7 @@ private slots: void newCardAdded(AbstractCardItem *card); void updateCardMenu(AbstractCardItem *card); + void actGameInfo(); void actConcede(); void actLeaveGame(); void actRemoveLocalArrows(); @@ -188,7 +187,7 @@ private slots: void actNextPhase(); void actNextTurn(); public: - TabGame(TabSupervisor *_tabSupervisor, QList &_clients, const Event_GameJoined &event); + TabGame(TabSupervisor *_tabSupervisor, QList &_clients, const Event_GameJoined &event, const QMap &_roomGameTypes); TabGame(GameReplay *replay); ~TabGame(); void retranslateUi(); @@ -196,11 +195,10 @@ public: const QMap &getPlayers() const { return players; } CardItem *getCard(int playerId, const QString &zoneName, int cardId) const; bool isHost() const { return hostId == localPlayerId; } - int getGameId() const { return gameId; } + int getGameId() const { return gameInfo.game_id(); } QString getTabText() const; bool getSpectator() const { return spectator; } - bool getSpectatorsCanTalk() const { return spectatorsCanTalk; } - bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; } + bool getSpectatorsSeeEverything() const { return gameInfo.spectators_omniscient(); } Player *getActiveLocalPlayer() const; AbstractClient *getClientForPlayer(int playerId) const; diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index 6e23afcc..c883f862 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -250,27 +250,35 @@ void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex) void TabSupervisor::gameJoined(const Event_GameJoined &event) { - TabGame *tab = new TabGame(this, QList() << client, event); + QMap roomGameTypes; + TabRoom *room = roomTabs.value(event.game_info().room_id()); + if (room) + roomGameTypes = room->getGameTypes(); + else + for (int i = 0; i < event.game_types_size(); ++i) + roomGameTypes.insert(event.game_types(i).game_type_id(), QString::fromStdString(event.game_types(i).description())); + + TabGame *tab = new TabGame(this, QList() << client, event, roomGameTypes); connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *))); connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool))); int tabIndex = myAddTab(tab); addCloseButtonToTab(tab, tabIndex); - gameTabs.insert(event.game_id(), tab); + gameTabs.insert(event.game_info().game_id(), tab); setCurrentWidget(tab); } void TabSupervisor::localGameJoined(const Event_GameJoined &event) { - TabGame *tab = new TabGame(this, localClients, event); + TabGame *tab = new TabGame(this, localClients, event, QMap()); connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *))); int tabIndex = myAddTab(tab); addCloseButtonToTab(tab, tabIndex); - gameTabs.insert(event.game_id(), tab); + gameTabs.insert(event.game_info().game_id(), tab); setCurrentWidget(tab); for (int i = 1; i < localClients.size(); ++i) { Command_JoinGame cmd; - cmd.set_game_id(event.game_id()); + cmd.set_game_id(event.game_info().game_id()); localClients[i]->sendCommand(localClients[i]->prepareRoomCommand(cmd, 0)); } } diff --git a/common/pb/event_game_joined.proto b/common/pb/event_game_joined.proto index 37cbd865..aa344ade 100644 --- a/common/pb/event_game_joined.proto +++ b/common/pb/event_game_joined.proto @@ -1,16 +1,15 @@ import "session_event.proto"; +import "serverinfo_game.proto"; +import "serverinfo_gametype.proto"; message Event_GameJoined { extend SessionEvent { optional Event_GameJoined ext = 1009; } - optional sint32 room_id = 1; - optional sint32 game_id = 2; - optional string game_description = 3; - optional sint32 host_id = 4; - optional sint32 player_id = 5; - optional bool spectator = 6; - optional bool spectators_can_talk = 7; - optional bool spectators_see_everything = 8; - optional bool resuming = 9; + optional ServerInfo_Game game_info = 1; + repeated ServerInfo_GameType game_types = 2; + optional sint32 host_id = 3; + optional sint32 player_id = 4; + optional bool spectator = 5; + optional bool resuming = 6; } diff --git a/common/pb/serverinfo_game.proto b/common/pb/serverinfo_game.proto index 15444a05..7544abe8 100644 --- a/common/pb/serverinfo_game.proto +++ b/common/pb/serverinfo_game.proto @@ -1,20 +1,22 @@ import "serverinfo_user.proto"; message ServerInfo_Game { - optional sint32 room_id = 1; - optional sint32 game_id = 2; - optional string description = 3; - optional bool with_password = 4; - optional uint32 player_count = 5; + optional sint32 server_id = 1 [default = -1]; + optional sint32 room_id = 2 [default = -1]; + optional sint32 game_id = 3 [default = -1]; + optional string description = 4; + optional bool with_password = 5; optional uint32 max_players = 6; - optional bool started = 7; - repeated sint32 game_types = 8; - optional ServerInfo_User creator_info = 9; - optional bool only_buddies = 10; - optional bool only_registered = 11; - optional bool spectators_allowed = 12; - optional bool spectators_need_password = 13; - optional uint32 spectators_count = 14; - optional uint32 start_time = 15; - optional sint32 server_id = 16 [default = -1]; + repeated sint32 game_types = 7; + optional ServerInfo_User creator_info = 8; + optional bool only_buddies = 9; + optional bool only_registered = 10; + optional bool spectators_allowed = 11; + optional bool spectators_need_password = 12; + optional bool spectators_can_chat = 13; + optional bool spectators_omniscient = 14; + optional uint32 player_count = 30; + optional uint32 spectators_count = 31; + optional bool started = 50; + optional uint32 start_time = 51; } diff --git a/common/server.h b/common/server.h index a314898d..f14959b0 100644 --- a/common/server.h +++ b/common/server.h @@ -108,7 +108,7 @@ protected: QMap externalUsers; QMap rooms; - virtual qint64 startSession(const QString &userName, const QString &address) { return -1; } + virtual qint64 startSession(const QString &userName, const QString &address) { return 0; } virtual void endSession(qint64 sessionId) { } virtual bool userExists(const QString &user) { return false; } virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reason) { return UnknownUser; } diff --git a/common/server_game.cpp b/common/server_game.cpp index c1302977..144e974a 100644 --- a/common/server_game.cpp +++ b/common/server_game.cpp @@ -77,7 +77,7 @@ Server_Game::Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const connect(this, SIGNAL(sigStartGameIfReady()), this, SLOT(doStartGameIfReady()), Qt::QueuedConnection); - currentReplay->mutable_game_info()->CopyFrom(getInfo()); + getInfo(*currentReplay->mutable_game_info()); if (room->getServer()->getGameShouldPing()) { pingClock = new QTimer(this); @@ -271,7 +271,7 @@ void Server_Game::doStartGameIfReady() replayList.append(currentReplay); currentReplay = new GameReplay; currentReplay->set_replay_id(room->getServer()->getNextReplayId()); - currentReplay->mutable_game_info()->CopyFrom(getInfo()); + getInfo(*currentReplay->mutable_game_info()); Event_GameStateChanged omniscientEvent; QListIterator omniscientGameStateIterator(getGameState(0, true, true)); @@ -294,7 +294,10 @@ void Server_Game::doStartGameIfReady() nextTurn(); locker.unlock(); - emit gameInfoChanged(getInfo()); + + ServerInfo_Game gameInfo; + getInfo(gameInfo); + emit gameInfoChanged(gameInfo); } void Server_Game::startGameIfReady() @@ -390,8 +393,11 @@ void Server_Game::addPlayer(Server_AbstractUserInterface *userInterface, Respons sendGameEventContainer(prepareGameEvent(Event_GameHostChanged(), hostId)); } - if (broadcastUpdate) - emit gameInfoChanged(getInfo()); + if (broadcastUpdate) { + ServerInfo_Game gameInfo; + getInfo(gameInfo); + emit gameInfoChanged(gameInfo); + } if ((newPlayer->getUserInfo()->user_level() & ServerInfo_User::IsRegistered) && !spectator) room->getServer()->addPersistentPlayer(playerName, room->getId(), gameId, newPlayer->getPlayerId()); @@ -439,7 +445,10 @@ void Server_Game::removePlayer(Server_Player *player) if (gameStarted && playerActive) nextTurn(); } - emit gameInfoChanged(getInfo()); + + ServerInfo_Game gameInfo; + getInfo(gameInfo); + emit gameInfoChanged(gameInfo); } void Server_Game::removeArrowsToPlayer(GameEventStorage &ges, Server_Player *player) @@ -672,15 +681,19 @@ QList Server_Game::getGameState(Server_Player *playerWhosAski void Server_Game::createGameJoinedEvent(Server_Player *player, ResponseContainer &rc, bool resuming) { Event_GameJoined event1; - event1.set_room_id(room->getId()); - event1.set_game_id(gameId); - event1.set_game_description(description.toStdString()); + getInfo(*event1.mutable_game_info()); event1.set_host_id(hostId); event1.set_player_id(player->getPlayerId()); event1.set_spectator(player->getSpectator()); - event1.set_spectators_can_talk(spectatorsCanTalk); - event1.set_spectators_see_everything(spectatorsSeeEverything); event1.set_resuming(resuming); + if (resuming) { + const QStringList &allGameTypes = room->getGameTypes(); + for (int i = 0; i < allGameTypes.size(); ++i) { + ServerInfo_GameType *newGameType = event1.add_game_types(); + newGameType->set_game_type_id(i); + newGameType->set_description(allGameTypes[i].toStdString()); + } + } rc.enqueuePostResponseItem(ServerMessage::SESSION_EVENT, Server_AbstractUserInterface::prepareSessionEvent(event1)); Event_GameStateChanged event2; @@ -728,11 +741,10 @@ GameEventContainer *Server_Game::prepareGameEvent(const ::google::protobuf::Mess return cont; } -ServerInfo_Game Server_Game::getInfo() const +void Server_Game::getInfo(ServerInfo_Game &result) const { QMutexLocker locker(&gameMutex); - ServerInfo_Game result; result.set_room_id(room->getId()); result.set_game_id(getGameId()); if (!players.isEmpty()) { @@ -749,8 +761,9 @@ ServerInfo_Game Server_Game::getInfo() const result.set_only_registered(onlyRegistered); result.set_spectators_allowed(getSpectatorsAllowed()); result.set_spectators_need_password(getSpectatorsNeedPassword()); + result.set_spectators_can_chat(spectatorsCanTalk); + result.set_spectators_omniscient(spectatorsSeeEverything); result.set_spectators_count(getSpectatorCount()); result.set_start_time(startTime.toTime_t()); } - return result; } diff --git a/common/server_game.h b/common/server_game.h index 3a8d4ee6..981fb87f 100644 --- a/common/server_game.h +++ b/common/server_game.h @@ -77,7 +77,7 @@ public: Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent); ~Server_Game(); Server_Room *getRoom() const { return room; } - ServerInfo_Game getInfo() const; + void getInfo(ServerInfo_Game &result) const; int getHostId() const { return hostId; } ServerInfo_User *getCreatorInfo() const { return creatorInfo; } bool getGameStarted() const { return gameStarted; } diff --git a/common/server_room.cpp b/common/server_room.cpp index 3b71704f..5a112b4b 100644 --- a/common/server_room.cpp +++ b/common/server_room.cpp @@ -54,7 +54,7 @@ ServerInfo_Room Server_Room::getInfo(bool complete, bool showGameTypes, bool upd if (complete) { QMapIterator gameIterator(games); while (gameIterator.hasNext()) - result.add_game_list()->CopyFrom(gameIterator.next().value()->getInfo()); + gameIterator.next().value()->getInfo(*result.add_game_list()); if (includeExternalData) { QMapIterator externalGameIterator(externalGames); while (externalGameIterator.hasNext()) @@ -231,9 +231,11 @@ void Server_Room::addGame(Server_Game *game) game->gameMutex.lock(); games.insert(game->getGameId(), game); - emit gameListChanged(game->getInfo()); + ServerInfo_Game gameInfo; + game->getInfo(gameInfo); game->gameMutex.unlock(); + emit gameListChanged(gameInfo); emit roomInfoChanged(getInfo(false, false, true)); } @@ -243,7 +245,11 @@ void Server_Room::removeGame(Server_Game *game) // called from ~Server_Game, which locks both mutexes anyway beforehand. disconnect(game, 0, this, 0); - emit gameListChanged(game->getInfo()); + + ServerInfo_Game gameInfo; + game->getInfo(gameInfo); + emit gameListChanged(gameInfo); + games.remove(game->getGameId()); emit roomInfoChanged(getInfo(false, false, true)); @@ -269,8 +275,11 @@ QList Server_Room::getGamesOfUser(const QString &userName) cons QMapIterator gamesIterator(games); while (gamesIterator.hasNext()) { Server_Game *game = gamesIterator.next().value(); - if (game->containsUser(userName)) - result.append(game->getInfo()); + if (game->containsUser(userName)) { + ServerInfo_Game gameInfo; + game->getInfo(gameInfo); + result.append(gameInfo); + } } return result; } diff --git a/servatrice/src/isl_interface.cpp b/servatrice/src/isl_interface.cpp index 136d99c2..96e55800 100644 --- a/servatrice/src/isl_interface.cpp +++ b/servatrice/src/isl_interface.cpp @@ -339,7 +339,7 @@ void IslInterface::processSessionEvent(const SessionEvent &event, qint64 session break; } const Event_GameJoined &gameJoined = event.GetExtension(Event_GameJoined::ext); - client->playerAddedToGame(gameJoined.game_id(), gameJoined.room_id(), gameJoined.player_id()); + client->playerAddedToGame(gameJoined.game_info().game_id(), gameJoined.game_info().room_id(), gameJoined.player_id()); client->sendProtocolItem(event); break; }