new protocol code
This commit is contained in:
parent
ba8d40211c
commit
888a64b0fd
25 changed files with 487 additions and 333 deletions
|
@ -56,8 +56,8 @@ void SetList::sortByKey()
|
|||
qSort(begin(), end(), CompareFunctor());
|
||||
}
|
||||
|
||||
CardInfo::CardInfo(CardDatabase *_db, const QString &_name, const QString &_manacost, const QString &_cardtype, const QString &_powtough, const QString &_text, const QStringList &_colors, int _tableRow, const SetList &_sets, const QString &_picURL)
|
||||
: db(_db), name(_name), sets(_sets), manacost(_manacost), cardtype(_cardtype), powtough(_powtough), text(_text), colors(_colors), picURL(_picURL), tableRow(_tableRow), pixmap(NULL)
|
||||
CardInfo::CardInfo(CardDatabase *_db, const QString &_name, const QString &_manacost, const QString &_cardtype, const QString &_powtough, const QString &_text, const QStringList &_colors, bool _cipt, int _tableRow, const SetList &_sets, const QString &_picURL)
|
||||
: db(_db), name(_name), sets(_sets), manacost(_manacost), cardtype(_cardtype), powtough(_powtough), text(_text), colors(_colors), picURL(_picURL), cipt(_cipt), tableRow(_tableRow), pixmap(NULL)
|
||||
{
|
||||
for (int i = 0; i < sets.size(); i++)
|
||||
sets[i]->append(this);
|
||||
|
@ -220,6 +220,8 @@ QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
|
|||
xml.writeTextElement("tablerow", QString::number(info->getTableRow()));
|
||||
xml.writeTextElement("text", info->getText());
|
||||
xml.writeTextElement("picURL", info->getPicURL());
|
||||
if (info->getCipt())
|
||||
xml.writeTextElement("cipt", "1");
|
||||
xml.writeEndElement(); // card
|
||||
|
||||
return xml;
|
||||
|
@ -383,6 +385,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
QStringList colors;
|
||||
SetList sets;
|
||||
int tableRow = 0;
|
||||
bool cipt = false;
|
||||
while (!xml.atEnd()) {
|
||||
if (xml.readNext() == QXmlStreamReader::EndElement)
|
||||
break;
|
||||
|
@ -404,8 +407,10 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
tableRow = xml.readElementText().toInt();
|
||||
else if (xml.name() == "picURL")
|
||||
picURL = xml.readElementText();
|
||||
else if (xml.name() == "cipt")
|
||||
cipt = (xml.readElementText() == "1");
|
||||
}
|
||||
cardHash.insert(name, new CardInfo(this, name, manacost, type, pt, text, colors, tableRow, sets, picURL));
|
||||
cardHash.insert(name, new CardInfo(this, name, manacost, type, pt, text, colors, cipt, tableRow, sets, picURL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ private:
|
|||
QString text;
|
||||
QStringList colors;
|
||||
QString picURL;
|
||||
bool cipt;
|
||||
int tableRow;
|
||||
QPixmap *pixmap;
|
||||
QMap<int, QPixmap *> scaledPixmapCache;
|
||||
|
@ -57,6 +58,7 @@ public:
|
|||
const QString &_powtough = QString(),
|
||||
const QString &_text = QString(),
|
||||
const QStringList &_colors = QStringList(),
|
||||
bool cipt = false,
|
||||
int _tableRow = 0,
|
||||
const SetList &_sets = SetList(),
|
||||
const QString &_picURL = QString());
|
||||
|
@ -67,6 +69,7 @@ public:
|
|||
const QString &getCardType() const { return cardtype; }
|
||||
const QString &getPowTough() const { return powtough; }
|
||||
const QString &getText() const { return text; }
|
||||
bool getCipt() const { return cipt; }
|
||||
void setText(const QString &_text) { text = _text; }
|
||||
const QStringList &getColors() const { return colors; }
|
||||
const QString &getPicURL() const { return picURL; }
|
||||
|
|
|
@ -142,12 +142,6 @@ CardItem *CardZone::takeCard(int position, int cardId, const QString &cardName,
|
|||
return c;
|
||||
}
|
||||
|
||||
void CardZone::setCardAttr(int cardId, const QString &aname, const QString &avalue)
|
||||
{
|
||||
if (hasCardAttr)
|
||||
player->sendGameCommand(new Command_SetCardAttr(-1, name, cardId, aname, avalue));
|
||||
}
|
||||
|
||||
void CardZone::moveAllToZone()
|
||||
{
|
||||
QList<QVariant> data = static_cast<QAction *>(sender())->data().toList();
|
||||
|
|
|
@ -52,7 +52,6 @@ public:
|
|||
CardItem *getCard(int cardId, const QString &cardName);
|
||||
// takeCard() finds a card by position and removes it from the zone and from all of its views.
|
||||
virtual CardItem *takeCard(int position, int cardId, const QString &cardName, bool canResize = true);
|
||||
void setCardAttr(int cardId, const QString &aname, const QString &avalue);
|
||||
ZoneViewZone *getView() const { return view; }
|
||||
void setView(ZoneViewZone *_view) { view = _view; }
|
||||
virtual void reorganizeCards() = 0;
|
||||
|
|
|
@ -90,14 +90,14 @@ void Client::processProtocolItem(ProtocolItem *item)
|
|||
{
|
||||
ProtocolResponse *response = qobject_cast<ProtocolResponse *>(item);
|
||||
if (response) {
|
||||
Command *cmd = pendingCommands.value(response->getCmdId(), 0);
|
||||
if (!cmd)
|
||||
CommandContainer *cmdCont = pendingCommands.value(response->getCmdId(), 0);
|
||||
if (!cmdCont)
|
||||
return;
|
||||
|
||||
pendingCommands.remove(cmd->getCmdId());
|
||||
cmd->processResponse(response);
|
||||
pendingCommands.remove(cmdCont->getCmdId());
|
||||
cmdCont->processResponse(response);
|
||||
delete response;
|
||||
delete cmd;
|
||||
delete cmdCont;
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -114,10 +114,10 @@ void Client::processProtocolItem(ProtocolItem *item)
|
|||
return;
|
||||
}
|
||||
|
||||
GameEvent *gameEvent = qobject_cast<GameEvent *>(item);
|
||||
if (gameEvent) {
|
||||
emit gameEventReceived(gameEvent);
|
||||
delete gameEvent;
|
||||
GameEventContainer *gameEventContainer = qobject_cast<GameEventContainer *>(item);
|
||||
if (gameEventContainer) {
|
||||
emit gameEventContainerReceived(gameEventContainer);
|
||||
delete gameEventContainer;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -139,8 +139,13 @@ void Client::setStatus(const ClientStatus _status)
|
|||
|
||||
void Client::sendCommand(Command *cmd)
|
||||
{
|
||||
cmd->write(xmlWriter);
|
||||
pendingCommands.insert(cmd->getCmdId(), cmd);
|
||||
sendCommandContainer(new CommandContainer(QList<Command *>() << cmd));
|
||||
}
|
||||
|
||||
void Client::sendCommandContainer(CommandContainer *cont)
|
||||
{
|
||||
cont->write(xmlWriter);
|
||||
pendingCommands.insert(cont->getCmdId(), cont);
|
||||
}
|
||||
|
||||
void Client::connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
|
||||
|
@ -162,7 +167,7 @@ void Client::disconnectFromServer()
|
|||
|
||||
timer->stop();
|
||||
|
||||
QList<Command *> pc = pendingCommands.values();
|
||||
QList<CommandContainer *> pc = pendingCommands.values();
|
||||
for (int i = 0; i < pc.size(); i++)
|
||||
delete pc[i];
|
||||
pendingCommands.clear();
|
||||
|
@ -174,7 +179,7 @@ void Client::disconnectFromServer()
|
|||
void Client::ping()
|
||||
{
|
||||
int maxTime = 0;
|
||||
QMapIterator<int, Command *> i(pendingCommands);
|
||||
QMapIterator<int, CommandContainer *> i(pendingCommands);
|
||||
while (i.hasNext()) {
|
||||
int time = i.next().value()->tick();
|
||||
if (time > maxTime)
|
||||
|
|
|
@ -9,14 +9,16 @@
|
|||
|
||||
class QTimer;
|
||||
class Command;
|
||||
class CommandContainer;
|
||||
class QXmlStreamReader;
|
||||
class QXmlStreamWriter;
|
||||
|
||||
class ProtocolItem;
|
||||
class ProtocolResponse;
|
||||
class TopLevelProtocolItem;
|
||||
class CommandContainer;
|
||||
class ChatEvent;
|
||||
class GameEvent;
|
||||
class GameEventContainer;
|
||||
class Event_ListGames;
|
||||
class Event_ServerMessage;
|
||||
class Event_ListChatChannels;
|
||||
|
@ -45,7 +47,7 @@ signals:
|
|||
// Chat events
|
||||
void chatEventReceived(ChatEvent *event);
|
||||
// Game events
|
||||
void gameEventReceived(GameEvent *event);
|
||||
void gameEventContainerReceived(GameEventContainer *event);
|
||||
// Generic events
|
||||
void listGamesEventReceived(Event_ListGames *event);
|
||||
void serverMessageEventReceived(Event_ServerMessage *event);
|
||||
|
@ -63,7 +65,7 @@ private:
|
|||
static const int maxTimeout = 10;
|
||||
|
||||
QTimer *timer;
|
||||
QMap<int, Command *> pendingCommands;
|
||||
QMap<int, CommandContainer *> pendingCommands;
|
||||
QTcpSocket *socket;
|
||||
QXmlStreamReader *xmlReader;
|
||||
QXmlStreamWriter *xmlWriter;
|
||||
|
@ -80,6 +82,7 @@ public:
|
|||
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
||||
void disconnectFromServer();
|
||||
void sendCommand(Command *cmd);
|
||||
void sendCommandContainer(CommandContainer *cont);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -908,6 +908,11 @@ void Player::sendGameCommand(GameCommand *command)
|
|||
static_cast<TabGame *>(parent())->sendGameCommand(command);
|
||||
}
|
||||
|
||||
void Player::sendCommandContainer(CommandContainer *cont)
|
||||
{
|
||||
static_cast<TabGame *>(parent())->sendCommandContainer(cont);
|
||||
}
|
||||
|
||||
void Player::cardMenuAction()
|
||||
{
|
||||
// Determine the appropriate handler function.
|
||||
|
|
|
@ -20,6 +20,7 @@ class HandZone;
|
|||
class ServerInfo_Player;
|
||||
class ServerInfo_Arrow;
|
||||
class ServerInfo_Counter;
|
||||
class CommandContainer;
|
||||
class GameCommand;
|
||||
class GameEvent;
|
||||
class Event_DeckSelect;
|
||||
|
@ -190,6 +191,7 @@ public:
|
|||
void processPlayerInfo(ServerInfo_Player *info);
|
||||
void processGameEvent(GameEvent *event);
|
||||
void sendGameCommand(GameCommand *command);
|
||||
void sendCommandContainer(CommandContainer *cont);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -226,25 +226,30 @@ Player *TabGame::addPlayer(int playerId, const QString &playerName)
|
|||
return newPlayer;
|
||||
}
|
||||
|
||||
void TabGame::processGameEvent(GameEvent *event)
|
||||
void TabGame::processGameEventContainer(GameEventContainer *cont)
|
||||
{
|
||||
switch (event->getItemId()) {
|
||||
case ItemId_Event_GameStateChanged: eventGameStateChanged(qobject_cast<Event_GameStateChanged *>(event)); break;
|
||||
case ItemId_Event_Join: eventJoin(qobject_cast<Event_Join *>(event)); break;
|
||||
case ItemId_Event_Leave: eventLeave(qobject_cast<Event_Leave *>(event)); break;
|
||||
case ItemId_Event_GameClosed: eventGameClosed(qobject_cast<Event_GameClosed *>(event)); break;
|
||||
case ItemId_Event_SetActivePlayer: eventSetActivePlayer(qobject_cast<Event_SetActivePlayer *>(event)); break;
|
||||
case ItemId_Event_SetActivePhase: eventSetActivePhase(qobject_cast<Event_SetActivePhase *>(event)); break;
|
||||
case ItemId_Event_Ping: eventPing(qobject_cast<Event_Ping *>(event)); break;
|
||||
|
||||
default: {
|
||||
Player *player = players.value(event->getPlayerId(), 0);
|
||||
if (!player) {
|
||||
qDebug() << "unhandled game event: invalid player id";
|
||||
break;
|
||||
const QList<GameEvent *> &eventList = cont->getEventList();
|
||||
for (int i = 0; i < eventList.size(); ++i) {
|
||||
GameEvent *event = eventList[i];
|
||||
|
||||
switch (event->getItemId()) {
|
||||
case ItemId_Event_GameStateChanged: eventGameStateChanged(qobject_cast<Event_GameStateChanged *>(event)); break;
|
||||
case ItemId_Event_Join: eventJoin(qobject_cast<Event_Join *>(event)); break;
|
||||
case ItemId_Event_Leave: eventLeave(qobject_cast<Event_Leave *>(event)); break;
|
||||
case ItemId_Event_GameClosed: eventGameClosed(qobject_cast<Event_GameClosed *>(event)); break;
|
||||
case ItemId_Event_SetActivePlayer: eventSetActivePlayer(qobject_cast<Event_SetActivePlayer *>(event)); break;
|
||||
case ItemId_Event_SetActivePhase: eventSetActivePhase(qobject_cast<Event_SetActivePhase *>(event)); break;
|
||||
case ItemId_Event_Ping: eventPing(qobject_cast<Event_Ping *>(event)); break;
|
||||
|
||||
default: {
|
||||
Player *player = players.value(event->getPlayerId(), 0);
|
||||
if (!player) {
|
||||
qDebug() << "unhandled game event: invalid player id";
|
||||
break;
|
||||
}
|
||||
player->processGameEvent(event);
|
||||
emit userEvent();
|
||||
}
|
||||
player->processGameEvent(event);
|
||||
emit userEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -255,6 +260,17 @@ void TabGame::sendGameCommand(GameCommand *command)
|
|||
client->sendCommand(command);
|
||||
}
|
||||
|
||||
void TabGame::sendCommandContainer(CommandContainer *cont)
|
||||
{
|
||||
const QList<Command *> &cmdList = cont->getCommandList();
|
||||
for (int i = 0; i < cmdList.size(); ++i) {
|
||||
GameCommand *cmd = qobject_cast<GameCommand *>(cmdList[i]);
|
||||
if (cmd)
|
||||
cmd->setGameId(gameId);
|
||||
}
|
||||
client->sendCommandContainer(cont);
|
||||
}
|
||||
|
||||
void TabGame::startGame()
|
||||
{
|
||||
currentPhase = -1;
|
||||
|
|
|
@ -20,8 +20,9 @@ class ZoneViewWidget;
|
|||
class PhasesToolbar;
|
||||
class PlayerListWidget;
|
||||
class ProtocolResponse;
|
||||
class GameEvent;
|
||||
class GameEventContainer;
|
||||
class GameCommand;
|
||||
class CommandContainer;
|
||||
class Event_GameStateChanged;
|
||||
class Event_Join;
|
||||
class Event_Leave;
|
||||
|
@ -103,9 +104,10 @@ public:
|
|||
int getGameId() const { return gameId; }
|
||||
QString getTabText() const { return tr("Game %1: %2").arg(gameId).arg(gameDescription); }
|
||||
|
||||
void processGameEvent(GameEvent *event);
|
||||
void processGameEventContainer(GameEventContainer *cont);
|
||||
public slots:
|
||||
void sendGameCommand(GameCommand *command);
|
||||
void sendCommandContainer(CommandContainer *cont);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -52,7 +52,7 @@ void TabSupervisor::start(Client *_client)
|
|||
{
|
||||
client = _client;
|
||||
connect(client, SIGNAL(chatEventReceived(ChatEvent *)), this, SLOT(processChatEvent(ChatEvent *)));
|
||||
connect(client, SIGNAL(gameEventReceived(GameEvent *)), this, SLOT(processGameEvent(GameEvent *)));
|
||||
connect(client, SIGNAL(gameEventContainerReceived(GameEventContainer *)), this, SLOT(processGameEventContainer(GameEventContainer *)));
|
||||
connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *)));
|
||||
connect(client, SIGNAL(maxPingTime(int, int)), this, SLOT(updatePingTime(int, int)));
|
||||
|
||||
|
@ -152,12 +152,12 @@ void TabSupervisor::processChatEvent(ChatEvent *event)
|
|||
tab->processChatEvent(event);
|
||||
}
|
||||
|
||||
void TabSupervisor::processGameEvent(GameEvent *event)
|
||||
void TabSupervisor::processGameEventContainer(GameEventContainer *cont)
|
||||
{
|
||||
TabGame *tab = gameTabs.value(event->getGameId());
|
||||
TabGame *tab = gameTabs.value(cont->getGameId());
|
||||
if (tab) {
|
||||
qDebug() << "gameEvent gameId =" << event->getGameId();
|
||||
tab->processGameEvent(event);
|
||||
qDebug() << "gameEvent gameId =" << cont->getGameId();
|
||||
tab->processGameEventContainer(cont);
|
||||
} else
|
||||
qDebug() << "gameEvent: invalid gameId";
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class TabChatChannel;
|
|||
class TabGame;
|
||||
class TabDeckStorage;
|
||||
class ChatEvent;
|
||||
class GameEvent;
|
||||
class GameEventContainer;
|
||||
class Event_GameJoined;
|
||||
|
||||
class TabSupervisor : public QTabWidget {
|
||||
|
@ -42,7 +42,7 @@ private slots:
|
|||
void chatChannelLeft(TabChatChannel *tab);
|
||||
void tabUserEvent();
|
||||
void processChatEvent(ChatEvent *event);
|
||||
void processGameEvent(GameEvent *event);
|
||||
void processGameEventContainer(GameEventContainer *cont);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -85,11 +85,13 @@ void TableZone::toggleTapped()
|
|||
tapAll = true;
|
||||
break;
|
||||
}
|
||||
QList<Command *> cmdList;
|
||||
for (int i = 0; i < selectedItems.size(); i++) {
|
||||
CardItem *temp = qgraphicsitem_cast<CardItem *>(selectedItems[i]);
|
||||
if (temp->getTapped() != tapAll)
|
||||
setCardAttr(temp->getId(), "tapped", tapAll ? "1" : "0");
|
||||
cmdList.append(new Command_SetCardAttr(-1, name, temp->getId(), "tapped", tapAll ? "1" : "0"));
|
||||
}
|
||||
player->sendCommandContainer(new CommandContainer(cmdList));
|
||||
}
|
||||
|
||||
CardItem *TableZone::takeCard(int position, int cardId, const QString &cardName, bool canResize)
|
||||
|
|
|
@ -26,6 +26,9 @@ void ProtocolItem::initializeHash()
|
|||
registerSerializableItem("file", DeckList_File::newItem);
|
||||
registerSerializableItem("directory", DeckList_Directory::newItem);
|
||||
|
||||
registerSerializableItem("containercmd", CommandContainer::newItem);
|
||||
registerSerializableItem("containergame_event", GameEventContainer::newItem);
|
||||
|
||||
registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem);
|
||||
registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem);
|
||||
|
||||
|
@ -83,14 +86,11 @@ void TopLevelProtocolItem::writeElement(QXmlStreamWriter * /*xml*/)
|
|||
{
|
||||
}
|
||||
|
||||
int Command::lastCmdId = 0;
|
||||
int CommandContainer::lastCmdId = 0;
|
||||
|
||||
Command::Command(const QString &_itemName, int _cmdId)
|
||||
: ProtocolItem("cmd", _itemName), ticks(0)
|
||||
Command::Command(const QString &_itemName)
|
||||
: ProtocolItem("cmd", _itemName)
|
||||
{
|
||||
if (_cmdId == -1)
|
||||
_cmdId = lastCmdId++;
|
||||
insertItem(new SerializableItem_Int("cmd_id", _cmdId));
|
||||
}
|
||||
|
||||
void Command::processResponse(ProtocolResponse *response)
|
||||
|
@ -99,6 +99,40 @@ void Command::processResponse(ProtocolResponse *response)
|
|||
emit finished(response->getResponseCode());
|
||||
}
|
||||
|
||||
CommandContainer::CommandContainer(const QList<Command *> &_commandList, int _cmdId)
|
||||
: ProtocolItem("container", "cmd"), ticks(0), resp(0), gameEventQueue(0)
|
||||
{
|
||||
if (_cmdId == -1)
|
||||
_cmdId = lastCmdId++;
|
||||
insertItem(new SerializableItem_Int("cmd_id", _cmdId));
|
||||
|
||||
for (int i = 0; i < _commandList.size(); ++i)
|
||||
itemList.append(_commandList[i]);
|
||||
}
|
||||
|
||||
void CommandContainer::processResponse(ProtocolResponse *response)
|
||||
{
|
||||
emit finished(response);
|
||||
emit finished(response->getResponseCode());
|
||||
|
||||
const QList<Command *> &cmdList = getCommandList();
|
||||
for (int i = 0; i < cmdList.size(); ++i)
|
||||
cmdList[i]->processResponse(response);
|
||||
}
|
||||
|
||||
void CommandContainer::setResponse(ProtocolResponse *_resp)
|
||||
{
|
||||
delete resp;
|
||||
resp = _resp;
|
||||
}
|
||||
|
||||
void CommandContainer::enqueueGameEvent(GameEvent *event, int gameId)
|
||||
{
|
||||
if (!gameEventQueue)
|
||||
gameEventQueue = new GameEventContainer(QList<GameEvent *>(), gameId);
|
||||
gameEventQueue->appendItem(event);
|
||||
}
|
||||
|
||||
Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path)
|
||||
: Command("deck_upload")
|
||||
{
|
||||
|
@ -187,10 +221,9 @@ Response_DumpZone::Response_DumpZone(int _cmdId, ResponseCode _responseCode, Ser
|
|||
insertItem(_zone);
|
||||
}
|
||||
|
||||
GameEvent::GameEvent(const QString &_eventName, int _gameId, int _playerId)
|
||||
GameEvent::GameEvent(const QString &_eventName, int _playerId)
|
||||
: ProtocolItem("game_event", _eventName)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("game_id", _gameId));
|
||||
insertItem(new SerializableItem_Int("player_id", _playerId));
|
||||
}
|
||||
|
||||
|
@ -221,16 +254,30 @@ Event_ListGames::Event_ListGames(const QList<ServerInfo_Game *> &_gameList)
|
|||
itemList.append(_gameList[i]);
|
||||
}
|
||||
|
||||
Event_Join::Event_Join(int _gameId, ServerInfo_Player *player)
|
||||
: GameEvent("join", _gameId, -1)
|
||||
Event_Join::Event_Join(ServerInfo_Player *player)
|
||||
: GameEvent("join", -1)
|
||||
{
|
||||
if (!player)
|
||||
player = new ServerInfo_Player;
|
||||
insertItem(player);
|
||||
}
|
||||
|
||||
Event_GameStateChanged::Event_GameStateChanged(int _gameId, bool _gameStarted, int _activePlayer, int _activePhase, const QList<ServerInfo_Player *> &_playerList)
|
||||
: GameEvent("game_state_changed", _gameId, -1)
|
||||
GameEventContainer::GameEventContainer(const QList<GameEvent *> &_eventList, int _gameId)
|
||||
: ProtocolItem("container", "game_event")
|
||||
{
|
||||
insertItem(new SerializableItem_Int("game_id", _gameId));
|
||||
|
||||
for (int i = 0; i < _eventList.size(); ++i)
|
||||
itemList.append(_eventList[i]);
|
||||
}
|
||||
|
||||
GameEventContainer *GameEventContainer::makeNew(GameEvent *event, int _gameId)
|
||||
{
|
||||
return new GameEventContainer(QList<GameEvent *>() << event, _gameId);
|
||||
}
|
||||
|
||||
Event_GameStateChanged::Event_GameStateChanged(bool _gameStarted, int _activePlayer, int _activePhase, const QList<ServerInfo_Player *> &_playerList)
|
||||
: GameEvent("game_state_changed", -1)
|
||||
{
|
||||
insertItem(new SerializableItem_Bool("game_started", _gameStarted));
|
||||
insertItem(new SerializableItem_Int("active_player", _activePlayer));
|
||||
|
@ -239,29 +286,29 @@ Event_GameStateChanged::Event_GameStateChanged(int _gameId, bool _gameStarted, i
|
|||
itemList.append(_playerList[i]);
|
||||
}
|
||||
|
||||
Event_Ping::Event_Ping(int _gameId, const QList<ServerInfo_PlayerPing *> &_pingList)
|
||||
: GameEvent("ping", _gameId, -1)
|
||||
Event_Ping::Event_Ping(const QList<ServerInfo_PlayerPing *> &_pingList)
|
||||
: GameEvent("ping", -1)
|
||||
{
|
||||
for (int i = 0; i < _pingList.size(); ++i)
|
||||
itemList.append(_pingList[i]);
|
||||
}
|
||||
|
||||
Event_CreateArrows::Event_CreateArrows(int _gameId, int _playerId, const QList<ServerInfo_Arrow *> &_arrowList)
|
||||
: GameEvent("create_arrows", _gameId, _playerId)
|
||||
Event_CreateArrows::Event_CreateArrows(int _playerId, const QList<ServerInfo_Arrow *> &_arrowList)
|
||||
: GameEvent("create_arrows", _playerId)
|
||||
{
|
||||
for (int i = 0; i < _arrowList.size(); ++i)
|
||||
itemList.append(_arrowList[i]);
|
||||
}
|
||||
|
||||
Event_CreateCounters::Event_CreateCounters(int _gameId, int _playerId, const QList<ServerInfo_Counter *> &_counterList)
|
||||
: GameEvent("create_counters", _gameId, _playerId)
|
||||
Event_CreateCounters::Event_CreateCounters(int _playerId, const QList<ServerInfo_Counter *> &_counterList)
|
||||
: GameEvent("create_counters", _playerId)
|
||||
{
|
||||
for (int i = 0; i < _counterList.size(); ++i)
|
||||
itemList.append(_counterList[i]);
|
||||
}
|
||||
|
||||
Event_DrawCards::Event_DrawCards(int _gameId, int _playerId, int _numberCards, const QList<ServerInfo_Card *> &_cardList)
|
||||
: GameEvent("draw_cards", _gameId, _playerId)
|
||||
Event_DrawCards::Event_DrawCards(int _playerId, int _numberCards, const QList<ServerInfo_Card *> &_cardList)
|
||||
: GameEvent("draw_cards", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("number_cards", _numberCards));
|
||||
for (int i = 0; i < _cardList.size(); ++i)
|
||||
|
|
|
@ -15,8 +15,12 @@ class QXmlStreamAttributes;
|
|||
|
||||
class ProtocolResponse;
|
||||
class DeckList;
|
||||
class GameEvent;
|
||||
class GameEventContainer;
|
||||
|
||||
enum ItemId {
|
||||
ItemId_CommandContainer = ItemId_Other + 50,
|
||||
ItemId_GameEventContainer = ItemId_Other + 51,
|
||||
ItemId_Command_DeckUpload = ItemId_Other + 100,
|
||||
ItemId_Command_DeckSelect = ItemId_Other + 101,
|
||||
ItemId_Event_ListChatChannels = ItemId_Other + 200,
|
||||
|
@ -40,7 +44,7 @@ class ProtocolItem : public SerializableItem_Map {
|
|||
private:
|
||||
static void initializeHashAuto();
|
||||
public:
|
||||
static const int protocolVersion = 5;
|
||||
static const int protocolVersion = 6;
|
||||
static void initializeHash();
|
||||
virtual int getItemId() const = 0;
|
||||
ProtocolItem(const QString &_itemType, const QString &_itemSubType);
|
||||
|
@ -75,16 +79,42 @@ signals:
|
|||
void finished(ProtocolResponse *response);
|
||||
void finished(ResponseCode response);
|
||||
private:
|
||||
int ticks;
|
||||
static int lastCmdId;
|
||||
QVariant extraData;
|
||||
public:
|
||||
Command(const QString &_itemName = QString(), int _cmdId = -1);
|
||||
Command(const QString &_itemName = QString());
|
||||
void setExtraData(const QVariant &_extraData) { extraData = _extraData; }
|
||||
QVariant getExtraData() const { return extraData; }
|
||||
void processResponse(ProtocolResponse *response);
|
||||
};
|
||||
|
||||
class CommandContainer : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void finished(ProtocolResponse *response);
|
||||
void finished(ResponseCode response);
|
||||
private:
|
||||
int ticks;
|
||||
static int lastCmdId;
|
||||
|
||||
// These are only for processing inside the server.
|
||||
ProtocolResponse *resp;
|
||||
QList<ProtocolItem *> itemQueue;
|
||||
GameEventContainer *gameEventQueue;
|
||||
public:
|
||||
CommandContainer(const QList<Command *> &_commandList = QList<Command *>(), int _cmdId = -1);
|
||||
static SerializableItem *newItem() { return new CommandContainer; }
|
||||
int getItemId() const { return ItemId_CommandContainer; }
|
||||
int getCmdId() const { return static_cast<SerializableItem_Int *>(itemMap.value("cmd_id"))->getData(); }
|
||||
int tick() { return ++ticks; }
|
||||
void processResponse(ProtocolResponse *response);
|
||||
void setExtraData(const QVariant &_extraData) { extraData = _extraData; }
|
||||
QVariant getExtraData() const { return extraData; }
|
||||
QList<Command *> getCommandList() const { return typecastItemList<Command *>(); }
|
||||
|
||||
ProtocolResponse *getResponse() const { return resp; }
|
||||
void setResponse(ProtocolResponse *_resp);
|
||||
const QList<ProtocolItem *> &getItemQueue() const { return itemQueue; }
|
||||
void enqueueItem(ProtocolItem *item) { itemQueue.append(item); }
|
||||
GameEventContainer *getGameEventQueue() const { return gameEventQueue; }
|
||||
void enqueueGameEvent(GameEvent *event, int gameId);
|
||||
};
|
||||
|
||||
class ChatCommand : public Command {
|
||||
|
@ -197,9 +227,20 @@ public:
|
|||
class GameEvent : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GameEvent(const QString &_eventName, int _gameId, int _playerId);
|
||||
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
|
||||
GameEvent(const QString &_eventName, int _playerId);
|
||||
int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); }
|
||||
};
|
||||
|
||||
class GameEventContainer : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GameEventContainer(const QList<GameEvent *> &_eventList = QList<GameEvent *>(), int _gameId = -1);
|
||||
static SerializableItem *newItem() { return new GameEventContainer; }
|
||||
int getItemId() const { return ItemId_GameEventContainer; }
|
||||
QList<GameEvent *> getEventList() const { return typecastItemList<GameEvent *>(); }
|
||||
static GameEventContainer *makeNew(GameEvent *event, int _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); }
|
||||
};
|
||||
|
||||
|
@ -240,7 +281,7 @@ public:
|
|||
class Event_Join : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_Join(int _gameId = -1, ServerInfo_Player * player = 0);
|
||||
Event_Join(ServerInfo_Player * player = 0);
|
||||
static SerializableItem *newItem() { return new Event_Join; }
|
||||
int getItemId() const { return ItemId_Event_Join; }
|
||||
ServerInfo_Player *getPlayer() const { return static_cast<ServerInfo_Player *>(itemMap.value("player")); }
|
||||
|
@ -249,7 +290,7 @@ public:
|
|||
class Event_GameStateChanged : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_GameStateChanged(int _gameId = -1, bool _gameStarted = false, int _activePlayer = -1, int _activePhase = -1, const QList<ServerInfo_Player *> &_playerList = QList<ServerInfo_Player *>());
|
||||
Event_GameStateChanged(bool _gameStarted = false, int _activePlayer = -1, int _activePhase = -1, const QList<ServerInfo_Player *> &_playerList = QList<ServerInfo_Player *>());
|
||||
static SerializableItem *newItem() { return new Event_GameStateChanged; }
|
||||
int getItemId() const { return ItemId_Event_GameStateChanged; }
|
||||
QList<ServerInfo_Player *> getPlayerList() const { return typecastItemList<ServerInfo_Player *>(); }
|
||||
|
@ -261,7 +302,7 @@ public:
|
|||
class Event_Ping : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_Ping(int _gameId = -1, const QList<ServerInfo_PlayerPing *> &_pingList = QList<ServerInfo_PlayerPing *>());
|
||||
Event_Ping(const QList<ServerInfo_PlayerPing *> &_pingList = QList<ServerInfo_PlayerPing *>());
|
||||
static SerializableItem *newItem() { return new Event_Ping; }
|
||||
int getItemId() const { return ItemId_Event_Ping; }
|
||||
QList<ServerInfo_PlayerPing *> getPingList() const { return typecastItemList<ServerInfo_PlayerPing *>(); }
|
||||
|
@ -270,7 +311,7 @@ public:
|
|||
class Event_CreateArrows : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_CreateArrows(int _gameId = -1, int _playerId = -1, const QList<ServerInfo_Arrow *> &_arrowList = QList<ServerInfo_Arrow *>());
|
||||
Event_CreateArrows(int _playerId = -1, const QList<ServerInfo_Arrow *> &_arrowList = QList<ServerInfo_Arrow *>());
|
||||
int getItemId() const { return ItemId_Event_CreateArrows; }
|
||||
static SerializableItem *newItem() { return new Event_CreateArrows; }
|
||||
QList<ServerInfo_Arrow *> getArrowList() const { return typecastItemList<ServerInfo_Arrow *>(); }
|
||||
|
@ -279,7 +320,7 @@ public:
|
|||
class Event_CreateCounters : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_CreateCounters(int _gameId = -1, int _playerId = -1, const QList<ServerInfo_Counter *> &_counterList = QList<ServerInfo_Counter *>());
|
||||
Event_CreateCounters(int _playerId = -1, const QList<ServerInfo_Counter *> &_counterList = QList<ServerInfo_Counter *>());
|
||||
int getItemId() const { return ItemId_Event_CreateCounters; }
|
||||
static SerializableItem *newItem() { return new Event_CreateCounters; }
|
||||
QList<ServerInfo_Counter *> getCounterList() const { return typecastItemList<ServerInfo_Counter *>(); }
|
||||
|
@ -288,7 +329,7 @@ public:
|
|||
class Event_DrawCards : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_DrawCards(int _gameId = -1, int _playerId = -1, int numberCards = -1, const QList<ServerInfo_Card *> &_cardList = QList<ServerInfo_Card *>());
|
||||
Event_DrawCards(int _playerId = -1, int numberCards = -1, const QList<ServerInfo_Card *> &_cardList = QList<ServerInfo_Card *>());
|
||||
int getItemId() const { return ItemId_Event_DrawCards; }
|
||||
static SerializableItem *newItem() { return new Event_DrawCards; }
|
||||
int getNumberCards() const { return static_cast<SerializableItem_Int *>(itemMap.value("number_cards"))->getData(); }
|
||||
|
|
|
@ -198,44 +198,44 @@ Command_StopDumpZone::Command_StopDumpZone(int _gameId, int _playerId, const QSt
|
|||
insertItem(new SerializableItem_Int("player_id", _playerId));
|
||||
insertItem(new SerializableItem_String("zone_name", _zoneName));
|
||||
}
|
||||
Event_Say::Event_Say(int _gameId, int _playerId, const QString &_message)
|
||||
: GameEvent("say", _gameId, _playerId)
|
||||
Event_Say::Event_Say(int _playerId, const QString &_message)
|
||||
: GameEvent("say", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_String("message", _message));
|
||||
}
|
||||
Event_Leave::Event_Leave(int _gameId, int _playerId)
|
||||
: GameEvent("leave", _gameId, _playerId)
|
||||
Event_Leave::Event_Leave(int _playerId)
|
||||
: GameEvent("leave", _playerId)
|
||||
{
|
||||
}
|
||||
Event_DeckSelect::Event_DeckSelect(int _gameId, int _playerId, int _deckId)
|
||||
: GameEvent("deck_select", _gameId, _playerId)
|
||||
Event_DeckSelect::Event_DeckSelect(int _playerId, int _deckId)
|
||||
: GameEvent("deck_select", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("deck_id", _deckId));
|
||||
}
|
||||
Event_GameClosed::Event_GameClosed(int _gameId, int _playerId)
|
||||
: GameEvent("game_closed", _gameId, _playerId)
|
||||
Event_GameClosed::Event_GameClosed(int _playerId)
|
||||
: GameEvent("game_closed", _playerId)
|
||||
{
|
||||
}
|
||||
Event_ReadyStart::Event_ReadyStart(int _gameId, int _playerId)
|
||||
: GameEvent("ready_start", _gameId, _playerId)
|
||||
Event_ReadyStart::Event_ReadyStart(int _playerId)
|
||||
: GameEvent("ready_start", _playerId)
|
||||
{
|
||||
}
|
||||
Event_Concede::Event_Concede(int _gameId, int _playerId)
|
||||
: GameEvent("concede", _gameId, _playerId)
|
||||
Event_Concede::Event_Concede(int _playerId)
|
||||
: GameEvent("concede", _playerId)
|
||||
{
|
||||
}
|
||||
Event_Shuffle::Event_Shuffle(int _gameId, int _playerId)
|
||||
: GameEvent("shuffle", _gameId, _playerId)
|
||||
Event_Shuffle::Event_Shuffle(int _playerId)
|
||||
: GameEvent("shuffle", _playerId)
|
||||
{
|
||||
}
|
||||
Event_RollDie::Event_RollDie(int _gameId, int _playerId, int _sides, int _value)
|
||||
: GameEvent("roll_die", _gameId, _playerId)
|
||||
Event_RollDie::Event_RollDie(int _playerId, int _sides, int _value)
|
||||
: GameEvent("roll_die", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("sides", _sides));
|
||||
insertItem(new SerializableItem_Int("value", _value));
|
||||
}
|
||||
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, int _newCardId, bool _faceDown)
|
||||
: GameEvent("move_card", _gameId, _playerId)
|
||||
Event_MoveCard::Event_MoveCard(int _playerId, int _cardId, const QString &_cardName, const QString &_startZone, int _position, const QString &_targetZone, int _x, int _y, int _newCardId, bool _faceDown)
|
||||
: GameEvent("move_card", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("card_id", _cardId));
|
||||
insertItem(new SerializableItem_String("card_name", _cardName));
|
||||
|
@ -247,8 +247,8 @@ Event_MoveCard::Event_MoveCard(int _gameId, int _playerId, int _cardId, const QS
|
|||
insertItem(new SerializableItem_Int("new_card_id", _newCardId));
|
||||
insertItem(new SerializableItem_Bool("face_down", _faceDown));
|
||||
}
|
||||
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)
|
||||
Event_CreateToken::Event_CreateToken(int _playerId, const QString &_zone, int _cardId, const QString &_cardName, const QString &_pt, int _x, int _y)
|
||||
: GameEvent("create_token", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_String("zone", _zone));
|
||||
insertItem(new SerializableItem_Int("card_id", _cardId));
|
||||
|
@ -257,49 +257,49 @@ Event_CreateToken::Event_CreateToken(int _gameId, int _playerId, const QString &
|
|||
insertItem(new SerializableItem_Int("x", _x));
|
||||
insertItem(new SerializableItem_Int("y", _y));
|
||||
}
|
||||
Event_DeleteArrow::Event_DeleteArrow(int _gameId, int _playerId, int _arrowId)
|
||||
: GameEvent("delete_arrow", _gameId, _playerId)
|
||||
Event_DeleteArrow::Event_DeleteArrow(int _playerId, int _arrowId)
|
||||
: GameEvent("delete_arrow", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("arrow_id", _arrowId));
|
||||
}
|
||||
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)
|
||||
Event_SetCardAttr::Event_SetCardAttr(int _playerId, const QString &_zone, int _cardId, const QString &_attrName, const QString &_attrValue)
|
||||
: GameEvent("set_card_attr", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_String("zone", _zone));
|
||||
insertItem(new SerializableItem_Int("card_id", _cardId));
|
||||
insertItem(new SerializableItem_String("attr_name", _attrName));
|
||||
insertItem(new SerializableItem_String("attr_value", _attrValue));
|
||||
}
|
||||
Event_SetCounter::Event_SetCounter(int _gameId, int _playerId, int _counterId, int _value)
|
||||
: GameEvent("set_counter", _gameId, _playerId)
|
||||
Event_SetCounter::Event_SetCounter(int _playerId, int _counterId, int _value)
|
||||
: GameEvent("set_counter", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("counter_id", _counterId));
|
||||
insertItem(new SerializableItem_Int("value", _value));
|
||||
}
|
||||
Event_DelCounter::Event_DelCounter(int _gameId, int _playerId, int _counterId)
|
||||
: GameEvent("del_counter", _gameId, _playerId)
|
||||
Event_DelCounter::Event_DelCounter(int _playerId, int _counterId)
|
||||
: GameEvent("del_counter", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("counter_id", _counterId));
|
||||
}
|
||||
Event_SetActivePlayer::Event_SetActivePlayer(int _gameId, int _playerId, int _activePlayerId)
|
||||
: GameEvent("set_active_player", _gameId, _playerId)
|
||||
Event_SetActivePlayer::Event_SetActivePlayer(int _playerId, int _activePlayerId)
|
||||
: GameEvent("set_active_player", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("active_player_id", _activePlayerId));
|
||||
}
|
||||
Event_SetActivePhase::Event_SetActivePhase(int _gameId, int _playerId, int _phase)
|
||||
: GameEvent("set_active_phase", _gameId, _playerId)
|
||||
Event_SetActivePhase::Event_SetActivePhase(int _playerId, int _phase)
|
||||
: GameEvent("set_active_phase", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("phase", _phase));
|
||||
}
|
||||
Event_DumpZone::Event_DumpZone(int _gameId, int _playerId, int _zoneOwnerId, const QString &_zone, int _numberCards)
|
||||
: GameEvent("dump_zone", _gameId, _playerId)
|
||||
Event_DumpZone::Event_DumpZone(int _playerId, int _zoneOwnerId, const QString &_zone, int _numberCards)
|
||||
: GameEvent("dump_zone", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("zone_owner_id", _zoneOwnerId));
|
||||
insertItem(new SerializableItem_String("zone", _zone));
|
||||
insertItem(new SerializableItem_Int("number_cards", _numberCards));
|
||||
}
|
||||
Event_StopDumpZone::Event_StopDumpZone(int _gameId, int _playerId, int _zoneOwnerId, const QString &_zone)
|
||||
: GameEvent("stop_dump_zone", _gameId, _playerId)
|
||||
Event_StopDumpZone::Event_StopDumpZone(int _playerId, int _zoneOwnerId, const QString &_zone)
|
||||
: GameEvent("stop_dump_zone", _playerId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("zone_owner_id", _zoneOwnerId));
|
||||
insertItem(new SerializableItem_String("zone", _zone));
|
||||
|
|
|
@ -308,7 +308,7 @@ public:
|
|||
class Event_Say : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_Say(int _gameId = -1, int _playerId = -1, const QString &_message = QString());
|
||||
Event_Say(int _playerId = -1, const QString &_message = QString());
|
||||
QString getMessage() const { return static_cast<SerializableItem_String *>(itemMap.value("message"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_Say; }
|
||||
int getItemId() const { return ItemId_Event_Say; }
|
||||
|
@ -316,14 +316,14 @@ public:
|
|||
class Event_Leave : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_Leave(int _gameId = -1, int _playerId = -1);
|
||||
Event_Leave(int _playerId = -1);
|
||||
static SerializableItem *newItem() { return new Event_Leave; }
|
||||
int getItemId() const { return ItemId_Event_Leave; }
|
||||
};
|
||||
class Event_DeckSelect : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_DeckSelect(int _gameId = -1, int _playerId = -1, int _deckId = -1);
|
||||
Event_DeckSelect(int _playerId = -1, int _deckId = -1);
|
||||
int getDeckId() const { return static_cast<SerializableItem_Int *>(itemMap.value("deck_id"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_DeckSelect; }
|
||||
int getItemId() const { return ItemId_Event_DeckSelect; }
|
||||
|
@ -331,35 +331,35 @@ public:
|
|||
class Event_GameClosed : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_GameClosed(int _gameId = -1, int _playerId = -1);
|
||||
Event_GameClosed(int _playerId = -1);
|
||||
static SerializableItem *newItem() { return new Event_GameClosed; }
|
||||
int getItemId() const { return ItemId_Event_GameClosed; }
|
||||
};
|
||||
class Event_ReadyStart : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_ReadyStart(int _gameId = -1, int _playerId = -1);
|
||||
Event_ReadyStart(int _playerId = -1);
|
||||
static SerializableItem *newItem() { return new Event_ReadyStart; }
|
||||
int getItemId() const { return ItemId_Event_ReadyStart; }
|
||||
};
|
||||
class Event_Concede : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_Concede(int _gameId = -1, int _playerId = -1);
|
||||
Event_Concede(int _playerId = -1);
|
||||
static SerializableItem *newItem() { return new Event_Concede; }
|
||||
int getItemId() const { return ItemId_Event_Concede; }
|
||||
};
|
||||
class Event_Shuffle : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_Shuffle(int _gameId = -1, int _playerId = -1);
|
||||
Event_Shuffle(int _playerId = -1);
|
||||
static SerializableItem *newItem() { return new Event_Shuffle; }
|
||||
int getItemId() const { return ItemId_Event_Shuffle; }
|
||||
};
|
||||
class Event_RollDie : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_RollDie(int _gameId = -1, int _playerId = -1, int _sides = -1, int _value = -1);
|
||||
Event_RollDie(int _playerId = -1, int _sides = -1, int _value = -1);
|
||||
int getSides() const { return static_cast<SerializableItem_Int *>(itemMap.value("sides"))->getData(); };
|
||||
int getValue() const { return static_cast<SerializableItem_Int *>(itemMap.value("value"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_RollDie; }
|
||||
|
@ -368,7 +368,7 @@ public:
|
|||
class Event_MoveCard : public GameEvent {
|
||||
Q_OBJECT
|
||||
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, int _newCardId = -1, bool _faceDown = false);
|
||||
Event_MoveCard(int _playerId = -1, int _cardId = -1, const QString &_cardName = QString(), const QString &_startZone = QString(), int _position = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, int _newCardId = -1, bool _faceDown = false);
|
||||
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
|
||||
QString getCardName() const { return static_cast<SerializableItem_String *>(itemMap.value("card_name"))->getData(); };
|
||||
QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); };
|
||||
|
@ -384,7 +384,7 @@ public:
|
|||
class Event_CreateToken : public GameEvent {
|
||||
Q_OBJECT
|
||||
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 _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 static_cast<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
|
||||
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
|
||||
QString getCardName() const { return static_cast<SerializableItem_String *>(itemMap.value("card_name"))->getData(); };
|
||||
|
@ -397,7 +397,7 @@ public:
|
|||
class Event_DeleteArrow : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_DeleteArrow(int _gameId = -1, int _playerId = -1, int _arrowId = -1);
|
||||
Event_DeleteArrow(int _playerId = -1, int _arrowId = -1);
|
||||
int getArrowId() const { return static_cast<SerializableItem_Int *>(itemMap.value("arrow_id"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_DeleteArrow; }
|
||||
int getItemId() const { return ItemId_Event_DeleteArrow; }
|
||||
|
@ -405,7 +405,7 @@ public:
|
|||
class Event_SetCardAttr : public GameEvent {
|
||||
Q_OBJECT
|
||||
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 _playerId = -1, const QString &_zone = QString(), int _cardId = -1, const QString &_attrName = QString(), const QString &_attrValue = QString());
|
||||
QString getZone() const { return static_cast<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
|
||||
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
|
||||
QString getAttrName() const { return static_cast<SerializableItem_String *>(itemMap.value("attr_name"))->getData(); };
|
||||
|
@ -416,7 +416,7 @@ public:
|
|||
class Event_SetCounter : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_SetCounter(int _gameId = -1, int _playerId = -1, int _counterId = -1, int _value = -1);
|
||||
Event_SetCounter(int _playerId = -1, int _counterId = -1, int _value = -1);
|
||||
int getCounterId() const { return static_cast<SerializableItem_Int *>(itemMap.value("counter_id"))->getData(); };
|
||||
int getValue() const { return static_cast<SerializableItem_Int *>(itemMap.value("value"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_SetCounter; }
|
||||
|
@ -425,7 +425,7 @@ public:
|
|||
class Event_DelCounter : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_DelCounter(int _gameId = -1, int _playerId = -1, int _counterId = -1);
|
||||
Event_DelCounter(int _playerId = -1, int _counterId = -1);
|
||||
int getCounterId() const { return static_cast<SerializableItem_Int *>(itemMap.value("counter_id"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_DelCounter; }
|
||||
int getItemId() const { return ItemId_Event_DelCounter; }
|
||||
|
@ -433,7 +433,7 @@ public:
|
|||
class Event_SetActivePlayer : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_SetActivePlayer(int _gameId = -1, int _playerId = -1, int _activePlayerId = -1);
|
||||
Event_SetActivePlayer(int _playerId = -1, int _activePlayerId = -1);
|
||||
int getActivePlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("active_player_id"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_SetActivePlayer; }
|
||||
int getItemId() const { return ItemId_Event_SetActivePlayer; }
|
||||
|
@ -441,7 +441,7 @@ public:
|
|||
class Event_SetActivePhase : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_SetActivePhase(int _gameId = -1, int _playerId = -1, int _phase = -1);
|
||||
Event_SetActivePhase(int _playerId = -1, int _phase = -1);
|
||||
int getPhase() const { return static_cast<SerializableItem_Int *>(itemMap.value("phase"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_SetActivePhase; }
|
||||
int getItemId() const { return ItemId_Event_SetActivePhase; }
|
||||
|
@ -449,7 +449,7 @@ public:
|
|||
class Event_DumpZone : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_DumpZone(int _gameId = -1, int _playerId = -1, int _zoneOwnerId = -1, const QString &_zone = QString(), int _numberCards = -1);
|
||||
Event_DumpZone(int _playerId = -1, int _zoneOwnerId = -1, const QString &_zone = QString(), int _numberCards = -1);
|
||||
int getZoneOwnerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("zone_owner_id"))->getData(); };
|
||||
QString getZone() const { return static_cast<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
|
||||
int getNumberCards() const { return static_cast<SerializableItem_Int *>(itemMap.value("number_cards"))->getData(); };
|
||||
|
@ -459,7 +459,7 @@ public:
|
|||
class Event_StopDumpZone : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_StopDumpZone(int _gameId = -1, int _playerId = -1, int _zoneOwnerId = -1, const QString &_zone = QString());
|
||||
Event_StopDumpZone(int _playerId = -1, int _zoneOwnerId = -1, const QString &_zone = QString());
|
||||
int getZoneOwnerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("zone_owner_id"))->getData(); };
|
||||
QString getZone() const { return static_cast<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_StopDumpZone; }
|
||||
|
|
|
@ -49,9 +49,9 @@ while (<file>) {
|
|||
$type = 'game_event';
|
||||
$namePrefix = 'Event';
|
||||
$baseClass = 'GameEvent';
|
||||
$parentConstructorCall = "$baseClass(\"$name1\", _gameId, _playerId)";
|
||||
$constructorParamsH = "int _gameId = -1, int _playerId = -1";
|
||||
$constructorParamsCpp = "int _gameId, int _playerId";
|
||||
$parentConstructorCall = "$baseClass(\"$name1\", _playerId)";
|
||||
$constructorParamsH = "int _playerId = -1";
|
||||
$constructorParamsCpp = "int _playerId";
|
||||
} elsif ($type == 4) {
|
||||
$type = 'generic_event';
|
||||
$namePrefix = 'Event';
|
||||
|
|
|
@ -66,7 +66,7 @@ void Server_Game::pingClockTimeout()
|
|||
pingTime = -1;
|
||||
pingList.append(new ServerInfo_PlayerPing(player->getPlayerId(), pingTime));
|
||||
}
|
||||
sendGameEvent(new Event_Ping(-1, pingList));
|
||||
sendGameEvent(new Event_Ping(pingList));
|
||||
|
||||
const int maxTime = static_cast<Server *>(parent())->getMaxGameInactivityTime();
|
||||
if (allPlayersInactive) {
|
||||
|
@ -119,7 +119,7 @@ void Server_Game::startGameIfReady()
|
|||
Server_Player *player = playerIterator.next().value();
|
||||
player->setConceded(false);
|
||||
player->setReadyStart(false);
|
||||
player->sendProtocolItem(new Event_GameStateChanged(gameId, gameStarted, 0, 0, getGameState(player)));
|
||||
sendGameEventToPlayer(player, new Event_GameStateChanged(gameStarted, 0, 0, getGameState(player)));
|
||||
}
|
||||
|
||||
/* QSqlQuery query;
|
||||
|
@ -157,7 +157,7 @@ void Server_Game::stopGameIfFinished()
|
|||
playerIterator.toFront();
|
||||
while (playerIterator.hasNext()) {
|
||||
Server_Player *player = playerIterator.next().value();
|
||||
player->sendProtocolItem(new Event_GameStateChanged(gameId, gameStarted, -1, -1, getGameState(player)));
|
||||
sendGameEventToPlayer(player, new Event_GameStateChanged(gameStarted, -1, -1, getGameState(player)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec
|
|||
int playerId = keyList.isEmpty() ? 0 : (keyList.last() + 1);
|
||||
|
||||
Server_Player *newPlayer = new Server_Player(this, playerId, handler->getPlayerName(), spectator, handler);
|
||||
sendGameEvent(new Event_Join(-1, new ServerInfo_Player(playerId, handler->getPlayerName(), spectator)));
|
||||
sendGameEvent(new Event_Join(new ServerInfo_Player(playerId, handler->getPlayerName(), spectator)));
|
||||
players.insert(playerId, newPlayer);
|
||||
|
||||
if (broadcastUpdate)
|
||||
|
@ -192,7 +192,7 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec
|
|||
void Server_Game::removePlayer(Server_Player *player)
|
||||
{
|
||||
players.remove(player->getPlayerId());
|
||||
sendGameEvent(new Event_Leave(-1, player->getPlayerId()));
|
||||
sendGameEvent(new Event_Leave(player->getPlayerId()));
|
||||
delete player;
|
||||
|
||||
if (!getPlayerCount())
|
||||
|
@ -205,7 +205,7 @@ void Server_Game::removePlayer(Server_Player *player)
|
|||
void Server_Game::setActivePlayer(int _activePlayer)
|
||||
{
|
||||
activePlayer = _activePlayer;
|
||||
sendGameEvent(new Event_SetActivePlayer(-1, -1, activePlayer));
|
||||
sendGameEvent(new Event_SetActivePlayer(-1, activePlayer));
|
||||
setActivePhase(0);
|
||||
}
|
||||
|
||||
|
@ -217,13 +217,13 @@ void Server_Game::setActivePhase(int _activePhase)
|
|||
QList<Server_Arrow *> toDelete = player->getArrows().values();
|
||||
for (int i = 0; i < toDelete.size(); ++i) {
|
||||
Server_Arrow *a = toDelete[i];
|
||||
sendGameEvent(new Event_DeleteArrow(-1, player->getPlayerId(), a->getId()));
|
||||
sendGameEvent(new Event_DeleteArrow(player->getPlayerId(), a->getId()));
|
||||
player->deleteArrow(a->getId());
|
||||
}
|
||||
}
|
||||
|
||||
activePhase = _activePhase;
|
||||
sendGameEvent(new Event_SetActivePhase(-1, -1, activePhase));
|
||||
sendGameEvent(new Event_SetActivePhase(-1, activePhase));
|
||||
}
|
||||
|
||||
QList<ServerInfo_Player *> Server_Game::getGameState(Server_Player *playerWhosAsking) const
|
||||
|
@ -282,13 +282,23 @@ QList<ServerInfo_Player *> Server_Game::getGameState(Server_Player *playerWhosAs
|
|||
|
||||
void Server_Game::sendGameEvent(GameEvent *event, Server_Player *exclude)
|
||||
{
|
||||
event->setGameId(gameId);
|
||||
sendGameEventContainer(new GameEventContainer(QList<GameEvent *>() << event), exclude);
|
||||
}
|
||||
|
||||
void Server_Game::sendGameEventContainer(GameEventContainer *cont, Server_Player *exclude)
|
||||
{
|
||||
cont->setGameId(gameId);
|
||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||
while (playerIterator.hasNext()) {
|
||||
Server_Player *p = playerIterator.next().value();
|
||||
if (p != exclude)
|
||||
p->sendProtocolItem(event, false);
|
||||
p->sendProtocolItem(cont, false);
|
||||
}
|
||||
|
||||
delete event;
|
||||
delete cont;
|
||||
}
|
||||
|
||||
void Server_Game::sendGameEventToPlayer(Server_Player *player, GameEvent *event)
|
||||
{
|
||||
player->sendProtocolItem(new GameEventContainer(QList<GameEvent *>() << event, gameId));
|
||||
}
|
||||
|
|
|
@ -73,6 +73,8 @@ public:
|
|||
|
||||
QList<ServerInfo_Player *> getGameState(Server_Player *playerWhosAsking) const;
|
||||
void sendGameEvent(GameEvent *event, Server_Player *exclude = 0);
|
||||
void sendGameEventContainer(GameEventContainer *cont, Server_Player *exclude = 0);
|
||||
void sendGameEventToPlayer(Server_Player *player, GameEvent *event);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -51,97 +51,110 @@ void Server_ProtocolHandler::playerRemovedFromGame(Server_Game *game)
|
|||
games.remove(game->getGameId());
|
||||
}
|
||||
|
||||
void Server_ProtocolHandler::processCommandHelper(Command *command)
|
||||
ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, CommandContainer *cont)
|
||||
{
|
||||
lastCommandTime = QDateTime::currentDateTime();
|
||||
|
||||
ResponseCode response = RespInvalidCommand;
|
||||
|
||||
ChatCommand *chatCommand = qobject_cast<ChatCommand *>(command);
|
||||
GameCommand *gameCommand = qobject_cast<GameCommand *>(command);
|
||||
if (chatCommand) {
|
||||
qDebug() << "received ChatCommand: channel =" << chatCommand->getChannel();
|
||||
if (authState == PasswordWrong) {
|
||||
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), RespLoginNeeded));
|
||||
return;
|
||||
}
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
||||
Server_ChatChannel *channel = chatChannels.value(chatCommand->getChannel(), 0);
|
||||
if (!channel) {
|
||||
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), RespNameNotFound));
|
||||
return;
|
||||
}
|
||||
if (!channel)
|
||||
return RespNameNotFound;
|
||||
|
||||
switch (command->getItemId()) {
|
||||
case ItemId_Command_ChatLeaveChannel: response = cmdChatLeaveChannel(qobject_cast<Command_ChatLeaveChannel *>(command), channel); break;
|
||||
case ItemId_Command_ChatSay: response = cmdChatSay(qobject_cast<Command_ChatSay *>(command), channel); break;
|
||||
case ItemId_Command_ChatLeaveChannel: return cmdChatLeaveChannel(qobject_cast<Command_ChatLeaveChannel *>(command), cont, channel);
|
||||
case ItemId_Command_ChatSay: return cmdChatSay(qobject_cast<Command_ChatSay *>(command), cont, channel);
|
||||
}
|
||||
} else if (gameCommand) {
|
||||
qDebug() << "received GameCommand: game =" << gameCommand->getGameId();
|
||||
if (authState == PasswordWrong) {
|
||||
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), RespLoginNeeded));
|
||||
return;
|
||||
}
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
||||
if (!games.contains(gameCommand->getGameId())) {
|
||||
qDebug() << "invalid game";
|
||||
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), RespNameNotFound));
|
||||
return;
|
||||
return RespNameNotFound;
|
||||
}
|
||||
QPair<Server_Game *, Server_Player *> gamePair = games.value(gameCommand->getGameId());
|
||||
Server_Game *game = gamePair.first;
|
||||
Server_Player *player = gamePair.second;
|
||||
|
||||
switch (command->getItemId()) {
|
||||
case ItemId_Command_DeckSelect: response = cmdDeckSelect(qobject_cast<Command_DeckSelect *>(command), game, player); break;
|
||||
case ItemId_Command_LeaveGame: response = cmdLeaveGame(qobject_cast<Command_LeaveGame *>(command), game, player); break;
|
||||
case ItemId_Command_ReadyStart: response = cmdReadyStart(qobject_cast<Command_ReadyStart *>(command), game, player); break;
|
||||
case ItemId_Command_Concede: response = cmdConcede(qobject_cast<Command_Concede *>(command), game, player); break;
|
||||
case ItemId_Command_Say: response = cmdSay(qobject_cast<Command_Say *>(command), game, player); break;
|
||||
case ItemId_Command_Shuffle: response = cmdShuffle(qobject_cast<Command_Shuffle *>(command), game, player); break;
|
||||
case ItemId_Command_Mulligan: response = cmdMulligan(qobject_cast<Command_Mulligan *>(command), game, player); break;
|
||||
case ItemId_Command_RollDie: response = cmdRollDie(qobject_cast<Command_RollDie *>(command), game, player); break;
|
||||
case ItemId_Command_DrawCards: response = cmdDrawCards(qobject_cast<Command_DrawCards *>(command), game, player); break;
|
||||
case ItemId_Command_MoveCard: response = cmdMoveCard(qobject_cast<Command_MoveCard *>(command), game, player); break;
|
||||
case ItemId_Command_CreateToken: response = cmdCreateToken(qobject_cast<Command_CreateToken *>(command), game, player); break;
|
||||
case ItemId_Command_CreateArrow: response = cmdCreateArrow(qobject_cast<Command_CreateArrow *>(command), game, player); break;
|
||||
case ItemId_Command_DeleteArrow: response = cmdDeleteArrow(qobject_cast<Command_DeleteArrow *>(command), game, player); break;
|
||||
case ItemId_Command_SetCardAttr: response = cmdSetCardAttr(qobject_cast<Command_SetCardAttr *>(command), game, player); break;
|
||||
case ItemId_Command_IncCounter: response = cmdIncCounter(qobject_cast<Command_IncCounter *>(command), game, player); break;
|
||||
case ItemId_Command_CreateCounter: response = cmdCreateCounter(qobject_cast<Command_CreateCounter *>(command), game, player); break;
|
||||
case ItemId_Command_SetCounter: response = cmdSetCounter(qobject_cast<Command_SetCounter *>(command), game, player); break;
|
||||
case ItemId_Command_DelCounter: response = cmdDelCounter(qobject_cast<Command_DelCounter *>(command), game, player); break;
|
||||
case ItemId_Command_NextTurn: response = cmdNextTurn(qobject_cast<Command_NextTurn *>(command), game, player); break;
|
||||
case ItemId_Command_SetActivePhase: response = cmdSetActivePhase(qobject_cast<Command_SetActivePhase *>(command), game, player); break;
|
||||
case ItemId_Command_DumpZone: response = cmdDumpZone(qobject_cast<Command_DumpZone *>(command), game, player); break;
|
||||
case ItemId_Command_StopDumpZone: response = cmdStopDumpZone(qobject_cast<Command_StopDumpZone *>(command), game, player); break;
|
||||
case ItemId_Command_DeckSelect: return cmdDeckSelect(qobject_cast<Command_DeckSelect *>(command), cont, game, player);
|
||||
case ItemId_Command_LeaveGame: return cmdLeaveGame(qobject_cast<Command_LeaveGame *>(command), cont, game, player);
|
||||
case ItemId_Command_ReadyStart: return cmdReadyStart(qobject_cast<Command_ReadyStart *>(command), cont, game, player);
|
||||
case ItemId_Command_Concede: return cmdConcede(qobject_cast<Command_Concede *>(command), cont, game, player);
|
||||
case ItemId_Command_Say: return cmdSay(qobject_cast<Command_Say *>(command), cont, game, player);
|
||||
case ItemId_Command_Shuffle: return cmdShuffle(qobject_cast<Command_Shuffle *>(command), cont, game, player);
|
||||
case ItemId_Command_Mulligan: return cmdMulligan(qobject_cast<Command_Mulligan *>(command), cont, game, player);
|
||||
case ItemId_Command_RollDie: return cmdRollDie(qobject_cast<Command_RollDie *>(command), cont, game, player);
|
||||
case ItemId_Command_DrawCards: return cmdDrawCards(qobject_cast<Command_DrawCards *>(command), cont, game, player);
|
||||
case ItemId_Command_MoveCard: return cmdMoveCard(qobject_cast<Command_MoveCard *>(command), cont, game, player);
|
||||
case ItemId_Command_CreateToken: return cmdCreateToken(qobject_cast<Command_CreateToken *>(command), cont, game, player);
|
||||
case ItemId_Command_CreateArrow: return cmdCreateArrow(qobject_cast<Command_CreateArrow *>(command), cont, game, player);
|
||||
case ItemId_Command_DeleteArrow: return cmdDeleteArrow(qobject_cast<Command_DeleteArrow *>(command), cont, game, player);
|
||||
case ItemId_Command_SetCardAttr: return cmdSetCardAttr(qobject_cast<Command_SetCardAttr *>(command), cont, game, player);
|
||||
case ItemId_Command_IncCounter: return cmdIncCounter(qobject_cast<Command_IncCounter *>(command), cont, game, player);
|
||||
case ItemId_Command_CreateCounter: return cmdCreateCounter(qobject_cast<Command_CreateCounter *>(command), cont, game, player);
|
||||
case ItemId_Command_SetCounter: return cmdSetCounter(qobject_cast<Command_SetCounter *>(command), cont, game, player);
|
||||
case ItemId_Command_DelCounter: return cmdDelCounter(qobject_cast<Command_DelCounter *>(command), cont, game, player);
|
||||
case ItemId_Command_NextTurn: return cmdNextTurn(qobject_cast<Command_NextTurn *>(command), cont, game, player);
|
||||
case ItemId_Command_SetActivePhase: return cmdSetActivePhase(qobject_cast<Command_SetActivePhase *>(command), cont, game, player);
|
||||
case ItemId_Command_DumpZone: return cmdDumpZone(qobject_cast<Command_DumpZone *>(command), cont, game, player);
|
||||
case ItemId_Command_StopDumpZone: return cmdStopDumpZone(qobject_cast<Command_StopDumpZone *>(command), cont, game, player);
|
||||
}
|
||||
} else {
|
||||
qDebug() << "received generic Command";
|
||||
switch (command->getItemId()) {
|
||||
case ItemId_Command_Ping: response = cmdPing(qobject_cast<Command_Ping *>(command)); break;
|
||||
case ItemId_Command_Login: response = cmdLogin(qobject_cast<Command_Login *>(command)); break;
|
||||
case ItemId_Command_DeckList: response = cmdDeckList(qobject_cast<Command_DeckList *>(command)); break;
|
||||
case ItemId_Command_DeckNewDir: response = cmdDeckNewDir(qobject_cast<Command_DeckNewDir *>(command)); break;
|
||||
case ItemId_Command_DeckDelDir: response = cmdDeckDelDir(qobject_cast<Command_DeckDelDir *>(command)); break;
|
||||
case ItemId_Command_DeckDel: response = cmdDeckDel(qobject_cast<Command_DeckDel *>(command)); break;
|
||||
case ItemId_Command_DeckUpload: response = cmdDeckUpload(qobject_cast<Command_DeckUpload *>(command)); break;
|
||||
case ItemId_Command_DeckDownload: response = cmdDeckDownload(qobject_cast<Command_DeckDownload *>(command)); break;
|
||||
case ItemId_Command_ListChatChannels: response = cmdListChatChannels(qobject_cast<Command_ListChatChannels *>(command)); break;
|
||||
case ItemId_Command_ChatJoinChannel: response = cmdChatJoinChannel(qobject_cast<Command_ChatJoinChannel *>(command)); break;
|
||||
case ItemId_Command_ListGames: response = cmdListGames(qobject_cast<Command_ListGames *>(command)); break;
|
||||
case ItemId_Command_CreateGame: response = cmdCreateGame(qobject_cast<Command_CreateGame *>(command)); break;
|
||||
case ItemId_Command_JoinGame: response = cmdJoinGame(qobject_cast<Command_JoinGame *>(command)); break;
|
||||
case ItemId_Command_Ping: return cmdPing(qobject_cast<Command_Ping *>(command), cont);
|
||||
case ItemId_Command_Login: return cmdLogin(qobject_cast<Command_Login *>(command), cont);
|
||||
case ItemId_Command_DeckList: return cmdDeckList(qobject_cast<Command_DeckList *>(command), cont);
|
||||
case ItemId_Command_DeckNewDir: return cmdDeckNewDir(qobject_cast<Command_DeckNewDir *>(command), cont);
|
||||
case ItemId_Command_DeckDelDir: return cmdDeckDelDir(qobject_cast<Command_DeckDelDir *>(command), cont);
|
||||
case ItemId_Command_DeckDel: return cmdDeckDel(qobject_cast<Command_DeckDel *>(command), cont);
|
||||
case ItemId_Command_DeckUpload: return cmdDeckUpload(qobject_cast<Command_DeckUpload *>(command), cont);
|
||||
case ItemId_Command_DeckDownload: return cmdDeckDownload(qobject_cast<Command_DeckDownload *>(command), cont);
|
||||
case ItemId_Command_ListChatChannels: return cmdListChatChannels(qobject_cast<Command_ListChatChannels *>(command), cont);
|
||||
case ItemId_Command_ChatJoinChannel: return cmdChatJoinChannel(qobject_cast<Command_ChatJoinChannel *>(command), cont);
|
||||
case ItemId_Command_ListGames: return cmdListGames(qobject_cast<Command_ListGames *>(command), cont);
|
||||
case ItemId_Command_CreateGame: return cmdCreateGame(qobject_cast<Command_CreateGame *>(command), cont);
|
||||
case ItemId_Command_JoinGame: return cmdJoinGame(qobject_cast<Command_JoinGame *>(command), cont);
|
||||
}
|
||||
}
|
||||
if (response != RespNothing)
|
||||
sendProtocolItem(new ProtocolResponse(command->getCmdId(), response));
|
||||
return RespInvalidCommand;
|
||||
}
|
||||
|
||||
void Server_ProtocolHandler::processCommand(Command *command)
|
||||
void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont)
|
||||
{
|
||||
processCommandHelper(command);
|
||||
const QList<Command *> &cmdList = cont->getCommandList();
|
||||
ResponseCode finalResponseCode = RespOk;
|
||||
for (int i = 0; i < cmdList.size(); ++i) {
|
||||
ResponseCode resp = processCommandHelper(cmdList[i], cont);
|
||||
if ((resp != RespOk) && (resp != RespNothing))
|
||||
finalResponseCode = resp;
|
||||
}
|
||||
|
||||
delete command;
|
||||
ProtocolResponse *pr = cont->getResponse();
|
||||
if (!pr)
|
||||
pr = new ProtocolResponse(cont->getCmdId(), finalResponseCode);
|
||||
|
||||
GameEventContainer *gQ = cont->getGameEventQueue();
|
||||
if (gQ) {
|
||||
Server_Game *game = games.value(gQ->getGameId()).first;
|
||||
game->sendGameEventContainer(gQ);
|
||||
}
|
||||
|
||||
const QList<ProtocolItem *> &iQ = cont->getItemQueue();
|
||||
for (int i = 0; i < iQ.size(); ++i)
|
||||
sendProtocolItem(iQ[i]);
|
||||
|
||||
sendProtocolItem(pr);
|
||||
|
||||
delete cont;
|
||||
|
||||
while (!itemQueue.isEmpty())
|
||||
sendProtocolItem(itemQueue.takeFirst());
|
||||
|
@ -165,12 +178,12 @@ QPair<Server_Game *, Server_Player *> Server_ProtocolHandler::getGame(int gameId
|
|||
return QPair<Server_Game *, Server_Player *>(0, 0);
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdPing(Command_Ping * /*cmd*/)
|
||||
ResponseCode Server_ProtocolHandler::cmdPing(Command_Ping * /*cmd*/, CommandContainer * /*cont*/)
|
||||
{
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd)
|
||||
ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContainer *cont)
|
||||
{
|
||||
QString userName = cmd->getUsername().simplified();
|
||||
if (userName.isEmpty())
|
||||
|
@ -193,8 +206,9 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd)
|
|||
if (gamePlayers[j]->getPlayerName() == playerName) {
|
||||
gamePlayers[j]->setProtocolHandler(this);
|
||||
games.insert(serverGames[i]->getGameId(), QPair<Server_Game *, Server_Player *>(serverGames[i], gamePlayers[j]));
|
||||
|
||||
enqueueProtocolItem(new Event_GameJoined(serverGames[i]->getGameId(), serverGames[i]->getDescription(), gamePlayers[j]->getPlayerId(), gamePlayers[j]->getSpectator(), true));
|
||||
enqueueProtocolItem(new Event_GameStateChanged(serverGames[i]->getGameId(), serverGames[i]->getGameStarted(), serverGames[i]->getActivePlayer(), serverGames[i]->getActivePhase(), serverGames[i]->getGameState(gamePlayers[j])));
|
||||
enqueueProtocolItem(GameEventContainer::makeNew(new Event_GameStateChanged(serverGames[i]->getGameStarted(), serverGames[i]->getActivePlayer(), serverGames[i]->getActivePhase(), serverGames[i]->getGameState(gamePlayers[j])), serverGames[i]->getGameId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +216,7 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd)
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdListChatChannels(Command_ListChatChannels * /*cmd*/)
|
||||
ResponseCode Server_ProtocolHandler::cmdListChatChannels(Command_ListChatChannels * /*cmd*/, CommandContainer *cont)
|
||||
{
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
@ -213,13 +227,13 @@ ResponseCode Server_ProtocolHandler::cmdListChatChannels(Command_ListChatChannel
|
|||
Server_ChatChannel *c = channelIterator.next().value();
|
||||
eventChannelList.append(new ServerInfo_ChatChannel(c->getName(), c->getDescription(), c->size(), c->getAutoJoin()));
|
||||
}
|
||||
sendProtocolItem(new Event_ListChatChannels(eventChannelList));
|
||||
cont->enqueueItem(new Event_ListChatChannels(eventChannelList));
|
||||
|
||||
acceptsChatChannelListChanges = true;
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdChatJoinChannel(Command_ChatJoinChannel *cmd)
|
||||
ResponseCode Server_ProtocolHandler::cmdChatJoinChannel(Command_ChatJoinChannel *cmd, CommandContainer *cont)
|
||||
{
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
@ -237,20 +251,20 @@ ResponseCode Server_ProtocolHandler::cmdChatJoinChannel(Command_ChatJoinChannel
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdChatLeaveChannel(Command_ChatLeaveChannel * /*cmd*/, Server_ChatChannel *channel)
|
||||
ResponseCode Server_ProtocolHandler::cmdChatLeaveChannel(Command_ChatLeaveChannel * /*cmd*/, CommandContainer *cont, Server_ChatChannel *channel)
|
||||
{
|
||||
chatChannels.remove(channel->getName());
|
||||
channel->removeClient(this);
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel)
|
||||
ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, CommandContainer *cont, Server_ChatChannel *channel)
|
||||
{
|
||||
channel->say(this, cmd->getMessage());
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/)
|
||||
ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/, CommandContainer *cont)
|
||||
{
|
||||
const QList<Server_Game *> &gameList = server->getGames();
|
||||
QList<ServerInfo_Game *> eventGameList;
|
||||
|
@ -267,24 +281,24 @@ ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/)
|
|||
g->getSpectatorCount()
|
||||
));
|
||||
}
|
||||
sendProtocolItem(new Event_ListGames(eventGameList));
|
||||
cont->enqueueItem(new Event_ListGames(eventGameList));
|
||||
|
||||
acceptsGameListChanges = true;
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd)
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont)
|
||||
{
|
||||
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), this);
|
||||
Server_Player *creator = game->getCreator();
|
||||
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator));
|
||||
|
||||
enqueueProtocolItem(new Event_GameJoined(game->getGameId(), game->getDescription(), creator->getPlayerId(), false, false));
|
||||
enqueueProtocolItem(new Event_GameStateChanged(game->getGameId(), game->getGameStarted(), game->getActivePlayer(), game->getActivePhase(), game->getGameState(creator)));
|
||||
enqueueProtocolItem(GameEventContainer::makeNew(new Event_GameStateChanged(game->getGameStarted(), game->getActivePlayer(), game->getActivePhase(), game->getGameState(creator)), game->getGameId()));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd)
|
||||
ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont)
|
||||
{
|
||||
if (games.contains(cmd->getGameId()))
|
||||
return RespContextError;
|
||||
|
@ -298,18 +312,18 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd)
|
|||
Server_Player *player = g->addPlayer(this, cmd->getSpectator());
|
||||
games.insert(cmd->getGameId(), QPair<Server_Game *, Server_Player *>(g, player));
|
||||
enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), g->getDescription(), player->getPlayerId(), cmd->getSpectator(), false));
|
||||
enqueueProtocolItem(new Event_GameStateChanged(cmd->getGameId(), g->getGameStarted(), g->getActivePlayer(), g->getActivePhase(), g->getGameState(player)));
|
||||
enqueueProtocolItem(GameEventContainer::makeNew(new Event_GameStateChanged(g->getGameStarted(), g->getActivePlayer(), g->getActivePhase(), g->getGameState(player)), cmd->getGameId()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
game->removePlayer(player);
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
DeckList *deck;
|
||||
if (cmd->getDeckId() == -1) {
|
||||
|
@ -325,48 +339,48 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Serv
|
|||
}
|
||||
player->setDeck(deck);
|
||||
|
||||
game->sendGameEvent(new Event_DeckSelect(-1, player->getPlayerId(), cmd->getDeckId()));
|
||||
game->sendGameEvent(new Event_DeckSelect(player->getPlayerId(), cmd->getDeckId()));
|
||||
|
||||
sendProtocolItem(new Response_DeckDownload(cmd->getCmdId(), RespOk, new DeckList(deck)));
|
||||
cont->setResponse(new Response_DeckDownload(cont->getCmdId(), RespOk, new DeckList(deck)));
|
||||
return RespNothing;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
player->setConceded(true);
|
||||
game->sendGameEvent(new Event_Concede(-1, player->getPlayerId()));
|
||||
game->sendGameEvent(new Event_Concede(player->getPlayerId()));
|
||||
game->stopGameIfFinished();
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!player->getDeck())
|
||||
return RespContextError;
|
||||
|
||||
player->setReadyStart(true);
|
||||
game->sendGameEvent(new Event_ReadyStart(-1, player->getPlayerId()));
|
||||
game->sendGameEvent(new Event_ReadyStart(player->getPlayerId()));
|
||||
game->startGameIfReady();
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
game->sendGameEvent(new Event_Say(-1, player->getPlayerId(), cmd->getMessage()));
|
||||
game->sendGameEvent(new Event_Say(player->getPlayerId(), cmd->getMessage()));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
player->getZones().value("deck")->shuffle();
|
||||
game->sendGameEvent(new Event_Shuffle(-1, player->getPlayerId()));
|
||||
game->sendGameEvent(new Event_Shuffle(player->getPlayerId()));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
@ -380,7 +394,7 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Ser
|
|||
moveCard(game, player, "hand", hand->cards.first()->getId(), "deck", 0, 0, false);
|
||||
|
||||
player->getZones().value("deck")->shuffle();
|
||||
game->sendGameEvent(new Event_Shuffle(-1, player->getPlayerId()));
|
||||
game->sendGameEvent(new Event_Shuffle(player->getPlayerId()));
|
||||
|
||||
drawCards(game, player, number);
|
||||
player->setInitialCards(number - 1);
|
||||
|
@ -388,9 +402,9 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Ser
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
game->sendGameEvent(new Event_RollDie(-1, player->getPlayerId(), cmd->getSides(), rng->getNumber(1, cmd->getSides())));
|
||||
game->sendGameEvent(new Event_RollDie(player->getPlayerId(), cmd->getSides(), rng->getNumber(1, cmd->getSides())));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
|
@ -411,14 +425,14 @@ ResponseCode Server_ProtocolHandler::drawCards(Server_Game *game, Server_Player
|
|||
cardList.append(new ServerInfo_Card(card->getId(), card->getName()));
|
||||
}
|
||||
|
||||
player->sendProtocolItem(new Event_DrawCards(game->getGameId(), player->getPlayerId(), cardList.size(), cardList));
|
||||
game->sendGameEvent(new Event_DrawCards(-1, player->getPlayerId(), cardList.size()), player);
|
||||
player->sendProtocolItem(GameEventContainer::makeNew(new Event_DrawCards(player->getPlayerId(), cardList.size(), cardList), game->getGameId()));
|
||||
game->sendGameEvent(new Event_DrawCards(player->getPlayerId(), cardList.size()), player);
|
||||
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
return drawCards(game, player, cmd->getNumber());
|
||||
}
|
||||
|
@ -475,7 +489,7 @@ ResponseCode Server_ProtocolHandler::moveCard(Server_Game *game, Server_Player *
|
|||
int privatePosition = -1;
|
||||
if (startzone->getType() == HiddenZone)
|
||||
privatePosition = position;
|
||||
player->sendProtocolItem(new Event_MoveCard(game->getGameId(), player->getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getName(), x, y, privateNewCardId, faceDown));
|
||||
player->sendProtocolItem(GameEventContainer::makeNew(new Event_MoveCard(player->getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getName(), x, y, privateNewCardId, faceDown), game->getGameId()));
|
||||
|
||||
// Other players do not get to see the start and/or target position of the card if the respective
|
||||
// part of the zone is being looked at. The information is not needed anyway because in hidden zones,
|
||||
|
@ -489,9 +503,9 @@ ResponseCode Server_ProtocolHandler::moveCard(Server_Game *game, Server_Player *
|
|||
x = -1;
|
||||
|
||||
if ((startzone->getType() == PublicZone) || (targetzone->getType() == PublicZone))
|
||||
game->sendGameEvent(new Event_MoveCard(-1, player->getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getName(), x, y, card->getId(), faceDown), player);
|
||||
game->sendGameEvent(new Event_MoveCard(player->getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getName(), x, y, card->getId(), faceDown), player);
|
||||
else
|
||||
game->sendGameEvent(new Event_MoveCard(-1, player->getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getName(), x, y, -1, false), player);
|
||||
game->sendGameEvent(new Event_MoveCard(player->getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getName(), x, y, -1, false), player);
|
||||
|
||||
// If the card was moved to another zone, delete all arrows from and to the card
|
||||
if (startzone != targetzone) {
|
||||
|
@ -512,12 +526,12 @@ ResponseCode Server_ProtocolHandler::moveCard(Server_Game *game, Server_Player *
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
return moveCard(game, player, cmd->getStartZone(), cmd->getCardId(), cmd->getTargetZone(), cmd->getX(), cmd->getY(), cmd->getFaceDown());
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
@ -529,12 +543,12 @@ ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Se
|
|||
|
||||
Server_Card *card = new Server_Card(cmd->getCardName(), player->newCardId(), cmd->getX(), cmd->getY());
|
||||
zone->insertCard(card, cmd->getX(), cmd->getY());
|
||||
game->sendGameEvent(new Event_CreateToken(-1, player->getPlayerId(), zone->getName(), card->getId(), card->getName(), cmd->getPt(), cmd->getX(), cmd->getY()));
|
||||
game->sendGameEvent(new Event_CreateToken(player->getPlayerId(), zone->getName(), card->getId(), card->getName(), cmd->getPt(), cmd->getX(), cmd->getY()));
|
||||
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
@ -560,7 +574,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Se
|
|||
|
||||
Server_Arrow *arrow = new Server_Arrow(player->newArrowId(), startCard, targetCard, cmd->getColor());
|
||||
player->addArrow(arrow);
|
||||
game->sendGameEvent(new Event_CreateArrows(-1, player->getPlayerId(), QList<ServerInfo_Arrow *>() << new ServerInfo_Arrow(
|
||||
game->sendGameEvent(new Event_CreateArrows(player->getPlayerId(), QList<ServerInfo_Arrow *>() << new ServerInfo_Arrow(
|
||||
arrow->getId(),
|
||||
startPlayer->getPlayerId(),
|
||||
startZone->getName(),
|
||||
|
@ -573,7 +587,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Se
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
@ -581,11 +595,11 @@ ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, Se
|
|||
if (!player->deleteArrow(cmd->getArrowId()))
|
||||
return RespNameNotFound;
|
||||
|
||||
game->sendGameEvent(new Event_DeleteArrow(-1, player->getPlayerId(), cmd->getArrowId()));
|
||||
game->sendGameEvent(new Event_DeleteArrow(player->getPlayerId(), cmd->getArrowId()));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
@ -608,11 +622,11 @@ ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Se
|
|||
if (!card->setAttribute(cmd->getAttrName(), cmd->getAttrValue(), false))
|
||||
return RespInvalidCommand;
|
||||
}
|
||||
game->sendGameEvent(new Event_SetCardAttr(-1, player->getPlayerId(), zone->getName(), cmd->getCardId(), cmd->getAttrName(), cmd->getAttrValue()));
|
||||
cont->enqueueGameEvent(new Event_SetCardAttr(player->getPlayerId(), zone->getName(), cmd->getCardId(), cmd->getAttrName(), cmd->getAttrValue()), game->getGameId());
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
@ -623,23 +637,23 @@ ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Serv
|
|||
return RespNameNotFound;
|
||||
|
||||
c->setCount(c->getCount() + cmd->getDelta());
|
||||
game->sendGameEvent(new Event_SetCounter(-1, player->getPlayerId(), c->getId(), c->getCount()));
|
||||
game->sendGameEvent(new Event_SetCounter(player->getPlayerId(), c->getId(), c->getCount()));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
Server_Counter *c = new Server_Counter(player->newCounterId(), cmd->getCounterName(), cmd->getColor(), cmd->getRadius(), cmd->getValue());
|
||||
player->addCounter(c);
|
||||
game->sendGameEvent(new Event_CreateCounters(-1, player->getPlayerId(), QList<ServerInfo_Counter *>() << new ServerInfo_Counter(c->getId(), c->getName(), c->getColor(), c->getRadius(), c->getCount())));
|
||||
game->sendGameEvent(new Event_CreateCounters(player->getPlayerId(), QList<ServerInfo_Counter *>() << new ServerInfo_Counter(c->getId(), c->getName(), c->getColor(), c->getRadius(), c->getCount())));
|
||||
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
@ -649,22 +663,22 @@ ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, Serv
|
|||
return RespNameNotFound;
|
||||
|
||||
c->setCount(cmd->getValue());
|
||||
game->sendGameEvent(new Event_SetCounter(-1, player->getPlayerId(), c->getId(), c->getCount()));
|
||||
game->sendGameEvent(new Event_SetCounter(player->getPlayerId(), c->getId(), c->getCount()));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
||||
if (!player->deleteCounter(cmd->getCounterId()))
|
||||
return RespNameNotFound;
|
||||
game->sendGameEvent(new Event_DelCounter(-1, player->getPlayerId(), cmd->getCounterId()));
|
||||
game->sendGameEvent(new Event_DelCounter(player->getPlayerId(), cmd->getCounterId()));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, Server_Game *game, Server_Player * /*player*/)
|
||||
ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player * /*player*/)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
@ -676,7 +690,7 @@ ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, Ser
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
@ -688,7 +702,7 @@ ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *c
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
@ -714,13 +728,13 @@ ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, Server_G
|
|||
}
|
||||
if (zone->getType() == HiddenZone) {
|
||||
zone->setCardsBeingLookedAt(numberCards);
|
||||
game->sendGameEvent(new Event_DumpZone(-1, player->getPlayerId(), otherPlayer->getPlayerId(), zone->getName(), numberCards));
|
||||
game->sendGameEvent(new Event_DumpZone(player->getPlayerId(), otherPlayer->getPlayerId(), zone->getName(), numberCards));
|
||||
}
|
||||
sendProtocolItem(new Response_DumpZone(cmd->getCmdId(), RespOk, new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), numberCards < zone->cards.size() ? zone->cards.size() : numberCards, respCardList)));
|
||||
cont->setResponse(new Response_DumpZone(cont->getCmdId(), RespOk, new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), numberCards < zone->cards.size() ? zone->cards.size() : numberCards, respCardList)));
|
||||
return RespNothing;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player)
|
||||
ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!game->getGameStarted())
|
||||
return RespGameNotStarted;
|
||||
|
@ -734,7 +748,7 @@ ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd,
|
|||
|
||||
if (zone->getType() == HiddenZone) {
|
||||
zone->setCardsBeingLookedAt(0);
|
||||
game->sendGameEvent(new Event_StopDumpZone(-1, player->getPlayerId(), cmd->getPlayerId(), zone->getName()));
|
||||
game->sendGameEvent(new Event_StopDumpZone(player->getPlayerId(), cmd->getPlayerId(), zone->getName()));
|
||||
}
|
||||
return RespOk;
|
||||
}
|
||||
|
|
|
@ -32,48 +32,48 @@ private:
|
|||
|
||||
virtual DeckList *getDeckFromDatabase(int deckId) = 0;
|
||||
|
||||
ResponseCode cmdPing(Command_Ping *cmd);
|
||||
ResponseCode cmdLogin(Command_Login *cmd);
|
||||
virtual ResponseCode cmdDeckList(Command_DeckList *cmd) = 0;
|
||||
virtual ResponseCode cmdDeckNewDir(Command_DeckNewDir *cmd) = 0;
|
||||
virtual ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd) = 0;
|
||||
virtual ResponseCode cmdDeckDel(Command_DeckDel *cmd) = 0;
|
||||
virtual ResponseCode cmdDeckUpload(Command_DeckUpload *cmd) = 0;
|
||||
virtual ResponseCode cmdDeckDownload(Command_DeckDownload *cmd) = 0;
|
||||
ResponseCode cmdListChatChannels(Command_ListChatChannels *cmd);
|
||||
ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd);
|
||||
ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, Server_ChatChannel *channel);
|
||||
ResponseCode cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel);
|
||||
ResponseCode cmdListGames(Command_ListGames *cmd);
|
||||
ResponseCode cmdCreateGame(Command_CreateGame *cmd);
|
||||
ResponseCode cmdJoinGame(Command_JoinGame *cmd);
|
||||
ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdConcede(Command_Concede *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDeckSelect(Command_DeckSelect *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdMulligan(Command_Mulligan *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdPing(Command_Ping *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdLogin(Command_Login *cmd, CommandContainer *cont);
|
||||
virtual ResponseCode cmdDeckList(Command_DeckList *cmd, CommandContainer *cont) = 0;
|
||||
virtual ResponseCode cmdDeckNewDir(Command_DeckNewDir *cmd, CommandContainer *cont) = 0;
|
||||
virtual ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd, CommandContainer *cont) = 0;
|
||||
virtual ResponseCode cmdDeckDel(Command_DeckDel *cmd, CommandContainer *cont) = 0;
|
||||
virtual ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont) = 0;
|
||||
virtual ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont) = 0;
|
||||
ResponseCode cmdListChatChannels(Command_ListChatChannels *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, CommandContainer *cont, Server_ChatChannel *channel);
|
||||
ResponseCode cmdChatSay(Command_ChatSay *cmd, CommandContainer *cont, Server_ChatChannel *channel);
|
||||
ResponseCode cmdListGames(Command_ListGames *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdConcede(Command_Concede *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdReadyStart(Command_ReadyStart *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDeckSelect(Command_DeckSelect *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdSay(Command_Say *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdShuffle(Command_Shuffle *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdMulligan(Command_Mulligan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdRollDie(Command_RollDie *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
// XXX Maybe the following function and others belong into Server_Player
|
||||
ResponseCode drawCards(Server_Game *game, Server_Player *player, int number);
|
||||
ResponseCode cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDrawCards(Command_DrawCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode moveCard(Server_Game *game, Server_Player *player, const QString &_startZone, int _cardId, const QString &_targetZone, int _x, int _y, bool _faceDown);
|
||||
ResponseCode cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdCreateCounter(Command_CreateCounter *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdNextTurn(Command_NextTurn *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdMoveCard(Command_MoveCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdCreateToken(Command_CreateToken *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdIncCounter(Command_IncCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdCreateCounter(Command_CreateCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdSetCounter(Command_SetCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDelCounter(Command_DelCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdNextTurn(Command_NextTurn *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDumpZone(Command_DumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||
|
||||
void processCommandHelper(Command *command);
|
||||
ResponseCode processCommandHelper(Command *command, CommandContainer *cont);
|
||||
private slots:
|
||||
void pingClockTimeout();
|
||||
public:
|
||||
|
@ -86,7 +86,7 @@ public:
|
|||
const QString &getPlayerName() const { return playerName; }
|
||||
const QDateTime &getLastCommandTime() const { return lastCommandTime; }
|
||||
|
||||
void processCommand(Command *command);
|
||||
void processCommandContainer(CommandContainer *cont);
|
||||
virtual void sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0;
|
||||
void enqueueProtocolItem(ProtocolItem *item);
|
||||
};
|
||||
|
|
|
@ -91,7 +91,11 @@ CardInfo *OracleImporter::addCard(QString cardName, const QString &cardCost, con
|
|||
if (cardText.contains(cardName + " is green."))
|
||||
colors << "G";
|
||||
|
||||
card = new CardInfo(this, cardName, cardCost, cardType, cardPT, fullCardText, colors);
|
||||
bool cipt = (cardText.contains(cardName + " enters the battlefield tapped."));
|
||||
if (cipt)
|
||||
qDebug() << cardName;
|
||||
|
||||
card = new CardInfo(this, cardName, cardCost, cardType, cardPT, fullCardText, colors, cipt);
|
||||
card->setPicURL(getURLFromName(cardName));
|
||||
int tableRow = 1;
|
||||
QString mainCardType = card->getMainCardType();
|
||||
|
|
|
@ -60,11 +60,11 @@ ServerSocketInterface::~ServerSocketInterface()
|
|||
|
||||
void ServerSocketInterface::processProtocolItem(ProtocolItem *item)
|
||||
{
|
||||
Command *command = qobject_cast<Command *>(item);
|
||||
if (!command)
|
||||
sendProtocolItem(new ProtocolResponse(command->getCmdId(), RespInvalidCommand));
|
||||
CommandContainer *cont = qobject_cast<CommandContainer *>(item);
|
||||
if (!cont)
|
||||
sendProtocolItem(new ProtocolResponse(cont->getCmdId(), RespInvalidCommand));
|
||||
else
|
||||
processCommand(command);
|
||||
processCommandContainer(cont);
|
||||
}
|
||||
|
||||
void ServerSocketInterface::readClient()
|
||||
|
@ -159,7 +159,7 @@ bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder)
|
|||
// CHECK AUTHENTICATION!
|
||||
// Also check for every function that data belonging to other users cannot be accessed.
|
||||
|
||||
ResponseCode ServerSocketInterface::cmdDeckList(Command_DeckList *cmd)
|
||||
ResponseCode ServerSocketInterface::cmdDeckList(Command_DeckList * /*cmd*/, CommandContainer *cont)
|
||||
{
|
||||
if (authState != PasswordRight)
|
||||
return RespFunctionNotAllowed;
|
||||
|
@ -171,12 +171,12 @@ ResponseCode ServerSocketInterface::cmdDeckList(Command_DeckList *cmd)
|
|||
if (!deckListHelper(root))
|
||||
return RespContextError;
|
||||
|
||||
sendProtocolItem(new Response_DeckList(cmd->getCmdId(), RespOk, root));
|
||||
cont->setResponse(new Response_DeckList(cont->getCmdId(), RespOk, root));
|
||||
|
||||
return RespNothing;
|
||||
}
|
||||
|
||||
ResponseCode ServerSocketInterface::cmdDeckNewDir(Command_DeckNewDir *cmd)
|
||||
ResponseCode ServerSocketInterface::cmdDeckNewDir(Command_DeckNewDir *cmd, CommandContainer * /*cont*/)
|
||||
{
|
||||
if (authState != PasswordRight)
|
||||
return RespFunctionNotAllowed;
|
||||
|
@ -218,7 +218,7 @@ void ServerSocketInterface::deckDelDirHelper(int basePathId)
|
|||
servatrice->execSqlQuery(query);
|
||||
}
|
||||
|
||||
ResponseCode ServerSocketInterface::cmdDeckDelDir(Command_DeckDelDir *cmd)
|
||||
ResponseCode ServerSocketInterface::cmdDeckDelDir(Command_DeckDelDir *cmd, CommandContainer * /*cont*/)
|
||||
{
|
||||
if (authState != PasswordRight)
|
||||
return RespFunctionNotAllowed;
|
||||
|
@ -232,7 +232,7 @@ ResponseCode ServerSocketInterface::cmdDeckDelDir(Command_DeckDelDir *cmd)
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode ServerSocketInterface::cmdDeckDel(Command_DeckDel *cmd)
|
||||
ResponseCode ServerSocketInterface::cmdDeckDel(Command_DeckDel *cmd, CommandContainer * /*cont*/)
|
||||
{
|
||||
if (authState != PasswordRight)
|
||||
return RespFunctionNotAllowed;
|
||||
|
@ -255,7 +255,7 @@ ResponseCode ServerSocketInterface::cmdDeckDel(Command_DeckDel *cmd)
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd)
|
||||
ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont)
|
||||
{
|
||||
if (authState != PasswordRight)
|
||||
return RespFunctionNotAllowed;
|
||||
|
@ -286,7 +286,7 @@ ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd)
|
|||
query.bindValue(":content", deckContents);
|
||||
servatrice->execSqlQuery(query);
|
||||
|
||||
sendProtocolItem(new Response_DeckUpload(cmd->getCmdId(), RespOk, new DeckList_File(deckName, query.lastInsertId().toInt(), QDateTime::currentDateTime())));
|
||||
cont->setResponse(new Response_DeckUpload(cont->getCmdId(), RespOk, new DeckList_File(deckName, query.lastInsertId().toInt(), QDateTime::currentDateTime())));
|
||||
return RespNothing;
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,7 @@ DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId)
|
|||
return deck;
|
||||
}
|
||||
|
||||
ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd)
|
||||
ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont)
|
||||
{
|
||||
if (authState != PasswordRight)
|
||||
return RespFunctionNotAllowed;
|
||||
|
@ -321,6 +321,6 @@ ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd)
|
|||
} catch(ResponseCode r) {
|
||||
return r;
|
||||
}
|
||||
sendProtocolItem(new Response_DeckDownload(cmd->getCmdId(), RespOk, deck));
|
||||
cont->setResponse(new Response_DeckDownload(cont->getCmdId(), RespOk, deck));
|
||||
return RespNothing;
|
||||
}
|
||||
|
|
|
@ -47,14 +47,14 @@ private:
|
|||
int getDeckPathId(int basePathId, QStringList path);
|
||||
int getDeckPathId(const QString &path);
|
||||
bool deckListHelper(DeckList_Directory *folder);
|
||||
ResponseCode cmdDeckList(Command_DeckList *cmd);
|
||||
ResponseCode cmdDeckNewDir(Command_DeckNewDir *cmd);
|
||||
ResponseCode cmdDeckList(Command_DeckList *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdDeckNewDir(Command_DeckNewDir *cmd, CommandContainer *cont);
|
||||
void deckDelDirHelper(int basePathId);
|
||||
ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd);
|
||||
ResponseCode cmdDeckDel(Command_DeckDel *cmd);
|
||||
ResponseCode cmdDeckUpload(Command_DeckUpload *cmd);
|
||||
ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdDeckDel(Command_DeckDel *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont);
|
||||
DeckList *getDeckFromDatabase(int deckId);
|
||||
ResponseCode cmdDeckDownload(Command_DeckDownload *cmd);
|
||||
ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont);
|
||||
public:
|
||||
ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent = 0);
|
||||
~ServerSocketInterface();
|
||||
|
|
Loading…
Reference in a new issue