mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 19:13:55 -07:00
moderators can override game restrictions and kick players when spectating; game host privileges shift when host leaves
This commit is contained in:
parent
bca7b6414b
commit
c7ef61f750
22 changed files with 165 additions and 90 deletions
|
|
@ -6,14 +6,15 @@
|
|||
#include <QMessageBox>
|
||||
#include <QHeaderView>
|
||||
#include <QInputDialog>
|
||||
#include "tab_supervisor.h"
|
||||
#include "dlg_creategame.h"
|
||||
#include "abstractclient.h"
|
||||
#include "protocol_items.h"
|
||||
#include "gameselector.h"
|
||||
#include "gamesmodel.h"
|
||||
|
||||
GameSelector::GameSelector(AbstractClient *_client, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent)
|
||||
: QGroupBox(parent), client(_client), room(_room)
|
||||
GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent)
|
||||
: QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room)
|
||||
{
|
||||
gameListView = new QTreeView;
|
||||
gameListModel = new GamesModel(_rooms, _gameTypes, this);
|
||||
|
|
@ -115,15 +116,16 @@ void GameSelector::actJoin()
|
|||
if (!ind.isValid())
|
||||
return;
|
||||
ServerInfo_Game *game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
|
||||
bool overrideRestrictions = !tabSupervisor->getAdminLocked();
|
||||
QString password;
|
||||
if (game->getHasPassword() && !(spectator && !game->getSpectatorsNeedPassword())) {
|
||||
if (game->getHasPassword() && !(spectator && !game->getSpectatorsNeedPassword()) && !overrideRestrictions) {
|
||||
bool ok;
|
||||
password = QInputDialog::getText(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok);
|
||||
if (!ok)
|
||||
return;
|
||||
}
|
||||
|
||||
Command_JoinGame *commandJoinGame = new Command_JoinGame(game->getRoomId(), game->getGameId(), password, spectator);
|
||||
Command_JoinGame *commandJoinGame = new Command_JoinGame(game->getRoomId(), game->getGameId(), password, spectator, overrideRestrictions);
|
||||
connect(commandJoinGame, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
|
||||
client->sendCommand(commandJoinGame);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ class GamesProxyModel;
|
|||
class QPushButton;
|
||||
class QCheckBox;
|
||||
class AbstractClient;
|
||||
class TabSupervisor;
|
||||
class TabRoom;
|
||||
|
||||
class GameSelector : public QGroupBox {
|
||||
|
|
@ -26,6 +27,7 @@ signals:
|
|||
void gameJoined(int gameId);
|
||||
private:
|
||||
AbstractClient *client;
|
||||
TabSupervisor *tabSupervisor;
|
||||
TabRoom *room;
|
||||
|
||||
QTreeView *gameListView;
|
||||
|
|
@ -34,7 +36,7 @@ private:
|
|||
QPushButton *createButton, *joinButton, *spectateButton;
|
||||
QCheckBox *showFullGamesCheckBox, *showRunningGamesCheckBox;
|
||||
public:
|
||||
GameSelector(AbstractClient *_client, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent = 0);
|
||||
GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
void processGameInfo(ServerInfo_Game *info);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ extern CardDatabase *db;
|
|||
|
||||
extern QTranslator *translator;
|
||||
const QString translationPrefix = "cockatrice";
|
||||
const QString versionString = "0.20111101";
|
||||
const QString versionString = "0.20111113";
|
||||
|
||||
void installNewTranslator();
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#include "protocol_items.h"
|
||||
#include "userlist.h"
|
||||
#include "userinfobox.h"
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
|
@ -46,8 +45,8 @@ bool PlayerListTWI::operator<(const QTreeWidgetItem &other) const
|
|||
return data(4, Qt::UserRole + 1).toInt() < other.data(4, Qt::UserRole + 1).toInt();
|
||||
}
|
||||
|
||||
PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, bool _gameCreator, QWidget *parent)
|
||||
: QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameCreator(_gameCreator), gameStarted(false)
|
||||
PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent)
|
||||
: QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameStarted(false)
|
||||
{
|
||||
readyIcon = QIcon(":/resources/icon_ready_start.svg");
|
||||
notReadyIcon = QIcon(":/resources/icon_not_ready_start.svg");
|
||||
|
|
@ -179,10 +178,18 @@ void PlayerListWidget::showContextMenu(const QPoint &pos, const QModelIndex &ind
|
|||
else
|
||||
menu->addAction(aAddToIgnoreList);
|
||||
}
|
||||
if (gameCreator) {
|
||||
if (game->isHost() || !game->getTabSupervisor()->getAdminLocked()) {
|
||||
menu->addSeparator();
|
||||
menu->addAction(aKick);
|
||||
}
|
||||
if (userName == game->getTabSupervisor()->getUserInfo()->getName()) {
|
||||
aChat->setEnabled(false);
|
||||
aAddToBuddyList->setEnabled(false);
|
||||
aRemoveFromBuddyList->setEnabled(false);
|
||||
aAddToIgnoreList->setEnabled(false);
|
||||
aRemoveFromIgnoreList->setEnabled(false);
|
||||
aKick->setEnabled(false);
|
||||
}
|
||||
|
||||
QAction *actionClicked = menu->exec(pos);
|
||||
if (actionClicked == aDetails) {
|
||||
|
|
|
|||
|
|
@ -31,13 +31,12 @@ private:
|
|||
TabSupervisor *tabSupervisor;
|
||||
AbstractClient *client;
|
||||
TabGame *game;
|
||||
bool gameCreator;
|
||||
QIcon readyIcon, notReadyIcon, concededIcon, playerIcon, spectatorIcon;
|
||||
bool gameStarted;
|
||||
signals:
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
public:
|
||||
PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, bool _gameCreator, QWidget *parent = 0);
|
||||
PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
void addPlayer(ServerInfo_PlayerProperties *player);
|
||||
void removePlayer(int playerId);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ private:
|
|||
public:
|
||||
Tab(TabSupervisor *_tabSupervisor, QWidget *parent = 0);
|
||||
QMenu *getTabMenu() const { return tabMenu; }
|
||||
TabSupervisor *getTabSupervisor() const { return tabSupervisor; }
|
||||
bool getContentsChanged() const { return contentsChanged; }
|
||||
void setContentsChanged(bool _contentsChanged) { contentsChanged = _contentsChanged; }
|
||||
virtual QString getTabText() const = 0;
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ void TabAdmin::actUnlock()
|
|||
lockButton->setEnabled(true);
|
||||
unlockButton->setEnabled(false);
|
||||
locked = false;
|
||||
emit adminLockChanged(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,4 +129,5 @@ void TabAdmin::actLock()
|
|||
lockButton->setEnabled(false);
|
||||
unlockButton->setEnabled(true);
|
||||
locked = true;
|
||||
}
|
||||
emit adminLockChanged(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ private:
|
|||
QPushButton *updateServerMessageButton, *shutdownServerButton;
|
||||
QGroupBox *adminGroupBox;
|
||||
QPushButton *unlockButton, *lockButton;
|
||||
signals:
|
||||
void adminLockChanged(bool lock);
|
||||
private slots:
|
||||
void actUpdateServerMessage();
|
||||
void actShutdownServer();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include "tab_game.h"
|
||||
#include "tab_supervisor.h"
|
||||
#include "cardinfowidget.h"
|
||||
#include "playerlistwidget.h"
|
||||
#include "messagelogwidget.h"
|
||||
|
|
@ -158,8 +159,8 @@ void DeckViewContainer::setDeck(DeckList *deck)
|
|||
readyStartButton->setEnabled(true);
|
||||
}
|
||||
|
||||
TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _localPlayerId, ServerInfo_User *_userInfo, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming)
|
||||
: Tab(_tabSupervisor), clients(_clients), gameId(_gameId), gameDescription(_gameDescription), localPlayerId(_localPlayerId), spectator(_spectator), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), gameStateKnown(false), started(false), resuming(_resuming), currentPhase(-1)
|
||||
TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _hostId, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming)
|
||||
: Tab(_tabSupervisor), clients(_clients), gameId(_gameId), gameDescription(_gameDescription), hostId(_hostId), localPlayerId(_localPlayerId), spectator(_spectator), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), gameStateKnown(false), started(false), resuming(_resuming), currentPhase(-1)
|
||||
{
|
||||
phasesToolbar = new PhasesToolbar;
|
||||
phasesToolbar->hide();
|
||||
|
|
@ -170,13 +171,13 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
|
|||
gameView->hide();
|
||||
|
||||
cardInfo = new CardInfoWidget(CardInfoWidget::ModeGameTab);
|
||||
playerListWidget = new PlayerListWidget(tabSupervisor, clients.first(), this, true);
|
||||
playerListWidget = new PlayerListWidget(tabSupervisor, clients.first(), this);
|
||||
playerListWidget->setFocusPolicy(Qt::NoFocus);
|
||||
connect(playerListWidget, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
|
||||
|
||||
timeElapsedLabel = new QLabel;
|
||||
timeElapsedLabel->setAlignment(Qt::AlignCenter);
|
||||
messageLog = new MessageLogWidget(_userInfo->getName(), _userInfo->getGender() == ServerInfo_User::Female);
|
||||
messageLog = new MessageLogWidget(tabSupervisor->getUserInfo()->getName(), tabSupervisor->getUserInfo()->getGender() == ServerInfo_User::Female);
|
||||
connect(messageLog, SIGNAL(cardNameHovered(QString)), cardInfo, SLOT(setCard(QString)));
|
||||
connect(messageLog, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
|
||||
connect(messageLog, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
||||
|
|
@ -208,11 +209,11 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
|
|||
mainLayout->addLayout(deckViewContainerLayout, 10);
|
||||
mainLayout->addWidget(splitter);
|
||||
|
||||
if (spectator && !spectatorsCanTalk) {
|
||||
if (spectator && !spectatorsCanTalk && tabSupervisor->getAdminLocked()) {
|
||||
sayLabel->hide();
|
||||
sayEdit->hide();
|
||||
}
|
||||
|
||||
connect(tabSupervisor, SIGNAL(adminLockChanged(bool)), this, SLOT(adminLockChanged(bool)));
|
||||
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay()));
|
||||
|
||||
// Menu actions
|
||||
|
|
@ -314,6 +315,13 @@ void TabGame::closeRequest()
|
|||
actLeaveGame();
|
||||
}
|
||||
|
||||
void TabGame::adminLockChanged(bool lock)
|
||||
{
|
||||
bool v = !(spectator && !spectatorsCanTalk && lock);
|
||||
sayLabel->setVisible(v);
|
||||
sayEdit->setVisible(v);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -433,6 +441,7 @@ void TabGame::processGameEventContainer(GameEventContainer *cont, AbstractClient
|
|||
case ItemId_Event_Join: eventJoin(static_cast<Event_Join *>(event), context); break;
|
||||
case ItemId_Event_Leave: eventLeave(static_cast<Event_Leave *>(event), context); break;
|
||||
case ItemId_Event_Kicked: eventKicked(static_cast<Event_Kicked *>(event), context); break;
|
||||
case ItemId_Event_GameHostChanged: eventGameHostChanged(static_cast<Event_GameHostChanged *>(event), context); break;
|
||||
case ItemId_Event_GameClosed: eventGameClosed(static_cast<Event_GameClosed *>(event), context); break;
|
||||
case ItemId_Event_SetActivePlayer: eventSetActivePlayer(static_cast<Event_SetActivePlayer *>(event), context); break;
|
||||
case ItemId_Event_SetActivePhase: eventSetActivePhase(static_cast<Event_SetActivePhase *>(event), context); break;
|
||||
|
|
@ -672,6 +681,11 @@ void TabGame::eventKicked(Event_Kicked * /*event*/, GameEventContext * /*context
|
|||
deleteLater();
|
||||
}
|
||||
|
||||
void TabGame::eventGameHostChanged(Event_GameHostChanged *event, GameEventContext * /*context*/)
|
||||
{
|
||||
hostId = event->getPlayerId();
|
||||
}
|
||||
|
||||
void TabGame::eventGameClosed(Event_GameClosed * /*event*/, GameEventContext * /*context*/)
|
||||
{
|
||||
started = false;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class Event_GameStateChanged;
|
|||
class Event_PlayerPropertiesChanged;
|
||||
class Event_Join;
|
||||
class Event_Leave;
|
||||
class Event_GameHostChanged;
|
||||
class Event_GameClosed;
|
||||
class Event_GameStart;
|
||||
class Event_SetActivePlayer;
|
||||
|
|
@ -88,6 +89,7 @@ private:
|
|||
QList<AbstractClient *> clients;
|
||||
int gameId;
|
||||
QString gameDescription;
|
||||
int hostId;
|
||||
int localPlayerId;
|
||||
bool spectator;
|
||||
bool spectatorsCanTalk, spectatorsSeeEverything;
|
||||
|
|
@ -132,6 +134,7 @@ private:
|
|||
void eventJoin(Event_Join *event, GameEventContext *context);
|
||||
void eventLeave(Event_Leave *event, GameEventContext *context);
|
||||
void eventKicked(Event_Kicked *event, GameEventContext *context);
|
||||
void eventGameHostChanged(Event_GameHostChanged *event, GameEventContext *context);
|
||||
void eventGameClosed(Event_GameClosed *event, GameEventContext *context);
|
||||
Player *setActivePlayer(int id);
|
||||
void eventSetActivePlayer(Event_SetActivePlayer *event, GameEventContext *context);
|
||||
|
|
@ -146,6 +149,7 @@ signals:
|
|||
void containerProcessingDone();
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
private slots:
|
||||
void adminLockChanged(bool lock);
|
||||
void newCardAdded(AbstractCardItem *card);
|
||||
|
||||
void actConcede();
|
||||
|
|
@ -156,12 +160,13 @@ private slots:
|
|||
void actNextPhase();
|
||||
void actNextTurn();
|
||||
public:
|
||||
TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _localPlayerId, ServerInfo_User *_userInfo, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming);
|
||||
TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _hostId, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming);
|
||||
~TabGame();
|
||||
void retranslateUi();
|
||||
void closeRequest();
|
||||
const QMap<int, Player *> &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; }
|
||||
QString getTabText() const { return tr("Game %1: %2").arg(gameId).arg(gameDescription); }
|
||||
bool getSpectator() const { return spectator; }
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
|
|||
|
||||
QMap<int, GameTypeMap> tempMap;
|
||||
tempMap.insert(info->getRoomId(), gameTypes);
|
||||
gameSelector = new GameSelector(client, this, QMap<int, QString>(), tempMap);
|
||||
gameSelector = new GameSelector(client, tabSupervisor, this, QMap<int, QString>(), tempMap);
|
||||
userList = new UserList(tabSupervisor, client, UserList::RoomList);
|
||||
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
|
||||
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ void TabSupervisor::start(AbstractClient *_client, ServerInfo_User *_userInfo)
|
|||
|
||||
if (userInfo->getUserLevel() & ServerInfo_User::IsModerator) {
|
||||
tabAdmin = new TabAdmin(this, client, (userInfo->getUserLevel() & ServerInfo_User::IsAdmin));
|
||||
connect(tabAdmin, SIGNAL(adminLockChanged(bool)), this, SIGNAL(adminLockChanged(bool)));
|
||||
myAddTab(tabAdmin);
|
||||
} else
|
||||
tabAdmin = 0;
|
||||
|
|
@ -227,7 +228,7 @@ void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex)
|
|||
|
||||
void TabSupervisor::gameJoined(Event_GameJoined *event)
|
||||
{
|
||||
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event->getGameId(), event->getGameDescription(), event->getPlayerId(), userInfo, event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
|
||||
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event->getGameId(), event->getGameDescription(), event->getHostId(), event->getPlayerId(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
|
||||
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);
|
||||
|
|
@ -238,7 +239,7 @@ void TabSupervisor::gameJoined(Event_GameJoined *event)
|
|||
|
||||
void TabSupervisor::localGameJoined(Event_GameJoined *event)
|
||||
{
|
||||
TabGame *tab = new TabGame(this, localClients, event->getGameId(), event->getGameDescription(), event->getPlayerId(), userInfo, event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
|
||||
TabGame *tab = new TabGame(this, localClients, event->getGameId(), event->getGameDescription(), event->getHostId(), event->getPlayerId(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
|
||||
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
|
||||
int tabIndex = myAddTab(tab);
|
||||
addCloseButtonToTab(tab, tabIndex);
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ public:
|
|||
signals:
|
||||
void setMenu(QMenu *menu);
|
||||
void localGameEnded();
|
||||
void adminLockChanged(bool lock);
|
||||
private slots:
|
||||
void closeButtonPressed();
|
||||
void updateCurrent(int index);
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ void UserList::gamesOfUserReceived(ProtocolResponse *resp)
|
|||
gameTypeMap.insert(roomList[i]->getRoomId(), tempMap);
|
||||
}
|
||||
|
||||
GameSelector *selector = new GameSelector(client, 0, roomMap, gameTypeMap);
|
||||
GameSelector *selector = new GameSelector(client, tabSupervisor, 0, roomMap, gameTypeMap);
|
||||
const QList<ServerInfo_Game *> gameList = response->getGameList();
|
||||
for (int i = 0; i < gameList.size(); ++i)
|
||||
selector->processGameInfo(gameList[i]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue