restructured protocol code

This commit is contained in:
Max-Wilhelm Bruker 2009-11-29 03:07:28 +01:00
parent 122f8ea916
commit 694070724c
32 changed files with 1202 additions and 2081 deletions

View file

@ -50,6 +50,7 @@ HEADERS += src/counter.h \
src/remotedecklist_treewidget.h \ src/remotedecklist_treewidget.h \
src/deckview.h \ src/deckview.h \
src/playerlistwidget.h \ src/playerlistwidget.h \
../common/serializable_item.h \
../common/decklist.h \ ../common/decklist.h \
../common/protocol.h \ ../common/protocol.h \
../common/protocol_items.h \ ../common/protocol_items.h \
@ -98,6 +99,7 @@ SOURCES += src/counter.cpp \
src/remotedecklist_treewidget.cpp \ src/remotedecklist_treewidget.cpp \
src/deckview.cpp \ src/deckview.cpp \
src/playerlistwidget.cpp \ src/playerlistwidget.cpp \
../common/serializable_item.cpp \
../common/decklist.cpp \ ../common/decklist.cpp \
../common/protocol.cpp \ ../common/protocol.cpp \
../common/protocol_items.cpp \ ../common/protocol_items.cpp \

View file

@ -6,7 +6,7 @@
#include "protocol_items.h" #include "protocol_items.h"
Client::Client(QObject *parent) Client::Client(QObject *parent)
: QObject(parent), currentItem(0), status(StatusDisconnected) : QObject(parent), topLevelItem(0), status(StatusDisconnected)
{ {
ProtocolItem::initializeHash(); ProtocolItem::initializeHash();
@ -58,44 +58,31 @@ void Client::readData()
qDebug() << data; qDebug() << data;
xmlReader->addData(data); xmlReader->addData(data);
if (currentItem) { if (topLevelItem)
if (!currentItem->read(xmlReader)) topLevelItem->read(xmlReader);
return; else {
currentItem = 0; while (!xmlReader->atEnd()) {
} xmlReader->readNext();
while (!xmlReader->atEnd()) { if (xmlReader->isStartElement() && (xmlReader->name().toString() == "cockatrice_server_stream")) {
xmlReader->readNext();
if (xmlReader->isStartElement()) {
QString itemType = xmlReader->name().toString();
if (itemType == "cockatrice_server_stream") {
int serverVersion = xmlReader->attributes().value("version").toString().toInt(); int serverVersion = xmlReader->attributes().value("version").toString().toInt();
if (serverVersion != ProtocolItem::protocolVersion) { if (serverVersion != ProtocolItem::protocolVersion) {
emit protocolVersionMismatch(ProtocolItem::protocolVersion, serverVersion); emit protocolVersionMismatch(ProtocolItem::protocolVersion, serverVersion);
disconnectFromServer(); disconnectFromServer();
return; return;
} else {
xmlWriter->writeStartDocument();
xmlWriter->writeStartElement("cockatrice_client_stream");
xmlWriter->writeAttribute("version", QString::number(ProtocolItem::protocolVersion));
setStatus(StatusLoggingIn);
Command_Login *cmdLogin = new Command_Login(userName, password);
connect(cmdLogin, SIGNAL(finished(ResponseCode)), this, SLOT(loginResponse(ResponseCode)));
sendCommand(cmdLogin);
continue;
} }
} xmlWriter->writeStartDocument();
QString itemName = xmlReader->attributes().value("name").toString(); xmlWriter->writeStartElement("cockatrice_client_stream");
qDebug() << "parseXml: startElement: " << "type =" << itemType << ", name =" << itemName; xmlWriter->writeAttribute("version", QString::number(ProtocolItem::protocolVersion));
currentItem = ProtocolItem::getNewItem(itemType + itemName);
if (!currentItem) topLevelItem = new TopLevelProtocolItem;
continue; connect(topLevelItem, SIGNAL(protocolItemReceived(ProtocolItem *)), this, SLOT(processProtocolItem(ProtocolItem *)));
if (!currentItem->read(xmlReader))
return; setStatus(StatusLoggingIn);
else { Command_Login *cmdLogin = new Command_Login(userName, password);
processProtocolItem(currentItem); connect(cmdLogin, SIGNAL(finished(ResponseCode)), this, SLOT(loginResponse(ResponseCode)));
currentItem = 0; sendCommand(cmdLogin);
topLevelItem->read(xmlReader);
} }
} }
} }
@ -171,7 +158,9 @@ void Client::connectToServer(const QString &hostname, unsigned int port, const Q
void Client::disconnectFromServer() void Client::disconnectFromServer()
{ {
currentItem = 0; delete topLevelItem;
topLevelItem = 0;
xmlReader->clear(); xmlReader->clear();
timer->stop(); timer->stop();

View file

@ -14,6 +14,7 @@ class QXmlStreamWriter;
class ProtocolItem; class ProtocolItem;
class ProtocolResponse; class ProtocolResponse;
class TopLevelProtocolItem;
class ChatEvent; class ChatEvent;
class GameEvent; class GameEvent;
class Event_ListGames; class Event_ListGames;
@ -56,6 +57,7 @@ private slots:
void slotSocketError(QAbstractSocket::SocketError error); void slotSocketError(QAbstractSocket::SocketError error);
void ping(); void ping();
void loginResponse(ResponseCode response); void loginResponse(ResponseCode response);
void processProtocolItem(ProtocolItem *item);
private: private:
static const int maxTimeout = 10; static const int maxTimeout = 10;
@ -64,11 +66,10 @@ private:
QTcpSocket *socket; QTcpSocket *socket;
QXmlStreamReader *xmlReader; QXmlStreamReader *xmlReader;
QXmlStreamWriter *xmlWriter; QXmlStreamWriter *xmlWriter;
ProtocolItem *currentItem; TopLevelProtocolItem *topLevelItem;
ClientStatus status; ClientStatus status;
QString userName, password; QString userName, password;
void setStatus(ClientStatus _status); void setStatus(ClientStatus _status);
void processProtocolItem(ProtocolItem *item);
public: public:
Client(QObject *parent = 0); Client(QObject *parent = 0);
~Client(); ~Client();

View file

@ -14,7 +14,7 @@
DeckListModel::DeckListModel(QObject *parent) DeckListModel::DeckListModel(QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
{ {
deckList = new DeckList(this); deckList = new DeckList;
connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree())); connect(deckList, SIGNAL(deckLoaded()), this, SLOT(rebuildTree()));
root = new InnerDecklistNode; root = new InnerDecklistNode;
} }
@ -22,6 +22,7 @@ DeckListModel::DeckListModel(QObject *parent)
DeckListModel::~DeckListModel() DeckListModel::~DeckListModel()
{ {
delete root; delete root;
delete deckList;
} }

View file

@ -1,9 +1,12 @@
#include "gamesmodel.h" #include "gamesmodel.h"
#include "protocol_datastructures.h"
GamesModel::~GamesModel() GamesModel::~GamesModel()
{ {
if (!gameList.isEmpty()) { if (!gameList.isEmpty()) {
beginRemoveRows(QModelIndex(), 0, gameList.size() - 1); beginRemoveRows(QModelIndex(), 0, gameList.size() - 1);
for (int i = 0; i < gameList.size(); ++i)
delete gameList[i];
gameList.clear(); gameList.clear();
endRemoveRows(); endRemoveRows();
} }
@ -20,13 +23,13 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
if ((index.row() >= gameList.size()) || (index.column() >= columnCount())) if ((index.row() >= gameList.size()) || (index.column() >= columnCount()))
return QVariant(); return QVariant();
const ServerGameInfo &g = gameList[index.row()]; ServerInfo_Game *g = gameList[index.row()];
switch (index.column()) { switch (index.column()) {
case 0: return g.getDescription(); case 0: return g->getDescription();
case 1: return g.getCreatorName(); case 1: return g->getCreatorName();
case 2: return g.getHasPassword() ? tr("yes") : tr("no"); case 2: return g->getHasPassword() ? tr("yes") : tr("no");
case 3: return QString("%1/%2").arg(g.getPlayerCount()).arg(g.getMaxPlayers()); case 3: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
case 4: return g.getSpectatorsAllowed() ? QVariant(g.getSpectatorCount()) : QVariant(tr("not allowed")); case 4: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorCount()) : QVariant(tr("not allowed"));
default: return QVariant(); default: return QVariant();
} }
} }
@ -45,30 +48,32 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro
} }
} }
const ServerGameInfo &GamesModel::getGame(int row) ServerInfo_Game *GamesModel::getGame(int row)
{ {
Q_ASSERT(row < gameList.size()); Q_ASSERT(row < gameList.size());
return gameList[row]; return gameList[row];
} }
void GamesModel::updateGameList(const ServerGameInfo &game) void GamesModel::updateGameList(ServerInfo_Game *_game)
{ {
ServerInfo_Game *game = new ServerInfo_Game(_game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), _game->getCreatorName(), _game->getSpectatorsAllowed(), _game->getSpectatorCount());
for (int i = 0; i < gameList.size(); i++) for (int i = 0; i < gameList.size(); i++)
if (gameList[i].getGameId() == game.getGameId()) { if (gameList[i]->getGameId() == game->getGameId()) {
if (game.getPlayerCount() == 0) { if (game->getPlayerCount() == 0) {
beginRemoveRows(QModelIndex(), i, i); beginRemoveRows(QModelIndex(), i, i);
gameList.removeAt(i); delete gameList.takeAt(i);
endRemoveRows(); endRemoveRows();
} else { } else {
delete gameList[i];
gameList[i] = game; gameList[i] = game;
emit dataChanged(index(i, 0), index(i, 4)); emit dataChanged(index(i, 0), index(i, 4));
} }
return; return;
} }
if (game.getPlayerCount() == 0) if (game->getPlayerCount() == 0)
return; return;
beginInsertRows(QModelIndex(), gameList.size(), gameList.size()); beginInsertRows(QModelIndex(), gameList.size(), gameList.size());
gameList << game; gameList.append(game);
endInsertRows(); endInsertRows();
} }
@ -93,8 +98,8 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc
if (!model) if (!model)
return false; return false;
const ServerGameInfo &game = model->getGame(sourceRow); ServerInfo_Game *game = model->getGame(sourceRow);
if (game.getPlayerCount() == game.getMaxPlayers()) if (game->getPlayerCount() == game->getMaxPlayers())
return false; return false;
return true; return true;

View file

@ -4,7 +4,8 @@
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QList> #include <QList>
#include "protocol_datastructures.h"
class ServerInfo_Game;
class GamesModel : public QAbstractTableModel { class GamesModel : public QAbstractTableModel {
Q_OBJECT Q_OBJECT
@ -16,10 +17,10 @@ public:
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
const ServerGameInfo &getGame(int row); ServerInfo_Game *getGame(int row);
void updateGameList(const ServerGameInfo &game); void updateGameList(ServerInfo_Game *game);
private: private:
QList<ServerGameInfo> gameList; QList<ServerInfo_Game *> gameList;
}; };
class GamesProxyModel : public QSortFilterProxyModel { class GamesProxyModel : public QSortFilterProxyModel {

View file

@ -373,7 +373,7 @@ void Player::actDrawCards()
void Player::actUntapAll() void Player::actUntapAll()
{ {
// client->setCardAttr("table", -1, "tapped", "false"); sendGameCommand(new Command_SetCardAttr(-1, "table", -1, "tapped", "0"));
} }
void Player::actRollDie() void Player::actRollDie()
@ -448,12 +448,15 @@ void Player::eventRollDie(Event_RollDie *event)
emit logRollDie(this, event->getSides(), event->getValue()); emit logRollDie(this, event->getSides(), event->getValue());
} }
void Player::eventCreateArrow(Event_CreateArrow *event) void Player::eventCreateArrows(Event_CreateArrows *event)
{ {
ArrowItem *arrow = addArrow(event->getArrow()); const QList<ServerInfo_Arrow *> eventArrowList = event->getArrowList();
if (!arrow) for (int i = 0; i < eventArrowList.size(); ++i) {
return; ArrowItem *arrow = addArrow(eventArrowList[i]);
emit logCreateArrow(this, arrow->getStartItem()->getOwner(), arrow->getStartItem()->getName(), arrow->getTargetItem()->getOwner(), arrow->getTargetItem()->getName()); if (!arrow)
return;
emit logCreateArrow(this, arrow->getStartItem()->getOwner(), arrow->getStartItem()->getName(), arrow->getTargetItem()->getOwner(), arrow->getTargetItem()->getName());
}
} }
void Player::eventDeleteArrow(Event_DeleteArrow *event) void Player::eventDeleteArrow(Event_DeleteArrow *event)
@ -492,9 +495,11 @@ void Player::eventSetCardAttr(Event_SetCardAttr *event)
} }
} }
void Player::eventCreateCounter(Event_CreateCounter *event) void Player::eventCreateCounters(Event_CreateCounters *event)
{ {
addCounter(event->getCounter()); const QList<ServerInfo_Counter *> &eventCounterList = event->getCounterList();
for (int i = 0; i < eventCounterList.size(); ++i)
addCounter(eventCounterList[i]);
} }
void Player::eventSetCounter(Event_SetCounter *event) void Player::eventSetCounter(Event_SetCounter *event)
@ -612,11 +617,11 @@ void Player::processGameEvent(GameEvent *event)
case ItemId_Event_ReadyStart: eventReadyStart(qobject_cast<Event_ReadyStart *>(event)); break; case ItemId_Event_ReadyStart: eventReadyStart(qobject_cast<Event_ReadyStart *>(event)); break;
case ItemId_Event_Shuffle: eventShuffle(qobject_cast<Event_Shuffle *>(event)); break; case ItemId_Event_Shuffle: eventShuffle(qobject_cast<Event_Shuffle *>(event)); break;
case ItemId_Event_RollDie: eventRollDie(qobject_cast<Event_RollDie *>(event)); break; case ItemId_Event_RollDie: eventRollDie(qobject_cast<Event_RollDie *>(event)); break;
case ItemId_Event_CreateArrow: eventCreateArrow(qobject_cast<Event_CreateArrow *>(event)); break; case ItemId_Event_CreateArrows: eventCreateArrows(qobject_cast<Event_CreateArrows *>(event)); break;
case ItemId_Event_DeleteArrow: eventDeleteArrow(qobject_cast<Event_DeleteArrow *>(event)); break; case ItemId_Event_DeleteArrow: eventDeleteArrow(qobject_cast<Event_DeleteArrow *>(event)); break;
case ItemId_Event_CreateToken: eventCreateToken(qobject_cast<Event_CreateToken *>(event)); break; case ItemId_Event_CreateToken: eventCreateToken(qobject_cast<Event_CreateToken *>(event)); break;
case ItemId_Event_SetCardAttr: eventSetCardAttr(qobject_cast<Event_SetCardAttr *>(event)); break; case ItemId_Event_SetCardAttr: eventSetCardAttr(qobject_cast<Event_SetCardAttr *>(event)); break;
case ItemId_Event_CreateCounter: eventCreateCounter(qobject_cast<Event_CreateCounter *>(event)); break; case ItemId_Event_CreateCounters: eventCreateCounters(qobject_cast<Event_CreateCounters *>(event)); break;
case ItemId_Event_SetCounter: eventSetCounter(qobject_cast<Event_SetCounter *>(event)); break; case ItemId_Event_SetCounter: eventSetCounter(qobject_cast<Event_SetCounter *>(event)); break;
case ItemId_Event_DelCounter: eventDelCounter(qobject_cast<Event_DelCounter *>(event)); break; case ItemId_Event_DelCounter: eventDelCounter(qobject_cast<Event_DelCounter *>(event)); break;
case ItemId_Event_DumpZone: eventDumpZone(qobject_cast<Event_DumpZone *>(event)); break; case ItemId_Event_DumpZone: eventDumpZone(qobject_cast<Event_DumpZone *>(event)); break;

View file

@ -27,11 +27,11 @@ class Event_Say;
class Event_ReadyStart; class Event_ReadyStart;
class Event_Shuffle; class Event_Shuffle;
class Event_RollDie; class Event_RollDie;
class Event_CreateArrow; class Event_CreateArrows;
class Event_DeleteArrow; class Event_DeleteArrow;
class Event_CreateToken; class Event_CreateToken;
class Event_SetCardAttr; class Event_SetCardAttr;
class Event_CreateCounter; class Event_CreateCounters;
class Event_SetCounter; class Event_SetCounter;
class Event_DelCounter; class Event_DelCounter;
class Event_DumpZone; class Event_DumpZone;
@ -118,11 +118,11 @@ private:
void eventReadyStart(Event_ReadyStart *event); void eventReadyStart(Event_ReadyStart *event);
void eventShuffle(Event_Shuffle *event); void eventShuffle(Event_Shuffle *event);
void eventRollDie(Event_RollDie *event); void eventRollDie(Event_RollDie *event);
void eventCreateArrow(Event_CreateArrow *event); void eventCreateArrows(Event_CreateArrows *event);
void eventDeleteArrow(Event_DeleteArrow *event); void eventDeleteArrow(Event_DeleteArrow *event);
void eventCreateToken(Event_CreateToken *event); void eventCreateToken(Event_CreateToken *event);
void eventSetCardAttr(Event_SetCardAttr *event); void eventSetCardAttr(Event_SetCardAttr *event);
void eventCreateCounter(Event_CreateCounter *event); void eventCreateCounters(Event_CreateCounters *event);
void eventSetCounter(Event_SetCounter *event); void eventSetCounter(Event_SetCounter *event);
void eventDelCounter(Event_DelCounter *event); void eventDelCounter(Event_DelCounter *event);
void eventDumpZone(Event_DumpZone *event); void eventDumpZone(Event_DumpZone *event);

View file

@ -54,12 +54,13 @@ void RemoteDeckList_TreeWidget::addFolderToTree(DeckList_Directory *folder, QTre
newItem->setData(0, Qt::UserRole, QString()); newItem->setData(0, Qt::UserRole, QString());
} }
for (int i = 0; i < folder->size(); ++i) { const QList<DeckList_TreeItem *> &folderItems = folder->getTreeItems();
DeckList_Directory *subFolder = dynamic_cast<DeckList_Directory *>(folder->at(i)); for (int i = 0; i < folderItems.size(); ++i) {
DeckList_Directory *subFolder = dynamic_cast<DeckList_Directory *>(folderItems[i]);
if (subFolder) if (subFolder)
addFolderToTree(subFolder, newItem); addFolderToTree(subFolder, newItem);
else else
addFileToTree(dynamic_cast<DeckList_File *>(folder->at(i)), newItem); addFileToTree(dynamic_cast<DeckList_File *>(folderItems[i]), newItem);
} }
} }

View file

@ -51,9 +51,9 @@ void TabChatChannel::processChatEvent(ChatEvent *event)
void TabChatChannel::processListPlayersEvent(Event_ChatListPlayers *event) void TabChatChannel::processListPlayersEvent(Event_ChatListPlayers *event)
{ {
const QList<ServerChatUserInfo> &players = event->getPlayerList(); const QList<ServerInfo_ChatUser *> &players = event->getPlayerList();
for (int i = 0; i < players.size(); ++i) for (int i = 0; i < players.size(); ++i)
playerList->addItem(players[i].getName()); playerList->addItem(players[i]->getName());
} }
void TabChatChannel::processJoinChannelEvent(Event_ChatJoinChannel *event) void TabChatChannel::processJoinChannelEvent(Event_ChatJoinChannel *event)

View file

@ -121,7 +121,6 @@ void TabDeckStorage::uploadFinished(ProtocolResponse *r)
if (!resp) if (!resp)
return; return;
Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender()); Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender());
delete cmd->getDeck();
QTreeWidgetItemIterator it(serverDirView); QTreeWidgetItemIterator it(serverDirView);
while (*it) { while (*it) {

View file

@ -324,11 +324,9 @@ void TabGame::deckSelectFinished(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_DeckSelect *cmd = static_cast<Command_DeckSelect *>(sender());
delete cmd->getDeck();
Deck_PictureCacher::cachePictures(resp->getDeck(), this); Deck_PictureCacher::cachePictures(resp->getDeck(), this);
deckView->setDeck(resp->getDeck()); deckView->setDeck(new DeckList(resp->getDeck()));
} }
void TabGame::readyStart() void TabGame::readyStart()

View file

@ -78,16 +78,16 @@ void GameSelector::actJoin()
QModelIndex ind = gameListView->currentIndex(); QModelIndex ind = gameListView->currentIndex();
if (!ind.isValid()) if (!ind.isValid())
return; return;
const ServerGameInfo &game = gameListModel->getGame(ind.data(Qt::UserRole).toInt()); ServerInfo_Game *game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
QString password; QString password;
if (game.getHasPassword()) { if (game->getHasPassword()) {
bool ok; bool ok;
password = QInputDialog::getText(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok); password = QInputDialog::getText(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok);
if (!ok) if (!ok)
return; return;
} }
Command_JoinGame *commandJoinGame = new Command_JoinGame(game.getGameId(), password, spectator); Command_JoinGame *commandJoinGame = new Command_JoinGame(game->getGameId(), password, spectator);
connect(commandJoinGame, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode))); connect(commandJoinGame, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
client->sendCommand(commandJoinGame); client->sendCommand(commandJoinGame);
@ -107,7 +107,7 @@ void GameSelector::retranslateUi()
void GameSelector::processListGamesEvent(Event_ListGames *event) void GameSelector::processListGamesEvent(Event_ListGames *event)
{ {
const QList<ServerGameInfo> &gamesToUpdate = event->getGameList(); const QList<ServerInfo_Game *> &gamesToUpdate = event->getGameList();
for (int i = 0; i < gamesToUpdate.size(); ++i) for (int i = 0; i < gamesToUpdate.size(); ++i)
gameListModel->updateGameList(gamesToUpdate[i]); gameListModel->updateGameList(gamesToUpdate[i]);
} }
@ -148,26 +148,26 @@ void ChatChannelSelector::retranslateUi()
void ChatChannelSelector::processListChatChannelsEvent(Event_ListChatChannels *event) void ChatChannelSelector::processListChatChannelsEvent(Event_ListChatChannels *event)
{ {
const QList<ServerChatChannelInfo> &channelsToUpdate = event->getChannelList(); const QList<ServerInfo_ChatChannel *> &channelsToUpdate = event->getChannelList();
for (int i = 0; i < channelsToUpdate.size(); ++i) { for (int i = 0; i < channelsToUpdate.size(); ++i) {
const ServerChatChannelInfo &channel = channelsToUpdate[i]; ServerInfo_ChatChannel *channel = channelsToUpdate[i];
for (int j = 0; j < channelList->topLevelItemCount(); ++j) { for (int j = 0; j < channelList->topLevelItemCount(); ++j) {
QTreeWidgetItem *twi = channelList->topLevelItem(j); QTreeWidgetItem *twi = channelList->topLevelItem(j);
if (twi->text(0) == channel.getName()) { if (twi->text(0) == channel->getName()) {
twi->setText(1, channel.getDescription()); twi->setText(1, channel->getDescription());
twi->setText(2, QString::number(channel.getPlayerCount())); twi->setText(2, QString::number(channel->getPlayerCount()));
return; return;
} }
} }
QTreeWidgetItem *twi = new QTreeWidgetItem(QStringList() << channel.getName() << channel.getDescription() << QString::number(channel.getPlayerCount())); QTreeWidgetItem *twi = new QTreeWidgetItem(QStringList() << channel->getName() << channel->getDescription() << QString::number(channel->getPlayerCount()));
twi->setTextAlignment(2, Qt::AlignRight); twi->setTextAlignment(2, Qt::AlignRight);
channelList->addTopLevelItem(twi); channelList->addTopLevelItem(twi);
channelList->resizeColumnToContents(0); channelList->resizeColumnToContents(0);
channelList->resizeColumnToContents(1); channelList->resizeColumnToContents(1);
channelList->resizeColumnToContents(2); channelList->resizeColumnToContents(2);
if (channel.getAutoJoin()) if (channel->getAutoJoin())
joinChannel(channel.getName()); joinChannel(channel->getName());
} }
} }

View file

@ -42,7 +42,7 @@ void ZoneViewZone::initializeCards()
} }
} }
void ZoneViewZone::zoneDumpReceived(QList<ServerInfo_Card> cards) /*void ZoneViewZone::zoneDumpReceived(QList<ServerInfo_Card *> cards)
{ {
for (int i = 0; i < cards.size(); i++) { for (int i = 0; i < cards.size(); i++) {
CardItem *card = new CardItem(player, cards[i].getName(), i, this); CardItem *card = new CardItem(player, cards[i].getName(), i, this);
@ -52,7 +52,7 @@ void ZoneViewZone::zoneDumpReceived(QList<ServerInfo_Card> cards)
emit contentsChanged(); emit contentsChanged();
reorganizeCards(); reorganizeCards();
} }
*/
// Because of boundingRect(), this function must not be called before the zone was added to a scene. // Because of boundingRect(), this function must not be called before the zone was added to a scene.
void ZoneViewZone::reorganizeCards() void ZoneViewZone::reorganizeCards()
{ {

View file

@ -29,7 +29,7 @@ public:
public slots: public slots:
void setSortingEnabled(int _sortingEnabled); void setSortingEnabled(int _sortingEnabled);
private slots: private slots:
void zoneDumpReceived(QList<ServerInfo_Card> cards); // void zoneDumpReceived(QList<ServerInfo_Card> cards);
protected: protected:
void addCardImpl(CardItem *card, int x, int y); void addCardImpl(CardItem *card, int x, int y);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;

View file

@ -21,6 +21,18 @@ int AbstractDecklistNode::depth() const
return 0; return 0;
} }
InnerDecklistNode::InnerDecklistNode(InnerDecklistNode *other, InnerDecklistNode *_parent)
: AbstractDecklistNode(_parent), name(other->getName())
{
for (int i = 0; i < other->size(); ++i) {
InnerDecklistNode *inner = dynamic_cast<InnerDecklistNode *>(other->at(i));
if (inner)
new InnerDecklistNode(inner, this);
else
new DecklistCardNode(dynamic_cast<DecklistCardNode *>(other->at(i)), this);
}
}
InnerDecklistNode::~InnerDecklistNode() InnerDecklistNode::~InnerDecklistNode()
{ {
clearTree(); clearTree();
@ -48,6 +60,11 @@ void InnerDecklistNode::clearTree()
clear(); clear();
} }
DecklistCardNode::DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent)
: AbstractDecklistCardNode(_parent), name(other->getName()), number(other->getNumber())
{
}
AbstractDecklistNode *InnerDecklistNode::findChild(const QString &name) AbstractDecklistNode *InnerDecklistNode::findChild(const QString &name)
{ {
for (int i = 0; i < size(); i++) for (int i = 0; i < size(); i++)
@ -178,76 +195,71 @@ const QStringList DeckList::fileNameFilters = QStringList()
<< QObject::tr("Plain text decks (*.dec *.mwDeck)") << QObject::tr("Plain text decks (*.dec *.mwDeck)")
<< QObject::tr("All files (*.*)"); << QObject::tr("All files (*.*)");
DeckList::DeckList(QObject *parent) DeckList::DeckList()
: QObject(parent), currentZone(0) : SerializableItem("cockatrice_deck"), currentZone(0)
{ {
root = new InnerDecklistNode; root = new InnerDecklistNode;
} }
DeckList::DeckList(DeckList *other)
: SerializableItem("cockatrice_deck"), currentZone(0)
{
root = new InnerDecklistNode(other->getRoot());
}
DeckList::~DeckList() DeckList::~DeckList()
{ {
delete root; delete root;
} }
bool DeckList::readElement(QXmlStreamReader *xml) void DeckList::readElement(QXmlStreamReader *xml)
{ {
if (currentZone) { if (currentZone) {
if (currentZone->readElement(xml)) if (currentZone->readElement(xml))
currentZone = 0; currentZone = 0;
return false; } else if (xml->isEndElement()) {
}
if (xml->isEndElement()) {
if (xml->name() == "deckname") if (xml->name() == "deckname")
name = currentElementText; name = currentElementText;
else if (xml->name() == "comments") else if (xml->name() == "comments")
comments = currentElementText; comments = currentElementText;
else if (xml->name() == "cockatrice_deck")
return true;
currentElementText.clear(); currentElementText.clear();
} else if (xml->isStartElement() && (xml->name() == "zone")) } else if (xml->isStartElement() && (xml->name() == "zone"))
currentZone = new InnerDecklistNode(xml->attributes().value("name").toString(), root); currentZone = new InnerDecklistNode(xml->attributes().value("name").toString(), root);
else if (xml->isCharacters() && !xml->isWhitespace()) else if (xml->isCharacters() && !xml->isWhitespace())
currentElementText = xml->text().toString(); currentElementText = xml->text().toString();
return false;
} }
void DeckList::writeElement(QXmlStreamWriter *xml) void DeckList::writeElement(QXmlStreamWriter *xml)
{ {
xml->writeStartElement("cockatrice_deck");
xml->writeAttribute("version", "1"); xml->writeAttribute("version", "1");
xml->writeTextElement("deckname", name); xml->writeTextElement("deckname", name);
xml->writeTextElement("comments", comments); xml->writeTextElement("comments", comments);
for (int i = 0; i < root->size(); i++) for (int i = 0; i < root->size(); i++)
root->at(i)->writeElement(xml); root->at(i)->writeElement(xml);
xml->writeEndElement(); // cockatrice_deck
} }
bool DeckList::loadFromXml(QXmlStreamReader *xml) void DeckList::loadFromXml(QXmlStreamReader *xml)
{ {
while (!xml->atEnd()) { while (!xml->atEnd()) {
xml->readNext(); xml->readNext();
if (xml->isStartElement()) { if (xml->isStartElement()) {
if (xml->name() != "cockatrice_deck") if (xml->name() != "cockatrice_deck")
return false; return;
while (!xml->atEnd()) { while (!xml->atEnd()) {
xml->readNext(); xml->readNext();
if (readElement(xml)) readElement(xml);
return true;
} }
} }
} }
return false;
} }
bool DeckList::loadFromFile_Native(QIODevice *device) bool DeckList::loadFromFile_Native(QIODevice *device)
{ {
QXmlStreamReader xml(device); QXmlStreamReader xml(device);
return loadFromXml(&xml); loadFromXml(&xml);
return true;
} }
bool DeckList::saveToFile_Native(QIODevice *device) bool DeckList::saveToFile_Native(QIODevice *device)
@ -256,7 +268,7 @@ bool DeckList::saveToFile_Native(QIODevice *device)
xml.setAutoFormatting(true); xml.setAutoFormatting(true);
xml.writeStartDocument(); xml.writeStartDocument();
writeElement(&xml); write(&xml);
xml.writeEndDocument(); xml.writeEndDocument();
return true; return true;

View file

@ -5,6 +5,7 @@
#include <QVector> #include <QVector>
#include <QPair> #include <QPair>
#include <QObject> #include <QObject>
#include "serializable_item.h"
class CardDatabase; class CardDatabase;
class QIODevice; class QIODevice;
@ -36,6 +37,7 @@ private:
class compareFunctor; class compareFunctor;
public: public:
InnerDecklistNode(const QString &_name = QString(), InnerDecklistNode *_parent = 0) : AbstractDecklistNode(_parent), name(_name) { } InnerDecklistNode(const QString &_name = QString(), InnerDecklistNode *_parent = 0) : AbstractDecklistNode(_parent), name(_name) { }
InnerDecklistNode(InnerDecklistNode *other, InnerDecklistNode *_parent = 0);
virtual ~InnerDecklistNode(); virtual ~InnerDecklistNode();
QString getName() const { return name; } QString getName() const { return name; }
void setName(const QString &_name) { name = _name; } void setName(const QString &_name) { name = _name; }
@ -72,13 +74,14 @@ private:
int number; int number;
public: public:
DecklistCardNode(const QString &_name = QString(), int _number = 1, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number) { } DecklistCardNode(const QString &_name = QString(), int _number = 1, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number) { }
DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent);
int getNumber() const { return number; } int getNumber() const { return number; }
void setNumber(int _number) { number = _number; } void setNumber(int _number) { number = _number; }
QString getName() const { return name; } QString getName() const { return name; }
void setName(const QString &_name) { name = _name; } void setName(const QString &_name) { name = _name; }
}; };
class DeckList : public QObject { class DeckList : public SerializableItem {
Q_OBJECT Q_OBJECT
public: public:
enum FileFormat { PlainTextFormat, CockatriceFormat }; enum FileFormat { PlainTextFormat, CockatriceFormat };
@ -96,16 +99,17 @@ public slots:
void setComments(const QString &_comments = QString()) { comments = _comments; } void setComments(const QString &_comments = QString()) { comments = _comments; }
public: public:
static const QStringList fileNameFilters; static const QStringList fileNameFilters;
DeckList(QObject *parent = 0); DeckList();
DeckList(DeckList *other);
~DeckList(); ~DeckList();
QString getName() const { return name; } QString getName() const { return name; }
QString getComments() const { return comments; } QString getComments() const { return comments; }
QString getLastFileName() const { return lastFileName; } QString getLastFileName() const { return lastFileName; }
FileFormat getLastFileFormat() const { return lastFileFormat; } FileFormat getLastFileFormat() const { return lastFileFormat; }
bool readElement(QXmlStreamReader *xml); void readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml); void writeElement(QXmlStreamWriter *xml);
bool loadFromXml(QXmlStreamReader *xml); void loadFromXml(QXmlStreamReader *xml);
bool loadFromFile_Native(QIODevice *device); bool loadFromFile_Native(QIODevice *device);
bool saveToFile_Native(QIODevice *device); bool saveToFile_Native(QIODevice *device);

View file

@ -5,100 +5,87 @@
#include "protocol_items.h" #include "protocol_items.h"
#include "decklist.h" #include "decklist.h"
QHash<QString, ProtocolItem::NewItemFunction> ProtocolItem::itemNameHash; ProtocolItem::ProtocolItem(const QString &_itemType, const QString &_itemSubType)
: SerializableItem_Map(_itemType, _itemSubType)
ProtocolItem::ProtocolItem(const QString &_itemName)
: itemName(_itemName)
{ {
} }
bool ProtocolItem::read(QXmlStreamReader *xml)
{
while (!xml->atEnd()) {
xml->readNext();
if (readElement(xml))
continue;
if (xml->isEndElement()) {
if (xml->name() == getItemType()) {
extractParameters();
return true;
} else {
QString tagName = xml->name().toString();
if (parameters.contains(tagName))
parameters[tagName] = currentElementText;
currentElementText.clear();
}
} else if (xml->isCharacters() && !xml->isWhitespace())
currentElementText = xml->text().toString();
}
return false;
}
void ProtocolItem::write(QXmlStreamWriter *xml)
{
xml->writeStartElement(getItemType());
if (!itemName.isEmpty())
xml->writeAttribute("name", itemName);
QMapIterator<QString, QString> i(parameters);
while (i.hasNext()) {
i.next();
xml->writeTextElement(i.key(), i.value());
}
writeElement(xml);
xml->writeEndElement();
}
ProtocolItem *ProtocolItem::getNewItem(const QString &name)
{
if (!itemNameHash.contains(name))
return 0;
return itemNameHash.value(name)();
}
void ProtocolItem::initializeHash() void ProtocolItem::initializeHash()
{ {
if (!itemNameHash.isEmpty())
return;
initializeHashAuto(); initializeHashAuto();
itemNameHash.insert("cmddeck_upload", Command_DeckUpload::newItem); registerSerializableItem("chat_channel", ServerInfo_ChatChannel::newItem);
itemNameHash.insert("cmddeck_select", Command_DeckSelect::newItem); registerSerializableItem("chat_user", ServerInfo_ChatUser::newItem);
registerSerializableItem("game", ServerInfo_Game::newItem);
registerSerializableItem("card", ServerInfo_Card::newItem);
registerSerializableItem("zone", ServerInfo_Zone::newItem);
registerSerializableItem("counter", ServerInfo_Counter::newItem);
registerSerializableItem("arrow", ServerInfo_Arrow::newItem);
registerSerializableItem("player", ServerInfo_Player::newItem);
registerSerializableItem("file", DeckList_File::newItem);
registerSerializableItem("directory", DeckList_Directory::newItem);
itemNameHash.insert("resp", ProtocolResponse::newItem); registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem);
registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem);
registerSerializableItem("resp", ProtocolResponse::newItem);
ProtocolResponse::initializeHash(); ProtocolResponse::initializeHash();
itemNameHash.insert("respdeck_list", Response_DeckList::newItem); registerSerializableItem("respdeck_list", Response_DeckList::newItem);
itemNameHash.insert("respdeck_download", Response_DeckDownload::newItem); registerSerializableItem("respdeck_download", Response_DeckDownload::newItem);
itemNameHash.insert("respdeck_upload", Response_DeckUpload::newItem); registerSerializableItem("respdeck_upload", Response_DeckUpload::newItem);
itemNameHash.insert("generic_eventlist_games", Event_ListGames::newItem); registerSerializableItem("generic_eventlist_games", Event_ListGames::newItem);
itemNameHash.insert("generic_eventlist_chat_channels", Event_ListChatChannels::newItem); registerSerializableItem("generic_eventlist_chat_channels", Event_ListChatChannels::newItem);
itemNameHash.insert("game_eventgame_state_changed", Event_GameStateChanged::newItem); registerSerializableItem("game_eventgame_state_changed", Event_GameStateChanged::newItem);
itemNameHash.insert("game_eventcreate_arrow", Event_CreateArrow::newItem); registerSerializableItem("game_eventcreate_arrows", Event_CreateArrows::newItem);
itemNameHash.insert("game_eventcreate_counter", Event_CreateCounter::newItem); registerSerializableItem("game_eventcreate_counters", Event_CreateCounters::newItem);
itemNameHash.insert("game_eventdraw_cards", Event_DrawCards::newItem); registerSerializableItem("game_eventdraw_cards", Event_DrawCards::newItem);
itemNameHash.insert("chat_eventchat_list_players", Event_ChatListPlayers::newItem); registerSerializableItem("chat_eventchat_list_players", Event_ChatListPlayers::newItem);
}
TopLevelProtocolItem::TopLevelProtocolItem()
: SerializableItem(QString()), currentItem(0)
{
}
bool TopLevelProtocolItem::readCurrentItem(QXmlStreamReader *xml)
{
if (currentItem) {
if (currentItem->read(xml)) {
emit protocolItemReceived(currentItem);
currentItem = 0;
}
return true;
} else
return false;
}
void TopLevelProtocolItem::readElement(QXmlStreamReader *xml)
{
if (!readCurrentItem(xml) && (xml->isStartElement())) {
QString childName = xml->name().toString();
QString childSubType = xml->attributes().value("type").toString();
currentItem = dynamic_cast<ProtocolItem *>(getNewItem(childName + childSubType));
if (!currentItem)
currentItem = new ProtocolItem_Invalid;
readCurrentItem(xml);
}
}
void TopLevelProtocolItem::writeElement(QXmlStreamWriter * /*xml*/)
{
} }
int Command::lastCmdId = 0; int Command::lastCmdId = 0;
Command::Command(const QString &_itemName, int _cmdId) Command::Command(const QString &_itemName, int _cmdId)
: ProtocolItem(_itemName), cmdId(_cmdId), ticks(0) : ProtocolItem("cmd", _itemName), ticks(0)
{ {
if (cmdId == -1) if (_cmdId == -1)
cmdId = lastCmdId++; _cmdId = lastCmdId++;
setParameter("cmd_id", cmdId); insertItem(new SerializableItem_Int("cmd_id", _cmdId));
}
void Command::extractParameters()
{
bool ok;
cmdId = parameters["cmd_id"].toInt(&ok);
if (!ok)
cmdId = -1;
} }
void Command::processResponse(ProtocolResponse *response) void Command::processResponse(ProtocolResponse *response)
@ -108,99 +95,40 @@ void Command::processResponse(ProtocolResponse *response)
} }
Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path) Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path)
: Command("deck_upload"), deck(_deck), path(_path), readFinished(false) : Command("deck_upload")
{ {
setParameter("path", path); insertItem(new SerializableItem_String("path", _path));
if (!_deck)
_deck = new DeckList;
insertItem(_deck);
} }
void Command_DeckUpload::extractParameters() DeckList *Command_DeckUpload::getDeck() const
{ {
Command::extractParameters(); return static_cast<DeckList *>(itemMap.value("cockatrice_deck"));
path = parameters["path"];
}
bool Command_DeckUpload::readElement(QXmlStreamReader *xml)
{
if (readFinished)
return false;
if (!deck) {
if (xml->isStartElement() && (xml->name() == "cockatrice_deck")) {
deck = new DeckList;
return true;
}
return false;
}
if (deck->readElement(xml))
readFinished = true;
return true;
}
void Command_DeckUpload::writeElement(QXmlStreamWriter *xml)
{
if (deck)
deck->writeElement(xml);
} }
Command_DeckSelect::Command_DeckSelect(int _gameId, DeckList *_deck, int _deckId) Command_DeckSelect::Command_DeckSelect(int _gameId, DeckList *_deck, int _deckId)
: GameCommand("deck_select", _gameId), deck(_deck), deckId(_deckId), readFinished(false) : GameCommand("deck_select", _gameId)
{ {
setParameter("deck_id", _deckId); insertItem(new SerializableItem_Int("deck_id", _deckId));
if (!_deck)
_deck = new DeckList;
insertItem(_deck);
} }
void Command_DeckSelect::extractParameters() DeckList *Command_DeckSelect::getDeck() const
{ {
GameCommand::extractParameters(); return static_cast<DeckList *>(itemMap.value("cockatrice_deck"));
bool ok;
deckId = parameters["deck_id"].toInt(&ok);
if (!ok)
deckId = -1;
}
bool Command_DeckSelect::readElement(QXmlStreamReader *xml)
{
if (readFinished)
return false;
if (!deck) {
if (xml->isStartElement() && (xml->name() == "cockatrice_deck")) {
deck = new DeckList;
return true;
}
return false;
}
if (deck->readElement(xml))
readFinished = true;
return true;
}
void Command_DeckSelect::writeElement(QXmlStreamWriter *xml)
{
if (deck)
deck->writeElement(xml);
} }
QHash<QString, ResponseCode> ProtocolResponse::responseHash; QHash<QString, ResponseCode> ProtocolResponse::responseHash;
ProtocolResponse::ProtocolResponse(int _cmdId, ResponseCode _responseCode, const QString &_itemName) ProtocolResponse::ProtocolResponse(int _cmdId, ResponseCode _responseCode, const QString &_itemName)
: ProtocolItem(_itemName), cmdId(_cmdId), responseCode(_responseCode) : ProtocolItem("resp", _itemName)
{ {
setParameter("cmd_id", cmdId); insertItem(new SerializableItem_Int("cmd_id", _cmdId));
setParameter("response_code", responseHash.key(responseCode)); insertItem(new SerializableItem_String("response_code", responseHash.key(_responseCode)));
}
void ProtocolResponse::extractParameters()
{
bool ok;
cmdId = parameters["cmd_id"].toInt(&ok);
if (!ok)
cmdId = -1;
responseCode = responseHash.value(parameters["response_code"], RespOk);
} }
void ProtocolResponse::initializeHash() void ProtocolResponse::initializeHash()
@ -215,359 +143,93 @@ void ProtocolResponse::initializeHash()
} }
Response_DeckList::Response_DeckList(int _cmdId, ResponseCode _responseCode, DeckList_Directory *_root) Response_DeckList::Response_DeckList(int _cmdId, ResponseCode _responseCode, DeckList_Directory *_root)
: ProtocolResponse(_cmdId, _responseCode, "deck_list"), root(_root), readFinished(false) : ProtocolResponse(_cmdId, _responseCode, "deck_list")
{ {
} if (!_root)
_root = new DeckList_Directory;
Response_DeckList::~Response_DeckList() insertItem(_root);
{
delete root;
}
bool Response_DeckList::readElement(QXmlStreamReader *xml)
{
if (readFinished)
return false;
if (!root) {
if (xml->isStartElement() && (xml->name() == "directory")) {
root = new DeckList_Directory;
return true;
}
return false;
}
if (root->readElement(xml))
readFinished = true;
return true;
}
void Response_DeckList::writeElement(QXmlStreamWriter *xml)
{
root->writeElement(xml);
} }
Response_DeckDownload::Response_DeckDownload(int _cmdId, ResponseCode _responseCode, DeckList *_deck) Response_DeckDownload::Response_DeckDownload(int _cmdId, ResponseCode _responseCode, DeckList *_deck)
: ProtocolResponse(_cmdId, _responseCode, "deck_download"), deck(_deck), readFinished(false) : ProtocolResponse(_cmdId, _responseCode, "deck_download")
{ {
if (!_deck)
_deck = new DeckList;
insertItem(_deck);
} }
bool Response_DeckDownload::readElement(QXmlStreamReader *xml) DeckList *Response_DeckDownload::getDeck() const
{ {
if (readFinished) return static_cast<DeckList *>(itemMap.value("cockatrice_deck"));
return false;
if (!deck) {
if (xml->isStartElement() && (xml->name() == "cockatrice_deck")) {
deck = new DeckList;
return true;
}
return false;
}
if (deck->readElement(xml))
readFinished = true;
return true;
}
void Response_DeckDownload::writeElement(QXmlStreamWriter *xml)
{
if (deck)
deck->writeElement(xml);
} }
Response_DeckUpload::Response_DeckUpload(int _cmdId, ResponseCode _responseCode, DeckList_File *_file) Response_DeckUpload::Response_DeckUpload(int _cmdId, ResponseCode _responseCode, DeckList_File *_file)
: ProtocolResponse(_cmdId, _responseCode, "deck_upload"), file(_file), readFinished(false) : ProtocolResponse(_cmdId, _responseCode, "deck_upload")
{ {
} if (!_file)
_file = new DeckList_File;
Response_DeckUpload::~Response_DeckUpload() insertItem(_file);
{
delete file;
}
bool Response_DeckUpload::readElement(QXmlStreamReader *xml)
{
if (readFinished)
return false;
if (!file) {
if (xml->isStartElement() && (xml->name() == "file")) {
file = new DeckList_File(xml->attributes().value("name").toString(), xml->attributes().value("id").toString().toInt(), QDateTime::fromTime_t(xml->attributes().value("upload_time").toString().toUInt()));
return true;
}
return false;
}
if (file->readElement(xml))
readFinished = true;
return true;
}
void Response_DeckUpload::writeElement(QXmlStreamWriter *xml)
{
if (file)
file->writeElement(xml);
}
GenericEvent::GenericEvent(const QString &_eventName)
: ProtocolItem(_eventName)
{
}
void GameEvent::extractParameters()
{
bool ok;
gameId = parameters["game_id"].toInt(&ok);
if (!ok)
gameId = -1;
playerId = parameters["player_id"].toInt(&ok);
if (!ok)
playerId = -1;
} }
GameEvent::GameEvent(const QString &_eventName, int _gameId, int _playerId) GameEvent::GameEvent(const QString &_eventName, int _gameId, int _playerId)
: ProtocolItem(_eventName), gameId(_gameId), playerId(_playerId) : ProtocolItem("game_event", _eventName)
{ {
setParameter("game_id", gameId); insertItem(new SerializableItem_Int("game_id", _gameId));
setParameter("player_id", playerId); insertItem(new SerializableItem_Int("player_id", _playerId));
}
void ChatEvent::extractParameters()
{
channel = parameters["channel"];
} }
ChatEvent::ChatEvent(const QString &_eventName, const QString &_channel) ChatEvent::ChatEvent(const QString &_eventName, const QString &_channel)
: ProtocolItem(_eventName), channel(_channel) : ProtocolItem("chat_event", _eventName)
{ {
setParameter("channel", channel); insertItem(new SerializableItem_String("channel", _channel));
} }
bool Event_ListChatChannels::readElement(QXmlStreamReader *xml) Event_ListChatChannels::Event_ListChatChannels(const QList<ServerInfo_ChatChannel *> &_channelList)
: GenericEvent("list_chat_channels")
{ {
if (xml->isStartElement() && (xml->name() == "channel")) { for (int i = 0; i < _channelList.size(); ++i)
channelList.append(ServerChatChannelInfo( itemList.append(_channelList[i]);
xml->attributes().value("name").toString(),
xml->attributes().value("description").toString(),
xml->attributes().value("player_count").toString().toInt(),
xml->attributes().value("auto_join").toString().toInt()
));
return true;
}
return false;
} }
void Event_ListChatChannels::writeElement(QXmlStreamWriter *xml) Event_ChatListPlayers::Event_ChatListPlayers(const QString &_channel, const QList<ServerInfo_ChatUser *> &_playerList)
: ChatEvent("chat_list_players", _channel)
{ {
for (int i = 0; i < channelList.size(); ++i) { for (int i = 0; i < _playerList.size(); ++i)
xml->writeStartElement("channel"); itemList.append(_playerList[i]);
xml->writeAttribute("name", channelList[i].getName());
xml->writeAttribute("description", channelList[i].getDescription());
xml->writeAttribute("player_count", QString::number(channelList[i].getPlayerCount()));
xml->writeAttribute("auto_join", channelList[i].getAutoJoin() ? "1" : "0");
xml->writeEndElement();
}
} }
bool Event_ChatListPlayers::readElement(QXmlStreamReader *xml) Event_ListGames::Event_ListGames(const QList<ServerInfo_Game *> &_gameList)
: GenericEvent("list_games")
{ {
if (xml->isStartElement() && ((xml->name() == "player"))) { for (int i = 0; i < _gameList.size(); ++i)
playerList.append(ServerChatUserInfo( itemList.append(_gameList[i]);
xml->attributes().value("name").toString()
));
return true;
}
return false;
}
void Event_ChatListPlayers::writeElement(QXmlStreamWriter *xml)
{
for (int i = 0; i < playerList.size(); ++i) {
xml->writeStartElement("player");
xml->writeAttribute("name", playerList[i].getName());
xml->writeEndElement();
}
}
bool Event_ListGames::readElement(QXmlStreamReader *xml)
{
if (xml->isStartElement() && (xml->name() == "game")) {
gameList.append(ServerGameInfo(
xml->attributes().value("id").toString().toInt(),
xml->attributes().value("description").toString(),
xml->attributes().value("has_password").toString().toInt(),
xml->attributes().value("player_count").toString().toInt(),
xml->attributes().value("max_players").toString().toInt(),
xml->attributes().value("creator").toString(),
xml->attributes().value("spectators_allowed").toString().toInt(),
xml->attributes().value("spectator_count").toString().toInt()
));
return true;
}
return false;
}
void Event_ListGames::writeElement(QXmlStreamWriter *xml)
{
for (int i = 0; i < gameList.size(); ++i) {
xml->writeStartElement("game");
xml->writeAttribute("id", QString::number(gameList[i].getGameId()));
xml->writeAttribute("description", gameList[i].getDescription());
xml->writeAttribute("has_password", gameList[i].getHasPassword() ? "1" : "0");
xml->writeAttribute("player_count", QString::number(gameList[i].getPlayerCount()));
xml->writeAttribute("max_players", QString::number(gameList[i].getMaxPlayers()));
xml->writeAttribute("creator", gameList[i].getCreatorName());
xml->writeAttribute("spectators_allowed", gameList[i].getSpectatorsAllowed() ? "1" : "0");
xml->writeAttribute("spectator_count", QString::number(gameList[i].getSpectatorCount()));
xml->writeEndElement();
}
} }
Event_GameStateChanged::Event_GameStateChanged(int _gameId, const QList<ServerInfo_Player *> &_playerList) Event_GameStateChanged::Event_GameStateChanged(int _gameId, const QList<ServerInfo_Player *> &_playerList)
: GameEvent("game_state_changed", _gameId, -1), currentItem(0), playerList(_playerList) : GameEvent("game_state_changed", _gameId, -1)
{ {
for (int i = 0; i < _playerList.size(); ++i)
itemList.append(_playerList[i]);
} }
Event_GameStateChanged::~Event_GameStateChanged() Event_CreateArrows::Event_CreateArrows(int _gameId, int _playerId, const QList<ServerInfo_Arrow *> &_arrowList)
: GameEvent("create_arrows", _gameId, _playerId)
{ {
for (int i = 0; i < playerList.size(); ++i) for (int i = 0; i < _arrowList.size(); ++i)
delete playerList[i]; itemList.append(_arrowList[i]);
} }
bool Event_GameStateChanged::readElement(QXmlStreamReader *xml) Event_CreateCounters::Event_CreateCounters(int _gameId, int _playerId, const QList<ServerInfo_Counter *> &_counterList)
: GameEvent("create_counters", _gameId, _playerId)
{ {
if (currentItem) { for (int i = 0; i < _counterList.size(); ++i)
if (currentItem->readElement(xml)) itemList.append(_counterList[i]);
currentItem = 0;
return true;
}
if (xml->isStartElement() && (xml->name() == "player")) {
ServerInfo_Player *player = new ServerInfo_Player;
playerList.append(player);
currentItem = player;
} else
return false;
if (currentItem)
if (currentItem->readElement(xml))
currentItem = 0;
return true;
}
void Event_GameStateChanged::writeElement(QXmlStreamWriter *xml)
{
for (int i = 0; i < playerList.size(); ++i)
playerList[i]->writeElement(xml);
}
Event_CreateArrow::Event_CreateArrow(int _gameId, int _playerId, ServerInfo_Arrow *_arrow)
: GameEvent("create_arrow", _gameId, _playerId), arrow(_arrow), readFinished(false)
{
}
Event_CreateArrow::~Event_CreateArrow()
{
delete arrow;
}
bool Event_CreateArrow::readElement(QXmlStreamReader *xml)
{
if (readFinished)
return false;
if (!arrow) {
if (xml->isStartElement() && (xml->name() == "arrow"))
arrow = new ServerInfo_Arrow;
else
return false;
}
if (arrow->readElement(xml))
readFinished = true;
return true;
}
void Event_CreateArrow::writeElement(QXmlStreamWriter *xml)
{
if (arrow)
arrow->writeElement(xml);
}
Event_CreateCounter::Event_CreateCounter(int _gameId, int _playerId, ServerInfo_Counter *_counter)
: GameEvent("create_counter", _gameId, _playerId), counter(_counter), readFinished(false)
{
}
Event_CreateCounter::~Event_CreateCounter()
{
delete counter;
}
bool Event_CreateCounter::readElement(QXmlStreamReader *xml)
{
if (readFinished)
return false;
if (!counter) {
if (xml->isStartElement() && (xml->name() == "counter"))
counter = new ServerInfo_Counter;
else
return false;
}
if (counter->readElement(xml))
readFinished = true;
return true;
}
void Event_CreateCounter::writeElement(QXmlStreamWriter *xml)
{
if (counter)
counter->writeElement(xml);
} }
Event_DrawCards::Event_DrawCards(int _gameId, int _playerId, int _numberCards, const QList<ServerInfo_Card *> &_cardList) Event_DrawCards::Event_DrawCards(int _gameId, int _playerId, int _numberCards, const QList<ServerInfo_Card *> &_cardList)
: GameEvent("draw_cards", _gameId, _playerId), currentItem(0), numberCards(_numberCards), cardList(_cardList) : GameEvent("draw_cards", _gameId, _playerId)
{ {
setParameter("number_cards", numberCards); insertItem(new SerializableItem_Int("number_cards", _numberCards));
} for (int i = 0; i < _cardList.size(); ++i)
itemList.append(_cardList[i]);
Event_DrawCards::~Event_DrawCards()
{
for (int i = 0; i < cardList.size(); ++i)
delete cardList[i];
}
void Event_DrawCards::extractParameters()
{
GameEvent::extractParameters();
bool ok;
numberCards = parameters["number_cards"].toInt(&ok);
if (!ok)
numberCards = -1;
}
bool Event_DrawCards::readElement(QXmlStreamReader *xml)
{
if (currentItem) {
if (currentItem->readElement(xml))
currentItem = 0;
return true;
}
if (xml->isStartElement() && (xml->name() == "card")) {
ServerInfo_Card *card = new ServerInfo_Card;
cardList.append(card);
currentItem = card;
} else
return false;
if (currentItem)
if (currentItem->readElement(xml))
currentItem = 0;
return true;
}
void Event_DrawCards::writeElement(QXmlStreamWriter *xml)
{
for (int i = 0; i < cardList.size(); ++i)
cardList[i]->writeElement(xml);
} }

View file

@ -23,43 +23,44 @@ enum ItemId {
ItemId_Event_ChatListPlayers = ItemId_Other + 201, ItemId_Event_ChatListPlayers = ItemId_Other + 201,
ItemId_Event_ListGames = ItemId_Other + 202, ItemId_Event_ListGames = ItemId_Other + 202,
ItemId_Event_GameStateChanged = ItemId_Other + 203, ItemId_Event_GameStateChanged = ItemId_Other + 203,
ItemId_Event_CreateArrow = ItemId_Other + 204, ItemId_Event_CreateArrows = ItemId_Other + 204,
ItemId_Event_CreateCounter = ItemId_Other + 205, ItemId_Event_CreateCounters = ItemId_Other + 205,
ItemId_Event_DrawCards = ItemId_Other + 206, ItemId_Event_DrawCards = ItemId_Other + 206,
ItemId_Response_DeckList = ItemId_Other + 300, ItemId_Response_DeckList = ItemId_Other + 300,
ItemId_Response_DeckDownload = ItemId_Other + 301, ItemId_Response_DeckDownload = ItemId_Other + 301,
ItemId_Response_DeckUpload = ItemId_Other + 302 ItemId_Response_DeckUpload = ItemId_Other + 302,
ItemId_Invalid = ItemId_Other + 1000
}; };
class ProtocolItem : public QObject { class ProtocolItem : public SerializableItem_Map {
Q_OBJECT Q_OBJECT
private:
QString currentElementText;
protected:
typedef ProtocolItem *(*NewItemFunction)();
static QHash<QString, NewItemFunction> itemNameHash;
QString itemName;
QMap<QString, QString> parameters;
void setParameter(const QString &name, const QString &value) { parameters[name] = value; }
void setParameter(const QString &name, bool value) { parameters[name] = (value ? "1" : "0"); }
void setParameter(const QString &name, int value) { parameters[name] = QString::number(value); }
void setParameter(const QString &name, const QColor &value) { parameters[name] = QString::number(ColorConverter::colorToInt(value)); }
virtual void extractParameters() { }
virtual QString getItemType() const = 0;
virtual bool readElement(QXmlStreamReader * /*xml*/) { return false; }
virtual void writeElement(QXmlStreamWriter * /*xml*/) { }
private: private:
static void initializeHashAuto(); static void initializeHashAuto();
public: public:
static const int protocolVersion = 4; static const int protocolVersion = 5;
virtual int getItemId() const = 0;
ProtocolItem(const QString &_itemName);
static void initializeHash(); static void initializeHash();
static ProtocolItem *getNewItem(const QString &name); virtual int getItemId() const = 0;
bool read(QXmlStreamReader *xml); ProtocolItem(const QString &_itemType, const QString &_itemSubType);
void write(QXmlStreamWriter *xml); };
class ProtocolItem_Invalid : public ProtocolItem {
public:
ProtocolItem_Invalid() : ProtocolItem(QString(), QString()) { }
int getItemId() const { return ItemId_Invalid; }
};
class TopLevelProtocolItem : public SerializableItem {
Q_OBJECT
signals:
void protocolItemReceived(ProtocolItem *item);
private:
ProtocolItem *currentItem;
bool readCurrentItem(QXmlStreamReader *xml);
protected:
void readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public:
TopLevelProtocolItem();
}; };
// ---------------- // ----------------
@ -72,106 +73,59 @@ signals:
void finished(ProtocolResponse *response); void finished(ProtocolResponse *response);
void finished(ResponseCode response); void finished(ResponseCode response);
private: private:
int cmdId;
int ticks; int ticks;
static int lastCmdId; static int lastCmdId;
QVariant extraData; QVariant extraData;
protected:
QString getItemType() const { return "cmd"; }
void extractParameters();
public: public:
Command(const QString &_itemName = QString(), int _cmdId = -1); Command(const QString &_itemName = QString(), int _cmdId = -1);
int getCmdId() const { return cmdId; } int getCmdId() const { return static_cast<SerializableItem_Int *>(itemMap.value("cmd_id"))->getData(); }
int tick() { return ++ticks; } int tick() { return ++ticks; }
void processResponse(ProtocolResponse *response); void processResponse(ProtocolResponse *response);
void setExtraData(const QVariant &_extraData) { extraData = _extraData; } void setExtraData(const QVariant &_extraData) { extraData = _extraData; }
QVariant getExtraData() const { return extraData; } QVariant getExtraData() const { return extraData; }
}; };
class InvalidCommand : public Command {
Q_OBJECT
public:
InvalidCommand() : Command() { }
int getItemId() const { return ItemId_Other; }
};
class ChatCommand : public Command { class ChatCommand : public Command {
Q_OBJECT Q_OBJECT
private:
QString channel;
protected:
void extractParameters()
{
Command::extractParameters();
channel = parameters["channel"];
}
public: public:
ChatCommand(const QString &_cmdName, const QString &_channel) ChatCommand(const QString &_cmdName, const QString &_channel)
: Command(_cmdName), channel(_channel) : Command(_cmdName)
{ {
setParameter("channel", channel); insertItem(new SerializableItem_String("channel", _channel));
} }
QString getChannel() const { return channel; } QString getChannel() const { return static_cast<SerializableItem_String *>(itemMap.value("channel"))->getData(); }
}; };
class GameCommand : public Command { class GameCommand : public Command {
Q_OBJECT Q_OBJECT
private:
int gameId;
protected:
void extractParameters()
{
Command::extractParameters();
gameId = parameters["game_id"].toInt();
}
public: public:
GameCommand(const QString &_cmdName, int _gameId) GameCommand(const QString &_cmdName, int _gameId)
: Command(_cmdName), gameId(_gameId) : Command(_cmdName)
{ {
setParameter("game_id", gameId); insertItem(new SerializableItem_Int("game_id", _gameId));
}
int getGameId() const { return gameId; }
void setGameId(int _gameId)
{
gameId = _gameId;
setParameter("game_id", gameId);
} }
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
void setGameId(int _gameId) { static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->setData(_gameId); }
}; };
class Command_DeckUpload : public Command { class Command_DeckUpload : public Command {
Q_OBJECT Q_OBJECT
private:
DeckList *deck;
QString path;
bool readFinished;
protected:
void extractParameters();
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public: public:
Command_DeckUpload(DeckList *_deck = 0, const QString &_path = QString()); Command_DeckUpload(DeckList *_deck = 0, const QString &_path = QString());
static ProtocolItem *newItem() { return new Command_DeckUpload; } static SerializableItem *newItem() { return new Command_DeckUpload; }
int getItemId() const { return ItemId_Command_DeckUpload; } int getItemId() const { return ItemId_Command_DeckUpload; }
DeckList *getDeck() const { return deck; } DeckList *getDeck() const;
QString getPath() const { return path; } QString getPath() const { return static_cast<SerializableItem_String *>(itemMap.value("path"))->getData(); }
}; };
class Command_DeckSelect : public GameCommand { class Command_DeckSelect : public GameCommand {
Q_OBJECT Q_OBJECT
private:
DeckList *deck;
int deckId;
bool readFinished;
protected:
void extractParameters();
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public: public:
Command_DeckSelect(int _gameId = -1, DeckList *_deck = 0, int _deckId = -1); Command_DeckSelect(int _gameId = -1, DeckList *_deck = 0, int _deckId = -1);
static ProtocolItem *newItem() { return new Command_DeckSelect; } static SerializableItem *newItem() { return new Command_DeckSelect; }
int getItemId() const { return ItemId_Command_DeckSelect; } int getItemId() const { return ItemId_Command_DeckSelect; }
DeckList *getDeck() const { return deck; } DeckList *getDeck() const;
int getDeckId() const { return deckId; } int getDeckId() const { return static_cast<SerializableItem_Int *>(itemMap.value("deck_id"))->getData(); }
}; };
// ----------------- // -----------------
@ -181,66 +135,41 @@ public:
class ProtocolResponse : public ProtocolItem { class ProtocolResponse : public ProtocolItem {
Q_OBJECT Q_OBJECT
private: private:
int cmdId;
ResponseCode responseCode;
static QHash<QString, ResponseCode> responseHash; static QHash<QString, ResponseCode> responseHash;
protected:
QString getItemType() const { return "resp"; }
void extractParameters();
public: public:
ProtocolResponse(int _cmdId = -1, ResponseCode _responseCode = RespOk, const QString &_itemName = QString()); ProtocolResponse(int _cmdId = -1, ResponseCode _responseCode = RespOk, const QString &_itemName = QString());
int getItemId() const { return ItemId_Other; } int getItemId() const { return ItemId_Other; }
static void initializeHash(); static void initializeHash();
static ProtocolItem *newItem() { return new ProtocolResponse; } static SerializableItem *newItem() { return new ProtocolResponse; }
int getCmdId() const { return cmdId; } int getCmdId() const { return static_cast<SerializableItem_Int *>(itemMap.value("cmd_id"))->getData(); }
ResponseCode getResponseCode() const { return responseCode; } ResponseCode getResponseCode() const { return responseHash.value(static_cast<SerializableItem_String *>(itemMap.value("response_code"))->getData(), RespOk); }
}; };
class Response_DeckList : public ProtocolResponse { class Response_DeckList : public ProtocolResponse {
Q_OBJECT Q_OBJECT
private:
DeckList_Directory *root;
bool readFinished;
protected:
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public: public:
Response_DeckList(int _cmdId = -1, ResponseCode _responseCode = RespOk, DeckList_Directory *_root = 0); Response_DeckList(int _cmdId = -1, ResponseCode _responseCode = RespOk, DeckList_Directory *_root = 0);
~Response_DeckList();
int getItemId() const { return ItemId_Response_DeckList; } int getItemId() const { return ItemId_Response_DeckList; }
static ProtocolItem *newItem() { return new Response_DeckList; } static SerializableItem *newItem() { return new Response_DeckList; }
DeckList_Directory *getRoot() const { return root; } DeckList_Directory *getRoot() const { return static_cast<DeckList_Directory *>(itemMap.value("directory")); }
}; };
class Response_DeckDownload : public ProtocolResponse { class Response_DeckDownload : public ProtocolResponse {
Q_OBJECT Q_OBJECT
private:
DeckList *deck;
bool readFinished;
protected:
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public: public:
Response_DeckDownload(int _cmdId = -1, ResponseCode _responseCode = RespOk, DeckList *_deck = 0); Response_DeckDownload(int _cmdId = -1, ResponseCode _responseCode = RespOk, DeckList *_deck = 0);
int getItemId() const { return ItemId_Response_DeckDownload; } int getItemId() const { return ItemId_Response_DeckDownload; }
static ProtocolItem *newItem() { return new Response_DeckDownload; } static SerializableItem *newItem() { return new Response_DeckDownload; }
DeckList *getDeck() const { return deck; } DeckList *getDeck() const;
}; };
class Response_DeckUpload : public ProtocolResponse { class Response_DeckUpload : public ProtocolResponse {
Q_OBJECT Q_OBJECT
private:
DeckList_File *file;
bool readFinished;
protected:
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public: public:
Response_DeckUpload(int _cmdId = -1, ResponseCode _responseCode = RespOk, DeckList_File *_file = 0); Response_DeckUpload(int _cmdId = -1, ResponseCode _responseCode = RespOk, DeckList_File *_file = 0);
~Response_DeckUpload();
int getItemId() const { return ItemId_Response_DeckUpload; } int getItemId() const { return ItemId_Response_DeckUpload; }
static ProtocolItem *newItem() { return new Response_DeckUpload; } static SerializableItem *newItem() { return new Response_DeckUpload; }
DeckList_File *getFile() const { return file; } DeckList_File *getFile() const { return static_cast<DeckList_File *>(itemMap.value("file")); }
}; };
// -------------- // --------------
@ -249,162 +178,89 @@ public:
class GenericEvent : public ProtocolItem { class GenericEvent : public ProtocolItem {
Q_OBJECT Q_OBJECT
protected:
QString getItemType() const { return "generic_event"; }
public: public:
GenericEvent(const QString &_eventName); GenericEvent(const QString &_eventName)
: ProtocolItem("generic_event", _eventName) { }
}; };
class GameEvent : public ProtocolItem { class GameEvent : public ProtocolItem {
Q_OBJECT Q_OBJECT
private:
int gameId;
int playerId;
protected:
QString getItemType() const { return "game_event"; }
void extractParameters();
public: public:
GameEvent(const QString &_eventName, int _gameId, int _playerId); GameEvent(const QString &_eventName, int _gameId, int _playerId);
int getGameId() const { return gameId; } int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
int getPlayerId() const { return playerId; } int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); }
void setGameId(int _gameId) void setGameId(int _gameId) { static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->setData(_gameId); }
{
gameId = _gameId;
setParameter("game_id", gameId);
}
}; };
class ChatEvent : public ProtocolItem { class ChatEvent : public ProtocolItem {
Q_OBJECT Q_OBJECT
private:
QString channel;
protected:
QString getItemType() const { return "chat_event"; }
void extractParameters();
public: public:
ChatEvent(const QString &_eventName, const QString &_channel); ChatEvent(const QString &_eventName, const QString &_channel);
QString getChannel() const { return channel; } QString getChannel() const { return static_cast<SerializableItem_String *>(itemMap.value("channel"))->getData(); }
}; };
class Event_ListChatChannels : public GenericEvent { class Event_ListChatChannels : public GenericEvent {
Q_OBJECT Q_OBJECT
private:
QList<ServerChatChannelInfo> channelList;
public: public:
Event_ListChatChannels() : GenericEvent("list_chat_channels") { } Event_ListChatChannels(const QList<ServerInfo_ChatChannel *> &_channelList = QList<ServerInfo_ChatChannel *>());
int getItemId() const { return ItemId_Event_ListChatChannels; } int getItemId() const { return ItemId_Event_ListChatChannels; }
static ProtocolItem *newItem() { return new Event_ListChatChannels; } static SerializableItem *newItem() { return new Event_ListChatChannels; }
void addChannel(const QString &_name, const QString &_description, int _playerCount, bool _autoJoin) QList<ServerInfo_ChatChannel *> getChannelList() const { return typecastItemList<ServerInfo_ChatChannel *>(); }
{
channelList.append(ServerChatChannelInfo(_name, _description, _playerCount, _autoJoin));
}
const QList<ServerChatChannelInfo> &getChannelList() const { return channelList; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
}; };
class Event_ChatListPlayers : public ChatEvent { class Event_ChatListPlayers : public ChatEvent {
Q_OBJECT Q_OBJECT
private:
QList<ServerChatUserInfo> playerList;
public: public:
Event_ChatListPlayers(const QString &_channel = QString()) : ChatEvent("chat_list_players", _channel) { } Event_ChatListPlayers(const QString &_channel = QString(), const QList<ServerInfo_ChatUser *> &_playerList = QList<ServerInfo_ChatUser *>());
int getItemId() const { return ItemId_Event_ChatListPlayers; } int getItemId() const { return ItemId_Event_ChatListPlayers; }
static ProtocolItem *newItem() { return new Event_ChatListPlayers; } static SerializableItem *newItem() { return new Event_ChatListPlayers; }
void addPlayer(const QString &_name) QList<ServerInfo_ChatUser *> getPlayerList() const { return typecastItemList<ServerInfo_ChatUser *>(); }
{
playerList.append(ServerChatUserInfo(_name));
}
const QList<ServerChatUserInfo> &getPlayerList() const { return playerList; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
}; };
class Event_ListGames : public GenericEvent { class Event_ListGames : public GenericEvent {
Q_OBJECT Q_OBJECT
private:
QList<ServerGameInfo> gameList;
public: public:
Event_ListGames() : GenericEvent("list_games") { } Event_ListGames(const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>());
int getItemId() const { return ItemId_Event_ListGames; } int getItemId() const { return ItemId_Event_ListGames; }
static ProtocolItem *newItem() { return new Event_ListGames; } static SerializableItem *newItem() { return new Event_ListGames; }
void addGame(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QString &_creatorName, bool _spectatorsAllowed, int _spectatorCount) QList<ServerInfo_Game *> getGameList() const { return typecastItemList<ServerInfo_Game *>(); }
{
gameList.append(ServerGameInfo(_gameId, _description, _hasPassword, _playerCount, _maxPlayers, _creatorName, _spectatorsAllowed, _spectatorCount));
}
const QList<ServerGameInfo> &getGameList() const { return gameList; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
}; };
class Event_GameStateChanged : public GameEvent { class Event_GameStateChanged : public GameEvent {
Q_OBJECT Q_OBJECT
private:
SerializableItem *currentItem;
QList<ServerInfo_Player *> playerList;
public: public:
Event_GameStateChanged(int _gameId = -1, const QList<ServerInfo_Player *> &_playerList = QList<ServerInfo_Player *>()); Event_GameStateChanged(int _gameId = -1, const QList<ServerInfo_Player *> &_playerList = QList<ServerInfo_Player *>());
~Event_GameStateChanged(); static SerializableItem *newItem() { return new Event_GameStateChanged; }
const QList<ServerInfo_Player *> &getPlayerList() const { return playerList; }
static ProtocolItem *newItem() { return new Event_GameStateChanged; }
int getItemId() const { return ItemId_Event_GameStateChanged; } int getItemId() const { return ItemId_Event_GameStateChanged; }
QList<ServerInfo_Player *> getPlayerList() const { return typecastItemList<ServerInfo_Player *>(); }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
}; };
class Event_CreateArrow : public GameEvent { class Event_CreateArrows : public GameEvent {
Q_OBJECT Q_OBJECT
private:
ServerInfo_Arrow *arrow;
bool readFinished;
protected:
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public: public:
Event_CreateArrow(int _gameId = -1, int _playerId = -1, ServerInfo_Arrow *_arrow = 0); Event_CreateArrows(int _gameId = -1, int _playerId = -1, const QList<ServerInfo_Arrow *> &_arrowList = QList<ServerInfo_Arrow *>());
~Event_CreateArrow(); int getItemId() const { return ItemId_Event_CreateArrows; }
int getItemId() const { return ItemId_Event_CreateArrow; } static SerializableItem *newItem() { return new Event_CreateArrows; }
static ProtocolItem *newItem() { return new Event_CreateArrow; } QList<ServerInfo_Arrow *> getArrowList() const { return typecastItemList<ServerInfo_Arrow *>(); }
ServerInfo_Arrow *getArrow() const { return arrow; }
}; };
class Event_CreateCounter : public GameEvent { class Event_CreateCounters : public GameEvent {
Q_OBJECT Q_OBJECT
private:
ServerInfo_Counter *counter;
bool readFinished;
protected:
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public: public:
Event_CreateCounter(int _gameId = -1, int _playerId = -1, ServerInfo_Counter *_counter = 0); Event_CreateCounters(int _gameId = -1, int _playerId = -1, const QList<ServerInfo_Counter *> &_counterList = QList<ServerInfo_Counter *>());
~Event_CreateCounter(); int getItemId() const { return ItemId_Event_CreateCounters; }
int getItemId() const { return ItemId_Event_CreateCounter; } static SerializableItem *newItem() { return new Event_CreateCounters; }
static ProtocolItem *newItem() { return new Event_CreateCounter; } QList<ServerInfo_Counter *> getCounterList() const { return typecastItemList<ServerInfo_Counter *>(); }
ServerInfo_Counter *getCounter() const { return counter; }
}; };
class Event_DrawCards : public GameEvent { class Event_DrawCards : public GameEvent {
Q_OBJECT Q_OBJECT
private:
SerializableItem *currentItem;
int numberCards;
QList<ServerInfo_Card *> cardList;
protected:
void extractParameters();
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public: public:
Event_DrawCards(int _gameId = -1, int _playerId = -1, int numberCards = -1, const QList<ServerInfo_Card *> &_cardList = QList<ServerInfo_Card *>()); Event_DrawCards(int _gameId = -1, int _playerId = -1, int numberCards = -1, const QList<ServerInfo_Card *> &_cardList = QList<ServerInfo_Card *>());
~Event_DrawCards();
int getItemId() const { return ItemId_Event_DrawCards; } int getItemId() const { return ItemId_Event_DrawCards; }
static ProtocolItem *newItem() { return new Event_DrawCards; } static SerializableItem *newItem() { return new Event_DrawCards; }
int getNumberCards() const { return numberCards; } int getNumberCards() const { return static_cast<SerializableItem_Int *>(itemMap.value("number_cards"))->getData(); }
const QList<ServerInfo_Card *> &getCardList() const { return cardList; } QList<ServerInfo_Card *> getCardList() const { return typecastItemList<ServerInfo_Card *>(); }
}; };
#endif #endif

View file

@ -2,244 +2,154 @@
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
ServerInfo_Player::~ServerInfo_Player() ServerInfo_ChatChannel::ServerInfo_ChatChannel(const QString &_name, const QString &_description, int _playerCount, bool _autoJoin)
: SerializableItem_Map("chat_channel")
{ {
for (int i = 0; i < zoneList.size(); ++i) insertItem(new SerializableItem_String("name", _name));
delete zoneList[i]; insertItem(new SerializableItem_String("description", _description));
for (int i = 0; i < arrowList.size(); ++i) insertItem(new SerializableItem_Int("player_count", _playerCount));
delete arrowList[i]; insertItem(new SerializableItem_Bool("auto_join", _autoJoin));
for (int i = 0; i < counterList.size(); ++i)
delete counterList[i];
} }
ServerInfo_Zone::~ServerInfo_Zone() ServerInfo_ChatUser::ServerInfo_ChatUser(const QString &_name)
: SerializableItem_Map("chat_user")
{ {
for (int i = 0; i < cardList.size(); ++i) insertItem(new SerializableItem_String("name", _name));
delete cardList[i];
} }
bool ServerInfo_Arrow::readElement(QXmlStreamReader *xml) ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QString &_creatorName, bool _spectatorsAllowed, int _spectatorCount)
: SerializableItem_Map("game")
{ {
if (xml->isStartElement() && (xml->name() == "arrow")) { insertItem(new SerializableItem_Int("game_id", _gameId));
id = xml->attributes().value("id").toString().toInt(); insertItem(new SerializableItem_String("description", _description));
startPlayerId = xml->attributes().value("start_player_id").toString().toInt(); insertItem(new SerializableItem_Bool("has_password", _hasPassword));
startZone = xml->attributes().value("start_zone").toString(); insertItem(new SerializableItem_Int("player_count", _playerCount));
startCardId = xml->attributes().value("start_card_id").toString().toInt(); insertItem(new SerializableItem_Int("max_players", _maxPlayers));
targetPlayerId = xml->attributes().value("target_player_id").toString().toInt(); insertItem(new SerializableItem_String("creator_name", _creatorName));
targetZone = xml->attributes().value("target_zone").toString(); insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
targetCardId = xml->attributes().value("target_card_id").toString().toInt(); insertItem(new SerializableItem_Int("spectator_count", _spectatorCount));
color = ColorConverter::colorFromInt(xml->attributes().value("color").toString().toInt());
} else if (xml->isEndElement() && (xml->name() == "arrow"))
return true;
return false;
} }
void ServerInfo_Arrow::writeElement(QXmlStreamWriter *xml) ServerInfo_Card::ServerInfo_Card(int _id, const QString &_name, int _x, int _y, int _counters, bool _tapped, bool _attacking, const QString &_annotation)
: SerializableItem_Map("card")
{ {
xml->writeStartElement("arrow"); insertItem(new SerializableItem_Int("id", _id));
xml->writeAttribute("id", QString::number(id)); insertItem(new SerializableItem_String("name", _name));
xml->writeAttribute("start_player_id", QString::number(startPlayerId)); insertItem(new SerializableItem_Int("x", _x));
xml->writeAttribute("start_zone", startZone); insertItem(new SerializableItem_Int("y", _y));
xml->writeAttribute("start_card_id", QString::number(startCardId)); insertItem(new SerializableItem_Int("counters", _counters));
xml->writeAttribute("target_player_id", QString::number(targetPlayerId)); insertItem(new SerializableItem_Bool("tapped", _tapped));
xml->writeAttribute("target_zone", targetZone); insertItem(new SerializableItem_Bool("attacking", _attacking));
xml->writeAttribute("target_card_id", QString::number(targetCardId)); insertItem(new SerializableItem_String("annotation", _annotation));
xml->writeAttribute("color", QString::number(ColorConverter::colorToInt(color)));
xml->writeEndElement();
} }
bool ServerInfo_Counter::readElement(QXmlStreamReader *xml) ServerInfo_Zone::ServerInfo_Zone(const QString &_name, ZoneType _type, bool _hasCoords, int _cardCount, const QList<ServerInfo_Card *> &_cardList)
: SerializableItem_Map("zone")
{ {
if (xml->isStartElement() && (xml->name() == "counter")) { insertItem(new SerializableItem_String("name", _name));
id = xml->attributes().value("id").toString().toInt(); insertItem(new SerializableItem_String("zone_type", typeToString(_type)));
name = xml->attributes().value("name").toString(); insertItem(new SerializableItem_Bool("has_coords", _hasCoords));
color = ColorConverter::colorFromInt(xml->attributes().value("color").toString().toInt()); insertItem(new SerializableItem_Int("card_count", _cardCount));
radius = xml->attributes().value("radius").toString().toInt();
count = xml->attributes().value("count").toString().toInt(); for (int i = 0; i < _cardList.size(); ++i)
} else if (xml->isEndElement() && (xml->name() == "counter")) itemList.append(_cardList[i]);
return true;
return false;
} }
void ServerInfo_Counter::writeElement(QXmlStreamWriter *xml) ZoneType ServerInfo_Zone::typeFromString(const QString &type) const
{ {
xml->writeStartElement("counter"); if (type == "private")
xml->writeAttribute("id", QString::number(id)); return PrivateZone;
xml->writeAttribute("name", name); else if (type == "hidden")
xml->writeAttribute("color", QString::number(ColorConverter::colorToInt(color))); return HiddenZone;
xml->writeAttribute("radius", QString::number(radius)); return PublicZone;
xml->writeAttribute("count", QString::number(count));
xml->writeEndElement();
} }
bool ServerInfo_Card::readElement(QXmlStreamReader *xml) QString ServerInfo_Zone::typeToString(ZoneType type) const
{ {
if (xml->isStartElement() && (xml->name() == "card")) {
id = xml->attributes().value("id").toString().toInt();
name = xml->attributes().value("name").toString();
x = xml->attributes().value("x").toString().toInt();
y = xml->attributes().value("y").toString().toInt();
counters = xml->attributes().value("counters").toString().toInt();
tapped = xml->attributes().value("tapped").toString().toInt();
attacking = xml->attributes().value("attacking").toString().toInt();
annotation = xml->attributes().value("annotation").toString();
} else if (xml->isEndElement() && (xml->name() == "card"))
return true;
return false;
}
void ServerInfo_Card::writeElement(QXmlStreamWriter *xml)
{
xml->writeStartElement("card");
xml->writeAttribute("id", QString::number(id));
xml->writeAttribute("name", name);
xml->writeAttribute("x", QString::number(x));
xml->writeAttribute("y", QString::number(y));
xml->writeAttribute("counters", QString::number(counters));
xml->writeAttribute("tapped", tapped ? "1" : "0");
xml->writeAttribute("attacking", attacking ? "1" : "0");
xml->writeAttribute("annotation", annotation);
xml->writeEndElement();
}
bool ServerInfo_Zone::readElement(QXmlStreamReader *xml)
{
if (currentItem) {
if (currentItem->readElement(xml))
currentItem = 0;
return false;
}
if (xml->isStartElement() && (xml->name() == "zone")) {
name = xml->attributes().value("name").toString();
type = (ZoneType) xml->attributes().value("type").toString().toInt();
hasCoords = xml->attributes().value("has_coords").toString().toInt();
cardCount = xml->attributes().value("card_count").toString().toInt();
} else if (xml->isStartElement() && (xml->name() == "card")) {
ServerInfo_Card *card = new ServerInfo_Card;
cardList.append(card);
currentItem = card;
} else if (xml->isEndElement() && (xml->name() == "zone"))
return true;
if (currentItem)
if (currentItem->readElement(xml))
currentItem = 0;
return false;
}
void ServerInfo_Zone::writeElement(QXmlStreamWriter *xml)
{
xml->writeStartElement("zone");
xml->writeAttribute("name", name);
QString typeStr;
switch (type) { switch (type) {
case PrivateZone: typeStr = "private"; break; case PrivateZone: return "private";
case HiddenZone: typeStr = "hidden"; break; case HiddenZone: return "hidden";
case PublicZone: typeStr = "public"; break; default: return "public";
} }
xml->writeAttribute("type", typeStr);
xml->writeAttribute("has_coords", hasCoords ? "1" : "0");
xml->writeAttribute("card_count", QString::number(cardCount));
for (int i = 0; i < cardList.size(); ++i)
cardList[i]->writeElement(xml);
xml->writeEndElement();
} }
bool ServerInfo_Player::readElement(QXmlStreamReader *xml) QList<ServerInfo_Card *> ServerInfo_Zone::getCardList() const
{ {
if (currentItem) { QList<ServerInfo_Card *> result;
if (currentItem->readElement(xml)) for (int i = 0; i < itemList.size(); ++i) {
currentItem = 0; ServerInfo_Card *card = dynamic_cast<ServerInfo_Card *>(itemList[i]);
return false; if (card)
result.append(card);
} }
if (xml->isStartElement() && (xml->name() == "player")) { return result;
playerId = xml->attributes().value("player_id").toString().toInt();
name = xml->attributes().value("name").toString();
} else if (xml->isStartElement() && (xml->name() == "zone")) {
ServerInfo_Zone *zone = new ServerInfo_Zone;
zoneList.append(zone);
currentItem = zone;
} else if (xml->isStartElement() && (xml->name() == "counter")) {
ServerInfo_Counter *counter = new ServerInfo_Counter;
counterList.append(counter);
currentItem = counter;
} else if (xml->isStartElement() && (xml->name() == "arrow")) {
ServerInfo_Arrow *arrow = new ServerInfo_Arrow;
arrowList.append(arrow);
currentItem = arrow;
} else if (xml->isEndElement() && (xml->name() == "player"))
return true;
if (currentItem)
if (currentItem->readElement(xml))
currentItem = 0;
return false;
} }
void ServerInfo_Player::writeElement(QXmlStreamWriter *xml) ServerInfo_Counter::ServerInfo_Counter(int _id, const QString &_name, const QColor &_color, int _radius, int _count)
: SerializableItem_Map("counter")
{ {
xml->writeStartElement("player"); insertItem(new SerializableItem_Int("id", _id));
xml->writeAttribute("player_id", QString::number(playerId)); insertItem(new SerializableItem_String("name", _name));
xml->writeAttribute("name", name); insertItem(new SerializableItem_Color("color", _color));
for (int i = 0; i < zoneList.size(); ++i) insertItem(new SerializableItem_Int("radius", _radius));
zoneList[i]->writeElement(xml); insertItem(new SerializableItem_Int("count", _count));
for (int i = 0; i < counterList.size(); ++i)
counterList[i]->writeElement(xml);
for (int i = 0; i < arrowList.size(); ++i)
arrowList[i]->writeElement(xml);
xml->writeEndElement();
} }
bool DeckList_File::readElement(QXmlStreamReader *xml) ServerInfo_Arrow::ServerInfo_Arrow(int _id, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const QColor &_color)
: SerializableItem_Map("arrow")
{ {
if (xml->isEndElement()) insertItem(new SerializableItem_Int("id", _id));
return true; insertItem(new SerializableItem_Int("start_player_id", _startPlayerId));
else insertItem(new SerializableItem_String("start_zone", _startZone));
return false; insertItem(new SerializableItem_Int("start_card_id", _startCardId));
insertItem(new SerializableItem_Int("target_player_id", _targetPlayerId));
insertItem(new SerializableItem_String("target_zone", _targetZone));
insertItem(new SerializableItem_Int("target_card_id", _targetCardId));
insertItem(new SerializableItem_Color("color", _color));
} }
void DeckList_File::writeElement(QXmlStreamWriter *xml) ServerInfo_Player::ServerInfo_Player(int _playerId, const QString &_name, const QList<ServerInfo_Zone *> &_zoneList, const QList<ServerInfo_Counter *> &_counterList, const QList<ServerInfo_Arrow *> &_arrowList)
: SerializableItem_Map("player"), zoneList(_zoneList), counterList(_counterList), arrowList(_arrowList)
{ {
xml->writeStartElement("file"); insertItem(new SerializableItem_Int("player_id", _playerId));
xml->writeAttribute("name", name); insertItem(new SerializableItem_String("name", _name));
xml->writeAttribute("id", QString::number(id));
xml->writeAttribute("upload_time", QString::number(uploadTime.toTime_t())); for (int i = 0; i < _zoneList.size(); ++i)
xml->writeEndElement(); itemList.append(_zoneList[i]);
for (int i = 0; i < _counterList.size(); ++i)
itemList.append(_counterList[i]);
for (int i = 0; i < _arrowList.size(); ++i)
itemList.append(_arrowList[i]);
} }
DeckList_Directory::~DeckList_Directory() void ServerInfo_Player::extractData()
{ {
for (int i = 0; i < size(); ++i) for (int i = 0; i < itemList.size(); ++i) {
delete at(i); ServerInfo_Zone *zone = dynamic_cast<ServerInfo_Zone *>(itemList[i]);
} ServerInfo_Counter *counter = dynamic_cast<ServerInfo_Counter *>(itemList[i]);
ServerInfo_Arrow *arrow = dynamic_cast<ServerInfo_Arrow *>(itemList[i]);
bool DeckList_Directory::readElement(QXmlStreamReader *xml) if (zone)
{ zoneList.append(zone);
if (currentItem) { else if (counter)
if (currentItem->readElement(xml)) counterList.append(counter);
currentItem = 0; else if (arrow)
return false; arrowList.append(arrow);
} }
if (xml->isStartElement() && (xml->name() == "directory")) {
DeckList_Directory *newItem = new DeckList_Directory(xml->attributes().value("name").toString());
append(newItem);
currentItem = newItem;
} else if (xml->isStartElement() && (xml->name() == "file")) {
DeckList_File *newItem = new DeckList_File(xml->attributes().value("name").toString(), xml->attributes().value("id").toString().toInt(), QDateTime::fromTime_t(xml->attributes().value("upload_time").toString().toUInt()));
append(newItem);
currentItem = newItem;
} else if (xml->isEndElement() && (xml->name() == "directory"))
return true;
return false;
} }
void DeckList_Directory::writeElement(QXmlStreamWriter *xml) DeckList_TreeItem::DeckList_TreeItem(const QString &_itemType, const QString &_name, int _id)
: SerializableItem_Map(_itemType)
{
insertItem(new SerializableItem_String("name", _name));
insertItem(new SerializableItem_Int("id", _id));
}
DeckList_File::DeckList_File(const QString &_name, int _id, QDateTime _uploadTime)
: DeckList_TreeItem("file", _name, _id)
{
insertItem(new SerializableItem_DateTime("upload_time", _uploadTime));
}
DeckList_Directory::DeckList_Directory(const QString &_name, int _id)
: DeckList_TreeItem("directory", _name, _id)
{ {
xml->writeStartElement("directory");
xml->writeAttribute("name", name);
for (int i = 0; i < size(); ++i)
at(i)->writeElement(xml);
xml->writeEndElement();
} }

View file

@ -4,9 +4,7 @@
#include <QString> #include <QString>
#include <QColor> #include <QColor>
#include <QDateTime> #include <QDateTime>
#include "serializable_item.h"
class QXmlStreamReader;
class QXmlStreamWriter;
enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespInvalidData, RespNameNotFound, RespLoginNeeded, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed }; enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespInvalidData, RespNameNotFound, RespLoginNeeded, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed };
@ -20,210 +18,124 @@ enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespInvalidData, Re
// list index, whereas cards in any other zone are referenced by their ids. // list index, whereas cards in any other zone are referenced by their ids.
enum ZoneType { PrivateZone, PublicZone, HiddenZone }; enum ZoneType { PrivateZone, PublicZone, HiddenZone };
class ColorConverter { class ServerInfo_ChatChannel : public SerializableItem_Map {
public: public:
static int colorToInt(const QColor &color) ServerInfo_ChatChannel(const QString &_name = QString(), const QString &_description = QString(), int _playerCount = -1, bool _autoJoin = false);
{ static SerializableItem *newItem() { return new ServerInfo_ChatChannel; }
return color.red() * 65536 + color.green() * 256 + color.blue(); QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
} QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
static QColor colorFromInt(int colorValue) int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); }
{ bool getAutoJoin() const { return static_cast<SerializableItem_Bool *>(itemMap.value("auto_join"))->getData(); }
return QColor(colorValue / 65536, (colorValue % 65536) / 256, colorValue % 256);
}
}; };
class SerializableItem { class ServerInfo_ChatUser : public SerializableItem_Map {
protected:
SerializableItem *currentItem;
public: public:
SerializableItem() : currentItem(0) { } ServerInfo_ChatUser(const QString &_name = QString());
virtual bool readElement(QXmlStreamReader *xml) = 0; static SerializableItem *newItem() { return new ServerInfo_ChatUser; }
virtual void writeElement(QXmlStreamWriter *xml) = 0; QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
}; };
class ServerChatChannelInfo { class ServerInfo_Game : public SerializableItem_Map {
public:
ServerInfo_Game(int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, const QString &_creatorName = QString(), bool _spectatorsAllowed = false, int _spectatorCount = -1);
static SerializableItem *newItem() { return new ServerInfo_Game; }
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
bool getHasPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("has_password"))->getData(); }
int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); }
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); }
QString getCreatorName() const { return static_cast<SerializableItem_String *>(itemMap.value("creator_name"))->getData(); }
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); }
int getSpectatorCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("spectator_count"))->getData(); }
};
class ServerInfo_Card : public SerializableItem_Map {
public:
ServerInfo_Card(int _id = -1, const QString &_name = QString(), int _x = -1, int _y = -1, int _counters = -1, bool _tapped = false, bool _attacking = false, const QString &_annotation = QString());
static SerializableItem *newItem() { return new ServerInfo_Card; }
int getId() const { return static_cast<SerializableItem_Int *>(itemMap.value("id"))->getData(); }
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); }
int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); }
int getCounters() const { return static_cast<SerializableItem_Int *>(itemMap.value("counters"))->getData(); }
bool getTapped() const { return static_cast<SerializableItem_Bool *>(itemMap.value("tapped"))->getData(); }
bool getAttacking() const { return static_cast<SerializableItem_Bool *>(itemMap.value("attacking"))->getData(); }
QString getAnnotation() const { return static_cast<SerializableItem_String *>(itemMap.value("annotation"))->getData(); }
};
class ServerInfo_Zone : public SerializableItem_Map {
private: private:
QString name; ZoneType typeFromString(const QString &type) const;
QString description; QString typeToString(ZoneType type) const;
int playerCount;
bool autoJoin;
public: public:
ServerChatChannelInfo(const QString &_name, const QString &_description, int _playerCount, bool _autoJoin) ServerInfo_Zone(const QString &_name = QString(), ZoneType _type = PrivateZone, bool _hasCoords = false, int _cardCount = -1, const QList<ServerInfo_Card *> &_cardList = QList<ServerInfo_Card *>());
: name(_name), description(_description), playerCount(_playerCount), autoJoin(_autoJoin) { } static SerializableItem *newItem() { return new ServerInfo_Zone; }
QString getName() const { return name; } QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
QString getDescription() const { return description; } ZoneType getType() const { return typeFromString(static_cast<SerializableItem_String *>(itemMap.value("type"))->getData()); }
int getPlayerCount() const { return playerCount; } bool getHasCoords() const { return static_cast<SerializableItem_Bool *>(itemMap.value("has_coords"))->getData(); }
bool getAutoJoin() const { return autoJoin; } int getCardCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_count"))->getData(); }
QList<ServerInfo_Card *> getCardList() const;
}; };
class ServerChatUserInfo { class ServerInfo_Counter : public SerializableItem_Map {
private:
QString name;
public: public:
ServerChatUserInfo(const QString &_name) ServerInfo_Counter(int _id = -1, const QString &_name = QString(), const QColor &_color = QColor(), int _radius = -1, int _count = -1);
: name(_name) { } static SerializableItem *newItem() { return new ServerInfo_Counter; }
QString getName() const { return name; } int getId() const { return static_cast<SerializableItem_Int *>(itemMap.value("id"))->getData(); }
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
QColor getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); }
int getRadius() const { return static_cast<SerializableItem_Int *>(itemMap.value("radius"))->getData(); }
int getCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("count"))->getData(); }
}; };
class ServerGameInfo { class ServerInfo_Arrow : public SerializableItem_Map {
private:
int gameId;
QString description;
bool hasPassword;
int playerCount;
int maxPlayers;
QString creatorName;
bool spectatorsAllowed;
int spectatorCount;
public: public:
ServerGameInfo(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QString &_creatorName, bool _spectatorsAllowed, int _spectatorCount) ServerInfo_Arrow(int _id = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const QColor &_color = QColor());
: gameId(_gameId), description(_description), hasPassword(_hasPassword), playerCount(_playerCount), maxPlayers(_maxPlayers), creatorName(_creatorName), spectatorsAllowed(_spectatorsAllowed), spectatorCount(_spectatorCount) { } static SerializableItem *newItem() { return new ServerInfo_Arrow; }
int getGameId() const { return gameId; } int getId() const { return static_cast<SerializableItem_Int *>(itemMap.value("id"))->getData(); }
QString getDescription() const { return description; } int getStartPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("start_player_id"))->getData(); }
bool getHasPassword() const { return hasPassword; } QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); }
int getPlayerCount() const { return playerCount; } int getStartCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("start_card_id"))->getData(); }
int getMaxPlayers() const { return maxPlayers; } int getTargetPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_player_id"))->getData(); }
QString getCreatorName() const { return creatorName; } QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); }
bool getSpectatorsAllowed() const { return spectatorsAllowed; } int getTargetCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_card_id"))->getData(); }
int getSpectatorCount() const { return spectatorCount; } QColor getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); }
}; };
class ServerInfo_Card : public SerializableItem { class ServerInfo_Player : public SerializableItem_Map {
private: private:
int id;
QString name;
int x, y;
int counters;
bool tapped;
bool attacking;
QString annotation;
public:
ServerInfo_Card(int _id = -1, const QString &_name = QString(), int _x = -1, int _y = -1, int _counters = -1, bool _tapped = false, bool _attacking = false, const QString &_annotation = QString())
: id(_id), name(_name), x(_x), y(_y), counters(_counters), tapped(_tapped), attacking(_attacking), annotation(_annotation) { }
int getId() const { return id; }
QString getName() const { return name; }
int getX() const { return x; }
int getY() const { return y; }
int getCounters() const { return counters; }
bool getTapped() const { return tapped; }
bool getAttacking() const { return attacking; }
QString getAnnotation() const { return annotation; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
};
class ServerInfo_Zone : public SerializableItem {
private:
QString name;
ZoneType type;
bool hasCoords;
int cardCount;
QList<ServerInfo_Card *> cardList;
public:
ServerInfo_Zone(const QString &_name = QString(), ZoneType _type = PrivateZone, bool _hasCoords = false, int _cardCount = -1, const QList<ServerInfo_Card *> &_cardList = QList<ServerInfo_Card *>())
: name(_name), type(_type), hasCoords(_hasCoords), cardCount(_cardCount), cardList(_cardList) { }
~ServerInfo_Zone();
QString getName() const { return name; }
ZoneType getType() const { return type; }
bool getHasCoords() const { return hasCoords; }
int getCardCount() const { return cardCount; }
const QList<ServerInfo_Card *> &getCardList() const { return cardList; }
void addCard(ServerInfo_Card *card) { cardList.append(card); ++cardCount; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
};
class ServerInfo_Counter : public SerializableItem {
private:
int id;
QString name;
QColor color;
int radius;
int count;
public:
ServerInfo_Counter(int _id = -1, const QString &_name = QString(), const QColor &_color = QColor(), int _radius = -1, int _count = -1)
: id(_id), name(_name), color(_color), radius(_radius), count(_count) { }
int getId() const { return id; }
QString getName() const { return name; }
QColor getColor() const { return color; }
int getRadius() const { return radius; }
int getCount() const { return count; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
};
class ServerInfo_Arrow : public SerializableItem {
private:
int id;
int startPlayerId;
QString startZone;
int startCardId;
int targetPlayerId;
QString targetZone;
int targetCardId;
QColor color;
public:
ServerInfo_Arrow(int _id = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const QColor &_color = QColor())
: id(_id), startPlayerId(_startPlayerId), startZone(_startZone), startCardId(_startCardId), targetPlayerId(_targetPlayerId), targetZone(_targetZone), targetCardId(_targetCardId), color(_color) { }
int getId() const { return id; }
int getStartPlayerId() const { return startPlayerId; }
QString getStartZone() const { return startZone; }
int getStartCardId() const { return startCardId; }
int getTargetPlayerId() const { return targetPlayerId; }
QString getTargetZone() const { return targetZone; }
int getTargetCardId() const { return targetCardId; }
QColor getColor() const { return color; }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
};
class ServerInfo_Player : public SerializableItem {
private:
int playerId;
QString name;
QList<ServerInfo_Zone *> zoneList; QList<ServerInfo_Zone *> zoneList;
QList<ServerInfo_Counter *> counterList; QList<ServerInfo_Counter *> counterList;
QList<ServerInfo_Arrow *> arrowList; QList<ServerInfo_Arrow *> arrowList;
protected:
void extractData();
public: public:
ServerInfo_Player(int _playerId = -1, const QString &_name = QString(), const QList<ServerInfo_Zone *> &_zoneList = QList<ServerInfo_Zone *>(), const QList<ServerInfo_Counter *> &_counterList = QList<ServerInfo_Counter *>(), const QList<ServerInfo_Arrow *> &_arrowList = QList<ServerInfo_Arrow *>()) ServerInfo_Player(int _playerId = -1, const QString &_name = QString(), const QList<ServerInfo_Zone *> &_zoneList = QList<ServerInfo_Zone *>(), const QList<ServerInfo_Counter *> &_counterList = QList<ServerInfo_Counter *>(), const QList<ServerInfo_Arrow *> &_arrowList = QList<ServerInfo_Arrow *>());
: playerId(_playerId), name(_name), zoneList(_zoneList), counterList(_counterList), arrowList(_arrowList) { } static SerializableItem *newItem() { return new ServerInfo_Player; }
~ServerInfo_Player(); int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); }
int getPlayerId() const { return playerId; } QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
QString getName() const { return name; }
const QList<ServerInfo_Zone *> &getZoneList() const { return zoneList; } const QList<ServerInfo_Zone *> &getZoneList() const { return zoneList; }
const QList<ServerInfo_Counter *> &getCounterList() const { return counterList; } const QList<ServerInfo_Counter *> &getCounterList() const { return counterList; }
const QList<ServerInfo_Arrow *> &getArrowList() const { return arrowList; } const QList<ServerInfo_Arrow *> &getArrowList() const { return arrowList; }
void addZone(ServerInfo_Zone *zone) { zoneList.append(zone); }
void addCounter(ServerInfo_Counter *counter) { counterList.append(counter); }
void addArrow(ServerInfo_Arrow *arrow) { arrowList.append(arrow); }
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
}; };
class DeckList_TreeItem : public SerializableItem { class DeckList_TreeItem : public SerializableItem_Map {
protected:
QString name;
int id;
public: public:
DeckList_TreeItem(const QString &_name, int _id) : name(_name), id(_id) { } DeckList_TreeItem(const QString &_itemType, const QString &_name, int _id);
QString getName() const { return name; } QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
int getId() const { return id; } int getId() const { return static_cast<SerializableItem_Int *>(itemMap.value("id"))->getData(); }
}; };
class DeckList_File : public DeckList_TreeItem { class DeckList_File : public DeckList_TreeItem {
private:
QDateTime uploadTime;
public: public:
DeckList_File(const QString &_name, int _id, QDateTime _uploadTime) : DeckList_TreeItem(_name, _id), uploadTime(_uploadTime) { } DeckList_File(const QString &_name = QString(), int _id = -1, QDateTime _uploadTime = QDateTime());
bool readElement(QXmlStreamReader *xml); static SerializableItem *newItem() { return new DeckList_File; }
void writeElement(QXmlStreamWriter *xml); QDateTime getUploadTime() const { return static_cast<SerializableItem_DateTime *>(itemMap.value("upload_time"))->getData(); }
QDateTime getUploadTime() const { return uploadTime; }
}; };
class DeckList_Directory : public DeckList_TreeItem, public QList<DeckList_TreeItem *> { class DeckList_Directory : public DeckList_TreeItem {
public: public:
DeckList_Directory(const QString &_name = QString(), int _id = 0) : DeckList_TreeItem(_name, _id) { } DeckList_Directory(const QString &_name = QString(), int _id = 0);
~DeckList_Directory(); static SerializableItem *newItem() { return new DeckList_Directory; }
bool readElement(QXmlStreamReader *xml); QList<DeckList_TreeItem *> getTreeItems() const { return typecastItemList<DeckList_TreeItem *>(); }
void writeElement(QXmlStreamWriter *xml);
}; };
#endif #endif

View file

@ -6,378 +6,209 @@ Command_Ping::Command_Ping()
{ {
} }
Command_Login::Command_Login(const QString &_username, const QString &_password) Command_Login::Command_Login(const QString &_username, const QString &_password)
: Command("login"), username(_username), password(_password) : Command("login")
{ {
setParameter("username", username); insertItem(new SerializableItem_String("username", _username));
setParameter("password", password); insertItem(new SerializableItem_String("password", _password));
}
void Command_Login::extractParameters()
{
Command::extractParameters();
username = parameters["username"];
password = parameters["password"];
} }
Command_DeckList::Command_DeckList() Command_DeckList::Command_DeckList()
: Command("deck_list") : Command("deck_list")
{ {
} }
Command_DeckNewDir::Command_DeckNewDir(const QString &_path, const QString &_dirName) Command_DeckNewDir::Command_DeckNewDir(const QString &_path, const QString &_dirName)
: Command("deck_new_dir"), path(_path), dirName(_dirName) : Command("deck_new_dir")
{ {
setParameter("path", path); insertItem(new SerializableItem_String("path", _path));
setParameter("dir_name", dirName); insertItem(new SerializableItem_String("dir_name", _dirName));
}
void Command_DeckNewDir::extractParameters()
{
Command::extractParameters();
path = parameters["path"];
dirName = parameters["dir_name"];
} }
Command_DeckDelDir::Command_DeckDelDir(const QString &_path) Command_DeckDelDir::Command_DeckDelDir(const QString &_path)
: Command("deck_del_dir"), path(_path) : Command("deck_del_dir")
{ {
setParameter("path", path); insertItem(new SerializableItem_String("path", _path));
}
void Command_DeckDelDir::extractParameters()
{
Command::extractParameters();
path = parameters["path"];
} }
Command_DeckDel::Command_DeckDel(int _deckId) Command_DeckDel::Command_DeckDel(int _deckId)
: Command("deck_del"), deckId(_deckId) : Command("deck_del")
{ {
setParameter("deck_id", deckId); insertItem(new SerializableItem_Int("deck_id", _deckId));
}
void Command_DeckDel::extractParameters()
{
Command::extractParameters();
deckId = parameters["deck_id"].toInt();
} }
Command_DeckDownload::Command_DeckDownload(int _deckId) Command_DeckDownload::Command_DeckDownload(int _deckId)
: Command("deck_download"), deckId(_deckId) : Command("deck_download")
{ {
setParameter("deck_id", deckId); insertItem(new SerializableItem_Int("deck_id", _deckId));
}
void Command_DeckDownload::extractParameters()
{
Command::extractParameters();
deckId = parameters["deck_id"].toInt();
} }
Command_ListChatChannels::Command_ListChatChannels() Command_ListChatChannels::Command_ListChatChannels()
: Command("list_chat_channels") : Command("list_chat_channels")
{ {
} }
Command_ChatJoinChannel::Command_ChatJoinChannel(const QString &_channel) Command_ChatJoinChannel::Command_ChatJoinChannel(const QString &_channel)
: Command("chat_join_channel"), channel(_channel) : Command("chat_join_channel")
{ {
setParameter("channel", channel); insertItem(new SerializableItem_String("channel", _channel));
}
void Command_ChatJoinChannel::extractParameters()
{
Command::extractParameters();
channel = parameters["channel"];
} }
Command_ChatLeaveChannel::Command_ChatLeaveChannel(const QString &_channel) Command_ChatLeaveChannel::Command_ChatLeaveChannel(const QString &_channel)
: ChatCommand("chat_leave_channel", _channel) : ChatCommand("chat_leave_channel", _channel)
{ {
} }
Command_ChatSay::Command_ChatSay(const QString &_channel, const QString &_message) Command_ChatSay::Command_ChatSay(const QString &_channel, const QString &_message)
: ChatCommand("chat_say", _channel), message(_message) : ChatCommand("chat_say", _channel)
{ {
setParameter("message", message); insertItem(new SerializableItem_String("message", _message));
}
void Command_ChatSay::extractParameters()
{
ChatCommand::extractParameters();
message = parameters["message"];
} }
Command_ListGames::Command_ListGames() Command_ListGames::Command_ListGames()
: Command("list_games") : Command("list_games")
{ {
} }
Command_CreateGame::Command_CreateGame(const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed) Command_CreateGame::Command_CreateGame(const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed)
: Command("create_game"), description(_description), password(_password), maxPlayers(_maxPlayers), spectatorsAllowed(_spectatorsAllowed) : Command("create_game")
{ {
setParameter("description", description); insertItem(new SerializableItem_String("description", _description));
setParameter("password", password); insertItem(new SerializableItem_String("password", _password));
setParameter("max_players", maxPlayers); insertItem(new SerializableItem_Int("max_players", _maxPlayers));
setParameter("spectators_allowed", spectatorsAllowed); insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
}
void Command_CreateGame::extractParameters()
{
Command::extractParameters();
description = parameters["description"];
password = parameters["password"];
maxPlayers = parameters["max_players"].toInt();
spectatorsAllowed = (parameters["spectators_allowed"] == "1");
} }
Command_JoinGame::Command_JoinGame(int _gameId, const QString &_password, bool _spectator) Command_JoinGame::Command_JoinGame(int _gameId, const QString &_password, bool _spectator)
: Command("join_game"), gameId(_gameId), password(_password), spectator(_spectator) : Command("join_game")
{ {
setParameter("game_id", gameId); insertItem(new SerializableItem_Int("game_id", _gameId));
setParameter("password", password); insertItem(new SerializableItem_String("password", _password));
setParameter("spectator", spectator); insertItem(new SerializableItem_Bool("spectator", _spectator));
}
void Command_JoinGame::extractParameters()
{
Command::extractParameters();
gameId = parameters["game_id"].toInt();
password = parameters["password"];
spectator = (parameters["spectator"] == "1");
} }
Command_LeaveGame::Command_LeaveGame(int _gameId) Command_LeaveGame::Command_LeaveGame(int _gameId)
: GameCommand("leave_game", _gameId) : GameCommand("leave_game", _gameId)
{ {
} }
Command_Say::Command_Say(int _gameId, const QString &_message) Command_Say::Command_Say(int _gameId, const QString &_message)
: GameCommand("say", _gameId), message(_message) : GameCommand("say", _gameId)
{ {
setParameter("message", message); insertItem(new SerializableItem_String("message", _message));
}
void Command_Say::extractParameters()
{
GameCommand::extractParameters();
message = parameters["message"];
} }
Command_Shuffle::Command_Shuffle(int _gameId) Command_Shuffle::Command_Shuffle(int _gameId)
: GameCommand("shuffle", _gameId) : GameCommand("shuffle", _gameId)
{ {
} }
Command_RollDie::Command_RollDie(int _gameId, int _sides) Command_RollDie::Command_RollDie(int _gameId, int _sides)
: GameCommand("roll_die", _gameId), sides(_sides) : GameCommand("roll_die", _gameId)
{ {
setParameter("sides", sides); insertItem(new SerializableItem_Int("sides", _sides));
}
void Command_RollDie::extractParameters()
{
GameCommand::extractParameters();
sides = parameters["sides"].toInt();
} }
Command_DrawCards::Command_DrawCards(int _gameId, int _number) Command_DrawCards::Command_DrawCards(int _gameId, int _number)
: GameCommand("draw_cards", _gameId), number(_number) : GameCommand("draw_cards", _gameId)
{ {
setParameter("number", number); insertItem(new SerializableItem_Int("number", _number));
}
void Command_DrawCards::extractParameters()
{
GameCommand::extractParameters();
number = parameters["number"].toInt();
} }
Command_MoveCard::Command_MoveCard(int _gameId, const QString &_startZone, int _cardId, const QString &_targetZone, int _x, int _y, bool _faceDown) Command_MoveCard::Command_MoveCard(int _gameId, const QString &_startZone, int _cardId, const QString &_targetZone, int _x, int _y, bool _faceDown)
: GameCommand("move_card", _gameId), startZone(_startZone), cardId(_cardId), targetZone(_targetZone), x(_x), y(_y), faceDown(_faceDown) : GameCommand("move_card", _gameId)
{ {
setParameter("start_zone", startZone); insertItem(new SerializableItem_String("start_zone", _startZone));
setParameter("card_id", cardId); insertItem(new SerializableItem_Int("card_id", _cardId));
setParameter("target_zone", targetZone); insertItem(new SerializableItem_String("target_zone", _targetZone));
setParameter("x", x); insertItem(new SerializableItem_Int("x", _x));
setParameter("y", y); insertItem(new SerializableItem_Int("y", _y));
setParameter("face_down", faceDown); insertItem(new SerializableItem_Bool("face_down", _faceDown));
}
void Command_MoveCard::extractParameters()
{
GameCommand::extractParameters();
startZone = parameters["start_zone"];
cardId = parameters["card_id"].toInt();
targetZone = parameters["target_zone"];
x = parameters["x"].toInt();
y = parameters["y"].toInt();
faceDown = (parameters["face_down"] == "1");
} }
Command_CreateToken::Command_CreateToken(int _gameId, const QString &_zone, const QString &_cardName, const QString &_pt, int _x, int _y) Command_CreateToken::Command_CreateToken(int _gameId, const QString &_zone, const QString &_cardName, const QString &_pt, int _x, int _y)
: GameCommand("create_token", _gameId), zone(_zone), cardName(_cardName), pt(_pt), x(_x), y(_y) : GameCommand("create_token", _gameId)
{ {
setParameter("zone", zone); insertItem(new SerializableItem_String("zone", _zone));
setParameter("card_name", cardName); insertItem(new SerializableItem_String("card_name", _cardName));
setParameter("pt", pt); insertItem(new SerializableItem_String("pt", _pt));
setParameter("x", x); insertItem(new SerializableItem_Int("x", _x));
setParameter("y", y); insertItem(new SerializableItem_Int("y", _y));
}
void Command_CreateToken::extractParameters()
{
GameCommand::extractParameters();
zone = parameters["zone"];
cardName = parameters["card_name"];
pt = parameters["pt"];
x = parameters["x"].toInt();
y = parameters["y"].toInt();
} }
Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const QColor &_color) Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const QColor &_color)
: GameCommand("create_arrow", _gameId), startPlayerId(_startPlayerId), startZone(_startZone), startCardId(_startCardId), targetPlayerId(_targetPlayerId), targetZone(_targetZone), targetCardId(_targetCardId), color(_color) : GameCommand("create_arrow", _gameId)
{ {
setParameter("start_player_id", startPlayerId); insertItem(new SerializableItem_Int("start_player_id", _startPlayerId));
setParameter("start_zone", startZone); insertItem(new SerializableItem_String("start_zone", _startZone));
setParameter("start_card_id", startCardId); insertItem(new SerializableItem_Int("start_card_id", _startCardId));
setParameter("target_player_id", targetPlayerId); insertItem(new SerializableItem_Int("target_player_id", _targetPlayerId));
setParameter("target_zone", targetZone); insertItem(new SerializableItem_String("target_zone", _targetZone));
setParameter("target_card_id", targetCardId); insertItem(new SerializableItem_Int("target_card_id", _targetCardId));
setParameter("color", color); insertItem(new SerializableItem_Color("color", _color));
}
void Command_CreateArrow::extractParameters()
{
GameCommand::extractParameters();
startPlayerId = parameters["start_player_id"].toInt();
startZone = parameters["start_zone"];
startCardId = parameters["start_card_id"].toInt();
targetPlayerId = parameters["target_player_id"].toInt();
targetZone = parameters["target_zone"];
targetCardId = parameters["target_card_id"].toInt();
color = ColorConverter::colorFromInt(parameters["color"].toInt());
} }
Command_DeleteArrow::Command_DeleteArrow(int _gameId, int _arrowId) Command_DeleteArrow::Command_DeleteArrow(int _gameId, int _arrowId)
: GameCommand("delete_arrow", _gameId), arrowId(_arrowId) : GameCommand("delete_arrow", _gameId)
{ {
setParameter("arrow_id", arrowId); insertItem(new SerializableItem_Int("arrow_id", _arrowId));
}
void Command_DeleteArrow::extractParameters()
{
GameCommand::extractParameters();
arrowId = parameters["arrow_id"].toInt();
} }
Command_SetCardAttr::Command_SetCardAttr(int _gameId, const QString &_zone, int _cardId, const QString &_attrName, const QString &_attrValue) Command_SetCardAttr::Command_SetCardAttr(int _gameId, const QString &_zone, int _cardId, const QString &_attrName, const QString &_attrValue)
: GameCommand("set_card_attr", _gameId), zone(_zone), cardId(_cardId), attrName(_attrName), attrValue(_attrValue) : GameCommand("set_card_attr", _gameId)
{ {
setParameter("zone", zone); insertItem(new SerializableItem_String("zone", _zone));
setParameter("card_id", cardId); insertItem(new SerializableItem_Int("card_id", _cardId));
setParameter("attr_name", attrName); insertItem(new SerializableItem_String("attr_name", _attrName));
setParameter("attr_value", attrValue); insertItem(new SerializableItem_String("attr_value", _attrValue));
}
void Command_SetCardAttr::extractParameters()
{
GameCommand::extractParameters();
zone = parameters["zone"];
cardId = parameters["card_id"].toInt();
attrName = parameters["attr_name"];
attrValue = parameters["attr_value"];
} }
Command_ReadyStart::Command_ReadyStart(int _gameId) Command_ReadyStart::Command_ReadyStart(int _gameId)
: GameCommand("ready_start", _gameId) : GameCommand("ready_start", _gameId)
{ {
} }
Command_IncCounter::Command_IncCounter(int _gameId, int _counterId, int _delta) Command_IncCounter::Command_IncCounter(int _gameId, int _counterId, int _delta)
: GameCommand("inc_counter", _gameId), counterId(_counterId), delta(_delta) : GameCommand("inc_counter", _gameId)
{ {
setParameter("counter_id", counterId); insertItem(new SerializableItem_Int("counter_id", _counterId));
setParameter("delta", delta); insertItem(new SerializableItem_Int("delta", _delta));
}
void Command_IncCounter::extractParameters()
{
GameCommand::extractParameters();
counterId = parameters["counter_id"].toInt();
delta = parameters["delta"].toInt();
} }
Command_CreateCounter::Command_CreateCounter(int _gameId, const QString &_counterName, const QColor &_color, int _radius, int _value) Command_CreateCounter::Command_CreateCounter(int _gameId, const QString &_counterName, const QColor &_color, int _radius, int _value)
: GameCommand("create_counter", _gameId), counterName(_counterName), color(_color), radius(_radius), value(_value) : GameCommand("create_counter", _gameId)
{ {
setParameter("counter_name", counterName); insertItem(new SerializableItem_String("counter_name", _counterName));
setParameter("color", color); insertItem(new SerializableItem_Color("color", _color));
setParameter("radius", radius); insertItem(new SerializableItem_Int("radius", _radius));
setParameter("value", value); insertItem(new SerializableItem_Int("value", _value));
}
void Command_CreateCounter::extractParameters()
{
GameCommand::extractParameters();
counterName = parameters["counter_name"];
color = ColorConverter::colorFromInt(parameters["color"].toInt());
radius = parameters["radius"].toInt();
value = parameters["value"].toInt();
} }
Command_SetCounter::Command_SetCounter(int _gameId, int _counterId, int _value) Command_SetCounter::Command_SetCounter(int _gameId, int _counterId, int _value)
: GameCommand("set_counter", _gameId), counterId(_counterId), value(_value) : GameCommand("set_counter", _gameId)
{ {
setParameter("counter_id", counterId); insertItem(new SerializableItem_Int("counter_id", _counterId));
setParameter("value", value); insertItem(new SerializableItem_Int("value", _value));
}
void Command_SetCounter::extractParameters()
{
GameCommand::extractParameters();
counterId = parameters["counter_id"].toInt();
value = parameters["value"].toInt();
} }
Command_DelCounter::Command_DelCounter(int _gameId, int _counterId) Command_DelCounter::Command_DelCounter(int _gameId, int _counterId)
: GameCommand("del_counter", _gameId), counterId(_counterId) : GameCommand("del_counter", _gameId)
{ {
setParameter("counter_id", counterId); insertItem(new SerializableItem_Int("counter_id", _counterId));
}
void Command_DelCounter::extractParameters()
{
GameCommand::extractParameters();
counterId = parameters["counter_id"].toInt();
} }
Command_NextTurn::Command_NextTurn(int _gameId) Command_NextTurn::Command_NextTurn(int _gameId)
: GameCommand("next_turn", _gameId) : GameCommand("next_turn", _gameId)
{ {
} }
Command_SetActivePhase::Command_SetActivePhase(int _gameId, int _phase) Command_SetActivePhase::Command_SetActivePhase(int _gameId, int _phase)
: GameCommand("set_active_phase", _gameId), phase(_phase) : GameCommand("set_active_phase", _gameId)
{ {
setParameter("phase", phase); insertItem(new SerializableItem_Int("phase", _phase));
}
void Command_SetActivePhase::extractParameters()
{
GameCommand::extractParameters();
phase = parameters["phase"].toInt();
} }
Command_DumpZone::Command_DumpZone(int _gameId, int _playerId, const QString &_zoneName, int _numberCards) Command_DumpZone::Command_DumpZone(int _gameId, int _playerId, const QString &_zoneName, int _numberCards)
: GameCommand("dump_zone", _gameId), playerId(_playerId), zoneName(_zoneName), numberCards(_numberCards) : GameCommand("dump_zone", _gameId)
{ {
setParameter("player_id", playerId); insertItem(new SerializableItem_Int("player_id", _playerId));
setParameter("zone_name", zoneName); insertItem(new SerializableItem_String("zone_name", _zoneName));
setParameter("number_cards", numberCards); insertItem(new SerializableItem_Int("number_cards", _numberCards));
}
void Command_DumpZone::extractParameters()
{
GameCommand::extractParameters();
playerId = parameters["player_id"].toInt();
zoneName = parameters["zone_name"];
numberCards = parameters["number_cards"].toInt();
} }
Command_StopDumpZone::Command_StopDumpZone(int _gameId, int _playerId, const QString &_zoneName) Command_StopDumpZone::Command_StopDumpZone(int _gameId, int _playerId, const QString &_zoneName)
: GameCommand("stop_dump_zone", _gameId), playerId(_playerId), zoneName(_zoneName) : GameCommand("stop_dump_zone", _gameId)
{ {
setParameter("player_id", playerId); insertItem(new SerializableItem_Int("player_id", _playerId));
setParameter("zone_name", zoneName); insertItem(new SerializableItem_String("zone_name", _zoneName));
}
void Command_StopDumpZone::extractParameters()
{
GameCommand::extractParameters();
playerId = parameters["player_id"].toInt();
zoneName = parameters["zone_name"];
} }
Event_Say::Event_Say(int _gameId, int _playerId, const QString &_message) Event_Say::Event_Say(int _gameId, int _playerId, const QString &_message)
: GameEvent("say", _gameId, _playerId), message(_message) : GameEvent("say", _gameId, _playerId)
{ {
setParameter("message", message); insertItem(new SerializableItem_String("message", _message));
}
void Event_Say::extractParameters()
{
GameEvent::extractParameters();
message = parameters["message"];
} }
Event_Join::Event_Join(int _gameId, int _playerId, const QString &_playerName, bool _spectator) Event_Join::Event_Join(int _gameId, int _playerId, const QString &_playerName, bool _spectator)
: GameEvent("join", _gameId, _playerId), playerName(_playerName), spectator(_spectator) : GameEvent("join", _gameId, _playerId)
{ {
setParameter("player_name", playerName); insertItem(new SerializableItem_String("player_name", _playerName));
setParameter("spectator", spectator); insertItem(new SerializableItem_Bool("spectator", _spectator));
}
void Event_Join::extractParameters()
{
GameEvent::extractParameters();
playerName = parameters["player_name"];
spectator = (parameters["spectator"] == "1");
} }
Event_Leave::Event_Leave(int _gameId, int _playerId) Event_Leave::Event_Leave(int _gameId, int _playerId)
: GameEvent("leave", _gameId, _playerId) : GameEvent("leave", _gameId, _playerId)
{ {
} }
Event_DeckSelect::Event_DeckSelect(int _gameId, int _playerId, int _deckId) Event_DeckSelect::Event_DeckSelect(int _gameId, int _playerId, int _deckId)
: GameEvent("deck_select", _gameId, _playerId), deckId(_deckId) : GameEvent("deck_select", _gameId, _playerId)
{ {
setParameter("deck_id", deckId); insertItem(new SerializableItem_Int("deck_id", _deckId));
}
void Event_DeckSelect::extractParameters()
{
GameEvent::extractParameters();
deckId = parameters["deck_id"].toInt();
} }
Event_GameClosed::Event_GameClosed(int _gameId, int _playerId) Event_GameClosed::Event_GameClosed(int _gameId, int _playerId)
: GameEvent("game_closed", _gameId, _playerId) : GameEvent("game_closed", _gameId, _playerId)
@ -396,210 +227,107 @@ Event_Shuffle::Event_Shuffle(int _gameId, int _playerId)
{ {
} }
Event_RollDie::Event_RollDie(int _gameId, int _playerId, int _sides, int _value) Event_RollDie::Event_RollDie(int _gameId, int _playerId, int _sides, int _value)
: GameEvent("roll_die", _gameId, _playerId), sides(_sides), value(_value) : GameEvent("roll_die", _gameId, _playerId)
{ {
setParameter("sides", sides); insertItem(new SerializableItem_Int("sides", _sides));
setParameter("value", value); insertItem(new SerializableItem_Int("value", _value));
}
void Event_RollDie::extractParameters()
{
GameEvent::extractParameters();
sides = parameters["sides"].toInt();
value = parameters["value"].toInt();
} }
Event_MoveCard::Event_MoveCard(int _gameId, int _playerId, int _cardId, const QString &_cardName, const QString &_startZone, int _position, const QString &_targetZone, int _x, int _y, bool _faceDown) Event_MoveCard::Event_MoveCard(int _gameId, int _playerId, int _cardId, const QString &_cardName, const QString &_startZone, int _position, const QString &_targetZone, int _x, int _y, bool _faceDown)
: GameEvent("move_card", _gameId, _playerId), cardId(_cardId), cardName(_cardName), startZone(_startZone), position(_position), targetZone(_targetZone), x(_x), y(_y), faceDown(_faceDown) : GameEvent("move_card", _gameId, _playerId)
{ {
setParameter("card_id", cardId); insertItem(new SerializableItem_Int("card_id", _cardId));
setParameter("card_name", cardName); insertItem(new SerializableItem_String("card_name", _cardName));
setParameter("start_zone", startZone); insertItem(new SerializableItem_String("start_zone", _startZone));
setParameter("position", position); insertItem(new SerializableItem_Int("position", _position));
setParameter("target_zone", targetZone); insertItem(new SerializableItem_String("target_zone", _targetZone));
setParameter("x", x); insertItem(new SerializableItem_Int("x", _x));
setParameter("y", y); insertItem(new SerializableItem_Int("y", _y));
setParameter("face_down", faceDown); insertItem(new SerializableItem_Bool("face_down", _faceDown));
}
void Event_MoveCard::extractParameters()
{
GameEvent::extractParameters();
cardId = parameters["card_id"].toInt();
cardName = parameters["card_name"];
startZone = parameters["start_zone"];
position = parameters["position"].toInt();
targetZone = parameters["target_zone"];
x = parameters["x"].toInt();
y = parameters["y"].toInt();
faceDown = (parameters["face_down"] == "1");
} }
Event_CreateToken::Event_CreateToken(int _gameId, int _playerId, const QString &_zone, int _cardId, const QString &_cardName, const QString &_pt, int _x, int _y) Event_CreateToken::Event_CreateToken(int _gameId, int _playerId, const QString &_zone, int _cardId, const QString &_cardName, const QString &_pt, int _x, int _y)
: GameEvent("create_token", _gameId, _playerId), zone(_zone), cardId(_cardId), cardName(_cardName), pt(_pt), x(_x), y(_y) : GameEvent("create_token", _gameId, _playerId)
{ {
setParameter("zone", zone); insertItem(new SerializableItem_String("zone", _zone));
setParameter("card_id", cardId); insertItem(new SerializableItem_Int("card_id", _cardId));
setParameter("card_name", cardName); insertItem(new SerializableItem_String("card_name", _cardName));
setParameter("pt", pt); insertItem(new SerializableItem_String("pt", _pt));
setParameter("x", x); insertItem(new SerializableItem_Int("x", _x));
setParameter("y", y); insertItem(new SerializableItem_Int("y", _y));
}
void Event_CreateToken::extractParameters()
{
GameEvent::extractParameters();
zone = parameters["zone"];
cardId = parameters["card_id"].toInt();
cardName = parameters["card_name"];
pt = parameters["pt"];
x = parameters["x"].toInt();
y = parameters["y"].toInt();
} }
Event_DeleteArrow::Event_DeleteArrow(int _gameId, int _playerId, int _arrowId) Event_DeleteArrow::Event_DeleteArrow(int _gameId, int _playerId, int _arrowId)
: GameEvent("delete_arrow", _gameId, _playerId), arrowId(_arrowId) : GameEvent("delete_arrow", _gameId, _playerId)
{ {
setParameter("arrow_id", arrowId); insertItem(new SerializableItem_Int("arrow_id", _arrowId));
}
void Event_DeleteArrow::extractParameters()
{
GameEvent::extractParameters();
arrowId = parameters["arrow_id"].toInt();
} }
Event_SetCardAttr::Event_SetCardAttr(int _gameId, int _playerId, const QString &_zone, int _cardId, const QString &_attrName, const QString &_attrValue) Event_SetCardAttr::Event_SetCardAttr(int _gameId, int _playerId, const QString &_zone, int _cardId, const QString &_attrName, const QString &_attrValue)
: GameEvent("set_card_attr", _gameId, _playerId), zone(_zone), cardId(_cardId), attrName(_attrName), attrValue(_attrValue) : GameEvent("set_card_attr", _gameId, _playerId)
{ {
setParameter("zone", zone); insertItem(new SerializableItem_String("zone", _zone));
setParameter("card_id", cardId); insertItem(new SerializableItem_Int("card_id", _cardId));
setParameter("attr_name", attrName); insertItem(new SerializableItem_String("attr_name", _attrName));
setParameter("attr_value", attrValue); insertItem(new SerializableItem_String("attr_value", _attrValue));
}
void Event_SetCardAttr::extractParameters()
{
GameEvent::extractParameters();
zone = parameters["zone"];
cardId = parameters["card_id"].toInt();
attrName = parameters["attr_name"];
attrValue = parameters["attr_value"];
} }
Event_SetCounter::Event_SetCounter(int _gameId, int _playerId, int _counterId, int _value) Event_SetCounter::Event_SetCounter(int _gameId, int _playerId, int _counterId, int _value)
: GameEvent("set_counter", _gameId, _playerId), counterId(_counterId), value(_value) : GameEvent("set_counter", _gameId, _playerId)
{ {
setParameter("counter_id", counterId); insertItem(new SerializableItem_Int("counter_id", _counterId));
setParameter("value", value); insertItem(new SerializableItem_Int("value", _value));
}
void Event_SetCounter::extractParameters()
{
GameEvent::extractParameters();
counterId = parameters["counter_id"].toInt();
value = parameters["value"].toInt();
} }
Event_DelCounter::Event_DelCounter(int _gameId, int _playerId, int _counterId) Event_DelCounter::Event_DelCounter(int _gameId, int _playerId, int _counterId)
: GameEvent("del_counter", _gameId, _playerId), counterId(_counterId) : GameEvent("del_counter", _gameId, _playerId)
{ {
setParameter("counter_id", counterId); insertItem(new SerializableItem_Int("counter_id", _counterId));
}
void Event_DelCounter::extractParameters()
{
GameEvent::extractParameters();
counterId = parameters["counter_id"].toInt();
} }
Event_SetActivePlayer::Event_SetActivePlayer(int _gameId, int _playerId, int _activePlayerId) Event_SetActivePlayer::Event_SetActivePlayer(int _gameId, int _playerId, int _activePlayerId)
: GameEvent("set_active_player", _gameId, _playerId), activePlayerId(_activePlayerId) : GameEvent("set_active_player", _gameId, _playerId)
{ {
setParameter("active_player_id", activePlayerId); insertItem(new SerializableItem_Int("active_player_id", _activePlayerId));
}
void Event_SetActivePlayer::extractParameters()
{
GameEvent::extractParameters();
activePlayerId = parameters["active_player_id"].toInt();
} }
Event_SetActivePhase::Event_SetActivePhase(int _gameId, int _playerId, int _phase) Event_SetActivePhase::Event_SetActivePhase(int _gameId, int _playerId, int _phase)
: GameEvent("set_active_phase", _gameId, _playerId), phase(_phase) : GameEvent("set_active_phase", _gameId, _playerId)
{ {
setParameter("phase", phase); insertItem(new SerializableItem_Int("phase", _phase));
}
void Event_SetActivePhase::extractParameters()
{
GameEvent::extractParameters();
phase = parameters["phase"].toInt();
} }
Event_DumpZone::Event_DumpZone(int _gameId, int _playerId, int _zoneOwnerId, const QString &_zone, int _numberCards) Event_DumpZone::Event_DumpZone(int _gameId, int _playerId, int _zoneOwnerId, const QString &_zone, int _numberCards)
: GameEvent("dump_zone", _gameId, _playerId), zoneOwnerId(_zoneOwnerId), zone(_zone), numberCards(_numberCards) : GameEvent("dump_zone", _gameId, _playerId)
{ {
setParameter("zone_owner_id", zoneOwnerId); insertItem(new SerializableItem_Int("zone_owner_id", _zoneOwnerId));
setParameter("zone", zone); insertItem(new SerializableItem_String("zone", _zone));
setParameter("number_cards", numberCards); insertItem(new SerializableItem_Int("number_cards", _numberCards));
}
void Event_DumpZone::extractParameters()
{
GameEvent::extractParameters();
zoneOwnerId = parameters["zone_owner_id"].toInt();
zone = parameters["zone"];
numberCards = parameters["number_cards"].toInt();
} }
Event_StopDumpZone::Event_StopDumpZone(int _gameId, int _playerId, int _zoneOwnerId, const QString &_zone) Event_StopDumpZone::Event_StopDumpZone(int _gameId, int _playerId, int _zoneOwnerId, const QString &_zone)
: GameEvent("stop_dump_zone", _gameId, _playerId), zoneOwnerId(_zoneOwnerId), zone(_zone) : GameEvent("stop_dump_zone", _gameId, _playerId)
{ {
setParameter("zone_owner_id", zoneOwnerId); insertItem(new SerializableItem_Int("zone_owner_id", _zoneOwnerId));
setParameter("zone", zone); insertItem(new SerializableItem_String("zone", _zone));
}
void Event_StopDumpZone::extractParameters()
{
GameEvent::extractParameters();
zoneOwnerId = parameters["zone_owner_id"].toInt();
zone = parameters["zone"];
} }
Event_ServerMessage::Event_ServerMessage(const QString &_message) Event_ServerMessage::Event_ServerMessage(const QString &_message)
: GenericEvent("server_message"), message(_message) : GenericEvent("server_message")
{ {
setParameter("message", message); insertItem(new SerializableItem_String("message", _message));
}
void Event_ServerMessage::extractParameters()
{
GenericEvent::extractParameters();
message = parameters["message"];
} }
Event_GameJoined::Event_GameJoined(int _gameId, int _playerId, bool _spectator) Event_GameJoined::Event_GameJoined(int _gameId, int _playerId, bool _spectator)
: GenericEvent("game_joined"), gameId(_gameId), playerId(_playerId), spectator(_spectator) : GenericEvent("game_joined")
{ {
setParameter("game_id", gameId); insertItem(new SerializableItem_Int("game_id", _gameId));
setParameter("player_id", playerId); insertItem(new SerializableItem_Int("player_id", _playerId));
setParameter("spectator", spectator); insertItem(new SerializableItem_Bool("spectator", _spectator));
}
void Event_GameJoined::extractParameters()
{
GenericEvent::extractParameters();
gameId = parameters["game_id"].toInt();
playerId = parameters["player_id"].toInt();
spectator = (parameters["spectator"] == "1");
} }
Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, const QString &_playerName) Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, const QString &_playerName)
: ChatEvent("chat_join_channel", _channel), playerName(_playerName) : ChatEvent("chat_join_channel", _channel)
{ {
setParameter("player_name", playerName); insertItem(new SerializableItem_String("player_name", _playerName));
}
void Event_ChatJoinChannel::extractParameters()
{
ChatEvent::extractParameters();
playerName = parameters["player_name"];
} }
Event_ChatLeaveChannel::Event_ChatLeaveChannel(const QString &_channel, const QString &_playerName) Event_ChatLeaveChannel::Event_ChatLeaveChannel(const QString &_channel, const QString &_playerName)
: ChatEvent("chat_leave_channel", _channel), playerName(_playerName) : ChatEvent("chat_leave_channel", _channel)
{ {
setParameter("player_name", playerName); insertItem(new SerializableItem_String("player_name", _playerName));
}
void Event_ChatLeaveChannel::extractParameters()
{
ChatEvent::extractParameters();
playerName = parameters["player_name"];
} }
Event_ChatSay::Event_ChatSay(const QString &_channel, const QString &_playerName, const QString &_message) Event_ChatSay::Event_ChatSay(const QString &_channel, const QString &_playerName, const QString &_message)
: ChatEvent("chat_say", _channel), playerName(_playerName), message(_message) : ChatEvent("chat_say", _channel)
{ {
setParameter("player_name", playerName); insertItem(new SerializableItem_String("player_name", _playerName));
setParameter("message", message); insertItem(new SerializableItem_String("message", _message));
}
void Event_ChatSay::extractParameters()
{
ChatEvent::extractParameters();
playerName = parameters["player_name"];
message = parameters["message"];
} }
void ProtocolItem::initializeHashAuto() void ProtocolItem::initializeHashAuto()
{ {

View file

@ -5,745 +5,502 @@
class Command_Ping : public Command { class Command_Ping : public Command {
Q_OBJECT Q_OBJECT
private:
public: public:
Command_Ping(); Command_Ping();
static ProtocolItem *newItem() { return new Command_Ping; } static SerializableItem *newItem() { return new Command_Ping; }
int getItemId() const { return ItemId_Command_Ping; } int getItemId() const { return ItemId_Command_Ping; }
}; };
class Command_Login : public Command { class Command_Login : public Command {
Q_OBJECT Q_OBJECT
private:
QString username;
QString password;
public: public:
Command_Login(const QString &_username = QString(), const QString &_password = QString()); Command_Login(const QString &_username = QString(), const QString &_password = QString());
QString getUsername() const { return username; } QString getUsername() const { return static_cast<SerializableItem_String *>(itemMap.value("username"))->getData(); };
QString getPassword() const { return password; } QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); };
static ProtocolItem *newItem() { return new Command_Login; } static SerializableItem *newItem() { return new Command_Login; }
int getItemId() const { return ItemId_Command_Login; } int getItemId() const { return ItemId_Command_Login; }
protected:
void extractParameters();
}; };
class Command_DeckList : public Command { class Command_DeckList : public Command {
Q_OBJECT Q_OBJECT
private:
public: public:
Command_DeckList(); Command_DeckList();
static ProtocolItem *newItem() { return new Command_DeckList; } static SerializableItem *newItem() { return new Command_DeckList; }
int getItemId() const { return ItemId_Command_DeckList; } int getItemId() const { return ItemId_Command_DeckList; }
}; };
class Command_DeckNewDir : public Command { class Command_DeckNewDir : public Command {
Q_OBJECT Q_OBJECT
private:
QString path;
QString dirName;
public: public:
Command_DeckNewDir(const QString &_path = QString(), const QString &_dirName = QString()); Command_DeckNewDir(const QString &_path = QString(), const QString &_dirName = QString());
QString getPath() const { return path; } QString getPath() const { return static_cast<SerializableItem_String *>(itemMap.value("path"))->getData(); };
QString getDirName() const { return dirName; } QString getDirName() const { return static_cast<SerializableItem_String *>(itemMap.value("dir_name"))->getData(); };
static ProtocolItem *newItem() { return new Command_DeckNewDir; } static SerializableItem *newItem() { return new Command_DeckNewDir; }
int getItemId() const { return ItemId_Command_DeckNewDir; } int getItemId() const { return ItemId_Command_DeckNewDir; }
protected:
void extractParameters();
}; };
class Command_DeckDelDir : public Command { class Command_DeckDelDir : public Command {
Q_OBJECT Q_OBJECT
private:
QString path;
public: public:
Command_DeckDelDir(const QString &_path = QString()); Command_DeckDelDir(const QString &_path = QString());
QString getPath() const { return path; } QString getPath() const { return static_cast<SerializableItem_String *>(itemMap.value("path"))->getData(); };
static ProtocolItem *newItem() { return new Command_DeckDelDir; } static SerializableItem *newItem() { return new Command_DeckDelDir; }
int getItemId() const { return ItemId_Command_DeckDelDir; } int getItemId() const { return ItemId_Command_DeckDelDir; }
protected:
void extractParameters();
}; };
class Command_DeckDel : public Command { class Command_DeckDel : public Command {
Q_OBJECT Q_OBJECT
private:
int deckId;
public: public:
Command_DeckDel(int _deckId = -1); Command_DeckDel(int _deckId = -1);
int getDeckId() const { return deckId; } int getDeckId() const { return static_cast<SerializableItem_Int *>(itemMap.value("deck_id"))->getData(); };
static ProtocolItem *newItem() { return new Command_DeckDel; } static SerializableItem *newItem() { return new Command_DeckDel; }
int getItemId() const { return ItemId_Command_DeckDel; } int getItemId() const { return ItemId_Command_DeckDel; }
protected:
void extractParameters();
}; };
class Command_DeckDownload : public Command { class Command_DeckDownload : public Command {
Q_OBJECT Q_OBJECT
private:
int deckId;
public: public:
Command_DeckDownload(int _deckId = -1); Command_DeckDownload(int _deckId = -1);
int getDeckId() const { return deckId; } int getDeckId() const { return static_cast<SerializableItem_Int *>(itemMap.value("deck_id"))->getData(); };
static ProtocolItem *newItem() { return new Command_DeckDownload; } static SerializableItem *newItem() { return new Command_DeckDownload; }
int getItemId() const { return ItemId_Command_DeckDownload; } int getItemId() const { return ItemId_Command_DeckDownload; }
protected:
void extractParameters();
}; };
class Command_ListChatChannels : public Command { class Command_ListChatChannels : public Command {
Q_OBJECT Q_OBJECT
private:
public: public:
Command_ListChatChannels(); Command_ListChatChannels();
static ProtocolItem *newItem() { return new Command_ListChatChannels; } static SerializableItem *newItem() { return new Command_ListChatChannels; }
int getItemId() const { return ItemId_Command_ListChatChannels; } int getItemId() const { return ItemId_Command_ListChatChannels; }
}; };
class Command_ChatJoinChannel : public Command { class Command_ChatJoinChannel : public Command {
Q_OBJECT Q_OBJECT
private:
QString channel;
public: public:
Command_ChatJoinChannel(const QString &_channel = QString()); Command_ChatJoinChannel(const QString &_channel = QString());
QString getChannel() const { return channel; } QString getChannel() const { return static_cast<SerializableItem_String *>(itemMap.value("channel"))->getData(); };
static ProtocolItem *newItem() { return new Command_ChatJoinChannel; } static SerializableItem *newItem() { return new Command_ChatJoinChannel; }
int getItemId() const { return ItemId_Command_ChatJoinChannel; } int getItemId() const { return ItemId_Command_ChatJoinChannel; }
protected:
void extractParameters();
}; };
class Command_ChatLeaveChannel : public ChatCommand { class Command_ChatLeaveChannel : public ChatCommand {
Q_OBJECT Q_OBJECT
private:
public: public:
Command_ChatLeaveChannel(const QString &_channel = QString()); Command_ChatLeaveChannel(const QString &_channel = QString());
static ProtocolItem *newItem() { return new Command_ChatLeaveChannel; } static SerializableItem *newItem() { return new Command_ChatLeaveChannel; }
int getItemId() const { return ItemId_Command_ChatLeaveChannel; } int getItemId() const { return ItemId_Command_ChatLeaveChannel; }
}; };
class Command_ChatSay : public ChatCommand { class Command_ChatSay : public ChatCommand {
Q_OBJECT Q_OBJECT
private:
QString message;
public: public:
Command_ChatSay(const QString &_channel = QString(), const QString &_message = QString()); Command_ChatSay(const QString &_channel = QString(), const QString &_message = QString());
QString getMessage() const { return message; } QString getMessage() const { return static_cast<SerializableItem_String *>(itemMap.value("message"))->getData(); };
static ProtocolItem *newItem() { return new Command_ChatSay; } static SerializableItem *newItem() { return new Command_ChatSay; }
int getItemId() const { return ItemId_Command_ChatSay; } int getItemId() const { return ItemId_Command_ChatSay; }
protected:
void extractParameters();
}; };
class Command_ListGames : public Command { class Command_ListGames : public Command {
Q_OBJECT Q_OBJECT
private:
public: public:
Command_ListGames(); Command_ListGames();
static ProtocolItem *newItem() { return new Command_ListGames; } static SerializableItem *newItem() { return new Command_ListGames; }
int getItemId() const { return ItemId_Command_ListGames; } int getItemId() const { return ItemId_Command_ListGames; }
}; };
class Command_CreateGame : public Command { class Command_CreateGame : public Command {
Q_OBJECT Q_OBJECT
private:
QString description;
QString password;
int maxPlayers;
bool spectatorsAllowed;
public: public:
Command_CreateGame(const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, bool _spectatorsAllowed = false); Command_CreateGame(const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, bool _spectatorsAllowed = false);
QString getDescription() const { return description; } QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); };
QString getPassword() const { return password; } QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); };
int getMaxPlayers() const { return maxPlayers; } int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); };
bool getSpectatorsAllowed() const { return spectatorsAllowed; } bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); };
static ProtocolItem *newItem() { return new Command_CreateGame; } static SerializableItem *newItem() { return new Command_CreateGame; }
int getItemId() const { return ItemId_Command_CreateGame; } int getItemId() const { return ItemId_Command_CreateGame; }
protected:
void extractParameters();
}; };
class Command_JoinGame : public Command { class Command_JoinGame : public Command {
Q_OBJECT Q_OBJECT
private:
int gameId;
QString password;
bool spectator;
public: public:
Command_JoinGame(int _gameId = -1, const QString &_password = QString(), bool _spectator = false); Command_JoinGame(int _gameId = -1, const QString &_password = QString(), bool _spectator = false);
int getGameId() const { return gameId; } int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); };
QString getPassword() const { return password; } QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); };
bool getSpectator() const { return spectator; } bool getSpectator() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectator"))->getData(); };
static ProtocolItem *newItem() { return new Command_JoinGame; } static SerializableItem *newItem() { return new Command_JoinGame; }
int getItemId() const { return ItemId_Command_JoinGame; } int getItemId() const { return ItemId_Command_JoinGame; }
protected:
void extractParameters();
}; };
class Command_LeaveGame : public GameCommand { class Command_LeaveGame : public GameCommand {
Q_OBJECT Q_OBJECT
private:
public: public:
Command_LeaveGame(int _gameId = -1); Command_LeaveGame(int _gameId = -1);
static ProtocolItem *newItem() { return new Command_LeaveGame; } static SerializableItem *newItem() { return new Command_LeaveGame; }
int getItemId() const { return ItemId_Command_LeaveGame; } int getItemId() const { return ItemId_Command_LeaveGame; }
}; };
class Command_Say : public GameCommand { class Command_Say : public GameCommand {
Q_OBJECT Q_OBJECT
private:
QString message;
public: public:
Command_Say(int _gameId = -1, const QString &_message = QString()); Command_Say(int _gameId = -1, const QString &_message = QString());
QString getMessage() const { return message; } QString getMessage() const { return static_cast<SerializableItem_String *>(itemMap.value("message"))->getData(); };
static ProtocolItem *newItem() { return new Command_Say; } static SerializableItem *newItem() { return new Command_Say; }
int getItemId() const { return ItemId_Command_Say; } int getItemId() const { return ItemId_Command_Say; }
protected:
void extractParameters();
}; };
class Command_Shuffle : public GameCommand { class Command_Shuffle : public GameCommand {
Q_OBJECT Q_OBJECT
private:
public: public:
Command_Shuffle(int _gameId = -1); Command_Shuffle(int _gameId = -1);
static ProtocolItem *newItem() { return new Command_Shuffle; } static SerializableItem *newItem() { return new Command_Shuffle; }
int getItemId() const { return ItemId_Command_Shuffle; } int getItemId() const { return ItemId_Command_Shuffle; }
}; };
class Command_RollDie : public GameCommand { class Command_RollDie : public GameCommand {
Q_OBJECT Q_OBJECT
private:
int sides;
public: public:
Command_RollDie(int _gameId = -1, int _sides = -1); Command_RollDie(int _gameId = -1, int _sides = -1);
int getSides() const { return sides; } int getSides() const { return static_cast<SerializableItem_Int *>(itemMap.value("sides"))->getData(); };
static ProtocolItem *newItem() { return new Command_RollDie; } static SerializableItem *newItem() { return new Command_RollDie; }
int getItemId() const { return ItemId_Command_RollDie; } int getItemId() const { return ItemId_Command_RollDie; }
protected:
void extractParameters();
}; };
class Command_DrawCards : public GameCommand { class Command_DrawCards : public GameCommand {
Q_OBJECT Q_OBJECT
private:
int number;
public: public:
Command_DrawCards(int _gameId = -1, int _number = -1); Command_DrawCards(int _gameId = -1, int _number = -1);
int getNumber() const { return number; } int getNumber() const { return static_cast<SerializableItem_Int *>(itemMap.value("number"))->getData(); };
static ProtocolItem *newItem() { return new Command_DrawCards; } static SerializableItem *newItem() { return new Command_DrawCards; }
int getItemId() const { return ItemId_Command_DrawCards; } int getItemId() const { return ItemId_Command_DrawCards; }
protected:
void extractParameters();
}; };
class Command_MoveCard : public GameCommand { class Command_MoveCard : public GameCommand {
Q_OBJECT Q_OBJECT
private:
QString startZone;
int cardId;
QString targetZone;
int x;
int y;
bool faceDown;
public: public:
Command_MoveCard(int _gameId = -1, const QString &_startZone = QString(), int _cardId = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, bool _faceDown = false); Command_MoveCard(int _gameId = -1, const QString &_startZone = QString(), int _cardId = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, bool _faceDown = false);
QString getStartZone() const { return startZone; } QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); };
int getCardId() const { return cardId; } int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
QString getTargetZone() const { return targetZone; } QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); };
int getX() const { return x; } int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); };
int getY() const { return y; } int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); };
bool getFaceDown() const { return faceDown; } bool getFaceDown() const { return static_cast<SerializableItem_Bool *>(itemMap.value("face_down"))->getData(); };
static ProtocolItem *newItem() { return new Command_MoveCard; } static SerializableItem *newItem() { return new Command_MoveCard; }
int getItemId() const { return ItemId_Command_MoveCard; } int getItemId() const { return ItemId_Command_MoveCard; }
protected:
void extractParameters();
}; };
class Command_CreateToken : public GameCommand { class Command_CreateToken : public GameCommand {
Q_OBJECT Q_OBJECT
private:
QString zone;
QString cardName;
QString pt;
int x;
int y;
public: public:
Command_CreateToken(int _gameId = -1, const QString &_zone = QString(), const QString &_cardName = QString(), const QString &_pt = QString(), int _x = -1, int _y = -1); Command_CreateToken(int _gameId = -1, const QString &_zone = QString(), const QString &_cardName = QString(), const QString &_pt = QString(), int _x = -1, int _y = -1);
QString getZone() const { return zone; } QString getZone() const { return static_cast<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
QString getCardName() const { return cardName; } QString getCardName() const { return static_cast<SerializableItem_String *>(itemMap.value("card_name"))->getData(); };
QString getPt() const { return pt; } QString getPt() const { return static_cast<SerializableItem_String *>(itemMap.value("pt"))->getData(); };
int getX() const { return x; } int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); };
int getY() const { return y; } int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); };
static ProtocolItem *newItem() { return new Command_CreateToken; } static SerializableItem *newItem() { return new Command_CreateToken; }
int getItemId() const { return ItemId_Command_CreateToken; } int getItemId() const { return ItemId_Command_CreateToken; }
protected:
void extractParameters();
}; };
class Command_CreateArrow : public GameCommand { class Command_CreateArrow : public GameCommand {
Q_OBJECT Q_OBJECT
private:
int startPlayerId;
QString startZone;
int startCardId;
int targetPlayerId;
QString targetZone;
int targetCardId;
QColor color;
public: public:
Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const QColor &_color = QColor()); Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const QColor &_color = QColor());
int getStartPlayerId() const { return startPlayerId; } int getStartPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("start_player_id"))->getData(); };
QString getStartZone() const { return startZone; } QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); };
int getStartCardId() const { return startCardId; } int getStartCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("start_card_id"))->getData(); };
int getTargetPlayerId() const { return targetPlayerId; } int getTargetPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_player_id"))->getData(); };
QString getTargetZone() const { return targetZone; } QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); };
int getTargetCardId() const { return targetCardId; } int getTargetCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_card_id"))->getData(); };
QColor getColor() const { return color; } QColor getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); };
static ProtocolItem *newItem() { return new Command_CreateArrow; } static SerializableItem *newItem() { return new Command_CreateArrow; }
int getItemId() const { return ItemId_Command_CreateArrow; } int getItemId() const { return ItemId_Command_CreateArrow; }
protected:
void extractParameters();
}; };
class Command_DeleteArrow : public GameCommand { class Command_DeleteArrow : public GameCommand {
Q_OBJECT Q_OBJECT
private:
int arrowId;
public: public:
Command_DeleteArrow(int _gameId = -1, int _arrowId = -1); Command_DeleteArrow(int _gameId = -1, int _arrowId = -1);
int getArrowId() const { return arrowId; } int getArrowId() const { return static_cast<SerializableItem_Int *>(itemMap.value("arrow_id"))->getData(); };
static ProtocolItem *newItem() { return new Command_DeleteArrow; } static SerializableItem *newItem() { return new Command_DeleteArrow; }
int getItemId() const { return ItemId_Command_DeleteArrow; } int getItemId() const { return ItemId_Command_DeleteArrow; }
protected:
void extractParameters();
}; };
class Command_SetCardAttr : public GameCommand { class Command_SetCardAttr : public GameCommand {
Q_OBJECT Q_OBJECT
private:
QString zone;
int cardId;
QString attrName;
QString attrValue;
public: public:
Command_SetCardAttr(int _gameId = -1, const QString &_zone = QString(), int _cardId = -1, const QString &_attrName = QString(), const QString &_attrValue = QString()); Command_SetCardAttr(int _gameId = -1, const QString &_zone = QString(), int _cardId = -1, const QString &_attrName = QString(), const QString &_attrValue = QString());
QString getZone() const { return zone; } QString getZone() const { return static_cast<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
int getCardId() const { return cardId; } int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
QString getAttrName() const { return attrName; } QString getAttrName() const { return static_cast<SerializableItem_String *>(itemMap.value("attr_name"))->getData(); };
QString getAttrValue() const { return attrValue; } QString getAttrValue() const { return static_cast<SerializableItem_String *>(itemMap.value("attr_value"))->getData(); };
static ProtocolItem *newItem() { return new Command_SetCardAttr; } static SerializableItem *newItem() { return new Command_SetCardAttr; }
int getItemId() const { return ItemId_Command_SetCardAttr; } int getItemId() const { return ItemId_Command_SetCardAttr; }
protected:
void extractParameters();
}; };
class Command_ReadyStart : public GameCommand { class Command_ReadyStart : public GameCommand {
Q_OBJECT Q_OBJECT
private:
public: public:
Command_ReadyStart(int _gameId = -1); Command_ReadyStart(int _gameId = -1);
static ProtocolItem *newItem() { return new Command_ReadyStart; } static SerializableItem *newItem() { return new Command_ReadyStart; }
int getItemId() const { return ItemId_Command_ReadyStart; } int getItemId() const { return ItemId_Command_ReadyStart; }
}; };
class Command_IncCounter : public GameCommand { class Command_IncCounter : public GameCommand {
Q_OBJECT Q_OBJECT
private:
int counterId;
int delta;
public: public:
Command_IncCounter(int _gameId = -1, int _counterId = -1, int _delta = -1); Command_IncCounter(int _gameId = -1, int _counterId = -1, int _delta = -1);
int getCounterId() const { return counterId; } int getCounterId() const { return static_cast<SerializableItem_Int *>(itemMap.value("counter_id"))->getData(); };
int getDelta() const { return delta; } int getDelta() const { return static_cast<SerializableItem_Int *>(itemMap.value("delta"))->getData(); };
static ProtocolItem *newItem() { return new Command_IncCounter; } static SerializableItem *newItem() { return new Command_IncCounter; }
int getItemId() const { return ItemId_Command_IncCounter; } int getItemId() const { return ItemId_Command_IncCounter; }
protected:
void extractParameters();
}; };
class Command_CreateCounter : public GameCommand { class Command_CreateCounter : public GameCommand {
Q_OBJECT Q_OBJECT
private:
QString counterName;
QColor color;
int radius;
int value;
public: public:
Command_CreateCounter(int _gameId = -1, const QString &_counterName = QString(), const QColor &_color = QColor(), int _radius = -1, int _value = -1); Command_CreateCounter(int _gameId = -1, const QString &_counterName = QString(), const QColor &_color = QColor(), int _radius = -1, int _value = -1);
QString getCounterName() const { return counterName; } QString getCounterName() const { return static_cast<SerializableItem_String *>(itemMap.value("counter_name"))->getData(); };
QColor getColor() const { return color; } QColor getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); };
int getRadius() const { return radius; } int getRadius() const { return static_cast<SerializableItem_Int *>(itemMap.value("radius"))->getData(); };
int getValue() const { return value; } int getValue() const { return static_cast<SerializableItem_Int *>(itemMap.value("value"))->getData(); };
static ProtocolItem *newItem() { return new Command_CreateCounter; } static SerializableItem *newItem() { return new Command_CreateCounter; }
int getItemId() const { return ItemId_Command_CreateCounter; } int getItemId() const { return ItemId_Command_CreateCounter; }
protected:
void extractParameters();
}; };
class Command_SetCounter : public GameCommand { class Command_SetCounter : public GameCommand {
Q_OBJECT Q_OBJECT
private:
int counterId;
int value;
public: public:
Command_SetCounter(int _gameId = -1, int _counterId = -1, int _value = -1); Command_SetCounter(int _gameId = -1, int _counterId = -1, int _value = -1);
int getCounterId() const { return counterId; } int getCounterId() const { return static_cast<SerializableItem_Int *>(itemMap.value("counter_id"))->getData(); };
int getValue() const { return value; } int getValue() const { return static_cast<SerializableItem_Int *>(itemMap.value("value"))->getData(); };
static ProtocolItem *newItem() { return new Command_SetCounter; } static SerializableItem *newItem() { return new Command_SetCounter; }
int getItemId() const { return ItemId_Command_SetCounter; } int getItemId() const { return ItemId_Command_SetCounter; }
protected:
void extractParameters();
}; };
class Command_DelCounter : public GameCommand { class Command_DelCounter : public GameCommand {
Q_OBJECT Q_OBJECT
private:
int counterId;
public: public:
Command_DelCounter(int _gameId = -1, int _counterId = -1); Command_DelCounter(int _gameId = -1, int _counterId = -1);
int getCounterId() const { return counterId; } int getCounterId() const { return static_cast<SerializableItem_Int *>(itemMap.value("counter_id"))->getData(); };
static ProtocolItem *newItem() { return new Command_DelCounter; } static SerializableItem *newItem() { return new Command_DelCounter; }
int getItemId() const { return ItemId_Command_DelCounter; } int getItemId() const { return ItemId_Command_DelCounter; }
protected:
void extractParameters();
}; };
class Command_NextTurn : public GameCommand { class Command_NextTurn : public GameCommand {
Q_OBJECT Q_OBJECT
private:
public: public:
Command_NextTurn(int _gameId = -1); Command_NextTurn(int _gameId = -1);
static ProtocolItem *newItem() { return new Command_NextTurn; } static SerializableItem *newItem() { return new Command_NextTurn; }
int getItemId() const { return ItemId_Command_NextTurn; } int getItemId() const { return ItemId_Command_NextTurn; }
}; };
class Command_SetActivePhase : public GameCommand { class Command_SetActivePhase : public GameCommand {
Q_OBJECT Q_OBJECT
private:
int phase;
public: public:
Command_SetActivePhase(int _gameId = -1, int _phase = -1); Command_SetActivePhase(int _gameId = -1, int _phase = -1);
int getPhase() const { return phase; } int getPhase() const { return static_cast<SerializableItem_Int *>(itemMap.value("phase"))->getData(); };
static ProtocolItem *newItem() { return new Command_SetActivePhase; } static SerializableItem *newItem() { return new Command_SetActivePhase; }
int getItemId() const { return ItemId_Command_SetActivePhase; } int getItemId() const { return ItemId_Command_SetActivePhase; }
protected:
void extractParameters();
}; };
class Command_DumpZone : public GameCommand { class Command_DumpZone : public GameCommand {
Q_OBJECT Q_OBJECT
private:
int playerId;
QString zoneName;
int numberCards;
public: public:
Command_DumpZone(int _gameId = -1, int _playerId = -1, const QString &_zoneName = QString(), int _numberCards = -1); Command_DumpZone(int _gameId = -1, int _playerId = -1, const QString &_zoneName = QString(), int _numberCards = -1);
int getPlayerId() const { return playerId; } int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); };
QString getZoneName() const { return zoneName; } QString getZoneName() const { return static_cast<SerializableItem_String *>(itemMap.value("zone_name"))->getData(); };
int getNumberCards() const { return numberCards; } int getNumberCards() const { return static_cast<SerializableItem_Int *>(itemMap.value("number_cards"))->getData(); };
static ProtocolItem *newItem() { return new Command_DumpZone; } static SerializableItem *newItem() { return new Command_DumpZone; }
int getItemId() const { return ItemId_Command_DumpZone; } int getItemId() const { return ItemId_Command_DumpZone; }
protected:
void extractParameters();
}; };
class Command_StopDumpZone : public GameCommand { class Command_StopDumpZone : public GameCommand {
Q_OBJECT Q_OBJECT
private:
int playerId;
QString zoneName;
public: public:
Command_StopDumpZone(int _gameId = -1, int _playerId = -1, const QString &_zoneName = QString()); Command_StopDumpZone(int _gameId = -1, int _playerId = -1, const QString &_zoneName = QString());
int getPlayerId() const { return playerId; } int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); };
QString getZoneName() const { return zoneName; } QString getZoneName() const { return static_cast<SerializableItem_String *>(itemMap.value("zone_name"))->getData(); };
static ProtocolItem *newItem() { return new Command_StopDumpZone; } static SerializableItem *newItem() { return new Command_StopDumpZone; }
int getItemId() const { return ItemId_Command_StopDumpZone; } int getItemId() const { return ItemId_Command_StopDumpZone; }
protected:
void extractParameters();
}; };
class Event_Say : public GameEvent { class Event_Say : public GameEvent {
Q_OBJECT Q_OBJECT
private:
QString message;
public: public:
Event_Say(int _gameId = -1, int _playerId = -1, const QString &_message = QString()); Event_Say(int _gameId = -1, int _playerId = -1, const QString &_message = QString());
QString getMessage() const { return message; } QString getMessage() const { return static_cast<SerializableItem_String *>(itemMap.value("message"))->getData(); };
static ProtocolItem *newItem() { return new Event_Say; } static SerializableItem *newItem() { return new Event_Say; }
int getItemId() const { return ItemId_Event_Say; } int getItemId() const { return ItemId_Event_Say; }
protected:
void extractParameters();
}; };
class Event_Join : public GameEvent { class Event_Join : public GameEvent {
Q_OBJECT Q_OBJECT
private:
QString playerName;
bool spectator;
public: public:
Event_Join(int _gameId = -1, int _playerId = -1, const QString &_playerName = QString(), bool _spectator = false); Event_Join(int _gameId = -1, int _playerId = -1, const QString &_playerName = QString(), bool _spectator = false);
QString getPlayerName() const { return playerName; } QString getPlayerName() const { return static_cast<SerializableItem_String *>(itemMap.value("player_name"))->getData(); };
bool getSpectator() const { return spectator; } bool getSpectator() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectator"))->getData(); };
static ProtocolItem *newItem() { return new Event_Join; } static SerializableItem *newItem() { return new Event_Join; }
int getItemId() const { return ItemId_Event_Join; } int getItemId() const { return ItemId_Event_Join; }
protected:
void extractParameters();
}; };
class Event_Leave : public GameEvent { class Event_Leave : public GameEvent {
Q_OBJECT Q_OBJECT
private:
public: public:
Event_Leave(int _gameId = -1, int _playerId = -1); Event_Leave(int _gameId = -1, int _playerId = -1);
static ProtocolItem *newItem() { return new Event_Leave; } static SerializableItem *newItem() { return new Event_Leave; }
int getItemId() const { return ItemId_Event_Leave; } int getItemId() const { return ItemId_Event_Leave; }
}; };
class Event_DeckSelect : public GameEvent { class Event_DeckSelect : public GameEvent {
Q_OBJECT Q_OBJECT
private:
int deckId;
public: public:
Event_DeckSelect(int _gameId = -1, int _playerId = -1, int _deckId = -1); Event_DeckSelect(int _gameId = -1, int _playerId = -1, int _deckId = -1);
int getDeckId() const { return deckId; } int getDeckId() const { return static_cast<SerializableItem_Int *>(itemMap.value("deck_id"))->getData(); };
static ProtocolItem *newItem() { return new Event_DeckSelect; } static SerializableItem *newItem() { return new Event_DeckSelect; }
int getItemId() const { return ItemId_Event_DeckSelect; } int getItemId() const { return ItemId_Event_DeckSelect; }
protected:
void extractParameters();
}; };
class Event_GameClosed : public GameEvent { class Event_GameClosed : public GameEvent {
Q_OBJECT Q_OBJECT
private:
public: public:
Event_GameClosed(int _gameId = -1, int _playerId = -1); Event_GameClosed(int _gameId = -1, int _playerId = -1);
static ProtocolItem *newItem() { return new Event_GameClosed; } static SerializableItem *newItem() { return new Event_GameClosed; }
int getItemId() const { return ItemId_Event_GameClosed; } int getItemId() const { return ItemId_Event_GameClosed; }
}; };
class Event_ReadyStart : public GameEvent { class Event_ReadyStart : public GameEvent {
Q_OBJECT Q_OBJECT
private:
public: public:
Event_ReadyStart(int _gameId = -1, int _playerId = -1); Event_ReadyStart(int _gameId = -1, int _playerId = -1);
static ProtocolItem *newItem() { return new Event_ReadyStart; } static SerializableItem *newItem() { return new Event_ReadyStart; }
int getItemId() const { return ItemId_Event_ReadyStart; } int getItemId() const { return ItemId_Event_ReadyStart; }
}; };
class Event_GameStart : public GameEvent { class Event_GameStart : public GameEvent {
Q_OBJECT Q_OBJECT
private:
public: public:
Event_GameStart(int _gameId = -1, int _playerId = -1); Event_GameStart(int _gameId = -1, int _playerId = -1);
static ProtocolItem *newItem() { return new Event_GameStart; } static SerializableItem *newItem() { return new Event_GameStart; }
int getItemId() const { return ItemId_Event_GameStart; } int getItemId() const { return ItemId_Event_GameStart; }
}; };
class Event_Shuffle : public GameEvent { class Event_Shuffle : public GameEvent {
Q_OBJECT Q_OBJECT
private:
public: public:
Event_Shuffle(int _gameId = -1, int _playerId = -1); Event_Shuffle(int _gameId = -1, int _playerId = -1);
static ProtocolItem *newItem() { return new Event_Shuffle; } static SerializableItem *newItem() { return new Event_Shuffle; }
int getItemId() const { return ItemId_Event_Shuffle; } int getItemId() const { return ItemId_Event_Shuffle; }
}; };
class Event_RollDie : public GameEvent { class Event_RollDie : public GameEvent {
Q_OBJECT Q_OBJECT
private:
int sides;
int value;
public: public:
Event_RollDie(int _gameId = -1, int _playerId = -1, int _sides = -1, int _value = -1); Event_RollDie(int _gameId = -1, int _playerId = -1, int _sides = -1, int _value = -1);
int getSides() const { return sides; } int getSides() const { return static_cast<SerializableItem_Int *>(itemMap.value("sides"))->getData(); };
int getValue() const { return value; } int getValue() const { return static_cast<SerializableItem_Int *>(itemMap.value("value"))->getData(); };
static ProtocolItem *newItem() { return new Event_RollDie; } static SerializableItem *newItem() { return new Event_RollDie; }
int getItemId() const { return ItemId_Event_RollDie; } int getItemId() const { return ItemId_Event_RollDie; }
protected:
void extractParameters();
}; };
class Event_MoveCard : public GameEvent { class Event_MoveCard : public GameEvent {
Q_OBJECT Q_OBJECT
private:
int cardId;
QString cardName;
QString startZone;
int position;
QString targetZone;
int x;
int y;
bool faceDown;
public: public:
Event_MoveCard(int _gameId = -1, int _playerId = -1, int _cardId = -1, const QString &_cardName = QString(), const QString &_startZone = QString(), int _position = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, bool _faceDown = false); Event_MoveCard(int _gameId = -1, int _playerId = -1, int _cardId = -1, const QString &_cardName = QString(), const QString &_startZone = QString(), int _position = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, bool _faceDown = false);
int getCardId() const { return cardId; } int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
QString getCardName() const { return cardName; } QString getCardName() const { return static_cast<SerializableItem_String *>(itemMap.value("card_name"))->getData(); };
QString getStartZone() const { return startZone; } QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); };
int getPosition() const { return position; } int getPosition() const { return static_cast<SerializableItem_Int *>(itemMap.value("position"))->getData(); };
QString getTargetZone() const { return targetZone; } QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); };
int getX() const { return x; } int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); };
int getY() const { return y; } int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); };
bool getFaceDown() const { return faceDown; } bool getFaceDown() const { return static_cast<SerializableItem_Bool *>(itemMap.value("face_down"))->getData(); };
static ProtocolItem *newItem() { return new Event_MoveCard; } static SerializableItem *newItem() { return new Event_MoveCard; }
int getItemId() const { return ItemId_Event_MoveCard; } int getItemId() const { return ItemId_Event_MoveCard; }
protected:
void extractParameters();
}; };
class Event_CreateToken : public GameEvent { class Event_CreateToken : public GameEvent {
Q_OBJECT Q_OBJECT
private:
QString zone;
int cardId;
QString cardName;
QString pt;
int x;
int y;
public: public:
Event_CreateToken(int _gameId = -1, int _playerId = -1, const QString &_zone = QString(), int _cardId = -1, const QString &_cardName = QString(), const QString &_pt = QString(), int _x = -1, int _y = -1); Event_CreateToken(int _gameId = -1, int _playerId = -1, const QString &_zone = QString(), int _cardId = -1, const QString &_cardName = QString(), const QString &_pt = QString(), int _x = -1, int _y = -1);
QString getZone() const { return zone; } QString getZone() const { return static_cast<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
int getCardId() const { return cardId; } int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
QString getCardName() const { return cardName; } QString getCardName() const { return static_cast<SerializableItem_String *>(itemMap.value("card_name"))->getData(); };
QString getPt() const { return pt; } QString getPt() const { return static_cast<SerializableItem_String *>(itemMap.value("pt"))->getData(); };
int getX() const { return x; } int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); };
int getY() const { return y; } int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); };
static ProtocolItem *newItem() { return new Event_CreateToken; } static SerializableItem *newItem() { return new Event_CreateToken; }
int getItemId() const { return ItemId_Event_CreateToken; } int getItemId() const { return ItemId_Event_CreateToken; }
protected:
void extractParameters();
}; };
class Event_DeleteArrow : public GameEvent { class Event_DeleteArrow : public GameEvent {
Q_OBJECT Q_OBJECT
private:
int arrowId;
public: public:
Event_DeleteArrow(int _gameId = -1, int _playerId = -1, int _arrowId = -1); Event_DeleteArrow(int _gameId = -1, int _playerId = -1, int _arrowId = -1);
int getArrowId() const { return arrowId; } int getArrowId() const { return static_cast<SerializableItem_Int *>(itemMap.value("arrow_id"))->getData(); };
static ProtocolItem *newItem() { return new Event_DeleteArrow; } static SerializableItem *newItem() { return new Event_DeleteArrow; }
int getItemId() const { return ItemId_Event_DeleteArrow; } int getItemId() const { return ItemId_Event_DeleteArrow; }
protected:
void extractParameters();
}; };
class Event_SetCardAttr : public GameEvent { class Event_SetCardAttr : public GameEvent {
Q_OBJECT Q_OBJECT
private:
QString zone;
int cardId;
QString attrName;
QString attrValue;
public: public:
Event_SetCardAttr(int _gameId = -1, int _playerId = -1, const QString &_zone = QString(), int _cardId = -1, const QString &_attrName = QString(), const QString &_attrValue = QString()); Event_SetCardAttr(int _gameId = -1, int _playerId = -1, const QString &_zone = QString(), int _cardId = -1, const QString &_attrName = QString(), const QString &_attrValue = QString());
QString getZone() const { return zone; } QString getZone() const { return static_cast<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
int getCardId() const { return cardId; } int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
QString getAttrName() const { return attrName; } QString getAttrName() const { return static_cast<SerializableItem_String *>(itemMap.value("attr_name"))->getData(); };
QString getAttrValue() const { return attrValue; } QString getAttrValue() const { return static_cast<SerializableItem_String *>(itemMap.value("attr_value"))->getData(); };
static ProtocolItem *newItem() { return new Event_SetCardAttr; } static SerializableItem *newItem() { return new Event_SetCardAttr; }
int getItemId() const { return ItemId_Event_SetCardAttr; } int getItemId() const { return ItemId_Event_SetCardAttr; }
protected:
void extractParameters();
}; };
class Event_SetCounter : public GameEvent { class Event_SetCounter : public GameEvent {
Q_OBJECT Q_OBJECT
private:
int counterId;
int value;
public: public:
Event_SetCounter(int _gameId = -1, int _playerId = -1, int _counterId = -1, int _value = -1); Event_SetCounter(int _gameId = -1, int _playerId = -1, int _counterId = -1, int _value = -1);
int getCounterId() const { return counterId; } int getCounterId() const { return static_cast<SerializableItem_Int *>(itemMap.value("counter_id"))->getData(); };
int getValue() const { return value; } int getValue() const { return static_cast<SerializableItem_Int *>(itemMap.value("value"))->getData(); };
static ProtocolItem *newItem() { return new Event_SetCounter; } static SerializableItem *newItem() { return new Event_SetCounter; }
int getItemId() const { return ItemId_Event_SetCounter; } int getItemId() const { return ItemId_Event_SetCounter; }
protected:
void extractParameters();
}; };
class Event_DelCounter : public GameEvent { class Event_DelCounter : public GameEvent {
Q_OBJECT Q_OBJECT
private:
int counterId;
public: public:
Event_DelCounter(int _gameId = -1, int _playerId = -1, int _counterId = -1); Event_DelCounter(int _gameId = -1, int _playerId = -1, int _counterId = -1);
int getCounterId() const { return counterId; } int getCounterId() const { return static_cast<SerializableItem_Int *>(itemMap.value("counter_id"))->getData(); };
static ProtocolItem *newItem() { return new Event_DelCounter; } static SerializableItem *newItem() { return new Event_DelCounter; }
int getItemId() const { return ItemId_Event_DelCounter; } int getItemId() const { return ItemId_Event_DelCounter; }
protected:
void extractParameters();
}; };
class Event_SetActivePlayer : public GameEvent { class Event_SetActivePlayer : public GameEvent {
Q_OBJECT Q_OBJECT
private:
int activePlayerId;
public: public:
Event_SetActivePlayer(int _gameId = -1, int _playerId = -1, int _activePlayerId = -1); Event_SetActivePlayer(int _gameId = -1, int _playerId = -1, int _activePlayerId = -1);
int getActivePlayerId() const { return activePlayerId; } int getActivePlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("active_player_id"))->getData(); };
static ProtocolItem *newItem() { return new Event_SetActivePlayer; } static SerializableItem *newItem() { return new Event_SetActivePlayer; }
int getItemId() const { return ItemId_Event_SetActivePlayer; } int getItemId() const { return ItemId_Event_SetActivePlayer; }
protected:
void extractParameters();
}; };
class Event_SetActivePhase : public GameEvent { class Event_SetActivePhase : public GameEvent {
Q_OBJECT Q_OBJECT
private:
int phase;
public: public:
Event_SetActivePhase(int _gameId = -1, int _playerId = -1, int _phase = -1); Event_SetActivePhase(int _gameId = -1, int _playerId = -1, int _phase = -1);
int getPhase() const { return phase; } int getPhase() const { return static_cast<SerializableItem_Int *>(itemMap.value("phase"))->getData(); };
static ProtocolItem *newItem() { return new Event_SetActivePhase; } static SerializableItem *newItem() { return new Event_SetActivePhase; }
int getItemId() const { return ItemId_Event_SetActivePhase; } int getItemId() const { return ItemId_Event_SetActivePhase; }
protected:
void extractParameters();
}; };
class Event_DumpZone : public GameEvent { class Event_DumpZone : public GameEvent {
Q_OBJECT Q_OBJECT
private:
int zoneOwnerId;
QString zone;
int numberCards;
public: public:
Event_DumpZone(int _gameId = -1, int _playerId = -1, int _zoneOwnerId = -1, const QString &_zone = QString(), int _numberCards = -1); Event_DumpZone(int _gameId = -1, int _playerId = -1, int _zoneOwnerId = -1, const QString &_zone = QString(), int _numberCards = -1);
int getZoneOwnerId() const { return zoneOwnerId; } int getZoneOwnerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("zone_owner_id"))->getData(); };
QString getZone() const { return zone; } QString getZone() const { return static_cast<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
int getNumberCards() const { return numberCards; } int getNumberCards() const { return static_cast<SerializableItem_Int *>(itemMap.value("number_cards"))->getData(); };
static ProtocolItem *newItem() { return new Event_DumpZone; } static SerializableItem *newItem() { return new Event_DumpZone; }
int getItemId() const { return ItemId_Event_DumpZone; } int getItemId() const { return ItemId_Event_DumpZone; }
protected:
void extractParameters();
}; };
class Event_StopDumpZone : public GameEvent { class Event_StopDumpZone : public GameEvent {
Q_OBJECT Q_OBJECT
private:
int zoneOwnerId;
QString zone;
public: public:
Event_StopDumpZone(int _gameId = -1, int _playerId = -1, int _zoneOwnerId = -1, const QString &_zone = QString()); Event_StopDumpZone(int _gameId = -1, int _playerId = -1, int _zoneOwnerId = -1, const QString &_zone = QString());
int getZoneOwnerId() const { return zoneOwnerId; } int getZoneOwnerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("zone_owner_id"))->getData(); };
QString getZone() const { return zone; } QString getZone() const { return static_cast<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
static ProtocolItem *newItem() { return new Event_StopDumpZone; } static SerializableItem *newItem() { return new Event_StopDumpZone; }
int getItemId() const { return ItemId_Event_StopDumpZone; } int getItemId() const { return ItemId_Event_StopDumpZone; }
protected:
void extractParameters();
}; };
class Event_ServerMessage : public GenericEvent { class Event_ServerMessage : public GenericEvent {
Q_OBJECT Q_OBJECT
private:
QString message;
public: public:
Event_ServerMessage(const QString &_message = QString()); Event_ServerMessage(const QString &_message = QString());
QString getMessage() const { return message; } QString getMessage() const { return static_cast<SerializableItem_String *>(itemMap.value("message"))->getData(); };
static ProtocolItem *newItem() { return new Event_ServerMessage; } static SerializableItem *newItem() { return new Event_ServerMessage; }
int getItemId() const { return ItemId_Event_ServerMessage; } int getItemId() const { return ItemId_Event_ServerMessage; }
protected:
void extractParameters();
}; };
class Event_GameJoined : public GenericEvent { class Event_GameJoined : public GenericEvent {
Q_OBJECT Q_OBJECT
private:
int gameId;
int playerId;
bool spectator;
public: public:
Event_GameJoined(int _gameId = -1, int _playerId = -1, bool _spectator = false); Event_GameJoined(int _gameId = -1, int _playerId = -1, bool _spectator = false);
int getGameId() const { return gameId; } int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); };
int getPlayerId() const { return playerId; } int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); };
bool getSpectator() const { return spectator; } bool getSpectator() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectator"))->getData(); };
static ProtocolItem *newItem() { return new Event_GameJoined; } static SerializableItem *newItem() { return new Event_GameJoined; }
int getItemId() const { return ItemId_Event_GameJoined; } int getItemId() const { return ItemId_Event_GameJoined; }
protected:
void extractParameters();
}; };
class Event_ChatJoinChannel : public ChatEvent { class Event_ChatJoinChannel : public ChatEvent {
Q_OBJECT Q_OBJECT
private:
QString playerName;
public: public:
Event_ChatJoinChannel(const QString &_channel = QString(), const QString &_playerName = QString()); Event_ChatJoinChannel(const QString &_channel = QString(), const QString &_playerName = QString());
QString getPlayerName() const { return playerName; } QString getPlayerName() const { return static_cast<SerializableItem_String *>(itemMap.value("player_name"))->getData(); };
static ProtocolItem *newItem() { return new Event_ChatJoinChannel; } static SerializableItem *newItem() { return new Event_ChatJoinChannel; }
int getItemId() const { return ItemId_Event_ChatJoinChannel; } int getItemId() const { return ItemId_Event_ChatJoinChannel; }
protected:
void extractParameters();
}; };
class Event_ChatLeaveChannel : public ChatEvent { class Event_ChatLeaveChannel : public ChatEvent {
Q_OBJECT Q_OBJECT
private:
QString playerName;
public: public:
Event_ChatLeaveChannel(const QString &_channel = QString(), const QString &_playerName = QString()); Event_ChatLeaveChannel(const QString &_channel = QString(), const QString &_playerName = QString());
QString getPlayerName() const { return playerName; } QString getPlayerName() const { return static_cast<SerializableItem_String *>(itemMap.value("player_name"))->getData(); };
static ProtocolItem *newItem() { return new Event_ChatLeaveChannel; } static SerializableItem *newItem() { return new Event_ChatLeaveChannel; }
int getItemId() const { return ItemId_Event_ChatLeaveChannel; } int getItemId() const { return ItemId_Event_ChatLeaveChannel; }
protected:
void extractParameters();
}; };
class Event_ChatSay : public ChatEvent { class Event_ChatSay : public ChatEvent {
Q_OBJECT Q_OBJECT
private:
QString playerName;
QString message;
public: public:
Event_ChatSay(const QString &_channel = QString(), const QString &_playerName = QString(), const QString &_message = QString()); Event_ChatSay(const QString &_channel = QString(), const QString &_playerName = QString(), const QString &_message = QString());
QString getPlayerName() const { return playerName; } QString getPlayerName() const { return static_cast<SerializableItem_String *>(itemMap.value("player_name"))->getData(); };
QString getMessage() const { return message; } QString getMessage() const { return static_cast<SerializableItem_String *>(itemMap.value("message"))->getData(); };
static ProtocolItem *newItem() { return new Event_ChatSay; } static SerializableItem *newItem() { return new Event_ChatSay; }
int getItemId() const { return ItemId_Event_ChatSay; } int getItemId() const { return ItemId_Event_ChatSay; }
protected:
void extractParameters();
}; };
#endif #endif

View file

@ -70,12 +70,9 @@ while (<file>) {
$className = $namePrefix . '_' . $name2; $className = $namePrefix . '_' . $name2;
$itemEnum .= "ItemId_$className = " . ++$itemId . ",\n"; $itemEnum .= "ItemId_$className = " . ++$itemId . ",\n";
$headerfileBuffer .= "class $className : public $baseClass {\n" $headerfileBuffer .= "class $className : public $baseClass {\n"
. "\tQ_OBJECT\n" . "\tQ_OBJECT\n";
. "private:\n"; $constructorCode = '';
$paramStr2 = ''; $getFunctionCode = '';
$paramStr3 = '';
$paramStr4 = '';
$paramStr5 = '';
while ($param = shift(@line)) { while ($param = shift(@line)) {
($key, $value) = split(/,/, $param); ($key, $value) = split(/,/, $param);
($prettyVarName = $value) =~ s/_(.)/\U$1\E/g; ($prettyVarName = $value) =~ s/_(.)/\U$1\E/g;
@ -85,52 +82,44 @@ while (<file>) {
if (!($constructorParamsCpp eq '')) { if (!($constructorParamsCpp eq '')) {
$constructorParamsCpp .= ', '; $constructorParamsCpp .= ', ';
} }
$paramStr2 .= ", $prettyVarName(_$prettyVarName)"; ($prettyVarName2 = $prettyVarName) =~ s/^(.)/\U$1\E/;
$paramStr3 .= "\tsetParameter(\"$value\", $prettyVarName);\n";
if ($key eq 'b') { if ($key eq 'b') {
$dataType = 'bool'; $dataType = 'bool';
$constructorParamsH .= "bool _$prettyVarName = false"; $constructorParamsH .= "bool _$prettyVarName = false";
$constructorParamsCpp .= "bool _$prettyVarName"; $constructorParamsCpp .= "bool _$prettyVarName";
$paramStr5 .= "\t$prettyVarName = (parameters[\"$value\"] == \"1\");\n"; $constructorCode .= "\tinsertItem(new SerializableItem_Bool(\"$value\", _$prettyVarName));\n";
$getFunctionCode .= "\t$dataType get$prettyVarName2() const { return static_cast<SerializableItem_Bool *>(itemMap.value(\"$value\"))->getData(); };\n";
} elsif ($key eq 's') { } elsif ($key eq 's') {
$dataType = 'QString'; $dataType = 'QString';
$constructorParamsH .= "const QString &_$prettyVarName = QString()"; $constructorParamsH .= "const QString &_$prettyVarName = QString()";
$constructorParamsCpp .= "const QString &_$prettyVarName"; $constructorParamsCpp .= "const QString &_$prettyVarName";
$paramStr5 .= "\t$prettyVarName = parameters[\"$value\"];\n"; $constructorCode .= "\tinsertItem(new SerializableItem_String(\"$value\", _$prettyVarName));\n";
$getFunctionCode .= "\t$dataType get$prettyVarName2() const { return static_cast<SerializableItem_String *>(itemMap.value(\"$value\"))->getData(); };\n";
} elsif ($key eq 'i') { } elsif ($key eq 'i') {
$dataType = 'int'; $dataType = 'int';
$constructorParamsH .= "int _$prettyVarName = -1"; $constructorParamsH .= "int _$prettyVarName = -1";
$constructorParamsCpp .= "int _$prettyVarName"; $constructorParamsCpp .= "int _$prettyVarName";
$paramStr5 .= "\t$prettyVarName = parameters[\"$value\"].toInt();\n"; $constructorCode .= "\tinsertItem(new SerializableItem_Int(\"$value\", _$prettyVarName));\n";
$getFunctionCode .= "\t$dataType get$prettyVarName2() const { return static_cast<SerializableItem_Int *>(itemMap.value(\"$value\"))->getData(); };\n";
} elsif ($key eq 'c') { } elsif ($key eq 'c') {
$dataType = 'QColor'; $dataType = 'QColor';
$constructorParamsH .= "const QColor &_$prettyVarName = QColor()"; $constructorParamsH .= "const QColor &_$prettyVarName = QColor()";
$constructorParamsCpp .= "const QColor &_$prettyVarName"; $constructorParamsCpp .= "const QColor &_$prettyVarName";
$paramStr5 .= "\t$prettyVarName = ColorConverter::colorFromInt(parameters[\"$value\"].toInt());\n"; $constructorCode .= "\tinsertItem(new SerializableItem_Color(\"$value\", _$prettyVarName));\n";
$getFunctionCode .= "\t$dataType get$prettyVarName2() const { return static_cast<SerializableItem_Color *>(itemMap.value(\"$value\"))->getData(); };\n";
} }
($prettyVarName2 = $prettyVarName) =~ s/^(.)/\U$1\E/;
$paramStr4 .= "\t$dataType get$prettyVarName2() const { return $prettyVarName; }\n";
$headerfileBuffer .= "\t$dataType $prettyVarName;\n";
} }
$headerfileBuffer .= "public:\n" $headerfileBuffer .= "public:\n"
. "\t$className($constructorParamsH);\n" . "\t$className($constructorParamsH);\n"
. $paramStr4 . $getFunctionCode
. "\tstatic ProtocolItem *newItem() { return new $className; }\n" . "\tstatic SerializableItem *newItem() { return new $className; }\n"
. "\tint getItemId() const { return ItemId_$className; }\n" . "\tint getItemId() const { return ItemId_$className; }\n"
. ($paramStr5 eq '' ? '' : "protected:\n\tvoid extractParameters();\n")
. "};\n"; . "};\n";
print cppfile $className . "::$className($constructorParamsCpp)\n" print cppfile $className . "::$className($constructorParamsCpp)\n"
. "\t: $parentConstructorCall$paramStr2\n" . "\t: $parentConstructorCall\n"
. "{\n" . "{\n"
. $paramStr3 . $constructorCode
. "}\n"; . "}\n";
if (!($paramStr5 eq '')) {
print cppfile "void $className" . "::extractParameters()\n"
. "{\n"
. "\t$baseClass" . "::extractParameters();\n"
. $paramStr5
. "}\n";
}
$initializeHash .= "\titemNameHash.insert(\"$type$name1\", $className" . "::newItem);\n"; $initializeHash .= "\titemNameHash.insert(\"$type$name1\", $className" . "::newItem);\n";
} }
close(file); close(file);

View file

@ -0,0 +1,157 @@
#include "serializable_item.h"
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QDebug>
QHash<QString, SerializableItem::NewItemFunction> SerializableItem::itemNameHash;
SerializableItem *SerializableItem::getNewItem(const QString &name)
{
if (!itemNameHash.contains(name))
return 0;
return itemNameHash.value(name)();
}
void SerializableItem::registerSerializableItem(const QString &name, NewItemFunction func)
{
itemNameHash.insert(name, func);
}
bool SerializableItem::read(QXmlStreamReader *xml)
{
while (!xml->atEnd()) {
xml->readNext();
readElement(xml);
if (xml->isEndElement() && (xml->name() == itemType))
return true;
}
return false;
}
void SerializableItem::write(QXmlStreamWriter *xml)
{
xml->writeStartElement(itemType);
if (!itemSubType.isEmpty())
xml->writeAttribute("type", itemSubType);
writeElement(xml);
xml->writeEndElement();
}
SerializableItem_Map::~SerializableItem_Map()
{
QMapIterator<QString, SerializableItem *> mapIterator(itemMap);
while (mapIterator.hasNext())
delete mapIterator.next().value();
for (int i = 0; i < itemList.size(); ++i)
delete itemList[i];
}
void SerializableItem_Map::readElement(QXmlStreamReader *xml)
{
if (currentItem) {
if (currentItem->read(xml))
currentItem = 0;
} else if (xml->isEndElement() && (xml->name() == itemType))
extractData();
else if (xml->isStartElement()) {
QString childName = xml->name().toString();
QString childSubType = xml->attributes().value("type").toString();
qDebug() << "Map: started new item, name=" << childName << "subtype=" << childSubType;
currentItem = itemMap.value(childName);
if (!currentItem) {
qDebug() << "Item not found in map";
currentItem = getNewItem(childName + childSubType);
itemList.append(currentItem);
if (!currentItem) {
qDebug() << "Item still not found";
currentItem = new SerializableItem_Invalid(childName);
}
}
if (currentItem->read(xml))
currentItem = 0;
}
}
void SerializableItem_Map::writeElement(QXmlStreamWriter *xml)
{
QMapIterator<QString, SerializableItem *> mapIterator(itemMap);
while (mapIterator.hasNext())
mapIterator.next().value()->write(xml);
for (int i = 0; i < itemList.size(); ++i)
itemList[i]->write(xml);
}
void SerializableItem_String::readElement(QXmlStreamReader *xml)
{
if (xml->isCharacters() && !xml->isWhitespace())
data = xml->text().toString();
}
void SerializableItem_String::writeElement(QXmlStreamWriter *xml)
{
xml->writeCharacters(data);
}
void SerializableItem_Int::readElement(QXmlStreamReader *xml)
{
if (xml->isCharacters() && !xml->isWhitespace()) {
bool ok;
data = xml->text().toString().toInt(&ok);
if (!ok)
data = -1;
}
}
void SerializableItem_Int::writeElement(QXmlStreamWriter *xml)
{
xml->writeCharacters(QString::number(data));
}
void SerializableItem_Bool::readElement(QXmlStreamReader *xml)
{
if (xml->isCharacters() && !xml->isWhitespace())
data = xml->text().toString() == "1";
}
void SerializableItem_Bool::writeElement(QXmlStreamWriter *xml)
{
xml->writeCharacters(data ? "1" : "0");
}
int SerializableItem_Color::colorToInt(const QColor &color) const
{
return color.red() * 65536 + color.green() * 256 + color.blue();
}
QColor SerializableItem_Color::colorFromInt(int colorValue) const
{
return QColor(colorValue / 65536, (colorValue % 65536) / 256, colorValue % 256);
}
void SerializableItem_Color::readElement(QXmlStreamReader *xml)
{
if (xml->isCharacters() && !xml->isWhitespace()) {
bool ok;
int colorValue = xml->text().toString().toInt(&ok);
data = ok ? colorFromInt(colorValue) : Qt::black;
}
}
void SerializableItem_Color::writeElement(QXmlStreamWriter *xml)
{
xml->writeCharacters(QString::number(colorToInt(data)));
}
void SerializableItem_DateTime::readElement(QXmlStreamReader *xml)
{
if (xml->isCharacters() && !xml->isWhitespace()) {
bool ok;
unsigned int dateTimeValue = xml->text().toString().toUInt(&ok);
data = ok ? QDateTime::fromTime_t(dateTimeValue) : QDateTime();
}
}
void SerializableItem_DateTime::writeElement(QXmlStreamWriter *xml)
{
xml->writeCharacters(QString::number(data.toTime_t()));
}

140
common/serializable_item.h Normal file
View file

@ -0,0 +1,140 @@
#ifndef SERIALIZABLE_ITEM_H
#define SERIALIZABLE_ITEM_H
#include <QObject>
#include <QMap>
#include <QList>
#include <QHash>
#include <QColor>
#include <QDateTime>
class QXmlStreamReader;
class QXmlStreamWriter;
class SerializableItem : public QObject {
Q_OBJECT
protected:
typedef SerializableItem *(*NewItemFunction)();
static QHash<QString, NewItemFunction> itemNameHash;
QString itemType, itemSubType;
public:
SerializableItem(const QString &_itemType, const QString &_itemSubType = QString())
: QObject(), itemType(_itemType), itemSubType(_itemSubType) { }
static void registerSerializableItem(const QString &name, NewItemFunction func);
static SerializableItem *getNewItem(const QString &name);
const QString &getItemType() const { return itemType; }
const QString &getItemSubType() const { return itemSubType; }
virtual void readElement(QXmlStreamReader *xml) = 0;
virtual void writeElement(QXmlStreamWriter *xml) = 0;
bool read(QXmlStreamReader *xml);
void write(QXmlStreamWriter *xml);
};
class SerializableItem_Invalid : public SerializableItem {
public:
SerializableItem_Invalid(const QString &_itemType) : SerializableItem(_itemType) { }
void readElement(QXmlStreamReader * /*xml*/) { }
void writeElement(QXmlStreamWriter * /*xml*/) { }
};
class SerializableItem_Map : public SerializableItem {
private:
SerializableItem *currentItem;
protected:
QMap<QString, SerializableItem *> itemMap;
QList<SerializableItem *> itemList;
virtual void extractData() { }
void insertItem(SerializableItem *item)
{
itemMap.insert(item->getItemType(), item);
}
template<class T> QList<T> typecastItemList() const
{
QList<T> result;
for (int i = 0; i < itemList.size(); ++i) {
T item = dynamic_cast<T>(itemList[i]);
if (item)
result.append(item);
}
return result;
}
public:
SerializableItem_Map(const QString &_itemType, const QString &_itemSubType = QString())
: SerializableItem(_itemType, _itemSubType), currentItem(0)
{
}
~SerializableItem_Map();
void readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
void appendItem(SerializableItem *item) { itemList.append(item); }
};
class SerializableItem_String : public SerializableItem {
private:
QString data;
protected:
void readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public:
SerializableItem_String(const QString &_itemType, const QString &_data)
: SerializableItem(_itemType), data(_data) { }
const QString &getData() { return data; }
void setData(const QString &_data) { data = _data; }
};
class SerializableItem_Int : public SerializableItem {
private:
int data;
protected:
void readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public:
SerializableItem_Int(const QString &_itemType, int _data)
: SerializableItem(_itemType), data(_data) { }
int getData() { return data; }
void setData(int _data) { data = _data; }
};
class SerializableItem_Bool : public SerializableItem {
private:
bool data;
protected:
void readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public:
SerializableItem_Bool(const QString &_itemType, bool _data)
: SerializableItem(_itemType), data(_data) { }
bool getData() { return data; }
void setData(bool _data) { data = _data; }
};
class SerializableItem_Color : public SerializableItem {
private:
QColor data;
int colorToInt(const QColor &color) const;
QColor colorFromInt(int colorValue) const;
protected:
void readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public:
SerializableItem_Color(const QString &_itemType, const QColor &_data)
: SerializableItem(_itemType), data(_data) { }
const QColor &getData() { return data; }
void setData(const QColor &_data) { data = _data; }
};
class SerializableItem_DateTime : public SerializableItem {
private:
QDateTime data;
protected:
void readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
public:
SerializableItem_DateTime(const QString &_itemType, const QDateTime &_data)
: SerializableItem(_itemType), data(_data) { }
const QDateTime &getData() { return data; }
void setData(const QDateTime &_data) { data = _data; }
};
#endif

View file

@ -61,10 +61,10 @@ Server_Game *Server::getGame(int gameId) const
void Server::broadcastGameListUpdate(Server_Game *game) void Server::broadcastGameListUpdate(Server_Game *game)
{ {
Event_ListGames *event = new Event_ListGames; QList<ServerInfo_Game *> eventGameList;
if (game->getPlayerCount()) if (game->getPlayerCount())
// Game is open // Game is open
event->addGame( eventGameList.append(new ServerInfo_Game(
game->getGameId(), game->getGameId(),
game->getDescription(), game->getDescription(),
!game->getPassword().isEmpty(), !game->getPassword().isEmpty(),
@ -73,10 +73,11 @@ void Server::broadcastGameListUpdate(Server_Game *game)
game->getCreatorName(), game->getCreatorName(),
game->getSpectatorsAllowed(), game->getSpectatorsAllowed(),
game->getSpectatorCount() game->getSpectatorCount()
); ));
else else
// Game is closing // Game is closing
event->addGame(game->getGameId(), QString(), false, 0, game->getMaxPlayers(), QString(), false, 0); eventGameList.append(new ServerInfo_Game(game->getGameId(), QString(), false, 0, game->getMaxPlayers(), QString(), false, 0));
Event_ListGames *event = new Event_ListGames(eventGameList);
for (int i = 0; i < clients.size(); i++) for (int i = 0; i < clients.size(); i++)
if (clients[i]->getAcceptsGameListChanges()) if (clients[i]->getAcceptsGameListChanges())
@ -87,8 +88,9 @@ void Server::broadcastGameListUpdate(Server_Game *game)
void Server::broadcastChannelUpdate() void Server::broadcastChannelUpdate()
{ {
Server_ChatChannel *channel = static_cast<Server_ChatChannel *>(sender()); Server_ChatChannel *channel = static_cast<Server_ChatChannel *>(sender());
Event_ListChatChannels *event = new Event_ListChatChannels; QList<ServerInfo_ChatChannel *> eventChannelList;
event->addChannel(channel->getName(), channel->getDescription(), channel->size(), channel->getAutoJoin()); eventChannelList.append(new ServerInfo_ChatChannel(channel->getName(), channel->getDescription(), channel->size(), channel->getAutoJoin()));
Event_ListChatChannels *event = new Event_ListChatChannels(eventChannelList);
for (int i = 0; i < clients.size(); ++i) for (int i = 0; i < clients.size(); ++i)
if (clients[i]->getAcceptsChatChannelListChanges()) if (clients[i]->getAcceptsChatChannelListChanges())

View file

@ -11,9 +11,10 @@ void Server_ChatChannel::addClient(Server_ProtocolHandler *client)
sendChatEvent(new Event_ChatJoinChannel(name, client->getPlayerName())); sendChatEvent(new Event_ChatJoinChannel(name, client->getPlayerName()));
append(client); append(client);
Event_ChatListPlayers *eventCLP = new Event_ChatListPlayers(name); QList<ServerInfo_ChatUser *> eventUserList;
for (int i = 0; i < size(); ++i) for (int i = 0; i < size(); ++i)
eventCLP->addPlayer(at(i)->getPlayerName()); eventUserList.append(new ServerInfo_ChatUser(at(i)->getPlayerName()));
Event_ChatListPlayers *eventCLP = new Event_ChatListPlayers(name, eventUserList);
client->enqueueProtocolItem(eventCLP); client->enqueueProtocolItem(eventCLP);
client->enqueueProtocolItem(new Event_ChatSay(name, QString(), joinMessage)); client->enqueueProtocolItem(new Event_ChatSay(name, QString(), joinMessage));

View file

@ -10,6 +10,7 @@
#include "server_counter.h" #include "server_counter.h"
#include "server_game.h" #include "server_game.h"
#include "server_player.h" #include "server_player.h"
#include "decklist.h"
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent) Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent)
: QObject(parent), server(_server), authState(PasswordWrong), acceptsGameListChanges(false) : QObject(parent), server(_server), authState(PasswordWrong), acceptsGameListChanges(false)
@ -148,13 +149,13 @@ ResponseCode Server_ProtocolHandler::cmdListChatChannels(Command_ListChatChannel
if (authState == PasswordWrong) if (authState == PasswordWrong)
return RespLoginNeeded; return RespLoginNeeded;
Event_ListChatChannels *event = new Event_ListChatChannels; QList<ServerInfo_ChatChannel *> eventChannelList;
QMapIterator<QString, Server_ChatChannel *> channelIterator(server->getChatChannels()); QMapIterator<QString, Server_ChatChannel *> channelIterator(server->getChatChannels());
while (channelIterator.hasNext()) { while (channelIterator.hasNext()) {
Server_ChatChannel *c = channelIterator.next().value(); Server_ChatChannel *c = channelIterator.next().value();
event->addChannel(c->getName(), c->getDescription(), c->size(), c->getAutoJoin()); eventChannelList.append(new ServerInfo_ChatChannel(c->getName(), c->getDescription(), c->size(), c->getAutoJoin()));
} }
sendProtocolItem(event); sendProtocolItem(new Event_ListChatChannels(eventChannelList));
acceptsChatChannelListChanges = true; acceptsChatChannelListChanges = true;
return RespOk; return RespOk;
@ -193,11 +194,11 @@ ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, Server_Cha
ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/) ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/)
{ {
Event_ListGames *event = new Event_ListGames;
const QList<Server_Game *> &gameList = server->getGames(); const QList<Server_Game *> &gameList = server->getGames();
QList<ServerInfo_Game *> eventGameList;
for (int i = 0; i < gameList.size(); ++i) { for (int i = 0; i < gameList.size(); ++i) {
Server_Game *g = gameList[i]; Server_Game *g = gameList[i];
event->addGame( eventGameList.append(new ServerInfo_Game(
g->getGameId(), g->getGameId(),
g->getDescription(), g->getDescription(),
!g->getPassword().isEmpty(), !g->getPassword().isEmpty(),
@ -206,9 +207,9 @@ ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/)
g->getCreatorName(), g->getCreatorName(),
g->getSpectatorsAllowed(), g->getSpectatorsAllowed(),
g->getSpectatorCount() g->getSpectatorCount()
); ));
} }
sendProtocolItem(event); sendProtocolItem(new Event_ListGames(eventGameList));
acceptsGameListChanges = true; acceptsGameListChanges = true;
return RespOk; return RespOk;
@ -253,7 +254,7 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Serv
if (cmd->getDeckId() == -1) { if (cmd->getDeckId() == -1) {
if (!cmd->getDeck()) if (!cmd->getDeck())
return RespInvalidData; return RespInvalidData;
deck = cmd->getDeck(); deck = new DeckList(cmd->getDeck());
} else { } else {
try { try {
deck = getDeckFromDatabase(cmd->getDeckId()); deck = getDeckFromDatabase(cmd->getDeckId());
@ -265,7 +266,7 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Serv
game->sendGameEvent(new Event_DeckSelect(-1, player->getPlayerId(), cmd->getDeckId())); game->sendGameEvent(new Event_DeckSelect(-1, player->getPlayerId(), cmd->getDeckId()));
sendProtocolItem(new Response_DeckDownload(cmd->getCmdId(), RespOk, deck)); sendProtocolItem(new Response_DeckDownload(cmd->getCmdId(), RespOk, new DeckList(deck)));
return RespNothing; return RespNothing;
} }
@ -427,7 +428,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Se
Server_Arrow *arrow = new Server_Arrow(player->newArrowId(), startCard, targetCard, cmd->getColor()); Server_Arrow *arrow = new Server_Arrow(player->newArrowId(), startCard, targetCard, cmd->getColor());
player->addArrow(arrow); player->addArrow(arrow);
game->sendGameEvent(new Event_CreateArrow(-1, player->getPlayerId(), new ServerInfo_Arrow( game->sendGameEvent(new Event_CreateArrows(-1, player->getPlayerId(), QList<ServerInfo_Arrow *>() << new ServerInfo_Arrow(
arrow->getId(), arrow->getId(),
startPlayer->getPlayerId(), startPlayer->getPlayerId(),
startZone->getName(), startZone->getName(),
@ -500,7 +501,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd
{ {
Server_Counter *c = new Server_Counter(player->newCounterId(), cmd->getCounterName(), cmd->getColor(), cmd->getRadius(), cmd->getValue()); Server_Counter *c = new Server_Counter(player->newCounterId(), cmd->getCounterName(), cmd->getColor(), cmd->getRadius(), cmd->getValue());
player->addCounter(c); player->addCounter(c);
game->sendGameEvent(new Event_CreateCounter(-1, player->getPlayerId(), new ServerInfo_Counter(c->getId(), c->getName(), c->getColor(), c->getRadius(), c->getCount()))); game->sendGameEvent(new Event_CreateCounters(-1, player->getPlayerId(), QList<ServerInfo_Counter *>() << new ServerInfo_Counter(c->getId(), c->getName(), c->getColor(), c->getRadius(), c->getCount())));
return RespOk; return RespOk;
} }

View file

@ -14,6 +14,7 @@ QT += network sql
HEADERS += src/servatrice.h \ HEADERS += src/servatrice.h \
src/serversocketinterface.h \ src/serversocketinterface.h \
../common/serializable_item.h \
../common/decklist.h \ ../common/decklist.h \
../common/protocol.h \ ../common/protocol.h \
../common/protocol_items.h \ ../common/protocol_items.h \
@ -33,6 +34,7 @@ HEADERS += src/servatrice.h \
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/servatrice.cpp \ src/servatrice.cpp \
src/serversocketinterface.cpp \ src/serversocketinterface.cpp \
../common/serializable_item.cpp \
../common/decklist.cpp \ ../common/decklist.cpp \
../common/protocol.cpp \ ../common/protocol.cpp \
../common/protocol_items.cpp \ ../common/protocol_items.cpp \

View file

@ -29,7 +29,7 @@
#include "server_player.h" #include "server_player.h"
ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent) ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent)
: Server_ProtocolHandler(_server, parent), servatrice(_server), socket(_socket), currentItem(0) : Server_ProtocolHandler(_server, parent), servatrice(_server), socket(_socket), topLevelItem(0)
{ {
xmlWriter = new QXmlStreamWriter; xmlWriter = new QXmlStreamWriter;
xmlWriter->setDevice(socket); xmlWriter->setDevice(socket);
@ -57,41 +57,31 @@ ServerSocketInterface::~ServerSocketInterface()
delete socket; delete socket;
} }
void ServerSocketInterface::itemFinishedReading() void ServerSocketInterface::processProtocolItem(ProtocolItem *item)
{ {
Command *command = qobject_cast<Command *>(currentItem); Command *command = qobject_cast<Command *>(item);
if (qobject_cast<InvalidCommand *>(command)) if (!command)
sendProtocolItem(new ProtocolResponse(command->getCmdId(), RespInvalidCommand)); sendProtocolItem(new ProtocolResponse(command->getCmdId(), RespInvalidCommand));
else else
processCommand(command); processCommand(command);
currentItem = 0;
} }
void ServerSocketInterface::readClient() void ServerSocketInterface::readClient()
{ {
xmlReader->addData(socket->readAll()); xmlReader->addData(socket->readAll());
if (currentItem) { if (topLevelItem)
if (!currentItem->read(xmlReader)) topLevelItem->read(xmlReader);
return; else
itemFinishedReading(); while (!xmlReader->atEnd()) {
} xmlReader->readNext();
while (!xmlReader->atEnd()) { if (xmlReader->isStartElement() && (xmlReader->name().toString() == "cockatrice_client_stream")) {
xmlReader->readNext(); topLevelItem = new TopLevelProtocolItem;
if (xmlReader->isStartElement()) { connect(topLevelItem, SIGNAL(protocolItemReceived(ProtocolItem *)), this, SLOT(processProtocolItem(ProtocolItem *)));
QString itemType = xmlReader->name().toString();
if (itemType == "cockatrice_client_stream") topLevelItem->read(xmlReader);
continue; }
QString itemName = xmlReader->attributes().value("name").toString();
qDebug() << "parseXml: startElement: " << "type =" << itemType << ", name =" << itemName;
currentItem = ProtocolItem::getNewItem(itemType + itemName);
if (!currentItem)
currentItem = new InvalidCommand;
if (!currentItem->read(xmlReader))
return;
itemFinishedReading();
} }
}
} }
void ServerSocketInterface::catchSocketError(QAbstractSocket::SocketError socketError) void ServerSocketInterface::catchSocketError(QAbstractSocket::SocketError socketError)
@ -147,7 +137,7 @@ bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder)
while (query.next()) { while (query.next()) {
DeckList_Directory *newFolder = new DeckList_Directory(query.value(1).toString(), query.value(0).toInt()); DeckList_Directory *newFolder = new DeckList_Directory(query.value(1).toString(), query.value(0).toInt());
folder->append(newFolder); folder->appendItem(newFolder);
if (!deckListHelper(newFolder)) if (!deckListHelper(newFolder))
return false; return false;
} }
@ -160,7 +150,7 @@ bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder)
while (query.next()) { while (query.next()) {
DeckList_File *newFile = new DeckList_File(query.value(1).toString(), query.value(0).toInt(), query.value(2).toDateTime()); DeckList_File *newFile = new DeckList_File(query.value(1).toString(), query.value(0).toInt(), query.value(2).toDateTime());
folder->append(newFile); folder->appendItem(newFile);
} }
return true; return true;
@ -266,7 +256,7 @@ ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd)
QString deckContents; QString deckContents;
QXmlStreamWriter deckWriter(&deckContents); QXmlStreamWriter deckWriter(&deckContents);
deckWriter.writeStartDocument(); deckWriter.writeStartDocument();
cmd->getDeck()->writeElement(&deckWriter); cmd->getDeck()->write(&deckWriter);
deckWriter.writeEndDocument(); deckWriter.writeEndDocument();
QString deckName = cmd->getDeck()->getName(); QString deckName = cmd->getDeck()->getName();
@ -281,8 +271,6 @@ ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd)
query.bindValue(":content", deckContents); query.bindValue(":content", deckContents);
servatrice->execSqlQuery(query); servatrice->execSqlQuery(query);
delete cmd->getDeck();
sendProtocolItem(new Response_DeckUpload(cmd->getCmdId(), RespOk, new DeckList_File(deckName, query.lastInsertId().toInt(), QDateTime::currentDateTime()))); sendProtocolItem(new Response_DeckUpload(cmd->getCmdId(), RespOk, new DeckList_File(deckName, query.lastInsertId().toInt(), QDateTime::currentDateTime())));
return RespNothing; return RespNothing;
} }
@ -302,8 +290,7 @@ DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId)
QXmlStreamReader deckReader(query.value(0).toString()); QXmlStreamReader deckReader(query.value(0).toString());
DeckList *deck = new DeckList; DeckList *deck = new DeckList;
if (!deck->loadFromXml(&deckReader)) deck->loadFromXml(&deckReader);
throw RespInvalidData;
return deck; return deck;
} }
@ -317,6 +304,5 @@ ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd)
return r; return r;
} }
sendProtocolItem(new Response_DeckDownload(cmd->getCmdId(), RespOk, deck)); sendProtocolItem(new Response_DeckDownload(cmd->getCmdId(), RespOk, deck));
delete deck;
return RespNothing; return RespNothing;
} }

View file

@ -28,6 +28,7 @@ class Servatrice;
class QXmlStreamReader; class QXmlStreamReader;
class QXmlStreamWriter; class QXmlStreamWriter;
class DeckList; class DeckList;
class TopLevelProtocolItem;
class ServerSocketInterface : public Server_ProtocolHandler class ServerSocketInterface : public Server_ProtocolHandler
{ {
@ -35,12 +36,13 @@ class ServerSocketInterface : public Server_ProtocolHandler
private slots: private slots:
void readClient(); void readClient();
void catchSocketError(QAbstractSocket::SocketError socketError); void catchSocketError(QAbstractSocket::SocketError socketError);
void processProtocolItem(ProtocolItem *item);
private: private:
Servatrice *servatrice; Servatrice *servatrice;
QTcpSocket *socket; QTcpSocket *socket;
QXmlStreamWriter *xmlWriter; QXmlStreamWriter *xmlWriter;
QXmlStreamReader *xmlReader; QXmlStreamReader *xmlReader;
ProtocolItem *currentItem; TopLevelProtocolItem *topLevelItem;
int getDeckPathId(int basePathId, QStringList path); int getDeckPathId(int basePathId, QStringList path);
int getDeckPathId(const QString &path); int getDeckPathId(const QString &path);
@ -53,8 +55,6 @@ private:
ResponseCode cmdDeckUpload(Command_DeckUpload *cmd); ResponseCode cmdDeckUpload(Command_DeckUpload *cmd);
DeckList *getDeckFromDatabase(int deckId); DeckList *getDeckFromDatabase(int deckId);
ResponseCode cmdDeckDownload(Command_DeckDownload *cmd); ResponseCode cmdDeckDownload(Command_DeckDownload *cmd);
void itemFinishedReading();
public: public:
ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent = 0); ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent = 0);
~ServerSocketInterface(); ~ServerSocketInterface();