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

@ -1,10 +1,14 @@
#include "abstractclient.h"
#include "protocol.h"
#include "protocol_items.h"
#include "pending_command.h"
#include "pb/commands.pb.h"
#include <google/protobuf/descriptor.h>
#include <QDebug>
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);
if (response) {
CommandContainer *cmdCont = pendingCommands.value(response->getCmdId(), 0);
if (!cmdCont)
const int cmdId = response->getCmdId();
PendingCommand *pend = pendingCommands.value(cmdId, 0);
if (!pend)
return;
pendingCommands.remove(cmdCont->getCmdId());
cmdCont->processResponse(response);
pendingCommands.remove(cmdId);
pend->processResponse(response);
if (response->getReceiverMayDelete())
delete response;
cmdCont->deleteLater();
pend->deleteLater();
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
#include <QObject>
#include <QVariant>
#include <google/protobuf/message.h>
#include "protocol_datastructures.h"
class Command;
class PendingCommand;
class CommandContainer;
class ProtocolItem;
class ProtocolResponse;
@ -56,20 +58,27 @@ signals:
void userInfoChanged(ServerInfo_User *userInfo);
void buddyListReceived(const QList<ServerInfo_User *> &buddyList);
void ignoreListReceived(const QList<ServerInfo_User *> &ignoreList);
private:
int nextCmdId;
protected slots:
void processProtocolItem(ProtocolItem *item);
protected:
QMap<int, CommandContainer *> pendingCommands;
QMap<int, PendingCommand *> pendingCommands;
ClientStatus status;
QString userName, password;
void setStatus(ClientStatus _status);
virtual void sendCommandContainer(const CommandContainer &cont) = 0;
public:
AbstractClient(QObject *parent = 0);
~AbstractClient();
ClientStatus getStatus() const { return status; }
virtual void sendCommand(Command *cmd);
virtual void sendCommandContainer(CommandContainer *cont) = 0;
void sendCommand(const CommandContainer &cont);
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

View file

@ -1,11 +1,12 @@
#include "abstractcounter.h"
#include "player.h"
#include "protocol_items.h"
#include <QPainter>
#include <QMenu>
#include <QAction>
#include <QGraphicsSceneMouseEvent>
#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)
: 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)
{
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();
} 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();
} else if (event->button() == Qt::MidButton) {
if (menu)
@ -111,8 +118,11 @@ void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
void AbstractCounter::incrementCounter()
{
int delta = static_cast<QAction *>(sender())->data().toInt();
player->sendGameCommand(new Command_IncCounter(-1, id, delta));
const int delta = static_cast<QAction *>(sender())->data().toInt();
Command_IncCounter cmd;
cmd.set_counter_id(id);
cmd.set_delta(delta);
player->sendGameCommand(cmd);
}
void AbstractCounter::setCounter()
@ -125,6 +135,11 @@ void AbstractCounter::setCounter()
return;
}
dialogSemaphore = false;
if (ok)
player->sendGameCommand(new Command_SetCounter(-1, id, newValue));
if (!ok)
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 "player.h"
#include "math.h"
#include "protocol_items.h"
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsScene>
#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)
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), color(_color), fullColor(true)
{
@ -129,8 +134,11 @@ void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
event->accept();
if (event->button() == Qt::RightButton)
player->sendGameCommand(new Command_DeleteArrow(-1, id));
if (event->button() == Qt::RightButton) {
Command_DeleteArrow cmd;
cmd.set_arrow_id(id);
player->sendGameCommand(cmd);
}
}
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.
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
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) {
CardZone *targetZone = targetCard->getZone();
player->sendGameCommand(new Command_CreateArrow(
-1,
startZone->getPlayer()->getId(),
startZone->getName(),
startCard->getId(),
targetZone->getPlayer()->getId(),
targetZone->getName(),
targetCard->getId(),
color
));
cmd.set_target_player_id(targetZone->getPlayer()->getId());
cmd.set_target_zone(targetZone->getName().toStdString());
cmd.set_target_card_id(targetCard->getId());
} else {
PlayerTarget *targetPlayer = qgraphicsitem_cast<PlayerTarget *>(targetItem);
player->sendGameCommand(new Command_CreateArrow(
-1,
startZone->getPlayer()->getId(),
startZone->getName(),
startCard->getId(),
targetPlayer->getOwner()->getId(),
QString(),
-1,
color
));
cmd.set_target_player_id(targetPlayer->getOwner()->getId());
}
player->sendGameCommand(cmd);
}
delArrow();
@ -277,15 +277,15 @@ void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
CardZone *startZone = startCard->getZone();
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
CardZone *targetZone = targetCard->getZone();
Command_AttachCard cmd;
cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_card_id(startCard->getId());
cmd.set_target_player_id(targetZone->getPlayer()->getId());
cmd.set_target_zone(targetZone->getName().toStdString());
cmd.set_target_card_id(targetCard->getId());
player->sendGameCommand(new Command_AttachCard(
-1,
startZone->getName(),
startCard->getId(),
targetZone->getPlayer()->getId(),
targetZone->getName(),
targetCard->getId()
));
player->sendGameCommand(cmd);
}
delArrow();

View file

@ -6,7 +6,8 @@
#include "carditem.h"
#include "player.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)
: AbstractGraphicsItem(parent), player(_p), name(_name), cards(_contentsKnown), view(NULL), menu(NULL), doubleClickAction(0), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable)
@ -179,12 +180,17 @@ void CardZone::moveAllToZone()
QList<QVariant> data = static_cast<QAction *>(sender())->data().toList();
QString targetZone = data[0].toString();
int targetX = data[1].toInt();
QList<CardToMove *> idList;
for (int i = 0; i < cards.size(); ++i)
idList.append(new CardToMove(cards[i]->getId()));
player->sendGameCommand(new Command_MoveCard(-1, getName(), idList, player->getId(), targetZone, targetX));
Command_MoveCard cmd;
cmd.set_start_zone(getName().toStdString());
cmd.set_target_player_id(player->getId());
cmd.set_target_zone(targetZone.toStdString());
cmd.set_x(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)

View file

@ -9,10 +9,13 @@
#include <QGroupBox>
#include <QMessageBox>
#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)
: QDialog(parent), client(_client), roomId(_roomId), gameTypes(_gameTypes)
#include "pending_command.h"
#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:"));
descriptionEdit = new QLineEdit;
@ -103,29 +106,27 @@ DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, const QMap<in
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);
while (gameTypeCheckBoxIterator.hasNext()) {
gameTypeCheckBoxIterator.next();
if (gameTypeCheckBoxIterator.value()->isChecked())
gameTypeList.append(new GameTypeId(gameTypeCheckBoxIterator.key()));
cmd.add_game_type_ids(gameTypeCheckBoxIterator.key());
}
Command_CreateGame *createCommand = new Command_CreateGame(
roomId,
descriptionEdit->text(),
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);
PendingCommand *pend = room->prepareRoomCommand(cmd);
connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
room->sendRoomCommand(pend);
okButton->setEnabled(false);
cancelButton->setEnabled(false);

View file

@ -2,7 +2,7 @@
#define DLG_CREATEGAME_H
#include <QDialog>
#include "abstractclient.h"
#include "protocol_datastructures.h"
class QLabel;
class QLineEdit;
@ -10,18 +10,18 @@ class QPushButton;
class QCheckBox;
class QGroupBox;
class QSpinBox;
class TabRoom;
class DlgCreateGame : public QDialog {
Q_OBJECT
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:
void actOK();
void checkResponse(ResponseCode response);
void spectatorsAllowedChanged(int state);
private:
AbstractClient *client;
int roomId;
TabRoom *room;
QMap<int, QString> gameTypes;
QMap<int, QCheckBox *> gameTypeCheckBoxes;

View file

@ -8,11 +8,12 @@
#include <QInputDialog>
#include "tab_supervisor.h"
#include "dlg_creategame.h"
#include "abstractclient.h"
#include "protocol_items.h"
#include "gameselector.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)
: QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room)
{
@ -84,7 +85,7 @@ void GameSelector::showRunningGamesChanged(int state)
void GameSelector::actCreate()
{
DlgCreateGame dlg(client, room->getRoomId(), room->getGameTypes(), this);
DlgCreateGame dlg(room, room->getGameTypes(), this);
dlg.exec();
}
@ -124,10 +125,16 @@ void GameSelector::actJoin()
if (!ok)
return;
}
Command_JoinGame *commandJoinGame = new Command_JoinGame(game->getRoomId(), game->getGameId(), password, spectator, overrideRestrictions);
connect(commandJoinGame, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
client->sendCommand(commandJoinGame);
Command_JoinGame cmd;
cmd.set_game_id(game->getGameId());
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)
createButton->setEnabled(false);

View file

@ -2,9 +2,10 @@
#include "handzone.h"
#include "settingscache.h"
#include "player.h"
#include "protocol_items.h"
#include "carddragitem.h"
#include "pb/command_move_card.pb.h"
HandZone::HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent)
: 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*/)
{
QList<CardToMove *> idList;
Command_MoveCard cmd;
cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_target_player_id(player->getId());
cmd.set_target_zone(getName().toStdString());
cmd.set_x(cards.size());
cmd.set_y(-1);
for (int i = 0; i < dragItems.size(); ++i)
idList.append(new CardToMove(dragItems[i]->getId()));
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), idList, player->getId(), getName(), cards.size(), -1));
player->sendGameCommand(cmd);
}
QRectF HandZone::boundingRect() const

View file

@ -2,23 +2,31 @@
#include "localserverinterface.h"
#include "protocol.h"
#include "pb/session_commands.pb.h"
LocalClient::LocalClient(LocalServerInterface *_lsi, const QString &_playerName, QObject *parent)
: AbstractClient(parent), lsi(_lsi)
{
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()
{
}
void LocalClient::sendCommandContainer(CommandContainer *cont)
void LocalClient::sendCommandContainer(const CommandContainer &cont)
{
cont->setReceiverMayDelete(false);
pendingCommands.insert(cont->getCmdId(), cont);
lsi->itemFromClient(cont);
// cont->setReceiverMayDelete(false);
// pendingCommands.insert(cont->getCmdId(), cont);
// lsi->itemFromClient(cont);
}
void LocalClient::itemFromServer(ProtocolItem *item)

View file

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

View file

@ -22,5 +22,5 @@ void LocalServerInterface::sendProtocolItem(ProtocolItem *item, bool deleteItem)
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
private:
DeckList *getDeckFromDatabase(int /*deckId*/) { return 0; }
ResponseCode cmdAddToList(Command_AddToList * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdRemoveFromList(Command_RemoveFromList * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckList(Command_DeckList * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckNewDir(Command_DeckNewDir * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckDelDir(Command_DeckDelDir * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckDel(Command_DeckDel * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckUpload(Command_DeckUpload * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckDownload(Command_DeckDownload * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdBanFromServer(Command_BanFromServer * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdShutdownServer(Command_ShutdownServer * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdUpdateServerMessage(Command_UpdateServerMessage * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdAddToList(const Command_AddToList & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdRemoveFromList(const Command_RemoveFromList & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckList(const Command_DeckList & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckNewDir(const Command_DeckNewDir & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckDelDir(const Command_DeckDelDir & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckDel(const Command_DeckDel & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckUpload(const Command_DeckUpload & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdDeckDownload(const Command_DeckDownload & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdBanFromServer(const Command_BanFromServer & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdShutdownServer(const Command_ShutdownServer & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage & /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
protected:
bool getCompressionSupport() const { return false; }
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 <math.h>
#include "phasestoolbar.h"
#include "protocol_items.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)
: 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());
if (button->getActive())
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()
{
emit sendGameCommand(new Command_NextTurn, -1);
emit sendGameCommand(Command_NextTurn(), -1);
}
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()
{
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 <QList>
#include <QGraphicsObject>
#include <google/protobuf/message.h>
class Player;
class GameCommand;
@ -62,7 +63,7 @@ private slots:
void actUntapAll();
void actDrawCard();
signals:
void sendGameCommand(GameCommand *command, int playerId);
void sendGameCommand(const ::google::protobuf::Message &command, int playerId);
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/);
};

View file

@ -5,7 +5,8 @@
#include "player.h"
#include "carddragitem.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)
: 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*/)
{
QList<CardToMove *> idList;
for (int i = 0; i < dragItems.size(); ++i)
idList.append(new CardToMove(dragItems[i]->getId()));
Command_MoveCard cmd;
cmd.set_start_zone(startZone->getName().toStdString());
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()

View file

@ -22,6 +22,21 @@
#include <QMenu>
#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)
: QObject(), QGraphicsItem(parentItem)
{
@ -345,13 +360,29 @@ void Player::playerListActionTriggered()
int otherPlayerId = action->data().toInt();
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) {
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) {
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) {
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()
{
sendGameCommand(new Command_Shuffle);
sendGameCommand(Command_Shuffle());
}
void Player::actDrawCard()
{
sendGameCommand(new Command_DrawCards(-1, 1));
Command_DrawCards cmd;
cmd.set_number(1);
sendGameCommand(cmd);
}
void Player::actMulligan()
{
sendGameCommand(new Command_Mulligan);
sendGameCommand(Command_Mulligan());
}
void Player::actDrawCards()
{
int number = QInputDialog::getInteger(0, tr("Draw cards"), tr("Number:"));
if (number)
sendGameCommand(new Command_DrawCards(-1, number));
if (number) {
Command_DrawCards cmd;
cmd.set_number(number);
sendGameCommand(cmd);
}
}
void Player::actUndoDraw()
{
sendGameCommand(new Command_UndoDraw);
sendGameCommand(Command_UndoDraw());
}
void Player::actMoveTopCardsToGrave()
@ -609,14 +645,21 @@ void Player::actMoveTopCardsToGrave()
if (!number)
return;
QList<Command *> commandList;
const int maxCards = zones.value("deck")->getCards().size();
if (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)
idList.append(new CardToMove(i));
sendGameCommand(new Command_MoveCard(-1, "deck", idList, getId(), "grave", 0, 0));
cmd.mutable_cards_to_move()->add_card()->set_card_id(i);
sendGameCommand(cmd);
}
void Player::actMoveTopCardsToExile()
@ -625,32 +668,56 @@ void Player::actMoveTopCardsToExile()
if (!number)
return;
QList<Command *> commandList;
const int maxCards = zones.value("deck")->getCards().size();
if (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)
idList.append(new CardToMove(i));
sendGameCommand(new Command_MoveCard(-1, "deck", idList, getId(), "rfg", 0, 0));
cmd.mutable_cards_to_move()->add_card()->set_card_id(i);
sendGameCommand(cmd);
}
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()
{
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()
{
bool ok;
int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok);
if (ok)
sendGameCommand(new Command_RollDie(-1, sides));
if (ok) {
Command_RollDie cmd;
cmd.set_sides(sides);
sendGameCommand(cmd);
}
}
void Player::actCreateToken()
@ -666,18 +733,30 @@ void Player::actCreateToken()
lastTokenDestroy = dlg.getDestroy();
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()
{
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()
{
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)
@ -1154,13 +1233,27 @@ void Player::processCardAttachment(ServerInfo_Player *info)
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();
if (ci->getTableRow() == 3)
sendGameCommand(new Command_MoveCard(-1, c->getZone()->getName(), QList<CardToMove *>() << new CardToMove(c->getId()), getId(), "stack", 0, 0));
else {
if (ci->getTableRow() == 3) {
cmd.set_target_zone("stack");
cmd.set_x(0);
cmd.set_y(0);
} else {
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)
@ -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);
}
void Player::sendCommandContainer(CommandContainer *cont)
void Player::sendCommandContainer(CommandContainer &cont)
{
static_cast<TabGame *>(parent())->sendCommandContainer(cont, id);
}
void Player::sendGameCommand(PendingCommand *pend)
{
static_cast<TabGame *>(parent())->sendGameCommand(pend, id);
}
bool Player::clearCardsToDelete()
{
if (cardsToDelete.isEmpty())
@ -1341,55 +1449,118 @@ void Player::cardMenuAction(QAction *a)
while (!sel.isEmpty())
cardList.append(qgraphicsitem_cast<CardItem *>(sel.takeFirst()));
QList<Command *> commandList;
QList< const ::google::protobuf::Message * > commandList;
if (a->data().toInt() <= 4)
for (int i = 0; i < cardList.size(); ++i) {
CardItem *card = cardList[i];
switch (a->data().toInt()) {
case 0:
if (!card->getTapped())
commandList.append(new Command_SetCardAttr(-1, card->getZone()->getName(), card->getId(), "tapped", "1"));
if (!card->getTapped()) {
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;
case 1:
if (card->getTapped())
commandList.append(new Command_SetCardAttr(-1, card->getZone()->getName(), card->getId(), "tapped", "0"));
if (card->getTapped()) {
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;
case 2:
commandList.append(new Command_SetCardAttr(-1, card->getZone()->getName(), card->getId(), "doesnt_untap", QString::number(!card->getDoesntUntap())));
break;
case 3: {
QString zone = card->getZone()->getName();
commandList.append(new Command_FlipCard(-1, zone, card->getId(), !card->getFaceDown()));
case 2: {
Command_SetCardAttr *cmd = new Command_SetCardAttr;
cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId());
cmd->set_attr_name("doesnt_untap");
cmd->set_attr_value(card->getDoesntUntap() ? "1" : "0");
commandList.append(cmd);
break;
}
case 4:
commandList.append(new Command_CreateToken(-1, card->getZone()->getName(), card->getName(), card->getColor(), card->getPT(), card->getAnnotation(), true, -1, card->getGridPoint().y()));
case 3: {
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;
}
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 {
QList<CardToMove *> idList;
ListOfCardsToMove idList;
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();
switch (a->data().toInt()) {
case 5:
commandList.append(new Command_MoveCard(-1, startZone, idList, getId(), "deck", 0, 0));
case 5: {
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;
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;
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;
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;
}
default: ;
}
}
sendCommandContainer(new CommandContainer(commandList));
static_cast<TabGame *>(parent())->sendGameCommand(prepareGameCommand(commandList));
}
void Player::actIncPT(int deltaP, int deltaT)
@ -1398,7 +1569,11 @@ void Player::actIncPT(int deltaP, int deltaT)
QListIterator<QGraphicsItem *> j(scene()->selectedItems());
while (j.hasNext()) {
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());
while (j.hasNext()) {
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();
while (i.hasNext()) {
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)
{
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)
@ -1476,8 +1662,14 @@ void Player::actCardCounterTrigger(QAction *a)
QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next());
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));
if (card->getCounters().value(counterId, 0) < MAX_COUNTERS_ON_CARD) {
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;
}
@ -1485,8 +1677,14 @@ void Player::actCardCounterTrigger(QAction *a)
QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next());
if (card->getCounters().value(counterId, 0))
sendGameCommand(new Command_SetCardCounter(-1, card->getZone()->getName(), card->getId(), counterId, card->getCounters().value(counterId, 0) - 1));
if (card->getCounters().value(counterId, 0)) {
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;
}
@ -1503,7 +1701,12 @@ void Player::actCardCounterTrigger(QAction *a)
QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) {
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;
}

View file

@ -5,6 +5,7 @@
#include <QPoint>
#include <QMap>
#include "carditem.h"
#include <google/protobuf/message.h>
class CardDatabase;
class QMenu;
@ -46,6 +47,7 @@ class Event_DestroyCard;
class Event_AttachCard;
class Event_DrawCards;
class Event_RevealCards;
class PendingCommand;
class PlayerArea : public QObject, public QGraphicsItem {
Q_OBJECT
@ -254,8 +256,12 @@ public:
void processCardAttachment(ServerInfo_Player *info);
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

View file

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

View file

@ -6,6 +6,10 @@
#include "protocol.h"
#include "protocol_items.h"
#include "pending_command.h"
#include "pb/commands.pb.h"
#include "pb/session_commands.pb.h"
RemoteClient::RemoteClient(QObject *parent)
: 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)));
xmlReader = new QXmlStreamReader;
xmlWriter = new QXmlStreamWriter;
xmlWriter->setDevice(socket);
}
RemoteClient::~RemoteClient()
@ -80,28 +82,41 @@ void RemoteClient::readData()
disconnectFromServer();
return;
}
xmlWriter->writeStartDocument();
/* xmlWriter->writeStartDocument();
xmlWriter->writeStartElement("cockatrice_client_stream");
xmlWriter->writeAttribute("version", QString::number(ProtocolItem::protocolVersion));
xmlWriter->writeAttribute("comp", "1");
*/
topLevelItem = new TopLevelProtocolItem;
connect(topLevelItem, SIGNAL(protocolItemReceived(ProtocolItem *)), this, SLOT(processProtocolItem(ProtocolItem *)));
setStatus(StatusLoggingIn);
Command_Login *cmdLogin = new Command_Login(userName, password);
connect(cmdLogin, SIGNAL(finished(ProtocolResponse *)), this, SLOT(loginResponse(ProtocolResponse *)));
sendCommand(cmdLogin);
Command_Login 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)
disconnectFromServer();
}
void RemoteClient::sendCommandContainer(CommandContainer *cont)
void RemoteClient::sendCommandContainer(const CommandContainer &cont)
{
cont->write(xmlWriter);
pendingCommands.insert(cont->getCmdId(), cont);
QByteArray buf;
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)
@ -123,7 +138,7 @@ void RemoteClient::disconnectFromServer()
timer->stop();
QList<CommandContainer *> pc = pendingCommands.values();
QList<PendingCommand *> pc = pendingCommands.values();
for (int i = 0; i < pc.size(); i++)
delete pc[i];
pendingCommands.clear();
@ -134,21 +149,21 @@ void RemoteClient::disconnectFromServer()
void RemoteClient::ping()
{
QMutableMapIterator<int, CommandContainer *> i(pendingCommands);
/* QMutableMapIterator<int, PendingCommand *> i(pendingCommands);
while (i.hasNext())
if (i.next().value()->tick() > maxTimeout) {
CommandContainer *cont = i.value();
i.remove();
cont->deleteLater();
}
*/
int maxTime = timeRunning - lastDataReceived;
emit maxPingTime(maxTime, maxTimeout);
if (maxTime >= maxTimeout) {
disconnectFromServer();
emit serverTimeout();
} else {
sendCommand(new Command_Ping);
sendCommand(prepareSessionCommand(Command_Ping()));
++timeRunning;
}
}

View file

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

View file

@ -5,6 +5,9 @@
#include "protocol_items.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::Node(_name, _parent)
{
@ -238,9 +241,10 @@ void RemoteDeckList_TreeModel::removeNode(RemoteDeckList_TreeModel::Node *node)
void RemoteDeckList_TreeModel::refreshTree()
{
Command_DeckList *command = new Command_DeckList;
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckListFinished(ProtocolResponse *)));
client->sendCommand(command);
PendingCommand *pend = client->prepareSessionCommand(Command_DeckList());
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckListFinished(ProtocolResponse *)));
client->sendCommand(pend);
}
void RemoteDeckList_TreeModel::deckListFinished(ProtocolResponse *r)

View file

@ -4,9 +4,10 @@
#include "stackzone.h"
#include "settingscache.h"
#include "player.h"
#include "protocol_items.h"
#include "carddragitem.h"
#include "pb/command_move_card.pb.h"
StackZone::StackZone(Player *_p, int _zoneHeight, QGraphicsItem *parent)
: SelectZone(_p, "stack", false, false, true, parent), zoneHeight(_zoneHeight)
{
@ -57,11 +58,17 @@ void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone
if (startZone == this)
return;
QList<CardToMove *> idList;
for (int i = 0; i < dragItems.size(); ++i)
idList.append(new CardToMove(dragItems[i]->getId()));
Command_MoveCard cmd;
cmd.set_start_zone(startZone->getName().toStdString());
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()

View file

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

View file

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

View file

@ -27,6 +27,18 @@
#include "settingscache.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)
: QPushButton(parent), readyStart(false)
{
@ -50,8 +62,8 @@ void ReadyStartButton::setReadyStart(bool _readyStart)
update();
}
DeckViewContainer::DeckViewContainer(AbstractClient *_client, TabGame *parent)
: QWidget(parent), client(_client)
DeckViewContainer::DeckViewContainer(int _playerId, TabGame *parent)
: QWidget(parent), playerId(_playerId)
{
loadLocalButton = new QPushButton;
loadRemoteButton = new QPushButton;
@ -110,18 +122,22 @@ void DeckViewContainer::loadLocalDeck()
return;
}
Command_DeckSelect *cmd = new Command_DeckSelect(static_cast<TabGame *>(parent())->getGameId(), deck, -1);
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckSelectFinished(ProtocolResponse *)));
client->sendCommand(cmd);
Command_DeckSelect cmd;
cmd.set_deck(""); // XXX
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()
{
DlgLoadRemoteDeck dlg(client);
DlgLoadRemoteDeck dlg(static_cast<TabGame *>(parent())->getClientForPlayer(playerId));
if (dlg.exec()) {
Command_DeckSelect *cmd = new Command_DeckSelect(static_cast<TabGame *>(parent())->getGameId(), 0, dlg.getDeckId());
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckSelectFinished(ProtocolResponse *)));
client->sendCommand(cmd);
Command_DeckSelect cmd;
cmd.set_deck_id(dlg.getDeckId());
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()
{
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()
{
Command_SetSideboardPlan cmd;
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)
@ -164,7 +185,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
{
phasesToolbar = new PhasesToolbar;
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);
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)
return;
sendGameCommand(new Command_Concede);
sendGameCommand(Command_Concede());
}
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)
return;
sendGameCommand(new Command_LeaveGame);
sendGameCommand(Command_LeaveGame());
deleteLater();
}
void TabGame::actSay()
{
if (!sayEdit->text().isEmpty()) {
sendGameCommand(new Command_Say(-1, sayEdit->text()));
Command_GameSay cmd;
cmd.set_message(sayEdit->text().toStdString());
sendGameCommand(cmd);
sayEdit->clear();
}
}
@ -351,7 +374,9 @@ void TabGame::actSay()
void TabGame::actPhaseAction()
{
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()
@ -359,12 +384,14 @@ void TabGame::actNextPhase()
int phase = currentPhase;
if (++phase >= phasesToolbar->phaseCount())
phase = 0;
sendGameCommand(new Command_SetActivePhase(-1, phase));
Command_SetActivePhase cmd;
cmd.set_phase(phase);
sendGameCommand(cmd);
}
void TabGame::actNextTurn()
{
sendGameCommand(new Command_NextTurn);
sendGameCommand(Command_NextTurn());
}
void TabGame::actRemoveLocalArrows()
@ -377,7 +404,9 @@ void TabGame::actRemoveLocalArrows()
QMapIterator<int, ArrowItem *> arrowIterator(player->getArrows());
while (arrowIterator.hasNext()) {
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);
if (local && !spectator) {
AbstractClient *client;
if (clients.size() > 1)
client = clients.at(playerId);
else {
client = clients.first();
if (clients.size() == 1)
newPlayer->setShortcutsActive();
}
DeckViewContainer *deckView = new DeckViewContainer(client, this);
DeckViewContainer *deckView = new DeckViewContainer(playerId, this);
connect(deckView, SIGNAL(newCardAdded(AbstractCardItem *)), this, SLOT(newCardAdded(AbstractCardItem *)));
deckViewContainers.insert(playerId, deckView);
deckViewContainerLayout->addWidget(deckView);
@ -462,37 +487,53 @@ void TabGame::processGameEventContainer(GameEventContainer *cont, AbstractClient
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 (playerId == -1)
playerId = getActiveLocalPlayer()->getId();
client = clients.at(playerId);
return clients.at(playerId);
} else
client = clients.first();
client->sendCommand(command);
return clients.first();
}
void TabGame::sendCommandContainer(CommandContainer *cont, int playerId)
void TabGame::sendGameCommand(PendingCommand *pend, int playerId)
{
const QList<Command *> &cmdList = cont->getCommandList();
for (int i = 0; i < cmdList.size(); ++i) {
GameCommand *cmd = qobject_cast<GameCommand *>(cmdList[i]);
if (cmd)
cmd->setGameId(gameId);
}
getClientForPlayer(playerId)->sendCommand(pend);
}
AbstractClient *client;
if (clients.size() > 1) {
if (playerId == -1)
playerId = getActiveLocalPlayer()->getId();
client = clients.at(playerId);
} else
client = clients.first();
client->sendCommandContainer(cont);
void TabGame::sendGameCommand(const google::protobuf::Message &command, int playerId)
{
AbstractClient *client = getClientForPlayer(playerId);
client->sendCommand(prepareGameCommand(command));
}
void TabGame::sendCommandContainer(CommandContainer &cont, int playerId)
{
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)

View file

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

View file

@ -8,6 +8,9 @@
#include "protocol_items.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)
: Tab(_tabSupervisor), client(_client), userName(_userName), userOnline(true)
{
@ -52,9 +55,14 @@ void TabMessage::sendMessage()
if (sayEdit->text().isEmpty() || !userOnline)
return;
Command_Message *cmd = new Command_Message(userName, sayEdit->text());
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(messageSent(ProtocolResponse *)));
client->sendCommand(cmd);
Command_Message cmd;
cmd.set_user_name(userName.toStdString());
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();
}

View file

@ -13,9 +13,13 @@
#include "tab_userlists.h"
#include "userlist.h"
#include "abstractclient.h"
#include "protocol_items.h"
#include "chatview.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)
: Tab(_tabSupervisor), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName)
@ -108,9 +112,12 @@ void TabRoom::sendMessage()
if (sayEdit->text().isEmpty())
return;
Command_RoomSay *cmd = new Command_RoomSay(roomId, sayEdit->text());
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(sayFinished(ProtocolResponse *)));
client->sendCommand(cmd);
Command_RoomSay cmd;
cmd.set_message(sayEdit->text().toStdString());
PendingCommand *pend = prepareRoomCommand(cmd);
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(sayFinished(ProtocolResponse *)));
sendRoomCommand(pend);
sayEdit->clear();
}
@ -122,7 +129,7 @@ void TabRoom::sayFinished(ProtocolResponse *response)
void TabRoom::actLeaveRoom()
{
client->sendCommand(new Command_LeaveRoom(roomId));
sendRoomCommand(prepareRoomCommand(Command_LeaveRoom()));
deleteLater();
}
@ -161,3 +168,17 @@ void TabRoom::processSayEvent(Event_RoomSay *event)
chatView->appendMessage(event->getPlayerName(), event->getMessage());
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 <QGroupBox>
#include <QMap>
#include <google/protobuf/message.h>
class AbstractClient;
class UserList;
@ -21,6 +22,7 @@ class Event_LeaveRoom;
class Event_RoomSay;
class ProtocolResponse;
class GameSelector;
class PendingCommand;
class TabRoom : public Tab {
Q_OBJECT
@ -62,6 +64,9 @@ public:
const QMap<int, QString> &getGameTypes() const { return gameTypes; }
QString getChannelName() const { return roomName; }
QString getTabText() const { return roomName; }
PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd);
void sendRoomCommand(PendingCommand *pend);
};
#endif

View file

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

View file

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

View file

@ -1,11 +1,14 @@
#include "tab_userlists.h"
#include "userlist.h"
#include "userinfobox.h"
#include "protocol_items.h"
#include "abstractclient.h"
#include <QDebug>
#include <QHBoxLayout>
#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)
: 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(removeFromListEventReceived(Event_RemoveFromList *)), this, SLOT(processRemoveFromListEvent(Event_RemoveFromList *)));
Command_ListUsers *cmd = new Command_ListUsers;
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processListUsersResponse(ProtocolResponse *)));
client->sendCommand(cmd);
PendingCommand *pend = client->prepareSessionCommand(Command_ListUsers());
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processListUsersResponse(ProtocolResponse *)));
client->sendCommand(pend);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(userInfoBox);

View file

@ -4,12 +4,14 @@
#include <math.h>
#include "tablezone.h"
#include "player.h"
#include "protocol_items.h"
#include "settingscache.h"
#include "arrowitem.h"
#include "carddragitem.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)
: 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)
{
QList<CardToMove *> idList;
for (int i = 0; i < dragItems.size(); ++i)
idList.append(new CardToMove(dragItems[i]->getId(), dragItems[i]->getFaceDown(), startZone->getName() == name ? QString() : dragItems[i]->getItem()->getInfo()->getPowTough()));
Command_MoveCard cmd;
cmd.set_start_zone(startZone->getName().toStdString());
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()
@ -181,13 +193,19 @@ void TableZone::toggleTapped()
tapAll = true;
break;
}
QList<Command *> cmdList;
QList< const ::google::protobuf::Message * > cmdList;
for (int i = 0; i < selectedItems.size(); i++) {
CardItem *temp = qgraphicsitem_cast<CardItem *>(selectedItems[i]);
if (temp->getTapped() != tapAll)
cmdList.append(new Command_SetCardAttr(-1, name, temp->getId(), "tapped", tapAll ? "1" : "0"));
if (temp->getTapped() != tapAll) {
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)

View file

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

View file

@ -20,6 +20,10 @@
#include <QCheckBox>
#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)
: QDialog(parent)
{
@ -292,7 +296,7 @@ void UserList::userClicked(QTreeWidgetItem *item, int /*column*/)
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);
if (!response)
return;
@ -314,7 +318,7 @@ void UserList::gamesOfUserReceived(ProtocolResponse *resp)
for (int i = 0; i < gameList.size(); ++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->show();
}
@ -334,7 +338,14 @@ void UserList::banUser_processUserInfoResponse(ProtocolResponse *r)
void UserList::banUser_dialogFinished()
{
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)
@ -390,22 +401,46 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
infoWidget->updateInfo(userName);
} else if (actionClicked == aChat)
emit openMessageDialog(userName, true);
else if (actionClicked == aAddToBuddyList)
client->sendCommand(new Command_AddToList("buddy", userName));
else if (actionClicked == aRemoveFromBuddyList)
client->sendCommand(new Command_RemoveFromList("buddy", userName));
else if (actionClicked == aShowGames) {
Command *cmd = new Command_GetGamesOfUser(userName);
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(gamesOfUserReceived(ProtocolResponse *)));
client->sendCommand(cmd);
} else if (actionClicked == aAddToIgnoreList)
client->sendCommand(new Command_AddToList("ignore", userName));
else if (actionClicked == aRemoveFromIgnoreList)
client->sendCommand(new Command_RemoveFromList("ignore", userName));
else if (actionClicked == aBan) {
Command_GetUserInfo *command = new Command_GetUserInfo(userName);
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(banUser_processUserInfoResponse(ProtocolResponse *)));
client->sendCommand(command);
else if (actionClicked == aAddToBuddyList) {
Command_AddToList cmd;
cmd.set_list("buddy");
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
} else if (actionClicked == aRemoveFromBuddyList) {
Command_RemoveFromList cmd;
cmd.set_list("buddy");
cmd.set_user_name(userName.toStdString());
client->sendCommand(client->prepareSessionCommand(cmd));
} else if (actionClicked == aShowGames) {
Command_GetGamesOfUser cmd;
cmd.set_user_name(userName.toStdString());
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;

View file

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

View file

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

View file

@ -2,8 +2,13 @@
#include <QDebug>
#include "zoneviewzone.h"
#include "player.h"
#include "protocol_items.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)
: 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);
reorganizeCards();
} else if (!origZone->contentsKnown()) {
Command_DumpZone *command = new Command_DumpZone(-1, player->getId(), name, numberCards);
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(zoneDumpReceived(ProtocolResponse *)));
player->sendGameCommand(command);
Command_DumpZone cmd;
cmd.set_player_id(player->getId());
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 {
const CardList &c = origZone->getCards();
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*/)
{
QList<CardToMove *> idList;
for (int i = 0; i < dragItems.size(); ++i)
idList.append(new CardToMove(dragItems[i]->getId()));
Command_MoveCard cmd;
cmd.set_start_zone(startZone->getName().toStdString());
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)