Commit 888a64b0 authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

new protocol code

parent ba8d4021
This diff is collapsed.
...@@ -32,48 +32,48 @@ private: ...@@ -32,48 +32,48 @@ private:
virtual DeckList *getDeckFromDatabase(int deckId) = 0; virtual DeckList *getDeckFromDatabase(int deckId) = 0;
ResponseCode cmdPing(Command_Ping *cmd); ResponseCode cmdPing(Command_Ping *cmd, CommandContainer *cont);
ResponseCode cmdLogin(Command_Login *cmd); ResponseCode cmdLogin(Command_Login *cmd, CommandContainer *cont);
virtual ResponseCode cmdDeckList(Command_DeckList *cmd) = 0; virtual ResponseCode cmdDeckList(Command_DeckList *cmd, CommandContainer *cont) = 0;
virtual ResponseCode cmdDeckNewDir(Command_DeckNewDir *cmd) = 0; virtual ResponseCode cmdDeckNewDir(Command_DeckNewDir *cmd, CommandContainer *cont) = 0;
virtual ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd) = 0; virtual ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd, CommandContainer *cont) = 0;
virtual ResponseCode cmdDeckDel(Command_DeckDel *cmd) = 0; virtual ResponseCode cmdDeckDel(Command_DeckDel *cmd, CommandContainer *cont) = 0;
virtual ResponseCode cmdDeckUpload(Command_DeckUpload *cmd) = 0; virtual ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont) = 0;
virtual ResponseCode cmdDeckDownload(Command_DeckDownload *cmd) = 0; virtual ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont) = 0;
ResponseCode cmdListChatChannels(Command_ListChatChannels *cmd); ResponseCode cmdListChatChannels(Command_ListChatChannels *cmd, CommandContainer *cont);
ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd); ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd, CommandContainer *cont);
ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, Server_ChatChannel *channel); ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, CommandContainer *cont, Server_ChatChannel *channel);
ResponseCode cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel); ResponseCode cmdChatSay(Command_ChatSay *cmd, CommandContainer *cont, Server_ChatChannel *channel);
ResponseCode cmdListGames(Command_ListGames *cmd); ResponseCode cmdListGames(Command_ListGames *cmd, CommandContainer *cont);
ResponseCode cmdCreateGame(Command_CreateGame *cmd); ResponseCode cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont);
ResponseCode cmdJoinGame(Command_JoinGame *cmd); ResponseCode cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont);
ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdConcede(Command_Concede *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdConcede(Command_Concede *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdReadyStart(Command_ReadyStart *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdDeckSelect(Command_DeckSelect *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdDeckSelect(Command_DeckSelect *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdSay(Command_Say *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdShuffle(Command_Shuffle *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdMulligan(Command_Mulligan *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdMulligan(Command_Mulligan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdRollDie(Command_RollDie *cmd, 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 // XXX Maybe the following function and others belong into Server_Player
ResponseCode drawCards(Server_Game *game, Server_Player *player, int number); 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 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 cmdMoveCard(Command_MoveCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdCreateToken(Command_CreateToken *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdIncCounter(Command_IncCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdCreateCounter(Command_CreateCounter *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdCreateCounter(Command_CreateCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdSetCounter(Command_SetCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdDelCounter(Command_DelCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdNextTurn(Command_NextTurn *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdNextTurn(Command_NextTurn *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player); ResponseCode cmdDumpZone(Command_DumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, 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: private slots:
void pingClockTimeout(); void pingClockTimeout();
public: public:
...@@ -86,7 +86,7 @@ public: ...@@ -86,7 +86,7 @@ public:
const QString &getPlayerName() const { return playerName; } const QString &getPlayerName() const { return playerName; }
const QDateTime &getLastCommandTime() const { return lastCommandTime; } const QDateTime &getLastCommandTime() const { return lastCommandTime; }
void processCommand(Command *command); void processCommandContainer(CommandContainer *cont);
virtual void sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0; virtual void sendProtocolItem(ProtocolItem *item, bool deleteItem = true) = 0;
void enqueueProtocolItem(ProtocolItem *item); void enqueueProtocolItem(ProtocolItem *item);
}; };
......
...@@ -91,7 +91,11 @@ CardInfo *OracleImporter::addCard(QString cardName, const QString &cardCost, con ...@@ -91,7 +91,11 @@ CardInfo *OracleImporter::addCard(QString cardName, const QString &cardCost, con
if (cardText.contains(cardName + " is green.")) if (cardText.contains(cardName + " is green."))
colors << "G"; 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)); card->setPicURL(getURLFromName(cardName));
int tableRow = 1; int tableRow = 1;
QString mainCardType = card->getMainCardType(); QString mainCardType = card->getMainCardType();
......
...@@ -60,11 +60,11 @@ ServerSocketInterface::~ServerSocketInterface() ...@@ -60,11 +60,11 @@ ServerSocketInterface::~ServerSocketInterface()
void ServerSocketInterface::processProtocolItem(ProtocolItem *item) void ServerSocketInterface::processProtocolItem(ProtocolItem *item)
{ {
Command *command = qobject_cast<Command *>(item); CommandContainer *cont = qobject_cast<CommandContainer *>(item);
if (!command) if (!cont)
sendProtocolItem(new ProtocolResponse(command->getCmdId(), RespInvalidCommand)); sendProtocolItem(new ProtocolResponse(cont->getCmdId(), RespInvalidCommand));
else else
processCommand(command); processCommandContainer(cont);
} }
void ServerSocketInterface::readClient() void ServerSocketInterface::readClient()
...@@ -159,7 +159,7 @@ bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder) ...@@ -159,7 +159,7 @@ bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder)
// CHECK AUTHENTICATION! // CHECK AUTHENTICATION!
// Also check for every function that data belonging to other users cannot be accessed. // 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) if (authState != PasswordRight)
return RespFunctionNotAllowed; return RespFunctionNotAllowed;
...@@ -171,12 +171,12 @@ ResponseCode ServerSocketInterface::cmdDeckList(Command_DeckList *cmd) ...@@ -171,12 +171,12 @@ ResponseCode ServerSocketInterface::cmdDeckList(Command_DeckList *cmd)
if (!deckListHelper(root)) if (!deckListHelper(root))
return RespContextError; return RespContextError;
sendProtocolItem(new Response_DeckList(cmd->getCmdId(), RespOk, root)); cont->setResponse(new Response_DeckList(cont->getCmdId(), RespOk, root));
return RespNothing; return RespNothing;
} }
ResponseCode ServerSocketInterface::cmdDeckNewDir(Command_DeckNewDir *cmd) ResponseCode ServerSocketInterface::cmdDeckNewDir(Command_DeckNewDir *cmd, CommandContainer * /*cont*/)
{ {
if (authState != PasswordRight) if (authState != PasswordRight)
return RespFunctionNotAllowed; return RespFunctionNotAllowed;
...@@ -218,7 +218,7 @@ void ServerSocketInterface::deckDelDirHelper(int basePathId) ...@@ -218,7 +218,7 @@ void ServerSocketInterface::deckDelDirHelper(int basePathId)
servatrice->execSqlQuery(query); servatrice->execSqlQuery(query);
} }
ResponseCode ServerSocketInterface::cmdDeckDelDir(Command_DeckDelDir *cmd) ResponseCode ServerSocketInterface::cmdDeckDelDir(Command_DeckDelDir *cmd, CommandContainer * /*cont*/)
{ {
if (authState != PasswordRight) if (authState != PasswordRight)
return RespFunctionNotAllowed; return RespFunctionNotAllowed;
...@@ -232,7 +232,7 @@ ResponseCode ServerSocketInterface::cmdDeckDelDir(Command_DeckDelDir *cmd) ...@@ -232,7 +232,7 @@ ResponseCode ServerSocketInterface::cmdDeckDelDir(Command_DeckDelDir *cmd)
return RespOk; return RespOk;
} }
ResponseCode ServerSocketInterface::cmdDeckDel(Command_DeckDel *cmd) ResponseCode ServerSocketInterface::cmdDeckDel(Command_DeckDel *cmd, CommandContainer * /*cont*/)
{ {
if (authState != PasswordRight) if (authState != PasswordRight)
return RespFunctionNotAllowed; return RespFunctionNotAllowed;
...@@ -255,7 +255,7 @@ ResponseCode ServerSocketInterface::cmdDeckDel(Command_DeckDel *cmd) ...@@ -255,7 +255,7 @@ ResponseCode ServerSocketInterface::cmdDeckDel(Command_DeckDel *cmd)
return RespOk; return RespOk;
} }
ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd) ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont)
{ {
if (authState != PasswordRight) if (authState != PasswordRight)
return RespFunctionNotAllowed; return RespFunctionNotAllowed;
...@@ -286,7 +286,7 @@ ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd) ...@@ -286,7 +286,7 @@ ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd)
query.bindValue(":content", deckContents); query.bindValue(":content", deckContents);
servatrice->execSqlQuery(query); 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; return RespNothing;
} }
...@@ -310,7 +310,7 @@ DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId) ...@@ -310,7 +310,7 @@ DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId)
return deck; return deck;
} }
ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd) ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont)
{ {
if (authState != PasswordRight) if (authState != PasswordRight)
return RespFunctionNotAllowed; return RespFunctionNotAllowed;
...@@ -321,6 +321,6 @@ ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd) ...@@ -321,6 +321,6 @@ ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd)
} catch(ResponseCode r) { } catch(ResponseCode r) {
return r; return r;
} }
sendProtocolItem(new Response_DeckDownload(cmd->getCmdId(), RespOk, deck)); cont->setResponse(new Response_DeckDownload(cont->getCmdId(), RespOk, deck));
return RespNothing; return RespNothing;
} }
...@@ -47,14 +47,14 @@ private: ...@@ -47,14 +47,14 @@ private:
int getDeckPathId(int basePathId, QStringList path); int getDeckPathId(int basePathId, QStringList path);
int getDeckPathId(const QString &path); int getDeckPathId(const QString &path);
bool deckListHelper(DeckList_Directory *folder); bool deckListHelper(DeckList_Directory *folder);
ResponseCode cmdDeckList(Command_DeckList *cmd); ResponseCode cmdDeckList(Command_DeckList *cmd, CommandContainer *cont);
ResponseCode cmdDeckNewDir(Command_DeckNewDir *cmd); ResponseCode cmdDeckNewDir(Command_DeckNewDir *cmd, CommandContainer *cont);
void deckDelDirHelper(int basePathId); void deckDelDirHelper(int basePathId);
ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd); ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd, CommandContainer *cont);
ResponseCode cmdDeckDel(Command_DeckDel *cmd); ResponseCode cmdDeckDel(Command_DeckDel *cmd, CommandContainer *cont);
ResponseCode cmdDeckUpload(Command_DeckUpload *cmd); ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont);
DeckList *getDeckFromDatabase(int deckId); DeckList *getDeckFromDatabase(int deckId);
ResponseCode cmdDeckDownload(Command_DeckDownload *cmd); ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont);
public: public:
ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent = 0); ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent = 0);
~ServerSocketInterface(); ~ServerSocketInterface();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment