From e2e9c5ab96c1ad75bd4b6d1c30bfe1c5bd47d4ca Mon Sep 17 00:00:00 2001 From: Zach H Date: Thu, 20 Apr 2017 03:01:28 -0400 Subject: [PATCH] disable join if spec disabled (#2605) --- cockatrice/src/gameselector.cpp | 20 +++++++++++++++++++- cockatrice/src/gameselector.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/gameselector.cpp b/cockatrice/src/gameselector.cpp index c73b224a..bb4541ca 100644 --- a/cockatrice/src/gameselector.cpp +++ b/cockatrice/src/gameselector.cpp @@ -98,6 +98,7 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin())); connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin())); + connect(gameListView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(updateButtonChoices(const QModelIndex &))); connect(gameListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(actJoin())); } @@ -144,7 +145,7 @@ void GameSelector::checkResponse(const Response &response) if (createButton) createButton->setEnabled(true); joinButton->setEnabled(true); - spectateButton->setEnabled(true); + switch (response.response_code()) { case Response::RespNotInRoom: QMessageBox::critical(this, tr("Error"), tr("Please join the appropriate room first.")); break; @@ -157,6 +158,9 @@ void GameSelector::checkResponse(const Response &response) case Response::RespInIgnoreList: QMessageBox::critical(this, tr("Error"), tr("You are being ignored by the creator of this game.")); break; default: ; } + + if (response.response_code() != Response::RespSpectatorsNotAllowed) + spectateButton->setEnabled(true); } void GameSelector::actJoin() @@ -212,3 +216,17 @@ void GameSelector::processGameInfo(const ServerInfo_Game &info) { gameListModel->updateGameList(info); } + +void GameSelector::updateButtonChoices(const QModelIndex &index) +{ + if (!index.isValid()) + return; + + const ServerInfo_Game &game = gameListModel->getGame(index.data(Qt::UserRole).toInt()); + bool overrideRestrictions = !tabSupervisor->getAdminLocked(); + + if (game.spectators_allowed() || overrideRestrictions) + spectateButton->setEnabled(true); + else + spectateButton->setEnabled(false); +} diff --git a/cockatrice/src/gameselector.h b/cockatrice/src/gameselector.h index 9d1d1ffe..421726e1 100644 --- a/cockatrice/src/gameselector.h +++ b/cockatrice/src/gameselector.h @@ -23,6 +23,7 @@ private slots: void actCreate(); void actJoin(); void checkResponse(const Response &response); + void updateButtonChoices(const QModelIndex &); signals: void gameJoined(int gameId); private: