diff --git a/cockatrice/src/client.cpp b/cockatrice/src/client.cpp index e709c9a8..e4f6d95b 100644 --- a/cockatrice/src/client.cpp +++ b/cockatrice/src/client.cpp @@ -350,3 +350,8 @@ PendingCommand *Client::dumpZone(int player, const QString &zone, int numberCard { return cmd(QString("dump_zone|%1|%2|%3").arg(player).arg(zone).arg(numberCards)); } + +PendingCommand *Client::stopDumpZone(int player, const QString &zone) +{ + return cmd(QString("stop_dump_zone|%1|%2").arg(player).arg(zone)); +} diff --git a/cockatrice/src/client.h b/cockatrice/src/client.h index 657476ef..706aea58 100644 --- a/cockatrice/src/client.h +++ b/cockatrice/src/client.h @@ -110,6 +110,7 @@ public: PendingCommand *setActivePlayer(int player); PendingCommand *setActivePhase(int phase); PendingCommand *dumpZone(int player, const QString &zone, int numberCards); + PendingCommand *stopDumpZone(int player, const QString &zone); public slots: void submitDeck(const QStringList &deck); }; diff --git a/cockatrice/src/game.cpp b/cockatrice/src/game.cpp index 4f095137..1edc79fa 100644 --- a/cockatrice/src/game.cpp +++ b/cockatrice/src/game.cpp @@ -137,7 +137,7 @@ Player *Game::addPlayer(int playerId, const QString &playerName, QPointF base, b Player *newPlayer = new Player(playerName, playerId, base, local, db, client, scene, this); connect(newPlayer, SIGNAL(sigShowCardMenu(QPoint)), this, SLOT(showCardMenu(QPoint))); - connect(newPlayer, SIGNAL(logMoveCard(Player *, QString, QString, QString)), this, SIGNAL(logMoveCard(Player *, QString, QString, QString))); + connect(newPlayer, SIGNAL(logMoveCard(Player *, QString, QString, int, QString, int)), this, SIGNAL(logMoveCard(Player *, QString, QString, int, QString, int))); connect(newPlayer, SIGNAL(logCreateToken(Player *, QString)), this, SIGNAL(logCreateToken(Player *, QString))); connect(newPlayer, SIGNAL(logSetCardCounters(Player *, QString, int, int)), this, SIGNAL(logSetCardCounters(Player *, QString, int, int))); connect(newPlayer, SIGNAL(logSetTapped(Player *, QString, bool)), this, SIGNAL(logSetTapped(Player *, QString, bool))); @@ -245,6 +245,11 @@ void Game::gameEvent(const ServerEventData &msg) emit logDumpZone(p, data[1], players.findPlayer(data[0].toInt())->getName(), data[2].toInt()); break; } + case eventStopDumpZone: { + QStringList data = msg.getEventData(); + emit logStopDumpZone(p, data[1], players.findPlayer(data[0].toInt())->getName()); + break; + } case eventMoveCard: { if (msg.getPlayerId() == localPlayer->getId()) break; diff --git a/cockatrice/src/game.h b/cockatrice/src/game.h index 5bc3d654..da9c8ccf 100644 --- a/cockatrice/src/game.h +++ b/cockatrice/src/game.h @@ -70,13 +70,14 @@ signals: void logShuffle(Player *player); void logRollDice(Player *player, int sides, int roll); void logDraw(Player *player, int number); - void logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone); + void logMoveCard(Player *player, QString cardName, QString startZone, int oldX, QString targetZone, int newX); void logCreateToken(Player *player, QString cardName); void logSetCardCounters(Player *player, QString cardName, int value, int oldValue); void logSetTapped(Player *player, QString cardName, bool tapped); void logSetCounter(Player *player, QString counterName, int value, int oldValue); void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap); void logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards); + void logStopDumpZone(Player *player, QString zoneName, QString zoneOwner); public: Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_actionsMenu, QMenu *_cardMenu, int playerId, const QString &playerName, QObject *parent = 0); ~Game(); diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index 2839dfd5..8a0b8786 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -94,7 +94,7 @@ void MessageLogWidget::logDraw(Player *player, int number) append(tr("%1 draws %2 cards").arg(sanitizeHtml(player->getName())).arg(number)); } -void MessageLogWidget::logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone) +void MessageLogWidget::logMoveCard(Player *player, QString cardName, QString startZone, int oldX, QString targetZone, int newX) { if ((startZone == "table") && (targetZone == "table")) return; @@ -176,6 +176,10 @@ void MessageLogWidget::logDumpZone(Player *player, QString zoneName, QString zon append(tr("%1 is looking at %2's %3").arg(sanitizeHtml(player->getName())).arg(zoneOwner).arg(zoneName)); } +void MessageLogWidget::logStopDumpZone(Player *player, QString zoneName, QString zoneOwner) +{ + append(tr("%1 stops looking at %2's %3").arg(sanitizeHtml(player->getName())).arg(zoneOwner).arg(zoneName)); +} void MessageLogWidget::connectToGame(Game *game) { @@ -188,13 +192,14 @@ void MessageLogWidget::connectToGame(Game *game) connect(game, SIGNAL(logShuffle(Player *)), this, SLOT(logShuffle(Player *))); connect(game, SIGNAL(logRollDice(Player *, int, int)), this, SLOT(logRollDice(Player *, int, int))); connect(game, SIGNAL(logDraw(Player *, int)), this, SLOT(logDraw(Player *, int))); - connect(game, SIGNAL(logMoveCard(Player *, QString, QString, QString)), this, SLOT(logMoveCard(Player *, QString, QString, QString))); + connect(game, SIGNAL(logMoveCard(Player *, QString, QString, int, QString, int)), this, SLOT(logMoveCard(Player *, QString, QString, int, QString, int))); connect(game, SIGNAL(logCreateToken(Player *, QString)), this, SLOT(logCreateToken(Player *, QString))); connect(game, SIGNAL(logSetCardCounters(Player *, QString, int, int)), this, SLOT(logSetCardCounters(Player *, QString, int, int))); connect(game, SIGNAL(logSetTapped(Player *, QString, bool)), this, SLOT(logSetTapped(Player *, QString, bool))); connect(game, SIGNAL(logSetCounter(Player *, QString, int, int)), this, SLOT(logSetCounter(Player *, QString, int, int))); connect(game, SIGNAL(logSetDoesntUntap(Player *, QString, bool)), this, SLOT(logSetDoesntUntap(Player *, QString, bool))); connect(game, SIGNAL(logDumpZone(Player *, QString, QString, int)), this, SLOT(logDumpZone(Player *, QString, QString, int))); + connect(game, SIGNAL(logStopDumpZone(Player *, QString, QString)), this, SLOT(logStopDumpZone(Player *, QString, QString))); } MessageLogWidget::MessageLogWidget(QWidget *parent) diff --git a/cockatrice/src/messagelogwidget.h b/cockatrice/src/messagelogwidget.h index df303bd2..e1b411cd 100644 --- a/cockatrice/src/messagelogwidget.h +++ b/cockatrice/src/messagelogwidget.h @@ -28,13 +28,14 @@ private slots: void logShuffle(Player *player); void logRollDice(Player *player, int sides, int roll); void logDraw(Player *player, int number); - void logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone); + void logMoveCard(Player *player, QString cardName, QString startZone, int oldX, QString targetZone, int newX); void logCreateToken(Player *player, QString cardName); void logSetCardCounters(Player *player, QString cardName, int value, int oldValue); void logSetTapped(Player *player, QString cardName, bool tapped); void logSetCounter(Player *player, QString counterName, int value, int oldValue); void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap); void logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards); + void logStopDumpZone(Player *player, QString zoneName, QString zoneOwner); public: void connectToGame(Game *game); MessageLogWidget(QWidget *parent = 0); diff --git a/cockatrice/src/pilezone.cpp b/cockatrice/src/pilezone.cpp index 7992f754..13e3cff7 100644 --- a/cockatrice/src/pilezone.cpp +++ b/cockatrice/src/pilezone.cpp @@ -6,8 +6,8 @@ #include "carddragitem.h" #include "zoneviewzone.h" -PileZone::PileZone(Player *_p, const QString &_name, bool _contentsKnown, QGraphicsItem *parent) - : CardZone(_p, _name, false, false, _contentsKnown, parent) +PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent) + : CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent) { setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor! setAcceptsHoverEvents(true); diff --git a/cockatrice/src/pilezone.h b/cockatrice/src/pilezone.h index 9a18c4c1..0b786333 100644 --- a/cockatrice/src/pilezone.h +++ b/cockatrice/src/pilezone.h @@ -5,7 +5,7 @@ class PileZone : public CardZone { public: - PileZone(Player *_p, const QString &_name, bool _contentsKnown, QGraphicsItem *parent = 0); + PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void reorganizeCards(); diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 992c7040..d6726ecd 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -220,6 +220,12 @@ void Player::gameEvent(const ServerEventData &event) bool facedown = data[7].toInt(); // XXX Mehr Fehlerbehandlung + int logPosition = position; + int logX = x; + if (position == -1) + position = 0; + if (x == -1) + x = 0; CardItem *card = startZone->takeCard(position, cardId, cardName); if (!card) // XXX qDebug("moveCard: card not found"); @@ -230,7 +236,7 @@ void Player::gameEvent(const ServerEventData &event) // The log event has to be sent before the card is added to the target zone // because the addCard function can modify the card object. - emit logMoveCard(this, card->getName(), startZone->getName(), targetZone->getName()); + emit logMoveCard(this, card->getName(), startZone->getName(), logPosition, targetZone->getName(), logX); targetZone->addCard(card, true, x, y); diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index a01b68a6..380dcb41 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -23,7 +23,7 @@ signals: void toggleZoneView(Player *player, QString zoneName, int number); void sigShowCardMenu(QPoint p); // Log events - void logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone); + void logMoveCard(Player *player, QString cardName, QString startZone, int oldX, QString targetZone, int newX); void logCreateToken(Player *player, QString cardName); void logSetCardCounters(Player *player, QString cardName, int value, int oldValue); void logSetTapped(Player *player, QString cardName, bool tapped); diff --git a/cockatrice/src/playerarea.cpp b/cockatrice/src/playerarea.cpp index d925a329..9c5028df 100644 --- a/cockatrice/src/playerarea.cpp +++ b/cockatrice/src/playerarea.cpp @@ -13,18 +13,18 @@ PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent) QPointF base = QPointF(55, 50); - PileZone *deck = new PileZone(_player, "deck", false, this); + PileZone *deck = new PileZone(_player, "deck", true, false, this); deck->setPos(base); qreal h = deck->boundingRect().height() + 20; - PileZone *grave = new PileZone(_player, "grave", true, this); + PileZone *grave = new PileZone(_player, "grave", false, true, this); grave->setPos(base + QPointF(0, h)); - PileZone *rfg = new PileZone(_player, "rfg", true, this); + PileZone *rfg = new PileZone(_player, "rfg", false, true, this); rfg->setPos(base + QPointF(0, 2 * h)); - PileZone *sb = new PileZone(_player, "sb", true, this); + PileZone *sb = new PileZone(_player, "sb", false, true, this); sb->setVisible(false); base = QPointF(deck->boundingRect().width() + 60, 0); diff --git a/cockatrice/src/servereventdata.cpp b/cockatrice/src/servereventdata.cpp index d26a357b..cf7ba9f4 100644 --- a/cockatrice/src/servereventdata.cpp +++ b/cockatrice/src/servereventdata.cpp @@ -3,7 +3,7 @@ // Message structure for server events: // {"private","public"}|PlayerId|PlayerName|EventType|EventData -const int event_count = 20; +const int event_count = 21; const event_string event_strings[event_count] = { {eventPlayerId, "player_id"}, {eventSay, "say"}, @@ -24,7 +24,8 @@ const event_string event_strings[event_count] = { {eventDelCounter, "del_counter"}, {eventSetActivePlayer, "set_active_player"}, {eventSetActivePhase, "set_active_phase"}, - {eventDumpZone, "dump_zone"} + {eventDumpZone, "dump_zone"}, + {eventStopDumpZone, "stop_dump_zone"} }; ServerEventData::ServerEventData(const QString &line) diff --git a/cockatrice/src/servereventdata.h b/cockatrice/src/servereventdata.h index dd8e5267..f471fc22 100644 --- a/cockatrice/src/servereventdata.h +++ b/cockatrice/src/servereventdata.h @@ -3,7 +3,6 @@ #include - enum ServerEventType { eventInvalid, eventPlayerId, @@ -25,7 +24,8 @@ enum ServerEventType { eventDelCounter, eventSetActivePlayer, eventSetActivePhase, - eventDumpZone + eventDumpZone, + eventStopDumpZone }; struct event_string { diff --git a/cockatrice/src/zoneviewwidget.cpp b/cockatrice/src/zoneviewwidget.cpp index 2df08ed4..ceaec6a4 100644 --- a/cockatrice/src/zoneviewwidget.cpp +++ b/cockatrice/src/zoneviewwidget.cpp @@ -14,6 +14,7 @@ ZoneViewWidget::ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_or qreal y = 10; if (_origZone->getIsShufflable() && (numberCards == 0)) { + qDebug(QString("ZoneViewWidget: bla!").toLatin1()); shuffleCheckBox = new QCheckBox("shuffle when closing"); shuffleCheckBox->setChecked(true); QGraphicsProxyWidget *shuffleProxy = new QGraphicsProxyWidget(this); @@ -65,6 +66,7 @@ void ZoneViewWidget::zoneDumpReceived(int commandId, QList car void ZoneViewWidget::closeEvent(QCloseEvent *event) { + player->client->stopDumpZone(player->getId(), zone->getName()); if (shuffleCheckBox) if (shuffleCheckBox->isChecked()) player->client->shuffle(); diff --git a/servatrice/src/playerzone.cpp b/servatrice/src/playerzone.cpp index 3ee149f0..6855d480 100644 --- a/servatrice/src/playerzone.cpp +++ b/servatrice/src/playerzone.cpp @@ -21,8 +21,8 @@ #include "abstractrng.h" #include "card.h" -PlayerZone::PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _is_private, bool _id_access) - : name(_name), has_coords(_has_coords), is_public(_is_public), is_private(_is_private), id_access(_id_access) +PlayerZone::PlayerZone(const QString &_name, bool _has_coords, ZoneType _type) + : name(_name), has_coords(_has_coords), type(_type), cardsBeingLookedAt(-1) { } @@ -42,7 +42,7 @@ void PlayerZone::shuffle(AbstractRNG *rnd) Card *PlayerZone::getCard(int id, bool remove, int *position) { - if (hasIdAccess()) { + if (type != HiddenZone) { QListIterator CardIterator(cards); int i = 0; while (CardIterator.hasNext()) { diff --git a/servatrice/src/playerzone.h b/servatrice/src/playerzone.h index f3afcdbc..a7782e1a 100644 --- a/servatrice/src/playerzone.h +++ b/servatrice/src/playerzone.h @@ -27,28 +27,32 @@ class Card; class AbstractRNG; class PlayerZone { +public: + // PrivateZone: Contents of the zone are always visible to the owner, + // but not to anyone else. + // PublicZone: Contents of the zone are always visible to anyone. + // HiddenZone: Contents of the zone are never visible to anyone. + // However, the owner of the zone can issue a dump_zone command, + // setting beingLookedAt to true. + // Cards in a zone with the type HiddenZone are referenced by their + // list index, whereas cards in any other zone are referenced by their ids. + enum ZoneType { PrivateZone, PublicZone, HiddenZone }; private: QString name; bool has_coords; - bool is_public; // Contents of the zone are always visible to anyone - bool is_private; // Contents of the zone are always visible to the owner - bool id_access; // getCard() finds by id, not by list index - // Example: When moving a card from the library to the table, - // the card has to be found by list index because the client - // does not know the id. But when moving a card from the hand - // to the table, the card can be found by id because the client - // knows the id and the hand does not need to have a specific order. + ZoneType type; + int cardsBeingLookedAt; public: - PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _is_private, bool _id_access); + PlayerZone(const QString &_name, bool _has_coords, ZoneType _type); ~PlayerZone(); Card *getCard(int id, bool remove, int *position = NULL); - bool isPublic() { return is_public; } - bool isPrivate() { return is_private; } - bool hasCoords() { return has_coords; } - bool hasIdAccess() { return id_access; } - QString getName() { return name; } + int getCardsBeingLookedAt() const { return cardsBeingLookedAt; } + void setCardsBeingLookedAt(bool _cardsBeingLookedAt) { cardsBeingLookedAt = _cardsBeingLookedAt; } + bool hasCoords() const { return has_coords; } + ZoneType getType() const { return type; } + QString getName() const { return name; } QList cards; void insertCard(Card *card, int x, int y); diff --git a/servatrice/src/serversocket.cpp b/servatrice/src/serversocket.cpp index 641e9dd3..4f626f3e 100644 --- a/servatrice/src/serversocket.cpp +++ b/servatrice/src/serversocket.cpp @@ -85,14 +85,14 @@ void ServerSocket::setupZones() // ------------------------------------------------------------------ // Create zones - PlayerZone *deck = new PlayerZone("deck", false, false, false, false); + PlayerZone *deck = new PlayerZone("deck", false, PlayerZone::HiddenZone); zones << deck; - PlayerZone *sb = new PlayerZone("sb", false, false, false, false); + PlayerZone *sb = new PlayerZone("sb", false, PlayerZone::HiddenZone); zones << sb; - zones << new PlayerZone("table", true, true, false, true); - zones << new PlayerZone("hand", false, false, true, true); - zones << new PlayerZone("grave", false, true, false, true); - zones << new PlayerZone("rfg", false, true, false, true); + zones << new PlayerZone("table", true, PlayerZone::PublicZone); + zones << new PlayerZone("hand", false, PlayerZone::PrivateZone); + zones << new PlayerZone("grave", false, PlayerZone::PublicZone); + zones << new PlayerZone("rfg", false, PlayerZone::PublicZone); // ------------------------------------------------------------------ @@ -209,6 +209,8 @@ const ServerSocket::CommandProperties ServerSocket::commandList[ServerSocket::nu {"dump_zone", true, true, true, QList() << QVariant::Int << QVariant::String << QVariant::Int, &ServerSocket::cmdDumpZone}, + {"stop_dump_zone", true, true, true, QList() << QVariant::Int + << QVariant::String, &ServerSocket::cmdStopDumpZone}, {"roll_dice", true, true, true, QList() << QVariant::Int, &ServerSocket::cmdRollDice}, {"set_active_player", true, true, true, QList() << QVariant::Int, &ServerSocket::cmdSetActivePlayer}, {"set_active_phase", true, true, true, QList() << QVariant::Int, &ServerSocket::cmdSetActivePhase} @@ -364,15 +366,28 @@ ReturnMessage::ReturnCode ServerSocket::cmdMoveCard(const QList ¶m if (facedown) card->setId(newCardId()); if ((!facedown && !card->getFaceDown()) - || (card->getFaceDown() && !facedown && startzone->isPublic() && targetzone->isPublic())) + || (card->getFaceDown() && !facedown && (startzone->getType() == PlayerZone::PublicZone) && (targetzone->getType() == PlayerZone::PublicZone))) publicCardName = card->getName(); if ((!facedown && !card->getFaceDown()) - || (card->getFaceDown() && !facedown && startzone->isPublic() && targetzone->isPublic()) - || (!facedown && targetzone->isPrivate())) + || (card->getFaceDown() && !facedown && (startzone->getType() == PlayerZone::PublicZone) && (targetzone->getType() == PlayerZone::PublicZone)) + || (!facedown && (targetzone->getType() != PlayerZone::PublicZone))) privateCardName = card->getName(); card->setFaceDown(facedown); - msg(QString("private|||move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(card->getId()) + + // The player does not get to see which card he moved if it moves between two parts of hidden zones which + // are not being looked at. + QString privateCardId = QString::number(card->getId()); + if ((targetzone->getType() == PlayerZone::HiddenZone) + && (startzone->getType() == PlayerZone::HiddenZone) + && (startzone->getCardsBeingLookedAt() <= position) + && (startzone->getCardsBeingLookedAt() != 0) + && (targetzone->getCardsBeingLookedAt() <= x) + && (targetzone->getCardsBeingLookedAt() != 0)) { + privateCardId = QString(); + privateCardName = QString(); + } + msg(QString("private|||move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(privateCardId) .arg(privateCardName) .arg(startzone->getName()) .arg(position) @@ -380,7 +395,16 @@ ReturnMessage::ReturnCode ServerSocket::cmdMoveCard(const QList ¶m .arg(x) .arg(y) .arg(facedown ? 1 : 0)); - if ((startzone->isPublic()) || (targetzone->isPublic())) + + // 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, + // all cards are equal. + if ((startzone->getType() == PlayerZone::HiddenZone) && ((startzone->getCardsBeingLookedAt() > position) || (startzone->getCardsBeingLookedAt() == 0))) + position = -1; + if ((targetzone->getType() == PlayerZone::HiddenZone) && ((targetzone->getCardsBeingLookedAt() > position) || (targetzone->getCardsBeingLookedAt() == 0))) + x = -1; + + if ((startzone->getType() == PlayerZone::PublicZone) || (targetzone->getType() == PlayerZone::PublicZone)) emit broadcastEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(card->getId()) .arg(publicCardName) .arg(startzone->getName()) @@ -529,7 +553,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdDumpZone(const QList ¶m PlayerZone *zone = player->getZone(params[1].toString()); if (!zone) return ReturnMessage::ReturnContextError; - if (!(zone->isPublic() || (player_id == playerId))) + if (!((zone->getType() == PlayerZone::PublicZone) || (player_id == playerId))) return ReturnMessage::ReturnContextError; QListIterator card_iterator(zone->cards); @@ -537,7 +561,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdDumpZone(const QList ¶m for (int i = 0; card_iterator.hasNext() && (i < number_cards || number_cards == 0); i++) { Card *tmp = card_iterator.next(); // XXX Face down cards - if (zone->hasIdAccess()) + if (zone->getType() != PlayerZone::HiddenZone) result << QString("%1|%2|%3|%4|%5|%6|%7|%8").arg(tmp->getId()) .arg(tmp->getName()) .arg(tmp->getX()) @@ -546,14 +570,32 @@ ReturnMessage::ReturnCode ServerSocket::cmdDumpZone(const QList ¶m .arg(tmp->getTapped()) .arg(tmp->getAttacking()) .arg(tmp->getAnnotation()); - else + else { + zone->setCardsBeingLookedAt(number_cards); result << QString("%1|%2||||||").arg(i).arg(tmp->getName()); + } } remsg->sendList(result); emit broadcastEvent(QString("dump_zone|%1|%2|%3").arg(player_id).arg(zone->getName()).arg(number_cards), this); return ReturnMessage::ReturnOk; } +ReturnMessage::ReturnCode ServerSocket::cmdStopDumpZone(const QList ¶ms) +{ + ServerSocket *player = game->getPlayer(params[0].toInt()); + if (!player) + return ReturnMessage::ReturnContextError; + PlayerZone *zone = player->getZone(params[1].toString()); + if (!zone) + return ReturnMessage::ReturnContextError; + + if (zone->getType() == PlayerZone::HiddenZone) { + zone->setCardsBeingLookedAt(-1); + emit broadcastEvent(QString("stop_dump_zone|%1|%2").arg(player->getPlayerId()).arg(zone->getName()), this); + } + return ReturnMessage::ReturnOk; +} + ReturnMessage::ReturnCode ServerSocket::cmdRollDice(const QList ¶ms) { int sides = params[0].toInt(); @@ -662,7 +704,7 @@ void ServerSocket::setGame(ServerGame *g) game = g; } -QStringList ServerSocket::listCounters() +QStringList ServerSocket::listCounters() const { QStringList counter_list; QListIterator i(counters); @@ -673,13 +715,13 @@ QStringList ServerSocket::listCounters() return counter_list; } -QStringList ServerSocket::listZones() +QStringList ServerSocket::listZones() const { QStringList zone_list; QListIterator i(zones); while (i.hasNext()) { PlayerZone *tmp = i.next(); - zone_list << QString("%1|%2|%3|%4").arg(tmp->getName()).arg(tmp->isPublic()).arg(tmp->hasCoords()).arg(tmp->cards.size()); + zone_list << QString("%1|%2|%3|%4").arg(tmp->getName()).arg(tmp->getType() == PlayerZone::PublicZone ? 1 : 0).arg(tmp->hasCoords()).arg(tmp->cards.size()); } return zone_list; } diff --git a/servatrice/src/serversocket.h b/servatrice/src/serversocket.h index 138988bd..2330f064 100644 --- a/servatrice/src/serversocket.h +++ b/servatrice/src/serversocket.h @@ -55,7 +55,7 @@ private: QList paramTypes; CommandHandler handler; }; - static const int numberCommands = 26; + static const int numberCommands = 27; static const CommandProperties commandList[numberCommands]; ReturnMessage::ReturnCode cmdPing(const QList ¶ms); @@ -81,6 +81,7 @@ private: ReturnMessage::ReturnCode cmdListCounters(const QList ¶ms); ReturnMessage::ReturnCode cmdListZones(const QList ¶ms); ReturnMessage::ReturnCode cmdDumpZone(const QList ¶ms); + ReturnMessage::ReturnCode cmdStopDumpZone(const QList ¶ms); ReturnMessage::ReturnCode cmdRollDice(const QList ¶ms); ReturnMessage::ReturnCode cmdSetActivePlayer(const QList ¶ms); ReturnMessage::ReturnCode cmdSetActivePhase(const QList ¶ms); @@ -116,8 +117,8 @@ public: void setPlayerId(int _id) { playerId = _id; } QString getPlayerName() const { return playerName; } bool getAcceptsGameListChanges() const { return acceptsGameListChanges; } - QStringList listCounters(); - QStringList listZones(); + QStringList listCounters() const; + QStringList listZones() const; void setupZones(); };