mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 00:04:48 -07:00
added responses + events
This commit is contained in:
parent
26f0f0df0e
commit
ca9122b9fb
84 changed files with 815 additions and 1482 deletions
|
|
@ -6,7 +6,6 @@
|
|||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
#include "protocol_item_ids.h"
|
||||
#include "protocol_datastructures.h"
|
||||
|
||||
class QXmlStreamReader;
|
||||
|
|
@ -20,39 +19,6 @@ class GameEventContainer;
|
|||
class GameEventContext;
|
||||
class MoveCardToZone;
|
||||
|
||||
enum ItemId {
|
||||
ItemId_CommandContainer = ItemId_Other + 50,
|
||||
ItemId_GameEventContainer = ItemId_Other + 51,
|
||||
ItemId_Command_CreateGame = ItemId_Other + 99,
|
||||
ItemId_Command_DeckUpload = ItemId_Other + 100,
|
||||
ItemId_Command_DeckSelect = ItemId_Other + 101,
|
||||
ItemId_Command_SetSideboardPlan = ItemId_Other + 102,
|
||||
ItemId_Command_MoveCard = ItemId_Other + 103,
|
||||
ItemId_Event_ListRooms = ItemId_Other + 200,
|
||||
ItemId_Event_JoinRoom = ItemId_Other + 201,
|
||||
ItemId_Event_ListGames = ItemId_Other + 203,
|
||||
ItemId_Event_UserJoined = ItemId_Other + 204,
|
||||
ItemId_Event_GameStateChanged = ItemId_Other + 205,
|
||||
ItemId_Event_PlayerPropertiesChanged = ItemId_Other + 206,
|
||||
ItemId_Event_CreateArrows = ItemId_Other + 207,
|
||||
ItemId_Event_CreateCounters = ItemId_Other + 208,
|
||||
ItemId_Event_DrawCards = ItemId_Other + 209,
|
||||
ItemId_Event_RevealCards = ItemId_Other + 210,
|
||||
ItemId_Event_Join = ItemId_Other + 211,
|
||||
ItemId_Event_Ping = ItemId_Other + 212,
|
||||
ItemId_Event_AddToList = ItemId_Other + 213,
|
||||
ItemId_Response_ListUsers = ItemId_Other + 300,
|
||||
ItemId_Response_GetGamesOfUser = ItemId_Other + 301,
|
||||
ItemId_Response_GetUserInfo = ItemId_Other + 302,
|
||||
ItemId_Response_DeckList = ItemId_Other + 303,
|
||||
ItemId_Response_DeckDownload = ItemId_Other + 304,
|
||||
ItemId_Response_DeckUpload = ItemId_Other + 305,
|
||||
ItemId_Response_DumpZone = ItemId_Other + 306,
|
||||
ItemId_Response_JoinRoom = ItemId_Other + 307,
|
||||
ItemId_Response_Login = ItemId_Other + 308,
|
||||
ItemId_Invalid = ItemId_Other + 1000
|
||||
};
|
||||
|
||||
class ProtocolItem : public SerializableItem_Map {
|
||||
Q_OBJECT
|
||||
private:
|
||||
|
|
@ -68,26 +34,6 @@ public:
|
|||
bool isEmpty() const { return false; }
|
||||
};
|
||||
|
||||
class ProtocolItem_Invalid : public ProtocolItem {
|
||||
public:
|
||||
ProtocolItem_Invalid() : ProtocolItem(QString(), QString()) { }
|
||||
int getItemId() const { return ItemId_Invalid; }
|
||||
};
|
||||
|
||||
class TopLevelProtocolItem : public SerializableItem {
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void protocolItemReceived(ProtocolItem *item);
|
||||
private:
|
||||
ProtocolItem *currentItem;
|
||||
bool readCurrentItem(QXmlStreamReader *xml);
|
||||
public:
|
||||
TopLevelProtocolItem();
|
||||
bool readElement(QXmlStreamReader *xml);
|
||||
void writeElement(QXmlStreamWriter *xml);
|
||||
bool isEmpty() const { return false; }
|
||||
};
|
||||
|
||||
// ----------------
|
||||
// --- COMMANDS ---
|
||||
// ----------------
|
||||
|
|
@ -118,67 +64,9 @@ public:
|
|||
void enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId = -1, GameEventContext *context = 0);
|
||||
int getPrivatePlayerId() const { return privatePlayerId; }
|
||||
};
|
||||
|
||||
// -----------------
|
||||
// --- RESPONSES ---
|
||||
// -----------------
|
||||
|
||||
class ProtocolResponse : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
private:
|
||||
static QHash<QString, ResponseCode> responseHash;
|
||||
public:
|
||||
ProtocolResponse(int _cmdId = -1, ResponseCode _responseCode = RespNothing, const QString &_itemName = QString());
|
||||
int getItemId() const { return ItemId_Other; }
|
||||
static void initializeHash();
|
||||
static SerializableItem *newItem() { return new ProtocolResponse; }
|
||||
int getCmdId() const { return static_cast<SerializableItem_Int *>(itemMap.value("cmd_id"))->getData(); }
|
||||
void setCmdId(int _cmdId) { static_cast<SerializableItem_Int *>(itemMap.value("cmd_id"))->setData(_cmdId); }
|
||||
ResponseCode getResponseCode() const { return responseHash.value(static_cast<SerializableItem_String *>(itemMap.value("response_code"))->getData(), RespOk); }
|
||||
};
|
||||
|
||||
class Response_JoinRoom : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Response_JoinRoom(int _cmdId = -1, ResponseCode _responseCode = RespOk, ServerInfo_Room *_roomInfo = 0);
|
||||
int getItemId() const { return ItemId_Response_JoinRoom; }
|
||||
static SerializableItem *newItem() { return new Response_JoinRoom; }
|
||||
ServerInfo_Room *getRoomInfo() const { return static_cast<ServerInfo_Room *>(itemMap.value("room")); }
|
||||
};
|
||||
|
||||
class Response_ListUsers : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Response_ListUsers(int _cmdId = -1, ResponseCode _responseCode = RespOk, const QList<ServerInfo_User *> &_userList = QList<ServerInfo_User *>());
|
||||
int getItemId() const { return ItemId_Response_ListUsers; }
|
||||
static SerializableItem *newItem() { return new Response_ListUsers; }
|
||||
QList<ServerInfo_User *> getUserList() const { return typecastItemList<ServerInfo_User *>(); }
|
||||
};
|
||||
|
||||
class Response_GetGamesOfUser : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<ServerInfo_Game *> gameList;
|
||||
QList<ServerInfo_Room *> roomList;
|
||||
protected:
|
||||
void extractData();
|
||||
public:
|
||||
Response_GetGamesOfUser(int _cmdId = -1, ResponseCode _responseCode = RespOk, const QList<ServerInfo_Room *> &_roomList = QList<ServerInfo_Room *>(), const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>());
|
||||
int getItemId() const { return ItemId_Response_GetGamesOfUser; }
|
||||
static SerializableItem *newItem() { return new Response_GetGamesOfUser; }
|
||||
QList<ServerInfo_Room *> getRoomList() const { return roomList; }
|
||||
QList<ServerInfo_Game *> getGameList() const { return gameList; }
|
||||
};
|
||||
|
||||
class Response_GetUserInfo : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Response_GetUserInfo(int _cmdId = -1, ResponseCode _responseCode = RespOk, ServerInfo_User *_userInfo = 0);
|
||||
int getItemId() const { return ItemId_Response_GetUserInfo; }
|
||||
static SerializableItem *newItem() { return new Response_GetUserInfo; }
|
||||
ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
|
||||
};
|
||||
|
||||
/*
|
||||
* XXX
|
||||
*
|
||||
class Response_DeckList : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
@ -205,203 +93,5 @@ public:
|
|||
static SerializableItem *newItem() { return new Response_DeckUpload; }
|
||||
DeckList_File *getFile() const { return static_cast<DeckList_File *>(itemMap.value("file")); }
|
||||
};
|
||||
|
||||
class Response_DumpZone : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Response_DumpZone(int _cmdId = -1, ResponseCode _responseCode = RespOk, ServerInfo_Zone *zone = 0);
|
||||
int getItemId() const { return ItemId_Response_DumpZone; }
|
||||
static SerializableItem *newItem() { return new Response_DumpZone; }
|
||||
ServerInfo_Zone *getZone() const { return static_cast<ServerInfo_Zone *>(itemMap.value("zone")); }
|
||||
};
|
||||
|
||||
class Response_Login : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Response_Login(int _cmdId = -1, ResponseCode _responseCode = RespOk, ServerInfo_User *_userInfo = 0, const QList<ServerInfo_User *> &_buddyList = QList<ServerInfo_User *>(), const QList<ServerInfo_User *> &_ignoreList = QList<ServerInfo_User *>());
|
||||
int getItemId() const { return ItemId_Response_Login; }
|
||||
static SerializableItem *newItem() { return new Response_Login; }
|
||||
ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
|
||||
QList<ServerInfo_User *> getBuddyList() const { return static_cast<ServerInfo_UserList *>(itemMap.value("buddy_list"))->getUserList(); }
|
||||
QList<ServerInfo_User *> getIgnoreList() const { return static_cast<ServerInfo_UserList *>(itemMap.value("ignore_list"))->getUserList(); }
|
||||
};
|
||||
|
||||
// --------------
|
||||
// --- EVENTS ---
|
||||
// --------------
|
||||
|
||||
class GenericEvent : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GenericEvent(const QString &_eventName)
|
||||
: ProtocolItem("generic_event", _eventName) { }
|
||||
};
|
||||
|
||||
class GameEvent : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GameEvent(const QString &_eventName, int _playerId);
|
||||
int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); }
|
||||
};
|
||||
|
||||
class GameEventContext : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
GameEventContext(const QString &_contextName);
|
||||
};
|
||||
|
||||
class GameEventContainer : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<GameEvent *> eventList;
|
||||
GameEventContext *context;
|
||||
protected:
|
||||
void extractData();
|
||||
public:
|
||||
GameEventContainer(const QList<GameEvent *> &_eventList = QList<GameEvent *>(), int _gameId = -1, GameEventContext *_context = 0);
|
||||
static SerializableItem *newItem() { return new GameEventContainer; }
|
||||
int getItemId() const { return ItemId_GameEventContainer; }
|
||||
QList<GameEvent *> getEventList() const { return eventList; }
|
||||
GameEventContext *getContext() const { return context; }
|
||||
void setContext(GameEventContext *_context);
|
||||
void addGameEvent(GameEvent *event);
|
||||
static GameEventContainer *makeNew(GameEvent *event, int _gameId);
|
||||
|
||||
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
|
||||
void setGameId(int _gameId) { static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->setData(_gameId); }
|
||||
};
|
||||
|
||||
class RoomEvent : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
RoomEvent(const QString &_eventName, int _roomId);
|
||||
int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); }
|
||||
};
|
||||
|
||||
class Event_ListRooms : public GenericEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_ListRooms(const QList<ServerInfo_Room *> &_roomList = QList<ServerInfo_Room *>());
|
||||
int getItemId() const { return ItemId_Event_ListRooms; }
|
||||
static SerializableItem *newItem() { return new Event_ListRooms; }
|
||||
QList<ServerInfo_Room *> getRoomList() const { return typecastItemList<ServerInfo_Room *>(); }
|
||||
};
|
||||
|
||||
class Event_JoinRoom : public RoomEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_JoinRoom(int _roomId = -1, ServerInfo_User *_info = 0);
|
||||
int getItemId() const { return ItemId_Event_JoinRoom; }
|
||||
static SerializableItem *newItem() { return new Event_JoinRoom; }
|
||||
ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
|
||||
};
|
||||
|
||||
class Event_ListGames : public RoomEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_ListGames(int _roomId = -1, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>());
|
||||
int getItemId() const { return ItemId_Event_ListGames; }
|
||||
static SerializableItem *newItem() { return new Event_ListGames; }
|
||||
QList<ServerInfo_Game *> getGameList() const { return typecastItemList<ServerInfo_Game *>(); }
|
||||
};
|
||||
|
||||
class Event_AddToList : public GenericEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_AddToList(const QString &_list = QString(), ServerInfo_User *_userInfo = 0);
|
||||
int getItemId() const { return ItemId_Event_AddToList; }
|
||||
static SerializableItem *newItem() { return new Event_AddToList; }
|
||||
ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
|
||||
QString getList() const { return static_cast<SerializableItem_String *>(itemMap.value("list"))->getData(); }
|
||||
};
|
||||
|
||||
class Event_UserJoined : public GenericEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_UserJoined(ServerInfo_User *_userInfo = 0);
|
||||
int getItemId() const { return ItemId_Event_UserJoined; }
|
||||
static SerializableItem *newItem() { return new Event_UserJoined; }
|
||||
ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
|
||||
};
|
||||
|
||||
class Event_Join : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_Join(ServerInfo_PlayerProperties *player = 0);
|
||||
static SerializableItem *newItem() { return new Event_Join; }
|
||||
int getItemId() const { return ItemId_Event_Join; }
|
||||
ServerInfo_PlayerProperties *getPlayer() const { return static_cast<ServerInfo_PlayerProperties *>(itemMap.value("player_properties")); }
|
||||
};
|
||||
|
||||
class Event_GameStateChanged : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_GameStateChanged(bool _gameStarted = false, int _activePlayer = -1, int _activePhase = -1, const QList<ServerInfo_Player *> &_playerList = QList<ServerInfo_Player *>());
|
||||
static SerializableItem *newItem() { return new Event_GameStateChanged; }
|
||||
int getItemId() const { return ItemId_Event_GameStateChanged; }
|
||||
QList<ServerInfo_Player *> getPlayerList() const { return typecastItemList<ServerInfo_Player *>(); }
|
||||
bool getGameStarted() const { return static_cast<SerializableItem_Bool *>(itemMap.value("game_started"))->getData(); }
|
||||
int getActivePlayer() const { return static_cast<SerializableItem_Int *>(itemMap.value("active_player"))->getData(); }
|
||||
int getActivePhase() const { return static_cast<SerializableItem_Int *>(itemMap.value("active_phase"))->getData(); }
|
||||
};
|
||||
|
||||
class Event_PlayerPropertiesChanged : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_PlayerPropertiesChanged(int _playerId = -1, ServerInfo_PlayerProperties *_properties = 0);
|
||||
static SerializableItem *newItem() { return new Event_PlayerPropertiesChanged; }
|
||||
int getItemId() const { return ItemId_Event_PlayerPropertiesChanged; }
|
||||
ServerInfo_PlayerProperties *getProperties() const { return static_cast<ServerInfo_PlayerProperties *>(itemMap.value("player_properties")); }
|
||||
};
|
||||
|
||||
class Event_Ping : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_Ping(int _secondsElapsed = -1, const QList<ServerInfo_PlayerPing *> &_pingList = QList<ServerInfo_PlayerPing *>());
|
||||
static SerializableItem *newItem() { return new Event_Ping; }
|
||||
int getItemId() const { return ItemId_Event_Ping; }
|
||||
int getSecondsElapsed() const { return static_cast<SerializableItem_Int *>(itemMap.value("seconds_elapsed"))->getData(); }
|
||||
QList<ServerInfo_PlayerPing *> getPingList() const { return typecastItemList<ServerInfo_PlayerPing *>(); }
|
||||
};
|
||||
|
||||
class Event_CreateArrows : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_CreateArrows(int _playerId = -1, const QList<ServerInfo_Arrow *> &_arrowList = QList<ServerInfo_Arrow *>());
|
||||
int getItemId() const { return ItemId_Event_CreateArrows; }
|
||||
static SerializableItem *newItem() { return new Event_CreateArrows; }
|
||||
QList<ServerInfo_Arrow *> getArrowList() const { return typecastItemList<ServerInfo_Arrow *>(); }
|
||||
};
|
||||
|
||||
class Event_CreateCounters : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_CreateCounters(int _playerId = -1, const QList<ServerInfo_Counter *> &_counterList = QList<ServerInfo_Counter *>());
|
||||
int getItemId() const { return ItemId_Event_CreateCounters; }
|
||||
static SerializableItem *newItem() { return new Event_CreateCounters; }
|
||||
QList<ServerInfo_Counter *> getCounterList() const { return typecastItemList<ServerInfo_Counter *>(); }
|
||||
};
|
||||
|
||||
class Event_DrawCards : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_DrawCards(int _playerId = -1, int numberCards = -1, const QList<ServerInfo_Card *> &_cardList = QList<ServerInfo_Card *>());
|
||||
int getItemId() const { return ItemId_Event_DrawCards; }
|
||||
static SerializableItem *newItem() { return new Event_DrawCards; }
|
||||
int getNumberCards() const { return static_cast<SerializableItem_Int *>(itemMap.value("number_cards"))->getData(); }
|
||||
QList<ServerInfo_Card *> getCardList() const { return typecastItemList<ServerInfo_Card *>(); }
|
||||
};
|
||||
|
||||
class Event_RevealCards : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_RevealCards(int _playerId = -1, const QString &_zoneName = QString(), int cardId = -1, int _otherPlayerId = -1, const QList<ServerInfo_Card *> &_cardList = QList<ServerInfo_Card *>());
|
||||
int getItemId() const { return ItemId_Event_RevealCards; }
|
||||
static SerializableItem *newItem() { return new Event_RevealCards; }
|
||||
QString getZoneName() const { return static_cast<SerializableItem_String *>(itemMap.value("zone_name"))->getData(); }
|
||||
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); }
|
||||
int getOtherPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("other_player_id"))->getData(); }
|
||||
QList<ServerInfo_Card *> getCardList() const { return typecastItemList<ServerInfo_Card *>(); }
|
||||
};
|
||||
|
||||
*/
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue