Merge branch 'master' of git://cockatrice.git.sourceforge.net/gitroot/cockatrice/cockatrice

This commit is contained in:
Max-Wilhelm Bruker 2011-01-28 03:29:41 +01:00
commit a1b6f31b17
45 changed files with 4915 additions and 1606 deletions

View file

@ -174,7 +174,8 @@ TRANSLATIONS += \
translations/cockatrice_pt.ts \
translations/cockatrice_pt-br.ts \
translations/cockatrice_fr.ts \
translations/cockatrice_ja.ts
translations/cockatrice_ja.ts \
translations/cockatrice_ru.ts
win32 {
RC_FILE = cockatrice.rc
}

View file

@ -24,13 +24,6 @@
<file>resources/icon_search.svg</file>
<file>resources/icon_clearsearch.svg</file>
<file>resources/hr.jpg</file>
<file>translations/cockatrice_de.qm</file>
<file>translations/cockatrice_en.qm</file>
<file>translations/cockatrice_es.qm</file>
<file>translations/cockatrice_pt.qm</file>
<file>translations/cockatrice_pt-br.qm</file>
<file>translations/cockatrice_fr.qm</file>
<file>translations/cockatrice_ja.qm</file>
<file>resources/appicon.svg</file>
<file>resources/add_to_sideboard.svg</file>
<file>resources/decrement.svg</file>
@ -44,6 +37,15 @@
<file>resources/icon_player.svg</file>
<file>resources/icon_spectator.svg</file>
<file>translations/cockatrice_de.qm</file>
<file>translations/cockatrice_en.qm</file>
<file>translations/cockatrice_es.qm</file>
<file>translations/cockatrice_pt.qm</file>
<file>translations/cockatrice_pt-br.qm</file>
<file>translations/cockatrice_fr.qm</file>
<file>translations/cockatrice_ja.qm</file>
<file>translations/cockatrice_ru.qm</file>
<file>resources/countries/at.svg</file>
<file>resources/countries/au.svg</file>
<file>resources/countries/be.svg</file>

View file

@ -97,13 +97,13 @@ void AbstractCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
event->ignore();
}
void AbstractCounter::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void AbstractCounter::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/)
{
hovered = true;
update();
}
void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
{
hovered = false;
update();

View file

@ -8,35 +8,37 @@ ChatView::ChatView(const QString &_ownName, QWidget *parent)
: QTextEdit(parent), ownName(_ownName)
{
setTextInteractionFlags(Qt::TextSelectableByMouse);
QTextTableFormat format;
format.setBorderStyle(QTextFrameFormat::BorderStyle_None);
table = textCursor().insertTable(1, 3, format);
}
void ChatView::appendMessage(const QString &sender, const QString &message)
{
QTextCursor cellCursor = table->cellAt(table->rows() - 1, 0).lastCursorPosition();
cellCursor.insertText(QDateTime::currentDateTime().toString("[hh:mm]"));
QTextTableCell senderCell = table->cellAt(table->rows() - 1, 1);
QTextCursor cursor(document()->lastBlock());
cursor.movePosition(QTextCursor::End);
QTextBlockFormat blockFormat;
blockFormat.setBottomMargin(3);
cursor.insertBlock(blockFormat);
QTextCharFormat timeFormat;
timeFormat.setForeground(Qt::black);
cursor.setCharFormat(timeFormat);
cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm] "));
QTextCharFormat senderFormat;
if (sender == ownName) {
senderFormat.setFontWeight(QFont::Bold);
senderFormat.setForeground(Qt::red);
} else
senderFormat.setForeground(Qt::blue);
senderCell.setFormat(senderFormat);
cellCursor = senderCell.lastCursorPosition();
cellCursor.insertText(sender);
QTextTableCell messageCell = table->cellAt(table->rows() - 1, 2);
cursor.setCharFormat(senderFormat);
cursor.insertText(sender + " ");
QTextCharFormat messageFormat;
if (sender.isEmpty())
messageFormat.setForeground(Qt::darkGreen);
messageCell.setFormat(messageFormat);
cellCursor = messageCell.lastCursorPosition();
cellCursor.insertText(message);
cursor.setCharFormat(messageFormat);
cursor.insertText(message);
table->appendRows(1);
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
}

View file

@ -11,8 +11,8 @@
#include "dlg_creategame.h"
#include "protocol_items.h"
DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *parent)
: QDialog(parent), client(_client), roomId(_roomId)
DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, const QMap<int, QString> &_gameTypes, QWidget *parent)
: QDialog(parent), client(_client), roomId(_roomId), gameTypes(_gameTypes)
{
descriptionLabel = new QLabel(tr("&Description:"));
descriptionEdit = new QLineEdit;
@ -29,6 +29,17 @@ DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *pare
maxPlayersEdit->setValue(2);
maxPlayersLabel->setBuddy(maxPlayersEdit);
QVBoxLayout *gameTypeLayout = new QVBoxLayout;
QMapIterator<int, QString> gameTypeIterator(gameTypes);
while (gameTypeIterator.hasNext()) {
gameTypeIterator.next();
QCheckBox *gameTypeCheckBox = new QCheckBox(gameTypeIterator.value());
gameTypeLayout->addWidget(gameTypeCheckBox);
gameTypeCheckBoxes.insert(gameTypeIterator.key(), gameTypeCheckBox);
}
QGroupBox *gameTypeGroupBox = new QGroupBox(tr("Game type"));
gameTypeGroupBox->setLayout(gameTypeLayout);
spectatorsAllowedCheckBox = new QCheckBox(tr("&Spectators allowed"));
spectatorsAllowedCheckBox->setChecked(true);
connect(spectatorsAllowedCheckBox, SIGNAL(stateChanged(int)), this, SLOT(spectatorsAllowedChanged(int)));
@ -50,7 +61,8 @@ DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *pare
grid->addWidget(passwordEdit, 1, 1);
grid->addWidget(maxPlayersLabel, 2, 0);
grid->addWidget(maxPlayersEdit, 2, 1);
grid->addWidget(spectatorsGroupBox, 3, 0, 1, 2);
grid->addWidget(gameTypeGroupBox, 3, 0, 1, 2);
grid->addWidget(spectatorsGroupBox, 4, 0, 1, 2);
okButton = new QPushButton(tr("&OK"));
okButton->setDefault(true);
@ -76,11 +88,20 @@ DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *pare
void DlgCreateGame::actOK()
{
QList<GameTypeId *> gameTypeList;
QMapIterator<int, QCheckBox *> gameTypeCheckBoxIterator(gameTypeCheckBoxes);
while (gameTypeCheckBoxIterator.hasNext()) {
gameTypeCheckBoxIterator.next();
if (gameTypeCheckBoxIterator.value()->isChecked())
gameTypeList.append(new GameTypeId(gameTypeCheckBoxIterator.key()));
}
Command_CreateGame *createCommand = new Command_CreateGame(
roomId,
descriptionEdit->text(),
passwordEdit->text(),
maxPlayersEdit->value(),
gameTypeList,
spectatorsAllowedCheckBox->isChecked(),
spectatorsNeedPasswordCheckBox->isChecked(),
spectatorsCanTalkCheckBox->isChecked(),

View file

@ -14,7 +14,7 @@ class QSpinBox;
class DlgCreateGame : public QDialog {
Q_OBJECT
public:
DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *parent = 0);
DlgCreateGame(AbstractClient *_client, int _roomId, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
private slots:
void actOK();
void checkResponse(ResponseCode response);
@ -22,6 +22,8 @@ private slots:
private:
AbstractClient *client;
int roomId;
QMap<int, QString> gameTypes;
QMap<int, QCheckBox *> gameTypeCheckBoxes;
QGroupBox *spectatorsGroupBox;
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;

View file

@ -1,6 +1,11 @@
#include "gamesmodel.h"
#include "protocol_datastructures.h"
GamesModel::GamesModel(const QMap<int, QString> &_gameTypes, QObject *parent)
: QAbstractTableModel(parent), gameTypes(_gameTypes)
{
}
GamesModel::~GamesModel()
{
if (!gameList.isEmpty()) {
@ -27,9 +32,16 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
switch (index.column()) {
case 0: return g->getDescription();
case 1: return g->getCreatorInfo()->getName();
case 2: return g->getHasPassword() ? (g->getSpectatorsNeedPassword() ? tr("yes") : tr("yes, free for spectators")) : tr("no");
case 3: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
case 4: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorCount()) : QVariant(tr("not allowed"));
case 2: {
QStringList result;
QList<GameTypeId *> gameTypeList = g->getGameTypes();
for (int i = 0; i < gameTypeList.size(); ++i)
result.append(gameTypes.value(gameTypeList[i]->getData()));
return result.join(", ");
}
case 3: return g->getHasPassword() ? (g->getSpectatorsNeedPassword() ? tr("yes") : tr("yes, free for spectators")) : tr("no");
case 4: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
case 5: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorCount()) : QVariant(tr("not allowed"));
default: return QVariant();
}
}
@ -41,9 +53,10 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro
switch (section) {
case 0: return tr("Description");
case 1: return tr("Creator");
case 2: return tr("Password");
case 3: return tr("Players");
case 4: return tr("Spectators");
case 2: return tr("Game type");
case 3: return tr("Password");
case 4: return tr("Players");
case 5: return tr("Spectators");
default: return QVariant();
}
}
@ -56,7 +69,11 @@ ServerInfo_Game *GamesModel::getGame(int row)
void GamesModel::updateGameList(ServerInfo_Game *_game)
{
ServerInfo_Game *game = new ServerInfo_Game(_game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), new ServerInfo_User(_game->getCreatorInfo()), _game->getSpectatorsAllowed(), _game->getSpectatorsNeedPassword(), _game->getSpectatorCount());
QList<GameTypeId *> gameTypeList, oldGameTypeList = _game->getGameTypes();
for (int i = 0; i < oldGameTypeList.size(); ++i)
gameTypeList.append(new GameTypeId(oldGameTypeList[i]->getData()));
ServerInfo_Game *game = new ServerInfo_Game(_game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), gameTypeList, new ServerInfo_User(_game->getCreatorInfo()), _game->getSpectatorsAllowed(), _game->getSpectatorsNeedPassword(), _game->getSpectatorCount());
for (int i = 0; i < gameList.size(); i++)
if (gameList[i]->getGameId() == game->getGameId()) {
if (game->getPlayerCount() == 0) {

View file

@ -9,8 +9,11 @@ class ServerInfo_Game;
class GamesModel : public QAbstractTableModel {
Q_OBJECT
private:
QList<ServerInfo_Game *> gameList;
QMap<int, QString> gameTypes;
public:
GamesModel(QObject *parent = 0) : QAbstractTableModel(parent) { }
GamesModel(const QMap<int, QString> &_gameTypes, QObject *parent = 0);
~GamesModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : gameList.size(); }
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 5; }
@ -19,8 +22,6 @@ public:
ServerInfo_Game *getGame(int row);
void updateGameList(ServerInfo_Game *game);
private:
QList<ServerInfo_Game *> gameList;
};
class GamesProxyModel : public QSortFilterProxyModel {

View file

@ -5,7 +5,7 @@
LocalServer::LocalServer(QObject *parent)
: Server(parent)
{
addRoom(new Server_Room(0, QString(), QString(), false, QString(), this));
addRoom(new Server_Room(0, QString(), QString(), false, QString(), QStringList(), this));
}
LocalServer::~LocalServer()

View file

@ -138,6 +138,14 @@ void MessageLogWidget::logDrawCards(Player *player, int number)
append(tr("%1 draws %2 cards.").arg(sanitizeHtml(player->getName())).arg(number));
}
void MessageLogWidget::logUndoDraw(Player *player, QString cardName)
{
if (cardName.isEmpty())
append(tr("%1 undoes his last draw.").arg(sanitizeHtml(player->getName())));
else
append(tr("%1 undoes his last draw (%2).").arg(sanitizeHtml(player->getName())).arg(sanitizeHtml(cardName)));
}
QPair<QString, QString> MessageLogWidget::getFromStr(CardZone *zone, QString cardName, int position) const
{
bool cardNameContainsStartZone = false;
@ -428,6 +436,7 @@ void MessageLogWidget::connectToPlayer(Player *player)
connect(player, SIGNAL(logDumpZone(Player *, CardZone *, int)), this, SLOT(logDumpZone(Player *, CardZone *, int)));
connect(player, SIGNAL(logStopDumpZone(Player *, CardZone *)), this, SLOT(logStopDumpZone(Player *, CardZone *)));
connect(player, SIGNAL(logDrawCards(Player *, int)), this, SLOT(logDrawCards(Player *, int)));
connect(player, SIGNAL(logUndoDraw(Player *, QString)), this, SLOT(logUndoDraw(Player *, QString)));
connect(player, SIGNAL(logRevealCards(Player *, CardZone *, int, QString, Player *)), this, SLOT(logRevealCards(Player *, CardZone *, int, QString, Player *)));
}

View file

@ -47,6 +47,7 @@ public slots:
void logShuffle(Player *player);
void logRollDie(Player *player, int sides, int roll);
void logDrawCards(Player *player, int number);
void logUndoDraw(Player *player, QString cardName);
void logMoveCard(Player *player, QString cardName, CardZone *startZone, int oldX, CardZone *targetZone, int newX);
void logFlipCard(Player *player, QString cardName, bool faceDown);
void logDestroyCard(Player *player, QString cardName);

View file

@ -130,6 +130,8 @@ Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
connect(aDrawCard, SIGNAL(triggered()), this, SLOT(actDrawCard()));
aDrawCards = new QAction(this);
connect(aDrawCards, SIGNAL(triggered()), this, SLOT(actDrawCards()));
aUndoDraw = new QAction(this);
connect(aUndoDraw, SIGNAL(triggered()), this, SLOT(actUndoDraw()));
aShuffle = new QAction(this);
connect(aShuffle, SIGNAL(triggered()), this, SLOT(actShuffle()));
aMulligan = new QAction(this);
@ -159,6 +161,7 @@ Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
libraryMenu = playerMenu->addMenu(QString());
libraryMenu->addAction(aDrawCard);
libraryMenu->addAction(aDrawCards);
libraryMenu->addAction(aUndoDraw);
libraryMenu->addSeparator();
libraryMenu->addAction(aShuffle);
libraryMenu->addSeparator();
@ -409,6 +412,7 @@ void Player::retranslateUi()
aViewSideboard->setText(tr("&View sideboard"));
aDrawCard->setText(tr("&Draw card"));
aDrawCards->setText(tr("D&raw cards..."));
aUndoDraw->setText(tr("&Undo last draw"));
aMulligan->setText(tr("Take &mulligan"));
aShuffle->setText(tr("&Shuffle"));
aMoveTopCardsToGrave->setText(tr("Move top cards to &graveyard..."));
@ -447,11 +451,13 @@ void Player::setShortcutsActive()
{
shortcutsActive = true;
aViewSideboard->setShortcut(tr("Ctrl+F3"));
aViewLibrary->setShortcut(tr("F3"));
aViewTopCards->setShortcut(tr("Ctrl+W"));
aViewGraveyard->setShortcut(tr("F4"));
aDrawCard->setShortcut(tr("Ctrl+D"));
aDrawCards->setShortcut(tr("Ctrl+E"));
aUndoDraw->setShortcut(tr("Ctrl+Shift+D"));
aMulligan->setShortcut(tr("Ctrl+M"));
aShuffle->setShortcut(tr("Ctrl+S"));
aUntapAll->setShortcut(tr("Ctrl+U"));
@ -468,11 +474,13 @@ void Player::setShortcutsInactive()
{
shortcutsActive = false;
aViewSideboard->setShortcut(QKeySequence());
aViewLibrary->setShortcut(QKeySequence());
aViewTopCards->setShortcut(QKeySequence());
aViewGraveyard->setShortcut(QKeySequence());
aDrawCard->setShortcut(QKeySequence());
aDrawCards->setShortcut(QKeySequence());
aUndoDraw->setShortcut(QKeySequence());
aMulligan->setShortcut(QKeySequence());
aShuffle->setShortcut(QKeySequence());
aUntapAll->setShortcut(QKeySequence());
@ -553,6 +561,11 @@ void Player::actDrawCards()
sendGameCommand(new Command_DrawCards(-1, number));
}
void Player::actUndoDraw()
{
sendGameCommand(new Command_UndoDraw);
}
void Player::actMoveTopCardsToGrave()
{
int number = QInputDialog::getInteger(0, tr("Move top cards to grave"), tr("Number:"));
@ -791,7 +804,7 @@ void Player::eventStopDumpZone(Event_StopDumpZone *event)
emit logStopDumpZone(this, zone);
}
void Player::eventMoveCard(Event_MoveCard *event)
void Player::eventMoveCard(Event_MoveCard *event, GameEventContext *context)
{
CardZone *startZone = zones.value(event->getStartZone(), 0);
Player *targetPlayer = static_cast<TabGame *>(parent())->getPlayers().value(event->getTargetPlayerId());
@ -838,7 +851,13 @@ void Player::eventMoveCard(Event_MoveCard *event)
// The log event has to be sent before the card is added to the target zone
// because the addCard function can modify the card object.
emit logMoveCard(this, card->getName(), startZone, logPosition, targetZone, logX);
if (context)
switch (context->getItemId()) {
case ItemId_Context_UndoDraw: emit logUndoDraw(this, card->getName()); break;
default: ;
}
else
emit logMoveCard(this, card->getName(), startZone, logPosition, targetZone, logX);
targetZone->addCard(card, true, x, y);
@ -981,25 +1000,25 @@ void Player::processGameEvent(GameEvent *event, GameEventContext *context)
{
qDebug() << "player event: id=" << event->getItemId();
switch (event->getItemId()) {
case ItemId_Event_Say: eventSay(qobject_cast<Event_Say *>(event)); break;
case ItemId_Event_Shuffle: eventShuffle(qobject_cast<Event_Shuffle *>(event)); break;
case ItemId_Event_RollDie: eventRollDie(qobject_cast<Event_RollDie *>(event)); break;
case ItemId_Event_CreateArrows: eventCreateArrows(qobject_cast<Event_CreateArrows *>(event)); break;
case ItemId_Event_DeleteArrow: eventDeleteArrow(qobject_cast<Event_DeleteArrow *>(event)); break;
case ItemId_Event_CreateToken: eventCreateToken(qobject_cast<Event_CreateToken *>(event)); break;
case ItemId_Event_SetCardAttr: eventSetCardAttr(qobject_cast<Event_SetCardAttr *>(event)); break;
case ItemId_Event_SetCardCounter: eventSetCardCounter(qobject_cast<Event_SetCardCounter *>(event)); break;
case ItemId_Event_CreateCounters: eventCreateCounters(qobject_cast<Event_CreateCounters *>(event)); break;
case ItemId_Event_SetCounter: eventSetCounter(qobject_cast<Event_SetCounter *>(event)); break;
case ItemId_Event_DelCounter: eventDelCounter(qobject_cast<Event_DelCounter *>(event)); break;
case ItemId_Event_DumpZone: eventDumpZone(qobject_cast<Event_DumpZone *>(event)); break;
case ItemId_Event_StopDumpZone: eventStopDumpZone(qobject_cast<Event_StopDumpZone *>(event)); break;
case ItemId_Event_MoveCard: eventMoveCard(qobject_cast<Event_MoveCard *>(event)); break;
case ItemId_Event_FlipCard: eventFlipCard(qobject_cast<Event_FlipCard *>(event)); break;
case ItemId_Event_DestroyCard: eventDestroyCard(qobject_cast<Event_DestroyCard *>(event)); break;
case ItemId_Event_AttachCard: eventAttachCard(qobject_cast<Event_AttachCard *>(event)); break;
case ItemId_Event_DrawCards: eventDrawCards(qobject_cast<Event_DrawCards *>(event)); break;
case ItemId_Event_RevealCards: eventRevealCards(qobject_cast<Event_RevealCards *>(event)); break;
case ItemId_Event_Say: eventSay(static_cast<Event_Say *>(event)); break;
case ItemId_Event_Shuffle: eventShuffle(static_cast<Event_Shuffle *>(event)); break;
case ItemId_Event_RollDie: eventRollDie(static_cast<Event_RollDie *>(event)); break;
case ItemId_Event_CreateArrows: eventCreateArrows(static_cast<Event_CreateArrows *>(event)); break;
case ItemId_Event_DeleteArrow: eventDeleteArrow(static_cast<Event_DeleteArrow *>(event)); break;
case ItemId_Event_CreateToken: eventCreateToken(static_cast<Event_CreateToken *>(event)); break;
case ItemId_Event_SetCardAttr: eventSetCardAttr(static_cast<Event_SetCardAttr *>(event)); break;
case ItemId_Event_SetCardCounter: eventSetCardCounter(static_cast<Event_SetCardCounter *>(event)); break;
case ItemId_Event_CreateCounters: eventCreateCounters(static_cast<Event_CreateCounters *>(event)); break;
case ItemId_Event_SetCounter: eventSetCounter(static_cast<Event_SetCounter *>(event)); break;
case ItemId_Event_DelCounter: eventDelCounter(static_cast<Event_DelCounter *>(event)); break;
case ItemId_Event_DumpZone: eventDumpZone(static_cast<Event_DumpZone *>(event)); break;
case ItemId_Event_StopDumpZone: eventStopDumpZone(static_cast<Event_StopDumpZone *>(event)); break;
case ItemId_Event_MoveCard: eventMoveCard(static_cast<Event_MoveCard *>(event), context); break;
case ItemId_Event_FlipCard: eventFlipCard(static_cast<Event_FlipCard *>(event)); break;
case ItemId_Event_DestroyCard: eventDestroyCard(static_cast<Event_DestroyCard *>(event)); break;
case ItemId_Event_AttachCard: eventAttachCard(static_cast<Event_AttachCard *>(event)); break;
case ItemId_Event_DrawCards: eventDrawCards(static_cast<Event_DrawCards *>(event)); break;
case ItemId_Event_RevealCards: eventRevealCards(static_cast<Event_RevealCards *>(event)); break;
default: {
qDebug() << "unhandled game event";
}

View file

@ -57,6 +57,7 @@ signals:
void logCreateArrow(Player *player, Player *startPlayer, QString startCard, Player *targetPlayer, QString targetCard, bool _playerTarget);
void logCreateToken(Player *player, QString cardName, QString pt);
void logDrawCards(Player *player, int number);
void logUndoDraw(Player *player, QString cardName);
void logMoveCard(Player *player, QString cardName, CardZone *startZone, int oldX, CardZone *targetZone, int newX);
void logFlipCard(Player *player, QString cardName, bool faceDown);
void logDestroyCard(Player *player, QString cardName);
@ -81,6 +82,7 @@ public slots:
void actShuffle();
void actDrawCard();
void actDrawCards();
void actUndoDraw();
void actMulligan();
void actMoveTopCardsToGrave();
void actMoveTopCardsToExile();
@ -119,7 +121,7 @@ private:
*aMoveRfgToTopLibrary, *aMoveRfgToBottomLibrary, *aMoveRfgToHand, *aMoveRfgToGrave,
*aViewLibrary, *aViewTopCards, *aMoveTopCardsToGrave, *aMoveTopCardsToExile, *aMoveTopCardToBottom,
*aViewGraveyard, *aViewRfg, *aViewSideboard,
*aDrawCard, *aDrawCards, *aMulligan, *aShuffle,
*aDrawCard, *aDrawCards, *aUndoDraw, *aMulligan, *aShuffle,
*aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken,
*aCardMenu;
@ -167,7 +169,7 @@ private:
void eventDelCounter(Event_DelCounter *event);
void eventDumpZone(Event_DumpZone *event);
void eventStopDumpZone(Event_StopDumpZone *event);
void eventMoveCard(Event_MoveCard *event);
void eventMoveCard(Event_MoveCard *event, GameEventContext *context);
void eventFlipCard(Event_FlipCard *event);
void eventDestroyCard(Event_DestroyCard *event);
void eventAttachCard(Event_AttachCard *event);

View file

@ -17,15 +17,16 @@
#include "gamesmodel.h"
#include "chatview.h"
GameSelector::GameSelector(AbstractClient *_client, int _roomId, QWidget *parent)
: QGroupBox(parent), client(_client), roomId(_roomId)
GameSelector::GameSelector(AbstractClient *_client, TabRoom *_room, QWidget *parent)
: QGroupBox(parent), client(_client), room(_room)
{
gameListView = new QTreeView;
gameListModel = new GamesModel(this);
gameListModel = new GamesModel(room->getGameTypes(), this);
gameListProxyModel = new GamesProxyModel(this);
gameListProxyModel->setSourceModel(gameListModel);
gameListView->setModel(gameListProxyModel);
gameListView->header()->setResizeMode(0, QHeaderView::ResizeToContents);
gameListView->setSortingEnabled(true);
showFullGamesCheckBox = new QCheckBox;
createButton = new QPushButton;
@ -61,7 +62,7 @@ void GameSelector::showFullGamesChanged(int state)
void GameSelector::actCreate()
{
DlgCreateGame dlg(client, roomId, this);
DlgCreateGame dlg(client, room->getRoomId(), room->getGameTypes(), this);
dlg.exec();
}
@ -96,7 +97,7 @@ void GameSelector::actJoin()
return;
}
Command_JoinGame *commandJoinGame = new Command_JoinGame(roomId, game->getGameId(), password, spectator);
Command_JoinGame *commandJoinGame = new Command_JoinGame(room->getRoomId(), game->getGameId(), password, spectator);
connect(commandJoinGame, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
client->sendCommand(commandJoinGame);
@ -122,7 +123,11 @@ void GameSelector::processGameInfo(ServerInfo_Game *info)
TabRoom::TabRoom(AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info)
: Tab(), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName)
{
gameSelector = new GameSelector(client, roomId);
const QList<ServerInfo_GameType *> gameTypeList = info->getGameTypeList();
for (int i = 0; i < gameTypeList.size(); ++i)
gameTypes.insert(gameTypeList[i]->getGameTypeId(), gameTypeList[i]->getDescription());
gameSelector = new GameSelector(client, this);
userList = new UserList(client, false);
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
@ -226,14 +231,12 @@ void TabRoom::processListGamesEvent(Event_ListGames *event)
void TabRoom::processJoinRoomEvent(Event_JoinRoom *event)
{
chatView->appendMessage(QString(), tr("%1 has joined the room.").arg(event->getUserInfo()->getName()));
userList->processUserInfo(event->getUserInfo());
userList->sortItems();
}
void TabRoom::processLeaveRoomEvent(Event_LeaveRoom *event)
{
chatView->appendMessage(QString(), tr("%1 has left the room.").arg(event->getPlayerName()));
userList->deleteUser(event->getPlayerName());
}

View file

@ -23,6 +23,7 @@ class Event_ListGames;
class Event_JoinRoom;
class Event_LeaveRoom;
class Event_RoomSay;
class TabRoom;
class GameSelector : public QGroupBox {
Q_OBJECT
@ -35,7 +36,7 @@ signals:
void gameJoined(int gameId);
private:
AbstractClient *client;
int roomId;
TabRoom *room;
QTreeView *gameListView;
GamesModel *gameListModel;
@ -43,7 +44,7 @@ private:
QPushButton *createButton, *joinButton, *spectateButton;
QCheckBox *showFullGamesCheckBox;
public:
GameSelector(AbstractClient *_client, int _roomId, QWidget *parent = 0);
GameSelector(AbstractClient *_client, TabRoom *_room, QWidget *parent = 0);
void retranslateUi();
void processGameInfo(ServerInfo_Game *info);
};
@ -55,6 +56,7 @@ private:
int roomId;
QString roomName;
QString ownName;
QMap<int, QString> gameTypes;
GameSelector *gameSelector;
UserList *userList;
@ -82,6 +84,7 @@ public:
void retranslateUi();
void processRoomEvent(RoomEvent *event);
int getRoomId() const { return roomId; }
const QMap<int, QString> &getGameTypes() const { return gameTypes; }
QString getChannelName() const { return roomName; }
QString getTabText() const { return roomName; }
};

View file

@ -8,7 +8,7 @@
#include <QMenu>
UserListItemDelegate::UserListItemDelegate(QObject *const parent)
: QItemDelegate(parent)
: QStyledItemDelegate(parent)
{
}
@ -21,7 +21,7 @@ bool UserListItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
return true;
}
}
return QItemDelegate::editorEvent(event, model, option, index);
return QStyledItemDelegate::editorEvent(event, model, option, index);
}
UserListTWI::UserListTWI()

View file

@ -3,13 +3,13 @@
#include <QGroupBox>
#include <QTreeWidgetItem>
#include <QItemDelegate>
#include <QStyledItemDelegate>
class QTreeWidget;
class ServerInfo_User;
class AbstractClient;
class UserListItemDelegate : public QItemDelegate {
class UserListItemDelegate : public QStyledItemDelegate {
public:
UserListItemDelegate(QObject *const parent);
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);

View file

@ -113,7 +113,7 @@ void MainWindow::actSinglePlayer()
}
tabSupervisor->startLocal(localClients);
Command_CreateGame *createCommand = new Command_CreateGame(0, QString(), QString(), numberPlayers, false, false, false, false);
Command_CreateGame *createCommand = new Command_CreateGame(0, QString(), QString(), numberPlayers, QList<GameTypeId *>(), false, false, false, false);
mainClient->sendCommand(createCommand);
}
@ -186,7 +186,10 @@ void MainWindow::socketError(const QString &errorStr)
void MainWindow::protocolVersionMismatch(int localVersion, int remoteVersion)
{
QMessageBox::critical(this, tr("Error"), tr("Protocol version mismatch. Local version: %1, remote version: %2.").arg(localVersion).arg(remoteVersion));
if (localVersion > remoteVersion)
QMessageBox::critical(this, tr("Error"), tr("You are trying to connect to an obsolete server. Please downgrade your Cockatrice version or connect to a suitable server.\nLocal version is %1, remote version is %2.").arg(localVersion).arg(remoteVersion));
else
QMessageBox::critical(this, tr("Error"), tr("Your Cockatrice client is obsolete. Please update your Cockatrice version.\nLocal version is %1, remote version is %2.").arg(localVersion).arg(remoteVersion));
}
void MainWindow::setClientStatusTitle()

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,7 @@ void ProtocolItem::initializeHash()
registerSerializableItem("room", ServerInfo_Room::newItem);
registerSerializableItem("user", ServerInfo_User::newItem);
registerSerializableItem("game", ServerInfo_Game::newItem);
registerSerializableItem("game_type", ServerInfo_GameType::newItem);
registerSerializableItem("card_counter", ServerInfo_CardCounter::newItem);
registerSerializableItem("card", ServerInfo_Card::newItem);
registerSerializableItem("zone", ServerInfo_Zone::newItem);
@ -28,10 +29,12 @@ void ProtocolItem::initializeHash()
registerSerializableItem("file", DeckList_File::newItem);
registerSerializableItem("directory", DeckList_Directory::newItem);
registerSerializableItem("card_id", CardId::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);
@ -138,26 +141,47 @@ void CommandContainer::setResponse(ProtocolResponse *_resp)
resp = _resp;
}
void CommandContainer::enqueueGameEventPublic(GameEvent *event, int gameId)
void CommandContainer::enqueueGameEventPublic(GameEvent *event, int gameId, GameEventContext *context)
{
if (!gameEventQueuePublic)
gameEventQueuePublic = new GameEventContainer(QList<GameEvent *>(), gameId);
gameEventQueuePublic->addGameEvent(event);
if (context)
gameEventQueuePublic->setContext(context);
}
void CommandContainer::enqueueGameEventOmniscient(GameEvent *event, int gameId)
void CommandContainer::enqueueGameEventOmniscient(GameEvent *event, int gameId, GameEventContext *context)
{
if (!gameEventQueueOmniscient)
gameEventQueueOmniscient = new GameEventContainer(QList<GameEvent *>(), gameId);
gameEventQueueOmniscient->addGameEvent(event);
if (context)
gameEventQueueOmniscient->setContext(context);
}
void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId)
void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId, GameEventContext *context)
{
if (!gameEventQueuePrivate)
gameEventQueuePrivate = new GameEventContainer(QList<GameEvent *>(), gameId);
gameEventQueuePrivate->addGameEvent(event);
privatePlayerId = playerId;
if (context)
gameEventQueuePrivate->setContext(context);
}
Command_CreateGame::Command_CreateGame(int _roomId, const QString &_description, const QString &_password, int _maxPlayers, const QList<GameTypeId *> &_gameTypes, 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("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)

View file

@ -17,11 +17,13 @@ class ProtocolResponse;
class DeckList;
class GameEvent;
class GameEventContainer;
class GameEventContext;
class MoveCardToZone;
enum ItemId {
ItemId_CommandContainer = ItemId_Other + 50,
ItemId_GameEventContainer = ItemId_Other + 51,
ItemId_Command_CreateGame = ItemId_Other + 99,
ItemId_Command_DeckUpload = ItemId_Other + 100,
ItemId_Command_DeckSelect = ItemId_Other + 101,
ItemId_Command_SetSideboardPlan = ItemId_Other + 102,
@ -55,7 +57,7 @@ private:
static void initializeHashAuto();
bool receiverMayDelete;
public:
static const int protocolVersion = 11;
static const int protocolVersion = 12;
static void initializeHash();
virtual int getItemId() const = 0;
bool getReceiverMayDelete() const { return receiverMayDelete; }
@ -132,11 +134,11 @@ public:
const QList<ProtocolItem *> &getItemQueue() const { return itemQueue; }
void enqueueItem(ProtocolItem *item) { itemQueue.append(item); }
GameEventContainer *getGameEventQueuePublic() const { return gameEventQueuePublic; }
void enqueueGameEventPublic(GameEvent *event, int gameId);
void enqueueGameEventPublic(GameEvent *event, int gameId, GameEventContext *context = 0);
GameEventContainer *getGameEventQueueOmniscient() const { return gameEventQueueOmniscient; }
void enqueueGameEventOmniscient(GameEvent *event, int gameId);
void enqueueGameEventOmniscient(GameEvent *event, int gameId, GameEventContext *context = 0);
GameEventContainer *getGameEventQueuePrivate() const { return gameEventQueuePrivate; }
void enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId = -1);
void enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId = -1, GameEventContext *context = 0);
int getPrivatePlayerId() const { return privatePlayerId; }
};
@ -172,6 +174,22 @@ public:
}
};
class Command_CreateGame : public RoomCommand {
Q_OBJECT
public:
Command_CreateGame(int _roomId = -1, const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, const QList<GameTypeId *> &_gameTypes = QList<GameTypeId *>(), bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, bool _spectatorsCanTalk = false, bool _spectatorsSeeEverything = false);
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); };
QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); };
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); };
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); };
bool getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); };
bool getSpectatorsCanTalk() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_can_talk"))->getData(); };
bool getSpectatorsSeeEverything() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_see_everything"))->getData(); };
QList<GameTypeId *> getGameTypes() const { return typecastItemList<GameTypeId *>(); }
static SerializableItem *newItem() { return new Command_CreateGame; }
int getItemId() const { return ItemId_Command_CreateGame; }
};
class Command_DeckUpload : public Command {
Q_OBJECT
public:

View file

@ -23,7 +23,7 @@ ServerInfo_User::ServerInfo_User(const ServerInfo_User *other, bool complete)
insertItem(new SerializableItem_ByteArray("avatar_bmp", complete ? other->getAvatarBmp() : QByteArray()));
}
ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, ServerInfo_User *_creatorInfo, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount)
ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QList<GameTypeId *> &_gameTypes, ServerInfo_User *_creatorInfo, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount)
: SerializableItem_Map("game")
{
insertItem(new SerializableItem_Int("game_id", _gameId));
@ -37,9 +37,19 @@ ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool
insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword));
insertItem(new SerializableItem_Int("spectator_count", _spectatorCount));
for (int i = 0; i < _gameTypes.size(); ++i)
itemList.append(_gameTypes[i]);
}
ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QString &_description, int _gameCount, int _playerCount, bool _autoJoin, const QList<ServerInfo_Game *> &_gameList, const QList<ServerInfo_User *> &_userList)
ServerInfo_GameType::ServerInfo_GameType(int _gameTypeId, const QString &_description)
: SerializableItem_Map("game_type")
{
insertItem(new SerializableItem_Int("game_type_id", _gameTypeId));
insertItem(new SerializableItem_String("description", _description));
}
ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QString &_description, int _gameCount, int _playerCount, bool _autoJoin, const QList<ServerInfo_Game *> &_gameList, const QList<ServerInfo_User *> &_userList, const QList<ServerInfo_GameType *> &_gameTypeList)
: SerializableItem_Map("room")
{
insertItem(new SerializableItem_Int("room_id", _roomId));
@ -55,6 +65,9 @@ ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QStrin
userList = _userList;
for (int i = 0; i < _userList.size(); ++i)
itemList.append(_userList[i]);
gameTypeList = _gameTypeList;
for (int i = 0; i < _gameTypeList.size(); ++i)
itemList.append(_gameTypeList[i]);
}
void ServerInfo_Room::extractData()
@ -70,6 +83,11 @@ void ServerInfo_Room::extractData()
gameList.append(game);
continue;
}
ServerInfo_GameType *gameType = dynamic_cast<ServerInfo_GameType *>(itemList[i]);
if (gameType) {
gameTypeList.append(gameType);
continue;
}
}
}

View file

@ -25,6 +25,11 @@ public:
CardId(int _cardId = -1) : SerializableItem_Int("card_id", _cardId) { }
static SerializableItem *newItem() { return new CardId; }
};
class GameTypeId : public SerializableItem_Int {
public:
GameTypeId(int _gameTypeId = -1) : SerializableItem_Int("game_type_id", _gameTypeId) { }
static SerializableItem *newItem() { return new GameTypeId; }
};
class ServerInfo_User : public SerializableItem_Map {
public:
@ -48,27 +53,37 @@ public:
class ServerInfo_Game : public SerializableItem_Map {
public:
ServerInfo_Game(int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, ServerInfo_User *creatorInfo = 0, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1);
ServerInfo_Game(int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, const QList<GameTypeId *> &_gameTypes = QList<GameTypeId *>(), ServerInfo_User *creatorInfo = 0, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1);
static SerializableItem *newItem() { return new ServerInfo_Game; }
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
bool getHasPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("has_password"))->getData(); }
int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); }
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); }
QList<GameTypeId *> getGameTypes() const { return typecastItemList<GameTypeId *>(); }
ServerInfo_User *getCreatorInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); }
bool getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); }
int getSpectatorCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("spectator_count"))->getData(); }
};
class ServerInfo_GameType : public SerializableItem_Map {
public:
ServerInfo_GameType(int _gameTypeId = -1, const QString &_description = QString());
static SerializableItem *newItem() { return new ServerInfo_GameType; }
int getGameTypeId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_type_id"))->getData(); }
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
};
class ServerInfo_Room : public SerializableItem_Map {
private:
QList<ServerInfo_Game *> gameList;
QList<ServerInfo_User *> userList;
QList<ServerInfo_GameType *> gameTypeList;
protected:
void extractData();
public:
ServerInfo_Room(int _id = -1, const QString &_name = QString(), const QString &_description = QString(), int _gameCount = -1, int _playerCount = -1, bool _autoJoin = false, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>(), const QList<ServerInfo_User *> &_userList = QList<ServerInfo_User *>());
ServerInfo_Room(int _id = -1, const QString &_name = QString(), const QString &_description = QString(), int _gameCount = -1, int _playerCount = -1, bool _autoJoin = false, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>(), const QList<ServerInfo_User *> &_userList = QList<ServerInfo_User *>(), const QList<ServerInfo_GameType *> &_gameTypeList = QList<ServerInfo_GameType *>());
static SerializableItem *newItem() { return new ServerInfo_Room; }
int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); }
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
@ -78,6 +93,7 @@ public:
bool getAutoJoin() const { return static_cast<SerializableItem_Bool *>(itemMap.value("auto_join"))->getData(); }
const QList<ServerInfo_Game *> &getGameList() const { return gameList; }
const QList<ServerInfo_User *> &getUserList() const { return userList; }
const QList<ServerInfo_GameType *> &getGameTypeList() const { return gameTypeList; }
};
class ServerInfo_CardCounter : public SerializableItem_Map {

View file

@ -13,14 +13,14 @@ ItemId_Command_ListRooms = 1011,
ItemId_Command_JoinRoom = 1012,
ItemId_Command_LeaveRoom = 1013,
ItemId_Command_RoomSay = 1014,
ItemId_Command_CreateGame = 1015,
ItemId_Command_JoinGame = 1016,
ItemId_Command_LeaveGame = 1017,
ItemId_Command_Say = 1018,
ItemId_Command_Shuffle = 1019,
ItemId_Command_Mulligan = 1020,
ItemId_Command_RollDie = 1021,
ItemId_Command_DrawCards = 1022,
ItemId_Command_JoinGame = 1015,
ItemId_Command_LeaveGame = 1016,
ItemId_Command_Say = 1017,
ItemId_Command_Shuffle = 1018,
ItemId_Command_Mulligan = 1019,
ItemId_Command_RollDie = 1020,
ItemId_Command_DrawCards = 1021,
ItemId_Command_UndoDraw = 1022,
ItemId_Command_FlipCard = 1023,
ItemId_Command_AttachCard = 1024,
ItemId_Command_CreateToken = 1025,
@ -68,6 +68,7 @@ ItemId_Event_RoomSay = 1066,
ItemId_Context_ReadyStart = 1067,
ItemId_Context_Concede = 1068,
ItemId_Context_DeckSelect = 1069,
ItemId_Command_UpdateServerMessage = 1070,
ItemId_Other = 1071
ItemId_Context_UndoDraw = 1070,
ItemId_Command_UpdateServerMessage = 1071,
ItemId_Other = 1072
};

View file

@ -69,17 +69,6 @@ Command_RoomSay::Command_RoomSay(int _roomId, const QString &_message)
{
insertItem(new SerializableItem_String("message", _message));
}
Command_CreateGame::Command_CreateGame(int _roomId, const QString &_description, const QString &_password, int _maxPlayers, 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("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));
}
Command_JoinGame::Command_JoinGame(int _roomId, int _gameId, const QString &_password, bool _spectator)
: RoomCommand("join_game", _roomId)
{
@ -114,6 +103,10 @@ Command_DrawCards::Command_DrawCards(int _gameId, int _number)
{
insertItem(new SerializableItem_Int("number", _number));
}
Command_UndoDraw::Command_UndoDraw(int _gameId)
: GameCommand("undo_draw", _gameId)
{
}
Command_FlipCard::Command_FlipCard(int _gameId, const QString &_zone, int _cardId, bool _faceDown)
: GameCommand("flip_card", _gameId)
{
@ -425,6 +418,10 @@ Context_DeckSelect::Context_DeckSelect(int _deckId)
{
insertItem(new SerializableItem_Int("deck_id", _deckId));
}
Context_UndoDraw::Context_UndoDraw()
: GameEventContext("undo_draw")
{
}
Command_UpdateServerMessage::Command_UpdateServerMessage()
: AdminCommand("update_server_message")
{
@ -445,7 +442,6 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("cmdjoin_room", Command_JoinRoom::newItem);
itemNameHash.insert("cmdleave_room", Command_LeaveRoom::newItem);
itemNameHash.insert("cmdroom_say", Command_RoomSay::newItem);
itemNameHash.insert("cmdcreate_game", Command_CreateGame::newItem);
itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem);
itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem);
itemNameHash.insert("cmdsay", Command_Say::newItem);
@ -453,6 +449,7 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("cmdmulligan", Command_Mulligan::newItem);
itemNameHash.insert("cmdroll_die", Command_RollDie::newItem);
itemNameHash.insert("cmddraw_cards", Command_DrawCards::newItem);
itemNameHash.insert("cmdundo_draw", Command_UndoDraw::newItem);
itemNameHash.insert("cmdflip_card", Command_FlipCard::newItem);
itemNameHash.insert("cmdattach_card", Command_AttachCard::newItem);
itemNameHash.insert("cmdcreate_token", Command_CreateToken::newItem);
@ -500,5 +497,6 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("game_event_contextready_start", Context_ReadyStart::newItem);
itemNameHash.insert("game_event_contextconcede", Context_Concede::newItem);
itemNameHash.insert("game_event_contextdeck_select", Context_DeckSelect::newItem);
itemNameHash.insert("game_event_contextundo_draw", Context_UndoDraw::newItem);
itemNameHash.insert("cmdupdate_server_message", Command_UpdateServerMessage::newItem);
}

View file

@ -12,7 +12,6 @@
0:join_room:i,room_id
1:leave_room
1:room_say:s,message
1:create_game:s,description:s,password:i,max_players:b,spectators_allowed:b,spectators_need_password:b,spectators_can_talk:b,spectators_see_everything
1:join_game:i,game_id:s,password:b,spectator
2:leave_game
2:say:s,message
@ -20,6 +19,7 @@
2:mulligan
2:roll_die:i,sides
2:draw_cards:i,number
2:undo_draw
2:flip_card:s,zone:i,card_id:b,face_down
2:attach_card:s,start_zone:i,card_id:i,target_player_id:s,target_zone:i,target_card_id
2:create_token:s,zone:s,card_name:s,color:s,pt:s,annotation:b,destroy:i,x:i,y
@ -67,4 +67,5 @@
6:ready_start
6:concede
6:deck_select:i,deck_id
6:undo_draw
7:update_server_message

View file

@ -113,20 +113,6 @@ public:
static SerializableItem *newItem() { return new Command_RoomSay; }
int getItemId() const { return ItemId_Command_RoomSay; }
};
class Command_CreateGame : public RoomCommand {
Q_OBJECT
public:
Command_CreateGame(int _roomId = -1, const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, bool _spectatorsCanTalk = false, bool _spectatorsSeeEverything = false);
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); };
QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); };
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); };
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); };
bool getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); };
bool getSpectatorsCanTalk() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_can_talk"))->getData(); };
bool getSpectatorsSeeEverything() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_see_everything"))->getData(); };
static SerializableItem *newItem() { return new Command_CreateGame; }
int getItemId() const { return ItemId_Command_CreateGame; }
};
class Command_JoinGame : public RoomCommand {
Q_OBJECT
public:
@ -182,6 +168,13 @@ public:
static SerializableItem *newItem() { return new Command_DrawCards; }
int getItemId() const { return ItemId_Command_DrawCards; }
};
class Command_UndoDraw : public GameCommand {
Q_OBJECT
public:
Command_UndoDraw(int _gameId = -1);
static SerializableItem *newItem() { return new Command_UndoDraw; }
int getItemId() const { return ItemId_Command_UndoDraw; }
};
class Command_FlipCard : public GameCommand {
Q_OBJECT
public:
@ -634,6 +627,13 @@ public:
static SerializableItem *newItem() { return new Context_DeckSelect; }
int getItemId() const { return ItemId_Context_DeckSelect; }
};
class Context_UndoDraw : public GameEventContext {
Q_OBJECT
public:
Context_UndoDraw();
static SerializableItem *newItem() { return new Context_UndoDraw; }
int getItemId() const { return ItemId_Context_UndoDraw; }
};
class Command_UpdateServerMessage : public AdminCommand {
Q_OBJECT
public:

View file

@ -28,8 +28,8 @@
#include <QTimer>
#include <QDebug>
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent)
: QObject(parent), creatorInfo(new ServerInfo_User(_creator->getUserInfo())), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), secondsElapsed(0)
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent)
: QObject(parent), creatorInfo(new ServerInfo_User(_creator->getUserInfo())), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), gameTypes(_gameTypes), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), secondsElapsed(0)
{
addPlayer(_creator, false, false);
@ -399,18 +399,25 @@ ServerInfo_Game *Server_Game::getInfo() const
{
if (players.isEmpty())
// Game is closing
return new ServerInfo_Game(getGameId(), QString(), false, 0, getMaxPlayers(), 0, false, 0);
else
return new ServerInfo_Game(getGameId(), QString(), false, 0, getMaxPlayers(), QList<GameTypeId *>(), 0, false, 0);
else {
// Game is open
QList<GameTypeId *> gameTypeList;
for (int i = 0; i < gameTypes.size(); ++i)
gameTypeList.append(new GameTypeId(gameTypes[i]));
return new ServerInfo_Game(
getGameId(),
getDescription(),
!getPassword().isEmpty(),
getPlayerCount(),
getMaxPlayers(),
gameTypeList,
new ServerInfo_User(getCreatorInfo(), false),
getSpectatorsAllowed(),
getSpectatorsNeedPassword(),
getSpectatorCount()
);
}
}

View file

@ -40,6 +40,7 @@ private:
QString description;
QString password;
int maxPlayers;
QList<int> gameTypes;
int activePlayer, activePhase;
bool spectatorsAllowed;
bool spectatorsNeedPassword;
@ -53,7 +54,7 @@ signals:
private slots:
void pingClockTimeout();
public:
Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
~Server_Game();
ServerInfo_Game *getInfo() const;
ServerInfo_User *getCreatorInfo() const { return creatorInfo; }

View file

@ -150,6 +150,8 @@ void Server_Player::clearZones()
while (arrowIterator.hasNext())
delete arrowIterator.next().value();
arrows.clear();
lastDrawList.clear();
}
ServerInfo_PlayerProperties *Server_Player::getProperties()
@ -199,6 +201,37 @@ bool Server_Player::deleteCounter(int counterId)
return true;
}
ResponseCode Server_Player::drawCards(CommandContainer *cont, int number)
{
Server_CardZone *deckZone = zones.value("deck");
Server_CardZone *handZone = zones.value("hand");
if (deckZone->cards.size() < number)
number = deckZone->cards.size();
QList<ServerInfo_Card *> cardListPrivate;
QList<ServerInfo_Card *> cardListOmniscient;
for (int i = 0; i < number; ++i) {
Server_Card *card = deckZone->cards.takeFirst();
handZone->cards.append(card);
lastDrawList.append(card->getId());
cardListPrivate.append(new ServerInfo_Card(card->getId(), card->getName()));
cardListOmniscient.append(new ServerInfo_Card(card->getId(), card->getName()));
}
cont->enqueueGameEventPrivate(new Event_DrawCards(playerId, cardListPrivate.size(), cardListPrivate), game->getGameId());
cont->enqueueGameEventOmniscient(new Event_DrawCards(playerId, cardListOmniscient.size(), cardListOmniscient), game->getGameId());
cont->enqueueGameEventPublic(new Event_DrawCards(playerId, cardListPrivate.size()), game->getGameId());
return RespOk;
}
ResponseCode Server_Player::undoDraw(CommandContainer *cont)
{
if (lastDrawList.isEmpty())
return RespContextError;
return moveCard(cont, zones.value("hand"), QList<int>() << lastDrawList.takeLast(), zones.value("deck"), 0, 0, false, false, false, true);
}
ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_startZone, const QList<int> &_cardIds, int targetPlayerId, const QString &_targetZone, int x, int y, bool faceDown, bool tapped)
{
Server_CardZone *startzone = getZones().value(_startZone);
@ -233,7 +266,7 @@ public:
}
};
ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<int> &_cardIds, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped, bool fixFreeSpaces)
ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<int> &_cardIds, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped, bool fixFreeSpaces, bool undoingDraw)
{
// Disallow controller change to other zones than the table.
if (((targetzone->getType() != PublicZone) || !targetzone->hasCoords()) && (startzone->getPlayer() != targetzone->getPlayer()))
@ -262,6 +295,13 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
Server_Card *card = cardsToMove[cardIndex].first;
int originalPosition = cardsToMove[cardIndex].second;
int position = startzone->removeCard(card);
if (startzone->getName() == "hand") {
if (undoingDraw)
lastDrawList.removeAt(lastDrawList.indexOf(card->getId()));
else if (lastDrawList.contains(card->getId()))
lastDrawList.clear();
}
if ((startzone == targetzone) && !startzone->hasCoords()) {
if (!secondHalf && (originalPosition < x)) {
xIndex = -1;
@ -346,8 +386,8 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
int privatePosition = -1;
if (startzone->getType() == HiddenZone)
privatePosition = position;
cont->enqueueGameEventPrivate(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, faceDown), game->getGameId());
cont->enqueueGameEventOmniscient(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, faceDown), game->getGameId());
cont->enqueueGameEventPrivate(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, faceDown), game->getGameId(), -1, undoingDraw ? new Context_UndoDraw : 0);
cont->enqueueGameEventOmniscient(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, faceDown), game->getGameId(), undoingDraw ? new Context_UndoDraw : 0);
// Other players do not get to see the start and/or target position of the card if the respective
// part of the zone is being looked at. The information is not needed anyway because in hidden zones,
@ -361,9 +401,9 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
newX = -1;
if ((startzone->getType() == PublicZone) || (targetzone->getType() == PublicZone))
cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, card->getId(), faceDown), game->getGameId());
cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, card->getId(), faceDown), game->getGameId(), undoingDraw ? new Context_UndoDraw : 0);
else
cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, -1, false), game->getGameId());
cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, -1, false), game->getGameId(), undoingDraw ? new Context_UndoDraw : 0);
if (tapped)
setCardAttrHelper(cont, targetzone->getName(), card->getId(), "tapped", "1");

View file

@ -30,6 +30,7 @@ private:
QMap<QString, Server_CardZone *> zones;
QMap<int, Server_Counter *> counters;
QMap<int, Server_Arrow *> arrows;
QList<int> lastDrawList;
int playerId;
bool spectator;
int initialCards;
@ -75,8 +76,10 @@ public:
void clearZones();
void setupZones();
ResponseCode drawCards(CommandContainer *cont, int number);
ResponseCode undoDraw(CommandContainer *cont);
ResponseCode moveCard(CommandContainer *cont, const QString &_startZone, const QList<int> &_cardId, int _targetPlayer, const QString &_targetZone, int _x, int _y, bool _faceDown, bool _tapped);
ResponseCode moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<int> &_cardId, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped, bool fixFreeSpaces = true);
ResponseCode moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<int> &_cardId, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped, bool fixFreeSpaces = true, bool undoingDraw = false);
void unattachCard(CommandContainer *cont, Server_Card *card);
ResponseCode setCardAttrHelper(CommandContainer *cont, const QString &zone, int cardId, const QString &attrName, const QString &attrValue);

View file

@ -97,6 +97,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
case ItemId_Command_Mulligan: return cmdMulligan(static_cast<Command_Mulligan *>(command), cont, game, player);
case ItemId_Command_RollDie: return cmdRollDie(static_cast<Command_RollDie *>(command), cont, game, player);
case ItemId_Command_DrawCards: return cmdDrawCards(static_cast<Command_DrawCards *>(command), cont, game, player);
case ItemId_Command_UndoDraw: return cmdUndoDraw(static_cast<Command_UndoDraw *>(command), cont, game, player);
case ItemId_Command_MoveCard: return cmdMoveCard(static_cast<Command_MoveCard *>(command), cont, game, player);
case ItemId_Command_FlipCard: return cmdFlipCard(static_cast<Command_FlipCard *>(command), cont, game, player);
case ItemId_Command_AttachCard: return cmdAttachCard(static_cast<Command_AttachCard *>(command), cont, game, player);
@ -355,7 +356,12 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm
if (authState == PasswordWrong)
return RespLoginNeeded;
Server_Game *game = room->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this);
QList<int> gameTypes;
QList<GameTypeId *> gameTypeList = cmd->getGameTypes();
for (int i = 0; i < gameTypeList.size(); ++i)
gameTypes.append(gameTypeList[i]->getData());
Server_Game *game = room->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), gameTypes, cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this);
Server_Player *creator = game->getPlayers().values().first();
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator));
@ -501,7 +507,7 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com
cont->enqueueGameEventPrivate(new Event_Shuffle(player->getPlayerId()), game->getGameId());
cont->enqueueGameEventPublic(new Event_Shuffle(player->getPlayerId()), game->getGameId());
drawCards(game, player, cont, number);
player->drawCards(cont, number);
return RespOk;
}
@ -515,7 +521,7 @@ ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, CommandCon
return RespOk;
}
ResponseCode Server_ProtocolHandler::drawCards(Server_Game *game, Server_Player *player, CommandContainer *cont, int number)
ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
{
if (player->getSpectator())
return RespFunctionNotAllowed;
@ -523,32 +529,19 @@ ResponseCode Server_ProtocolHandler::drawCards(Server_Game *game, Server_Player
if (!game->getGameStarted())
return RespGameNotStarted;
Server_CardZone *deck = player->getZones().value("deck");
Server_CardZone *hand = player->getZones().value("hand");
if (deck->cards.size() < number)
number = deck->cards.size();
QList<ServerInfo_Card *> cardListPrivate;
QList<ServerInfo_Card *> cardListOmniscient;
for (int i = 0; i < number; ++i) {
Server_Card *card = deck->cards.takeFirst();
hand->cards.append(card);
cardListPrivate.append(new ServerInfo_Card(card->getId(), card->getName()));
cardListOmniscient.append(new ServerInfo_Card(card->getId(), card->getName()));
}
cont->enqueueGameEventPrivate(new Event_DrawCards(player->getPlayerId(), cardListPrivate.size(), cardListPrivate), game->getGameId());
cont->enqueueGameEventOmniscient(new Event_DrawCards(player->getPlayerId(), cardListOmniscient.size(), cardListOmniscient), game->getGameId());
cont->enqueueGameEventPublic(new Event_DrawCards(player->getPlayerId(), cardListPrivate.size()), game->getGameId());
return RespOk;
return player->drawCards(cont, cmd->getNumber());
}
ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdUndoDraw(Command_UndoDraw *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
{
return drawCards(game, player, cont, cmd->getNumber());
}
if (player->getSpectator())
return RespFunctionNotAllowed;
if (!game->getGameStarted())
return RespGameNotStarted;
return player->undoDraw(cont);
}
ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
{

View file

@ -61,8 +61,8 @@ private:
ResponseCode cmdShuffle(Command_Shuffle *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdMulligan(Command_Mulligan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdRollDie(Command_RollDie *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode drawCards(Server_Game *game, Server_Player *player, CommandContainer *cont, int number);
ResponseCode cmdDrawCards(Command_DrawCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdUndoDraw(Command_UndoDraw *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdMoveCard(Command_MoveCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdFlipCard(Command_FlipCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdAttachCard(Command_AttachCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);

View file

@ -3,8 +3,8 @@
#include "server_game.h"
#include <QDebug>
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, Server *parent)
: QObject(parent), id(_id), name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage)
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
: QObject(parent), id(_id), name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes)
{
}
@ -17,6 +17,7 @@ ServerInfo_Room *Server_Room::getInfo(bool complete) const
{
QList<ServerInfo_Game *> gameList;
QList<ServerInfo_User *> userList;
QList<ServerInfo_GameType *> gameTypeList;
if (complete) {
QMapIterator<int, Server_Game *> gameIterator(games);
while (gameIterator.hasNext())
@ -24,9 +25,12 @@ ServerInfo_Room *Server_Room::getInfo(bool complete) const
for (int i = 0; i < size(); ++i)
userList.append(new ServerInfo_User(at(i)->getUserInfo(), false));
for (int i = 0; i < gameTypes.size(); ++i)
gameTypeList.append(new ServerInfo_GameType(i, gameTypes[i]));
}
return new ServerInfo_Room(id, name, description, games.size(), size(), autoJoin, gameList, userList);
return new ServerInfo_Room(id, name, description, games.size(), size(), autoJoin, gameList, userList, gameTypeList);
}
void Server_Room::addClient(Server_ProtocolHandler *client)
@ -64,9 +68,9 @@ void Server_Room::broadcastGameListUpdate(Server_Game *game)
delete event;
}
Server_Game *Server_Room::createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator)
Server_Game *Server_Room::createGame(const QString &description, const QString &password, int maxPlayers, const QList<int> &gameTypes, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator)
{
Server_Game *newGame = new Server_Game(creator, static_cast<Server *>(parent())->getNextGameId(), description, password, maxPlayers, spectatorsAllowed, spectatorsNeedPassword, spectatorsCanTalk, spectatorsSeeEverything, this);
Server_Game *newGame = new Server_Game(creator, static_cast<Server *>(parent())->getNextGameId(), description, password, maxPlayers, gameTypes, spectatorsAllowed, spectatorsNeedPassword, spectatorsCanTalk, spectatorsSeeEverything, this);
games.insert(newGame->getGameId(), newGame);
connect(newGame, SIGNAL(gameClosing()), this, SLOT(removeGame()));

View file

@ -25,11 +25,12 @@ private:
QString description;
bool autoJoin;
QString joinMessage;
QStringList gameTypes;
QMap<int, Server_Game *> games;
private slots:
void removeGame();
public:
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, Server *parent);
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
int getId() const { return id; }
QString getName() const { return name; }
QString getDescription() const { return description; }
@ -43,7 +44,7 @@ public:
void removeClient(Server_ProtocolHandler *client);
void say(Server_ProtocolHandler *client, const QString &s);
void broadcastGameListUpdate(Server_Game *game);
Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator);
Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, const QList<int> &_gameTypes, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator);
void sendRoomEvent(RoomEvent *event);
};

View file

@ -19,6 +19,10 @@ size=1
1\description="Play anything here."
1\autojoin=true
1\joinmessage="This message is only here to show that rooms can have a join message."
1\game_types\size=3
1\game_types\1\name="GameType1"
1\game_types\2\name="GameType2"
1\game_types\3\name="GameType3"
[game]
max_game_inactivity_time=120

View file

@ -58,12 +58,22 @@ Servatrice::Servatrice(QObject *parent)
int size = settings->beginReadArray("rooms");
for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i);
QStringList gameTypes;
int size2 = settings->beginReadArray("game_types");
for (int j = 0; j < size2; ++j) {
settings->setArrayIndex(j);
gameTypes.append(settings->value("name").toString());
}
settings->endArray();
Server_Room *newRoom = new Server_Room(
i,
settings->value("name").toString(),
settings->value("description").toString(),
settings->value("autojoin").toBool(),
settings->value("joinmessage").toString(),
gameTypes,
this
);
addRoom(newRoom);
@ -225,4 +235,4 @@ void Servatrice::statusUpdate()
execSqlQuery(query);
}
const QString Servatrice::versionString = "Servatrice 0.20110126";
const QString Servatrice::versionString = "Servatrice 0.20110127";

View file

@ -85,7 +85,7 @@ void ServerSocketInterface::readClient()
void ServerSocketInterface::catchSocketError(QAbstractSocket::SocketError socketError)
{
qDebug(QString("socket error: %1").arg(socketError).toLatin1());
qDebug() << "Socket error:" << socketError;
deleteLater();
}
@ -327,7 +327,7 @@ ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd, C
// ADMIN FUNCTIONS.
// Permission is checked by the calling function.
ResponseCode ServerSocketInterface::cmdUpdateServerMessage(Command_UpdateServerMessage *cmd, CommandContainer *cont)
ResponseCode ServerSocketInterface::cmdUpdateServerMessage(Command_UpdateServerMessage * /*cmd*/, CommandContainer * /*cont*/)
{
servatrice->updateLoginMessage();
return RespOk;