This commit is contained in:
Max-Wilhelm Bruker 2011-01-01 22:53:54 +01:00
commit b73001e9fd
44 changed files with 738 additions and 660 deletions

View file

@ -78,7 +78,7 @@ HEADERS += src/counter.h \
../common/server_arrow.h \ ../common/server_arrow.h \
../common/server_card.h \ ../common/server_card.h \
../common/server_cardzone.h \ ../common/server_cardzone.h \
../common/server_chatchannel.h \ ../common/server_room.h \
../common/server_counter.h \ ../common/server_counter.h \
../common/server_game.h \ ../common/server_game.h \
../common/server_player.h \ ../common/server_player.h \
@ -154,7 +154,7 @@ SOURCES += src/counter.cpp \
../common/server.cpp \ ../common/server.cpp \
../common/server_card.cpp \ ../common/server_card.cpp \
../common/server_cardzone.cpp \ ../common/server_cardzone.cpp \
../common/server_chatchannel.cpp \ ../common/server_room.cpp \
../common/server_game.cpp \ ../common/server_game.cpp \
../common/server_player.cpp \ ../common/server_player.cpp \
../common/server_protocolhandler.cpp ../common/server_protocolhandler.cpp

View file

@ -20,6 +20,7 @@ public:
~AbstractCardDragItem(); ~AbstractCardDragItem();
QRectF boundingRect() const { return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); } QRectF boundingRect() const { return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
AbstractCardItem *getItem() const { return item; }
QPointF getHotSpot() const { return hotSpot; } QPointF getHotSpot() const { return hotSpot; }
void addChildDrag(AbstractCardDragItem *child); void addChildDrag(AbstractCardDragItem *child);
virtual void updatePosition(const QPointF &cursorScenePos) = 0; virtual void updatePosition(const QPointF &cursorScenePos) = 0;

View file

@ -75,11 +75,11 @@ void CardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
CardZone *startZone = static_cast<CardItem *>(item)->getZone(); CardZone *startZone = static_cast<CardItem *>(item)->getZone();
if (currentZone && !(static_cast<CardItem *>(item)->getAttachedTo() && (startZone == currentZone))) { if (currentZone && !(static_cast<CardItem *>(item)->getAttachedTo() && (startZone == currentZone))) {
if (!occupied) if (!occupied)
currentZone->handleDropEvent(id, startZone, (sp - currentZone->scenePos()).toPoint(), faceDown); currentZone->handleDropEvent(this, startZone, (sp - currentZone->scenePos()).toPoint(), faceDown);
for (int i = 0; i < childDrags.size(); i++) { for (int i = 0; i < childDrags.size(); i++) {
CardDragItem *c = static_cast<CardDragItem *>(childDrags[i]); CardDragItem *c = static_cast<CardDragItem *>(childDrags[i]);
if (!(static_cast<CardItem *>(c->item)->getAttachedTo() && (startZone == currentZone)) && !c->occupied) if (!(static_cast<CardItem *>(c->item)->getAttachedTo() && (startZone == currentZone)) && !c->occupied)
currentZone->handleDropEvent(c->id, startZone, (sp - currentZone->scenePos() + c->getHotSpot()).toPoint(), faceDown); currentZone->handleDropEvent(static_cast<CardDragItem *>(c), startZone, (sp - currentZone->scenePos() + c->getHotSpot()).toPoint(), faceDown);
sc->removeItem(c); sc->removeItem(c);
} }
} }

View file

@ -13,6 +13,7 @@ private:
CardZone *currentZone; CardZone *currentZone;
public: public:
CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag = 0); CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag = 0);
int getId() const { return id; }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void updatePosition(const QPointF &cursorScenePos); void updatePosition(const QPointF &cursorScenePos);
protected: protected:

View file

@ -17,91 +17,68 @@
#include "tab_game.h" #include "tab_game.h"
CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, QGraphicsItem *parent) CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, QGraphicsItem *parent)
: AbstractCardItem(_name, _owner, parent), id(_cardid), attacking(false), facedown(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0) : AbstractCardItem(_name, _owner, parent), zone(0), id(_cardid), attacking(false), facedown(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0)
{ {
owner->addCard(this); owner->addCard(this);
if (owner->getLocal()) { aTap = new QAction(this);
aTap = new QAction(this); aTap->setData(0);
aTap->setData(0); connect(aTap, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aTap, SIGNAL(triggered()), owner, SLOT(cardMenuAction())); aUntap = new QAction(this);
aUntap = new QAction(this); aUntap->setData(1);
aUntap->setData(1); connect(aUntap, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aUntap, SIGNAL(triggered()), owner, SLOT(cardMenuAction())); aDoesntUntap = new QAction(this);
aDoesntUntap = new QAction(this); aDoesntUntap->setData(2);
aDoesntUntap->setData(2); connect(aDoesntUntap, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aDoesntUntap, SIGNAL(triggered()), owner, SLOT(cardMenuAction())); aAttach = new QAction(this);
aAttach = new QAction(this); connect(aAttach, SIGNAL(triggered()), this, SLOT(actAttach()));
connect(aAttach, SIGNAL(triggered()), owner, SLOT(actAttach())); aUnattach = new QAction(this);
aUnattach = new QAction(this); connect(aUnattach, SIGNAL(triggered()), this, SLOT(actUnattach()));
connect(aUnattach, SIGNAL(triggered()), owner, SLOT(actUnattach())); aSetPT = new QAction(this);
aSetPT = new QAction(this); connect(aSetPT, SIGNAL(triggered()), this, SLOT(actSetPT()));
connect(aSetPT, SIGNAL(triggered()), owner, SLOT(actSetPT())); aSetAnnotation = new QAction(this);
aSetAnnotation = new QAction(this); connect(aSetAnnotation, SIGNAL(triggered()), this, SLOT(actSetAnnotation()));
connect(aSetAnnotation, SIGNAL(triggered()), owner, SLOT(actSetAnnotation())); aFlip = new QAction(this);
aFlip = new QAction(this); aFlip->setData(3);
aFlip->setData(3); connect(aFlip, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aFlip, SIGNAL(triggered()), owner, SLOT(cardMenuAction())); aClone = new QAction(this);
aClone = new QAction(this); aClone->setData(4);
aClone->setData(4); connect(aClone, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aClone, SIGNAL(triggered()), owner, SLOT(cardMenuAction())); aMoveToTopLibrary = new QAction(this);
aMoveToTopLibrary = new QAction(this); aMoveToTopLibrary->setData(5);
aMoveToTopLibrary->setData(5); aMoveToBottomLibrary = new QAction(this);
aMoveToBottomLibrary = new QAction(this); aMoveToBottomLibrary->setData(6);
aMoveToBottomLibrary->setData(6); aMoveToGraveyard = new QAction(this);
aMoveToGraveyard = new QAction(this); aMoveToGraveyard->setData(7);
aMoveToGraveyard->setData(7); aMoveToExile = new QAction(this);
aMoveToExile = new QAction(this); aMoveToExile->setData(8);
aMoveToExile->setData(8); connect(aMoveToTopLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToTopLibrary, SIGNAL(triggered()), owner, SLOT(cardMenuAction())); connect(aMoveToBottomLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToBottomLibrary, SIGNAL(triggered()), owner, SLOT(cardMenuAction())); connect(aMoveToGraveyard, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToGraveyard, SIGNAL(triggered()), owner, SLOT(cardMenuAction())); connect(aMoveToExile, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToExile, SIGNAL(triggered()), owner, SLOT(cardMenuAction()));
aPlay = new QAction(this);
connect(aPlay, SIGNAL(triggered()), this, SLOT(actPlay()));
cardMenu = new QMenu; for (int i = 0; i < 3; ++i) {
cardMenu->addAction(aTap); QAction *tempAddCounter = new QAction(this);
cardMenu->addAction(aUntap); tempAddCounter->setData(9 + i * 1000);
cardMenu->addAction(aDoesntUntap); QAction *tempRemoveCounter = new QAction(this);
cardMenu->addAction(aFlip); tempRemoveCounter->setData(10 + i * 1000);
cardMenu->addSeparator(); QAction *tempSetCounter = new QAction(this);
cardMenu->addAction(aAttach); tempSetCounter->setData(11 + i * 1000);
cardMenu->addAction(aUnattach); aAddCounter.append(tempAddCounter);
cardMenu->addSeparator(); aRemoveCounter.append(tempRemoveCounter);
cardMenu->addAction(aSetPT); aSetCounter.append(tempSetCounter);
cardMenu->addAction(aSetAnnotation); connect(tempAddCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger()));
cardMenu->addSeparator(); connect(tempRemoveCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger()));
cardMenu->addAction(aClone); connect(tempSetCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger()));
for (int i = 0; i < 3; ++i) { }
QAction *tempAddCounter = new QAction(this); cardMenu = new QMenu;
tempAddCounter->setData(9 + i * 1000); moveMenu = new QMenu;
QAction *tempRemoveCounter = new QAction(this);
tempRemoveCounter->setData(10 + i * 1000); retranslateUi();
QAction *tempSetCounter = new QAction(this); updateCardMenu();
tempSetCounter->setData(11 + i * 1000);
aAddCounter.append(tempAddCounter);
aRemoveCounter.append(tempRemoveCounter);
aSetCounter.append(tempSetCounter);
connect(tempAddCounter, SIGNAL(triggered()), owner, SLOT(actCardCounterTrigger()));
connect(tempRemoveCounter, SIGNAL(triggered()), owner, SLOT(actCardCounterTrigger()));
connect(tempSetCounter, SIGNAL(triggered()), owner, SLOT(actCardCounterTrigger()));
cardMenu->addSeparator();
cardMenu->addAction(tempAddCounter);
cardMenu->addAction(tempRemoveCounter);
cardMenu->addAction(tempSetCounter);
}
cardMenu->addSeparator();
moveMenu = cardMenu->addMenu(QString());
moveMenu->addAction(aMoveToTopLibrary);
moveMenu->addAction(aMoveToBottomLibrary);
moveMenu->addAction(aMoveToGraveyard);
moveMenu->addAction(aMoveToExile);
retranslateUi();
} else
cardMenu = 0;
} }
CardItem::~CardItem() CardItem::~CardItem()
@ -110,6 +87,8 @@ CardItem::~CardItem()
delete cardMenu; delete cardMenu;
cardMenu = 0; cardMenu = 0;
delete moveMenu;
moveMenu = 0;
deleteDragItem(); deleteDragItem();
} }
@ -139,37 +118,85 @@ void CardItem::deleteLater()
AbstractCardItem::deleteLater(); AbstractCardItem::deleteLater();
} }
void CardItem::setZone(CardZone *_zone)
{
zone = _zone;
updateCardMenu();
}
void CardItem::updateCardMenu()
{
cardMenu->clear();
if (owner->getLocal()) {
if (zone) {
if (zone->getName() == "table") {
cardMenu->addAction(aTap);
cardMenu->addAction(aUntap);
cardMenu->addAction(aDoesntUntap);
cardMenu->addAction(aFlip);
cardMenu->addSeparator();
cardMenu->addAction(aAttach);
if (attachedTo)
cardMenu->addAction(aUnattach);
cardMenu->addSeparator();
cardMenu->addAction(aSetPT);
cardMenu->addAction(aSetAnnotation);
cardMenu->addSeparator();
cardMenu->addAction(aClone);
for (int i = 0; i < aAddCounter.size(); ++i) {
cardMenu->addSeparator();
cardMenu->addAction(aAddCounter[i]);
cardMenu->addAction(aRemoveCounter[i]);
cardMenu->addAction(aSetCounter[i]);
}
cardMenu->addSeparator();
} else {
cardMenu->addAction(aPlay);
}
}
moveMenu->clear();
moveMenu->addAction(aMoveToTopLibrary);
moveMenu->addAction(aMoveToBottomLibrary);
moveMenu->addAction(aMoveToGraveyard);
moveMenu->addAction(aMoveToExile);
cardMenu->addMenu(moveMenu);
}
}
void CardItem::retranslateUi() void CardItem::retranslateUi()
{ {
if (owner->getLocal()) { aPlay->setText(tr("&Play"));
aTap->setText(tr("&Tap"));
aUntap->setText(tr("&Untap")); aTap->setText(tr("&Tap"));
aDoesntUntap->setText(tr("Toggle &normal untapping")); aUntap->setText(tr("&Untap"));
aFlip->setText(tr("&Flip")); aDoesntUntap->setText(tr("Toggle &normal untapping"));
aClone->setText(tr("&Clone")); aFlip->setText(tr("&Flip"));
aAttach->setText(tr("&Attach to card...")); aClone->setText(tr("&Clone"));
aAttach->setShortcut(tr("Ctrl+A")); aAttach->setText(tr("&Attach to card..."));
aUnattach->setText(tr("Unattac&h")); aAttach->setShortcut(tr("Ctrl+A"));
aSetPT->setText(tr("Set &P/T...")); aUnattach->setText(tr("Unattac&h"));
aSetAnnotation->setText(tr("&Set annotation...")); aSetPT->setText(tr("Set &P/T..."));
QStringList counterColors; aSetAnnotation->setText(tr("&Set annotation..."));
counterColors.append(tr("red")); QStringList counterColors;
counterColors.append(tr("yellow")); counterColors.append(tr("red"));
counterColors.append(tr("green")); counterColors.append(tr("yellow"));
for (int i = 0; i < aAddCounter.size(); ++i) counterColors.append(tr("green"));
aAddCounter[i]->setText(tr("&Add counter (%1)").arg(counterColors[i])); for (int i = 0; i < aAddCounter.size(); ++i)
for (int i = 0; i < aRemoveCounter.size(); ++i) aAddCounter[i]->setText(tr("&Add counter (%1)").arg(counterColors[i]));
aRemoveCounter[i]->setText(tr("&Remove counter (%1)").arg(counterColors[i])); for (int i = 0; i < aRemoveCounter.size(); ++i)
for (int i = 0; i < aSetCounter.size(); ++i) aRemoveCounter[i]->setText(tr("&Remove counter (%1)").arg(counterColors[i]));
aSetCounter[i]->setText(tr("&Set counters (%1)...").arg(counterColors[i])); for (int i = 0; i < aSetCounter.size(); ++i)
aMoveToTopLibrary->setText(tr("&top of library")); aSetCounter[i]->setText(tr("&Set counters (%1)...").arg(counterColors[i]));
aMoveToBottomLibrary->setText(tr("&bottom of library")); aMoveToTopLibrary->setText(tr("&top of library"));
aMoveToGraveyard->setText(tr("&graveyard")); aMoveToBottomLibrary->setText(tr("&bottom of library"));
aMoveToGraveyard->setShortcut(tr("Ctrl+Del")); aMoveToGraveyard->setText(tr("&graveyard"));
aMoveToExile->setText(tr("&exile")); aMoveToGraveyard->setShortcut(tr("Ctrl+Del"));
aMoveToExile->setText(tr("&exile"));
moveMenu->setTitle(tr("&Move to"));
} moveMenu->setTitle(tr("&Move to"));
} }
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
@ -263,6 +290,8 @@ void CardItem::setAttachedTo(CardItem *_attachedTo)
if (zone) if (zone)
zone->reorganizeCards(); zone->reorganizeCards();
updateCardMenu();
} }
void CardItem::resetState() void CardItem::resetState()
@ -376,7 +405,7 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
} }
void CardItem::playCard(QGraphicsSceneMouseEvent *event) void CardItem::playCard(bool faceDown)
{ {
// Do nothing if the card belongs to another player // Do nothing if the card belongs to another player
if (!owner->getLocal()) if (!owner->getLocal())
@ -385,22 +414,19 @@ void CardItem::playCard(QGraphicsSceneMouseEvent *event)
TableZone *tz = qobject_cast<TableZone *>(zone); TableZone *tz = qobject_cast<TableZone *>(zone);
if (tz) if (tz)
tz->toggleTapped(); tz->toggleTapped();
else { else
bool faceDown = event->modifiers().testFlag(Qt::ShiftModifier); zone->getPlayer()->playCard(this, faceDown, info->getCipt());
bool tapped = info->getCipt();
zone->getPlayer()->playCard(this, faceDown, tapped);
}
} }
void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::RightButton) { if (event->button() == Qt::RightButton) {
if (cardMenu) if (cardMenu)
cardMenu->exec(event->screenPos()); if (!cardMenu->isEmpty())
cardMenu->exec(event->screenPos());
} else if ((event->button() == Qt::LeftButton) && !settingsCache->getDoubleClickToPlay()) { } else if ((event->button() == Qt::LeftButton) && !settingsCache->getDoubleClickToPlay()) {
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
playCard(event); playCard(event->modifiers().testFlag(Qt::ShiftModifier));
} }
AbstractCardItem::mouseReleaseEvent(event); AbstractCardItem::mouseReleaseEvent(event);
@ -409,7 +435,7 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{ {
if (settingsCache->getDoubleClickToPlay()) if (settingsCache->getDoubleClickToPlay())
playCard(event); playCard(event->modifiers().testFlag(Qt::ShiftModifier));
event->accept(); event->accept();
} }
@ -423,3 +449,38 @@ QVariant CardItem::itemChange(GraphicsItemChange change, const QVariant &value)
} }
return QGraphicsItem::itemChange(change, value); return QGraphicsItem::itemChange(change, value);
} }
void CardItem::cardMenuAction()
{
owner->cardMenuAction(static_cast<QAction *>(sender()));
}
void CardItem::actAttach()
{
owner->actAttach(static_cast<QAction *>(sender()));
}
void CardItem::actUnattach()
{
owner->actUnattach(static_cast<QAction *>(sender()));
}
void CardItem::actSetPT()
{
owner->actSetPT(static_cast<QAction *>(sender()));
}
void CardItem::actSetAnnotation()
{
owner->actSetAnnotation(static_cast<QAction *>(sender()));
}
void CardItem::actCardCounterTrigger()
{
owner->actCardCounterTrigger(static_cast<QAction *>(sender()));
}
void CardItem::actPlay()
{
playCard(false);
}

View file

@ -30,12 +30,21 @@ private:
QList<CardItem *> attachedCards; QList<CardItem *> attachedCards;
QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter; QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter;
QAction *aTap, *aUntap, *aDoesntUntap, *aAttach, *aUnattach, *aSetPT, *aSetAnnotation, *aFlip, *aClone, QAction *aPlay,
*aTap, *aUntap, *aDoesntUntap, *aAttach, *aUnattach, *aSetPT, *aSetAnnotation, *aFlip, *aClone,
*aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToGraveyard, *aMoveToExile; *aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToGraveyard, *aMoveToExile;
QMenu *cardMenu, *moveMenu; QMenu *cardMenu, *moveMenu;
void playCard(QGraphicsSceneMouseEvent *event); void playCard(bool faceDown);
void prepareDelete(); void prepareDelete();
private slots:
void cardMenuAction();
void actCardCounterTrigger();
void actAttach();
void actUnattach();
void actSetPT();
void actSetAnnotation();
void actPlay();
public slots: public slots:
void deleteLater(); void deleteLater();
public: public:
@ -45,13 +54,14 @@ public:
~CardItem(); ~CardItem();
void retranslateUi(); void retranslateUi();
CardZone *getZone() const { return zone; } CardZone *getZone() const { return zone; }
void setZone(CardZone *_zone) { zone = _zone; } void setZone(CardZone *_zone);
QMenu *getCardMenu() const { return cardMenu; } QMenu *getCardMenu() const { return cardMenu; }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QPoint getGridPoint() const { return gridPoint; } QPoint getGridPoint() const { return gridPoint; }
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; } void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
QPoint getGridPos() const { return gridPoint; } QPoint getGridPos() const { return gridPoint; }
Player *getOwner() const { return owner; } Player *getOwner() const { return owner; }
void setOwner(Player *_owner) { owner = _owner; }
int getId() const { return id; } int getId() const { return id; }
void setId(int _id) { id = _id; } void setId(int _id) { id = _id; }
bool getAttacking() const { return attacking; } bool getAttacking() const { return attacking; }
@ -75,6 +85,7 @@ public:
const QList<CardItem *> &getAttachedCards() const { return attachedCards; } const QList<CardItem *> &getAttachedCards() const { return attachedCards; }
void resetState(); void resetState();
void processCardInfo(ServerInfo_Card *info); void processCardInfo(ServerInfo_Card *info);
void updateCardMenu();
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown); CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown);
void deleteDragItem(); void deleteDragItem();

View file

@ -166,7 +166,7 @@ void CardZone::moveAllToZone()
// Cards need to be moved in reverse order so that the other // Cards need to be moved in reverse order so that the other
// cards' list index doesn't change // cards' list index doesn't change
for (int i = cards.size() - 1; i >= 0; i--) for (int i = cards.size() - 1; i >= 0; i--)
player->sendGameCommand(new Command_MoveCard(-1, getName(), cards.at(i)->getId(), targetZone, targetX)); player->sendGameCommand(new Command_MoveCard(-1, getName(), cards.at(i)->getId(), player->getId(), targetZone, targetX));
} }
QPointF CardZone::closestGridPoint(const QPointF &point) QPointF CardZone::closestGridPoint(const QPointF &point)

View file

@ -12,6 +12,7 @@ class ZoneViewZone;
class QMenu; class QMenu;
class QAction; class QAction;
class QPainter; class QPainter;
class CardDragItem;
class CardZone : public QObject, public AbstractGraphicsItem { class CardZone : public QObject, public AbstractGraphicsItem {
Q_OBJECT Q_OBJECT
@ -34,7 +35,7 @@ public slots:
public: public:
enum { Type = typeZone }; enum { Type = typeZone };
int type() const { return Type; } int type() const { return Type; }
virtual void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown) = 0; virtual void handleDropEvent(CardDragItem *dragItem, CardZone *startZone, const QPoint &dropPoint, bool faceDown) = 0;
CardZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0, bool isView = false); CardZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0, bool isView = false);
~CardZone(); ~CardZone();
void retranslateUi(); void retranslateUi();

View file

@ -3,6 +3,7 @@
#include "settingscache.h" #include "settingscache.h"
#include "player.h" #include "player.h"
#include "protocol_items.h" #include "protocol_items.h"
#include "carddragitem.h"
HandZone::HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent) HandZone::HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent)
: SelectZone(_p, "hand", false, false, _contentsKnown, parent), zoneHeight(_zoneHeight) : SelectZone(_p, "hand", false, false, _contentsKnown, parent), zoneHeight(_zoneHeight)
@ -36,9 +37,9 @@ void HandZone::addCardImpl(CardItem *card, int x, int /*y*/)
card->update(); card->update();
} }
void HandZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/) void HandZone::handleDropEvent(CardDragItem *dragItem, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
{ {
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), cards.size(), -1, false)); player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), dragItem->getId(), player->getId(), getName(), cards.size(), -1, false));
} }
QRectF HandZone::boundingRect() const QRectF HandZone::boundingRect() const

View file

@ -14,7 +14,7 @@ public slots:
void updateOrientation(); void updateOrientation();
public: public:
HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent = 0); HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent = 0);
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown); void handleDropEvent(CardDragItem *dragItem, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
QRectF boundingRect() const; QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards(); void reorganizeCards();

View file

@ -48,9 +48,9 @@ void PileZone::addCardImpl(CardItem *card, int x, int /*y*/)
card->setParentItem(this); card->setParentItem(this);
} }
void PileZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/) void PileZone::handleDropEvent(CardDragItem *dragItem, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
{ {
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), 0, 0, false)); player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), dragItem->getId(), player->getId(), getName(), 0, 0, false));
} }
void PileZone::reorganizeCards() void PileZone::reorganizeCards()

View file

@ -9,7 +9,7 @@ public:
QRectF boundingRect() const; QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards(); void reorganizeCards();
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown); void handleDropEvent(CardDragItem *dragItem, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
protected: protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event);

View file

@ -562,7 +562,7 @@ void Player::actMoveTopCardsToGrave()
if (number > maxCards) if (number > maxCards)
number = maxCards; number = maxCards;
for (int i = 0; i < number; ++i) for (int i = 0; i < number; ++i)
commandList.append(new Command_MoveCard(-1, "deck", 0, "grave", 0, 0, false)); commandList.append(new Command_MoveCard(-1, "deck", 0, getId(), "grave", 0, 0, false));
sendCommandContainer(new CommandContainer(commandList)); sendCommandContainer(new CommandContainer(commandList));
} }
@ -577,13 +577,13 @@ void Player::actMoveTopCardsToExile()
if (number > maxCards) if (number > maxCards)
number = maxCards; number = maxCards;
for (int i = 0; i < number; ++i) for (int i = 0; i < number; ++i)
commandList.append(new Command_MoveCard(-1, "deck", 0, "rfg", 0, 0, false)); commandList.append(new Command_MoveCard(-1, "deck", 0, getId(), "rfg", 0, 0, false));
sendCommandContainer(new CommandContainer(commandList)); sendCommandContainer(new CommandContainer(commandList));
} }
void Player::actMoveTopCardToBottom() void Player::actMoveTopCardToBottom()
{ {
sendGameCommand(new Command_MoveCard(-1, "deck", 0, "deck", -1, 0, false)); sendGameCommand(new Command_MoveCard(-1, "deck", 0, getId(), "deck", -1, 0, false));
} }
void Player::actUntapAll() void Player::actUntapAll()
@ -790,7 +790,10 @@ void Player::eventStopDumpZone(Event_StopDumpZone *event)
void Player::eventMoveCard(Event_MoveCard *event) void Player::eventMoveCard(Event_MoveCard *event)
{ {
CardZone *startZone = zones.value(event->getStartZone(), 0); CardZone *startZone = zones.value(event->getStartZone(), 0);
CardZone *targetZone = zones.value(event->getTargetZone(), 0); Player *targetPlayer = static_cast<TabGame *>(parent())->getPlayers().value(event->getTargetPlayerId());
if (!targetPlayer)
return;
CardZone *targetZone = targetPlayer->getZones().value(event->getTargetZone(), 0);
if (!startZone || !targetZone) if (!startZone || !targetZone)
return; return;
@ -820,6 +823,13 @@ void Player::eventMoveCard(Event_MoveCard *event)
if (startZone != targetZone) { if (startZone != targetZone) {
card->setBeingPointedAt(false); card->setBeingPointedAt(false);
card->setHovered(false); card->setHovered(false);
const QList<CardItem *> &attachedCards = card->getAttachedCards();
for (int i = 0; i < attachedCards.size(); ++i)
attachedCards[i]->setParentItem(targetZone);
if (startZone->getPlayer() != targetZone->getPlayer())
card->setOwner(targetZone->getPlayer());
} }
// The log event has to be sent before the card is added to the target zone // The log event has to be sent before the card is added to the target zone
@ -1076,10 +1086,10 @@ void Player::playCard(CardItem *c, bool faceDown, bool tapped)
{ {
CardInfo *ci = c->getInfo(); CardInfo *ci = c->getInfo();
if (ci->getTableRow() == 3) if (ci->getTableRow() == 3)
stack->handleDropEvent(c->getId(), c->getZone(), QPoint(), false); sendGameCommand(new Command_MoveCard(-1, c->getZone()->getName(), c->getId(), getId(), "stack", 0, 0, false));
else { else {
QPoint gridPoint = QPoint(-1, 2 - ci->getTableRow()); QPoint gridPoint = QPoint(-1, 2 - ci->getTableRow());
table->handleDropEventByGrid(c->getId(), c->getZone(), gridPoint, faceDown, tapped); sendGameCommand(new Command_MoveCard(-1, c->getZone()->getName(), c->getId(), getId(), "table", gridPoint.x(), gridPoint.y(), faceDown, tapped));
} }
} }
@ -1246,9 +1256,8 @@ bool Player::clearCardsToDelete()
return true; return true;
} }
void Player::cardMenuAction() void Player::cardMenuAction(QAction *a)
{ {
QAction *a = static_cast<QAction *>(sender());
QList<QGraphicsItem *> sel = scene()->selectedItems(); QList<QGraphicsItem *> sel = scene()->selectedItems();
QList<Command *> commandList; QList<Command *> commandList;
while (!sel.isEmpty()) { while (!sel.isEmpty()) {
@ -1273,19 +1282,19 @@ void Player::cardMenuAction()
break; break;
} }
case 4: case 4:
commandList.append(new Command_CreateToken(-1, card->getZone()->getName(), card->getName(), card->getColor(), card->getPT(), card->getAnnotation(), card->getDestroyOnZoneChange(), -1, card->getGridPoint().y())); commandList.append(new Command_CreateToken(-1, card->getZone()->getName(), card->getName(), card->getColor(), card->getPT(), card->getAnnotation(), true, -1, card->getGridPoint().y()));
break; break;
case 5: case 5:
commandList.append(new Command_MoveCard(-1, card->getZone()->getName(), card->getId(), "deck", 0, 0, false)); commandList.append(new Command_MoveCard(-1, card->getZone()->getName(), card->getId(), getId(), "deck", 0, 0, false));
break; break;
case 6: case 6:
commandList.append(new Command_MoveCard(-1, card->getZone()->getName(), card->getId(), "deck", -1, 0, false)); commandList.append(new Command_MoveCard(-1, card->getZone()->getName(), card->getId(), getId(), "deck", -1, 0, false));
break; break;
case 7: case 7:
commandList.append(new Command_MoveCard(-1, card->getZone()->getName(), card->getId(), "grave", 0, 0, false)); commandList.append(new Command_MoveCard(-1, card->getZone()->getName(), card->getId(), getId(), "grave", 0, 0, false));
break; break;
case 8: case 8:
commandList.append(new Command_MoveCard(-1, card->getZone()->getName(), card->getId(), "rfg", 0, 0, false)); commandList.append(new Command_MoveCard(-1, card->getZone()->getName(), card->getId(), getId(), "rfg", 0, 0, false));
break; break;
default: ; default: ;
} }
@ -1293,7 +1302,7 @@ void Player::cardMenuAction()
sendCommandContainer(new CommandContainer(commandList)); sendCommandContainer(new CommandContainer(commandList));
} }
void Player::actSetPT() void Player::actSetPT(QAction * /*a*/)
{ {
QString oldPT; QString oldPT;
QListIterator<QGraphicsItem *> i(scene()->selectedItems()); QListIterator<QGraphicsItem *> i(scene()->selectedItems());
@ -1318,7 +1327,7 @@ void Player::actSetPT()
} }
} }
void Player::actSetAnnotation() void Player::actSetAnnotation(QAction * /*a*/)
{ {
QString oldAnnotation; QString oldAnnotation;
QListIterator<QGraphicsItem *> i(scene()->selectedItems()); QListIterator<QGraphicsItem *> i(scene()->selectedItems());
@ -1344,24 +1353,22 @@ void Player::actSetAnnotation()
} }
} }
void Player::actAttach() void Player::actAttach(QAction *a)
{ {
CardItem *card = static_cast<CardItem *>(sender()->parent()); CardItem *card = static_cast<CardItem *>(a->parent());
ArrowAttachItem *arrow = new ArrowAttachItem(card); ArrowAttachItem *arrow = new ArrowAttachItem(card);
scene()->addItem(arrow); scene()->addItem(arrow);
arrow->grabMouse(); arrow->grabMouse();
} }
void Player::actUnattach() void Player::actUnattach(QAction *a)
{ {
CardItem *card = static_cast<CardItem *>(sender()->parent()); CardItem *card = static_cast<CardItem *>(a->parent());
sendGameCommand(new Command_AttachCard(-1, card->getZone()->getName(), card->getId(), -1, QString(), -1)); sendGameCommand(new Command_AttachCard(-1, card->getZone()->getName(), card->getId(), -1, QString(), -1));
} }
void Player::actCardCounterTrigger() void Player::actCardCounterTrigger(QAction *a)
{ {
QAction *a = static_cast<QAction *>(sender());
int counterId = a->data().toInt() / 1000; int counterId = a->data().toInt() / 1000;
int action = a->data().toInt() % 1000; int action = a->data().toInt() % 1000;
switch (action) { switch (action) {

View file

@ -94,12 +94,12 @@ public slots:
void actSayMessage(); void actSayMessage();
void actAttach(); void actAttach(QAction *action);
void actUnattach(); void actUnattach(QAction *action);
void actSetPT(); void actSetPT(QAction *action);
void actSetAnnotation(); void actSetAnnotation(QAction *action);
void cardMenuAction(); void cardMenuAction(QAction *action);
void actCardCounterTrigger(); void actCardCounterTrigger(QAction *action);
private slots: private slots:
void addPlayer(Player *player); void addPlayer(Player *player);

View file

@ -5,6 +5,7 @@
#include "settingscache.h" #include "settingscache.h"
#include "player.h" #include "player.h"
#include "protocol_items.h" #include "protocol_items.h"
#include "carddragitem.h"
StackZone::StackZone(Player *_p, int _zoneHeight, QGraphicsItem *parent) StackZone::StackZone(Player *_p, int _zoneHeight, QGraphicsItem *parent)
: SelectZone(_p, "stack", false, false, true, parent), zoneHeight(_zoneHeight) : SelectZone(_p, "stack", false, false, true, parent), zoneHeight(_zoneHeight)
@ -51,11 +52,11 @@ void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*optio
painter->fillRect(boundingRect(), QBrush(bgPixmap)); painter->fillRect(boundingRect(), QBrush(bgPixmap));
} }
void StackZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/) void StackZone::handleDropEvent(CardDragItem *dragItem, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
{ {
if (startZone == this) if (startZone == this)
return; return;
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), 0, 0, false)); player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), dragItem->getId(), player->getId(), getName(), 0, 0, false));
} }
void StackZone::reorganizeCards() void StackZone::reorganizeCards()

View file

@ -12,7 +12,7 @@ private slots:
void updateBgPixmap(); void updateBgPixmap();
public: public:
StackZone(Player *_p, int _zoneHeight, QGraphicsItem *parent = 0); StackZone(Player *_p, int _zoneHeight, QGraphicsItem *parent = 0);
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown); void handleDropEvent(CardDragItem *dragItem, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
QRectF boundingRect() const; QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards(); void reorganizeCards();

View file

@ -7,6 +7,7 @@
#include "protocol_items.h" #include "protocol_items.h"
#include "settingscache.h" #include "settingscache.h"
#include "arrowitem.h" #include "arrowitem.h"
#include "carddragitem.h"
TableZone::TableZone(Player *_p, QGraphicsItem *parent) TableZone::TableZone(Player *_p, QGraphicsItem *parent)
: SelectZone(_p, "table", true, false, true, parent), active(false) : SelectZone(_p, "table", true, false, true, parent), active(false)
@ -84,14 +85,14 @@ void TableZone::addCardImpl(CardItem *card, int _x, int _y)
card->update(); card->update();
} }
void TableZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown) void TableZone::handleDropEvent(CardDragItem *dragItem, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
{ {
handleDropEventByGrid(cardId, startZone, mapToGrid(dropPoint), faceDown); handleDropEventByGrid(dragItem, startZone, mapToGrid(dropPoint), faceDown);
} }
void TableZone::handleDropEventByGrid(int cardId, CardZone *startZone, const QPoint &gridPoint, bool faceDown, bool tapped) void TableZone::handleDropEventByGrid(CardDragItem *dragItem, CardZone *startZone, const QPoint &gridPoint, bool faceDown, bool tapped)
{ {
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), gridPoint.x(), gridPoint.y(), faceDown, tapped)); static_cast<CardItem *>(dragItem->getItem())->getZone()->getPlayer()->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), dragItem->getId(), player->getId(), getName(), gridPoint.x(), gridPoint.y(), faceDown, tapped));
} }
void TableZone::reorganizeCards() void TableZone::reorganizeCards()
@ -223,18 +224,21 @@ CardItem *TableZone::getCardFromCoords(const QPointF &point) const
return getCardFromGrid(gridPoint); return getCardFromGrid(gridPoint);
} }
QPointF TableZone::mapFromGrid(const QPoint &gridPoint) const QPointF TableZone::mapFromGrid(QPoint gridPoint) const
{ {
qreal x, y; qreal x, y;
x = marginX + (gridPoint.x() % 3) * CARD_WIDTH / 3.0; x = marginX + (gridPoint.x() % 3) * CARD_WIDTH / 3.0;
for (int i = 0; i < gridPoint.x() / 3; ++i) for (int i = 0; i < gridPoint.x() / 3; ++i)
x += gridPointWidth.value(gridPoint.y() * 1000 + i, CARD_WIDTH) + paddingX; x += gridPointWidth.value(gridPoint.y() * 1000 + i, CARD_WIDTH) + paddingX;
y = boxLineWidth + gridPoint.y() * (CARD_HEIGHT + paddingY + 20) + (gridPoint.x() % 3) * 10; if (isInverted())
gridPoint.setY(2 - gridPoint.y());
y = boxLineWidth + gridPoint.y() * (CARD_HEIGHT + paddingY + 20) + (gridPoint.x() % 3) * 10;
/*
if (isInverted()) if (isInverted())
y = height - CARD_HEIGHT - y; y = height - CARD_HEIGHT - y;
*/
return QPointF(x, y); return QPointF(x, y);
} }
@ -242,9 +246,9 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
{ {
qreal x = mapPoint.x() - marginX; qreal x = mapPoint.x() - marginX;
qreal y = mapPoint.y(); qreal y = mapPoint.y();
if (isInverted()) /* if (isInverted())
y = height - y; y = height - y;
y -= boxLineWidth; */ y -= boxLineWidth;
if (x < 0) if (x < 0)
x = 0; x = 0;
@ -256,6 +260,8 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
y = height - CARD_HEIGHT; y = height - CARD_HEIGHT;
int resultY = round(y / (CARD_HEIGHT + paddingY + 20)); int resultY = round(y / (CARD_HEIGHT + paddingY + 20));
if (isInverted())
resultY = 2 - resultY;
int baseX = -1; int baseX = -1;
qreal oldTempX = 0, tempX = 0; qreal oldTempX = 0, tempX = 0;

View file

@ -29,11 +29,11 @@ public:
QRectF boundingRect() const; QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void toggleTapped(); void toggleTapped();
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown = false); void handleDropEvent(CardDragItem *dragItem, CardZone *startZone, const QPoint &dropPoint, bool faceDown = false);
void handleDropEventByGrid(int cardId, CardZone *startZone, const QPoint &gridPoint, bool faceDown = false, bool tapped = false); void handleDropEventByGrid(CardDragItem *dragItem, CardZone *startZone, const QPoint &gridPoint, bool faceDown = false, bool tapped = false);
CardItem *getCardFromGrid(const QPoint &gridPoint) const; CardItem *getCardFromGrid(const QPoint &gridPoint) const;
CardItem *getCardFromCoords(const QPointF &point) const; CardItem *getCardFromCoords(const QPointF &point) const;
QPointF mapFromGrid(const QPoint &gridPoint) const; QPointF mapFromGrid(QPoint gridPoint) const;
QPoint mapToGrid(const QPointF &mapPoint) const; QPoint mapToGrid(const QPointF &mapPoint) const;
QPointF closestGridPoint(const QPointF &point); QPointF closestGridPoint(const QPointF &point);
CardItem *takeCard(int position, int cardId, bool canResize = true); CardItem *takeCard(int position, int cardId, bool canResize = true);

View file

@ -308,8 +308,9 @@ bool WndDeckEditor::actSaveDeck()
else if (deckModel->getDeckList()->saveToFile(lastFileName, lastFileFormat)) { else if (deckModel->getDeckList()->saveToFile(lastFileName, lastFileFormat)) {
setWindowModified(false); setWindowModified(false);
return true; return true;
} else }
return false; QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved.\nPlease check that the directory is writable and try again."));
return false;
} }
bool WndDeckEditor::actSaveDeckAs() bool WndDeckEditor::actSaveDeckAs()
@ -332,6 +333,7 @@ bool WndDeckEditor::actSaveDeckAs()
setWindowModified(false); setWindowModified(false);
return true; return true;
} }
QMessageBox::critical(this, tr("Error"), tr("The deck could not be saved.\nPlease check that the directory is writable and try again."));
return false; return false;
} }

View file

@ -3,6 +3,7 @@
#include "zoneviewzone.h" #include "zoneviewzone.h"
#include "player.h" #include "player.h"
#include "protocol_items.h" #include "protocol_items.h"
#include "carddragitem.h"
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QGraphicsItem *parent) ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QGraphicsItem *parent)
: SelectZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0), numberCards(_numberCards), origZone(_origZone), sortByName(false), sortByType(false) : SelectZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0), numberCards(_numberCards), origZone(_origZone), sortByName(false), sortByType(false)
@ -122,9 +123,9 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
card->update(); card->update();
} }
void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/) void ZoneViewZone::handleDropEvent(CardDragItem *dragItem, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
{ {
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), 0, 0, false)); player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), dragItem->getId(), player->getId(), getName(), 0, 0, false));
} }
void ZoneViewZone::removeCard(int position) void ZoneViewZone::removeCard(int position)

View file

@ -13,7 +13,7 @@ class ZoneViewZone : public SelectZone, public QGraphicsLayoutItem {
private: private:
QRectF bRect, optimumRect; QRectF bRect, optimumRect;
int minRows, numberCards; int minRows, numberCards;
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown); void handleDropEvent(CardDragItem *dragItem, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
CardZone *origZone; CardZone *origZone;
bool sortByName, sortByType; bool sortByName, sortByType;
public: public:

View file

@ -14,7 +14,7 @@ void ProtocolItem::initializeHash()
initializeHashAuto(); initializeHashAuto();
registerSerializableItem("move_card_to_zone", MoveCardToZone::newItem); registerSerializableItem("move_card_to_zone", MoveCardToZone::newItem);
registerSerializableItem("chat_channel", ServerInfo_ChatChannel::newItem); registerSerializableItem("room", ServerInfo_Room::newItem);
registerSerializableItem("user", ServerInfo_User::newItem); registerSerializableItem("user", ServerInfo_User::newItem);
registerSerializableItem("game", ServerInfo_Game::newItem); registerSerializableItem("game", ServerInfo_Game::newItem);
registerSerializableItem("card_counter", ServerInfo_CardCounter::newItem); registerSerializableItem("card_counter", ServerInfo_CardCounter::newItem);
@ -44,9 +44,10 @@ void ProtocolItem::initializeHash()
registerSerializableItem("respdeck_upload", Response_DeckUpload::newItem); registerSerializableItem("respdeck_upload", Response_DeckUpload::newItem);
registerSerializableItem("respdump_zone", Response_DumpZone::newItem); registerSerializableItem("respdump_zone", Response_DumpZone::newItem);
registerSerializableItem("generic_eventlist_games", Event_ListGames::newItem); registerSerializableItem("room_eventlist_games", Event_ListGames::newItem);
registerSerializableItem("room_eventjoin_room", Event_JoinRoom::newItem);
registerSerializableItem("generic_eventuser_joined", Event_UserJoined::newItem); registerSerializableItem("generic_eventuser_joined", Event_UserJoined::newItem);
registerSerializableItem("generic_eventlist_chat_channels", Event_ListChatChannels::newItem); registerSerializableItem("generic_eventlist_rooms", Event_ListRooms::newItem);
registerSerializableItem("game_eventjoin", Event_Join::newItem); registerSerializableItem("game_eventjoin", Event_Join::newItem);
registerSerializableItem("game_eventgame_state_changed", Event_GameStateChanged::newItem); registerSerializableItem("game_eventgame_state_changed", Event_GameStateChanged::newItem);
registerSerializableItem("game_eventplayer_properties_changed", Event_PlayerPropertiesChanged::newItem); registerSerializableItem("game_eventplayer_properties_changed", Event_PlayerPropertiesChanged::newItem);
@ -55,8 +56,6 @@ void ProtocolItem::initializeHash()
registerSerializableItem("game_eventdraw_cards", Event_DrawCards::newItem); registerSerializableItem("game_eventdraw_cards", Event_DrawCards::newItem);
registerSerializableItem("game_eventreveal_cards", Event_RevealCards::newItem); registerSerializableItem("game_eventreveal_cards", Event_RevealCards::newItem);
registerSerializableItem("game_eventping", Event_Ping::newItem); registerSerializableItem("game_eventping", Event_Ping::newItem);
registerSerializableItem("chat_eventchat_list_players", Event_ChatListPlayers::newItem);
registerSerializableItem("chat_eventchat_join_channel", Event_ChatJoinChannel::newItem);
} }
TopLevelProtocolItem::TopLevelProtocolItem() TopLevelProtocolItem::TopLevelProtocolItem()
@ -284,36 +283,29 @@ GameEventContext::GameEventContext(const QString &_contextName)
{ {
} }
ChatEvent::ChatEvent(const QString &_eventName, const QString &_channel) RoomEvent::RoomEvent(const QString &_eventName, int _roomId)
: ProtocolItem("chat_event", _eventName) : ProtocolItem("room_event", _eventName)
{ {
insertItem(new SerializableItem_String("channel", _channel)); insertItem(new SerializableItem_Int("room_id", _roomId));
} }
Event_ListChatChannels::Event_ListChatChannels(const QList<ServerInfo_ChatChannel *> &_channelList) Event_ListRooms::Event_ListRooms(const QList<ServerInfo_Room *> &_roomList)
: GenericEvent("list_chat_channels") : GenericEvent("list_rooms")
{ {
for (int i = 0; i < _channelList.size(); ++i) for (int i = 0; i < _roomList.size(); ++i)
itemList.append(_channelList[i]); itemList.append(_roomList[i]);
} }
Event_ChatListPlayers::Event_ChatListPlayers(const QString &_channel, const QList<ServerInfo_User *> &_playerList) Event_JoinRoom::Event_JoinRoom(int _roomId, ServerInfo_User *_info)
: ChatEvent("chat_list_players", _channel) : RoomEvent("join_room", _roomId)
{
for (int i = 0; i < _playerList.size(); ++i)
itemList.append(_playerList[i]);
}
Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, ServerInfo_User *_info)
: ChatEvent("chat_join_channel", _channel)
{ {
if (!_info) if (!_info)
_info = new ServerInfo_User; _info = new ServerInfo_User;
insertItem(_info); insertItem(_info);
} }
Event_ListGames::Event_ListGames(const QList<ServerInfo_Game *> &_gameList) Event_ListGames::Event_ListGames(int _roomId, const QList<ServerInfo_Game *> &_gameList)
: GenericEvent("list_games") : RoomEvent("list_games", _roomId)
{ {
for (int i = 0; i < _gameList.size(); ++i) for (int i = 0; i < _gameList.size(); ++i)
itemList.append(_gameList[i]); itemList.append(_gameList[i]);

View file

@ -25,9 +25,8 @@ enum ItemId {
ItemId_Command_DeckUpload = ItemId_Other + 100, ItemId_Command_DeckUpload = ItemId_Other + 100,
ItemId_Command_DeckSelect = ItemId_Other + 101, ItemId_Command_DeckSelect = ItemId_Other + 101,
ItemId_Command_SetSideboardPlan = ItemId_Other + 102, ItemId_Command_SetSideboardPlan = ItemId_Other + 102,
ItemId_Event_ListChatChannels = ItemId_Other + 200, ItemId_Event_ListRooms = ItemId_Other + 200,
ItemId_Event_ChatListPlayers = ItemId_Other + 201, ItemId_Event_JoinRoom = ItemId_Other + 201,
ItemId_Event_ChatJoinChannel = ItemId_Other + 202,
ItemId_Event_ListGames = ItemId_Other + 203, ItemId_Event_ListGames = ItemId_Other + 203,
ItemId_Event_UserJoined = ItemId_Other + 204, ItemId_Event_UserJoined = ItemId_Other + 204,
ItemId_Event_GameStateChanged = ItemId_Other + 205, ItemId_Event_GameStateChanged = ItemId_Other + 205,
@ -136,15 +135,15 @@ public:
int getPrivatePlayerId() const { return privatePlayerId; } int getPrivatePlayerId() const { return privatePlayerId; }
}; };
class ChatCommand : public Command { class RoomCommand : public Command {
Q_OBJECT Q_OBJECT
public: public:
ChatCommand(const QString &_cmdName, const QString &_channel) RoomCommand(const QString &_cmdName, int _roomId)
: Command(_cmdName) : Command(_cmdName)
{ {
insertItem(new SerializableItem_String("channel", _channel)); insertItem(new SerializableItem_Int("room_id", _roomId));
} }
QString getChannel() const { return static_cast<SerializableItem_String *>(itemMap.value("channel"))->getData(); } int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); }
}; };
class GameCommand : public Command { class GameCommand : public Command {
@ -304,44 +303,35 @@ public:
void setGameId(int _gameId) { static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->setData(_gameId); } void setGameId(int _gameId) { static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->setData(_gameId); }
}; };
class ChatEvent : public ProtocolItem { class RoomEvent : public ProtocolItem {
Q_OBJECT Q_OBJECT
public: public:
ChatEvent(const QString &_eventName, const QString &_channel); RoomEvent(const QString &_eventName, int _roomId);
QString getChannel() const { return static_cast<SerializableItem_String *>(itemMap.value("channel"))->getData(); } int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); }
}; };
class Event_ListChatChannels : public GenericEvent { class Event_ListRooms : public GenericEvent {
Q_OBJECT Q_OBJECT
public: public:
Event_ListChatChannels(const QList<ServerInfo_ChatChannel *> &_channelList = QList<ServerInfo_ChatChannel *>()); Event_ListRooms(const QList<ServerInfo_Room *> &_roomList = QList<ServerInfo_Room *>());
int getItemId() const { return ItemId_Event_ListChatChannels; } int getItemId() const { return ItemId_Event_ListRooms; }
static SerializableItem *newItem() { return new Event_ListChatChannels; } static SerializableItem *newItem() { return new Event_ListRooms; }
QList<ServerInfo_ChatChannel *> getChannelList() const { return typecastItemList<ServerInfo_ChatChannel *>(); } QList<ServerInfo_Room *> getRoomList() const { return typecastItemList<ServerInfo_Room *>(); }
}; };
class Event_ChatListPlayers : public ChatEvent { class Event_JoinRoom : public RoomEvent {
Q_OBJECT Q_OBJECT
public: public:
Event_ChatListPlayers(const QString &_channel = QString(), const QList<ServerInfo_User *> &_playerList = QList<ServerInfo_User *>()); Event_JoinRoom(int _roomId = -1, ServerInfo_User *_info = 0);
int getItemId() const { return ItemId_Event_ChatListPlayers; } int getItemId() const { return ItemId_Event_JoinRoom; }
static SerializableItem *newItem() { return new Event_ChatListPlayers; } static SerializableItem *newItem() { return new Event_JoinRoom; }
QList<ServerInfo_User *> getPlayerList() const { return typecastItemList<ServerInfo_User *>(); }
};
class Event_ChatJoinChannel : public ChatEvent {
Q_OBJECT
public:
Event_ChatJoinChannel(const QString &_channel = QString(), ServerInfo_User *_info = 0);
int getItemId() const { return ItemId_Event_ChatJoinChannel; }
static SerializableItem *newItem() { return new Event_ChatJoinChannel; }
ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); } ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
}; };
class Event_ListGames : public GenericEvent { class Event_ListGames : public RoomEvent {
Q_OBJECT Q_OBJECT
public: public:
Event_ListGames(const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>()); Event_ListGames(int _roomId = -1, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>());
int getItemId() const { return ItemId_Event_ListGames; } int getItemId() const { return ItemId_Event_ListGames; }
static SerializableItem *newItem() { return new Event_ListGames; } static SerializableItem *newItem() { return new Event_ListGames; }
QList<ServerInfo_Game *> getGameList() const { return typecastItemList<ServerInfo_Game *>(); } QList<ServerInfo_Game *> getGameList() const { return typecastItemList<ServerInfo_Game *>(); }

View file

@ -3,11 +3,13 @@
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
ServerInfo_ChatChannel::ServerInfo_ChatChannel(const QString &_name, const QString &_description, int _playerCount, bool _autoJoin) ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QString &_description, int _gameCount, int _playerCount, bool _autoJoin)
: SerializableItem_Map("chat_channel") : SerializableItem_Map("room")
{ {
insertItem(new SerializableItem_Int("room_id", _roomId));
insertItem(new SerializableItem_String("name", _name)); insertItem(new SerializableItem_String("name", _name));
insertItem(new SerializableItem_String("description", _description)); insertItem(new SerializableItem_String("description", _description));
insertItem(new SerializableItem_Int("game_count", _gameCount));
insertItem(new SerializableItem_Int("player_count", _playerCount)); insertItem(new SerializableItem_Int("player_count", _playerCount));
insertItem(new SerializableItem_Bool("auto_join", _autoJoin)); insertItem(new SerializableItem_Bool("auto_join", _autoJoin));
} }

View file

@ -20,12 +20,14 @@ enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespInvalidData, Re
// list index, whereas cards in any other zone are referenced by their ids. // list index, whereas cards in any other zone are referenced by their ids.
enum ZoneType { PrivateZone, PublicZone, HiddenZone }; enum ZoneType { PrivateZone, PublicZone, HiddenZone };
class ServerInfo_ChatChannel : public SerializableItem_Map { class ServerInfo_Room : public SerializableItem_Map {
public: public:
ServerInfo_ChatChannel(const QString &_name = QString(), const QString &_description = QString(), int _playerCount = -1, bool _autoJoin = false); ServerInfo_Room(int _id = -1, const QString &_name = QString(), const QString &_description = QString(), int _gameCount = -1, int _playerCount = -1, bool _autoJoin = false);
static SerializableItem *newItem() { return new ServerInfo_ChatChannel; } 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(); } QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); } QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
int getGameCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_count"))->getData(); }
int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); } int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); }
bool getAutoJoin() const { return static_cast<SerializableItem_Bool *>(itemMap.value("auto_join"))->getData(); } bool getAutoJoin() const { return static_cast<SerializableItem_Bool *>(itemMap.value("auto_join"))->getData(); }
}; };

View file

@ -2,73 +2,72 @@ enum AutoItemId {
ItemId_Command_Ping = 1001, ItemId_Command_Ping = 1001,
ItemId_Command_Login = 1002, ItemId_Command_Login = 1002,
ItemId_Command_Message = 1003, ItemId_Command_Message = 1003,
ItemId_Command_GetUserInfo = 1004, ItemId_Command_ListUsers = 1004,
ItemId_Command_DeckList = 1005, ItemId_Command_GetUserInfo = 1005,
ItemId_Command_DeckNewDir = 1006, ItemId_Command_DeckList = 1006,
ItemId_Command_DeckDelDir = 1007, ItemId_Command_DeckNewDir = 1007,
ItemId_Command_DeckDel = 1008, ItemId_Command_DeckDelDir = 1008,
ItemId_Command_DeckDownload = 1009, ItemId_Command_DeckDel = 1009,
ItemId_Command_ListChatChannels = 1010, ItemId_Command_DeckDownload = 1010,
ItemId_Command_ChatJoinChannel = 1011, ItemId_Command_ListRooms = 1011,
ItemId_Command_ChatLeaveChannel = 1012, ItemId_Command_JoinRoom = 1012,
ItemId_Command_ChatSay = 1013, ItemId_Command_LeaveRoom = 1013,
ItemId_Command_ListGames = 1014, ItemId_Command_RoomSay = 1014,
ItemId_Command_ListUsers = 1015, ItemId_Command_CreateGame = 1015,
ItemId_Command_CreateGame = 1016, ItemId_Command_JoinGame = 1016,
ItemId_Command_JoinGame = 1017, ItemId_Command_LeaveGame = 1017,
ItemId_Command_LeaveGame = 1018, ItemId_Command_Say = 1018,
ItemId_Command_Say = 1019, ItemId_Command_Shuffle = 1019,
ItemId_Command_Shuffle = 1020, ItemId_Command_Mulligan = 1020,
ItemId_Command_Mulligan = 1021, ItemId_Command_RollDie = 1021,
ItemId_Command_RollDie = 1022, ItemId_Command_DrawCards = 1022,
ItemId_Command_DrawCards = 1023, ItemId_Command_MoveCard = 1023,
ItemId_Command_MoveCard = 1024, ItemId_Command_FlipCard = 1024,
ItemId_Command_FlipCard = 1025, ItemId_Command_AttachCard = 1025,
ItemId_Command_AttachCard = 1026, ItemId_Command_CreateToken = 1026,
ItemId_Command_CreateToken = 1027, ItemId_Command_CreateArrow = 1027,
ItemId_Command_CreateArrow = 1028, ItemId_Command_DeleteArrow = 1028,
ItemId_Command_DeleteArrow = 1029, ItemId_Command_SetCardAttr = 1029,
ItemId_Command_SetCardAttr = 1030, ItemId_Command_SetCardCounter = 1030,
ItemId_Command_SetCardCounter = 1031, ItemId_Command_IncCardCounter = 1031,
ItemId_Command_IncCardCounter = 1032, ItemId_Command_ReadyStart = 1032,
ItemId_Command_ReadyStart = 1033, ItemId_Command_Concede = 1033,
ItemId_Command_Concede = 1034, ItemId_Command_IncCounter = 1034,
ItemId_Command_IncCounter = 1035, ItemId_Command_CreateCounter = 1035,
ItemId_Command_CreateCounter = 1036, ItemId_Command_SetCounter = 1036,
ItemId_Command_SetCounter = 1037, ItemId_Command_DelCounter = 1037,
ItemId_Command_DelCounter = 1038, ItemId_Command_NextTurn = 1038,
ItemId_Command_NextTurn = 1039, ItemId_Command_SetActivePhase = 1039,
ItemId_Command_SetActivePhase = 1040, ItemId_Command_DumpZone = 1040,
ItemId_Command_DumpZone = 1041, ItemId_Command_StopDumpZone = 1041,
ItemId_Command_StopDumpZone = 1042, ItemId_Command_RevealCards = 1042,
ItemId_Command_RevealCards = 1043, ItemId_Event_Say = 1043,
ItemId_Event_Say = 1044, ItemId_Event_Leave = 1044,
ItemId_Event_Leave = 1045, ItemId_Event_GameClosed = 1045,
ItemId_Event_GameClosed = 1046, ItemId_Event_Shuffle = 1046,
ItemId_Event_Shuffle = 1047, ItemId_Event_RollDie = 1047,
ItemId_Event_RollDie = 1048, ItemId_Event_MoveCard = 1048,
ItemId_Event_MoveCard = 1049, ItemId_Event_FlipCard = 1049,
ItemId_Event_FlipCard = 1050, ItemId_Event_DestroyCard = 1050,
ItemId_Event_DestroyCard = 1051, ItemId_Event_AttachCard = 1051,
ItemId_Event_AttachCard = 1052, ItemId_Event_CreateToken = 1052,
ItemId_Event_CreateToken = 1053, ItemId_Event_DeleteArrow = 1053,
ItemId_Event_DeleteArrow = 1054, ItemId_Event_SetCardAttr = 1054,
ItemId_Event_SetCardAttr = 1055, ItemId_Event_SetCardCounter = 1055,
ItemId_Event_SetCardCounter = 1056, ItemId_Event_SetCounter = 1056,
ItemId_Event_SetCounter = 1057, ItemId_Event_DelCounter = 1057,
ItemId_Event_DelCounter = 1058, ItemId_Event_SetActivePlayer = 1058,
ItemId_Event_SetActivePlayer = 1059, ItemId_Event_SetActivePhase = 1059,
ItemId_Event_SetActivePhase = 1060, ItemId_Event_DumpZone = 1060,
ItemId_Event_DumpZone = 1061, ItemId_Event_StopDumpZone = 1061,
ItemId_Event_StopDumpZone = 1062, ItemId_Event_ServerMessage = 1062,
ItemId_Event_ServerMessage = 1063, ItemId_Event_Message = 1063,
ItemId_Event_Message = 1064, ItemId_Event_GameJoined = 1064,
ItemId_Event_GameJoined = 1065, ItemId_Event_UserLeft = 1065,
ItemId_Event_UserLeft = 1066, ItemId_Event_LeaveRoom = 1066,
ItemId_Event_ChatLeaveChannel = 1067, ItemId_Event_RoomSay = 1067,
ItemId_Event_ChatSay = 1068, ItemId_Context_ReadyStart = 1068,
ItemId_Context_ReadyStart = 1069, ItemId_Context_Concede = 1069,
ItemId_Context_Concede = 1070, ItemId_Context_DeckSelect = 1070,
ItemId_Context_DeckSelect = 1071, ItemId_Other = 1071
ItemId_Other = 1072
}; };

View file

@ -17,6 +17,10 @@ Command_Message::Command_Message(const QString &_userName, const QString &_text)
insertItem(new SerializableItem_String("user_name", _userName)); insertItem(new SerializableItem_String("user_name", _userName));
insertItem(new SerializableItem_String("text", _text)); insertItem(new SerializableItem_String("text", _text));
} }
Command_ListUsers::Command_ListUsers()
: Command("list_users")
{
}
Command_GetUserInfo::Command_GetUserInfo(const QString &_userName) Command_GetUserInfo::Command_GetUserInfo(const QString &_userName)
: Command("get_user_info") : Command("get_user_info")
{ {
@ -47,34 +51,26 @@ Command_DeckDownload::Command_DeckDownload(int _deckId)
{ {
insertItem(new SerializableItem_Int("deck_id", _deckId)); insertItem(new SerializableItem_Int("deck_id", _deckId));
} }
Command_ListChatChannels::Command_ListChatChannels() Command_ListRooms::Command_ListRooms()
: Command("list_chat_channels") : Command("list_rooms")
{ {
} }
Command_ChatJoinChannel::Command_ChatJoinChannel(const QString &_channel) Command_JoinRoom::Command_JoinRoom(int _roomId)
: Command("chat_join_channel") : Command("join_room")
{ {
insertItem(new SerializableItem_String("channel", _channel)); insertItem(new SerializableItem_Int("room_id", _roomId));
} }
Command_ChatLeaveChannel::Command_ChatLeaveChannel(const QString &_channel) Command_LeaveRoom::Command_LeaveRoom(int _roomId)
: ChatCommand("chat_leave_channel", _channel) : RoomCommand("leave_room", _roomId)
{ {
} }
Command_ChatSay::Command_ChatSay(const QString &_channel, const QString &_message) Command_RoomSay::Command_RoomSay(int _roomId, const QString &_message)
: ChatCommand("chat_say", _channel) : RoomCommand("room_say", _roomId)
{ {
insertItem(new SerializableItem_String("message", _message)); insertItem(new SerializableItem_String("message", _message));
} }
Command_ListGames::Command_ListGames() Command_CreateGame::Command_CreateGame(int _roomId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything)
: Command("list_games") : RoomCommand("create_game", _roomId)
{
}
Command_ListUsers::Command_ListUsers()
: Command("list_users")
{
}
Command_CreateGame::Command_CreateGame(const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything)
: Command("create_game")
{ {
insertItem(new SerializableItem_String("description", _description)); insertItem(new SerializableItem_String("description", _description));
insertItem(new SerializableItem_String("password", _password)); insertItem(new SerializableItem_String("password", _password));
@ -84,8 +80,8 @@ Command_CreateGame::Command_CreateGame(const QString &_description, const QStrin
insertItem(new SerializableItem_Bool("spectators_can_talk", _spectatorsCanTalk)); insertItem(new SerializableItem_Bool("spectators_can_talk", _spectatorsCanTalk));
insertItem(new SerializableItem_Bool("spectators_see_everything", _spectatorsSeeEverything)); insertItem(new SerializableItem_Bool("spectators_see_everything", _spectatorsSeeEverything));
} }
Command_JoinGame::Command_JoinGame(int _gameId, const QString &_password, bool _spectator) Command_JoinGame::Command_JoinGame(int _roomId, int _gameId, const QString &_password, bool _spectator)
: Command("join_game") : RoomCommand("join_game", _roomId)
{ {
insertItem(new SerializableItem_Int("game_id", _gameId)); insertItem(new SerializableItem_Int("game_id", _gameId));
insertItem(new SerializableItem_String("password", _password)); insertItem(new SerializableItem_String("password", _password));
@ -118,11 +114,12 @@ Command_DrawCards::Command_DrawCards(int _gameId, int _number)
{ {
insertItem(new SerializableItem_Int("number", _number)); insertItem(new SerializableItem_Int("number", _number));
} }
Command_MoveCard::Command_MoveCard(int _gameId, const QString &_startZone, int _cardId, const QString &_targetZone, int _x, int _y, bool _faceDown, bool _tapped) Command_MoveCard::Command_MoveCard(int _gameId, const QString &_startZone, int _cardId, int _targetPlayerId, const QString &_targetZone, int _x, int _y, bool _faceDown, bool _tapped)
: GameCommand("move_card", _gameId) : GameCommand("move_card", _gameId)
{ {
insertItem(new SerializableItem_String("start_zone", _startZone)); insertItem(new SerializableItem_String("start_zone", _startZone));
insertItem(new SerializableItem_Int("card_id", _cardId)); insertItem(new SerializableItem_Int("card_id", _cardId));
insertItem(new SerializableItem_Int("target_player_id", _targetPlayerId));
insertItem(new SerializableItem_String("target_zone", _targetZone)); insertItem(new SerializableItem_String("target_zone", _targetZone));
insertItem(new SerializableItem_Int("x", _x)); insertItem(new SerializableItem_Int("x", _x));
insertItem(new SerializableItem_Int("y", _y)); insertItem(new SerializableItem_Int("y", _y));
@ -283,13 +280,14 @@ Event_RollDie::Event_RollDie(int _playerId, int _sides, int _value)
insertItem(new SerializableItem_Int("sides", _sides)); insertItem(new SerializableItem_Int("sides", _sides));
insertItem(new SerializableItem_Int("value", _value)); insertItem(new SerializableItem_Int("value", _value));
} }
Event_MoveCard::Event_MoveCard(int _playerId, int _cardId, const QString &_cardName, const QString &_startZone, int _position, const QString &_targetZone, int _x, int _y, int _newCardId, bool _faceDown) Event_MoveCard::Event_MoveCard(int _playerId, int _cardId, const QString &_cardName, const QString &_startZone, int _position, int _targetPlayerId, const QString &_targetZone, int _x, int _y, int _newCardId, bool _faceDown)
: GameEvent("move_card", _playerId) : GameEvent("move_card", _playerId)
{ {
insertItem(new SerializableItem_Int("card_id", _cardId)); insertItem(new SerializableItem_Int("card_id", _cardId));
insertItem(new SerializableItem_String("card_name", _cardName)); insertItem(new SerializableItem_String("card_name", _cardName));
insertItem(new SerializableItem_String("start_zone", _startZone)); insertItem(new SerializableItem_String("start_zone", _startZone));
insertItem(new SerializableItem_Int("position", _position)); insertItem(new SerializableItem_Int("position", _position));
insertItem(new SerializableItem_Int("target_player_id", _targetPlayerId));
insertItem(new SerializableItem_String("target_zone", _targetZone)); insertItem(new SerializableItem_String("target_zone", _targetZone));
insertItem(new SerializableItem_Int("x", _x)); insertItem(new SerializableItem_Int("x", _x));
insertItem(new SerializableItem_Int("y", _y)); insertItem(new SerializableItem_Int("y", _y));
@ -415,13 +413,13 @@ Event_UserLeft::Event_UserLeft(const QString &_userName)
{ {
insertItem(new SerializableItem_String("user_name", _userName)); insertItem(new SerializableItem_String("user_name", _userName));
} }
Event_ChatLeaveChannel::Event_ChatLeaveChannel(const QString &_channel, const QString &_playerName) Event_LeaveRoom::Event_LeaveRoom(int _roomId, const QString &_playerName)
: ChatEvent("chat_leave_channel", _channel) : RoomEvent("leave_room", _roomId)
{ {
insertItem(new SerializableItem_String("player_name", _playerName)); insertItem(new SerializableItem_String("player_name", _playerName));
} }
Event_ChatSay::Event_ChatSay(const QString &_channel, const QString &_playerName, const QString &_message) Event_RoomSay::Event_RoomSay(int _roomId, const QString &_playerName, const QString &_message)
: ChatEvent("chat_say", _channel) : RoomEvent("room_say", _roomId)
{ {
insertItem(new SerializableItem_String("player_name", _playerName)); insertItem(new SerializableItem_String("player_name", _playerName));
insertItem(new SerializableItem_String("message", _message)); insertItem(new SerializableItem_String("message", _message));
@ -444,18 +442,17 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("cmdping", Command_Ping::newItem); itemNameHash.insert("cmdping", Command_Ping::newItem);
itemNameHash.insert("cmdlogin", Command_Login::newItem); itemNameHash.insert("cmdlogin", Command_Login::newItem);
itemNameHash.insert("cmdmessage", Command_Message::newItem); itemNameHash.insert("cmdmessage", Command_Message::newItem);
itemNameHash.insert("cmdlist_users", Command_ListUsers::newItem);
itemNameHash.insert("cmdget_user_info", Command_GetUserInfo::newItem); itemNameHash.insert("cmdget_user_info", Command_GetUserInfo::newItem);
itemNameHash.insert("cmddeck_list", Command_DeckList::newItem); itemNameHash.insert("cmddeck_list", Command_DeckList::newItem);
itemNameHash.insert("cmddeck_new_dir", Command_DeckNewDir::newItem); itemNameHash.insert("cmddeck_new_dir", Command_DeckNewDir::newItem);
itemNameHash.insert("cmddeck_del_dir", Command_DeckDelDir::newItem); itemNameHash.insert("cmddeck_del_dir", Command_DeckDelDir::newItem);
itemNameHash.insert("cmddeck_del", Command_DeckDel::newItem); itemNameHash.insert("cmddeck_del", Command_DeckDel::newItem);
itemNameHash.insert("cmddeck_download", Command_DeckDownload::newItem); itemNameHash.insert("cmddeck_download", Command_DeckDownload::newItem);
itemNameHash.insert("cmdlist_chat_channels", Command_ListChatChannels::newItem); itemNameHash.insert("cmdlist_rooms", Command_ListRooms::newItem);
itemNameHash.insert("cmdchat_join_channel", Command_ChatJoinChannel::newItem); itemNameHash.insert("cmdjoin_room", Command_JoinRoom::newItem);
itemNameHash.insert("cmdchat_leave_channel", Command_ChatLeaveChannel::newItem); itemNameHash.insert("cmdleave_room", Command_LeaveRoom::newItem);
itemNameHash.insert("cmdchat_say", Command_ChatSay::newItem); itemNameHash.insert("cmdroom_say", Command_RoomSay::newItem);
itemNameHash.insert("cmdlist_games", Command_ListGames::newItem);
itemNameHash.insert("cmdlist_users", Command_ListUsers::newItem);
itemNameHash.insert("cmdcreate_game", Command_CreateGame::newItem); itemNameHash.insert("cmdcreate_game", Command_CreateGame::newItem);
itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem); itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem);
itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem); itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem);
@ -507,8 +504,8 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("generic_eventmessage", Event_Message::newItem); itemNameHash.insert("generic_eventmessage", Event_Message::newItem);
itemNameHash.insert("generic_eventgame_joined", Event_GameJoined::newItem); itemNameHash.insert("generic_eventgame_joined", Event_GameJoined::newItem);
itemNameHash.insert("generic_eventuser_left", Event_UserLeft::newItem); itemNameHash.insert("generic_eventuser_left", Event_UserLeft::newItem);
itemNameHash.insert("chat_eventchat_leave_channel", Event_ChatLeaveChannel::newItem); itemNameHash.insert("room_eventleave_room", Event_LeaveRoom::newItem);
itemNameHash.insert("chat_eventchat_say", Event_ChatSay::newItem); itemNameHash.insert("room_eventroom_say", Event_RoomSay::newItem);
itemNameHash.insert("game_event_contextready_start", Context_ReadyStart::newItem); itemNameHash.insert("game_event_contextready_start", Context_ReadyStart::newItem);
itemNameHash.insert("game_event_contextconcede", Context_Concede::newItem); itemNameHash.insert("game_event_contextconcede", Context_Concede::newItem);
itemNameHash.insert("game_event_contextdeck_select", Context_DeckSelect::newItem); itemNameHash.insert("game_event_contextdeck_select", Context_DeckSelect::newItem);

View file

@ -1,27 +1,26 @@
0:ping 0:ping
0:login:s,username:s,password 0:login:s,username:s,password
0:message:s,user_name:s,text 0:message:s,user_name:s,text
0:list_users
0:get_user_info:s,user_name 0:get_user_info:s,user_name
0:deck_list 0:deck_list
0:deck_new_dir:s,path:s,dir_name 0:deck_new_dir:s,path:s,dir_name
0:deck_del_dir:s,path 0:deck_del_dir:s,path
0:deck_del:i,deck_id 0:deck_del:i,deck_id
0:deck_download:i,deck_id 0:deck_download:i,deck_id
0:list_chat_channels 0:list_rooms
0:chat_join_channel:s,channel 0:join_room:i,room_id
1:chat_leave_channel 1:leave_room
1:chat_say:s,message 1:room_say:s,message
0:list_games 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
0:list_users 1:join_game:i,game_id:s,password:b,spectator
0:create_game:s,description:s,password:i,max_players:b,spectators_allowed:b,spectators_need_password:b,spectators_can_talk:b,spectators_see_everything
0:join_game:i,game_id:s,password:b,spectator
2:leave_game 2:leave_game
2:say:s,message 2:say:s,message
2:shuffle 2:shuffle
2:mulligan 2:mulligan
2:roll_die:i,sides 2:roll_die:i,sides
2:draw_cards:i,number 2:draw_cards:i,number
2:move_card:s,start_zone:i,card_id:s,target_zone:i,x:i,y:b,face_down:b,tapped 2:move_card:s,start_zone:i,card_id:i,target_player_id:s,target_zone:i,x:i,y:b,face_down:b,tapped
2:flip_card:s,zone:i,card_id:b,face_down 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: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 2:create_token:s,zone:s,card_name:s,color:s,pt:s,annotation:b,destroy:i,x:i,y
@ -46,7 +45,7 @@
3:game_closed 3:game_closed
3:shuffle 3:shuffle
3:roll_die:i,sides:i,value 3:roll_die:i,sides:i,value
3:move_card:i,card_id:s,card_name:s,start_zone:i,position:s,target_zone:i,x:i,y:i,new_card_id:b,face_down 3:move_card:i,card_id:s,card_name:s,start_zone:i,position:i,target_player_id:s,target_zone:i,x:i,y:i,new_card_id:b,face_down
3:flip_card:s,zone:i,card_id:s,card_name:b,face_down 3:flip_card:s,zone:i,card_id:s,card_name:b,face_down
3:destroy_card:s,zone:i,card_id 3:destroy_card:s,zone:i,card_id
3:attach_card:s,start_zone:i,card_id:i,target_player_id:s,target_zone:i,target_card_id 3:attach_card:s,start_zone:i,card_id:i,target_player_id:s,target_zone:i,target_card_id
@ -64,8 +63,8 @@
4:message:s,sender_name:s,receiver_name:s,text 4:message:s,sender_name:s,receiver_name:s,text
4:game_joined:i,game_id:s,game_description:i,player_id:b,spectator:b,spectators_can_talk:b,spectators_see_everything:b,resuming 4:game_joined:i,game_id:s,game_description:i,player_id:b,spectator:b,spectators_can_talk:b,spectators_see_everything:b,resuming
4:user_left:s,user_name 4:user_left:s,user_name
5:chat_leave_channel:s,player_name 5:leave_room:s,player_name
5:chat_say:s,player_name:s,message 5:room_say:s,player_name:s,message
6:ready_start 6:ready_start
6:concede 6:concede
6:deck_select:i,deck_id 6:deck_select:i,deck_id

View file

@ -28,6 +28,13 @@ public:
static SerializableItem *newItem() { return new Command_Message; } static SerializableItem *newItem() { return new Command_Message; }
int getItemId() const { return ItemId_Command_Message; } int getItemId() const { return ItemId_Command_Message; }
}; };
class Command_ListUsers : public Command {
Q_OBJECT
public:
Command_ListUsers();
static SerializableItem *newItem() { return new Command_ListUsers; }
int getItemId() const { return ItemId_Command_ListUsers; }
};
class Command_GetUserInfo : public Command { class Command_GetUserInfo : public Command {
Q_OBJECT Q_OBJECT
public: public:
@ -76,54 +83,40 @@ public:
static SerializableItem *newItem() { return new Command_DeckDownload; } static SerializableItem *newItem() { return new Command_DeckDownload; }
int getItemId() const { return ItemId_Command_DeckDownload; } int getItemId() const { return ItemId_Command_DeckDownload; }
}; };
class Command_ListChatChannels : public Command { class Command_ListRooms : public Command {
Q_OBJECT Q_OBJECT
public: public:
Command_ListChatChannels(); Command_ListRooms();
static SerializableItem *newItem() { return new Command_ListChatChannels; } static SerializableItem *newItem() { return new Command_ListRooms; }
int getItemId() const { return ItemId_Command_ListChatChannels; } int getItemId() const { return ItemId_Command_ListRooms; }
}; };
class Command_ChatJoinChannel : public Command { class Command_JoinRoom : public Command {
Q_OBJECT Q_OBJECT
public: public:
Command_ChatJoinChannel(const QString &_channel = QString()); Command_JoinRoom(int _roomId = -1);
QString getChannel() const { return static_cast<SerializableItem_String *>(itemMap.value("channel"))->getData(); }; int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); };
static SerializableItem *newItem() { return new Command_ChatJoinChannel; } static SerializableItem *newItem() { return new Command_JoinRoom; }
int getItemId() const { return ItemId_Command_ChatJoinChannel; } int getItemId() const { return ItemId_Command_JoinRoom; }
}; };
class Command_ChatLeaveChannel : public ChatCommand { class Command_LeaveRoom : public RoomCommand {
Q_OBJECT Q_OBJECT
public: public:
Command_ChatLeaveChannel(const QString &_channel = QString()); Command_LeaveRoom(int _roomId = -1);
static SerializableItem *newItem() { return new Command_ChatLeaveChannel; } static SerializableItem *newItem() { return new Command_LeaveRoom; }
int getItemId() const { return ItemId_Command_ChatLeaveChannel; } int getItemId() const { return ItemId_Command_LeaveRoom; }
}; };
class Command_ChatSay : public ChatCommand { class Command_RoomSay : public RoomCommand {
Q_OBJECT Q_OBJECT
public: public:
Command_ChatSay(const QString &_channel = QString(), const QString &_message = QString()); Command_RoomSay(int _roomId = -1, const QString &_message = QString());
QString getMessage() const { return static_cast<SerializableItem_String *>(itemMap.value("message"))->getData(); }; QString getMessage() const { return static_cast<SerializableItem_String *>(itemMap.value("message"))->getData(); };
static SerializableItem *newItem() { return new Command_ChatSay; } static SerializableItem *newItem() { return new Command_RoomSay; }
int getItemId() const { return ItemId_Command_ChatSay; } int getItemId() const { return ItemId_Command_RoomSay; }
}; };
class Command_ListGames : public Command { class Command_CreateGame : public RoomCommand {
Q_OBJECT Q_OBJECT
public: public:
Command_ListGames(); 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);
static SerializableItem *newItem() { return new Command_ListGames; }
int getItemId() const { return ItemId_Command_ListGames; }
};
class Command_ListUsers : public Command {
Q_OBJECT
public:
Command_ListUsers();
static SerializableItem *newItem() { return new Command_ListUsers; }
int getItemId() const { return ItemId_Command_ListUsers; }
};
class Command_CreateGame : public Command {
Q_OBJECT
public:
Command_CreateGame(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 getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); };
QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->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(); }; int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); };
@ -134,10 +127,10 @@ public:
static SerializableItem *newItem() { return new Command_CreateGame; } static SerializableItem *newItem() { return new Command_CreateGame; }
int getItemId() const { return ItemId_Command_CreateGame; } int getItemId() const { return ItemId_Command_CreateGame; }
}; };
class Command_JoinGame : public Command { class Command_JoinGame : public RoomCommand {
Q_OBJECT Q_OBJECT
public: public:
Command_JoinGame(int _gameId = -1, const QString &_password = QString(), bool _spectator = false); Command_JoinGame(int _roomId = -1, int _gameId = -1, const QString &_password = QString(), bool _spectator = false);
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }; int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); };
QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); }; QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); };
bool getSpectator() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectator"))->getData(); }; bool getSpectator() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectator"))->getData(); };
@ -192,9 +185,10 @@ public:
class Command_MoveCard : public GameCommand { class Command_MoveCard : public GameCommand {
Q_OBJECT Q_OBJECT
public: public:
Command_MoveCard(int _gameId = -1, const QString &_startZone = QString(), int _cardId = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, bool _faceDown = false, bool _tapped = false); Command_MoveCard(int _gameId = -1, const QString &_startZone = QString(), int _cardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, bool _faceDown = false, bool _tapped = false);
QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); }; QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); };
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); }; int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
int getTargetPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_player_id"))->getData(); };
QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); }; QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); };
int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); }; int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); };
int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); }; int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); };
@ -432,11 +426,12 @@ public:
class Event_MoveCard : public GameEvent { class Event_MoveCard : public GameEvent {
Q_OBJECT Q_OBJECT
public: public:
Event_MoveCard(int _playerId = -1, int _cardId = -1, const QString &_cardName = QString(), const QString &_startZone = QString(), int _position = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, int _newCardId = -1, bool _faceDown = false); Event_MoveCard(int _playerId = -1, int _cardId = -1, const QString &_cardName = QString(), const QString &_startZone = QString(), int _position = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, int _newCardId = -1, bool _faceDown = false);
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); }; int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
QString getCardName() const { return static_cast<SerializableItem_String *>(itemMap.value("card_name"))->getData(); }; QString getCardName() const { return static_cast<SerializableItem_String *>(itemMap.value("card_name"))->getData(); };
QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); }; QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); };
int getPosition() const { return static_cast<SerializableItem_Int *>(itemMap.value("position"))->getData(); }; int getPosition() const { return static_cast<SerializableItem_Int *>(itemMap.value("position"))->getData(); };
int getTargetPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_player_id"))->getData(); };
QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); }; QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); };
int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); }; int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); };
int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); }; int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); };
@ -615,22 +610,22 @@ public:
static SerializableItem *newItem() { return new Event_UserLeft; } static SerializableItem *newItem() { return new Event_UserLeft; }
int getItemId() const { return ItemId_Event_UserLeft; } int getItemId() const { return ItemId_Event_UserLeft; }
}; };
class Event_ChatLeaveChannel : public ChatEvent { class Event_LeaveRoom : public RoomEvent {
Q_OBJECT Q_OBJECT
public: public:
Event_ChatLeaveChannel(const QString &_channel = QString(), const QString &_playerName = QString()); Event_LeaveRoom(int _roomId = -1, const QString &_playerName = QString());
QString getPlayerName() const { return static_cast<SerializableItem_String *>(itemMap.value("player_name"))->getData(); }; QString getPlayerName() const { return static_cast<SerializableItem_String *>(itemMap.value("player_name"))->getData(); };
static SerializableItem *newItem() { return new Event_ChatLeaveChannel; } static SerializableItem *newItem() { return new Event_LeaveRoom; }
int getItemId() const { return ItemId_Event_ChatLeaveChannel; } int getItemId() const { return ItemId_Event_LeaveRoom; }
}; };
class Event_ChatSay : public ChatEvent { class Event_RoomSay : public RoomEvent {
Q_OBJECT Q_OBJECT
public: public:
Event_ChatSay(const QString &_channel = QString(), const QString &_playerName = QString(), const QString &_message = QString()); Event_RoomSay(int _roomId = -1, const QString &_playerName = QString(), const QString &_message = QString());
QString getPlayerName() const { return static_cast<SerializableItem_String *>(itemMap.value("player_name"))->getData(); }; QString getPlayerName() const { return static_cast<SerializableItem_String *>(itemMap.value("player_name"))->getData(); };
QString getMessage() const { return static_cast<SerializableItem_String *>(itemMap.value("message"))->getData(); }; QString getMessage() const { return static_cast<SerializableItem_String *>(itemMap.value("message"))->getData(); };
static SerializableItem *newItem() { return new Event_ChatSay; } static SerializableItem *newItem() { return new Event_RoomSay; }
int getItemId() const { return ItemId_Event_ChatSay; } int getItemId() const { return ItemId_Event_RoomSay; }
}; };
class Context_ReadyStart : public GameEventContext { class Context_ReadyStart : public GameEventContext {
Q_OBJECT Q_OBJECT

View file

@ -34,10 +34,10 @@ while (<file>) {
} elsif ($type == 1) { } elsif ($type == 1) {
$type = 'cmd'; $type = 'cmd';
$namePrefix = 'Command'; $namePrefix = 'Command';
$baseClass = 'ChatCommand'; $baseClass = 'RoomCommand';
$parentConstructorCall = "$baseClass(\"$name1\", _channel)"; $parentConstructorCall = "$baseClass(\"$name1\", _roomId)";
$constructorParamsH = "const QString &_channel = QString()"; $constructorParamsH = "int _roomId = -1";
$constructorParamsCpp = "const QString &_channel"; $constructorParamsCpp = "int _roomId";
} elsif ($type == 2) { } elsif ($type == 2) {
$type = 'cmd'; $type = 'cmd';
$namePrefix = 'Command'; $namePrefix = 'Command';
@ -60,12 +60,12 @@ while (<file>) {
$constructorParamsH = ""; $constructorParamsH = "";
$constructorParamsCpp = ""; $constructorParamsCpp = "";
} elsif ($type == 5) { } elsif ($type == 5) {
$type = 'chat_event'; $type = 'room_event';
$namePrefix = 'Event'; $namePrefix = 'Event';
$baseClass = 'ChatEvent'; $baseClass = 'RoomEvent';
$parentConstructorCall = "$baseClass(\"$name1\", _channel)"; $parentConstructorCall = "$baseClass(\"$name1\", _roomId)";
$constructorParamsH = "const QString &_channel = QString()"; $constructorParamsH = "int _roomId = -1";
$constructorParamsCpp = "const QString &_channel"; $constructorParamsCpp = "int _roomId";
} elsif ($type == 6) { } elsif ($type == 6) {
$type = 'game_event_context'; $type = 'game_event_context';
$namePrefix = 'Context'; $namePrefix = 'Context';

View file

@ -20,7 +20,7 @@
#include "server.h" #include "server.h"
#include "server_game.h" #include "server_game.h"
#include "server_counter.h" #include "server_counter.h"
#include "server_chatchannel.h" #include "server_room.h"
#include "server_protocolhandler.h" #include "server_protocolhandler.h"
#include "protocol_datastructures.h" #include "protocol_datastructures.h"
#include <QDebug> #include <QDebug>
@ -69,17 +69,6 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
return authState; return authState;
} }
Server_Game *Server::createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator)
{
Server_Game *newGame = new Server_Game(creator, nextGameId++, description, password, maxPlayers, spectatorsAllowed, spectatorsNeedPassword, spectatorsCanTalk, spectatorsSeeEverything, this);
games.insert(newGame->getGameId(), newGame);
connect(newGame, SIGNAL(gameClosing()), this, SLOT(gameClosing()));
broadcastGameListUpdate(newGame);
return newGame;
}
void Server::addClient(Server_ProtocolHandler *client) void Server::addClient(Server_ProtocolHandler *client)
{ {
clients << client; clients << client;
@ -106,56 +95,29 @@ Server_Game *Server::getGame(int gameId) const
return games.value(gameId); return games.value(gameId);
} }
void Server::broadcastGameListUpdate(Server_Game *game) void Server::broadcastRoomUpdate()
{ {
QList<ServerInfo_Game *> eventGameList; Server_Room *room = static_cast<Server_Room *>(sender());
if (game->getPlayerCount()) QList<ServerInfo_Room *> eventRoomList;
// Game is open eventRoomList.append(new ServerInfo_Room(room->getId(), room->getName(), room->getDescription(), room->getGames().size(), room->size(), room->getAutoJoin()));
eventGameList.append(new ServerInfo_Game( Event_ListRooms *event = new Event_ListRooms(eventRoomList);
game->getGameId(),
game->getDescription(),
!game->getPassword().isEmpty(),
game->getPlayerCount(),
game->getMaxPlayers(),
new ServerInfo_User(game->getCreatorInfo()),
game->getSpectatorsAllowed(),
game->getSpectatorsNeedPassword(),
game->getSpectatorCount()
));
else
// Game is closing
eventGameList.append(new ServerInfo_Game(game->getGameId(), QString(), false, 0, game->getMaxPlayers(), 0, false, 0));
Event_ListGames *event = new Event_ListGames(eventGameList);
for (int i = 0; i < clients.size(); i++)
if (clients[i]->getAcceptsGameListChanges())
clients[i]->sendProtocolItem(event, false);
delete event;
}
void Server::broadcastChannelUpdate()
{
Server_ChatChannel *channel = static_cast<Server_ChatChannel *>(sender());
QList<ServerInfo_ChatChannel *> eventChannelList;
eventChannelList.append(new ServerInfo_ChatChannel(channel->getName(), channel->getDescription(), channel->size(), channel->getAutoJoin()));
Event_ListChatChannels *event = new Event_ListChatChannels(eventChannelList);
for (int i = 0; i < clients.size(); ++i) for (int i = 0; i < clients.size(); ++i)
if (clients[i]->getAcceptsChatChannelListChanges()) if (clients[i]->getAcceptsRoomListChanges())
clients[i]->sendProtocolItem(event, false); clients[i]->sendProtocolItem(event, false);
delete event; delete event;
} }
void Server::gameClosing() void Server::gameClosing(int gameId)
{ {
qDebug("Server::gameClosing"); qDebug("Server::gameClosing");
Server_Game *game = static_cast<Server_Game *>(sender()); games.remove(gameId);
broadcastGameListUpdate(game);
games.remove(games.key(game));
} }
void Server::addChatChannel(Server_ChatChannel *newChannel) void Server::addRoom(Server_Room *newRoom)
{ {
chatChannels.insert(newChannel->getName(), newChannel); rooms.insert(newRoom->getId(), newRoom);
connect(newChannel, SIGNAL(channelInfoChanged()), this, SLOT(broadcastChannelUpdate())); connect(newRoom, SIGNAL(roomInfoChanged()), this, SLOT(broadcastRoomUpdate()));
connect(newRoom, SIGNAL(gameCreated(Server_Game *)), this, SLOT(gameCreated(Server_Game *)));
connect(newRoom, SIGNAL(gameClosing(int)), this, SLOT(gameClosing(int)));
} }

View file

@ -6,7 +6,7 @@
#include <QMap> #include <QMap>
class Server_Game; class Server_Game;
class Server_ChatChannel; class Server_Room;
class Server_ProtocolHandler; class Server_ProtocolHandler;
class ServerInfo_User; class ServerInfo_User;
@ -18,22 +18,21 @@ class Server : public QObject
signals: signals:
void pingClockTimeout(); void pingClockTimeout();
private slots: private slots:
void gameClosing(); void gameClosing(int gameId);
void broadcastChannelUpdate(); void broadcastRoomUpdate();
public: public:
Server(QObject *parent = 0); Server(QObject *parent = 0);
~Server(); ~Server();
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password); AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password);
QList<Server_Game *> getGames() const { return games.values(); } QList<Server_Game *> getGames() const { return games.values(); }
Server_Game *getGame(int gameId) const; Server_Game *getGame(int gameId) const;
const QMap<QString, Server_ChatChannel *> &getChatChannels() { return chatChannels; } const QMap<int, Server_Room *> &getRooms() { return rooms; }
void broadcastGameListUpdate(Server_Game *game); int getNextGameId() { return nextGameId++; }
const QMap<QString, Server_ProtocolHandler *> &getUsers() const { return users; } const QMap<QString, Server_ProtocolHandler *> &getUsers() const { return users; }
void addClient(Server_ProtocolHandler *player); void addClient(Server_ProtocolHandler *player);
void removeClient(Server_ProtocolHandler *player); void removeClient(Server_ProtocolHandler *player);
virtual QString getLoginMessage() const = 0; virtual QString getLoginMessage() const = 0;
Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator);
virtual bool getGameShouldPing() const = 0; virtual bool getGameShouldPing() const = 0;
virtual int getMaxGameInactivityTime() const = 0; virtual int getMaxGameInactivityTime() const = 0;
@ -42,12 +41,12 @@ protected:
QMap<int, Server_Game *> games; QMap<int, Server_Game *> games;
QList<Server_ProtocolHandler *> clients; QList<Server_ProtocolHandler *> clients;
QMap<QString, Server_ProtocolHandler *> users; QMap<QString, Server_ProtocolHandler *> users;
QMap<QString, Server_ChatChannel *> chatChannels; QMap<int, Server_Room *> rooms;
virtual AuthenticationResult checkUserPassword(const QString &user, const QString &password) = 0; virtual AuthenticationResult checkUserPassword(const QString &user, const QString &password) = 0;
virtual ServerInfo_User *getUserData(const QString &name) = 0; virtual ServerInfo_User *getUserData(const QString &name) = 0;
int nextGameId; int nextGameId;
void addChatChannel(Server_ChatChannel *newChannel); void addRoom(Server_Room *newRoom);
}; };
#endif #endif

View file

@ -1,42 +0,0 @@
#include "server_chatchannel.h"
#include "server_protocolhandler.h"
Server_ChatChannel::Server_ChatChannel(const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage)
: name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage)
{
}
void Server_ChatChannel::addClient(Server_ProtocolHandler *client)
{
sendChatEvent(new Event_ChatJoinChannel(name, new ServerInfo_User(client->getUserInfo())));
append(client);
QList<ServerInfo_User *> eventUserList;
for (int i = 0; i < size(); ++i)
eventUserList.append(new ServerInfo_User(at(i)->getUserInfo()));
Event_ChatListPlayers *eventCLP = new Event_ChatListPlayers(name, eventUserList);
client->enqueueProtocolItem(eventCLP);
client->enqueueProtocolItem(new Event_ChatSay(name, QString(), joinMessage));
emit channelInfoChanged();
}
void Server_ChatChannel::removeClient(Server_ProtocolHandler *client)
{
removeAt(indexOf(client));
sendChatEvent(new Event_ChatLeaveChannel(name, client->getUserInfo()->getName()));
emit channelInfoChanged();
}
void Server_ChatChannel::say(Server_ProtocolHandler *client, const QString &s)
{
sendChatEvent(new Event_ChatSay(name, client->getUserInfo()->getName(), s));
}
void Server_ChatChannel::sendChatEvent(ChatEvent *event)
{
for (int i = 0; i < size(); ++i)
at(i)->sendProtocolItem(event, false);
delete event;
}

View file

@ -1,32 +0,0 @@
#ifndef CHATCHANNEL_H
#define CHATCHANNEL_H
#include <QList>
#include <QObject>
#include <QStringList>
class Server_ProtocolHandler;
class ChatEvent;
class Server_ChatChannel : public QObject, public QList<Server_ProtocolHandler *> {
Q_OBJECT
signals:
void channelInfoChanged();
private:
QString name;
QString description;
bool autoJoin;
QString joinMessage;
public:
Server_ChatChannel(const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage);
QString getName() const { return name; }
QString getDescription() const { return description; }
bool getAutoJoin() const { return autoJoin; }
void addClient(Server_ProtocolHandler *client);
void removeClient(Server_ProtocolHandler *client);
void say(Server_ProtocolHandler *client, const QString &s);
void sendChatEvent(ChatEvent *event);
};
#endif

View file

@ -18,6 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "server.h" #include "server.h"
#include "server_room.h"
#include "server_game.h" #include "server_game.h"
#include "server_protocolhandler.h" #include "server_protocolhandler.h"
#include "server_arrow.h" #include "server_arrow.h"
@ -27,12 +28,12 @@
#include <QTimer> #include <QTimer>
#include <QDebug> #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 *parent) 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) : 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)
{ {
addPlayer(_creator, false, false); addPlayer(_creator, false, false);
if (parent->getGameShouldPing()) { if (parent->getServer()->getGameShouldPing()) {
pingClock = new QTimer(this); pingClock = new QTimer(this);
connect(pingClock, SIGNAL(timeout()), this, SLOT(pingClockTimeout())); connect(pingClock, SIGNAL(timeout()), this, SLOT(pingClockTimeout()));
pingClock->start(1000); pingClock->start(1000);
@ -71,7 +72,7 @@ void Server_Game::pingClockTimeout()
} }
sendGameEvent(new Event_Ping(pingList)); sendGameEvent(new Event_Ping(pingList));
const int maxTime = static_cast<Server *>(parent())->getMaxGameInactivityTime(); const int maxTime = static_cast<Server_Room *>(parent())->getServer()->getMaxGameInactivityTime();
if (allPlayersInactive) { if (allPlayersInactive) {
if ((++inactivityCounter >= maxTime) && (maxTime > 0)) if ((++inactivityCounter >= maxTime) && (maxTime > 0))
deleteLater(); deleteLater();
@ -193,7 +194,7 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec
players.insert(playerId, newPlayer); players.insert(playerId, newPlayer);
if (broadcastUpdate) if (broadcastUpdate)
qobject_cast<Server *>(parent())->broadcastGameListUpdate(this); qobject_cast<Server_Room *>(parent())->broadcastGameListUpdate(this);
return newPlayer; return newPlayer;
} }
@ -231,7 +232,7 @@ void Server_Game::removePlayer(Server_Player *player)
deleteLater(); deleteLater();
else if (!spectator) else if (!spectator)
stopGameIfFinished(); stopGameIfFinished();
qobject_cast<Server *>(parent())->broadcastGameListUpdate(this); qobject_cast<Server_Room *>(parent())->broadcastGameListUpdate(this);
} }
void Server_Game::setActivePlayer(int _activePlayer) void Server_Game::setActivePlayer(int _activePlayer)
@ -391,3 +392,23 @@ void Server_Game::sendGameEventToPlayer(Server_Player *player, GameEvent *event)
{ {
player->sendProtocolItem(new GameEventContainer(QList<GameEvent *>() << event, gameId)); player->sendProtocolItem(new GameEventContainer(QList<GameEvent *>() << event, gameId));
} }
ServerInfo_Game *Server_Game::getInfo() const
{
if (players.isEmpty())
// Game is open
return new ServerInfo_Game(getGameId(), QString(), false, 0, getMaxPlayers(), 0, false, 0);
else
// Game is closing
return new ServerInfo_Game(
getGameId(),
getDescription(),
!getPassword().isEmpty(),
getPlayerCount(),
getMaxPlayers(),
new ServerInfo_User(getCreatorInfo()),
getSpectatorsAllowed(),
getSpectatorsNeedPassword(),
getSpectatorCount()
);
}

View file

@ -27,7 +27,7 @@
#include "protocol.h" #include "protocol.h"
class QTimer; class QTimer;
class Server; class Server_Room;
class ServerInfo_User; class ServerInfo_User;
class Server_Game : public QObject { class Server_Game : public QObject {
@ -52,8 +52,9 @@ signals:
private slots: private slots:
void pingClockTimeout(); void pingClockTimeout();
public: 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 *parent); 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_Game();
ServerInfo_Game *getInfo() const;
ServerInfo_User *getCreatorInfo() const { return creatorInfo; } ServerInfo_User *getCreatorInfo() const { return creatorInfo; }
bool getGameStarted() const { return gameStarted; } bool getGameStarted() const { return gameStarted; }
int getPlayerCount() const; int getPlayerCount() const;

View file

@ -198,10 +198,13 @@ bool Server_Player::deleteCounter(int counterId)
return true; return true;
} }
ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_startZone, int _cardId, const QString &_targetZone, int x, int y, bool faceDown, bool tapped) ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_startZone, int _cardId, int targetPlayerId, const QString &_targetZone, int x, int y, bool faceDown, bool tapped)
{ {
Server_CardZone *startzone = getZones().value(_startZone); Server_CardZone *startzone = getZones().value(_startZone);
Server_CardZone *targetzone = getZones().value(_targetZone); Server_Player *targetPlayer = game->getPlayers().value(targetPlayerId);
if (!targetPlayer)
return RespNameNotFound;
Server_CardZone *targetzone = targetPlayer->getZones().value(_targetZone);
if ((!startzone) || (!targetzone)) if ((!startzone) || (!targetzone))
return RespNameNotFound; return RespNameNotFound;
@ -210,12 +213,10 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_sta
ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *startzone, int _cardId, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped) ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *startzone, int _cardId, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped)
{ {
// Collision detection // Disallow controller change between different zones.
/* if (targetzone->hasCoords()) if ((startzone->getName() != targetzone->getName()) && (startzone->getPlayer() != targetzone->getPlayer()))
for (int i = 0; i < targetzone->cards.size(); ++i) return RespContextError;
if ((targetzone->cards[i]->getX() == x) && (targetzone->cards[i]->getY() == y) && (x != -1))
return RespContextError;
*/
int position = -1; int position = -1;
Server_Card *card = startzone->getCard(_cardId, false, &position); Server_Card *card = startzone->getCard(_cardId, false, &position);
if (!card) if (!card)
@ -226,15 +227,19 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
int oldX = card->getX(), oldY = card->getY(); int oldX = card->getX(), oldY = card->getY();
if (startzone != targetzone) { // Attachment relationships can be retained when moving a card onto the opponent's table
if (startzone->getName() != targetzone->getName()) {
// Delete all attachment relationships // Delete all attachment relationships
if (card->getParentCard()) if (card->getParentCard())
card->setParentCard(0); card->setParentCard(0);
const QList<Server_Card *> &attachedCards = card->getAttachedCards(); // Make a copy of the list because the original one gets modified during the loop
QList<Server_Card *> attachedCards = card->getAttachedCards();
for (int i = 0; i < attachedCards.size(); ++i) for (int i = 0; i < attachedCards.size(); ++i)
attachedCards[i]->getZone()->getPlayer()->unattachCard(cont, attachedCards[i]); attachedCards[i]->getZone()->getPlayer()->unattachCard(cont, attachedCards[i]);
}
if (startzone != targetzone) {
// Delete all arrows from and to the card // Delete all arrows from and to the card
const QList<Server_Player *> &players = game->getPlayers().values(); const QList<Server_Player *> &players = game->getPlayers().values();
for (int i = 0; i < players.size(); ++i) { for (int i = 0; i < players.size(); ++i) {
@ -266,7 +271,6 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
card->resetState(); card->resetState();
} else } else
// if (x == -1)
x = targetzone->getFreeGridColumn(x, y, card->getName()); x = targetzone->getFreeGridColumn(x, y, card->getName());
targetzone->insertCard(card, x, y); targetzone->insertCard(card, x, y);
@ -302,8 +306,8 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
int privatePosition = -1; int privatePosition = -1;
if (startzone->getType() == HiddenZone) if (startzone->getType() == HiddenZone)
privatePosition = position; privatePosition = position;
cont->enqueueGameEventPrivate(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getName(), x, y, privateNewCardId, faceDown), game->getGameId()); cont->enqueueGameEventPrivate(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), x, y, privateNewCardId, faceDown), game->getGameId());
cont->enqueueGameEventOmniscient(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getName(), x, y, privateNewCardId, faceDown), game->getGameId()); cont->enqueueGameEventOmniscient(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), x, y, privateNewCardId, faceDown), game->getGameId());
// Other players do not get to see the start and/or target position of the card if the respective // 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, // part of the zone is being looked at. The information is not needed anyway because in hidden zones,
@ -317,9 +321,9 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
x = -1; x = -1;
if ((startzone->getType() == PublicZone) || (targetzone->getType() == PublicZone)) if ((startzone->getType() == PublicZone) || (targetzone->getType() == PublicZone))
cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getName(), x, y, card->getId(), faceDown), game->getGameId()); cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), x, y, card->getId(), faceDown), game->getGameId());
else else
cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getName(), x, y, -1, false), game->getGameId()); cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), x, y, -1, false), game->getGameId());
if (tapped) if (tapped)
setCardAttrHelper(cont, targetzone->getName(), card->getId(), "tapped", "1"); setCardAttrHelper(cont, targetzone->getName(), card->getId(), "tapped", "1");
@ -338,7 +342,7 @@ void Server_Player::unattachCard(CommandContainer *cont, Server_Card *card)
cont->enqueueGameEventPrivate(new Event_AttachCard(getPlayerId(), zone->getName(), card->getId(), -1, QString(), -1), game->getGameId()); cont->enqueueGameEventPrivate(new Event_AttachCard(getPlayerId(), zone->getName(), card->getId(), -1, QString(), -1), game->getGameId());
cont->enqueueGameEventPublic(new Event_AttachCard(getPlayerId(), zone->getName(), card->getId(), -1, QString(), -1), game->getGameId()); cont->enqueueGameEventPublic(new Event_AttachCard(getPlayerId(), zone->getName(), card->getId(), -1, QString(), -1), game->getGameId());
moveCard(cont, zone->getName(), card->getId(), zone->getName(), -1, card->getY(), card->getFaceDown(), card->getTapped()); moveCard(cont, zone, card->getId(), zone, -1, card->getY(), card->getFaceDown(), card->getTapped());
} }
ResponseCode Server_Player::setCardAttrHelper(CommandContainer *cont, const QString &zoneName, int cardId, const QString &attrName, const QString &attrValue) ResponseCode Server_Player::setCardAttrHelper(CommandContainer *cont, const QString &zoneName, int cardId, const QString &attrName, const QString &attrValue)

View file

@ -74,7 +74,7 @@ public:
void clearZones(); void clearZones();
void setupZones(); void setupZones();
ResponseCode moveCard(CommandContainer *cont, const QString &_startZone, int _cardId, const QString &_targetZone, int _x, int _y, bool _faceDown, bool _tapped); ResponseCode moveCard(CommandContainer *cont, const QString &_startZone, int _cardId, int _targetPlayer, const QString &_targetZone, int _x, int _y, bool _faceDown, bool _tapped);
ResponseCode moveCard(CommandContainer *cont, Server_CardZone *startzone, int _cardId, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped); ResponseCode moveCard(CommandContainer *cont, Server_CardZone *startzone, int _cardId, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped);
void unattachCard(CommandContainer *cont, Server_Card *card); void unattachCard(CommandContainer *cont, Server_Card *card);
ResponseCode setCardAttrHelper(CommandContainer *cont, const QString &zone, int cardId, const QString &attrName, const QString &attrValue); ResponseCode setCardAttrHelper(CommandContainer *cont, const QString &zone, int cardId, const QString &attrName, const QString &attrValue);

View file

@ -3,7 +3,7 @@
#include "server_protocolhandler.h" #include "server_protocolhandler.h"
#include "protocol.h" #include "protocol.h"
#include "protocol_items.h" #include "protocol_items.h"
#include "server_chatchannel.h" #include "server_room.h"
#include "server_card.h" #include "server_card.h"
#include "server_arrow.h" #include "server_arrow.h"
#include "server_cardzone.h" #include "server_cardzone.h"
@ -14,7 +14,7 @@
#include <QDateTime> #include <QDateTime>
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent) Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent)
: QObject(parent), server(_server), authState(PasswordWrong), acceptsGameListChanges(false), acceptsUserListChanges(false), acceptsChatChannelListChanges(false), userInfo(0), lastCommandTime(QDateTime::currentDateTime()) : QObject(parent), server(_server), authState(PasswordWrong), acceptsUserListChanges(false), acceptsRoomListChanges(false), userInfo(0), lastCommandTime(QDateTime::currentDateTime())
{ {
connect(server, SIGNAL(pingClockTimeout()), this, SLOT(pingClockTimeout())); connect(server, SIGNAL(pingClockTimeout()), this, SLOT(pingClockTimeout()));
} }
@ -37,9 +37,9 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
p->setProtocolHandler(0); p->setProtocolHandler(0);
} }
QMapIterator<QString, Server_ChatChannel *> chatChannelIterator(chatChannels); QMapIterator<int, Server_Room *> roomIterator(rooms);
while (chatChannelIterator.hasNext()) while (roomIterator.hasNext())
chatChannelIterator.next().value()->removeClient(this); roomIterator.next().value()->removeClient(this);
delete userInfo; delete userInfo;
} }
@ -54,20 +54,22 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
{ {
lastCommandTime = QDateTime::currentDateTime(); lastCommandTime = QDateTime::currentDateTime();
ChatCommand *chatCommand = qobject_cast<ChatCommand *>(command); RoomCommand *roomCommand = qobject_cast<RoomCommand *>(command);
GameCommand *gameCommand = qobject_cast<GameCommand *>(command); GameCommand *gameCommand = qobject_cast<GameCommand *>(command);
if (chatCommand) { if (roomCommand) {
qDebug() << "received ChatCommand: channel =" << chatCommand->getChannel(); qDebug() << "received RoomCommand: roomId =" << roomCommand->getRoomId();
if (authState == PasswordWrong) if (authState == PasswordWrong)
return RespLoginNeeded; return RespLoginNeeded;
Server_ChatChannel *channel = chatChannels.value(chatCommand->getChannel(), 0); Server_Room *room = rooms.value(roomCommand->getRoomId(), 0);
if (!channel) if (!room)
return RespNameNotFound; return RespNameNotFound;
switch (command->getItemId()) { switch (command->getItemId()) {
case ItemId_Command_ChatLeaveChannel: return cmdChatLeaveChannel(qobject_cast<Command_ChatLeaveChannel *>(command), cont, channel); case ItemId_Command_LeaveRoom: return cmdLeaveRoom(qobject_cast<Command_LeaveRoom *>(command), cont, room);
case ItemId_Command_ChatSay: return cmdChatSay(qobject_cast<Command_ChatSay *>(command), cont, channel); case ItemId_Command_RoomSay: return cmdRoomSay(qobject_cast<Command_RoomSay *>(command), cont, room);
case ItemId_Command_CreateGame: return cmdCreateGame(qobject_cast<Command_CreateGame *>(command), cont, room);
case ItemId_Command_JoinGame: return cmdJoinGame(qobject_cast<Command_JoinGame *>(command), cont, room);
} }
} else if (gameCommand) { } else if (gameCommand) {
qDebug() << "received GameCommand: game =" << gameCommand->getGameId(); qDebug() << "received GameCommand: game =" << gameCommand->getGameId();
@ -125,12 +127,9 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
case ItemId_Command_DeckUpload: return cmdDeckUpload(qobject_cast<Command_DeckUpload *>(command), cont); case ItemId_Command_DeckUpload: return cmdDeckUpload(qobject_cast<Command_DeckUpload *>(command), cont);
case ItemId_Command_DeckDownload: return cmdDeckDownload(qobject_cast<Command_DeckDownload *>(command), cont); case ItemId_Command_DeckDownload: return cmdDeckDownload(qobject_cast<Command_DeckDownload *>(command), cont);
case ItemId_Command_GetUserInfo: return cmdGetUserInfo(qobject_cast<Command_GetUserInfo *>(command), cont); case ItemId_Command_GetUserInfo: return cmdGetUserInfo(qobject_cast<Command_GetUserInfo *>(command), cont);
case ItemId_Command_ListChatChannels: return cmdListChatChannels(qobject_cast<Command_ListChatChannels *>(command), cont); case ItemId_Command_ListRooms: return cmdListRooms(qobject_cast<Command_ListRooms *>(command), cont);
case ItemId_Command_ChatJoinChannel: return cmdChatJoinChannel(qobject_cast<Command_ChatJoinChannel *>(command), cont); case ItemId_Command_JoinRoom: return cmdJoinRoom(qobject_cast<Command_JoinRoom *>(command), cont);
case ItemId_Command_ListUsers: return cmdListUsers(qobject_cast<Command_ListUsers *>(command), cont); case ItemId_Command_ListUsers: return cmdListUsers(qobject_cast<Command_ListUsers *>(command), cont);
case ItemId_Command_ListGames: return cmdListGames(qobject_cast<Command_ListGames *>(command), cont);
case ItemId_Command_CreateGame: return cmdCreateGame(qobject_cast<Command_CreateGame *>(command), cont);
case ItemId_Command_JoinGame: return cmdJoinGame(qobject_cast<Command_JoinGame *>(command), cont);
} }
} }
return RespInvalidCommand; return RespInvalidCommand;
@ -273,51 +272,50 @@ ResponseCode Server_ProtocolHandler::cmdGetUserInfo(Command_GetUserInfo *cmd, Co
return RespNothing; return RespNothing;
} }
ResponseCode Server_ProtocolHandler::cmdListChatChannels(Command_ListChatChannels * /*cmd*/, CommandContainer *cont) ResponseCode Server_ProtocolHandler::cmdListRooms(Command_ListRooms * /*cmd*/, CommandContainer *cont)
{ {
if (authState == PasswordWrong) if (authState == PasswordWrong)
return RespLoginNeeded; return RespLoginNeeded;
QList<ServerInfo_ChatChannel *> eventChannelList; QList<ServerInfo_Room *> eventRoomList;
QMapIterator<QString, Server_ChatChannel *> channelIterator(server->getChatChannels()); QMapIterator<int, Server_Room *> roomIterator(server->getRooms());
while (channelIterator.hasNext()) { while (roomIterator.hasNext()) {
Server_ChatChannel *c = channelIterator.next().value(); Server_Room *r = roomIterator.next().value();
eventChannelList.append(new ServerInfo_ChatChannel(c->getName(), c->getDescription(), c->size(), c->getAutoJoin())); eventRoomList.append(new ServerInfo_Room(r->getId(), r->getName(), r->getDescription(), r->getGames().size(), r->size(), r->getAutoJoin()));
} }
cont->enqueueItem(new Event_ListChatChannels(eventChannelList)); cont->enqueueItem(new Event_ListRooms(eventRoomList));
acceptsChatChannelListChanges = true; acceptsRoomListChanges = true;
return RespOk; return RespOk;
} }
ResponseCode Server_ProtocolHandler::cmdChatJoinChannel(Command_ChatJoinChannel *cmd, CommandContainer *cont) ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandContainer *cont)
{ {
if (authState == PasswordWrong) if (authState == PasswordWrong)
return RespLoginNeeded; return RespLoginNeeded;
if (chatChannels.contains(cmd->getChannel())) if (rooms.contains(cmd->getRoomId()))
return RespContextError; return RespContextError;
QMap<QString, Server_ChatChannel *> allChannels = server->getChatChannels(); Server_Room *r = server->getRooms().value(cmd->getRoomId(), 0);
Server_ChatChannel *c = allChannels.value(cmd->getChannel(), 0); if (!r)
if (!c)
return RespNameNotFound; return RespNameNotFound;
c->addClient(this); r->addClient(this);
chatChannels.insert(cmd->getChannel(), c); rooms.insert(r->getId(), r);
return RespOk; return RespOk;
} }
ResponseCode Server_ProtocolHandler::cmdChatLeaveChannel(Command_ChatLeaveChannel * /*cmd*/, CommandContainer *cont, Server_ChatChannel *channel) ResponseCode Server_ProtocolHandler::cmdLeaveRoom(Command_LeaveRoom * /*cmd*/, CommandContainer *cont, Server_Room *room)
{ {
chatChannels.remove(channel->getName()); rooms.remove(room->getId());
channel->removeClient(this); room->removeClient(this);
return RespOk; return RespOk;
} }
ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, CommandContainer *cont, Server_ChatChannel *channel) ResponseCode Server_ProtocolHandler::cmdRoomSay(Command_RoomSay *cmd, CommandContainer *cont, Server_Room *room)
{ {
channel->say(this, cmd->getMessage()); room->say(this, cmd->getMessage());
return RespOk; return RespOk;
} }
@ -337,39 +335,12 @@ ResponseCode Server_ProtocolHandler::cmdListUsers(Command_ListUsers * /*cmd*/, C
return RespNothing; return RespNothing;
} }
ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/, CommandContainer *cont) ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont, Server_Room *room)
{ {
if (authState == PasswordWrong) if (authState == PasswordWrong)
return RespLoginNeeded; return RespLoginNeeded;
const QList<Server_Game *> &gameList = server->getGames(); Server_Game *game = room->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this);
QList<ServerInfo_Game *> eventGameList;
for (int i = 0; i < gameList.size(); ++i) {
Server_Game *g = gameList[i];
eventGameList.append(new ServerInfo_Game(
g->getGameId(),
g->getDescription(),
!g->getPassword().isEmpty(),
g->getPlayerCount(),
g->getMaxPlayers(),
new ServerInfo_User(g->getCreatorInfo()),
g->getSpectatorsAllowed(),
g->getSpectatorsNeedPassword(),
g->getSpectatorCount()
));
}
cont->enqueueItem(new Event_ListGames(eventGameList));
acceptsGameListChanges = true;
return RespOk;
}
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont)
{
if (authState == PasswordWrong)
return RespLoginNeeded;
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this);
Server_Player *creator = game->getPlayers().values().first(); Server_Player *creator = game->getPlayers().values().first();
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator)); games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator));
@ -378,7 +349,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm
return RespOk; return RespOk;
} }
ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont) ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont, Server_Room *room)
{ {
if (authState == PasswordWrong) if (authState == PasswordWrong)
return RespLoginNeeded; return RespLoginNeeded;
@ -386,7 +357,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandC
if (games.contains(cmd->getGameId())) if (games.contains(cmd->getGameId()))
return RespContextError; return RespContextError;
Server_Game *g = server->getGame(cmd->getGameId()); Server_Game *g = room->getGames().value(cmd->getGameId());
if (!g) if (!g)
return RespNameNotFound; return RespNameNotFound;
@ -507,10 +478,11 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com
Server_CardZone *hand = player->getZones().value("hand"); Server_CardZone *hand = player->getZones().value("hand");
int number = (hand->cards.size() <= 1) ? player->getInitialCards() : hand->cards.size() - 1; int number = (hand->cards.size() <= 1) ? player->getInitialCards() : hand->cards.size() - 1;
Server_CardZone *deck = player->getZones().value("deck");
while (!hand->cards.isEmpty()) while (!hand->cards.isEmpty())
player->moveCard(cont, "hand", hand->cards.first()->getId(), "deck", 0, 0, false, false); player->moveCard(cont, hand, hand->cards.first()->getId(), deck, 0, 0, false, false);
player->getZones().value("deck")->shuffle(); deck->shuffle();
cont->enqueueGameEventPrivate(new Event_Shuffle(player->getPlayerId()), game->getGameId()); cont->enqueueGameEventPrivate(new Event_Shuffle(player->getPlayerId()), game->getGameId());
cont->enqueueGameEventPublic(new Event_Shuffle(player->getPlayerId()), game->getGameId()); cont->enqueueGameEventPublic(new Event_Shuffle(player->getPlayerId()), game->getGameId());
@ -571,7 +543,7 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandC
if (!game->getGameStarted()) if (!game->getGameStarted())
return RespGameNotStarted; return RespGameNotStarted;
return player->moveCard(cont, cmd->getStartZone(), cmd->getCardId(), cmd->getTargetZone(), cmd->getX(), cmd->getY(), cmd->getFaceDown(), cmd->getTapped()); return player->moveCard(cont, cmd->getStartZone(), cmd->getCardId(), cmd->getTargetPlayerId(), cmd->getTargetZone(), cmd->getX(), cmd->getY(), cmd->getFaceDown(), cmd->getTapped());
} }
ResponseCode Server_ProtocolHandler::cmdFlipCard(Command_FlipCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) ResponseCode Server_ProtocolHandler::cmdFlipCard(Command_FlipCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)

View file

@ -10,6 +10,7 @@
class Server_Player; class Server_Player;
class Server_Card; class Server_Card;
class ServerInfo_User; class ServerInfo_User;
class Server_Room;
class QTimer; class QTimer;
class Server_ProtocolHandler : public QObject { class Server_ProtocolHandler : public QObject {
@ -17,15 +18,14 @@ class Server_ProtocolHandler : public QObject {
protected: protected:
Server *server; Server *server;
QMap<int, QPair<Server_Game *, Server_Player *> > games; QMap<int, QPair<Server_Game *, Server_Player *> > games;
QMap<QString, Server_ChatChannel *> chatChannels; QMap<int, Server_Room *> rooms;
Server *getServer() const { return server; } Server *getServer() const { return server; }
QPair<Server_Game *, Server_Player *> getGame(int gameId) const; QPair<Server_Game *, Server_Player *> getGame(int gameId) const;
AuthenticationResult authState; AuthenticationResult authState;
bool acceptsGameListChanges;
bool acceptsUserListChanges; bool acceptsUserListChanges;
bool acceptsChatChannelListChanges; bool acceptsRoomListChanges;
ServerInfo_User *userInfo; ServerInfo_User *userInfo;
private: private:
@ -45,14 +45,13 @@ private:
virtual ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont) = 0; virtual ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont) = 0;
virtual ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont) = 0; virtual ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont) = 0;
ResponseCode cmdGetUserInfo(Command_GetUserInfo *cmd, CommandContainer *cont); ResponseCode cmdGetUserInfo(Command_GetUserInfo *cmd, CommandContainer *cont);
ResponseCode cmdListChatChannels(Command_ListChatChannels *cmd, CommandContainer *cont); ResponseCode cmdListRooms(Command_ListRooms *cmd, CommandContainer *cont);
ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd, CommandContainer *cont); ResponseCode cmdJoinRoom(Command_JoinRoom *cmd, CommandContainer *cont);
ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, CommandContainer *cont, Server_ChatChannel *channel); ResponseCode cmdLeaveRoom(Command_LeaveRoom *cmd, CommandContainer *cont, Server_Room *room);
ResponseCode cmdChatSay(Command_ChatSay *cmd, CommandContainer *cont, Server_ChatChannel *channel); ResponseCode cmdRoomSay(Command_RoomSay *cmd, CommandContainer *cont, Server_Room *room);
ResponseCode cmdListUsers(Command_ListUsers *cmd, CommandContainer *cont); ResponseCode cmdListUsers(Command_ListUsers *cmd, CommandContainer *cont);
ResponseCode cmdListGames(Command_ListGames *cmd, CommandContainer *cont); ResponseCode cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont, Server_Room *room);
ResponseCode cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont); ResponseCode cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont, Server_Room *room);
ResponseCode cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont);
ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdConcede(Command_Concede *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); ResponseCode cmdConcede(Command_Concede *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdReadyStart(Command_ReadyStart *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); ResponseCode cmdReadyStart(Command_ReadyStart *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
@ -91,9 +90,8 @@ public:
~Server_ProtocolHandler(); ~Server_ProtocolHandler();
void playerRemovedFromGame(Server_Game *game); void playerRemovedFromGame(Server_Game *game);
bool getAcceptsGameListChanges() const { return acceptsGameListChanges; }
bool getAcceptsUserListChanges() const { return acceptsUserListChanges; } bool getAcceptsUserListChanges() const { return acceptsUserListChanges; }
bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; } bool getAcceptsRoomListChanges() const { return acceptsRoomListChanges; }
ServerInfo_User *getUserInfo() const { return userInfo; } ServerInfo_User *getUserInfo() const { return userInfo; }
void setUserInfo(ServerInfo_User *_userInfo) { userInfo = _userInfo; } void setUserInfo(ServerInfo_User *_userInfo) { userInfo = _userInfo; }
const QDateTime &getLastCommandTime() const { return lastCommandTime; } const QDateTime &getLastCommandTime() const { return lastCommandTime; }

76
common/server_room.cpp Normal file
View file

@ -0,0 +1,76 @@
#include "server_room.h"
#include "server_protocolhandler.h"
#include "server_game.h"
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 *Server_Room::getServer() const
{
return static_cast<Server *>(parent());
}
QList<ServerInfo_User *> Server_Room::addClient(Server_ProtocolHandler *client)
{
sendRoomEvent(new Event_JoinRoom(id, new ServerInfo_User(client->getUserInfo())));
append(client);
QList<ServerInfo_User *> eventUserList;
for (int i = 0; i < size(); ++i)
eventUserList.append(new ServerInfo_User(at(i)->getUserInfo()));
emit roomInfoChanged();
return eventUserList;
}
void Server_Room::removeClient(Server_ProtocolHandler *client)
{
removeAt(indexOf(client));
sendRoomEvent(new Event_LeaveRoom(id, client->getUserInfo()->getName()));
emit roomInfoChanged();
}
void Server_Room::say(Server_ProtocolHandler *client, const QString &s)
{
sendRoomEvent(new Event_RoomSay(id, client->getUserInfo()->getName(), s));
}
void Server_Room::sendRoomEvent(RoomEvent *event)
{
for (int i = 0; i < size(); ++i)
at(i)->sendProtocolItem(event, false);
delete event;
}
void Server_Room::broadcastGameListUpdate(Server_Game *game)
{
Event_ListGames *event = new Event_ListGames(id, QList<ServerInfo_Game *>() << game->getInfo());
for (int i = 0; i < size(); i++)
at(i)->sendProtocolItem(event, false);
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 *newGame = new Server_Game(creator, static_cast<Server *>(parent())->getNextGameId(), description, password, maxPlayers, spectatorsAllowed, spectatorsNeedPassword, spectatorsCanTalk, spectatorsSeeEverything, this);
games.insert(newGame->getGameId(), newGame);
connect(newGame, SIGNAL(gameClosing()), this, SLOT(removeGame()));
broadcastGameListUpdate(newGame);
emit gameCreated(newGame);
return newGame;
}
void Server_Room::removeGame()
{
Server_Game *game = static_cast<Server_Game *>(sender());
broadcastGameListUpdate(game);
games.remove(game->getGameId());
emit gameClosing(game->getGameId());
}

48
common/server_room.h Normal file
View file

@ -0,0 +1,48 @@
#ifndef SERVER_ROOM_H
#define SERVER_ROOM_H
#include <QList>
#include <QMap>
#include <QObject>
#include <QStringList>
class Server_ProtocolHandler;
class RoomEvent;
class ServerInfo_User;
class Server_Game;
class Server;
class Server_Room : public QObject, public QList<Server_ProtocolHandler *> {
Q_OBJECT
signals:
void roomInfoChanged();
void gameCreated(Server_Game *game);
void gameClosing(int gameId);
private:
int id;
QString name;
QString description;
bool autoJoin;
QString joinMessage;
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);
int getId() const { return id; }
QString getName() const { return name; }
QString getDescription() const { return description; }
bool getAutoJoin() const { return autoJoin; }
const QMap<int, Server_Game *> &getGames() const { return games; }
Server *getServer() const;
QList<ServerInfo_User *> addClient(Server_ProtocolHandler *client);
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);
void sendRoomEvent(RoomEvent *event);
};
#endif

View file

@ -27,7 +27,7 @@ HEADERS += src/servatrice.h \
../common/server_arrow.h \ ../common/server_arrow.h \
../common/server_card.h \ ../common/server_card.h \
../common/server_cardzone.h \ ../common/server_cardzone.h \
../common/server_chatchannel.h \ ../common/server_room.h \
../common/server_counter.h \ ../common/server_counter.h \
../common/server_game.h \ ../common/server_game.h \
../common/server_player.h \ ../common/server_player.h \
@ -48,7 +48,7 @@ SOURCES += src/main.cpp \
../common/server.cpp \ ../common/server.cpp \
../common/server_card.cpp \ ../common/server_card.cpp \
../common/server_cardzone.cpp \ ../common/server_cardzone.cpp \
../common/server_chatchannel.cpp \ ../common/server_room.cpp \
../common/server_game.cpp \ ../common/server_game.cpp \
../common/server_player.cpp \ ../common/server_player.cpp \
../common/server_protocolhandler.cpp ../common/server_protocolhandler.cpp

View file

@ -22,7 +22,7 @@
#include <QDebug> #include <QDebug>
#include <iostream> #include <iostream>
#include "servatrice.h" #include "servatrice.h"
#include "server_chatchannel.h" #include "server_room.h"
#include "serversocketinterface.h" #include "serversocketinterface.h"
#include "protocol.h" #include "protocol.h"
@ -49,16 +49,18 @@ Servatrice::Servatrice(QObject *parent)
if (dbType == "mysql") if (dbType == "mysql")
openDatabase(); openDatabase();
int size = settings->beginReadArray("chatchannels"); int size = settings->beginReadArray("rooms");
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i); settings->setArrayIndex(i);
Server_ChatChannel *newChannel = new Server_ChatChannel( Server_Room *newRoom = new Server_Room(
i,
settings->value("name").toString(), settings->value("name").toString(),
settings->value("description").toString(), settings->value("description").toString(),
settings->value("autojoin").toBool(), settings->value("autojoin").toBool(),
settings->value("joinmessage").toString() settings->value("joinmessage").toString(),
this
); );
addChatChannel(newChannel); addRoom(newRoom);
} }
settings->endArray(); settings->endArray();