some server code
This commit is contained in:
parent
6923c98dc2
commit
29bf3d3774
18 changed files with 729 additions and 137 deletions
|
@ -22,7 +22,6 @@ bool ProtocolItem::read(QXmlStreamReader *xml)
|
||||||
if (xml->name() == getItemType()) {
|
if (xml->name() == getItemType()) {
|
||||||
extractParameters();
|
extractParameters();
|
||||||
qDebug() << "FERTIG";
|
qDebug() << "FERTIG";
|
||||||
deleteLater();
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
QString tagName = xml->name().toString();
|
QString tagName = xml->name().toString();
|
||||||
|
@ -111,6 +110,7 @@ void ProtocolResponse::extractParameters()
|
||||||
void ProtocolResponse::initializeHash()
|
void ProtocolResponse::initializeHash()
|
||||||
{
|
{
|
||||||
responseHash.insert("ok", RespOk);
|
responseHash.insert("ok", RespOk);
|
||||||
|
responseHash.insert("invalid_command", RespInvalidCommand);
|
||||||
responseHash.insert("name_not_found", RespNameNotFound);
|
responseHash.insert("name_not_found", RespNameNotFound);
|
||||||
responseHash.insert("login_needed", RespLoginNeeded);
|
responseHash.insert("login_needed", RespLoginNeeded);
|
||||||
responseHash.insert("context_error", RespContextError);
|
responseHash.insert("context_error", RespContextError);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include "protocol_item_ids.h"
|
||||||
|
|
||||||
class QXmlStreamReader;
|
class QXmlStreamReader;
|
||||||
class QXmlStreamWriter;
|
class QXmlStreamWriter;
|
||||||
|
@ -29,6 +30,7 @@ private:
|
||||||
static void initializeHashAuto();
|
static void initializeHashAuto();
|
||||||
public:
|
public:
|
||||||
static const int protocolVersion = 4;
|
static const int protocolVersion = 4;
|
||||||
|
virtual int getItemId() const = 0;
|
||||||
ProtocolItem(const QString &_itemName);
|
ProtocolItem(const QString &_itemName);
|
||||||
static void initializeHash();
|
static void initializeHash();
|
||||||
static ProtocolItem *getNewItem(const QString &name);
|
static ProtocolItem *getNewItem(const QString &name);
|
||||||
|
@ -45,7 +47,15 @@ protected:
|
||||||
QString getItemType() const { return "cmd"; }
|
QString getItemType() const { return "cmd"; }
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
public:
|
public:
|
||||||
Command(const QString &_itemName, int _cmdId = -1);
|
Command(const QString &_itemName = QString(), int _cmdId = -1);
|
||||||
|
int getCmdId() const { return cmdId; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class InvalidCommand : public Command {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
InvalidCommand() : Command() { }
|
||||||
|
int getItemId() const { return ItemId_Other; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class ChatCommand : public Command {
|
class ChatCommand : public Command {
|
||||||
|
@ -87,7 +97,7 @@ public:
|
||||||
class ProtocolResponse : public ProtocolItem {
|
class ProtocolResponse : public ProtocolItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum ResponseCode { RespOk, RespNameNotFound, RespLoginNeeded, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed };
|
enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespNameNotFound, RespLoginNeeded, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed };
|
||||||
private:
|
private:
|
||||||
int cmdId;
|
int cmdId;
|
||||||
ResponseCode responseCode;
|
ResponseCode responseCode;
|
||||||
|
@ -97,6 +107,7 @@ protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
public:
|
public:
|
||||||
ProtocolResponse(int _cmdId = -1, ResponseCode _responseCode = RespOk);
|
ProtocolResponse(int _cmdId = -1, ResponseCode _responseCode = RespOk);
|
||||||
|
int getItemId() const { return ItemId_Other; }
|
||||||
static void initializeHash();
|
static void initializeHash();
|
||||||
static ProtocolItem *newItem() { return new ProtocolResponse; }
|
static ProtocolItem *newItem() { return new ProtocolResponse; }
|
||||||
};
|
};
|
||||||
|
|
55
common/protocol_item_ids.h
Normal file
55
common/protocol_item_ids.h
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
enum AutoItemId {
|
||||||
|
ItemId_Command_Ping = 1001,
|
||||||
|
ItemId_Command_Login = 1002,
|
||||||
|
ItemId_Command_ChatListChannels = 1003,
|
||||||
|
ItemId_Command_ChatJoinChannel = 1004,
|
||||||
|
ItemId_Command_ChatLeaveChannel = 1005,
|
||||||
|
ItemId_Command_ChatSay = 1006,
|
||||||
|
ItemId_Command_ListGames = 1007,
|
||||||
|
ItemId_Command_CreateGame = 1008,
|
||||||
|
ItemId_Command_JoinGame = 1009,
|
||||||
|
ItemId_Command_LeaveGame = 1010,
|
||||||
|
ItemId_Command_Say = 1011,
|
||||||
|
ItemId_Command_Shuffle = 1012,
|
||||||
|
ItemId_Command_RollDie = 1013,
|
||||||
|
ItemId_Command_DrawCards = 1014,
|
||||||
|
ItemId_Command_MoveCard = 1015,
|
||||||
|
ItemId_Command_CreateToken = 1016,
|
||||||
|
ItemId_Command_CreateArrow = 1017,
|
||||||
|
ItemId_Command_DeleteArrow = 1018,
|
||||||
|
ItemId_Command_SetCardAttr = 1019,
|
||||||
|
ItemId_Command_ReadyStart = 1020,
|
||||||
|
ItemId_Command_IncCounter = 1021,
|
||||||
|
ItemId_Command_AddCounter = 1022,
|
||||||
|
ItemId_Command_SetCounter = 1023,
|
||||||
|
ItemId_Command_DelCounter = 1024,
|
||||||
|
ItemId_Command_NextTurn = 1025,
|
||||||
|
ItemId_Command_SetActivePhase = 1026,
|
||||||
|
ItemId_Command_DumpZone = 1027,
|
||||||
|
ItemId_Command_StopDumpZone = 1028,
|
||||||
|
ItemId_Command_DumpAll = 1029,
|
||||||
|
ItemId_Command_SubmitDeck = 1030,
|
||||||
|
ItemId_Event_Say = 1031,
|
||||||
|
ItemId_Event_Join = 1032,
|
||||||
|
ItemId_Event_Leave = 1033,
|
||||||
|
ItemId_Event_GameClosed = 1034,
|
||||||
|
ItemId_Event_ReadyStart = 1035,
|
||||||
|
ItemId_Event_SetupZones = 1036,
|
||||||
|
ItemId_Event_GameStart = 1037,
|
||||||
|
ItemId_Event_Shuffle = 1038,
|
||||||
|
ItemId_Event_RollDie = 1039,
|
||||||
|
ItemId_Event_MoveCard = 1040,
|
||||||
|
ItemId_Event_CreateToken = 1041,
|
||||||
|
ItemId_Event_CreateArrow = 1042,
|
||||||
|
ItemId_Event_DeleteArrow = 1043,
|
||||||
|
ItemId_Event_SetCardAttr = 1044,
|
||||||
|
ItemId_Event_AddCounter = 1045,
|
||||||
|
ItemId_Event_SetCounter = 1046,
|
||||||
|
ItemId_Event_DelCounter = 1047,
|
||||||
|
ItemId_Event_SetActivePlayer = 1048,
|
||||||
|
ItemId_Event_SetActivePhase = 1049,
|
||||||
|
ItemId_Event_DumpZone = 1050,
|
||||||
|
ItemId_Event_StopDumpZone = 1051,
|
||||||
|
ItemId_Event_Welcome = 1052,
|
||||||
|
ItemId_Other = 1053
|
||||||
|
};
|
|
@ -137,11 +137,11 @@ void Command_MoveCard::extractParameters()
|
||||||
y = parameters["y"].toInt();
|
y = parameters["y"].toInt();
|
||||||
faceDown = (parameters["face_down"] == "1");
|
faceDown = (parameters["face_down"] == "1");
|
||||||
}
|
}
|
||||||
Command_CreateToken::Command_CreateToken(int _gameId, const QString &_zone, const QString &_name, const QString &_pt, int _x, int _y)
|
Command_CreateToken::Command_CreateToken(int _gameId, const QString &_zone, const QString &_cardName, const QString &_pt, int _x, int _y)
|
||||||
: GameCommand("create_token", _gameId), zone(_zone), name(_name), pt(_pt), x(_x), y(_y)
|
: GameCommand("create_token", _gameId), zone(_zone), cardName(_cardName), pt(_pt), x(_x), y(_y)
|
||||||
{
|
{
|
||||||
setParameter("zone", zone);
|
setParameter("zone", zone);
|
||||||
setParameter("name", name);
|
setParameter("card_name", cardName);
|
||||||
setParameter("pt", pt);
|
setParameter("pt", pt);
|
||||||
setParameter("x", x);
|
setParameter("x", x);
|
||||||
setParameter("y", y);
|
setParameter("y", y);
|
||||||
|
@ -150,19 +150,19 @@ void Command_CreateToken::extractParameters()
|
||||||
{
|
{
|
||||||
GameCommand::extractParameters();
|
GameCommand::extractParameters();
|
||||||
zone = parameters["zone"];
|
zone = parameters["zone"];
|
||||||
name = parameters["name"];
|
cardName = parameters["card_name"];
|
||||||
pt = parameters["pt"];
|
pt = parameters["pt"];
|
||||||
x = parameters["x"].toInt();
|
x = parameters["x"].toInt();
|
||||||
y = parameters["y"].toInt();
|
y = parameters["y"].toInt();
|
||||||
}
|
}
|
||||||
Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetPlayerZone, int _targetCardId, int _color)
|
Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, int _color)
|
||||||
: GameCommand("create_arrow", _gameId), startPlayerId(_startPlayerId), startZone(_startZone), startCardId(_startCardId), targetPlayerId(_targetPlayerId), targetPlayerZone(_targetPlayerZone), targetCardId(_targetCardId), color(_color)
|
: GameCommand("create_arrow", _gameId), startPlayerId(_startPlayerId), startZone(_startZone), startCardId(_startCardId), targetPlayerId(_targetPlayerId), targetZone(_targetZone), targetCardId(_targetCardId), color(_color)
|
||||||
{
|
{
|
||||||
setParameter("start_player_id", startPlayerId);
|
setParameter("start_player_id", startPlayerId);
|
||||||
setParameter("start_zone", startZone);
|
setParameter("start_zone", startZone);
|
||||||
setParameter("start_card_id", startCardId);
|
setParameter("start_card_id", startCardId);
|
||||||
setParameter("target_player_id", targetPlayerId);
|
setParameter("target_player_id", targetPlayerId);
|
||||||
setParameter("target_player_zone", targetPlayerZone);
|
setParameter("target_zone", targetZone);
|
||||||
setParameter("target_card_id", targetCardId);
|
setParameter("target_card_id", targetCardId);
|
||||||
setParameter("color", color);
|
setParameter("color", color);
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ void Command_CreateArrow::extractParameters()
|
||||||
startZone = parameters["start_zone"];
|
startZone = parameters["start_zone"];
|
||||||
startCardId = parameters["start_card_id"].toInt();
|
startCardId = parameters["start_card_id"].toInt();
|
||||||
targetPlayerId = parameters["target_player_id"].toInt();
|
targetPlayerId = parameters["target_player_id"].toInt();
|
||||||
targetPlayerZone = parameters["target_player_zone"];
|
targetZone = parameters["target_zone"];
|
||||||
targetCardId = parameters["target_card_id"].toInt();
|
targetCardId = parameters["target_card_id"].toInt();
|
||||||
color = parameters["color"].toInt();
|
color = parameters["color"].toInt();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
2:roll_die:i,sides
|
2:roll_die:i,sides
|
||||||
2:draw_cards:i,number
|
2:draw_cards:i,number
|
||||||
2:move_card:s,start_zone:i,card_id:s,target_zone:i,x:i,y:b,face_down
|
2:move_card:s,start_zone:i,card_id:s,target_zone:i,x:i,y:b,face_down
|
||||||
2:create_token:s,zone:s,name:s,pt:i,x:i,y
|
2:create_token:s,zone:s,card_name:s,pt:i,x:i,y
|
||||||
2:create_arrow:i,start_player_id:s,start_zone:i,start_card_id:i,target_player_id:s,target_player_zone:i,target_card_id:i,color
|
2:create_arrow:i,start_player_id:s,start_zone:i,start_card_id:i,target_player_id:s,target_zone:i,target_card_id:i,color
|
||||||
2:delete_arrow:i,arrow_id
|
2:delete_arrow:i,arrow_id
|
||||||
2:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value
|
2:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value
|
||||||
2:ready_start
|
2:ready_start
|
||||||
|
|
|
@ -9,6 +9,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Command_Ping();
|
Command_Ping();
|
||||||
static ProtocolItem *newItem() { return new Command_Ping; }
|
static ProtocolItem *newItem() { return new Command_Ping; }
|
||||||
|
int getItemId() const { return ItemId_Command_Ping; }
|
||||||
};
|
};
|
||||||
class Command_Login : public Command {
|
class Command_Login : public Command {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -20,6 +21,7 @@ public:
|
||||||
QString getUsername() const { return username; }
|
QString getUsername() const { return username; }
|
||||||
QString getPassword() const { return password; }
|
QString getPassword() const { return password; }
|
||||||
static ProtocolItem *newItem() { return new Command_Login; }
|
static ProtocolItem *newItem() { return new Command_Login; }
|
||||||
|
int getItemId() const { return ItemId_Command_Login; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -29,6 +31,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Command_ChatListChannels();
|
Command_ChatListChannels();
|
||||||
static ProtocolItem *newItem() { return new Command_ChatListChannels; }
|
static ProtocolItem *newItem() { return new Command_ChatListChannels; }
|
||||||
|
int getItemId() const { return ItemId_Command_ChatListChannels; }
|
||||||
};
|
};
|
||||||
class Command_ChatJoinChannel : public Command {
|
class Command_ChatJoinChannel : public Command {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -38,6 +41,7 @@ public:
|
||||||
Command_ChatJoinChannel(const QString &_channel = QString());
|
Command_ChatJoinChannel(const QString &_channel = QString());
|
||||||
QString getChannel() const { return channel; }
|
QString getChannel() const { return channel; }
|
||||||
static ProtocolItem *newItem() { return new Command_ChatJoinChannel; }
|
static ProtocolItem *newItem() { return new Command_ChatJoinChannel; }
|
||||||
|
int getItemId() const { return ItemId_Command_ChatJoinChannel; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -47,6 +51,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Command_ChatLeaveChannel(const QString &_channel = QString());
|
Command_ChatLeaveChannel(const QString &_channel = QString());
|
||||||
static ProtocolItem *newItem() { return new Command_ChatLeaveChannel; }
|
static ProtocolItem *newItem() { return new Command_ChatLeaveChannel; }
|
||||||
|
int getItemId() const { return ItemId_Command_ChatLeaveChannel; }
|
||||||
};
|
};
|
||||||
class Command_ChatSay : public ChatCommand {
|
class Command_ChatSay : public ChatCommand {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -56,6 +61,7 @@ public:
|
||||||
Command_ChatSay(const QString &_channel = QString(), const QString &_message = QString());
|
Command_ChatSay(const QString &_channel = QString(), const QString &_message = QString());
|
||||||
QString getMessage() const { return message; }
|
QString getMessage() const { return message; }
|
||||||
static ProtocolItem *newItem() { return new Command_ChatSay; }
|
static ProtocolItem *newItem() { return new Command_ChatSay; }
|
||||||
|
int getItemId() const { return ItemId_Command_ChatSay; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -65,6 +71,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Command_ListGames();
|
Command_ListGames();
|
||||||
static ProtocolItem *newItem() { return new Command_ListGames; }
|
static ProtocolItem *newItem() { return new Command_ListGames; }
|
||||||
|
int getItemId() const { return ItemId_Command_ListGames; }
|
||||||
};
|
};
|
||||||
class Command_CreateGame : public Command {
|
class Command_CreateGame : public Command {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -80,6 +87,7 @@ public:
|
||||||
int getMaxPlayers() const { return maxPlayers; }
|
int getMaxPlayers() const { return maxPlayers; }
|
||||||
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
||||||
static ProtocolItem *newItem() { return new Command_CreateGame; }
|
static ProtocolItem *newItem() { return new Command_CreateGame; }
|
||||||
|
int getItemId() const { return ItemId_Command_CreateGame; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -95,6 +103,7 @@ public:
|
||||||
QString getPassword() const { return password; }
|
QString getPassword() const { return password; }
|
||||||
bool getSpectator() const { return spectator; }
|
bool getSpectator() const { return spectator; }
|
||||||
static ProtocolItem *newItem() { return new Command_JoinGame; }
|
static ProtocolItem *newItem() { return new Command_JoinGame; }
|
||||||
|
int getItemId() const { return ItemId_Command_JoinGame; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -104,6 +113,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Command_LeaveGame(int _gameId = -1);
|
Command_LeaveGame(int _gameId = -1);
|
||||||
static ProtocolItem *newItem() { return new Command_LeaveGame; }
|
static ProtocolItem *newItem() { return new Command_LeaveGame; }
|
||||||
|
int getItemId() const { return ItemId_Command_LeaveGame; }
|
||||||
};
|
};
|
||||||
class Command_Say : public GameCommand {
|
class Command_Say : public GameCommand {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -113,6 +123,7 @@ public:
|
||||||
Command_Say(int _gameId = -1, const QString &_message = QString());
|
Command_Say(int _gameId = -1, const QString &_message = QString());
|
||||||
QString getMessage() const { return message; }
|
QString getMessage() const { return message; }
|
||||||
static ProtocolItem *newItem() { return new Command_Say; }
|
static ProtocolItem *newItem() { return new Command_Say; }
|
||||||
|
int getItemId() const { return ItemId_Command_Say; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -122,6 +133,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Command_Shuffle(int _gameId = -1);
|
Command_Shuffle(int _gameId = -1);
|
||||||
static ProtocolItem *newItem() { return new Command_Shuffle; }
|
static ProtocolItem *newItem() { return new Command_Shuffle; }
|
||||||
|
int getItemId() const { return ItemId_Command_Shuffle; }
|
||||||
};
|
};
|
||||||
class Command_RollDie : public GameCommand {
|
class Command_RollDie : public GameCommand {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -131,6 +143,7 @@ public:
|
||||||
Command_RollDie(int _gameId = -1, int _sides = -1);
|
Command_RollDie(int _gameId = -1, int _sides = -1);
|
||||||
int getSides() const { return sides; }
|
int getSides() const { return sides; }
|
||||||
static ProtocolItem *newItem() { return new Command_RollDie; }
|
static ProtocolItem *newItem() { return new Command_RollDie; }
|
||||||
|
int getItemId() const { return ItemId_Command_RollDie; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -142,6 +155,7 @@ public:
|
||||||
Command_DrawCards(int _gameId = -1, int _number = -1);
|
Command_DrawCards(int _gameId = -1, int _number = -1);
|
||||||
int getNumber() const { return number; }
|
int getNumber() const { return number; }
|
||||||
static ProtocolItem *newItem() { return new Command_DrawCards; }
|
static ProtocolItem *newItem() { return new Command_DrawCards; }
|
||||||
|
int getItemId() const { return ItemId_Command_DrawCards; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -163,6 +177,7 @@ public:
|
||||||
int getY() const { return y; }
|
int getY() const { return y; }
|
||||||
bool getFaceDown() const { return faceDown; }
|
bool getFaceDown() const { return faceDown; }
|
||||||
static ProtocolItem *newItem() { return new Command_MoveCard; }
|
static ProtocolItem *newItem() { return new Command_MoveCard; }
|
||||||
|
int getItemId() const { return ItemId_Command_MoveCard; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -170,18 +185,19 @@ class Command_CreateToken : public GameCommand {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QString zone;
|
QString zone;
|
||||||
QString name;
|
QString cardName;
|
||||||
QString pt;
|
QString pt;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
public:
|
public:
|
||||||
Command_CreateToken(int _gameId = -1, const QString &_zone = QString(), const QString &_name = QString(), const QString &_pt = QString(), int _x = -1, int _y = -1);
|
Command_CreateToken(int _gameId = -1, const QString &_zone = QString(), const QString &_cardName = QString(), const QString &_pt = QString(), int _x = -1, int _y = -1);
|
||||||
QString getZone() const { return zone; }
|
QString getZone() const { return zone; }
|
||||||
QString getName() const { return name; }
|
QString getCardName() const { return cardName; }
|
||||||
QString getPt() const { return pt; }
|
QString getPt() const { return pt; }
|
||||||
int getX() const { return x; }
|
int getX() const { return x; }
|
||||||
int getY() const { return y; }
|
int getY() const { return y; }
|
||||||
static ProtocolItem *newItem() { return new Command_CreateToken; }
|
static ProtocolItem *newItem() { return new Command_CreateToken; }
|
||||||
|
int getItemId() const { return ItemId_Command_CreateToken; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -192,19 +208,20 @@ private:
|
||||||
QString startZone;
|
QString startZone;
|
||||||
int startCardId;
|
int startCardId;
|
||||||
int targetPlayerId;
|
int targetPlayerId;
|
||||||
QString targetPlayerZone;
|
QString targetZone;
|
||||||
int targetCardId;
|
int targetCardId;
|
||||||
int color;
|
int color;
|
||||||
public:
|
public:
|
||||||
Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetPlayerZone = QString(), int _targetCardId = -1, int _color = -1);
|
Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, int _color = -1);
|
||||||
int getStartPlayerId() const { return startPlayerId; }
|
int getStartPlayerId() const { return startPlayerId; }
|
||||||
QString getStartZone() const { return startZone; }
|
QString getStartZone() const { return startZone; }
|
||||||
int getStartCardId() const { return startCardId; }
|
int getStartCardId() const { return startCardId; }
|
||||||
int getTargetPlayerId() const { return targetPlayerId; }
|
int getTargetPlayerId() const { return targetPlayerId; }
|
||||||
QString getTargetPlayerZone() const { return targetPlayerZone; }
|
QString getTargetZone() const { return targetZone; }
|
||||||
int getTargetCardId() const { return targetCardId; }
|
int getTargetCardId() const { return targetCardId; }
|
||||||
int getColor() const { return color; }
|
int getColor() const { return color; }
|
||||||
static ProtocolItem *newItem() { return new Command_CreateArrow; }
|
static ProtocolItem *newItem() { return new Command_CreateArrow; }
|
||||||
|
int getItemId() const { return ItemId_Command_CreateArrow; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -216,6 +233,7 @@ public:
|
||||||
Command_DeleteArrow(int _gameId = -1, int _arrowId = -1);
|
Command_DeleteArrow(int _gameId = -1, int _arrowId = -1);
|
||||||
int getArrowId() const { return arrowId; }
|
int getArrowId() const { return arrowId; }
|
||||||
static ProtocolItem *newItem() { return new Command_DeleteArrow; }
|
static ProtocolItem *newItem() { return new Command_DeleteArrow; }
|
||||||
|
int getItemId() const { return ItemId_Command_DeleteArrow; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -233,6 +251,7 @@ public:
|
||||||
QString getAttrName() const { return attrName; }
|
QString getAttrName() const { return attrName; }
|
||||||
QString getAttrValue() const { return attrValue; }
|
QString getAttrValue() const { return attrValue; }
|
||||||
static ProtocolItem *newItem() { return new Command_SetCardAttr; }
|
static ProtocolItem *newItem() { return new Command_SetCardAttr; }
|
||||||
|
int getItemId() const { return ItemId_Command_SetCardAttr; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -242,6 +261,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Command_ReadyStart(int _gameId = -1);
|
Command_ReadyStart(int _gameId = -1);
|
||||||
static ProtocolItem *newItem() { return new Command_ReadyStart; }
|
static ProtocolItem *newItem() { return new Command_ReadyStart; }
|
||||||
|
int getItemId() const { return ItemId_Command_ReadyStart; }
|
||||||
};
|
};
|
||||||
class Command_IncCounter : public GameCommand {
|
class Command_IncCounter : public GameCommand {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -253,6 +273,7 @@ public:
|
||||||
int getCounterId() const { return counterId; }
|
int getCounterId() const { return counterId; }
|
||||||
int getDelta() const { return delta; }
|
int getDelta() const { return delta; }
|
||||||
static ProtocolItem *newItem() { return new Command_IncCounter; }
|
static ProtocolItem *newItem() { return new Command_IncCounter; }
|
||||||
|
int getItemId() const { return ItemId_Command_IncCounter; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -270,6 +291,7 @@ public:
|
||||||
int getRadius() const { return radius; }
|
int getRadius() const { return radius; }
|
||||||
int getValue() const { return value; }
|
int getValue() const { return value; }
|
||||||
static ProtocolItem *newItem() { return new Command_AddCounter; }
|
static ProtocolItem *newItem() { return new Command_AddCounter; }
|
||||||
|
int getItemId() const { return ItemId_Command_AddCounter; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -283,6 +305,7 @@ public:
|
||||||
int getCounterId() const { return counterId; }
|
int getCounterId() const { return counterId; }
|
||||||
int getValue() const { return value; }
|
int getValue() const { return value; }
|
||||||
static ProtocolItem *newItem() { return new Command_SetCounter; }
|
static ProtocolItem *newItem() { return new Command_SetCounter; }
|
||||||
|
int getItemId() const { return ItemId_Command_SetCounter; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -294,6 +317,7 @@ public:
|
||||||
Command_DelCounter(int _gameId = -1, int _counterId = -1);
|
Command_DelCounter(int _gameId = -1, int _counterId = -1);
|
||||||
int getCounterId() const { return counterId; }
|
int getCounterId() const { return counterId; }
|
||||||
static ProtocolItem *newItem() { return new Command_DelCounter; }
|
static ProtocolItem *newItem() { return new Command_DelCounter; }
|
||||||
|
int getItemId() const { return ItemId_Command_DelCounter; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -303,6 +327,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Command_NextTurn(int _gameId = -1);
|
Command_NextTurn(int _gameId = -1);
|
||||||
static ProtocolItem *newItem() { return new Command_NextTurn; }
|
static ProtocolItem *newItem() { return new Command_NextTurn; }
|
||||||
|
int getItemId() const { return ItemId_Command_NextTurn; }
|
||||||
};
|
};
|
||||||
class Command_SetActivePhase : public GameCommand {
|
class Command_SetActivePhase : public GameCommand {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -312,6 +337,7 @@ public:
|
||||||
Command_SetActivePhase(int _gameId = -1, int _phase = -1);
|
Command_SetActivePhase(int _gameId = -1, int _phase = -1);
|
||||||
int getPhase() const { return phase; }
|
int getPhase() const { return phase; }
|
||||||
static ProtocolItem *newItem() { return new Command_SetActivePhase; }
|
static ProtocolItem *newItem() { return new Command_SetActivePhase; }
|
||||||
|
int getItemId() const { return ItemId_Command_SetActivePhase; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -327,6 +353,7 @@ public:
|
||||||
QString getZoneName() const { return zoneName; }
|
QString getZoneName() const { return zoneName; }
|
||||||
int getNumberCards() const { return numberCards; }
|
int getNumberCards() const { return numberCards; }
|
||||||
static ProtocolItem *newItem() { return new Command_DumpZone; }
|
static ProtocolItem *newItem() { return new Command_DumpZone; }
|
||||||
|
int getItemId() const { return ItemId_Command_DumpZone; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -340,6 +367,7 @@ public:
|
||||||
int getPlayerId() const { return playerId; }
|
int getPlayerId() const { return playerId; }
|
||||||
QString getZoneName() const { return zoneName; }
|
QString getZoneName() const { return zoneName; }
|
||||||
static ProtocolItem *newItem() { return new Command_StopDumpZone; }
|
static ProtocolItem *newItem() { return new Command_StopDumpZone; }
|
||||||
|
int getItemId() const { return ItemId_Command_StopDumpZone; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -349,6 +377,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Command_DumpAll(int _gameId = -1);
|
Command_DumpAll(int _gameId = -1);
|
||||||
static ProtocolItem *newItem() { return new Command_DumpAll; }
|
static ProtocolItem *newItem() { return new Command_DumpAll; }
|
||||||
|
int getItemId() const { return ItemId_Command_DumpAll; }
|
||||||
};
|
};
|
||||||
class Command_SubmitDeck : public GameCommand {
|
class Command_SubmitDeck : public GameCommand {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -356,6 +385,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Command_SubmitDeck(int _gameId = -1);
|
Command_SubmitDeck(int _gameId = -1);
|
||||||
static ProtocolItem *newItem() { return new Command_SubmitDeck; }
|
static ProtocolItem *newItem() { return new Command_SubmitDeck; }
|
||||||
|
int getItemId() const { return ItemId_Command_SubmitDeck; }
|
||||||
};
|
};
|
||||||
class Event_Say : public GameEvent {
|
class Event_Say : public GameEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -365,6 +395,7 @@ public:
|
||||||
Event_Say(int _gameId = -1, int _playerId = -1, const QString &_message = QString());
|
Event_Say(int _gameId = -1, int _playerId = -1, const QString &_message = QString());
|
||||||
QString getMessage() const { return message; }
|
QString getMessage() const { return message; }
|
||||||
static ProtocolItem *newItem() { return new Event_Say; }
|
static ProtocolItem *newItem() { return new Event_Say; }
|
||||||
|
int getItemId() const { return ItemId_Event_Say; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -378,6 +409,7 @@ public:
|
||||||
QString getPlayerName() const { return playerName; }
|
QString getPlayerName() const { return playerName; }
|
||||||
bool getSpectator() const { return spectator; }
|
bool getSpectator() const { return spectator; }
|
||||||
static ProtocolItem *newItem() { return new Event_Join; }
|
static ProtocolItem *newItem() { return new Event_Join; }
|
||||||
|
int getItemId() const { return ItemId_Event_Join; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -387,6 +419,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Event_Leave(int _gameId = -1, int _playerId = -1);
|
Event_Leave(int _gameId = -1, int _playerId = -1);
|
||||||
static ProtocolItem *newItem() { return new Event_Leave; }
|
static ProtocolItem *newItem() { return new Event_Leave; }
|
||||||
|
int getItemId() const { return ItemId_Event_Leave; }
|
||||||
};
|
};
|
||||||
class Event_GameClosed : public GameEvent {
|
class Event_GameClosed : public GameEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -394,6 +427,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Event_GameClosed(int _gameId = -1, int _playerId = -1);
|
Event_GameClosed(int _gameId = -1, int _playerId = -1);
|
||||||
static ProtocolItem *newItem() { return new Event_GameClosed; }
|
static ProtocolItem *newItem() { return new Event_GameClosed; }
|
||||||
|
int getItemId() const { return ItemId_Event_GameClosed; }
|
||||||
};
|
};
|
||||||
class Event_ReadyStart : public GameEvent {
|
class Event_ReadyStart : public GameEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -401,6 +435,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Event_ReadyStart(int _gameId = -1, int _playerId = -1);
|
Event_ReadyStart(int _gameId = -1, int _playerId = -1);
|
||||||
static ProtocolItem *newItem() { return new Event_ReadyStart; }
|
static ProtocolItem *newItem() { return new Event_ReadyStart; }
|
||||||
|
int getItemId() const { return ItemId_Event_ReadyStart; }
|
||||||
};
|
};
|
||||||
class Event_SetupZones : public GameEvent {
|
class Event_SetupZones : public GameEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -412,6 +447,7 @@ public:
|
||||||
int getDeckSize() const { return deckSize; }
|
int getDeckSize() const { return deckSize; }
|
||||||
int getSbSize() const { return sbSize; }
|
int getSbSize() const { return sbSize; }
|
||||||
static ProtocolItem *newItem() { return new Event_SetupZones; }
|
static ProtocolItem *newItem() { return new Event_SetupZones; }
|
||||||
|
int getItemId() const { return ItemId_Event_SetupZones; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -421,6 +457,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Event_GameStart(int _gameId = -1, int _playerId = -1);
|
Event_GameStart(int _gameId = -1, int _playerId = -1);
|
||||||
static ProtocolItem *newItem() { return new Event_GameStart; }
|
static ProtocolItem *newItem() { return new Event_GameStart; }
|
||||||
|
int getItemId() const { return ItemId_Event_GameStart; }
|
||||||
};
|
};
|
||||||
class Event_Shuffle : public GameEvent {
|
class Event_Shuffle : public GameEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -428,6 +465,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Event_Shuffle(int _gameId = -1, int _playerId = -1);
|
Event_Shuffle(int _gameId = -1, int _playerId = -1);
|
||||||
static ProtocolItem *newItem() { return new Event_Shuffle; }
|
static ProtocolItem *newItem() { return new Event_Shuffle; }
|
||||||
|
int getItemId() const { return ItemId_Event_Shuffle; }
|
||||||
};
|
};
|
||||||
class Event_RollDie : public GameEvent {
|
class Event_RollDie : public GameEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -439,6 +477,7 @@ public:
|
||||||
int getSides() const { return sides; }
|
int getSides() const { return sides; }
|
||||||
int getValue() const { return value; }
|
int getValue() const { return value; }
|
||||||
static ProtocolItem *newItem() { return new Event_RollDie; }
|
static ProtocolItem *newItem() { return new Event_RollDie; }
|
||||||
|
int getItemId() const { return ItemId_Event_RollDie; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -464,6 +503,7 @@ public:
|
||||||
int getY() const { return y; }
|
int getY() const { return y; }
|
||||||
bool getFaceDown() const { return faceDown; }
|
bool getFaceDown() const { return faceDown; }
|
||||||
static ProtocolItem *newItem() { return new Event_MoveCard; }
|
static ProtocolItem *newItem() { return new Event_MoveCard; }
|
||||||
|
int getItemId() const { return ItemId_Event_MoveCard; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -485,6 +525,7 @@ public:
|
||||||
int getX() const { return x; }
|
int getX() const { return x; }
|
||||||
int getY() const { return y; }
|
int getY() const { return y; }
|
||||||
static ProtocolItem *newItem() { return new Event_CreateToken; }
|
static ProtocolItem *newItem() { return new Event_CreateToken; }
|
||||||
|
int getItemId() const { return ItemId_Event_CreateToken; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -510,6 +551,7 @@ public:
|
||||||
int getTargetCardId() const { return targetCardId; }
|
int getTargetCardId() const { return targetCardId; }
|
||||||
int getColor() const { return color; }
|
int getColor() const { return color; }
|
||||||
static ProtocolItem *newItem() { return new Event_CreateArrow; }
|
static ProtocolItem *newItem() { return new Event_CreateArrow; }
|
||||||
|
int getItemId() const { return ItemId_Event_CreateArrow; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -521,6 +563,7 @@ public:
|
||||||
Event_DeleteArrow(int _gameId = -1, int _playerId = -1, int _arrowId = -1);
|
Event_DeleteArrow(int _gameId = -1, int _playerId = -1, int _arrowId = -1);
|
||||||
int getArrowId() const { return arrowId; }
|
int getArrowId() const { return arrowId; }
|
||||||
static ProtocolItem *newItem() { return new Event_DeleteArrow; }
|
static ProtocolItem *newItem() { return new Event_DeleteArrow; }
|
||||||
|
int getItemId() const { return ItemId_Event_DeleteArrow; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -538,6 +581,7 @@ public:
|
||||||
QString getAttrName() const { return attrName; }
|
QString getAttrName() const { return attrName; }
|
||||||
QString getAttrValue() const { return attrValue; }
|
QString getAttrValue() const { return attrValue; }
|
||||||
static ProtocolItem *newItem() { return new Event_SetCardAttr; }
|
static ProtocolItem *newItem() { return new Event_SetCardAttr; }
|
||||||
|
int getItemId() const { return ItemId_Event_SetCardAttr; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -557,6 +601,7 @@ public:
|
||||||
int getRadius() const { return radius; }
|
int getRadius() const { return radius; }
|
||||||
int getValue() const { return value; }
|
int getValue() const { return value; }
|
||||||
static ProtocolItem *newItem() { return new Event_AddCounter; }
|
static ProtocolItem *newItem() { return new Event_AddCounter; }
|
||||||
|
int getItemId() const { return ItemId_Event_AddCounter; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -570,6 +615,7 @@ public:
|
||||||
int getCounterId() const { return counterId; }
|
int getCounterId() const { return counterId; }
|
||||||
int getValue() const { return value; }
|
int getValue() const { return value; }
|
||||||
static ProtocolItem *newItem() { return new Event_SetCounter; }
|
static ProtocolItem *newItem() { return new Event_SetCounter; }
|
||||||
|
int getItemId() const { return ItemId_Event_SetCounter; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -581,6 +627,7 @@ public:
|
||||||
Event_DelCounter(int _gameId = -1, int _playerId = -1, int _counterId = -1);
|
Event_DelCounter(int _gameId = -1, int _playerId = -1, int _counterId = -1);
|
||||||
int getCounterId() const { return counterId; }
|
int getCounterId() const { return counterId; }
|
||||||
static ProtocolItem *newItem() { return new Event_DelCounter; }
|
static ProtocolItem *newItem() { return new Event_DelCounter; }
|
||||||
|
int getItemId() const { return ItemId_Event_DelCounter; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -592,6 +639,7 @@ public:
|
||||||
Event_SetActivePlayer(int _gameId = -1, int _playerId = -1, int _activePlayerId = -1);
|
Event_SetActivePlayer(int _gameId = -1, int _playerId = -1, int _activePlayerId = -1);
|
||||||
int getActivePlayerId() const { return activePlayerId; }
|
int getActivePlayerId() const { return activePlayerId; }
|
||||||
static ProtocolItem *newItem() { return new Event_SetActivePlayer; }
|
static ProtocolItem *newItem() { return new Event_SetActivePlayer; }
|
||||||
|
int getItemId() const { return ItemId_Event_SetActivePlayer; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -603,6 +651,7 @@ public:
|
||||||
Event_SetActivePhase(int _gameId = -1, int _playerId = -1, int _phase = -1);
|
Event_SetActivePhase(int _gameId = -1, int _playerId = -1, int _phase = -1);
|
||||||
int getPhase() const { return phase; }
|
int getPhase() const { return phase; }
|
||||||
static ProtocolItem *newItem() { return new Event_SetActivePhase; }
|
static ProtocolItem *newItem() { return new Event_SetActivePhase; }
|
||||||
|
int getItemId() const { return ItemId_Event_SetActivePhase; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -618,6 +667,7 @@ public:
|
||||||
QString getZone() const { return zone; }
|
QString getZone() const { return zone; }
|
||||||
int getNumberCards() const { return numberCards; }
|
int getNumberCards() const { return numberCards; }
|
||||||
static ProtocolItem *newItem() { return new Event_DumpZone; }
|
static ProtocolItem *newItem() { return new Event_DumpZone; }
|
||||||
|
int getItemId() const { return ItemId_Event_DumpZone; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -631,6 +681,7 @@ public:
|
||||||
int getZoneOwnerId() const { return zoneOwnerId; }
|
int getZoneOwnerId() const { return zoneOwnerId; }
|
||||||
QString getZone() const { return zone; }
|
QString getZone() const { return zone; }
|
||||||
static ProtocolItem *newItem() { return new Event_StopDumpZone; }
|
static ProtocolItem *newItem() { return new Event_StopDumpZone; }
|
||||||
|
int getItemId() const { return ItemId_Event_StopDumpZone; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
@ -642,6 +693,7 @@ public:
|
||||||
Event_Welcome(const QString &_message = QString());
|
Event_Welcome(const QString &_message = QString());
|
||||||
QString getMessage() const { return message; }
|
QString getMessage() const { return message; }
|
||||||
static ProtocolItem *newItem() { return new Event_Welcome; }
|
static ProtocolItem *newItem() { return new Event_Welcome; }
|
||||||
|
int getItemId() const { return ItemId_Event_Welcome; }
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
$initializeHash = '';
|
$initializeHash = '';
|
||||||
|
$itemId = 1000;
|
||||||
|
|
||||||
|
$headerfileBuffer = '';
|
||||||
|
|
||||||
|
open(idfile, ">protocol_item_ids.h");
|
||||||
|
|
||||||
open(headerfile, ">protocol_items.h");
|
open(headerfile, ">protocol_items.h");
|
||||||
print headerfile "#ifndef PROTOCOL_ITEMS_H\n"
|
print headerfile "#ifndef PROTOCOL_ITEMS_H\n"
|
||||||
|
@ -56,7 +61,8 @@ while (<file>) {
|
||||||
$constructorParamsCpp = "";
|
$constructorParamsCpp = "";
|
||||||
}
|
}
|
||||||
$className = $namePrefix . '_' . $name2;
|
$className = $namePrefix . '_' . $name2;
|
||||||
print headerfile "class $className : public $baseClass {\n"
|
$itemEnum .= "ItemId_$className = " . ++$itemId . ",\n";
|
||||||
|
$headerfileBuffer .= "class $className : public $baseClass {\n"
|
||||||
. "\tQ_OBJECT\n"
|
. "\tQ_OBJECT\n"
|
||||||
. "private:\n";
|
. "private:\n";
|
||||||
$paramStr2 = '';
|
$paramStr2 = '';
|
||||||
|
@ -92,12 +98,13 @@ while (<file>) {
|
||||||
}
|
}
|
||||||
($prettyVarName2 = $prettyVarName) =~ s/^(.)/\U$1\E/;
|
($prettyVarName2 = $prettyVarName) =~ s/^(.)/\U$1\E/;
|
||||||
$paramStr4 .= "\t$dataType get$prettyVarName2() const { return $prettyVarName; }\n";
|
$paramStr4 .= "\t$dataType get$prettyVarName2() const { return $prettyVarName; }\n";
|
||||||
print headerfile "\t$dataType $prettyVarName;\n";
|
$headerfileBuffer .= "\t$dataType $prettyVarName;\n";
|
||||||
}
|
}
|
||||||
print headerfile "public:\n"
|
$headerfileBuffer .= "public:\n"
|
||||||
. "\t$className($constructorParamsH);\n"
|
. "\t$className($constructorParamsH);\n"
|
||||||
. $paramStr4
|
. $paramStr4
|
||||||
. "\tstatic ProtocolItem *newItem() { return new $className; }\n"
|
. "\tstatic ProtocolItem *newItem() { return new $className; }\n"
|
||||||
|
. "\tint getItemId() const { return ItemId_$className; }\n"
|
||||||
. ($paramStr5 eq '' ? '' : "protected:\n\tvoid extractParameters();\n")
|
. ($paramStr5 eq '' ? '' : "protected:\n\tvoid extractParameters();\n")
|
||||||
. "};\n";
|
. "};\n";
|
||||||
print cppfile $className . "::$className($constructorParamsCpp)\n"
|
print cppfile $className . "::$className($constructorParamsCpp)\n"
|
||||||
|
@ -116,7 +123,14 @@ while (<file>) {
|
||||||
}
|
}
|
||||||
close(file);
|
close(file);
|
||||||
|
|
||||||
print headerfile "\n#endif\n";
|
print idfile "enum AutoItemId {\n"
|
||||||
|
. $itemEnum
|
||||||
|
. "ItemId_Other = " . ++$itemId . "\n"
|
||||||
|
. "};\n";
|
||||||
|
close(idfile);
|
||||||
|
|
||||||
|
print headerfile $headerfileBuffer
|
||||||
|
. "\n#endif\n";
|
||||||
close(headerfile);
|
close(headerfile);
|
||||||
|
|
||||||
print cppfile "void ProtocolItem::initializeHashAuto()\n"
|
print cppfile "void ProtocolItem::initializeHashAuto()\n"
|
||||||
|
|
|
@ -101,17 +101,17 @@ void Server_Game::startGameIfReady()
|
||||||
setActivePlayer(0);
|
setActivePlayer(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnMessage::ReturnCode Server_Game::checkJoin(const QString &_password, bool spectator)
|
ProtocolResponse::ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator)
|
||||||
{
|
{
|
||||||
if (_password != password)
|
if (_password != password)
|
||||||
return ReturnMessage::ReturnPasswordWrong;
|
return ProtocolResponse::RespWrongPassword;
|
||||||
if (spectator) {
|
if (spectator) {
|
||||||
if (!spectatorsAllowed)
|
if (!spectatorsAllowed)
|
||||||
return ReturnMessage::ReturnSpectatorsNotAllowed;
|
return ProtocolResponse::RespSpectatorsNotAllowed;
|
||||||
} else if (gameStarted || (getPlayerCount() >= getMaxPlayers()))
|
} else if (gameStarted || (getPlayerCount() >= getMaxPlayers()))
|
||||||
return ReturnMessage::ReturnContextError;
|
return ProtocolResponse::RespContextError;
|
||||||
|
|
||||||
return ReturnMessage::ReturnOk;
|
return ProtocolResponse::RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
Server_Player *Server_Game::addPlayer(const QString &playerName, bool spectator)
|
Server_Player *Server_Game::addPlayer(const QString &playerName, bool spectator)
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "server_player.h"
|
#include "server_player.h"
|
||||||
#include "returnmessage.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
class Server_Game : public QObject {
|
class Server_Game : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
int getMaxPlayers() const { return maxPlayers; }
|
int getMaxPlayers() const { return maxPlayers; }
|
||||||
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
||||||
QString getGameListLine() const;
|
QString getGameListLine() const;
|
||||||
ReturnMessage::ReturnCode checkJoin(const QString &_password, bool spectator);
|
ProtocolResponse::ResponseCode checkJoin(const QString &_password, bool spectator);
|
||||||
Server_Player *addPlayer(const QString &playerName, bool spectator);
|
Server_Player *addPlayer(const QString &playerName, bool spectator);
|
||||||
void removePlayer(Server_Player *player);
|
void removePlayer(Server_Player *player);
|
||||||
void startGameIfReady();
|
void startGameIfReady();
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
#include "server_protocolhandler.h"
|
#include "server_protocolhandler.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
#include "server_chatchannel.h"
|
||||||
|
#include "server_card.h"
|
||||||
|
#include "server_arrow.h"
|
||||||
|
#include "server_cardzone.h"
|
||||||
|
#include "server_counter.h"
|
||||||
|
#include "server_game.h"
|
||||||
|
#include "server_player.h"
|
||||||
|
|
||||||
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent)
|
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent)
|
||||||
: QObject(parent), server(_server), authState(PasswordWrong), acceptsGameListChanges(false)
|
: QObject(parent), server(_server), authState(PasswordWrong), acceptsGameListChanges(false)
|
||||||
|
@ -14,15 +21,70 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
|
||||||
|
|
||||||
void Server_ProtocolHandler::processCommand(Command *command)
|
void Server_ProtocolHandler::processCommand(Command *command)
|
||||||
{
|
{
|
||||||
|
ProtocolResponse::ResponseCode response = ProtocolResponse::RespInvalidCommand;
|
||||||
|
|
||||||
ChatCommand *chatCommand = qobject_cast<ChatCommand *>(command);
|
ChatCommand *chatCommand = qobject_cast<ChatCommand *>(command);
|
||||||
GameCommand *gameCommand = qobject_cast<GameCommand *>(command);
|
GameCommand *gameCommand = qobject_cast<GameCommand *>(command);
|
||||||
if (chatCommand) {
|
if (chatCommand) {
|
||||||
qDebug() << "received ChatCommand: channel =" << chatCommand->getChannel();
|
qDebug() << "received ChatCommand: channel =" << chatCommand->getChannel();
|
||||||
|
Server_ChatChannel *channel = chatChannels.value(chatCommand->getChannel(), 0);
|
||||||
|
if (!channel) {
|
||||||
|
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), ProtocolResponse::RespNameNotFound));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
} else if (gameCommand) {
|
} else if (gameCommand) {
|
||||||
qDebug() << "received GameCommand: game =" << gameCommand->getGameId();
|
qDebug() << "received GameCommand: game =" << gameCommand->getGameId();
|
||||||
|
if (!games.contains(gameCommand->getGameId())) {
|
||||||
|
sendProtocolItem(new ProtocolResponse(gameCommand->getCmdId(), ProtocolResponse::RespNameNotFound));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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_LeaveGame: response = cmdLeaveGame(qobject_cast<Command_LeaveGame *>(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_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_ReadyStart: response = cmdReadyStart(qobject_cast<Command_ReadyStart *>(command), game, player); break;
|
||||||
|
case ItemId_Command_IncCounter: response = cmdIncCounter(qobject_cast<Command_IncCounter *>(command), game, player); break;
|
||||||
|
case ItemId_Command_AddCounter: response = cmdAddCounter(qobject_cast<Command_AddCounter *>(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_DumpAll: response = cmdDumpAll(qobject_cast<Command_DumpAll *>(command), game, player); break;
|
||||||
|
case ItemId_Command_SubmitDeck: response = cmdSubmitDeck(qobject_cast<Command_SubmitDeck *>(command), game, player); break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "received generic Command";
|
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_ChatListChannels: response = cmdChatListChannels(qobject_cast<Command_ChatListChannels *>(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (response != ProtocolResponse::RespNothing)
|
||||||
|
sendProtocolItem(new ProtocolResponse(command->getCmdId(), response));
|
||||||
|
|
||||||
|
delete command;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<Server_Game *, Server_Player *> Server_ProtocolHandler::getGame(int gameId) const
|
QPair<Server_Game *, Server_Player *> Server_ProtocolHandler::getGame(int gameId) const
|
||||||
|
@ -31,3 +93,438 @@ QPair<Server_Game *, Server_Player *> Server_ProtocolHandler::getGame(int gameId
|
||||||
return games.value(gameId);
|
return games.value(gameId);
|
||||||
return QPair<Server_Game *, Server_Player *>(0, 0);
|
return QPair<Server_Game *, Server_Player *>(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdPing(Command_Ping *cmd)
|
||||||
|
{
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd)
|
||||||
|
{
|
||||||
|
authState = server->checkUserPassword(cmd->getUsername(), cmd->getPassword());
|
||||||
|
if (authState == PasswordWrong)
|
||||||
|
return ProtocolResponse::RespWrongPassword;
|
||||||
|
playerName = cmd->getUsername();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Mit enqueueProtocolItem() lösen!
|
||||||
|
|
||||||
|
QStringList loginMessage = server->getLoginMessage();
|
||||||
|
for (int i = 0; i < loginMessage.size(); ++i)
|
||||||
|
msg("chat|server_message||" + loginMessage[i]);
|
||||||
|
*/
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatListChannels(Command_ChatListChannels *cmd)
|
||||||
|
{
|
||||||
|
QMapIterator<QString, Server_ChatChannel *> channelIterator(server->getChatChannels());
|
||||||
|
while (channelIterator.hasNext()) {
|
||||||
|
Server_ChatChannel *c = channelIterator.next().value();
|
||||||
|
// msg(c->getChannelListLine());
|
||||||
|
}
|
||||||
|
|
||||||
|
acceptsChatChannelListChanges = true;
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatJoinChannel(Command_ChatJoinChannel *cmd)
|
||||||
|
{
|
||||||
|
if (chatChannels.contains(cmd->getChannel()))
|
||||||
|
return ProtocolResponse::RespContextError;
|
||||||
|
|
||||||
|
QMap<QString, Server_ChatChannel *> allChannels = server->getChatChannels();
|
||||||
|
Server_ChatChannel *c = allChannels.value(cmd->getChannel(), 0);
|
||||||
|
if (!c)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
|
||||||
|
// hier wird irgendwo ein Event erzeugt, das nach dem ok kommen muss -> evtl mit enqueue
|
||||||
|
c->addClient(this);
|
||||||
|
chatChannels.insert(cmd->getChannel(), c);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, Server_ChatChannel *channel)
|
||||||
|
{
|
||||||
|
chatChannels.remove(channel->getName());
|
||||||
|
channel->removeClient(this);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel)
|
||||||
|
{
|
||||||
|
channel->say(this, cmd->getMessage());
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames *cmd)
|
||||||
|
{
|
||||||
|
const QList<Server_Game *> &gameList = server->getGames();
|
||||||
|
for (int i = 0; i < gameList.size(); ++i) {
|
||||||
|
// msg(gameList[i]->getGameListLine());
|
||||||
|
}
|
||||||
|
acceptsGameListChanges = true;
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd)
|
||||||
|
{
|
||||||
|
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), playerName);
|
||||||
|
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, game->getCreator()));
|
||||||
|
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd)
|
||||||
|
{
|
||||||
|
Server_Game *g = server->getGame(cmd->getGameId());
|
||||||
|
if (!g)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode result = g->checkJoin(cmd->getPassword(), cmd->getSpectator());
|
||||||
|
if (result == ProtocolResponse::RespOk) {
|
||||||
|
Server_Player *player = g->addPlayer(playerName, cmd->getSpectator());
|
||||||
|
games.insert(cmd->getGameId(), QPair<Server_Game *, Server_Player *>(g, player));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
game->removePlayer(player);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
// XXX
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
player->getZones().value("deck")->shuffle();
|
||||||
|
// game->broadcastEvent("shuffle", player);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
// game->broadcastEvent(QString("roll_die|%1|%2").arg(sides).arg(rng->getNumber(1, sides)), player);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
Server_CardZone *deck = player->getZones().value("deck");
|
||||||
|
Server_CardZone *hand = player->getZones().value("hand");
|
||||||
|
int number = cmd->getNumber();
|
||||||
|
if (deck->cards.size() < number)
|
||||||
|
number = deck->cards.size();
|
||||||
|
|
||||||
|
for (int i = 0; i < number; ++i) {
|
||||||
|
Server_Card *card = deck->cards.takeFirst();
|
||||||
|
hand->cards.append(card);
|
||||||
|
// player->privateEvent(QString("draw|%1|%2").arg(card->getId()).arg(card->getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// game->broadcastEvent(QString("draw|%1").arg(number), player);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
// ID Karte, Startzone, Zielzone, Koordinaten X, Y, Facedown
|
||||||
|
Server_CardZone *startzone = player->getZones().value(cmd->getStartZone());
|
||||||
|
Server_CardZone *targetzone = player->getZones().value(cmd->getTargetZone());
|
||||||
|
if ((!startzone) || (!targetzone))
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
|
||||||
|
int position = -1;
|
||||||
|
Server_Card *card = startzone->getCard(cmd->getCardId(), true, &position);
|
||||||
|
if (!card)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
int x = cmd->getX();
|
||||||
|
if (x == -1)
|
||||||
|
x = targetzone->cards.size();
|
||||||
|
int y = 0;
|
||||||
|
if (targetzone->hasCoords())
|
||||||
|
y = cmd->getY();
|
||||||
|
bool facedown = cmd->getFaceDown();
|
||||||
|
|
||||||
|
targetzone->insertCard(card, x, y);
|
||||||
|
|
||||||
|
bool targetBeingLookedAt = (targetzone->getType() != Server_CardZone::HiddenZone) || (targetzone->getCardsBeingLookedAt() > x) || (targetzone->getCardsBeingLookedAt() == -1);
|
||||||
|
bool sourceBeingLookedAt = (startzone->getType() != Server_CardZone::HiddenZone) || (startzone->getCardsBeingLookedAt() > position) || (startzone->getCardsBeingLookedAt() == -1);
|
||||||
|
|
||||||
|
bool targetHiddenToPlayer = facedown || !targetBeingLookedAt;
|
||||||
|
bool targetHiddenToOthers = facedown || (targetzone->getType() != Server_CardZone::PublicZone);
|
||||||
|
bool sourceHiddenToPlayer = card->getFaceDown() || !sourceBeingLookedAt;
|
||||||
|
bool sourceHiddenToOthers = card->getFaceDown() || (startzone->getType() != Server_CardZone::PublicZone);
|
||||||
|
|
||||||
|
QString privateCardName, publicCardName;
|
||||||
|
if (!(sourceHiddenToPlayer && targetHiddenToPlayer))
|
||||||
|
privateCardName = card->getName();
|
||||||
|
if (!(sourceHiddenToOthers && targetHiddenToOthers))
|
||||||
|
publicCardName = card->getName();
|
||||||
|
|
||||||
|
if (facedown)
|
||||||
|
card->setId(player->newCardId());
|
||||||
|
card->setFaceDown(facedown);
|
||||||
|
|
||||||
|
// The player does not get to see which card he moved if it moves between two parts of hidden zones which
|
||||||
|
// are not being looked at.
|
||||||
|
QString privateCardId = QString::number(card->getId());
|
||||||
|
if (!targetBeingLookedAt && !sourceBeingLookedAt) {
|
||||||
|
privateCardId = QString();
|
||||||
|
privateCardName = QString();
|
||||||
|
}
|
||||||
|
/* player->privateEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(privateCardId)
|
||||||
|
.arg(privateCardName)
|
||||||
|
.arg(startzone->getName())
|
||||||
|
.arg(position)
|
||||||
|
.arg(targetzone->getName())
|
||||||
|
.arg(x)
|
||||||
|
.arg(y)
|
||||||
|
.arg(facedown ? 1 : 0));
|
||||||
|
*/
|
||||||
|
// 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,
|
||||||
|
// all cards are equal.
|
||||||
|
if ((startzone->getType() == Server_CardZone::HiddenZone) && ((startzone->getCardsBeingLookedAt() > position) || (startzone->getCardsBeingLookedAt() == -1)))
|
||||||
|
position = -1;
|
||||||
|
if ((targetzone->getType() == Server_CardZone::HiddenZone) && ((targetzone->getCardsBeingLookedAt() > x) || (targetzone->getCardsBeingLookedAt() == -1)))
|
||||||
|
x = -1;
|
||||||
|
|
||||||
|
/* if ((startzone->getType() == Server_CardZone::PublicZone) || (targetzone->getType() == Server_CardZone::PublicZone))
|
||||||
|
game->broadcastEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(card->getId())
|
||||||
|
.arg(publicCardName)
|
||||||
|
.arg(startzone->getName())
|
||||||
|
.arg(position)
|
||||||
|
.arg(targetzone->getName())
|
||||||
|
.arg(x)
|
||||||
|
.arg(y)
|
||||||
|
.arg(facedown ? 1 : 0), player);
|
||||||
|
else
|
||||||
|
game->broadcastEvent(QString("move_card|||%1|%2|%3|%4|%5|0").arg(startzone->getName())
|
||||||
|
.arg(position)
|
||||||
|
.arg(targetzone->getName())
|
||||||
|
.arg(x)
|
||||||
|
.arg(y), player);
|
||||||
|
*/
|
||||||
|
// If the card was moved to another zone, delete all arrows from and to the card
|
||||||
|
if (startzone != targetzone) {
|
||||||
|
const QList<Server_Player *> &players = game->getPlayers();
|
||||||
|
for (int i = 0; i < players.size(); ++i) {
|
||||||
|
QList<int> arrowsToDelete;
|
||||||
|
QMapIterator<int, Server_Arrow *> arrowIterator(players[i]->getArrows());
|
||||||
|
while (arrowIterator.hasNext()) {
|
||||||
|
Server_Arrow *arrow = arrowIterator.next().value();
|
||||||
|
if ((arrow->getStartCard() == card) || (arrow->getTargetCard() == card))
|
||||||
|
arrowsToDelete.append(arrow->getId());
|
||||||
|
}
|
||||||
|
for (int j = 0; j < arrowsToDelete.size(); ++j)
|
||||||
|
players[i]->deleteArrow(arrowsToDelete[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
// zone, cardname, powtough, x, y
|
||||||
|
// powtough wird erst mal ignoriert
|
||||||
|
Server_CardZone *zone = player->getZones().value(cmd->getZone());
|
||||||
|
if (!zone)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
|
||||||
|
Server_Card *card = new Server_Card(cmd->getCardName(), player->newCardId(), cmd->getX(), cmd->getY());
|
||||||
|
zone->insertCard(card, cmd->getX(), cmd->getY());
|
||||||
|
/* game->broadcastEvent(QString("create_token|%1|%2|%3|%4|%5|%6").arg(zone->getName())
|
||||||
|
.arg(cardid)
|
||||||
|
.arg(cardname)
|
||||||
|
.arg(powtough)
|
||||||
|
.arg(x)
|
||||||
|
.arg(y), player);
|
||||||
|
*/ return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
Server_Player *startPlayer = game->getPlayer(cmd->getStartPlayerId());
|
||||||
|
Server_Player *targetPlayer = game->getPlayer(cmd->getTargetPlayerId());
|
||||||
|
if (!startPlayer || !targetPlayer)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
Server_CardZone *startZone = startPlayer->getZones().value(cmd->getStartZone());
|
||||||
|
Server_CardZone *targetZone = targetPlayer->getZones().value(cmd->getTargetZone());
|
||||||
|
if (!startZone || !targetZone)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
Server_Card *startCard = startZone->getCard(cmd->getStartCardId(), false);
|
||||||
|
Server_Card *targetCard = targetZone->getCard(cmd->getTargetCardId(), false);
|
||||||
|
if (!startCard || !targetCard || (startCard == targetCard))
|
||||||
|
return ProtocolResponse::RespContextError;
|
||||||
|
QMapIterator<int, Server_Arrow *> arrowIterator(player->getArrows());
|
||||||
|
while (arrowIterator.hasNext()) {
|
||||||
|
Server_Arrow *temp = arrowIterator.next().value();
|
||||||
|
if ((temp->getStartCard() == startCard) && (temp->getTargetCard() == targetCard))
|
||||||
|
return ProtocolResponse::RespContextError;
|
||||||
|
}
|
||||||
|
|
||||||
|
Server_Arrow *arrow = new Server_Arrow(player->newArrowId(), startCard, targetCard, cmd->getColor());
|
||||||
|
player->addArrow(arrow);
|
||||||
|
/* game->broadcastEvent(QString("create_arrow|%1|%2|%3|%4|%5|%6|%7|%8")
|
||||||
|
.arg(arrow->getId())
|
||||||
|
.arg(startPlayer->getPlayerId())
|
||||||
|
.arg(startZone->getName())
|
||||||
|
.arg(startCard->getId())
|
||||||
|
.arg(targetPlayer->getPlayerId())
|
||||||
|
.arg(targetZone->getName())
|
||||||
|
.arg(targetCard->getId())
|
||||||
|
.arg(cmd->getColor()), player
|
||||||
|
);
|
||||||
|
*/ return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
if (!player->deleteArrow(cmd->getArrowId()))
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
|
||||||
|
// game->broadcastEvent(QString("delete_arrow|%1").arg(arrowId), player);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
// zone, card id, attr name, attr value
|
||||||
|
// card id = -1 => affects all cards in the specified zone
|
||||||
|
Server_CardZone *zone = player->getZones().value(cmd->getZone());
|
||||||
|
if (!zone)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
|
||||||
|
if (cmd->getCardId() == -1) {
|
||||||
|
QListIterator<Server_Card *> CardIterator(zone->cards);
|
||||||
|
while (CardIterator.hasNext())
|
||||||
|
if (!CardIterator.next()->setAttribute(cmd->getAttrName(), cmd->getAttrValue(), true))
|
||||||
|
return ProtocolResponse::RespInvalidCommand;
|
||||||
|
} else {
|
||||||
|
Server_Card *card = zone->getCard(cmd->getCardId(), false);
|
||||||
|
if (!card)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
if (!card->setAttribute(cmd->getAttrName(), cmd->getAttrValue(), false))
|
||||||
|
return ProtocolResponse::RespInvalidCommand;
|
||||||
|
}
|
||||||
|
// game->broadcastEvent(QString("set_card_attr|%1|%2|%3|%4").arg(zone->getName()).arg(cardid).arg(aname).arg(avalue), player);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
player->setStatus(StatusReadyStart);
|
||||||
|
// game->broadcastEvent(QString("ready_start"), player);
|
||||||
|
game->startGameIfReady();
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
const QMap<int, Server_Counter *> counters = player->getCounters();
|
||||||
|
Server_Counter *c = counters.value(cmd->getCounterId(), 0);
|
||||||
|
if (!c)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
|
||||||
|
c->setCount(c->getCount() + cmd->getDelta());
|
||||||
|
// game->broadcastEvent(QString("set_counter|%1|%2").arg(c->getId()).arg(c->getCount()), player);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdAddCounter(Command_AddCounter *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
Server_Counter *c = new Server_Counter(player->newCounterId(), cmd->getCounterName(), cmd->getColor(), cmd->getRadius(), cmd->getValue());
|
||||||
|
player->addCounter(c);
|
||||||
|
// game->broadcastEvent(QString("add_counter|%1|%2|%3|%4|%5").arg(c->getId()).arg(c->getName()).arg(color).arg(radius).arg(count), player);
|
||||||
|
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
Server_Counter *c = player->getCounters().value(cmd->getCounterId(), 0);;
|
||||||
|
if (!c)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
|
||||||
|
c->setCount(cmd->getValue());
|
||||||
|
// game->broadcastEvent(QString("set_counter|%1|%2").arg(c->getId()).arg(count), player);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
if (!player->deleteCounter(cmd->getCounterId()))
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
// game->broadcastEvent(QString("del_counter|%1").arg(counterId), player);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, Server_Game *game, Server_Player * /*player*/)
|
||||||
|
{
|
||||||
|
int activePlayer = game->getActivePlayer();
|
||||||
|
if (++activePlayer == game->getPlayerCount())
|
||||||
|
activePlayer = 0;
|
||||||
|
game->setActivePlayer(activePlayer);
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
if (game->getActivePlayer() != player->getPlayerId())
|
||||||
|
return ProtocolResponse::RespContextError;
|
||||||
|
game->setActivePhase(cmd->getPhase());
|
||||||
|
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId());
|
||||||
|
if (!otherPlayer)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
Server_CardZone *zone = otherPlayer->getZones().value(cmd->getZoneName());
|
||||||
|
if (!zone)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
if (!((zone->getType() == Server_CardZone::PublicZone) || (player == otherPlayer)))
|
||||||
|
return ProtocolResponse::RespContextError;
|
||||||
|
|
||||||
|
if (zone->getType() == Server_CardZone::HiddenZone) {
|
||||||
|
// game->broadcastEvent(QString("dump_zone|%1|%2|%3").arg(player_id).arg(zone->getName()).arg(number_cards), player);
|
||||||
|
}
|
||||||
|
// remsg->sendList(dumpZoneHelper(otherPlayer, zone, number_cards));
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId());
|
||||||
|
if (!otherPlayer)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
Server_CardZone *zone = otherPlayer->getZones().value(cmd->getZoneName());
|
||||||
|
if (!zone)
|
||||||
|
return ProtocolResponse::RespNameNotFound;
|
||||||
|
|
||||||
|
if (zone->getType() == Server_CardZone::HiddenZone) {
|
||||||
|
zone->setCardsBeingLookedAt(0);
|
||||||
|
// game->broadcastEvent(QString("stop_dump_zone|%1|%2").arg(otherPlayer->getPlayerId()).arg(zone->getName()), player);
|
||||||
|
}
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode Server_ProtocolHandler::cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
return ProtocolResponse::RespOk;
|
||||||
|
}
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
#include "protocol.h"
|
||||||
|
#include "protocol_items.h"
|
||||||
|
|
||||||
class Server_Player;
|
class Server_Player;
|
||||||
class Command;
|
|
||||||
class ProtocolItem;
|
|
||||||
|
|
||||||
class Server_ProtocolHandler : public QObject {
|
class Server_ProtocolHandler : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -23,6 +23,40 @@ private:
|
||||||
AuthenticationResult authState;
|
AuthenticationResult authState;
|
||||||
bool acceptsGameListChanges;
|
bool acceptsGameListChanges;
|
||||||
bool acceptsChatChannelListChanges;
|
bool acceptsChatChannelListChanges;
|
||||||
|
|
||||||
|
ProtocolResponse::ResponseCode cmdPing(Command_Ping *cmd);
|
||||||
|
ProtocolResponse::ResponseCode cmdLogin(Command_Login *cmd);
|
||||||
|
ProtocolResponse::ResponseCode cmdChatListChannels(Command_ChatListChannels *cmd);
|
||||||
|
ProtocolResponse::ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd);
|
||||||
|
ProtocolResponse::ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, Server_ChatChannel *channel);
|
||||||
|
ProtocolResponse::ResponseCode cmdChatSay(Command_ChatSay *cmd, Server_ChatChannel *channel);
|
||||||
|
ProtocolResponse::ResponseCode cmdListGames(Command_ListGames *cmd);
|
||||||
|
ProtocolResponse::ResponseCode cmdCreateGame(Command_CreateGame *cmd);
|
||||||
|
ProtocolResponse::ResponseCode cmdJoinGame(Command_JoinGame *cmd);
|
||||||
|
ProtocolResponse::ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdDrawCards(Command_DrawCards *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdMoveCard(Command_MoveCard *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdCreateToken(Command_CreateToken *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdAddCounter(Command_AddCounter *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdDelCounter(Command_DelCounter *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdNextTurn(Command_NextTurn *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ProtocolResponse::ResponseCode cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
|
||||||
|
QList<ProtocolItem *> itemQueue;
|
||||||
|
void enqueueProtocolItem(ProtocolItem *item);
|
||||||
public:
|
public:
|
||||||
Server_ProtocolHandler(Server *_server, QObject *parent = 0);
|
Server_ProtocolHandler(Server *_server, QObject *parent = 0);
|
||||||
~Server_ProtocolHandler();
|
~Server_ProtocolHandler();
|
||||||
|
|
|
@ -15,7 +15,6 @@ QT -= gui
|
||||||
|
|
||||||
HEADERS += src/servatrice.h \
|
HEADERS += src/servatrice.h \
|
||||||
src/serversocketinterface.h \
|
src/serversocketinterface.h \
|
||||||
src/version.h \
|
|
||||||
../common/protocol.h \
|
../common/protocol.h \
|
||||||
../common/protocol_items.h \
|
../common/protocol_items.h \
|
||||||
../common/rng_abstract.h \
|
../common/rng_abstract.h \
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
#include "returnmessage.h"
|
|
||||||
#include "serversocket.h"
|
|
||||||
|
|
||||||
bool ReturnMessage::send(ReturnCode code)
|
|
||||||
{
|
|
||||||
ServerSocket *s = qobject_cast<ServerSocket *>(parent());
|
|
||||||
if (!s)
|
|
||||||
return false;
|
|
||||||
QString returnCodeString;
|
|
||||||
switch (code) {
|
|
||||||
case ReturnNothing: return true;
|
|
||||||
case ReturnOk: returnCodeString = "ok"; break;
|
|
||||||
case ReturnNameNotFound: returnCodeString = "name_not_found"; break;
|
|
||||||
case ReturnLoginNeeded: returnCodeString = "login_needed"; break;
|
|
||||||
case ReturnSyntaxError: returnCodeString = "syntax"; break;
|
|
||||||
case ReturnContextError: returnCodeString = "context"; break;
|
|
||||||
case ReturnPasswordWrong: returnCodeString = "password"; break;
|
|
||||||
case ReturnSpectatorsNotAllowed: returnCodeString = "spectators_not_allowed"; break;
|
|
||||||
}
|
|
||||||
s->msg(QString("resp|%1|%2").arg(msg_id)
|
|
||||||
.arg(returnCodeString));
|
|
||||||
return (code == ReturnOk);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ReturnMessage::sendList(const QStringList &args, const QString &prefix)
|
|
||||||
{
|
|
||||||
ServerSocket *s = qobject_cast<ServerSocket *>(parent());
|
|
||||||
if (!s)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
QString arg1 = prefix.isEmpty() ? cmd : prefix;
|
|
||||||
for (int i = 0; i < args.size(); i++)
|
|
||||||
s->msg(QString("%1|%2|%3").arg(arg1)
|
|
||||||
.arg(msg_id)
|
|
||||||
.arg(args[i]));
|
|
||||||
return true;
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
#ifndef RETURNMESSAGE_H
|
|
||||||
#define RETURNMESSAGE_H
|
|
||||||
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
class ReturnMessage : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
private:
|
|
||||||
unsigned int msg_id;
|
|
||||||
QString cmd;
|
|
||||||
public:
|
|
||||||
enum ReturnCode { ReturnNothing, ReturnOk, ReturnNameNotFound, ReturnLoginNeeded, ReturnSyntaxError, ReturnContextError, ReturnPasswordWrong, ReturnSpectatorsNotAllowed };
|
|
||||||
ReturnMessage(QObject *parent = 0) : QObject(parent), msg_id(0) { }
|
|
||||||
unsigned int getMsgId() const { return msg_id; }
|
|
||||||
void setMsgId(unsigned int _msg_id) { msg_id = _msg_id; }
|
|
||||||
void setCmd(const QString &_cmd) { cmd = _cmd; }
|
|
||||||
bool send(ReturnCode code);
|
|
||||||
bool sendList(const QStringList &args, const QString &prefix = QString());
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -22,10 +22,13 @@
|
||||||
#include "servatrice.h"
|
#include "servatrice.h"
|
||||||
#include "server_chatchannel.h"
|
#include "server_chatchannel.h"
|
||||||
#include "serversocketinterface.h"
|
#include "serversocketinterface.h"
|
||||||
|
#include "protocol.h"
|
||||||
|
|
||||||
Servatrice::Servatrice(QObject *parent)
|
Servatrice::Servatrice(QObject *parent)
|
||||||
: Server(parent)
|
: Server(parent)
|
||||||
{
|
{
|
||||||
|
ProtocolItem::initializeHash();
|
||||||
|
|
||||||
tcpServer = new QTcpServer(this);
|
tcpServer = new QTcpServer(this);
|
||||||
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newConnection()));
|
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(newConnection()));
|
||||||
tcpServer->listen(QHostAddress::Any, 4747); // XXX make customizable
|
tcpServer->listen(QHostAddress::Any, 4747); // XXX make customizable
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
|
||||||
ServerSocketInterface::ServerSocketInterface(Server *_server, QTcpSocket *_socket, QObject *parent)
|
ServerSocketInterface::ServerSocketInterface(Server *_server, QTcpSocket *_socket, QObject *parent)
|
||||||
: Server_ProtocolHandler(_server, parent), socket(_socket)
|
: Server_ProtocolHandler(_server, parent), socket(_socket), currentItem(0)
|
||||||
{
|
{
|
||||||
xmlWriter = new QXmlStreamWriter;
|
xmlWriter = new QXmlStreamWriter;
|
||||||
xmlWriter->setDevice(socket);
|
xmlWriter->setDevice(socket);
|
||||||
|
@ -39,7 +39,7 @@ ServerSocketInterface::ServerSocketInterface(Server *_server, QTcpSocket *_socke
|
||||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(catchSocketError(QAbstractSocket::SocketError)));
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(catchSocketError(QAbstractSocket::SocketError)));
|
||||||
|
|
||||||
xmlWriter->writeStartDocument();
|
xmlWriter->writeStartDocument();
|
||||||
xmlWriter->writeStartElement("cockatrice_communication");
|
xmlWriter->writeStartElement("cockatrice_server_stream");
|
||||||
xmlWriter->writeAttribute("version", QString::number(ProtocolItem::protocolVersion));
|
xmlWriter->writeAttribute("version", QString::number(ProtocolItem::protocolVersion));
|
||||||
|
|
||||||
sendProtocolItem(new Event_Welcome(Servatrice::versionString));
|
sendProtocolItem(new Event_Welcome(Servatrice::versionString));
|
||||||
|
@ -64,32 +64,38 @@ ServerSocketInterface::~ServerSocketInterface()
|
||||||
|
|
||||||
void ServerSocketInterface::readClient()
|
void ServerSocketInterface::readClient()
|
||||||
{
|
{
|
||||||
|
qDebug() << "readClient";
|
||||||
xmlReader->addData(socket->readAll());
|
xmlReader->addData(socket->readAll());
|
||||||
|
|
||||||
while (canReadLine()) {
|
if (currentItem) {
|
||||||
QString line = QString(readLine()).trimmed();
|
if (!currentItem->read(xmlReader))
|
||||||
if (line.isNull())
|
return;
|
||||||
break;
|
currentItem = 0;
|
||||||
|
}
|
||||||
qDebug(QString("<<< %1").arg(line).toLatin1());
|
while (!xmlReader->atEnd()) {
|
||||||
/* switch (PlayerStatus) {
|
xmlReader->readNext();
|
||||||
case StatusNormal:
|
if (xmlReader->isStartElement()) {
|
||||||
case StatusReadyStart:
|
QString itemType = xmlReader->name().toString();
|
||||||
case StatusPlaying:
|
if (itemType == "cockatrice_client_stream")
|
||||||
parseCommand(line);
|
continue;
|
||||||
break;
|
QString itemName = xmlReader->attributes().value("name").toString();
|
||||||
case StatusSubmitDeck:
|
qDebug() << "parseXml: startElement: " << "type =" << itemType << ", name =" << itemName;
|
||||||
QString card = line;
|
currentItem = ProtocolItem::getNewItem(itemType + itemName);
|
||||||
if (card == ".") {
|
if (!currentItem)
|
||||||
PlayerStatus = StatusNormal;
|
currentItem = new InvalidCommand;
|
||||||
remsg->send(ReturnMessage::ReturnOk);
|
if (!currentItem->read(xmlReader))
|
||||||
} else if (card.startsWith("SB:"))
|
return;
|
||||||
SideboardList << card.mid(3);
|
else {
|
||||||
|
Command *command = qobject_cast<Command *>(currentItem);
|
||||||
|
if (qobject_cast<InvalidCommand *>(command))
|
||||||
|
sendProtocolItem(new ProtocolResponse(command->getCmdId(), ProtocolResponse::RespInvalidCommand));
|
||||||
else
|
else
|
||||||
DeckList << card;
|
processCommand(command);
|
||||||
|
currentItem = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/}
|
}
|
||||||
|
|
||||||
void ServerSocketInterface::catchSocketError(QAbstractSocket::SocketError socketError)
|
void ServerSocketInterface::catchSocketError(QAbstractSocket::SocketError socketError)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#define SERVERSOCKETINTERFACE_H
|
#define SERVERSOCKETINTERFACE_H
|
||||||
|
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <server_protocolhandler.h>
|
#include "server_protocolhandler.h"
|
||||||
|
|
||||||
class QTcpSocket;
|
class QTcpSocket;
|
||||||
class Server;
|
class Server;
|
||||||
|
@ -38,6 +38,7 @@ private:
|
||||||
QTcpSocket *socket;
|
QTcpSocket *socket;
|
||||||
QXmlStreamWriter *xmlWriter;
|
QXmlStreamWriter *xmlWriter;
|
||||||
QXmlStreamReader *xmlReader;
|
QXmlStreamReader *xmlReader;
|
||||||
|
ProtocolItem *currentItem;
|
||||||
public:
|
public:
|
||||||
ServerSocketInterface(Server *_server, QTcpSocket *_socket, QObject *parent = 0);
|
ServerSocketInterface(Server *_server, QTcpSocket *_socket, QObject *parent = 0);
|
||||||
~ServerSocketInterface();
|
~ServerSocketInterface();
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
/***************************************************************************
|
|
||||||
* Copyright (C) 2008 by Max-Wilhelm Bruker *
|
|
||||||
* brukie@laptop *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the *
|
|
||||||
* Free Software Foundation, Inc., *
|
|
||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
static const int PROTOCOL_VERSION = 2;
|
|
||||||
static const char *VERSION_STRING = "Servatrice 0.20091017";
|
|
Loading…
Reference in a new issue