protobuf client->server communication almost working

This commit is contained in:
Max-Wilhelm Bruker 2011-12-18 18:35:14 +01:00
parent 4eb9dfc5bf
commit 314f17091d
96 changed files with 1633 additions and 860 deletions

View file

@ -6,6 +6,7 @@ MOC_DIR = build
OBJECTS_DIR = build OBJECTS_DIR = build
RESOURCES = cockatrice.qrc RESOURCES = cockatrice.qrc
QT += network script svg QT += network script svg
LIBS += -lprotobuf
unix:!macx { unix:!macx {
CONFIG += mobility CONFIG += mobility
MOBILITY = multimedia MOBILITY = multimedia
@ -81,6 +82,7 @@ HEADERS += src/abstractcounter.h \
src/translation.h \ src/translation.h \
src/priceupdater.h \ src/priceupdater.h \
src/soundengine.h \ src/soundengine.h \
src/pending_command.h \
../common/color.h \ ../common/color.h \
../common/serializable_item.h \ ../common/serializable_item.h \
../common/decklist.h \ ../common/decklist.h \
@ -167,6 +169,7 @@ SOURCES += src/abstractcounter.cpp \
src/localclient.cpp \ src/localclient.cpp \
src/priceupdater.cpp \ src/priceupdater.cpp \
src/soundengine.cpp \ src/soundengine.cpp \
src/pending_command.cpp \
../common/serializable_item.cpp \ ../common/serializable_item.cpp \
../common/decklist.cpp \ ../common/decklist.cpp \
../common/protocol.cpp \ ../common/protocol.cpp \
@ -183,6 +186,9 @@ SOURCES += src/abstractcounter.cpp \
../common/server_player.cpp \ ../common/server_player.cpp \
../common/server_protocolhandler.cpp ../common/server_protocolhandler.cpp
include ( ../pb_headers )
include ( ../pb_sources )
TRANSLATIONS += \ TRANSLATIONS += \
translations/cockatrice_de.ts \ translations/cockatrice_de.ts \
translations/cockatrice_en.ts \ translations/cockatrice_en.ts \

View file

@ -1,10 +1,14 @@
#include "abstractclient.h" #include "abstractclient.h"
#include "protocol.h" #include "protocol.h"
#include "protocol_items.h" #include "protocol_items.h"
#include "pending_command.h"
#include "pb/commands.pb.h"
#include <google/protobuf/descriptor.h>
#include <QDebug> #include <QDebug>
AbstractClient::AbstractClient(QObject *parent) AbstractClient::AbstractClient(QObject *parent)
: QObject(parent), status(StatusDisconnected) : QObject(parent), nextCmdId(0), status(StatusDisconnected)
{ {
} }
@ -16,15 +20,16 @@ void AbstractClient::processProtocolItem(ProtocolItem *item)
{ {
ProtocolResponse *response = qobject_cast<ProtocolResponse *>(item); ProtocolResponse *response = qobject_cast<ProtocolResponse *>(item);
if (response) { if (response) {
CommandContainer *cmdCont = pendingCommands.value(response->getCmdId(), 0); const int cmdId = response->getCmdId();
if (!cmdCont) PendingCommand *pend = pendingCommands.value(cmdId, 0);
if (!pend)
return; return;
pendingCommands.remove(cmdCont->getCmdId()); pendingCommands.remove(cmdId);
cmdCont->processResponse(response); pend->processResponse(response);
if (response->getReceiverMayDelete()) if (response->getReceiverMayDelete())
delete response; delete response;
cmdCont->deleteLater(); pend->deleteLater();
return; return;
} }
@ -73,7 +78,39 @@ void AbstractClient::setStatus(const ClientStatus _status)
} }
} }
void AbstractClient::sendCommand(Command *cmd) void AbstractClient::sendCommand(const CommandContainer &cont)
{ {
sendCommandContainer(new CommandContainer(QList<Command *>() << cmd)); sendCommand(new PendingCommand(cont));
}
void AbstractClient::sendCommand(PendingCommand *pend)
{
const int cmdId = nextCmdId++;
pendingCommands.insert(cmdId, pend);
pend->getCommandContainer().set_cmd_id(cmdId);
sendCommandContainer(pend->getCommandContainer());
}
PendingCommand *AbstractClient::prepareSessionCommand(const ::google::protobuf::Message &cmd)
{
CommandContainer cont;
SessionCommand *c = cont.add_session_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont);
}
PendingCommand *AbstractClient::prepareModeratorCommand(const ::google::protobuf::Message &cmd)
{
CommandContainer cont;
ModeratorCommand *c = cont.add_moderator_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont);
}
PendingCommand *AbstractClient::prepareAdminCommand(const ::google::protobuf::Message &cmd)
{
CommandContainer cont;
AdminCommand *c = cont.add_admin_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont);
} }

View file

@ -2,9 +2,11 @@
#define ABSTRACTCLIENT_H #define ABSTRACTCLIENT_H
#include <QObject> #include <QObject>
#include <QVariant>
#include <google/protobuf/message.h>
#include "protocol_datastructures.h" #include "protocol_datastructures.h"
class Command; class PendingCommand;
class CommandContainer; class CommandContainer;
class ProtocolItem; class ProtocolItem;
class ProtocolResponse; class ProtocolResponse;
@ -56,20 +58,27 @@ signals:
void userInfoChanged(ServerInfo_User *userInfo); void userInfoChanged(ServerInfo_User *userInfo);
void buddyListReceived(const QList<ServerInfo_User *> &buddyList); void buddyListReceived(const QList<ServerInfo_User *> &buddyList);
void ignoreListReceived(const QList<ServerInfo_User *> &ignoreList); void ignoreListReceived(const QList<ServerInfo_User *> &ignoreList);
private:
int nextCmdId;
protected slots: protected slots:
void processProtocolItem(ProtocolItem *item); void processProtocolItem(ProtocolItem *item);
protected: protected:
QMap<int, CommandContainer *> pendingCommands; QMap<int, PendingCommand *> pendingCommands;
ClientStatus status; ClientStatus status;
QString userName, password; QString userName, password;
void setStatus(ClientStatus _status); void setStatus(ClientStatus _status);
virtual void sendCommandContainer(const CommandContainer &cont) = 0;
public: public:
AbstractClient(QObject *parent = 0); AbstractClient(QObject *parent = 0);
~AbstractClient(); ~AbstractClient();
ClientStatus getStatus() const { return status; } ClientStatus getStatus() const { return status; }
virtual void sendCommand(Command *cmd); void sendCommand(const CommandContainer &cont);
virtual void sendCommandContainer(CommandContainer *cont) = 0; void sendCommand(PendingCommand *pend);
PendingCommand *prepareSessionCommand(const ::google::protobuf::Message &cmd);
PendingCommand *prepareModeratorCommand(const ::google::protobuf::Message &cmd);
PendingCommand *prepareAdminCommand(const ::google::protobuf::Message &cmd);
}; };
#endif #endif

View file

@ -1,11 +1,12 @@
#include "abstractcounter.h" #include "abstractcounter.h"
#include "player.h" #include "player.h"
#include "protocol_items.h"
#include <QPainter> #include <QPainter>
#include <QMenu> #include <QMenu>
#include <QAction> #include <QAction>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneHoverEvent> #include <QGraphicsSceneHoverEvent>
#include "pb/command_inc_counter.pb.h"
#include "pb/command_set_counter.pb.h"
AbstractCounter::AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent) AbstractCounter::AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent)
: QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value), hovered(false), aDec(0), aInc(0), dialogSemaphore(false), deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea) : QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value), hovered(false), aDec(0), aInc(0), dialogSemaphore(false), deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea)
@ -84,10 +85,16 @@ void AbstractCounter::setValue(int _value)
void AbstractCounter::mousePressEvent(QGraphicsSceneMouseEvent *event) void AbstractCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
player->sendGameCommand(new Command_IncCounter(-1, id, 1)); Command_IncCounter cmd;
cmd.set_counter_id(id);
cmd.set_delta(1);
player->sendGameCommand(cmd);
event->accept(); event->accept();
} else if (event->button() == Qt::RightButton) { } else if (event->button() == Qt::RightButton) {
player->sendGameCommand(new Command_IncCounter(-1, id, -1)); Command_IncCounter cmd;
cmd.set_counter_id(id);
cmd.set_delta(-1);
player->sendGameCommand(cmd);
event->accept(); event->accept();
} else if (event->button() == Qt::MidButton) { } else if (event->button() == Qt::MidButton) {
if (menu) if (menu)
@ -111,8 +118,11 @@ void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
void AbstractCounter::incrementCounter() void AbstractCounter::incrementCounter()
{ {
int delta = static_cast<QAction *>(sender())->data().toInt(); const int delta = static_cast<QAction *>(sender())->data().toInt();
player->sendGameCommand(new Command_IncCounter(-1, id, delta)); Command_IncCounter cmd;
cmd.set_counter_id(id);
cmd.set_delta(delta);
player->sendGameCommand(cmd);
} }
void AbstractCounter::setCounter() void AbstractCounter::setCounter()
@ -125,6 +135,11 @@ void AbstractCounter::setCounter()
return; return;
} }
dialogSemaphore = false; dialogSemaphore = false;
if (ok) if (!ok)
player->sendGameCommand(new Command_SetCounter(-1, id, newValue)); return;
Command_SetCounter cmd;
cmd.set_counter_id(id);
cmd.set_value(newValue);
player->sendGameCommand(cmd);
} }

View file

@ -4,12 +4,17 @@
#include "cardzone.h" #include "cardzone.h"
#include "player.h" #include "player.h"
#include "math.h" #include "math.h"
#include "protocol_items.h"
#include <QPainter> #include <QPainter>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QDebug> #include <QDebug>
#include "color.h"
// XXX
#include "pb/command_attach_card.pb.h"
#include "pb/command_create_arrow.pb.h"
#include "pb/command_delete_arrow.pb.h"
ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color) ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color)
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), color(_color), fullColor(true) : QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), color(_color), fullColor(true)
{ {
@ -129,8 +134,11 @@ void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
} }
event->accept(); event->accept();
if (event->button() == Qt::RightButton) if (event->button() == Qt::RightButton) {
player->sendGameCommand(new Command_DeleteArrow(-1, id)); Command_DeleteArrow cmd;
cmd.set_arrow_id(id);
player->sendGameCommand(cmd);
}
} }
ArrowDragItem::ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color) ArrowDragItem::ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color)
@ -197,31 +205,23 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
// The target item can be a player as well. // The target item can be a player as well.
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem); CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem); CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
Command_CreateArrow cmd;
cmd.mutable_arrow_color()->CopyFrom(Color(color).get_color()); // XXX
cmd.set_start_player_id(startZone->getPlayer()->getId());
cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_start_card_id(startCard->getId());
if (targetCard) { if (targetCard) {
CardZone *targetZone = targetCard->getZone(); CardZone *targetZone = targetCard->getZone();
player->sendGameCommand(new Command_CreateArrow( cmd.set_target_player_id(targetZone->getPlayer()->getId());
-1, cmd.set_target_zone(targetZone->getName().toStdString());
startZone->getPlayer()->getId(), cmd.set_target_card_id(targetCard->getId());
startZone->getName(),
startCard->getId(),
targetZone->getPlayer()->getId(),
targetZone->getName(),
targetCard->getId(),
color
));
} else { } else {
PlayerTarget *targetPlayer = qgraphicsitem_cast<PlayerTarget *>(targetItem); PlayerTarget *targetPlayer = qgraphicsitem_cast<PlayerTarget *>(targetItem);
player->sendGameCommand(new Command_CreateArrow( cmd.set_target_player_id(targetPlayer->getOwner()->getId());
-1,
startZone->getPlayer()->getId(),
startZone->getName(),
startCard->getId(),
targetPlayer->getOwner()->getId(),
QString(),
-1,
color
));
} }
player->sendGameCommand(cmd);
} }
delArrow(); delArrow();
@ -278,14 +278,14 @@ void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem); CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
CardZone *targetZone = targetCard->getZone(); CardZone *targetZone = targetCard->getZone();
player->sendGameCommand(new Command_AttachCard( Command_AttachCard cmd;
-1, cmd.set_start_zone(startZone->getName().toStdString());
startZone->getName(), cmd.set_card_id(startCard->getId());
startCard->getId(), cmd.set_target_player_id(targetZone->getPlayer()->getId());
targetZone->getPlayer()->getId(), cmd.set_target_zone(targetZone->getName().toStdString());
targetZone->getName(), cmd.set_target_card_id(targetCard->getId());
targetCard->getId()
)); player->sendGameCommand(cmd);
} }
delArrow(); delArrow();

View file

@ -6,7 +6,8 @@
#include "carditem.h" #include "carditem.h"
#include "player.h" #include "player.h"
#include "zoneviewzone.h" #include "zoneviewzone.h"
#include "protocol_items.h" #include "protocol_datastructures.h"
#include "pb/command_move_card.pb.h"
CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent, bool isView) CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent, bool isView)
: AbstractGraphicsItem(parent), player(_p), name(_name), cards(_contentsKnown), view(NULL), menu(NULL), doubleClickAction(0), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable) : AbstractGraphicsItem(parent), player(_p), name(_name), cards(_contentsKnown), view(NULL), menu(NULL), doubleClickAction(0), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable)
@ -180,11 +181,16 @@ void CardZone::moveAllToZone()
QString targetZone = data[0].toString(); QString targetZone = data[0].toString();
int targetX = data[1].toInt(); int targetX = data[1].toInt();
QList<CardToMove *> idList; Command_MoveCard cmd;
for (int i = 0; i < cards.size(); ++i) cmd.set_start_zone(getName().toStdString());
idList.append(new CardToMove(cards[i]->getId())); cmd.set_target_player_id(player->getId());
cmd.set_target_zone(targetZone.toStdString());
cmd.set_x(targetX);
player->sendGameCommand(new Command_MoveCard(-1, getName(), idList, player->getId(), targetZone, targetX)); for (int i = 0; i < cards.size(); ++i)
cmd.mutable_cards_to_move()->add_card()->set_card_id(cards[i]->getId());
player->sendGameCommand(cmd);
} }
QPointF CardZone::closestGridPoint(const QPointF &point) QPointF CardZone::closestGridPoint(const QPointF &point)

View file

@ -9,10 +9,13 @@
#include <QGroupBox> #include <QGroupBox>
#include <QMessageBox> #include <QMessageBox>
#include "dlg_creategame.h" #include "dlg_creategame.h"
#include "protocol_items.h" #include "tab_room.h"
DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, const QMap<int, QString> &_gameTypes, QWidget *parent) #include "pending_command.h"
: QDialog(parent), client(_client), roomId(_roomId), gameTypes(_gameTypes) #include "pb/room_commands.pb.h"
DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent)
: QDialog(parent), room(_room), gameTypes(_gameTypes)
{ {
descriptionLabel = new QLabel(tr("&Description:")); descriptionLabel = new QLabel(tr("&Description:"));
descriptionEdit = new QLineEdit; descriptionEdit = new QLineEdit;
@ -103,29 +106,27 @@ DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, const QMap<in
void DlgCreateGame::actOK() void DlgCreateGame::actOK()
{ {
QList<GameTypeId *> gameTypeList; Command_CreateGame cmd;
cmd.set_description(descriptionEdit->text().toStdString());
cmd.set_password(passwordEdit->text().toStdString());
cmd.set_max_players(maxPlayersEdit->value());
cmd.set_only_buddies(onlyBuddiesCheckBox->isChecked());
cmd.set_only_registered(onlyRegisteredCheckBox->isChecked());
cmd.set_spectators_allowed(spectatorsAllowedCheckBox->isChecked());
cmd.set_spectators_need_password(spectatorsNeedPasswordCheckBox->isChecked());
cmd.set_spectators_can_talk(spectatorsCanTalkCheckBox->isChecked());
cmd.set_spectators_see_everything(spectatorsSeeEverythingCheckBox->isChecked());
QMapIterator<int, QCheckBox *> gameTypeCheckBoxIterator(gameTypeCheckBoxes); QMapIterator<int, QCheckBox *> gameTypeCheckBoxIterator(gameTypeCheckBoxes);
while (gameTypeCheckBoxIterator.hasNext()) { while (gameTypeCheckBoxIterator.hasNext()) {
gameTypeCheckBoxIterator.next(); gameTypeCheckBoxIterator.next();
if (gameTypeCheckBoxIterator.value()->isChecked()) if (gameTypeCheckBoxIterator.value()->isChecked())
gameTypeList.append(new GameTypeId(gameTypeCheckBoxIterator.key())); cmd.add_game_type_ids(gameTypeCheckBoxIterator.key());
} }
Command_CreateGame *createCommand = new Command_CreateGame( PendingCommand *pend = room->prepareRoomCommand(cmd);
roomId, connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
descriptionEdit->text(), room->sendRoomCommand(pend);
passwordEdit->text(),
maxPlayersEdit->value(),
gameTypeList,
onlyBuddiesCheckBox->isChecked(),
onlyRegisteredCheckBox->isChecked(),
spectatorsAllowedCheckBox->isChecked(),
spectatorsNeedPasswordCheckBox->isChecked(),
spectatorsCanTalkCheckBox->isChecked(),
spectatorsSeeEverythingCheckBox->isChecked()
);
connect(createCommand, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
client->sendCommand(createCommand);
okButton->setEnabled(false); okButton->setEnabled(false);
cancelButton->setEnabled(false); cancelButton->setEnabled(false);

View file

@ -2,7 +2,7 @@
#define DLG_CREATEGAME_H #define DLG_CREATEGAME_H
#include <QDialog> #include <QDialog>
#include "abstractclient.h" #include "protocol_datastructures.h"
class QLabel; class QLabel;
class QLineEdit; class QLineEdit;
@ -10,18 +10,18 @@ class QPushButton;
class QCheckBox; class QCheckBox;
class QGroupBox; class QGroupBox;
class QSpinBox; class QSpinBox;
class TabRoom;
class DlgCreateGame : public QDialog { class DlgCreateGame : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
DlgCreateGame(AbstractClient *_client, int _roomId, const QMap<int, QString> &_gameTypes, QWidget *parent = 0); DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
private slots: private slots:
void actOK(); void actOK();
void checkResponse(ResponseCode response); void checkResponse(ResponseCode response);
void spectatorsAllowedChanged(int state); void spectatorsAllowedChanged(int state);
private: private:
AbstractClient *client; TabRoom *room;
int roomId;
QMap<int, QString> gameTypes; QMap<int, QString> gameTypes;
QMap<int, QCheckBox *> gameTypeCheckBoxes; QMap<int, QCheckBox *> gameTypeCheckBoxes;

View file

@ -8,11 +8,12 @@
#include <QInputDialog> #include <QInputDialog>
#include "tab_supervisor.h" #include "tab_supervisor.h"
#include "dlg_creategame.h" #include "dlg_creategame.h"
#include "abstractclient.h"
#include "protocol_items.h"
#include "gameselector.h" #include "gameselector.h"
#include "gamesmodel.h" #include "gamesmodel.h"
#include "pending_command.h"
#include "pb/room_commands.pb.h"
GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent) GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent)
: QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room) : QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room)
{ {
@ -84,7 +85,7 @@ void GameSelector::showRunningGamesChanged(int state)
void GameSelector::actCreate() void GameSelector::actCreate()
{ {
DlgCreateGame dlg(client, room->getRoomId(), room->getGameTypes(), this); DlgCreateGame dlg(room, room->getGameTypes(), this);
dlg.exec(); dlg.exec();
} }
@ -125,9 +126,15 @@ void GameSelector::actJoin()
return; return;
} }
Command_JoinGame *commandJoinGame = new Command_JoinGame(game->getRoomId(), game->getGameId(), password, spectator, overrideRestrictions); Command_JoinGame cmd;
connect(commandJoinGame, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode))); cmd.set_game_id(game->getGameId());
client->sendCommand(commandJoinGame); cmd.set_password(password.toStdString());
cmd.set_spectator(spectator);
cmd.set_override_restrictions(overrideRestrictions);
PendingCommand *pend = room->prepareRoomCommand(cmd);
connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
room->sendRoomCommand(pend);
if (createButton) if (createButton)
createButton->setEnabled(false); createButton->setEnabled(false);

View file

@ -2,9 +2,10 @@
#include "handzone.h" #include "handzone.h"
#include "settingscache.h" #include "settingscache.h"
#include "player.h" #include "player.h"
#include "protocol_items.h"
#include "carddragitem.h" #include "carddragitem.h"
#include "pb/command_move_card.pb.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)
{ {
@ -39,11 +40,17 @@ void HandZone::addCardImpl(CardItem *card, int x, int /*y*/)
void HandZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/) void HandZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/)
{ {
QList<CardToMove *> idList; Command_MoveCard cmd;
for (int i = 0; i < dragItems.size(); ++i) cmd.set_start_zone(startZone->getName().toStdString());
idList.append(new CardToMove(dragItems[i]->getId())); cmd.set_target_player_id(player->getId());
cmd.set_target_zone(getName().toStdString());
cmd.set_x(cards.size());
cmd.set_y(-1);
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), idList, player->getId(), getName(), cards.size(), -1)); for (int i = 0; i < dragItems.size(); ++i)
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
player->sendGameCommand(cmd);
} }
QRectF HandZone::boundingRect() const QRectF HandZone::boundingRect() const

View file

@ -2,23 +2,31 @@
#include "localserverinterface.h" #include "localserverinterface.h"
#include "protocol.h" #include "protocol.h"
#include "pb/session_commands.pb.h"
LocalClient::LocalClient(LocalServerInterface *_lsi, const QString &_playerName, QObject *parent) LocalClient::LocalClient(LocalServerInterface *_lsi, const QString &_playerName, QObject *parent)
: AbstractClient(parent), lsi(_lsi) : AbstractClient(parent), lsi(_lsi)
{ {
connect(lsi, SIGNAL(itemToClient(ProtocolItem *)), this, SLOT(itemFromServer(ProtocolItem *))); connect(lsi, SIGNAL(itemToClient(ProtocolItem *)), this, SLOT(itemFromServer(ProtocolItem *)));
sendCommand(new Command_Login(_playerName, QString()));
sendCommand(new Command_JoinRoom(0)); Command_Login loginCmd;
loginCmd.set_user_name(_playerName.toStdString());
sendCommand(prepareSessionCommand(loginCmd));
Command_JoinRoom joinCmd;
joinCmd.set_room_id(0);
sendCommand(prepareSessionCommand(joinCmd));
} }
LocalClient::~LocalClient() LocalClient::~LocalClient()
{ {
} }
void LocalClient::sendCommandContainer(CommandContainer *cont) void LocalClient::sendCommandContainer(const CommandContainer &cont)
{ {
cont->setReceiverMayDelete(false); // cont->setReceiverMayDelete(false);
pendingCommands.insert(cont->getCmdId(), cont); // pendingCommands.insert(cont->getCmdId(), cont);
lsi->itemFromClient(cont); // lsi->itemFromClient(cont);
} }
void LocalClient::itemFromServer(ProtocolItem *item) void LocalClient::itemFromServer(ProtocolItem *item)

View file

@ -13,7 +13,7 @@ public:
LocalClient(LocalServerInterface *_lsi, const QString &_playerName, QObject *parent = 0); LocalClient(LocalServerInterface *_lsi, const QString &_playerName, QObject *parent = 0);
~LocalClient(); ~LocalClient();
void sendCommandContainer(CommandContainer *cont); void sendCommandContainer(const CommandContainer &cont);
private slots: private slots:
void itemFromServer(ProtocolItem *item); void itemFromServer(ProtocolItem *item);

View file

@ -22,5 +22,5 @@ void LocalServerInterface::sendProtocolItem(ProtocolItem *item, bool deleteItem)
void LocalServerInterface::itemFromClient(ProtocolItem *item) void LocalServerInterface::itemFromClient(ProtocolItem *item)
{ {
processCommandContainer(static_cast<CommandContainer *>(item)); //processCommandContainer(static_cast<CommandContainer *>(item));
} }

View file

@ -10,17 +10,17 @@ class LocalServerInterface : public Server_ProtocolHandler
Q_OBJECT Q_OBJECT
private: private:
DeckList *getDeckFromDatabase(int /*deckId*/) { return 0; } DeckList *getDeckFromDatabase(int /*deckId*/) { return 0; }
ResponseCode cmdAddToList(Command_AddToList * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } ResponseCode cmdAddToList(const Command_AddToList & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdRemoveFromList(Command_RemoveFromList * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } ResponseCode cmdRemoveFromList(const Command_RemoveFromList & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckList(Command_DeckList * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } ResponseCode cmdDeckList(const Command_DeckList & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckNewDir(Command_DeckNewDir * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } ResponseCode cmdDeckNewDir(const Command_DeckNewDir & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckDelDir(Command_DeckDelDir * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } ResponseCode cmdDeckDelDir(const Command_DeckDelDir & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckDel(Command_DeckDel * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } ResponseCode cmdDeckDel(const Command_DeckDel & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckUpload(Command_DeckUpload * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } ResponseCode cmdDeckUpload(const Command_DeckUpload & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckDownload(Command_DeckDownload * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } ResponseCode cmdDeckDownload(const Command_DeckDownload & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdBanFromServer(Command_BanFromServer * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } ResponseCode cmdBanFromServer(const Command_BanFromServer & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdShutdownServer(Command_ShutdownServer * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } ResponseCode cmdShutdownServer(const Command_ShutdownServer & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdUpdateServerMessage(Command_UpdateServerMessage * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; } ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
protected: protected:
bool getCompressionSupport() const { return false; } bool getCompressionSupport() const { return false; }
public: public:

View file

@ -0,0 +1,9 @@
#include "pending_command.h"
#include "protocol.h"
void PendingCommand::processResponse(ProtocolResponse *response)
{
qDebug("processResponse");
emit finished(response);
emit finished(response->getResponseCode());
}

View file

@ -0,0 +1,29 @@
#ifndef PENDING_COMMAND_H
#define PENDING_COMMAND_H
#include "protocol_datastructures.h"
#include "pb/commands.pb.h"
#include <QVariant>
class ProtocolResponse;
class PendingCommand : public QObject {
Q_OBJECT
signals:
void finished(ProtocolResponse *response);
void finished(ResponseCode response);
private:
CommandContainer commandContainer;
QVariant extraData;
int ticks;
public:
PendingCommand(const CommandContainer &_commandContainer, QVariant _extraData = QVariant())
: commandContainer(_commandContainer), extraData(_extraData), ticks(0) { }
CommandContainer &getCommandContainer() { return commandContainer; }
void setExtraData(const QVariant &_extraData) { extraData = _extraData; }
QVariant getExtraData() const { return extraData; }
void processResponse(ProtocolResponse *response);
int tick() { return ++ticks; }
};
#endif

View file

@ -5,9 +5,13 @@
#include <QDebug> #include <QDebug>
#include <math.h> #include <math.h>
#include "phasestoolbar.h" #include "phasestoolbar.h"
#include "protocol_items.h"
#include "pixmapgenerator.h" #include "pixmapgenerator.h"
#include "pb/command_set_active_phase.pb.h"
#include "pb/command_next_turn.pb.h"
#include "pb/command_set_card_attr.pb.h"
#include "pb/command_draw_cards.pb.h"
PhaseButton::PhaseButton(const QString &_name, QGraphicsItem *parent, QAction *_doubleClickAction, bool _highlightable) PhaseButton::PhaseButton(const QString &_name, QGraphicsItem *parent, QAction *_doubleClickAction, bool _highlightable)
: QObject(), QGraphicsItem(parent), name(_name), active(false), highlightable(_highlightable), activeAnimationCounter(0), doubleClickAction(_doubleClickAction), width(50) : QObject(), QGraphicsItem(parent), name(_name), active(false), highlightable(_highlightable), activeAnimationCounter(0), doubleClickAction(_doubleClickAction), width(50)
{ {
@ -222,20 +226,33 @@ void PhasesToolbar::phaseButtonClicked()
PhaseButton *button = qobject_cast<PhaseButton *>(sender()); PhaseButton *button = qobject_cast<PhaseButton *>(sender());
if (button->getActive()) if (button->getActive())
button->triggerDoubleClickAction(); button->triggerDoubleClickAction();
emit sendGameCommand(new Command_SetActivePhase(-1, buttonList.indexOf(button)), -1);
Command_SetActivePhase cmd;
cmd.set_phase(buttonList.indexOf(button));
emit sendGameCommand(cmd, -1);
} }
void PhasesToolbar::actNextTurn() void PhasesToolbar::actNextTurn()
{ {
emit sendGameCommand(new Command_NextTurn, -1); emit sendGameCommand(Command_NextTurn(), -1);
} }
void PhasesToolbar::actUntapAll() void PhasesToolbar::actUntapAll()
{ {
emit sendGameCommand(new Command_SetCardAttr(-1, "table", -1, "tapped", "0"), -1); Command_SetCardAttr cmd;
cmd.set_zone("table");
cmd.set_card_id(-1);
cmd.set_attr_name("tapped");
cmd.set_attr_value("0");
emit sendGameCommand(cmd, -1);
} }
void PhasesToolbar::actDrawCard() void PhasesToolbar::actDrawCard()
{ {
emit sendGameCommand(new Command_DrawCards(-1, 1), -1); Command_DrawCards cmd;
cmd.set_number(1);
emit sendGameCommand(cmd, -1);
} }

View file

@ -4,6 +4,7 @@
#include <QFrame> #include <QFrame>
#include <QList> #include <QList>
#include <QGraphicsObject> #include <QGraphicsObject>
#include <google/protobuf/message.h>
class Player; class Player;
class GameCommand; class GameCommand;
@ -62,7 +63,7 @@ private slots:
void actUntapAll(); void actUntapAll();
void actDrawCard(); void actDrawCard();
signals: signals:
void sendGameCommand(GameCommand *command, int playerId); void sendGameCommand(const ::google::protobuf::Message &command, int playerId);
protected: protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/); void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/);
}; };

View file

@ -5,7 +5,8 @@
#include "player.h" #include "player.h"
#include "carddragitem.h" #include "carddragitem.h"
#include "zoneviewzone.h" #include "zoneviewzone.h"
#include "protocol_items.h"
#include "pb/command_move_card.pb.h"
PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent) PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent)
: CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent) : CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent)
@ -50,11 +51,17 @@ void PileZone::addCardImpl(CardItem *card, int x, int /*y*/)
void PileZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/) void PileZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/)
{ {
QList<CardToMove *> idList; Command_MoveCard cmd;
for (int i = 0; i < dragItems.size(); ++i) cmd.set_start_zone(startZone->getName().toStdString());
idList.append(new CardToMove(dragItems[i]->getId())); cmd.set_target_player_id(player->getId());
cmd.set_target_zone(getName().toStdString());
cmd.set_x(0);
cmd.set_y(0);
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), idList, player->getId(), getName(), 0, 0)); for (int i = 0; i < dragItems.size(); ++i)
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
player->sendGameCommand(cmd);
} }
void PileZone::reorganizeCards() void PileZone::reorganizeCards()

View file

@ -22,6 +22,21 @@
#include <QMenu> #include <QMenu>
#include <QDebug> #include <QDebug>
#include "pb/command_reveal_cards.pb.h"
#include "pb/command_shuffle.pb.h"
#include "pb/command_attach_card.pb.h"
#include "pb/command_set_card_attr.pb.h"
#include "pb/command_set_card_counter.pb.h"
#include "pb/command_mulligan.pb.h"
#include "pb/command_move_card.pb.h"
#include "pb/command_draw_cards.pb.h"
#include "pb/command_undo_draw.pb.h"
#include "pb/command_roll_die.pb.h"
#include "pb/command_create_token.pb.h"
#include "pb/command_flip_card.pb.h"
#include "pb/command_game_say.pb.h"
PlayerArea::PlayerArea(QGraphicsItem *parentItem) PlayerArea::PlayerArea(QGraphicsItem *parentItem)
: QObject(), QGraphicsItem(parentItem) : QObject(), QGraphicsItem(parentItem)
{ {
@ -345,13 +360,29 @@ void Player::playerListActionTriggered()
int otherPlayerId = action->data().toInt(); int otherPlayerId = action->data().toInt();
if (menu == mRevealLibrary) { if (menu == mRevealLibrary) {
sendGameCommand(new Command_RevealCards(-1, "deck", -1, otherPlayerId)); Command_RevealCards cmd;
cmd.set_zone_name("deck");
cmd.set_card_id(-1);
cmd.set_player_id(otherPlayerId);
sendGameCommand(cmd);
} else if (menu == mRevealTopCard) { } else if (menu == mRevealTopCard) {
sendGameCommand(new Command_RevealCards(-1, "deck", 0, otherPlayerId)); Command_RevealCards cmd;
cmd.set_zone_name("deck");
cmd.set_card_id(0);
cmd.set_player_id(otherPlayerId);
sendGameCommand(cmd);
} else if (menu == mRevealHand) { } else if (menu == mRevealHand) {
sendGameCommand(new Command_RevealCards(-1, "hand", -1, otherPlayerId)); Command_RevealCards cmd;
cmd.set_zone_name("hand");
cmd.set_card_id(-1);
cmd.set_player_id(otherPlayerId);
sendGameCommand(cmd);
} else if (menu == mRevealRandomHandCard) { } else if (menu == mRevealRandomHandCard) {
sendGameCommand(new Command_RevealCards(-1, "hand", -2, otherPlayerId)); Command_RevealCards cmd;
cmd.set_zone_name("hand");
cmd.set_card_id(-2);
cmd.set_player_id(otherPlayerId);
sendGameCommand(cmd);
} }
} }
@ -578,29 +609,34 @@ void Player::actViewSideboard()
void Player::actShuffle() void Player::actShuffle()
{ {
sendGameCommand(new Command_Shuffle); sendGameCommand(Command_Shuffle());
} }
void Player::actDrawCard() void Player::actDrawCard()
{ {
sendGameCommand(new Command_DrawCards(-1, 1)); Command_DrawCards cmd;
cmd.set_number(1);
sendGameCommand(cmd);
} }
void Player::actMulligan() void Player::actMulligan()
{ {
sendGameCommand(new Command_Mulligan); sendGameCommand(Command_Mulligan());
} }
void Player::actDrawCards() void Player::actDrawCards()
{ {
int number = QInputDialog::getInteger(0, tr("Draw cards"), tr("Number:")); int number = QInputDialog::getInteger(0, tr("Draw cards"), tr("Number:"));
if (number) if (number) {
sendGameCommand(new Command_DrawCards(-1, number)); Command_DrawCards cmd;
cmd.set_number(number);
sendGameCommand(cmd);
}
} }
void Player::actUndoDraw() void Player::actUndoDraw()
{ {
sendGameCommand(new Command_UndoDraw); sendGameCommand(Command_UndoDraw());
} }
void Player::actMoveTopCardsToGrave() void Player::actMoveTopCardsToGrave()
@ -609,14 +645,21 @@ void Player::actMoveTopCardsToGrave()
if (!number) if (!number)
return; return;
QList<Command *> commandList;
const int maxCards = zones.value("deck")->getCards().size(); const int maxCards = zones.value("deck")->getCards().size();
if (number > maxCards) if (number > maxCards)
number = maxCards; number = maxCards;
QList<CardToMove *> idList;
Command_MoveCard cmd;
cmd.set_start_zone("deck");
cmd.set_target_player_id(getId());
cmd.set_target_zone("grave");
cmd.set_x(0);
cmd.set_y(0);
for (int i = 0; i < number; ++i) for (int i = 0; i < number; ++i)
idList.append(new CardToMove(i)); cmd.mutable_cards_to_move()->add_card()->set_card_id(i);
sendGameCommand(new Command_MoveCard(-1, "deck", idList, getId(), "grave", 0, 0));
sendGameCommand(cmd);
} }
void Player::actMoveTopCardsToExile() void Player::actMoveTopCardsToExile()
@ -625,32 +668,56 @@ void Player::actMoveTopCardsToExile()
if (!number) if (!number)
return; return;
QList<Command *> commandList;
const int maxCards = zones.value("deck")->getCards().size(); const int maxCards = zones.value("deck")->getCards().size();
if (number > maxCards) if (number > maxCards)
number = maxCards; number = maxCards;
QList<CardToMove *> idList;
Command_MoveCard cmd;
cmd.set_start_zone("deck");
cmd.set_target_player_id(getId());
cmd.set_target_zone("rfg");
cmd.set_x(0);
cmd.set_y(0);
for (int i = 0; i < number; ++i) for (int i = 0; i < number; ++i)
idList.append(new CardToMove(i)); cmd.mutable_cards_to_move()->add_card()->set_card_id(i);
sendGameCommand(new Command_MoveCard(-1, "deck", idList, getId(), "rfg", 0, 0));
sendGameCommand(cmd);
} }
void Player::actMoveTopCardToBottom() void Player::actMoveTopCardToBottom()
{ {
sendGameCommand(new Command_MoveCard(-1, "deck", QList<CardToMove *>() << new CardToMove(0), getId(), "deck", -1, 0)); Command_MoveCard cmd;
cmd.set_start_zone("deck");
cmd.mutable_cards_to_move()->add_card()->set_card_id(0);
cmd.set_target_player_id(getId());
cmd.set_target_zone("deck");
cmd.set_x(-1);
cmd.set_y(0);
sendGameCommand(cmd);
} }
void Player::actUntapAll() void Player::actUntapAll()
{ {
sendGameCommand(new Command_SetCardAttr(-1, "table", -1, "tapped", "0")); Command_SetCardAttr cmd;
cmd.set_zone("table");
cmd.set_card_id(-1);
cmd.set_attr_name("tapped");
cmd.set_attr_value("0");
sendGameCommand(cmd);
} }
void Player::actRollDie() void Player::actRollDie()
{ {
bool ok; bool ok;
int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok); int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok);
if (ok) if (ok) {
sendGameCommand(new Command_RollDie(-1, sides)); Command_RollDie cmd;
cmd.set_sides(sides);
sendGameCommand(cmd);
}
} }
void Player::actCreateToken() void Player::actCreateToken()
@ -666,18 +733,30 @@ void Player::actCreateToken()
lastTokenDestroy = dlg.getDestroy(); lastTokenDestroy = dlg.getDestroy();
aCreateAnotherToken->setEnabled(true); aCreateAnotherToken->setEnabled(true);
sendGameCommand(new Command_CreateToken(-1, "table", dlg.getName(), dlg.getColor(), dlg.getPT(), dlg.getAnnotation(), dlg.getDestroy(), -1, 0)); actCreateAnotherToken();
} }
void Player::actCreateAnotherToken() void Player::actCreateAnotherToken()
{ {
sendGameCommand(new Command_CreateToken(-1, "table", lastTokenName, lastTokenColor, lastTokenPT, lastTokenAnnotation, lastTokenDestroy, -1, 0)); Command_CreateToken cmd;
cmd.set_zone("table");
cmd.set_card_name(lastTokenName.toStdString());
cmd.set_color(lastTokenColor.toStdString());
cmd.set_pt(lastTokenPT.toStdString());
cmd.set_annotation(lastTokenAnnotation.toStdString());
cmd.set_destroy_on_zone_change(lastTokenDestroy);
cmd.set_x(-1);
cmd.set_y(0);
sendGameCommand(cmd);
} }
void Player::actSayMessage() void Player::actSayMessage()
{ {
QAction *a = qobject_cast<QAction *>(sender()); QAction *a = qobject_cast<QAction *>(sender());
sendGameCommand(new Command_Say(-1, a->text())); Command_GameSay cmd;
cmd.set_message(a->text().toStdString());
sendGameCommand(cmd);
} }
void Player::setCardAttrHelper(GameEventContext *context, CardItem *card, const QString &aname, const QString &avalue, bool allCards) void Player::setCardAttrHelper(GameEventContext *context, CardItem *card, const QString &aname, const QString &avalue, bool allCards)
@ -1154,13 +1233,27 @@ void Player::processCardAttachment(ServerInfo_Player *info)
void Player::playCard(CardItem *c, bool faceDown, bool tapped) void Player::playCard(CardItem *c, bool faceDown, bool tapped)
{ {
Command_MoveCard cmd;
cmd.set_start_zone(c->getZone()->getName().toStdString());
cmd.set_target_player_id(getId());
CardToMove *cardToMove = cmd.mutable_cards_to_move()->add_card();
cardToMove->set_card_id(c->getId());
CardInfo *ci = c->getInfo(); CardInfo *ci = c->getInfo();
if (ci->getTableRow() == 3) if (ci->getTableRow() == 3) {
sendGameCommand(new Command_MoveCard(-1, c->getZone()->getName(), QList<CardToMove *>() << new CardToMove(c->getId()), getId(), "stack", 0, 0)); cmd.set_target_zone("stack");
else { cmd.set_x(0);
cmd.set_y(0);
} else {
QPoint gridPoint = QPoint(-1, 2 - ci->getTableRow()); QPoint gridPoint = QPoint(-1, 2 - ci->getTableRow());
sendGameCommand(new Command_MoveCard(-1, c->getZone()->getName(), QList<CardToMove *>() << new CardToMove(c->getId(), faceDown, ci->getPowTough(), tapped), getId(), "table", gridPoint.x(), gridPoint.y())); cardToMove->set_face_down(faceDown);
cardToMove->set_pt(ci->getPowTough().toStdString());
cardToMove->set_tapped(tapped);
cmd.set_target_zone("table");
cmd.set_x(gridPoint.x());
cmd.set_y(gridPoint.y());
} }
sendGameCommand(cmd);
} }
void Player::addCard(CardItem *c) void Player::addCard(CardItem *c)
@ -1312,16 +1405,31 @@ void Player::rearrangeCounters()
} }
} }
void Player::sendGameCommand(GameCommand *command) PendingCommand * Player::prepareGameCommand(const google::protobuf::Message &cmd)
{
return static_cast<TabGame *>(parent())->prepareGameCommand(cmd);
}
PendingCommand * Player::prepareGameCommand(const QList<const::google::protobuf::Message *> &cmdList)
{
return static_cast<TabGame *>(parent())->prepareGameCommand(cmdList);
}
void Player::sendGameCommand(const google::protobuf::Message &command)
{ {
static_cast<TabGame *>(parent())->sendGameCommand(command, id); static_cast<TabGame *>(parent())->sendGameCommand(command, id);
} }
void Player::sendCommandContainer(CommandContainer *cont) void Player::sendCommandContainer(CommandContainer &cont)
{ {
static_cast<TabGame *>(parent())->sendCommandContainer(cont, id); static_cast<TabGame *>(parent())->sendCommandContainer(cont, id);
} }
void Player::sendGameCommand(PendingCommand *pend)
{
static_cast<TabGame *>(parent())->sendGameCommand(pend, id);
}
bool Player::clearCardsToDelete() bool Player::clearCardsToDelete()
{ {
if (cardsToDelete.isEmpty()) if (cardsToDelete.isEmpty())
@ -1341,55 +1449,118 @@ void Player::cardMenuAction(QAction *a)
while (!sel.isEmpty()) while (!sel.isEmpty())
cardList.append(qgraphicsitem_cast<CardItem *>(sel.takeFirst())); cardList.append(qgraphicsitem_cast<CardItem *>(sel.takeFirst()));
QList<Command *> commandList; QList< const ::google::protobuf::Message * > commandList;
if (a->data().toInt() <= 4) if (a->data().toInt() <= 4)
for (int i = 0; i < cardList.size(); ++i) { for (int i = 0; i < cardList.size(); ++i) {
CardItem *card = cardList[i]; CardItem *card = cardList[i];
switch (a->data().toInt()) { switch (a->data().toInt()) {
case 0: case 0:
if (!card->getTapped()) if (!card->getTapped()) {
commandList.append(new Command_SetCardAttr(-1, card->getZone()->getName(), card->getId(), "tapped", "1")); Command_SetCardAttr *cmd = new Command_SetCardAttr;
cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId());
cmd->set_attr_name("tapped");
cmd->set_attr_value("1");
commandList.append(cmd);
}
break; break;
case 1: case 1:
if (card->getTapped()) if (card->getTapped()) {
commandList.append(new Command_SetCardAttr(-1, card->getZone()->getName(), card->getId(), "tapped", "0")); Command_SetCardAttr *cmd = new Command_SetCardAttr;
cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId());
cmd->set_attr_name("tapped");
cmd->set_attr_value("0");
commandList.append(cmd);
}
break; break;
case 2: case 2: {
commandList.append(new Command_SetCardAttr(-1, card->getZone()->getName(), card->getId(), "doesnt_untap", QString::number(!card->getDoesntUntap()))); Command_SetCardAttr *cmd = new Command_SetCardAttr;
break; cmd->set_zone(card->getZone()->getName().toStdString());
case 3: { cmd->set_card_id(card->getId());
QString zone = card->getZone()->getName(); cmd->set_attr_name("doesnt_untap");
commandList.append(new Command_FlipCard(-1, zone, card->getId(), !card->getFaceDown())); cmd->set_attr_value(card->getDoesntUntap() ? "1" : "0");
commandList.append(cmd);
break; break;
} }
case 4: case 3: {
commandList.append(new Command_CreateToken(-1, card->getZone()->getName(), card->getName(), card->getColor(), card->getPT(), card->getAnnotation(), true, -1, card->getGridPoint().y())); Command_FlipCard *cmd = new Command_FlipCard;
cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId());
cmd->set_face_down(!card->getFaceDown());
commandList.append(cmd);
break; break;
}
case 4: {
Command_CreateToken *cmd = new Command_CreateToken;
cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_name(card->getName().toStdString());
cmd->set_color(card->getColor().toStdString());
cmd->set_pt(card->getPT().toStdString());
cmd->set_annotation(card->getAnnotation().toStdString());
cmd->set_destroy_on_zone_change(true);
cmd->set_x(-1);
cmd->set_y(card->getGridPoint().y());
commandList.append(cmd);
break;
}
} }
} }
else { else {
QList<CardToMove *> idList; ListOfCardsToMove idList;
for (int i = 0; i < cardList.size(); ++i) for (int i = 0; i < cardList.size(); ++i)
idList.append(new CardToMove(cardList[i]->getId())); idList.add_card()->set_card_id(cardList[i]->getId());
QString startZone = cardList[0]->getZone()->getName(); QString startZone = cardList[0]->getZone()->getName();
switch (a->data().toInt()) { switch (a->data().toInt()) {
case 5: case 5: {
commandList.append(new Command_MoveCard(-1, startZone, idList, getId(), "deck", 0, 0)); Command_MoveCard *cmd = new Command_MoveCard;
cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(getId());
cmd->set_target_zone("deck");
cmd->set_x(0);
cmd->set_y(0);
commandList.append(cmd);
break; break;
case 6: }
commandList.append(new Command_MoveCard(-1, startZone, idList, getId(), "deck", -1, 0)); case 6: {
Command_MoveCard *cmd = new Command_MoveCard;
cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(getId());
cmd->set_target_zone("deck");
cmd->set_x(-1);
cmd->set_y(0);
commandList.append(cmd);
break; break;
case 7: }
commandList.append(new Command_MoveCard(-1, startZone, idList, getId(), "grave", 0, 0)); case 7: {
Command_MoveCard *cmd = new Command_MoveCard;
cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(getId());
cmd->set_target_zone("grave");
cmd->set_x(0);
cmd->set_y(0);
commandList.append(cmd);
break; break;
case 8: }
commandList.append(new Command_MoveCard(-1, startZone, idList, getId(), "rfg", 0, 0)); case 8: {
Command_MoveCard *cmd = new Command_MoveCard;
cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(getId());
cmd->set_target_zone("rfg");
cmd->set_x(0);
cmd->set_y(0);
commandList.append(cmd);
break; break;
}
default: ; default: ;
} }
} }
sendCommandContainer(new CommandContainer(commandList)); static_cast<TabGame *>(parent())->sendGameCommand(prepareGameCommand(commandList));
} }
void Player::actIncPT(int deltaP, int deltaT) void Player::actIncPT(int deltaP, int deltaT)
@ -1398,7 +1569,11 @@ void Player::actIncPT(int deltaP, int deltaT)
QListIterator<QGraphicsItem *> j(scene()->selectedItems()); QListIterator<QGraphicsItem *> j(scene()->selectedItems());
while (j.hasNext()) { while (j.hasNext()) {
CardItem *card = static_cast<CardItem *>(j.next()); CardItem *card = static_cast<CardItem *>(j.next());
sendGameCommand(new Command_SetCardAttr(-1, card->getZone()->getName(), card->getId(), "pt", ptString)); Command_SetCardAttr cmd;
cmd.set_zone(card->getZone()->getName().toStdString());
cmd.set_card_id(card->getId());
cmd.set_attr_name("pt");
cmd.set_attr_value(ptString.toStdString());
} }
} }
@ -1423,7 +1598,11 @@ void Player::actSetPT(QAction * /*a*/)
QListIterator<QGraphicsItem *> j(scene()->selectedItems()); QListIterator<QGraphicsItem *> j(scene()->selectedItems());
while (j.hasNext()) { while (j.hasNext()) {
CardItem *card = static_cast<CardItem *>(j.next()); CardItem *card = static_cast<CardItem *>(j.next());
sendGameCommand(new Command_SetCardAttr(-1, card->getZone()->getName(), card->getId(), "pt", pt)); Command_SetCardAttr cmd;
cmd.set_zone(card->getZone()->getName().toStdString());
cmd.set_card_id(card->getId());
cmd.set_attr_name("pt");
cmd.set_attr_value(pt.toStdString());
} }
} }
@ -1449,7 +1628,11 @@ void Player::actSetAnnotation(QAction * /*a*/)
i.toFront(); i.toFront();
while (i.hasNext()) { while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next()); CardItem *card = static_cast<CardItem *>(i.next());
sendGameCommand(new Command_SetCardAttr(-1, card->getZone()->getName(), card->getId(), "annotation", annotation)); Command_SetCardAttr cmd;
cmd.set_zone(card->getZone()->getName().toStdString());
cmd.set_card_id(card->getId());
cmd.set_attr_name("annotation");
cmd.set_attr_value(annotation.toStdString());
} }
} }
@ -1464,7 +1647,10 @@ void Player::actAttach(QAction *a)
void Player::actUnattach(QAction *a) void Player::actUnattach(QAction *a)
{ {
CardItem *card = static_cast<CardItem *>(a->parent()); CardItem *card = static_cast<CardItem *>(a->parent());
sendGameCommand(new Command_AttachCard(-1, card->getZone()->getName(), card->getId(), -1, QString(), -1)); Command_AttachCard cmd;
cmd.set_start_zone(card->getZone()->getName().toStdString());
cmd.set_card_id(card->getId());
sendGameCommand(cmd);
} }
void Player::actCardCounterTrigger(QAction *a) void Player::actCardCounterTrigger(QAction *a)
@ -1476,8 +1662,14 @@ void Player::actCardCounterTrigger(QAction *a)
QListIterator<QGraphicsItem *> i(scene()->selectedItems()); QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) { while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next()); CardItem *card = static_cast<CardItem *>(i.next());
if (card->getCounters().value(counterId, 0) < MAX_COUNTERS_ON_CARD) if (card->getCounters().value(counterId, 0) < MAX_COUNTERS_ON_CARD) {
sendGameCommand(new Command_SetCardCounter(-1, card->getZone()->getName(), card->getId(), counterId, card->getCounters().value(counterId, 0) + 1)); Command_SetCardCounter cmd;
cmd.set_zone(card->getZone()->getName().toStdString());
cmd.set_card_id(card->getId());
cmd.set_counter_id(counterId);
cmd.set_counter_value(card->getCounters().value(counterId, 0) + 1);
sendGameCommand(cmd);
}
} }
break; break;
} }
@ -1485,8 +1677,14 @@ void Player::actCardCounterTrigger(QAction *a)
QListIterator<QGraphicsItem *> i(scene()->selectedItems()); QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) { while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next()); CardItem *card = static_cast<CardItem *>(i.next());
if (card->getCounters().value(counterId, 0)) if (card->getCounters().value(counterId, 0)) {
sendGameCommand(new Command_SetCardCounter(-1, card->getZone()->getName(), card->getId(), counterId, card->getCounters().value(counterId, 0) - 1)); Command_SetCardCounter cmd;
cmd.set_zone(card->getZone()->getName().toStdString());
cmd.set_card_id(card->getId());
cmd.set_counter_id(counterId);
cmd.set_counter_value(card->getCounters().value(counterId, 0) - 1);
sendGameCommand(cmd);
}
} }
break; break;
} }
@ -1503,7 +1701,12 @@ void Player::actCardCounterTrigger(QAction *a)
QListIterator<QGraphicsItem *> i(scene()->selectedItems()); QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) { while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next()); CardItem *card = static_cast<CardItem *>(i.next());
sendGameCommand(new Command_SetCardCounter(-1, card->getZone()->getName(), card->getId(), counterId, number)); Command_SetCardCounter cmd;
cmd.set_zone(card->getZone()->getName().toStdString());
cmd.set_card_id(card->getId());
cmd.set_counter_id(counterId);
cmd.set_counter_value(number);
sendGameCommand(cmd);
} }
break; break;
} }

View file

@ -5,6 +5,7 @@
#include <QPoint> #include <QPoint>
#include <QMap> #include <QMap>
#include "carditem.h" #include "carditem.h"
#include <google/protobuf/message.h>
class CardDatabase; class CardDatabase;
class QMenu; class QMenu;
@ -46,6 +47,7 @@ class Event_DestroyCard;
class Event_AttachCard; class Event_AttachCard;
class Event_DrawCards; class Event_DrawCards;
class Event_RevealCards; class Event_RevealCards;
class PendingCommand;
class PlayerArea : public QObject, public QGraphicsItem { class PlayerArea : public QObject, public QGraphicsItem {
Q_OBJECT Q_OBJECT
@ -254,8 +256,12 @@ public:
void processCardAttachment(ServerInfo_Player *info); void processCardAttachment(ServerInfo_Player *info);
void processGameEvent(GameEvent *event, GameEventContext *context); void processGameEvent(GameEvent *event, GameEventContext *context);
void sendGameCommand(GameCommand *command);
void sendCommandContainer(CommandContainer *cont); PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
PendingCommand *prepareGameCommand(const QList< const ::google::protobuf::Message * > &cmdList);
void sendGameCommand(PendingCommand *pend);
void sendGameCommand(const google::protobuf::Message &command);
void sendCommandContainer(CommandContainer &cont);
}; };
#endif #endif

View file

@ -13,6 +13,9 @@
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
#include "pb/session_commands.pb.h"
#include "pb/command_kick_from_game.pb.h"
PlayerListItemDelegate::PlayerListItemDelegate(QObject *const parent) PlayerListItemDelegate::PlayerListItemDelegate(QObject *const parent)
: QStyledItemDelegate(parent) : QStyledItemDelegate(parent)
{ {
@ -198,16 +201,35 @@ void PlayerListWidget::showContextMenu(const QPoint &pos, const QModelIndex &ind
infoWidget->updateInfo(userName); infoWidget->updateInfo(userName);
} else if (actionClicked == aChat) } else if (actionClicked == aChat)
emit openMessageDialog(userName, true); emit openMessageDialog(userName, true);
else if (actionClicked == aAddToBuddyList) else if (actionClicked == aAddToBuddyList) {
client->sendCommand(new Command_AddToList("buddy", userName)); Command_AddToList cmd;
else if (actionClicked == aRemoveFromBuddyList) cmd.set_list("buddy");
client->sendCommand(new Command_RemoveFromList("buddy", userName)); cmd.set_user_name(userName.toStdString());
else if (actionClicked == aAddToIgnoreList)
client->sendCommand(new Command_AddToList("ignore", userName)); client->sendCommand(client->prepareSessionCommand(cmd));
else if (actionClicked == aRemoveFromIgnoreList) } else if (actionClicked == aRemoveFromBuddyList) {
client->sendCommand(new Command_RemoveFromList("ignore", userName)); Command_RemoveFromList cmd;
else if (actionClicked == aKick) cmd.set_list("buddy");
game->sendGameCommand(new Command_KickFromGame(-1, playerId)); cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
} else if (actionClicked == aAddToIgnoreList) {
Command_AddToList cmd;
cmd.set_list("ignore");
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
} else if (actionClicked == aRemoveFromIgnoreList) {
Command_RemoveFromList cmd;
cmd.set_list("ignore");
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
} else if (actionClicked == aKick) {
Command_KickFromGame cmd;
cmd.set_player_id(playerId);
game->sendGameCommand(cmd);
}
delete menu; delete menu;
delete aUserName; delete aUserName;

View file

@ -6,6 +6,10 @@
#include "protocol.h" #include "protocol.h"
#include "protocol_items.h" #include "protocol_items.h"
#include "pending_command.h"
#include "pb/commands.pb.h"
#include "pb/session_commands.pb.h"
RemoteClient::RemoteClient(QObject *parent) RemoteClient::RemoteClient(QObject *parent)
: AbstractClient(parent), timeRunning(0), lastDataReceived(0), topLevelItem(0) : AbstractClient(parent), timeRunning(0), lastDataReceived(0), topLevelItem(0)
{ {
@ -21,8 +25,6 @@ RemoteClient::RemoteClient(QObject *parent)
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError))); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError)));
xmlReader = new QXmlStreamReader; xmlReader = new QXmlStreamReader;
xmlWriter = new QXmlStreamWriter;
xmlWriter->setDevice(socket);
} }
RemoteClient::~RemoteClient() RemoteClient::~RemoteClient()
@ -80,28 +82,41 @@ void RemoteClient::readData()
disconnectFromServer(); disconnectFromServer();
return; return;
} }
xmlWriter->writeStartDocument(); /* xmlWriter->writeStartDocument();
xmlWriter->writeStartElement("cockatrice_client_stream"); xmlWriter->writeStartElement("cockatrice_client_stream");
xmlWriter->writeAttribute("version", QString::number(ProtocolItem::protocolVersion)); xmlWriter->writeAttribute("version", QString::number(ProtocolItem::protocolVersion));
xmlWriter->writeAttribute("comp", "1"); xmlWriter->writeAttribute("comp", "1");
*/
topLevelItem = new TopLevelProtocolItem; topLevelItem = new TopLevelProtocolItem;
connect(topLevelItem, SIGNAL(protocolItemReceived(ProtocolItem *)), this, SLOT(processProtocolItem(ProtocolItem *))); connect(topLevelItem, SIGNAL(protocolItemReceived(ProtocolItem *)), this, SLOT(processProtocolItem(ProtocolItem *)));
setStatus(StatusLoggingIn); setStatus(StatusLoggingIn);
Command_Login *cmdLogin = new Command_Login(userName, password);
connect(cmdLogin, SIGNAL(finished(ProtocolResponse *)), this, SLOT(loginResponse(ProtocolResponse *))); Command_Login cmdLogin;
sendCommand(cmdLogin); cmdLogin.set_user_name(userName.toStdString());
cmdLogin.set_password(password.toStdString());
PendingCommand *pend = prepareSessionCommand(cmdLogin);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(loginResponse(ProtocolResponse *)));
sendCommand(pend);
} }
} }
if (status == StatusDisconnecting) if (status == StatusDisconnecting)
disconnectFromServer(); disconnectFromServer();
} }
void RemoteClient::sendCommandContainer(CommandContainer *cont) void RemoteClient::sendCommandContainer(const CommandContainer &cont)
{ {
cont->write(xmlWriter); QByteArray buf;
pendingCommands.insert(cont->getCmdId(), cont); unsigned int size = cont.ByteSize();
buf.resize(size + 4);
cont.SerializeToArray(buf.data() + 4, size);
buf.data()[3] = (unsigned char) size;
buf.data()[2] = (unsigned char) (size >> 8);
buf.data()[1] = (unsigned char) (size >> 16);
buf.data()[0] = (unsigned char) (size >> 24);
socket->write(buf);
} }
void RemoteClient::connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password) void RemoteClient::connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
@ -123,7 +138,7 @@ void RemoteClient::disconnectFromServer()
timer->stop(); timer->stop();
QList<CommandContainer *> pc = pendingCommands.values(); QList<PendingCommand *> pc = pendingCommands.values();
for (int i = 0; i < pc.size(); i++) for (int i = 0; i < pc.size(); i++)
delete pc[i]; delete pc[i];
pendingCommands.clear(); pendingCommands.clear();
@ -134,21 +149,21 @@ void RemoteClient::disconnectFromServer()
void RemoteClient::ping() void RemoteClient::ping()
{ {
QMutableMapIterator<int, CommandContainer *> i(pendingCommands); /* QMutableMapIterator<int, PendingCommand *> i(pendingCommands);
while (i.hasNext()) while (i.hasNext())
if (i.next().value()->tick() > maxTimeout) { if (i.next().value()->tick() > maxTimeout) {
CommandContainer *cont = i.value(); CommandContainer *cont = i.value();
i.remove(); i.remove();
cont->deleteLater(); cont->deleteLater();
} }
*/
int maxTime = timeRunning - lastDataReceived; int maxTime = timeRunning - lastDataReceived;
emit maxPingTime(maxTime, maxTimeout); emit maxPingTime(maxTime, maxTimeout);
if (maxTime >= maxTimeout) { if (maxTime >= maxTimeout) {
disconnectFromServer(); disconnectFromServer();
emit serverTimeout(); emit serverTimeout();
} else { } else {
sendCommand(new Command_Ping); sendCommand(prepareSessionCommand(Command_Ping()));
++timeRunning; ++timeRunning;
} }
} }

View file

@ -29,8 +29,9 @@ private:
QTimer *timer; QTimer *timer;
QTcpSocket *socket; QTcpSocket *socket;
QXmlStreamReader *xmlReader; QXmlStreamReader *xmlReader;
QXmlStreamWriter *xmlWriter;
TopLevelProtocolItem *topLevelItem; TopLevelProtocolItem *topLevelItem;
void sendCommandContainer(const CommandContainer &cont);
public: public:
RemoteClient(QObject *parent = 0); RemoteClient(QObject *parent = 0);
~RemoteClient(); ~RemoteClient();
@ -38,8 +39,6 @@ public:
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password); void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
void disconnectFromServer(); void disconnectFromServer();
void sendCommandContainer(CommandContainer *cont);
}; };
#endif #endif

View file

@ -5,6 +5,9 @@
#include "protocol_items.h" #include "protocol_items.h"
#include "abstractclient.h" #include "abstractclient.h"
#include "pending_command.h"
#include "pb/session_commands.pb.h"
RemoteDeckList_TreeModel::DirectoryNode::DirectoryNode(const QString &_name, RemoteDeckList_TreeModel::DirectoryNode *_parent) RemoteDeckList_TreeModel::DirectoryNode::DirectoryNode(const QString &_name, RemoteDeckList_TreeModel::DirectoryNode *_parent)
: RemoteDeckList_TreeModel::Node(_name, _parent) : RemoteDeckList_TreeModel::Node(_name, _parent)
{ {
@ -238,9 +241,10 @@ void RemoteDeckList_TreeModel::removeNode(RemoteDeckList_TreeModel::Node *node)
void RemoteDeckList_TreeModel::refreshTree() void RemoteDeckList_TreeModel::refreshTree()
{ {
Command_DeckList *command = new Command_DeckList; PendingCommand *pend = client->prepareSessionCommand(Command_DeckList());
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckListFinished(ProtocolResponse *))); connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckListFinished(ProtocolResponse *)));
client->sendCommand(command);
client->sendCommand(pend);
} }
void RemoteDeckList_TreeModel::deckListFinished(ProtocolResponse *r) void RemoteDeckList_TreeModel::deckListFinished(ProtocolResponse *r)

View file

@ -4,9 +4,10 @@
#include "stackzone.h" #include "stackzone.h"
#include "settingscache.h" #include "settingscache.h"
#include "player.h" #include "player.h"
#include "protocol_items.h"
#include "carddragitem.h" #include "carddragitem.h"
#include "pb/command_move_card.pb.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)
{ {
@ -57,11 +58,17 @@ void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone
if (startZone == this) if (startZone == this)
return; return;
QList<CardToMove *> idList; Command_MoveCard cmd;
for (int i = 0; i < dragItems.size(); ++i) cmd.set_start_zone(startZone->getName().toStdString());
idList.append(new CardToMove(dragItems[i]->getId())); cmd.set_target_player_id(player->getId());
cmd.set_target_zone(getName().toStdString());
cmd.set_x(0);
cmd.set_y(0);
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), idList, player->getId(), getName(), 0, 0)); for (int i = 0; i < dragItems.size(); ++i)
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
player->sendGameCommand(cmd);
} }
void StackZone::reorganizeCards() void StackZone::reorganizeCards()

View file

@ -9,7 +9,8 @@
#include <QLineEdit> #include <QLineEdit>
#include "tab_admin.h" #include "tab_admin.h"
#include "abstractclient.h" #include "abstractclient.h"
#include "protocol_items.h"
#include "pb/admin_commands.pb.h"
ShutdownDialog::ShutdownDialog(QWidget *parent) ShutdownDialog::ShutdownDialog(QWidget *parent)
: QDialog(parent) : QDialog(parent)
@ -100,14 +101,19 @@ void TabAdmin::retranslateUi()
void TabAdmin::actUpdateServerMessage() void TabAdmin::actUpdateServerMessage()
{ {
client->sendCommand(new Command_UpdateServerMessage()); client->sendCommand(client->prepareAdminCommand(Command_UpdateServerMessage()));
} }
void TabAdmin::actShutdownServer() void TabAdmin::actShutdownServer()
{ {
ShutdownDialog dlg; ShutdownDialog dlg;
if (dlg.exec()) if (dlg.exec()) {
client->sendCommand(new Command_ShutdownServer(dlg.getReason(), dlg.getMinutes())); Command_ShutdownServer cmd;
cmd.set_reason(dlg.getReason().toStdString());
cmd.set_minutes(dlg.getMinutes());
client->sendCommand(client->prepareAdminCommand(cmd));
}
} }
void TabAdmin::actUnlock() void TabAdmin::actUnlock()

View file

@ -17,6 +17,13 @@
#include "window_deckeditor.h" #include "window_deckeditor.h"
#include "settingscache.h" #include "settingscache.h"
#include "pending_command.h"
#include "pb/command_deck_upload.pb.h"
#include "pb/command_deck_download.pb.h"
#include "pb/command_deck_new_dir.pb.h"
#include "pb/command_deck_del_dir.pb.h"
#include "pb/command_deck_del.pb.h"
TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client) TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client)
: Tab(_tabSupervisor), client(_client) : Tab(_tabSupervisor), client(_client)
{ {
@ -157,9 +164,9 @@ void TabDeckStorage::actUpload()
curRight = curRight->getParent(); curRight = curRight->getParent();
targetPath = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight)->getPath(); targetPath = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight)->getPath();
Command_DeckUpload *command = new Command_DeckUpload(deck, targetPath); // Command_DeckUpload *command = new Command_DeckUpload(deck, targetPath);
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(uploadFinished(ProtocolResponse *))); // connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(uploadFinished(ProtocolResponse *)));
client->sendCommand(command); // client->sendCommand(command);
} }
void TabDeckStorage::uploadFinished(ProtocolResponse *r) void TabDeckStorage::uploadFinished(ProtocolResponse *r)
@ -167,9 +174,9 @@ void TabDeckStorage::uploadFinished(ProtocolResponse *r)
Response_DeckUpload *resp = qobject_cast<Response_DeckUpload *>(r); Response_DeckUpload *resp = qobject_cast<Response_DeckUpload *>(r);
if (!resp) if (!resp)
return; return;
Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender()); // Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender());
//
serverDirView->addFileToTree(resp->getFile(), serverDirView->getNodeByPath(cmd->getPath())); // serverDirView->addFileToTree(resp->getFile(), serverDirView->getNodeByPath(cmd->getPath()));
} }
void TabDeckStorage::actOpenRemoteDeck() void TabDeckStorage::actOpenRemoteDeck()
@ -178,9 +185,9 @@ void TabDeckStorage::actOpenRemoteDeck()
if (!curRight) if (!curRight)
return; return;
Command_DeckDownload *command = new Command_DeckDownload(curRight->getId()); // Command_DeckDownload *command = new Command_DeckDownload(curRight->getId());
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(openRemoteDeckFinished(ProtocolResponse *))); // connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(openRemoteDeckFinished(ProtocolResponse *)));
client->sendCommand(command); // client->sendCommand(command);
} }
void TabDeckStorage::openRemoteDeckFinished(ProtocolResponse *r) void TabDeckStorage::openRemoteDeckFinished(ProtocolResponse *r)
@ -211,10 +218,10 @@ void TabDeckStorage::actDownload()
return; return;
filePath += QString("/deck_%1.cod").arg(curRight->getId()); filePath += QString("/deck_%1.cod").arg(curRight->getId());
Command_DeckDownload *command = new Command_DeckDownload(curRight->getId()); // Command_DeckDownload *command = new Command_DeckDownload(curRight->getId());
command->setExtraData(filePath); // command->setExtraData(filePath);
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(downloadFinished(ProtocolResponse *))); // connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(downloadFinished(ProtocolResponse *)));
client->sendCommand(command); // client->sendCommand(command);
} }
void TabDeckStorage::downloadFinished(ProtocolResponse *r) void TabDeckStorage::downloadFinished(ProtocolResponse *r)
@ -222,10 +229,10 @@ void TabDeckStorage::downloadFinished(ProtocolResponse *r)
Response_DeckDownload *resp = qobject_cast<Response_DeckDownload *>(r); Response_DeckDownload *resp = qobject_cast<Response_DeckDownload *>(r);
if (!resp) if (!resp)
return; return;
Command_DeckDownload *cmd = static_cast<Command_DeckDownload *>(sender()); // Command_DeckDownload *cmd = static_cast<Command_DeckDownload *>(sender());
//
QString filePath = cmd->getExtraData().toString(); // QString filePath = cmd->getExtraData().toString();
resp->getDeck()->saveToFile(filePath, DeckList::CockatriceFormat); // resp->getDeck()->saveToFile(filePath, DeckList::CockatriceFormat);
} }
void TabDeckStorage::actNewFolder() void TabDeckStorage::actNewFolder()
@ -243,9 +250,13 @@ void TabDeckStorage::actNewFolder()
RemoteDeckList_TreeModel::DirectoryNode *dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight); RemoteDeckList_TreeModel::DirectoryNode *dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight);
targetPath = dir->getPath(); targetPath = dir->getPath();
Command_DeckNewDir *command = new Command_DeckNewDir(targetPath, folderName); Command_DeckNewDir cmd;
connect(command, SIGNAL(finished(ResponseCode)), this, SLOT(newFolderFinished(ResponseCode))); cmd.set_path(targetPath.toStdString());
client->sendCommand(command); cmd.set_dir_name(folderName.toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(newFolderFinished(ResponseCode)));
client->sendCommand(pend);
} }
void TabDeckStorage::newFolderFinished(ResponseCode resp) void TabDeckStorage::newFolderFinished(ResponseCode resp)
@ -253,13 +264,13 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp)
if (resp != RespOk) if (resp != RespOk)
return; return;
Command_DeckNewDir *cmd = static_cast<Command_DeckNewDir *>(sender()); // Command_DeckNewDir *cmd = static_cast<Command_DeckNewDir *>(sender());
serverDirView->addFolderToTree(cmd->getDirName(), serverDirView->getNodeByPath(cmd->getPath())); // serverDirView->addFolderToTree(cmd->getDirName(), serverDirView->getNodeByPath(cmd->getPath()));
} }
void TabDeckStorage::actDelete() void TabDeckStorage::actDelete()
{ {
Command *command; PendingCommand *pend;
RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem(); RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem();
if (!curRight) if (!curRight)
return; return;
@ -268,11 +279,17 @@ void TabDeckStorage::actDelete()
QString path = dir->getPath(); QString path = dir->getPath();
if (path.isEmpty()) if (path.isEmpty())
return; return;
command = new Command_DeckDelDir(path); Command_DeckDelDir cmd;
} else cmd.set_path(path.toStdString());
command = new Command_DeckDel(dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(curRight)->getId()); pend = client->prepareSessionCommand(cmd);
connect(command, SIGNAL(finished(ResponseCode)), this, SLOT(deleteFinished(ResponseCode))); } else {
client->sendCommand(command); Command_DeckDel cmd;
cmd.set_deck_id(dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(curRight)->getId());
pend = client->prepareSessionCommand(cmd);
}
connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(deleteFinished(ResponseCode)));
client->sendCommand(pend);
} }
void TabDeckStorage::deleteFinished(ResponseCode resp) void TabDeckStorage::deleteFinished(ResponseCode resp)
@ -281,11 +298,11 @@ void TabDeckStorage::deleteFinished(ResponseCode resp)
return; return;
RemoteDeckList_TreeModel::Node *toDelete = 0; RemoteDeckList_TreeModel::Node *toDelete = 0;
Command_DeckDelDir *cmdDelDir = qobject_cast<Command_DeckDelDir *>(sender()); // Command_DeckDelDir *cmdDelDir = qobject_cast<Command_DeckDelDir *>(sender());
if (cmdDelDir) // if (cmdDelDir)
toDelete = serverDirView->getNodeByPath(cmdDelDir->getPath()); // toDelete = serverDirView->getNodeByPath(cmdDelDir->getPath());
else // else
toDelete = serverDirView->getNodeById(static_cast<Command_DeckDel *>(sender())->getDeckId()); // toDelete = serverDirView->getNodeById(static_cast<Command_DeckDel *>(sender())->getDeckId());
if (toDelete) if (toDelete)
serverDirView->removeNode(toDelete); serverDirView->removeNode(toDelete);

View file

@ -27,6 +27,18 @@
#include "settingscache.h" #include "settingscache.h"
#include "carddatabase.h" #include "carddatabase.h"
#include <google/protobuf/descriptor.h>
#include "pending_command.h"
#include "pb/command_concede.pb.h"
#include "pb/command_deck_select.pb.h"
#include "pb/command_ready_start.pb.h"
#include "pb/command_set_sideboard_plan.pb.h"
#include "pb/command_leave_game.pb.h"
#include "pb/command_game_say.pb.h"
#include "pb/command_set_active_phase.pb.h"
#include "pb/command_next_turn.pb.h"
#include "pb/command_delete_arrow.pb.h"
ReadyStartButton::ReadyStartButton(QWidget *parent) ReadyStartButton::ReadyStartButton(QWidget *parent)
: QPushButton(parent), readyStart(false) : QPushButton(parent), readyStart(false)
{ {
@ -50,8 +62,8 @@ void ReadyStartButton::setReadyStart(bool _readyStart)
update(); update();
} }
DeckViewContainer::DeckViewContainer(AbstractClient *_client, TabGame *parent) DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
: QWidget(parent), client(_client) : QWidget(parent), playerId(_playerId)
{ {
loadLocalButton = new QPushButton; loadLocalButton = new QPushButton;
loadRemoteButton = new QPushButton; loadRemoteButton = new QPushButton;
@ -110,18 +122,22 @@ void DeckViewContainer::loadLocalDeck()
return; return;
} }
Command_DeckSelect *cmd = new Command_DeckSelect(static_cast<TabGame *>(parent())->getGameId(), deck, -1); Command_DeckSelect cmd;
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckSelectFinished(ProtocolResponse *))); cmd.set_deck(""); // XXX
client->sendCommand(cmd); PendingCommand *pend = static_cast<TabGame *>(parent())->prepareGameCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckSelectFinished(ProtocolResponse *)));
static_cast<TabGame *>(parent())->sendGameCommand(pend, playerId);
} }
void DeckViewContainer::loadRemoteDeck() void DeckViewContainer::loadRemoteDeck()
{ {
DlgLoadRemoteDeck dlg(client); DlgLoadRemoteDeck dlg(static_cast<TabGame *>(parent())->getClientForPlayer(playerId));
if (dlg.exec()) { if (dlg.exec()) {
Command_DeckSelect *cmd = new Command_DeckSelect(static_cast<TabGame *>(parent())->getGameId(), 0, dlg.getDeckId()); Command_DeckSelect cmd;
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckSelectFinished(ProtocolResponse *))); cmd.set_deck_id(dlg.getDeckId());
client->sendCommand(cmd); PendingCommand *pend = static_cast<TabGame *>(parent())->prepareGameCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckSelectFinished(ProtocolResponse *)));
static_cast<TabGame *>(parent())->sendGameCommand(pend, playerId);
} }
} }
@ -138,13 +154,18 @@ void DeckViewContainer::deckSelectFinished(ProtocolResponse *r)
void DeckViewContainer::readyStart() void DeckViewContainer::readyStart()
{ {
client->sendCommand(new Command_ReadyStart(static_cast<TabGame *>(parent())->getGameId(), !readyStartButton->getReadyStart())); Command_ReadyStart cmd;
cmd.set_ready(!readyStartButton->getReadyStart());
static_cast<TabGame *>(parent())->sendGameCommand(cmd);
} }
void DeckViewContainer::sideboardPlanChanged() void DeckViewContainer::sideboardPlanChanged()
{ {
Command_SetSideboardPlan cmd;
QList<MoveCardToZone *> newPlan = deckView->getSideboardPlan(); QList<MoveCardToZone *> newPlan = deckView->getSideboardPlan();
client->sendCommand(new Command_SetSideboardPlan(static_cast<TabGame *>(parent())->getGameId(), newPlan)); for (int i = 0; i < newPlan.size(); ++i)
cmd.add_move_list()->CopyFrom(newPlan[i]->toPB());
static_cast<TabGame *>(parent())->sendGameCommand(cmd);
} }
void DeckViewContainer::setReadyStart(bool ready) void DeckViewContainer::setReadyStart(bool ready)
@ -164,7 +185,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
{ {
phasesToolbar = new PhasesToolbar; phasesToolbar = new PhasesToolbar;
phasesToolbar->hide(); phasesToolbar->hide();
connect(phasesToolbar, SIGNAL(sendGameCommand(GameCommand *, int)), this, SLOT(sendGameCommand(GameCommand *, int))); connect(phasesToolbar, SIGNAL(sendGameCommand(const ::google::protobuf::Message &, int)), this, SLOT(sendGameCommand(const ::google::protobuf::Message &, int)));
scene = new GameScene(phasesToolbar, this); scene = new GameScene(phasesToolbar, this);
gameView = new GameView(scene); gameView = new GameView(scene);
@ -327,7 +348,7 @@ void TabGame::actConcede()
if (QMessageBox::question(this, tr("Concede"), tr("Are you sure you want to concede this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) if (QMessageBox::question(this, tr("Concede"), tr("Are you sure you want to concede this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
return; return;
sendGameCommand(new Command_Concede); sendGameCommand(Command_Concede());
} }
void TabGame::actLeaveGame() void TabGame::actLeaveGame()
@ -336,14 +357,16 @@ void TabGame::actLeaveGame()
if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
return; return;
sendGameCommand(new Command_LeaveGame); sendGameCommand(Command_LeaveGame());
deleteLater(); deleteLater();
} }
void TabGame::actSay() void TabGame::actSay()
{ {
if (!sayEdit->text().isEmpty()) { if (!sayEdit->text().isEmpty()) {
sendGameCommand(new Command_Say(-1, sayEdit->text())); Command_GameSay cmd;
cmd.set_message(sayEdit->text().toStdString());
sendGameCommand(cmd);
sayEdit->clear(); sayEdit->clear();
} }
} }
@ -351,7 +374,9 @@ void TabGame::actSay()
void TabGame::actPhaseAction() void TabGame::actPhaseAction()
{ {
int phase = phaseActions.indexOf(static_cast<QAction *>(sender())); int phase = phaseActions.indexOf(static_cast<QAction *>(sender()));
emit sendGameCommand(new Command_SetActivePhase(-1, phase), -1); Command_SetActivePhase cmd;
cmd.set_phase(phase);
sendGameCommand(cmd);
} }
void TabGame::actNextPhase() void TabGame::actNextPhase()
@ -359,12 +384,14 @@ void TabGame::actNextPhase()
int phase = currentPhase; int phase = currentPhase;
if (++phase >= phasesToolbar->phaseCount()) if (++phase >= phasesToolbar->phaseCount())
phase = 0; phase = 0;
sendGameCommand(new Command_SetActivePhase(-1, phase)); Command_SetActivePhase cmd;
cmd.set_phase(phase);
sendGameCommand(cmd);
} }
void TabGame::actNextTurn() void TabGame::actNextTurn()
{ {
sendGameCommand(new Command_NextTurn); sendGameCommand(Command_NextTurn());
} }
void TabGame::actRemoveLocalArrows() void TabGame::actRemoveLocalArrows()
@ -377,7 +404,9 @@ void TabGame::actRemoveLocalArrows()
QMapIterator<int, ArrowItem *> arrowIterator(player->getArrows()); QMapIterator<int, ArrowItem *> arrowIterator(player->getArrows());
while (arrowIterator.hasNext()) { while (arrowIterator.hasNext()) {
ArrowItem *a = arrowIterator.next().value(); ArrowItem *a = arrowIterator.next().value();
sendGameCommand(new Command_DeleteArrow(-1, a->getId())); Command_DeleteArrow cmd;
cmd.set_arrow_id(a->getId());
sendGameCommand(cmd);
} }
} }
} }
@ -392,14 +421,10 @@ Player *TabGame::addPlayer(int playerId, ServerInfo_User *info)
messageLog->connectToPlayer(newPlayer); messageLog->connectToPlayer(newPlayer);
if (local && !spectator) { if (local && !spectator) {
AbstractClient *client; if (clients.size() == 1)
if (clients.size() > 1)
client = clients.at(playerId);
else {
client = clients.first();
newPlayer->setShortcutsActive(); newPlayer->setShortcutsActive();
}
DeckViewContainer *deckView = new DeckViewContainer(client, this); DeckViewContainer *deckView = new DeckViewContainer(playerId, this);
connect(deckView, SIGNAL(newCardAdded(AbstractCardItem *)), this, SLOT(newCardAdded(AbstractCardItem *))); connect(deckView, SIGNAL(newCardAdded(AbstractCardItem *)), this, SLOT(newCardAdded(AbstractCardItem *)));
deckViewContainers.insert(playerId, deckView); deckViewContainers.insert(playerId, deckView);
deckViewContainerLayout->addWidget(deckView); deckViewContainerLayout->addWidget(deckView);
@ -462,37 +487,53 @@ void TabGame::processGameEventContainer(GameEventContainer *cont, AbstractClient
messageLog->containerProcessingDone(); messageLog->containerProcessingDone();
} }
void TabGame::sendGameCommand(GameCommand *command, int playerId) AbstractClient *TabGame::getClientForPlayer(int playerId) const
{ {
command->setGameId(gameId);
AbstractClient *client;
if (clients.size() > 1) { if (clients.size() > 1) {
if (playerId == -1) if (playerId == -1)
playerId = getActiveLocalPlayer()->getId(); playerId = getActiveLocalPlayer()->getId();
client = clients.at(playerId); return clients.at(playerId);
} else } else
client = clients.first(); return clients.first();
client->sendCommand(command);
} }
void TabGame::sendCommandContainer(CommandContainer *cont, int playerId) void TabGame::sendGameCommand(PendingCommand *pend, int playerId)
{ {
const QList<Command *> &cmdList = cont->getCommandList(); getClientForPlayer(playerId)->sendCommand(pend);
for (int i = 0; i < cmdList.size(); ++i) { }
GameCommand *cmd = qobject_cast<GameCommand *>(cmdList[i]);
if (cmd)
cmd->setGameId(gameId);
}
AbstractClient *client; void TabGame::sendGameCommand(const google::protobuf::Message &command, int playerId)
if (clients.size() > 1) { {
if (playerId == -1) AbstractClient *client = getClientForPlayer(playerId);
playerId = getActiveLocalPlayer()->getId(); client->sendCommand(prepareGameCommand(command));
client = clients.at(playerId); }
} else
client = clients.first(); void TabGame::sendCommandContainer(CommandContainer &cont, int playerId)
client->sendCommandContainer(cont); {
cont.set_game_id(gameId);
getClientForPlayer(playerId)->sendCommand(cont);
}
PendingCommand *TabGame::prepareGameCommand(const ::google::protobuf::Message &cmd)
{
CommandContainer cont;
cont.set_game_id(gameId);
GameCommand *c = cont.add_game_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont);
}
PendingCommand *TabGame::prepareGameCommand(const QList< const ::google::protobuf::Message * > &cmdList)
{
CommandContainer cont;
cont.set_game_id(gameId);
for (int i = 0; i < cmdList.size(); ++i) {
GameCommand *c = cont.add_game_command();
c->GetReflection()->MutableMessage(c, cmdList[i]->GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(*cmdList[i]);
delete cmdList[i];
}
return new PendingCommand(cont);
} }
void TabGame::startGame(bool resuming) void TabGame::startGame(bool resuming)

View file

@ -4,6 +4,7 @@
#include <QMap> #include <QMap>
#include <QPushButton> #include <QPushButton>
#include "tab.h" #include "tab.h"
#include <google/protobuf/message.h>
class AbstractClient; class AbstractClient;
class CardDatabase; class CardDatabase;
@ -47,6 +48,7 @@ class DeckList;
class QVBoxLayout; class QVBoxLayout;
class QHBoxLayout; class QHBoxLayout;
class ServerInfo_User; class ServerInfo_User;
class PendingCommand;
class ReadyStartButton : public QPushButton { class ReadyStartButton : public QPushButton {
Q_OBJECT Q_OBJECT
@ -66,7 +68,7 @@ private:
QPushButton *loadLocalButton, *loadRemoteButton; QPushButton *loadLocalButton, *loadRemoteButton;
ReadyStartButton *readyStartButton; ReadyStartButton *readyStartButton;
DeckView *deckView; DeckView *deckView;
AbstractClient *client; int playerId;
private slots: private slots:
void loadLocalDeck(); void loadLocalDeck();
void loadRemoteDeck(); void loadRemoteDeck();
@ -76,7 +78,7 @@ private slots:
signals: signals:
void newCardAdded(AbstractCardItem *card); void newCardAdded(AbstractCardItem *card);
public: public:
DeckViewContainer(AbstractClient *_client, TabGame *parent = 0); DeckViewContainer(int _playerId, TabGame *parent = 0);
void retranslateUi(); void retranslateUi();
void setButtonsVisible(bool _visible); void setButtonsVisible(bool _visible);
void setReadyStart(bool ready); void setReadyStart(bool ready);
@ -173,11 +175,15 @@ public:
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; } bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; } bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
Player *getActiveLocalPlayer() const; Player *getActiveLocalPlayer() const;
AbstractClient *getClientForPlayer(int playerId) const;
void processGameEventContainer(GameEventContainer *cont, AbstractClient *client); void processGameEventContainer(GameEventContainer *cont, AbstractClient *client);
PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
PendingCommand *prepareGameCommand(const QList< const ::google::protobuf::Message * > &cmdList);
public slots: public slots:
void sendGameCommand(GameCommand *command, int playerId = -1); void sendGameCommand(PendingCommand *pend, int playerId = -1);
void sendCommandContainer(CommandContainer *cont, int playerId = -1); void sendGameCommand(const ::google::protobuf::Message &command, int playerId = -1);
void sendCommandContainer(CommandContainer &cont, int playerId = -1);
}; };
#endif #endif

View file

@ -8,6 +8,9 @@
#include "protocol_items.h" #include "protocol_items.h"
#include "chatview.h" #include "chatview.h"
#include "pending_command.h"
#include "pb/session_commands.pb.h"
TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const QString &_userName) TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const QString &_userName)
: Tab(_tabSupervisor), client(_client), userName(_userName), userOnline(true) : Tab(_tabSupervisor), client(_client), userName(_userName), userOnline(true)
{ {
@ -52,9 +55,14 @@ void TabMessage::sendMessage()
if (sayEdit->text().isEmpty() || !userOnline) if (sayEdit->text().isEmpty() || !userOnline)
return; return;
Command_Message *cmd = new Command_Message(userName, sayEdit->text()); Command_Message cmd;
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(messageSent(ProtocolResponse *))); cmd.set_user_name(userName.toStdString());
client->sendCommand(cmd); cmd.set_message(sayEdit->text().toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(messageSent(ProtocolResponse *)));
client->sendCommand(pend);
sayEdit->clear(); sayEdit->clear();
} }

View file

@ -13,9 +13,13 @@
#include "tab_userlists.h" #include "tab_userlists.h"
#include "userlist.h" #include "userlist.h"
#include "abstractclient.h" #include "abstractclient.h"
#include "protocol_items.h"
#include "chatview.h" #include "chatview.h"
#include "gameselector.h" #include "gameselector.h"
#include "protocol_items.h"
#include "pending_command.h"
#include <google/protobuf/descriptor.h>
#include "pb/room_commands.pb.h"
TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info) TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info)
: Tab(_tabSupervisor), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName) : Tab(_tabSupervisor), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName)
@ -108,9 +112,12 @@ void TabRoom::sendMessage()
if (sayEdit->text().isEmpty()) if (sayEdit->text().isEmpty())
return; return;
Command_RoomSay *cmd = new Command_RoomSay(roomId, sayEdit->text()); Command_RoomSay cmd;
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(sayFinished(ProtocolResponse *))); cmd.set_message(sayEdit->text().toStdString());
client->sendCommand(cmd);
PendingCommand *pend = prepareRoomCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(sayFinished(ProtocolResponse *)));
sendRoomCommand(pend);
sayEdit->clear(); sayEdit->clear();
} }
@ -122,7 +129,7 @@ void TabRoom::sayFinished(ProtocolResponse *response)
void TabRoom::actLeaveRoom() void TabRoom::actLeaveRoom()
{ {
client->sendCommand(new Command_LeaveRoom(roomId)); sendRoomCommand(prepareRoomCommand(Command_LeaveRoom()));
deleteLater(); deleteLater();
} }
@ -161,3 +168,17 @@ void TabRoom::processSayEvent(Event_RoomSay *event)
chatView->appendMessage(event->getPlayerName(), event->getMessage()); chatView->appendMessage(event->getPlayerName(), event->getMessage());
emit userEvent(false); emit userEvent(false);
} }
PendingCommand *TabRoom::prepareRoomCommand(const ::google::protobuf::Message &cmd)
{
CommandContainer cont;
RoomCommand *c = cont.add_room_command();
cont.set_room_id(roomId);
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont);
}
void TabRoom::sendRoomCommand(PendingCommand *pend)
{
client->sendCommand(pend);
}

View file

@ -4,6 +4,7 @@
#include "tab.h" #include "tab.h"
#include <QGroupBox> #include <QGroupBox>
#include <QMap> #include <QMap>
#include <google/protobuf/message.h>
class AbstractClient; class AbstractClient;
class UserList; class UserList;
@ -21,6 +22,7 @@ class Event_LeaveRoom;
class Event_RoomSay; class Event_RoomSay;
class ProtocolResponse; class ProtocolResponse;
class GameSelector; class GameSelector;
class PendingCommand;
class TabRoom : public Tab { class TabRoom : public Tab {
Q_OBJECT Q_OBJECT
@ -62,6 +64,9 @@ public:
const QMap<int, QString> &getGameTypes() const { return gameTypes; } const QMap<int, QString> &getGameTypes() const { return gameTypes; }
QString getChannelName() const { return roomName; } QString getChannelName() const { return roomName; }
QString getTabText() const { return roomName; } QString getTabText() const { return roomName; }
PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd);
void sendRoomCommand(PendingCommand *pend);
}; };
#endif #endif

View file

@ -17,6 +17,9 @@
#include "userinfobox.h" #include "userinfobox.h"
#include <QDebug> #include <QDebug>
#include "pending_command.h"
#include "pb/session_commands.pb.h"
RoomSelector::RoomSelector(AbstractClient *_client, QWidget *parent) RoomSelector::RoomSelector(AbstractClient *_client, QWidget *parent)
: QGroupBox(parent), client(_client) : QGroupBox(parent), client(_client)
{ {
@ -42,7 +45,7 @@ RoomSelector::RoomSelector(AbstractClient *_client, QWidget *parent)
setLayout(vbox); setLayout(vbox);
connect(client, SIGNAL(listRoomsEventReceived(Event_ListRooms *)), this, SLOT(processListRoomsEvent(Event_ListRooms *))); connect(client, SIGNAL(listRoomsEventReceived(Event_ListRooms *)), this, SLOT(processListRoomsEvent(Event_ListRooms *)));
client->sendCommand(new Command_ListRooms); client->sendCommand(client->prepareSessionCommand(Command_ListRooms()));
} }
void RoomSelector::retranslateUi() void RoomSelector::retranslateUi()
@ -91,10 +94,14 @@ void RoomSelector::processListRoomsEvent(Event_ListRooms *event)
void RoomSelector::joinRoom(int id, bool setCurrent) void RoomSelector::joinRoom(int id, bool setCurrent)
{ {
Command_JoinRoom *command = new Command_JoinRoom(id); Command_JoinRoom cmd;
command->setExtraData(setCurrent); cmd.set_room_id(id);
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(joinFinished(ProtocolResponse *)));
client->sendCommand(command); PendingCommand *pend = client->prepareSessionCommand(cmd);
pend->setExtraData(setCurrent);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(joinFinished(ProtocolResponse *)));
client->sendCommand(pend);
} }
void RoomSelector::joinClicked() void RoomSelector::joinClicked()
@ -114,7 +121,7 @@ void RoomSelector::joinFinished(ProtocolResponse *r)
if (!resp) if (!resp)
return; return;
emit roomJoined(resp->getRoomInfo(), static_cast<Command *>(sender())->getExtraData().toBool()); emit roomJoined(resp->getRoomInfo(), static_cast<PendingCommand *>(sender())->getExtraData().toBool());
} }
TabServer::TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent) TabServer::TabServer(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent)

View file

@ -13,6 +13,8 @@
#include <QDebug> #include <QDebug>
#include <QPainter> #include <QPainter>
#include "pb/room_commands.pb.h"
CloseButton::CloseButton(QWidget *parent) CloseButton::CloseButton(QWidget *parent)
: QAbstractButton(parent) : QAbstractButton(parent)
{ {
@ -247,8 +249,9 @@ void TabSupervisor::localGameJoined(Event_GameJoined *event)
setCurrentWidget(tab); setCurrentWidget(tab);
for (int i = 1; i < localClients.size(); ++i) { for (int i = 1; i < localClients.size(); ++i) {
Command_JoinGame *cmd = new Command_JoinGame(0, event->getGameId()); // Command_JoinGame *cmd = new Command_JoinGame(0, event->getGameId());
localClients[i]->sendCommand(cmd); // localClients[i]->sendCommand(cmd);
// XXX
} }
} }

View file

@ -1,11 +1,14 @@
#include "tab_userlists.h" #include "tab_userlists.h"
#include "userlist.h" #include "userlist.h"
#include "userinfobox.h" #include "userinfobox.h"
#include "protocol_items.h"
#include "abstractclient.h" #include "abstractclient.h"
#include <QDebug> #include <QDebug>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "protocol_items.h"
#include "pending_command.h"
#include "pb/session_commands.pb.h"
TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerInfo_User *userInfo, QWidget *parent) TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerInfo_User *userInfo, QWidget *parent)
: Tab(_tabSupervisor, parent), client(_client) : Tab(_tabSupervisor, parent), client(_client)
@ -27,9 +30,9 @@ TabUserLists::TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_clien
connect(client, SIGNAL(addToListEventReceived(Event_AddToList *)), this, SLOT(processAddToListEvent(Event_AddToList *))); connect(client, SIGNAL(addToListEventReceived(Event_AddToList *)), this, SLOT(processAddToListEvent(Event_AddToList *)));
connect(client, SIGNAL(removeFromListEventReceived(Event_RemoveFromList *)), this, SLOT(processRemoveFromListEvent(Event_RemoveFromList *))); connect(client, SIGNAL(removeFromListEventReceived(Event_RemoveFromList *)), this, SLOT(processRemoveFromListEvent(Event_RemoveFromList *)));
Command_ListUsers *cmd = new Command_ListUsers; PendingCommand *pend = client->prepareSessionCommand(Command_ListUsers());
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processListUsersResponse(ProtocolResponse *))); connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processListUsersResponse(ProtocolResponse *)));
client->sendCommand(cmd); client->sendCommand(pend);
QVBoxLayout *vbox = new QVBoxLayout; QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(userInfoBox); vbox->addWidget(userInfoBox);

View file

@ -4,12 +4,14 @@
#include <math.h> #include <math.h>
#include "tablezone.h" #include "tablezone.h"
#include "player.h" #include "player.h"
#include "protocol_items.h"
#include "settingscache.h" #include "settingscache.h"
#include "arrowitem.h" #include "arrowitem.h"
#include "carddragitem.h" #include "carddragitem.h"
#include "carddatabase.h" #include "carddatabase.h"
#include "pb/command_move_card.pb.h"
#include "pb/command_set_card_attr.pb.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)
{ {
@ -93,11 +95,21 @@ void TableZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone
void TableZone::handleDropEventByGrid(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &gridPoint) void TableZone::handleDropEventByGrid(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &gridPoint)
{ {
QList<CardToMove *> idList; Command_MoveCard cmd;
for (int i = 0; i < dragItems.size(); ++i) cmd.set_start_zone(startZone->getName().toStdString());
idList.append(new CardToMove(dragItems[i]->getId(), dragItems[i]->getFaceDown(), startZone->getName() == name ? QString() : dragItems[i]->getItem()->getInfo()->getPowTough())); cmd.set_target_player_id(player->getId());
cmd.set_target_zone(getName().toStdString());
cmd.set_x(gridPoint.x());
cmd.set_y(gridPoint.y());
startZone->getPlayer()->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), idList, player->getId(), getName(), gridPoint.x(), gridPoint.y())); for (int i = 0; i < dragItems.size(); ++i) {
CardToMove *ctm = cmd.mutable_cards_to_move()->add_card();
ctm->set_card_id(dragItems[i]->getId());
ctm->set_face_down(dragItems[i]->getFaceDown());
ctm->set_pt(startZone->getName() == name ? std::string() : dragItems[i]->getItem()->getInfo()->getPowTough().toStdString());
}
startZone->getPlayer()->sendGameCommand(cmd);
} }
void TableZone::reorganizeCards() void TableZone::reorganizeCards()
@ -181,13 +193,19 @@ void TableZone::toggleTapped()
tapAll = true; tapAll = true;
break; break;
} }
QList<Command *> cmdList; QList< const ::google::protobuf::Message * > cmdList;
for (int i = 0; i < selectedItems.size(); i++) { for (int i = 0; i < selectedItems.size(); i++) {
CardItem *temp = qgraphicsitem_cast<CardItem *>(selectedItems[i]); CardItem *temp = qgraphicsitem_cast<CardItem *>(selectedItems[i]);
if (temp->getTapped() != tapAll) if (temp->getTapped() != tapAll) {
cmdList.append(new Command_SetCardAttr(-1, name, temp->getId(), "tapped", tapAll ? "1" : "0")); Command_SetCardAttr *cmd = new Command_SetCardAttr;
cmd->set_zone(name.toStdString());
cmd->set_card_id(temp->getId());
cmd->set_attr_name("tapped");
cmd->set_attr_value(tapAll ? "1" : "0");
cmdList.append(cmd);
}
} }
player->sendCommandContainer(new CommandContainer(cmdList)); player->sendGameCommand(player->prepareGameCommand(cmdList));
} }
CardItem *TableZone::takeCard(int position, int cardId, bool canResize) CardItem *TableZone::takeCard(int position, int cardId, bool canResize)

View file

@ -6,6 +6,9 @@
#include <QLabel> #include <QLabel>
#include <QGridLayout> #include <QGridLayout>
#include "pending_command.h"
#include "pb/session_commands.pb.h"
UserInfoBox::UserInfoBox(AbstractClient *_client, bool _fullInfo, QWidget *parent, Qt::WindowFlags flags) UserInfoBox::UserInfoBox(AbstractClient *_client, bool _fullInfo, QWidget *parent, Qt::WindowFlags flags)
: QWidget(parent, flags), client(_client), fullInfo(_fullInfo) : QWidget(parent, flags), client(_client), fullInfo(_fullInfo)
{ {
@ -80,9 +83,13 @@ void UserInfoBox::updateInfo(ServerInfo_User *user)
void UserInfoBox::updateInfo(const QString &userName) void UserInfoBox::updateInfo(const QString &userName)
{ {
Command_GetUserInfo *command = new Command_GetUserInfo(userName); Command_GetUserInfo cmd;
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processResponse(ProtocolResponse *))); cmd.set_user_name(userName.toStdString());
client->sendCommand(command);
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processResponse(ProtocolResponse *)));
client->sendCommand(pend);
} }
void UserInfoBox::processResponse(ProtocolResponse *r) void UserInfoBox::processResponse(ProtocolResponse *r)

View file

@ -20,6 +20,10 @@
#include <QCheckBox> #include <QCheckBox>
#include <QMessageBox> #include <QMessageBox>
#include "pending_command.h"
#include "pb/session_commands.pb.h"
#include "pb/moderator_commands.pb.h"
BanDialog::BanDialog(ServerInfo_User *info, QWidget *parent) BanDialog::BanDialog(ServerInfo_User *info, QWidget *parent)
: QDialog(parent) : QDialog(parent)
{ {
@ -292,7 +296,7 @@ void UserList::userClicked(QTreeWidgetItem *item, int /*column*/)
void UserList::gamesOfUserReceived(ProtocolResponse *resp) void UserList::gamesOfUserReceived(ProtocolResponse *resp)
{ {
Command_GetGamesOfUser *command = static_cast<Command_GetGamesOfUser *>(sender()); //Command_GetGamesOfUser *command = static_cast<Command_GetGamesOfUser *>(sender());
Response_GetGamesOfUser *response = qobject_cast<Response_GetGamesOfUser *>(resp); Response_GetGamesOfUser *response = qobject_cast<Response_GetGamesOfUser *>(resp);
if (!response) if (!response)
return; return;
@ -314,7 +318,7 @@ void UserList::gamesOfUserReceived(ProtocolResponse *resp)
for (int i = 0; i < gameList.size(); ++i) for (int i = 0; i < gameList.size(); ++i)
selector->processGameInfo(gameList[i]); selector->processGameInfo(gameList[i]);
selector->setWindowTitle(tr("%1's games").arg(command->getUserName())); // selector->setWindowTitle(tr("%1's games").arg(command->getUserName()));
selector->setAttribute(Qt::WA_DeleteOnClose); selector->setAttribute(Qt::WA_DeleteOnClose);
selector->show(); selector->show();
} }
@ -334,7 +338,14 @@ void UserList::banUser_processUserInfoResponse(ProtocolResponse *r)
void UserList::banUser_dialogFinished() void UserList::banUser_dialogFinished()
{ {
BanDialog *dlg = static_cast<BanDialog *>(sender()); BanDialog *dlg = static_cast<BanDialog *>(sender());
client->sendCommand(new Command_BanFromServer(dlg->getBanName(), dlg->getBanIP(), dlg->getMinutes(), dlg->getReason()));
Command_BanFromServer cmd;
cmd.set_user_name(dlg->getBanName().toStdString());
cmd.set_address(dlg->getBanIP().toStdString());
cmd.set_minutes(dlg->getMinutes());
cmd.set_reason(dlg->getReason().toStdString());
client->sendCommand(client->prepareModeratorCommand(cmd));
} }
void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index) void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
@ -390,22 +401,46 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
infoWidget->updateInfo(userName); infoWidget->updateInfo(userName);
} else if (actionClicked == aChat) } else if (actionClicked == aChat)
emit openMessageDialog(userName, true); emit openMessageDialog(userName, true);
else if (actionClicked == aAddToBuddyList) else if (actionClicked == aAddToBuddyList) {
client->sendCommand(new Command_AddToList("buddy", userName)); Command_AddToList cmd;
else if (actionClicked == aRemoveFromBuddyList) cmd.set_list("buddy");
client->sendCommand(new Command_RemoveFromList("buddy", userName)); cmd.set_user_name(userName.toStdString());
else if (actionClicked == aShowGames) {
Command *cmd = new Command_GetGamesOfUser(userName); client->sendCommand(client->prepareSessionCommand(cmd));
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(gamesOfUserReceived(ProtocolResponse *))); } else if (actionClicked == aRemoveFromBuddyList) {
client->sendCommand(cmd); Command_RemoveFromList cmd;
} else if (actionClicked == aAddToIgnoreList) cmd.set_list("buddy");
client->sendCommand(new Command_AddToList("ignore", userName)); cmd.set_user_name(userName.toStdString());
else if (actionClicked == aRemoveFromIgnoreList)
client->sendCommand(new Command_RemoveFromList("ignore", userName)); client->sendCommand(client->prepareSessionCommand(cmd));
else if (actionClicked == aBan) { } else if (actionClicked == aShowGames) {
Command_GetUserInfo *command = new Command_GetUserInfo(userName); Command_GetGamesOfUser cmd;
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(banUser_processUserInfoResponse(ProtocolResponse *))); cmd.set_user_name(userName.toStdString());
client->sendCommand(command);
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(gamesOfUserReceived(ProtocolResponse *)));
client->sendCommand(pend);
} else if (actionClicked == aAddToIgnoreList) {
Command_AddToList cmd;
cmd.set_list("ignore");
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
} else if (actionClicked == aRemoveFromIgnoreList) {
Command_RemoveFromList cmd;
cmd.set_list("ignore");
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
} else if (actionClicked == aBan) {
Command_GetUserInfo cmd;
cmd.set_user_name(userName.toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(banUser_processUserInfoResponse(ProtocolResponse *)));
client->sendCommand(pend);
} }
delete menu; delete menu;

View file

@ -134,8 +134,8 @@ void MainWindow::actSinglePlayer()
} }
tabSupervisor->startLocal(localClients); tabSupervisor->startLocal(localClients);
Command_CreateGame *createCommand = new Command_CreateGame(0, QString(), QString(), numberPlayers, QList<GameTypeId *>(), false, false, false, false); // Command_CreateGame *createCommand = new Command_CreateGame(0, QString(), QString(), numberPlayers, QList<GameTypeId *>(), false, false, false, false);
mainClient->sendCommand(createCommand); // mainClient->sendCommand(createCommand);
} }
void MainWindow::localGameEnded() void MainWindow::localGameEnded()

View file

@ -15,6 +15,9 @@
#include "settingscache.h" #include "settingscache.h"
#include "gamescene.h" #include "gamescene.h"
#include "pb/command_stop_dump_zone.pb.h"
#include "pb/command_shuffle.pb.h"
TitleLabel::TitleLabel() TitleLabel::TitleLabel()
: QGraphicsWidget(), text(" ") : QGraphicsWidget(), text(" ")
{ {
@ -156,11 +159,15 @@ void ZoneViewWidget::resizeToZoneContents()
void ZoneViewWidget::closeEvent(QCloseEvent *event) void ZoneViewWidget::closeEvent(QCloseEvent *event)
{ {
disconnect(zone, SIGNAL(beingDeleted()), this, 0); disconnect(zone, SIGNAL(beingDeleted()), this, 0);
if (zone->getNumberCards() != -2) if (zone->getNumberCards() != -2) {
player->sendGameCommand(new Command_StopDumpZone(-1, player->getId(), zone->getName())); Command_StopDumpZone cmd;
cmd.set_player_id(player->getId());
cmd.set_zone_name(zone->getName().toStdString());
player->sendGameCommand(cmd);
}
if (shuffleCheckBox) if (shuffleCheckBox)
if (shuffleCheckBox->isChecked()) if (shuffleCheckBox->isChecked())
player->sendGameCommand(new Command_Shuffle); player->sendGameCommand(Command_Shuffle());
emit closePressed(this); emit closePressed(this);
deleteLater(); deleteLater();
event->accept(); event->accept();

View file

@ -2,8 +2,13 @@
#include <QDebug> #include <QDebug>
#include "zoneviewzone.h" #include "zoneviewzone.h"
#include "player.h" #include "player.h"
#include "protocol_items.h"
#include "carddragitem.h" #include "carddragitem.h"
#include "protocol_items.h"
#include "protocol_datastructures.h"
#include "pb/command_dump_zone.pb.h"
#include "pb/command_move_card.pb.h"
#include "pending_command.h"
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, bool _revealZone, QGraphicsItem *parent) ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, bool _revealZone, QGraphicsItem *parent)
: SelectZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0), numberCards(_numberCards), origZone(_origZone), revealZone(_revealZone), sortByName(false), sortByType(false) : SelectZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0), numberCards(_numberCards), origZone(_origZone), revealZone(_revealZone), sortByName(false), sortByType(false)
@ -36,9 +41,14 @@ void ZoneViewZone::initializeCards(const QList<ServerInfo_Card *> &cardList)
addCard(new CardItem(player, cardList[i]->getName(), cardList[i]->getId(), revealZone, this), false, i); addCard(new CardItem(player, cardList[i]->getName(), cardList[i]->getId(), revealZone, this), false, i);
reorganizeCards(); reorganizeCards();
} else if (!origZone->contentsKnown()) { } else if (!origZone->contentsKnown()) {
Command_DumpZone *command = new Command_DumpZone(-1, player->getId(), name, numberCards); Command_DumpZone cmd;
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(zoneDumpReceived(ProtocolResponse *))); cmd.set_player_id(player->getId());
player->sendGameCommand(command); cmd.set_zone_name(name.toStdString());
cmd.set_number_cards(numberCards);
PendingCommand *pend = player->prepareGameCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(zoneDumpReceived(ProtocolResponse *)));
player->sendGameCommand(pend);
} else { } else {
const CardList &c = origZone->getCards(); const CardList &c = origZone->getCards();
int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size()); int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size());
@ -126,11 +136,17 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
void ZoneViewZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/) void ZoneViewZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &/*dropPoint*/)
{ {
QList<CardToMove *> idList; Command_MoveCard cmd;
for (int i = 0; i < dragItems.size(); ++i) cmd.set_start_zone(startZone->getName().toStdString());
idList.append(new CardToMove(dragItems[i]->getId())); cmd.set_target_player_id(player->getId());
cmd.set_target_zone(getName().toStdString());
cmd.set_x(0);
cmd.set_y(0);
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), idList, player->getId(), getName(), 0, 0)); for (int i = 0; i < dragItems.size(); ++i)
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
player->sendGameCommand(cmd);
} }
void ZoneViewZone::removeCard(int position) void ZoneViewZone::removeCard(int position)

View file

@ -24,6 +24,14 @@ public:
{ {
return QColor(value / 65536, (value % 65536) / 256, value % 256); return QColor(value / 65536, (value % 65536) / 256, value % 256);
} }
color get_color() const // HACK
{
color c;
c.set_r(value / 65536);
c.set_g((value % 65536) / 256);
c.set_b(value % 256);
return c;
}
#endif #endif
}; };

View file

@ -9,6 +9,8 @@
#include <QSet> #include <QSet>
#include "serializable_item.h" #include "serializable_item.h"
#include "pb/move_card_to_zone.pb.h"
class CardDatabase; class CardDatabase;
class QIODevice; class QIODevice;
class QTextStream; class QTextStream;
@ -25,6 +27,7 @@ public:
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(); }
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(); }
MoveCard_ToZone toPB() { MoveCard_ToZone foo; foo.set_card_name(getCardName().toStdString()); foo.set_start_zone(getStartZone().toStdString()); foo.set_target_zone(getTargetZone().toStdString()); return foo; } // XXX
}; };
class SideboardPlan : public SerializableItem_Map { class SideboardPlan : public SerializableItem_Map {

View file

@ -1,237 +0,0 @@
import "color.proto";
import "move_card_to_zone.proto";
message Command_KickFromGame {
optional sint32 player_id = 1;
}
message Command_LeaveGame {
}
message Command_GameSay {
optional string message = 1;
}
message Command_Shuffle {
}
message Command_Mulligan {
}
message Command_RollDie {
optional uint32 sides = 1;
}
message Command_DrawCards {
optional uint32 number = 1;
}
message Command_UndoDraw {
}
message Command_FlipCard {
optional string zone = 1;
optional sint32 card_id = 2;
optional bool face_down = 3;
}
message Command_AttachCard {
optional string start_zone = 1;
optional sint32 card_id = 2;
optional sint32 target_player_id = 3;
optional string target_zone = 4;
optional sint32 target_card_id = 5;
}
message Command_CreateToken {
optional string zone = 1;
optional string card_name = 2;
optional string color = 3;
optional string pt = 4;
optional string annotation = 5;
optional bool destroy_on_zone_change = 6;
optional sint32 x = 7;
optional sint32 y = 8;
}
message Command_CreateArrow {
optional sint32 start_player_id = 1;
optional string start_zone = 2;
optional sint32 start_card_id = 3;
optional sint32 target_player_id = 4;
optional string target_zone = 5;
optional sint32 target_card_id = 6;
optional color arrow_color = 7;
}
message Command_DeleteArrow {
optional sint32 arrow_id = 1;
}
message Command_SetCardAttr {
optional string zone = 1;
optional sint32 card_id = 2;
optional string attr_name = 3;
optional string attr_value = 4;
}
message Command_SetCardCounter {
optional string zone = 1;
optional sint32 card_id = 2;
optional sint32 counter_id = 3;
optional sint32 counter_value = 4;
}
message Command_IncCardCounter {
optional string zone = 1;
optional sint32 card_id = 2;
optional sint32 counter_id = 3;
optional sint32 counter_delta = 4;
}
message Command_ReadyStart {
optional bool ready = 1;
}
message Command_Concede {
}
message Command_IncCounter {
optional sint32 counter_id = 1;
optional sint32 delta = 2;
}
message Command_CreateCounter {
optional string counter_name = 1;
optional color counter_color = 2;
optional uint32 radius = 3;
optional sint32 value = 4;
}
message Command_SetCounter {
optional sint32 counter_id = 1;
optional sint32 value = 2;
}
message Command_DelCounter {
optional sint32 counter_id = 1;
}
message Command_NextTurn {
}
message Command_SetActivePhase {
optional uint32 phase = 1;
}
message Command_DumpZone {
optional sint32 player_id = 1;
optional string zone_name = 2;
optional sint32 number_cards = 3;
}
message Command_StopDumpZone {
optional sint32 player_id = 1;
optional string zone_name = 2;
}
message Command_RevealCards {
optional string zone_name = 1;
optional sint32 card_id = 2;
optional sint32 player_id = 3;
}
message CardToMove {
optional sint32 card_id = 1;
optional bool face_down = 2;
optional string pt = 3;
optional bool tapped = 4;
}
message Command_MoveCard {
optional string start_zone = 1;
repeated CardToMove cards_to_move = 2;
optional sint32 target_player_id = 3;
optional string target_zone = 4;
optional sint32 x = 5;
optional sint32 y = 6;
}
message Command_SetSideboardPlan {
repeated MoveCard_ToZone move_list = 1;
}
message Command_DeckSelect {
optional string deck = 1;
optional sint32 deck_id = 2;
}
message GameCommand {
enum GameCommandType {
KICK_FROM_GAME = 1000;
LEAVE_GAME = 1001;
GAME_SAY = 1002;
SHUFFLE = 1003;
MULLIGAN = 1004;
ROLL_DIE = 1005;
DRAW_CARDS = 1006;
UNDO_DRAW = 1007;
FLIP_CARD = 1008;
ATTACH_CARD = 1009;
CREATE_TOKEN = 1010;
CREATE_ARROW = 1011;
DELETE_ARROW = 1012;
SET_CARD_ATTR = 1013;
SET_CARD_COUNTER = 1014;
INC_CARD_COUNTER = 1015;
READY_START = 1016;
CONCEDE = 1017;
INC_COUNTER = 1018;
CREATE_COUNTER = 1019;
SET_COUNTER = 1020;
DEL_COUNTER = 1021;
NEXT_TURN = 1022;
SET_ACTIVE_PHASE = 1023;
DUMP_ZONE = 1024;
STOP_DUMP_ZONE = 1025;
REVEAL_CARDS = 1026;
MOVE_CARD = 1027;
SET_SIDEBOARD_PLAN = 1028;
DECK_SELECT = 1029;
}
extensions 100 to max;
}
extend GameCommand {
optional Command_KickFromGame command_kick_from_game = 1000;
optional Command_LeaveGame command_leave_game = 1001;
optional Command_GameSay command_game_say = 1002;
optional Command_Shuffle command_shuffle = 1003;
optional Command_Mulligan command_mulligan = 1004;
optional Command_RollDie command_roll_die = 1005;
optional Command_DrawCards command_draw_cards = 1006;
optional Command_UndoDraw command_undo_draw = 1007;
optional Command_FlipCard command_flip_card = 1008;
optional Command_AttachCard command_attach_card = 1009;
optional Command_CreateToken command_create_token = 1010;
optional Command_CreateArrow command_create_arrow = 1011;
optional Command_DeleteArrow command_delete_arrow = 1012;
optional Command_SetCardAttr command_set_card_attr = 1013;
optional Command_SetCardCounter command_set_card_counter = 1014;
optional Command_IncCardCounter command_inc_card_counter = 1015;
optional Command_ReadyStart command_ready_start = 1016;
optional Command_Concede command_concede = 1017;
optional Command_IncCounter command_inc_counter = 1018;
optional Command_CreateCounter command_create_counter = 1019;
optional Command_SetCounter command_set_counter = 1020;
optional Command_DelCounter command_del_counter = 1021;
optional Command_NextTurn command_next_turn = 1022;
optional Command_SetActivePhase command_set_active_phase = 1023;
optional Command_DumpZone command_dump_zone = 1024;
optional Command_StopDumpZone command_stop_dump_zone = 1025;
optional Command_RevealCards command_reveal_cards = 1026;
optional Command_MoveCard command_move_card = 1027;
optional Command_SetSideboardPlan command_set_sideboard_plan = 1028;
optional Command_DeckSelect command_deck_select = 1029;
}

View file

@ -0,0 +1,5 @@
[Dolphin]
AdditionalInfoV2=Details_Size,Details_Date,CustomizedDetails
Timestamp=2011,12,18,12,16,39
Version=2
ViewMode=1

View file

@ -1,11 +1,3 @@
message Command_UpdateServerMessage {
}
message Command_ShutdownServer {
optional string reason = 1;
optional uint32 minutes = 2;
}
message AdminCommand { message AdminCommand {
enum AdminCommandType { enum AdminCommandType {
UPDATE_SERVER_MESSAGE = 1000; UPDATE_SERVER_MESSAGE = 1000;
@ -14,8 +6,16 @@ message AdminCommand {
extensions 100 to max; extensions 100 to max;
} }
extend AdminCommand { message Command_UpdateServerMessage {
optional Command_UpdateServerMessage command_update_server_message = 1000; extend AdminCommand {
optional Command_ShutdownServer command_shutdown_server = 1001; optional Command_UpdateServerMessage ext = 1000;
}
} }
message Command_ShutdownServer {
extend AdminCommand {
optional Command_ShutdownServer ext = 1001;
}
optional string reason = 1;
optional uint32 minutes = 2;
}

View file

@ -0,0 +1,13 @@
import "game_commands.proto";
message Command_AttachCard {
extend GameCommand {
optional Command_AttachCard ext = 1009;
}
optional string start_zone = 1;
optional sint32 card_id = 2;
optional sint32 target_player_id = 3;
optional string target_zone = 4;
optional sint32 target_card_id = 5;
}

View file

@ -0,0 +1,6 @@
import "game_commands.proto";
message Command_Concede {
extend GameCommand {
optional Command_Concede ext = 1017;
}
}

View file

@ -0,0 +1,17 @@
import "game_commands.proto";
import "color.proto";
message Command_CreateArrow {
extend GameCommand {
optional Command_CreateArrow ext = 1011;
}
optional sint32 start_player_id = 1;
optional string start_zone = 2;
optional sint32 start_card_id = 3;
optional sint32 target_player_id = 4;
optional string target_zone = 5;
optional sint32 target_card_id = 6;
optional color arrow_color = 7;
}

View file

@ -0,0 +1,12 @@
import "game_commands.proto";
import "color.proto";
message Command_CreateCounter {
extend GameCommand {
optional Command_CreateCounter ext = 1019;
}
optional string counter_name = 1;
optional color counter_color = 2;
optional uint32 radius = 3;
optional sint32 value = 4;
}

View file

@ -0,0 +1,16 @@
import "game_commands.proto";
message Command_CreateToken {
extend GameCommand {
optional Command_CreateToken ext = 1010;
}
optional string zone = 1;
optional string card_name = 2;
optional string color = 3;
optional string pt = 4;
optional string annotation = 5;
optional bool destroy_on_zone_change = 6;
optional sint32 x = 7;
optional sint32 y = 8;
}

View file

@ -0,0 +1,8 @@
import "session_commands.proto";
message Command_DeckDel {
extend SessionCommand {
optional Command_DeckDel ext = 1011;
}
optional uint32 deck_id = 1;
}

View file

@ -0,0 +1,9 @@
import "session_commands.proto";
message Command_DeckDelDir {
extend SessionCommand {
optional Command_DeckDelDir ext = 1010;
}
optional string path = 1;
}

View file

@ -0,0 +1,9 @@
import "session_commands.proto";
message Command_DeckDownload {
extend SessionCommand {
optional Command_DeckDownload ext = 1012;
}
optional uint32 deck_id = 1;
}

View file

@ -0,0 +1,10 @@
import "session_commands.proto";
message Command_DeckNewDir {
extend SessionCommand {
optional Command_DeckNewDir ext = 1009;
}
optional string path = 1;
optional string dir_name = 2;
}

View file

@ -0,0 +1,8 @@
import "game_commands.proto";
message Command_DeckSelect {
extend GameCommand {
optional Command_DeckSelect ext = 1029;
}
optional string deck = 1;
optional sint32 deck_id = 2;
}

View file

@ -0,0 +1,10 @@
import "session_commands.proto";
message Command_DeckUpload {
extend SessionCommand {
optional Command_DeckUpload ext = 1013;
}
optional string path = 1;
optional string deck_list = 2;
}

View file

@ -0,0 +1,7 @@
import "game_commands.proto";
message Command_DelCounter {
extend GameCommand {
optional Command_DelCounter ext = 1021;
}
optional sint32 counter_id = 1;
}

View file

@ -0,0 +1,7 @@
import "game_commands.proto";
message Command_DeleteArrow {
extend GameCommand {
optional Command_DeleteArrow ext = 1012;
}
optional sint32 arrow_id = 1;
}

View file

@ -0,0 +1,8 @@
import "game_commands.proto";
message Command_DrawCards {
extend GameCommand {
optional Command_DrawCards ext = 1006;
}
optional uint32 number = 1;
}

View file

@ -0,0 +1,9 @@
import "game_commands.proto";
message Command_DumpZone {
extend GameCommand {
optional Command_DumpZone ext = 1024;
}
optional sint32 player_id = 1;
optional string zone_name = 2;
optional sint32 number_cards = 3;
}

View file

@ -0,0 +1,11 @@
import "game_commands.proto";
message Command_FlipCard {
extend GameCommand {
optional Command_FlipCard ext = 1008;
}
optional string zone = 1;
optional sint32 card_id = 2;
optional bool face_down = 3;
}

View file

@ -0,0 +1,9 @@
import "game_commands.proto";
message Command_GameSay {
extend GameCommand {
optional Command_GameSay ext = 1002;
}
optional string message = 1;
}

View file

@ -0,0 +1,10 @@
import "game_commands.proto";
message Command_IncCardCounter {
extend GameCommand {
optional Command_IncCardCounter ext = 1015;
}
optional string zone = 1;
optional sint32 card_id = 2;
optional sint32 counter_id = 3;
optional sint32 counter_delta = 4;
}

View file

@ -0,0 +1,8 @@
import "game_commands.proto";
message Command_IncCounter {
extend GameCommand {
optional Command_IncCounter ext = 1018;
}
optional sint32 counter_id = 1;
optional sint32 delta = 2;
}

View file

@ -0,0 +1,8 @@
import "game_commands.proto";
message Command_KickFromGame {
extend GameCommand {
optional Command_KickFromGame ext = 1000;
}
optional sint32 player_id = 1;
}

View file

@ -0,0 +1,7 @@
import "game_commands.proto";
message Command_LeaveGame {
extend GameCommand {
optional Command_LeaveGame ext = 1001;
}
}

View file

@ -0,0 +1,24 @@
import "game_commands.proto";
message CardToMove {
optional sint32 card_id = 1;
optional bool face_down = 2;
optional string pt = 3;
optional bool tapped = 4;
}
message ListOfCardsToMove {
repeated CardToMove card = 1;
}
message Command_MoveCard {
extend GameCommand {
optional Command_MoveCard ext = 1027;
}
optional string start_zone = 1;
optional ListOfCardsToMove cards_to_move = 2;
optional sint32 target_player_id = 3;
optional string target_zone = 4;
optional sint32 x = 5;
optional sint32 y = 6;
}

View file

@ -0,0 +1,8 @@
import "game_commands.proto";
message Command_Mulligan {
extend GameCommand {
optional Command_Mulligan ext = 1004;
}
}

View file

@ -0,0 +1,6 @@
import "game_commands.proto";
message Command_NextTurn {
extend GameCommand {
optional Command_NextTurn ext = 1022;
}
}

View file

@ -0,0 +1,7 @@
import "game_commands.proto";
message Command_ReadyStart {
extend GameCommand {
optional Command_ReadyStart ext = 1016;
}
optional bool ready = 1;
}

View file

@ -0,0 +1,9 @@
import "game_commands.proto";
message Command_RevealCards {
extend GameCommand {
optional Command_RevealCards ext = 1026;
}
optional string zone_name = 1;
optional sint32 card_id = 2;
optional sint32 player_id = 3;
}

View file

@ -0,0 +1,8 @@
import "game_commands.proto";
message Command_RollDie {
extend GameCommand {
optional Command_RollDie ext = 1005;
}
optional uint32 sides = 1;
}

View file

@ -0,0 +1,7 @@
import "game_commands.proto";
message Command_SetActivePhase {
extend GameCommand {
optional Command_SetActivePhase ext = 1023;
}
optional uint32 phase = 1;
}

View file

@ -0,0 +1,10 @@
import "game_commands.proto";
message Command_SetCardAttr {
extend GameCommand {
optional Command_SetCardAttr ext = 1013;
}
optional string zone = 1;
optional sint32 card_id = 2;
optional string attr_name = 3;
optional string attr_value = 4;
}

View file

@ -0,0 +1,10 @@
import "game_commands.proto";
message Command_SetCardCounter {
extend GameCommand {
optional Command_SetCardCounter ext = 1014;
}
optional string zone = 1;
optional sint32 card_id = 2;
optional sint32 counter_id = 3;
optional sint32 counter_value = 4;
}

View file

@ -0,0 +1,8 @@
import "game_commands.proto";
message Command_SetCounter {
extend GameCommand {
optional Command_SetCounter ext = 1020;
}
optional sint32 counter_id = 1;
optional sint32 value = 2;
}

View file

@ -0,0 +1,10 @@
import "game_commands.proto";
import "move_card_to_zone.proto";
message Command_SetSideboardPlan {
extend GameCommand {
optional Command_SetSideboardPlan ext = 1028;
}
repeated MoveCard_ToZone move_list = 1;
}

View file

@ -0,0 +1,7 @@
import "game_commands.proto";
message Command_Shuffle {
extend GameCommand {
optional Command_Shuffle ext = 1003;
}
}

View file

@ -0,0 +1,8 @@
import "game_commands.proto";
message Command_StopDumpZone {
extend GameCommand {
optional Command_StopDumpZone ext = 1025;
}
optional sint32 player_id = 1;
optional string zone_name = 2;
}

View file

@ -0,0 +1,6 @@
import "game_commands.proto";
message Command_UndoDraw {
extend GameCommand {
optional Command_UndoDraw ext = 1007;
}
}

View file

@ -5,13 +5,6 @@ import "moderator_commands.proto";
import "admin_commands.proto"; import "admin_commands.proto";
message CommandContainer { message CommandContainer {
enum CommandType {
SESSION = 0;
GAME = 1;
ROOM = 2;
MODERATOR = 3;
ADMIN = 4;
}
required uint64 cmd_id = 1; required uint64 cmd_id = 1;
optional uint32 game_id = 10; optional uint32 game_id = 10;

View file

@ -0,0 +1,35 @@
message GameCommand {
enum GameCommandType {
KICK_FROM_GAME = 1000;
LEAVE_GAME = 1001;
GAME_SAY = 1002;
SHUFFLE = 1003;
MULLIGAN = 1004;
ROLL_DIE = 1005;
DRAW_CARDS = 1006;
UNDO_DRAW = 1007;
FLIP_CARD = 1008;
ATTACH_CARD = 1009;
CREATE_TOKEN = 1010;
CREATE_ARROW = 1011;
DELETE_ARROW = 1012;
SET_CARD_ATTR = 1013;
SET_CARD_COUNTER = 1014;
INC_CARD_COUNTER = 1015;
READY_START = 1016;
CONCEDE = 1017;
INC_COUNTER = 1018;
CREATE_COUNTER = 1019;
SET_COUNTER = 1020;
DEL_COUNTER = 1021;
NEXT_TURN = 1022;
SET_ACTIVE_PHASE = 1023;
DUMP_ZONE = 1024;
STOP_DUMP_ZONE = 1025;
REVEAL_CARDS = 1026;
MOVE_CARD = 1027;
SET_SIDEBOARD_PLAN = 1028;
DECK_SELECT = 1029;
}
extensions 100 to max;
}

View file

@ -1,12 +1,3 @@
message Command_BanFromServer {
optional string user_name = 1;
optional string address = 2;
optional uint32 minutes = 3;
optional string reason = 4;
}
message ModeratorCommand { message ModeratorCommand {
enum ModeratorCommandType { enum ModeratorCommandType {
BAN_FROM_SERVER = 1000; BAN_FROM_SERVER = 1000;
@ -14,7 +5,12 @@ message ModeratorCommand {
extensions 100 to max; extensions 100 to max;
} }
extend ModeratorCommand { message Command_BanFromServer {
optional Command_BanFromServer command_ban_from_server = 1000; extend ModeratorCommand {
optional Command_BanFromServer ext = 1000;
}
optional string user_name = 1;
optional string address = 2;
optional uint32 minutes = 3;
optional string reason = 4;
} }

View file

@ -1,12 +1,30 @@
message RoomCommand {
enum RoomCommandType {
LEAVE_ROOM = 1000;
ROOM_SAY = 1001;
CREATE_GAME = 1002;
JOIN_GAME = 1003;
}
extensions 100 to max;
}
message Command_LeaveRoom { message Command_LeaveRoom {
extend RoomCommand {
optional Command_LeaveRoom ext = 1000;
}
} }
message Command_RoomSay { message Command_RoomSay {
extend RoomCommand {
optional Command_RoomSay ext = 1001;
}
optional string message = 1; optional string message = 1;
} }
message Command_CreateGame { message Command_CreateGame {
extend RoomCommand {
optional Command_CreateGame ext = 1002;
}
optional string description = 1; optional string description = 1;
optional string password = 2; optional string password = 2;
optional uint32 max_players = 3; optional uint32 max_players = 3;
@ -20,27 +38,11 @@ message Command_CreateGame {
} }
message Command_JoinGame { message Command_JoinGame {
extend RoomCommand {
optional Command_JoinGame ext = 1003;
}
optional uint32 game_id = 1; optional uint32 game_id = 1;
optional string password = 2; optional string password = 2;
optional bool spectator = 3; optional bool spectator = 3;
optional bool override_restrictions = 4; optional bool override_restrictions = 4;
} }
message RoomCommand {
enum RoomCommandType {
LEAVE_ROOM = 1000;
ROOM_SAY = 1001;
CREATE_GAME = 1002;
JOIN_GAME = 1003;
}
extensions 100 to max;
}
extend RoomCommand {
optional Command_LeaveRoom command_leave_room = 1000;
optional Command_RoomSay command_room_say = 1001;
optional Command_CreateGame command_create_game = 1002;
optional Command_JoinGame command_join_game = 1003;
}

View file

@ -0,0 +1,98 @@
message SessionCommand {
enum SessionCommandType {
PING = 1000;
LOGIN = 1001;
MESSAGE = 1002;
LIST_USERS = 1003;
GET_GAMES_OF_USER = 1004;
GET_USER_INFO = 1005;
ADD_TO_LIST = 1006;
REMOVE_FROM_LIST = 1007;
DECK_LIST = 1008;
DECK_NEW_DIR = 1009;
DECK_DEL_DIR = 1010;
DECK_DEL = 1011;
DECK_DOWNLOAD = 1012;
DECK_UPLOAD = 1013;
LIST_ROOMS = 1014;
JOIN_ROOM = 1015;
}
extensions 100 to max;
}
message Command_Ping {
extend SessionCommand {
optional Command_Ping ext = 1000;
}
}
message Command_Login {
extend SessionCommand {
optional Command_Login ext = 1001;
}
optional string user_name = 1;
optional string password = 2;
}
message Command_Message {
extend SessionCommand {
optional Command_Message ext = 1002;
}
optional string user_name = 1;
optional string message = 2;
}
message Command_ListUsers {
extend SessionCommand {
optional Command_ListUsers ext = 1003;
}
}
message Command_GetGamesOfUser {
extend SessionCommand {
optional Command_GetGamesOfUser ext = 1004;
}
optional string user_name = 1;
}
message Command_GetUserInfo {
extend SessionCommand {
optional Command_GetUserInfo ext = 1005;
}
optional string user_name = 1;
}
message Command_AddToList {
extend SessionCommand {
optional Command_AddToList ext = 1006;
}
optional string list = 1;
optional string user_name = 2;
}
message Command_RemoveFromList {
extend SessionCommand {
optional Command_RemoveFromList ext = 1007;
}
optional string list = 1;
optional string user_name = 2;
}
message Command_DeckList {
extend SessionCommand {
optional Command_DeckList ext = 1008;
}
}
message Command_ListRooms {
extend SessionCommand {
optional Command_ListRooms ext = 1014;
}
}
message Command_JoinRoom {
extend SessionCommand {
optional Command_JoinRoom ext = 1015;
}
optional uint32 room_id = 1;
}

View file

@ -1,107 +0,0 @@
message Command_Ping {
}
message Command_Login {
optional string user_name = 1;
optional string password = 2;
}
message Command_Message {
optional string user_name = 1;
optional string message = 2;
}
message Command_ListUsers {
}
message Command_GetGamesOfUser {
optional string user_name = 1;
}
message Command_GetUserInfo {
optional string user_name = 1;
}
message Command_AddToList {
optional string list = 1;
optional string user_name = 2;
}
message Command_RemoveFromList {
optional string list = 1;
optional string user_name = 2;
}
message Command_DeckList {
}
message Command_DeckNewDir {
optional string path = 1;
optional string dir_name = 2;
}
message Command_DeckDelDir {
optional string path = 1;
}
message Command_DeckDel {
optional uint32 deck_id = 1;
}
message Command_DeckDownload {
optional uint32 deck_id = 1;
}
message Command_DeckUpload {
optional string path = 1;
optional string deck_list = 2;
}
message Command_ListRooms {
}
message Command_JoinRoom {
optional uint32 room_id = 1;
}
message SessionCommand {
enum SessionCommandType {
PING = 1000;
LOGIN = 1001;
MESSAGE = 1002;
LIST_USERS = 1003;
GET_GAMES_OF_USER = 1004;
GET_USER_INFO = 1005;
ADD_TO_LIST = 1006;
REMOVE_FROM_LIST = 1007;
DECK_LIST = 1008;
DECK_NEW_DIR = 1009;
DECK_DEL_DIR = 1010;
DECK_DEL = 1011;
DECK_DOWNLOAD = 1012;
DECK_UPLOAD = 1013;
LIST_ROOMS = 1014;
JOIN_ROOM = 1015;
}
extensions 100 to max;
}
extend SessionCommand {
optional Command_Ping command_ping = 1000;
optional Command_Login command_login = 1001;
optional Command_Message command_message = 1002;
optional Command_ListUsers command_list_users = 1003;
optional Command_GetGamesOfUser command_get_games_of_user = 1004;
optional Command_GetUserInfo command_get_user_info = 1005;
optional Command_AddToList command_add_to_list = 1006;
optional Command_RemoveFromList command_remove_from_list = 1007;
optional Command_DeckList command_deck_list = 1008;
optional Command_DeckNewDir command_deck_new_dir = 1009;
optional Command_DeckDelDir command_deck_del_dir = 1010;
optional Command_DeckDel command_deck_del = 1011;
optional Command_DeckDownload command_deck_download = 1012;
optional Command_DeckUpload command_deck_upload = 1013;
optional Command_ListRooms command_list_rooms = 1014;
optional Command_JoinRoom command_join_room = 1015;
}

View file

@ -30,10 +30,10 @@ void ProtocolItem::initializeHash()
registerSerializableItem("directory", DeckList_Directory::newItem); registerSerializableItem("directory", DeckList_Directory::newItem);
// registerSerializableItem("card_to_move", CardToMove::newItem); // registerSerializableItem("card_to_move", CardToMove::newItem);
registerSerializableItem("game_type_id", GameTypeId::newItem); registerSerializableItem("game_type_id", GameTypeId::newItem);
/*
registerSerializableItem("containercmd", CommandContainer::newItem);
registerSerializableItem("containergame_event", GameEventContainer::newItem);
// registerSerializableItem("containercmd", CommandContainer::newItem);
registerSerializableItem("containergame_event", GameEventContainer::newItem);
/*
registerSerializableItem("cmdcreate_game", Command_CreateGame::newItem); registerSerializableItem("cmdcreate_game", Command_CreateGame::newItem);
registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem); registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem);
registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem); registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem);

View file

@ -24,7 +24,7 @@
#include <QSet> #include <QSet>
#include <QDebug> #include <QDebug>
#include "server_game.h" #include "server_game.h"
#include "pb/game_commands.pb.h" #include "pb/command_move_card.pb.h"
Server_CardZone::Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ZoneType _type) Server_CardZone::Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ZoneType _type)
: player(_player), name(_name), has_coords(_has_coords), type(_type), cardsBeingLookedAt(0) : player(_player), name(_name), has_coords(_has_coords), type(_type), cardsBeingLookedAt(0)

View file

@ -8,7 +8,7 @@
#include "protocol.h" #include "protocol.h"
#include "protocol_items.h" #include "protocol_items.h"
#include "decklist.h" #include "decklist.h"
#include "pb/game_commands.pb.h" #include "pb/command_move_card.pb.h"
#include <QDebug> #include <QDebug>
Server_Player::Server_Player(Server_Game *_game, int _playerId, ServerInfo_User *_userInfo, bool _spectator, Server_ProtocolHandler *_handler) Server_Player::Server_Player(Server_Game *_game, int _playerId, ServerInfo_User *_userInfo, bool _spectator, Server_ProtocolHandler *_handler)

View file

@ -13,6 +13,41 @@
#include "decklist.h" #include "decklist.h"
#include <QDateTime> #include <QDateTime>
#include "pb/commands.pb.h" #include "pb/commands.pb.h"
#include "pb/command_attach_card.pb.h"
#include "pb/command_concede.pb.h"
#include "pb/command_create_arrow.pb.h"
#include "pb/command_create_counter.pb.h"
#include "pb/command_create_token.pb.h"
#include "pb/command_deck_select.pb.h"
#include "pb/command_del_counter.pb.h"
#include "pb/command_delete_arrow.pb.h"
#include "pb/command_draw_cards.pb.h"
#include "pb/command_dump_zone.pb.h"
#include "pb/command_flip_card.pb.h"
#include "pb/command_game_say.pb.h"
#include "pb/command_inc_card_counter.pb.h"
#include "pb/command_inc_counter.pb.h"
#include "pb/command_kick_from_game.pb.h"
#include "pb/command_leave_game.pb.h"
#include "pb/command_move_card.pb.h"
#include "pb/command_mulligan.pb.h"
#include "pb/command_next_turn.pb.h"
#include "pb/command_ready_start.pb.h"
#include "pb/command_reveal_cards.pb.h"
#include "pb/command_roll_die.pb.h"
#include "pb/command_set_active_phase.pb.h"
#include "pb/command_set_card_attr.pb.h"
#include "pb/command_set_card_counter.pb.h"
#include "pb/command_set_counter.pb.h"
#include "pb/command_set_sideboard_plan.pb.h"
#include "pb/command_shuffle.pb.h"
#include "pb/command_stop_dump_zone.pb.h"
#include "pb/command_undo_draw.pb.h"
#include "pb/command_deck_upload.pb.h"
#include "pb/command_deck_download.pb.h"
#include "pb/command_deck_new_dir.pb.h"
#include "pb/command_deck_del_dir.pb.h"
#include "pb/command_deck_del.pb.h"
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent) Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent)
@ -76,33 +111,33 @@ ResponseCode Server_ProtocolHandler::processSessionCommandContainer(CommandConta
{ {
ResponseCode finalResponseCode = RespOk; ResponseCode finalResponseCode = RespOk;
for (int i = cont->session_command_size() - 1; i >= 0; --i) { for (int i = cont->session_command_size() - 1; i >= 0; --i) {
ResponseCode resp; ResponseCode resp = RespInvalidCommand;
const SessionCommand &sc = cont->session_command(i); const SessionCommand &sc = cont->session_command(i);
std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; std::vector< const ::google::protobuf::FieldDescriptor * > fieldList;
sc.GetReflection()->ListFields(sc, &fieldList); sc.GetReflection()->ListFields(sc, &fieldList);
int num = 0; int num = 0;
for (unsigned int j = 0; j < fieldList.size(); ++j) for (unsigned int j = 0; j < fieldList.size(); ++j)
if (fieldList[j]->number() >= 100) { if (fieldList[j]->is_extension()) {
num = fieldList[j]->number(); num = fieldList[j]->number();
break; break;
} }
switch ((SessionCommand::SessionCommandType) num) { switch ((SessionCommand::SessionCommandType) num) {
case SessionCommand::PING: resp = cmdPing(sc.GetExtension(command_ping), cont); break; case SessionCommand::PING: resp = cmdPing(sc.GetExtension(Command_Ping::ext), cont); break;
case SessionCommand::LOGIN: resp = cmdLogin(sc.GetExtension(command_login), cont, bla); break; case SessionCommand::LOGIN: resp = cmdLogin(sc.GetExtension(Command_Login::ext), cont, bla); break;
case SessionCommand::MESSAGE: resp = cmdMessage(sc.GetExtension(command_message), cont, bla); break; case SessionCommand::MESSAGE: resp = cmdMessage(sc.GetExtension(Command_Message::ext), cont, bla); break;
case SessionCommand::ADD_TO_LIST: resp = cmdAddToList(sc.GetExtension(command_add_to_list), cont); break; case SessionCommand::ADD_TO_LIST: resp = cmdAddToList(sc.GetExtension(Command_AddToList::ext), cont); break;
case SessionCommand::REMOVE_FROM_LIST: resp = cmdRemoveFromList(sc.GetExtension(command_remove_from_list), cont); break; case SessionCommand::REMOVE_FROM_LIST: resp = cmdRemoveFromList(sc.GetExtension(Command_RemoveFromList::ext), cont); break;
case SessionCommand::DECK_LIST: resp = cmdDeckList(sc.GetExtension(command_deck_list), cont); break; case SessionCommand::DECK_LIST: resp = cmdDeckList(sc.GetExtension(Command_DeckList::ext), cont); break;
case SessionCommand::DECK_NEW_DIR: resp = cmdDeckNewDir(sc.GetExtension(command_deck_new_dir), cont); break; case SessionCommand::DECK_NEW_DIR: resp = cmdDeckNewDir(sc.GetExtension(Command_DeckNewDir::ext), cont); break;
case SessionCommand::DECK_DEL_DIR: resp = cmdDeckDelDir(sc.GetExtension(command_deck_del_dir), cont); break; case SessionCommand::DECK_DEL_DIR: resp = cmdDeckDelDir(sc.GetExtension(Command_DeckDelDir::ext), cont); break;
case SessionCommand::DECK_DEL: resp = cmdDeckDel(sc.GetExtension(command_deck_del), cont); break; case SessionCommand::DECK_DEL: resp = cmdDeckDel(sc.GetExtension(Command_DeckDel::ext), cont); break;
case SessionCommand::DECK_UPLOAD: resp = cmdDeckUpload(sc.GetExtension(command_deck_upload), cont); break; case SessionCommand::DECK_UPLOAD: resp = cmdDeckUpload(sc.GetExtension(Command_DeckUpload::ext), cont); break;
case SessionCommand::DECK_DOWNLOAD: resp = cmdDeckDownload(sc.GetExtension(command_deck_download), cont); break; case SessionCommand::DECK_DOWNLOAD: resp = cmdDeckDownload(sc.GetExtension(Command_DeckDownload::ext), cont); break;
case SessionCommand::GET_GAMES_OF_USER: resp = cmdGetGamesOfUser(sc.GetExtension(command_get_games_of_user), cont, bla); break; case SessionCommand::GET_GAMES_OF_USER: resp = cmdGetGamesOfUser(sc.GetExtension(Command_GetGamesOfUser::ext), cont, bla); break;
case SessionCommand::GET_USER_INFO: resp = cmdGetUserInfo(sc.GetExtension(command_get_user_info), cont, bla); break; case SessionCommand::GET_USER_INFO: resp = cmdGetUserInfo(sc.GetExtension(Command_GetUserInfo::ext), cont, bla); break;
case SessionCommand::LIST_ROOMS: resp = cmdListRooms(sc.GetExtension(command_list_rooms), cont, bla); break; case SessionCommand::LIST_ROOMS: resp = cmdListRooms(sc.GetExtension(Command_ListRooms::ext), cont, bla); break;
case SessionCommand::JOIN_ROOM: resp = cmdJoinRoom(sc.GetExtension(command_join_room), cont, bla); break; case SessionCommand::JOIN_ROOM: resp = cmdJoinRoom(sc.GetExtension(Command_JoinRoom::ext), cont, bla); break;
case SessionCommand::LIST_USERS: resp = cmdListUsers(sc.GetExtension(command_list_users), cont, bla); break; case SessionCommand::LIST_USERS: resp = cmdListUsers(sc.GetExtension(Command_ListUsers::ext), cont, bla); break;
} }
if ((resp != RespOk) && (resp != RespNothing)) if ((resp != RespOk) && (resp != RespNothing))
finalResponseCode = resp; finalResponseCode = resp;
@ -123,21 +158,21 @@ ResponseCode Server_ProtocolHandler::processRoomCommandContainer(CommandContaine
ResponseCode finalResponseCode = RespOk; ResponseCode finalResponseCode = RespOk;
for (int i = cont->room_command_size() - 1; i >= 0; --i) { for (int i = cont->room_command_size() - 1; i >= 0; --i) {
ResponseCode resp; ResponseCode resp = RespInvalidCommand;
const RoomCommand &sc = cont->room_command(i); const RoomCommand &sc = cont->room_command(i);
std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; std::vector< const ::google::protobuf::FieldDescriptor * > fieldList;
sc.GetReflection()->ListFields(sc, &fieldList); sc.GetReflection()->ListFields(sc, &fieldList);
int num = 0; int num = 0;
for (unsigned int j = 0; j < fieldList.size(); ++j) for (unsigned int j = 0; j < fieldList.size(); ++j)
if (fieldList[j]->number() >= 100) { if (fieldList[j]->is_extension()) {
num = fieldList[j]->number(); num = fieldList[j]->number();
break; break;
} }
switch ((RoomCommand::RoomCommandType) num) { switch ((RoomCommand::RoomCommandType) num) {
case RoomCommand::LEAVE_ROOM: resp = cmdLeaveRoom(sc.GetExtension(command_leave_room), cont, room); break; case RoomCommand::LEAVE_ROOM: resp = cmdLeaveRoom(sc.GetExtension(Command_LeaveRoom::ext), cont, room); break;
case RoomCommand::ROOM_SAY: resp = cmdRoomSay(sc.GetExtension(command_room_say), cont, room); break; case RoomCommand::ROOM_SAY: resp = cmdRoomSay(sc.GetExtension(Command_RoomSay::ext), cont, room); break;
case RoomCommand::CREATE_GAME: resp = cmdCreateGame(sc.GetExtension(command_create_game), cont, room); break; case RoomCommand::CREATE_GAME: resp = cmdCreateGame(sc.GetExtension(Command_CreateGame::ext), cont, room); break;
case RoomCommand::JOIN_GAME: resp = cmdJoinGame(sc.GetExtension(command_join_game), cont, room); break; case RoomCommand::JOIN_GAME: resp = cmdJoinGame(sc.GetExtension(Command_JoinGame::ext), cont, room); break;
} }
if ((resp != RespOk) && (resp != RespNothing)) if ((resp != RespOk) && (resp != RespNothing))
finalResponseCode = resp; finalResponseCode = resp;
@ -164,47 +199,47 @@ ResponseCode Server_ProtocolHandler::processGameCommandContainer(CommandContaine
ResponseCode finalResponseCode = RespOk; ResponseCode finalResponseCode = RespOk;
for (int i = cont->game_command_size() - 1; i >= 0; --i) { for (int i = cont->game_command_size() - 1; i >= 0; --i) {
ResponseCode resp; ResponseCode resp = RespInvalidCommand;
const GameCommand &sc = cont->game_command(i); const GameCommand &sc = cont->game_command(i);
std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; std::vector< const ::google::protobuf::FieldDescriptor * > fieldList;
sc.GetReflection()->ListFields(sc, &fieldList); sc.GetReflection()->ListFields(sc, &fieldList);
int num = 0; int num = 0;
for (unsigned int j = 0; j < fieldList.size(); ++j) for (unsigned int j = 0; j < fieldList.size(); ++j)
if (fieldList[j]->number() >= 100) { if (fieldList[j]->is_extension()) {
num = fieldList[j]->number(); num = fieldList[j]->number();
break; break;
} }
switch ((GameCommand::GameCommandType) num) { switch ((GameCommand::GameCommandType) num) {
case GameCommand::KICK_FROM_GAME: resp = cmdKickFromGame(sc.GetExtension(command_kick_from_game), cont, game, player, bla); break; case GameCommand::KICK_FROM_GAME: resp = cmdKickFromGame(sc.GetExtension(Command_KickFromGame::ext), cont, game, player, bla); break;
case GameCommand::LEAVE_GAME: resp = cmdLeaveGame(sc.GetExtension(command_leave_game), cont, game, player, bla); break; case GameCommand::LEAVE_GAME: resp = cmdLeaveGame(sc.GetExtension(Command_LeaveGame::ext), cont, game, player, bla); break;
case GameCommand::GAME_SAY: resp = cmdGameSay(sc.GetExtension(command_game_say), cont, game, player, bla); break; case GameCommand::GAME_SAY: resp = cmdGameSay(sc.GetExtension(Command_GameSay::ext), cont, game, player, bla); break;
case GameCommand::SHUFFLE: resp = cmdShuffle(sc.GetExtension(command_shuffle), cont, game, player, bla); break; case GameCommand::SHUFFLE: resp = cmdShuffle(sc.GetExtension(Command_Shuffle::ext), cont, game, player, bla); break;
case GameCommand::MULLIGAN: resp = cmdMulligan(sc.GetExtension(command_mulligan), cont, game, player, bla); break; case GameCommand::MULLIGAN: resp = cmdMulligan(sc.GetExtension(Command_Mulligan::ext), cont, game, player, bla); break;
case GameCommand::ROLL_DIE: resp = cmdRollDie(sc.GetExtension(command_roll_die), cont, game, player, bla); break; case GameCommand::ROLL_DIE: resp = cmdRollDie(sc.GetExtension(Command_RollDie::ext), cont, game, player, bla); break;
case GameCommand::DRAW_CARDS: resp = cmdDrawCards(sc.GetExtension(command_draw_cards), cont, game, player, bla); break; case GameCommand::DRAW_CARDS: resp = cmdDrawCards(sc.GetExtension(Command_DrawCards::ext), cont, game, player, bla); break;
case GameCommand::UNDO_DRAW: resp = cmdUndoDraw(sc.GetExtension(command_undo_draw), cont, game, player, bla); break; case GameCommand::UNDO_DRAW: resp = cmdUndoDraw(sc.GetExtension(Command_UndoDraw::ext), cont, game, player, bla); break;
case GameCommand::FLIP_CARD: resp = cmdFlipCard(sc.GetExtension(command_flip_card), cont, game, player, bla); break; case GameCommand::FLIP_CARD: resp = cmdFlipCard(sc.GetExtension(Command_FlipCard::ext), cont, game, player, bla); break;
case GameCommand::ATTACH_CARD: resp = cmdAttachCard(sc.GetExtension(command_attach_card), cont, game, player, bla); break; case GameCommand::ATTACH_CARD: resp = cmdAttachCard(sc.GetExtension(Command_AttachCard::ext), cont, game, player, bla); break;
case GameCommand::CREATE_TOKEN: resp = cmdCreateToken(sc.GetExtension(command_create_token), cont, game, player, bla); break; case GameCommand::CREATE_TOKEN: resp = cmdCreateToken(sc.GetExtension(Command_CreateToken::ext), cont, game, player, bla); break;
case GameCommand::CREATE_ARROW: resp = cmdCreateArrow(sc.GetExtension(command_create_arrow), cont, game, player, bla); break; case GameCommand::CREATE_ARROW: resp = cmdCreateArrow(sc.GetExtension(Command_CreateArrow::ext), cont, game, player, bla); break;
case GameCommand::DELETE_ARROW: resp = cmdDeleteArrow(sc.GetExtension(command_delete_arrow), cont, game, player, bla); break; case GameCommand::DELETE_ARROW: resp = cmdDeleteArrow(sc.GetExtension(Command_DeleteArrow::ext), cont, game, player, bla); break;
case GameCommand::SET_CARD_ATTR: resp = cmdSetCardAttr(sc.GetExtension(command_set_card_attr), cont, game, player, bla); break; case GameCommand::SET_CARD_ATTR: resp = cmdSetCardAttr(sc.GetExtension(Command_SetCardAttr::ext), cont, game, player, bla); break;
case GameCommand::SET_CARD_COUNTER: resp = cmdSetCardCounter(sc.GetExtension(command_set_card_counter), cont, game, player, bla); break; case GameCommand::SET_CARD_COUNTER: resp = cmdSetCardCounter(sc.GetExtension(Command_SetCardCounter::ext), cont, game, player, bla); break;
case GameCommand::INC_CARD_COUNTER: resp = cmdIncCardCounter(sc.GetExtension(command_inc_card_counter), cont, game, player, bla); break; case GameCommand::INC_CARD_COUNTER: resp = cmdIncCardCounter(sc.GetExtension(Command_IncCardCounter::ext), cont, game, player, bla); break;
case GameCommand::READY_START: resp = cmdReadyStart(sc.GetExtension(command_ready_start), cont, game, player, bla); break; case GameCommand::READY_START: resp = cmdReadyStart(sc.GetExtension(Command_ReadyStart::ext), cont, game, player, bla); break;
case GameCommand::CONCEDE: resp = cmdConcede(sc.GetExtension(command_concede), cont, game, player, bla); break; case GameCommand::CONCEDE: resp = cmdConcede(sc.GetExtension(Command_Concede::ext), cont, game, player, bla); break;
case GameCommand::INC_COUNTER: resp = cmdIncCounter(sc.GetExtension(command_inc_counter), cont, game, player, bla); break; case GameCommand::INC_COUNTER: resp = cmdIncCounter(sc.GetExtension(Command_IncCounter::ext), cont, game, player, bla); break;
case GameCommand::CREATE_COUNTER: resp = cmdCreateCounter(sc.GetExtension(command_create_counter), cont, game, player, bla); break; case GameCommand::CREATE_COUNTER: resp = cmdCreateCounter(sc.GetExtension(Command_CreateCounter::ext), cont, game, player, bla); break;
case GameCommand::SET_COUNTER: resp = cmdSetCounter(sc.GetExtension(command_set_counter), cont, game, player, bla); break; case GameCommand::SET_COUNTER: resp = cmdSetCounter(sc.GetExtension(Command_SetCounter::ext), cont, game, player, bla); break;
case GameCommand::DEL_COUNTER: resp = cmdDelCounter(sc.GetExtension(command_del_counter), cont, game, player, bla); break; case GameCommand::DEL_COUNTER: resp = cmdDelCounter(sc.GetExtension(Command_DelCounter::ext), cont, game, player, bla); break;
case GameCommand::NEXT_TURN: resp = cmdNextTurn(sc.GetExtension(command_next_turn), cont, game, player, bla); break; case GameCommand::NEXT_TURN: resp = cmdNextTurn(sc.GetExtension(Command_NextTurn::ext), cont, game, player, bla); break;
case GameCommand::SET_ACTIVE_PHASE: resp = cmdSetActivePhase(sc.GetExtension(command_set_active_phase), cont, game, player, bla); break; case GameCommand::SET_ACTIVE_PHASE: resp = cmdSetActivePhase(sc.GetExtension(Command_SetActivePhase::ext), cont, game, player, bla); break;
case GameCommand::DUMP_ZONE: resp = cmdDumpZone(sc.GetExtension(command_dump_zone), cont, game, player, bla); break; case GameCommand::DUMP_ZONE: resp = cmdDumpZone(sc.GetExtension(Command_DumpZone::ext), cont, game, player, bla); break;
case GameCommand::STOP_DUMP_ZONE: resp = cmdStopDumpZone(sc.GetExtension(command_stop_dump_zone), cont, game, player, bla); break; case GameCommand::STOP_DUMP_ZONE: resp = cmdStopDumpZone(sc.GetExtension(Command_StopDumpZone::ext), cont, game, player, bla); break;
case GameCommand::REVEAL_CARDS: resp = cmdRevealCards(sc.GetExtension(command_reveal_cards), cont, game, player, bla); break; case GameCommand::REVEAL_CARDS: resp = cmdRevealCards(sc.GetExtension(Command_RevealCards::ext), cont, game, player, bla); break;
case GameCommand::MOVE_CARD: resp = cmdMoveCard(sc.GetExtension(command_move_card), cont, game, player, bla); break; case GameCommand::MOVE_CARD: resp = cmdMoveCard(sc.GetExtension(Command_MoveCard::ext), cont, game, player, bla); break;
case GameCommand::SET_SIDEBOARD_PLAN: resp = cmdSetSideboardPlan(sc.GetExtension(command_set_sideboard_plan), cont, game, player, bla); break; case GameCommand::SET_SIDEBOARD_PLAN: resp = cmdSetSideboardPlan(sc.GetExtension(Command_SetSideboardPlan::ext), cont, game, player, bla); break;
case GameCommand::DECK_SELECT: resp = cmdDeckSelect(sc.GetExtension(command_deck_select), cont, game, player, bla); break; case GameCommand::DECK_SELECT: resp = cmdDeckSelect(sc.GetExtension(Command_DeckSelect::ext), cont, game, player, bla); break;
} }
if ((resp != RespOk) && (resp != RespNothing)) if ((resp != RespOk) && (resp != RespNothing))
finalResponseCode = resp; finalResponseCode = resp;
@ -214,23 +249,25 @@ ResponseCode Server_ProtocolHandler::processGameCommandContainer(CommandContaine
ResponseCode Server_ProtocolHandler::processModeratorCommandContainer(CommandContainer *cont, BlaContainer *bla) ResponseCode Server_ProtocolHandler::processModeratorCommandContainer(CommandContainer *cont, BlaContainer *bla)
{ {
if (!userInfo)
return RespLoginNeeded;
if (!(userInfo->getUserLevel() & ServerInfo_User::IsModerator)) if (!(userInfo->getUserLevel() & ServerInfo_User::IsModerator))
return RespLoginNeeded; return RespLoginNeeded;
ResponseCode finalResponseCode = RespOk; ResponseCode finalResponseCode = RespOk;
for (int i = cont->moderator_command_size() - 1; i >= 0; --i) { for (int i = cont->moderator_command_size() - 1; i >= 0; --i) {
ResponseCode resp; ResponseCode resp = RespInvalidCommand;
const ModeratorCommand &sc = cont->moderator_command(i); const ModeratorCommand &sc = cont->moderator_command(i);
std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; std::vector< const ::google::protobuf::FieldDescriptor * > fieldList;
sc.GetReflection()->ListFields(sc, &fieldList); sc.GetReflection()->ListFields(sc, &fieldList);
int num = 0; int num = 0;
for (unsigned int j = 0; j < fieldList.size(); ++j) for (unsigned int j = 0; j < fieldList.size(); ++j)
if (fieldList[j]->number() >= 100) { if (fieldList[j]->is_extension()) {
num = fieldList[j]->number(); num = fieldList[j]->number();
break; break;
} }
switch ((ModeratorCommand::ModeratorCommandType) num) { switch ((ModeratorCommand::ModeratorCommandType) num) {
case ModeratorCommand::BAN_FROM_SERVER: resp = cmdBanFromServer(sc.GetExtension(command_ban_from_server), cont); break; case ModeratorCommand::BAN_FROM_SERVER: resp = cmdBanFromServer(sc.GetExtension(Command_BanFromServer::ext), cont); break;
} }
if ((resp != RespOk) && (resp != RespNothing)) if ((resp != RespOk) && (resp != RespNothing))
finalResponseCode = resp; finalResponseCode = resp;
@ -240,24 +277,26 @@ ResponseCode Server_ProtocolHandler::processModeratorCommandContainer(CommandCon
ResponseCode Server_ProtocolHandler::processAdminCommandContainer(CommandContainer *cont, BlaContainer *bla) ResponseCode Server_ProtocolHandler::processAdminCommandContainer(CommandContainer *cont, BlaContainer *bla)
{ {
if (!userInfo)
return RespLoginNeeded;
if (!(userInfo->getUserLevel() & ServerInfo_User::IsAdmin)) if (!(userInfo->getUserLevel() & ServerInfo_User::IsAdmin))
return RespLoginNeeded; return RespLoginNeeded;
ResponseCode finalResponseCode = RespOk; ResponseCode finalResponseCode = RespOk;
for (int i = cont->admin_command_size() - 1; i >= 0; --i) { for (int i = cont->admin_command_size() - 1; i >= 0; --i) {
ResponseCode resp; ResponseCode resp = RespInvalidCommand;
const AdminCommand &sc = cont->admin_command(i); const AdminCommand &sc = cont->admin_command(i);
std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; std::vector< const ::google::protobuf::FieldDescriptor * > fieldList;
sc.GetReflection()->ListFields(sc, &fieldList); sc.GetReflection()->ListFields(sc, &fieldList);
int num = 0; int num = 0;
for (unsigned int j = 0; j < fieldList.size(); ++j) for (unsigned int j = 0; j < fieldList.size(); ++j)
if (fieldList[j]->number() >= 100) { if (fieldList[j]->is_extension()) {
num = fieldList[j]->number(); num = fieldList[j]->number();
break; break;
} }
switch ((AdminCommand::AdminCommandType) num) { switch ((AdminCommand::AdminCommandType) num) {
case AdminCommand::SHUTDOWN_SERVER: resp = cmdShutdownServer(sc.GetExtension(command_shutdown_server), cont); break; case AdminCommand::SHUTDOWN_SERVER: resp = cmdShutdownServer(sc.GetExtension(Command_ShutdownServer::ext), cont); break;
case AdminCommand::UPDATE_SERVER_MESSAGE: resp = cmdUpdateServerMessage(sc.GetExtension(command_update_server_message), cont); break; case AdminCommand::UPDATE_SERVER_MESSAGE: resp = cmdUpdateServerMessage(sc.GetExtension(Command_UpdateServerMessage::ext), cont); break;
} }
if ((resp != RespOk) && (resp != RespNothing)) if ((resp != RespOk) && (resp != RespNothing))
finalResponseCode = resp; finalResponseCode = resp;
@ -857,8 +896,8 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(const Command_MoveCard &cmd, Co
return RespContextError; return RespContextError;
QList<const CardToMove *> cardsToMove; QList<const CardToMove *> cardsToMove;
for (int i = 0; i < cmd.cards_to_move_size(); ++i) for (int i = 0; i < cmd.cards_to_move().card_size(); ++i)
cardsToMove.append(&cmd.cards_to_move(i)); cardsToMove.append(&cmd.cards_to_move().card(i));
return player->moveCard(bla, QString::fromStdString(cmd.start_zone()), cardsToMove, cmd.target_player_id(), QString::fromStdString(cmd.target_zone()), cmd.x(), cmd.y()); return player->moveCard(bla, QString::fromStdString(cmd.start_zone()), cardsToMove, cmd.target_player_id(), QString::fromStdString(cmd.target_zone()), cmd.x(), cmd.y());
} }

View file

@ -37,15 +37,7 @@ HEADERS += src/main.h \
../common/server_game.h \ ../common/server_game.h \
../common/server_player.h \ ../common/server_player.h \
../common/server_protocolhandler.h \ ../common/server_protocolhandler.h \
../common/server_arrowtarget.h \ ../common/server_arrowtarget.h
../common/pb/commands.pb.h \
../common/pb/color.pb.h \
../common/pb/move_card_to_zone.pb.h \
../common/pb/game_commands.pb.h \
../common/pb/room_commands.pb.h \
../common/pb/session_commands.pb.h \
../common/pb/moderator_commands.pb.h \
../common/pb/admin_commands.pb.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
@ -68,13 +60,7 @@ SOURCES += src/main.cpp \
../common/server_room.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
../common/pb/commands.pb.cc \
../common/pb/color.pb.cc \
../common/pb/move_card_to_zone.pb.cc \
../common/pb/game_commands.pb.cc \
../common/pb/room_commands.pb.cc \
../common/pb/session_commands.pb.cc \
../common/pb/moderator_commands.pb.cc \
../common/pb/admin_commands.pb.cc
include ( ../pb_headers )
include ( ../pb_sources )

View file

@ -33,11 +33,17 @@
#include "server_logger.h" #include "server_logger.h"
#include "pb/commands.pb.h" #include "pb/commands.pb.h"
#include "pb/command_deck_upload.pb.h"
#include "pb/command_deck_download.pb.h"
#include "pb/command_deck_new_dir.pb.h"
#include "pb/command_deck_del_dir.pb.h"
#include "pb/command_deck_del.pb.h"
#include <string> #include <string>
#include <iostream> #include <iostream>
ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent) ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent)
: Server_ProtocolHandler(_server, parent), servatrice(_server), socket(_socket), topLevelItem(0), compressionSupport(false) : Server_ProtocolHandler(_server, parent), servatrice(_server), socket(_socket), topLevelItem(0), compressionSupport(false), messageInProgress(false)
{ {
xmlWriter = new QXmlStreamWriter(&xmlBuffer); xmlWriter = new QXmlStreamWriter(&xmlBuffer);
xmlReader = new QXmlStreamReader; xmlReader = new QXmlStreamReader;
@ -107,6 +113,7 @@ void ServerSocketInterface::readClient()
CommandContainer *newCommandContainer = new CommandContainer; CommandContainer *newCommandContainer = new CommandContainer;
newCommandContainer->ParseFromArray(inputBuffer.data(), messageLength); newCommandContainer->ParseFromArray(inputBuffer.data(), messageLength);
logger->logMessage(QString::fromStdString(newCommandContainer->ShortDebugString()), this);
inputBuffer.remove(0, messageLength); inputBuffer.remove(0, messageLength);
messageInProgress = false; messageInProgress = false;