From 4eb9dfc5bfbcd5b61b7773ea48e13ee9812f10e5 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sun, 4 Dec 2011 23:21:31 +0100 Subject: [PATCH] server-side part of client -> server commands almost converted to ProtocolBuffers. not usable yet --- common/color.h | 3 + common/pb/admin_commands.proto | 21 + common/pb/color.proto | 6 + common/pb/commands.proto | 25 + common/pb/game_commands.proto | 237 ++++++++ common/pb/moderator_commands.proto | 20 + common/pb/move_card_to_zone.proto | 5 + common/pb/room_commands.proto | 46 ++ common/pb/session_commands.proto | 107 ++++ common/protocol.cpp | 24 +- common/protocol.h | 44 +- common/protocol_datastructures.cpp | 9 - common/protocol_datastructures.h | 16 +- common/protocol_item_ids.h | 124 ++-- common/protocol_items.cpp | 326 ---------- common/protocol_items.dat | 48 -- common/protocol_items.h | 422 ------------- common/server_cardzone.cpp | 16 +- common/server_cardzone.h | 6 +- common/server_player.cpp | 82 +-- common/server_player.h | 14 +- common/server_protocolhandler.cpp | 740 +++++++++++++---------- common/server_protocolhandler.h | 169 ++++-- servatrice/servatrice.pro | 24 +- servatrice/src/serversocketinterface.cpp | 106 ++-- servatrice/src/serversocketinterface.h | 29 +- 26 files changed, 1233 insertions(+), 1436 deletions(-) create mode 100644 common/pb/admin_commands.proto create mode 100644 common/pb/color.proto create mode 100644 common/pb/commands.proto create mode 100644 common/pb/game_commands.proto create mode 100644 common/pb/moderator_commands.proto create mode 100644 common/pb/move_card_to_zone.proto create mode 100644 common/pb/room_commands.proto create mode 100644 common/pb/session_commands.proto diff --git a/common/color.h b/common/color.h index af498fdb..1483ff2b 100644 --- a/common/color.h +++ b/common/color.h @@ -5,10 +5,13 @@ #include #endif +#include "pb/color.pb.h" + class Color { private: int value; public: + Color(const color &other) : value(other.r() * 65536 + other.g() * 256 + other.b()) { } // TEMPORARY HACK Color(int _value = 0) : value(_value) { } Color(int r, int g, int b) : value(r * 65536 + g * 256 + b) { } int getValue() const { return value; } diff --git a/common/pb/admin_commands.proto b/common/pb/admin_commands.proto new file mode 100644 index 00000000..e60ac4b9 --- /dev/null +++ b/common/pb/admin_commands.proto @@ -0,0 +1,21 @@ +message Command_UpdateServerMessage { +} + +message Command_ShutdownServer { + optional string reason = 1; + optional uint32 minutes = 2; +} + +message AdminCommand { + enum AdminCommandType { + UPDATE_SERVER_MESSAGE = 1000; + SHUTDOWN_SERVER = 1001; + } + extensions 100 to max; +} + +extend AdminCommand { + optional Command_UpdateServerMessage command_update_server_message = 1000; + optional Command_ShutdownServer command_shutdown_server = 1001; +} + diff --git a/common/pb/color.proto b/common/pb/color.proto new file mode 100644 index 00000000..90fdb781 --- /dev/null +++ b/common/pb/color.proto @@ -0,0 +1,6 @@ +message color { + optional uint32 r = 1; + optional uint32 g = 2; + optional uint32 b = 3; + optional uint32 a = 4; +} \ No newline at end of file diff --git a/common/pb/commands.proto b/common/pb/commands.proto new file mode 100644 index 00000000..57ef67a9 --- /dev/null +++ b/common/pb/commands.proto @@ -0,0 +1,25 @@ +import "session_commands.proto"; +import "game_commands.proto"; +import "room_commands.proto"; +import "moderator_commands.proto"; +import "admin_commands.proto"; + +message CommandContainer { + enum CommandType { + SESSION = 0; + GAME = 1; + ROOM = 2; + MODERATOR = 3; + ADMIN = 4; + } + required uint64 cmd_id = 1; + + optional uint32 game_id = 10; + optional uint32 room_id = 20; + + repeated SessionCommand session_command = 100; + repeated GameCommand game_command = 101; + repeated RoomCommand room_command = 102; + repeated ModeratorCommand moderator_command = 103; + repeated AdminCommand admin_command = 104; +} diff --git a/common/pb/game_commands.proto b/common/pb/game_commands.proto new file mode 100644 index 00000000..e33a31f0 --- /dev/null +++ b/common/pb/game_commands.proto @@ -0,0 +1,237 @@ +import "color.proto"; +import "move_card_to_zone.proto"; + +message Command_KickFromGame { + optional sint32 player_id = 1; +} + +message Command_LeaveGame { +} + +message Command_GameSay { + optional string message = 1; +} + +message Command_Shuffle { +} + +message Command_Mulligan { +} + +message Command_RollDie { + optional uint32 sides = 1; +} + +message Command_DrawCards { + optional uint32 number = 1; +} + +message Command_UndoDraw { +} + +message Command_FlipCard { + optional string zone = 1; + optional sint32 card_id = 2; + optional bool face_down = 3; +} + +message Command_AttachCard { + optional string start_zone = 1; + optional sint32 card_id = 2; + optional sint32 target_player_id = 3; + optional string target_zone = 4; + optional sint32 target_card_id = 5; +} + +message Command_CreateToken { + optional string zone = 1; + optional string card_name = 2; + optional string color = 3; + optional string pt = 4; + optional string annotation = 5; + optional bool destroy_on_zone_change = 6; + optional sint32 x = 7; + optional sint32 y = 8; +} + +message Command_CreateArrow { + optional sint32 start_player_id = 1; + optional string start_zone = 2; + optional sint32 start_card_id = 3; + optional sint32 target_player_id = 4; + optional string target_zone = 5; + optional sint32 target_card_id = 6; + optional color arrow_color = 7; +} + +message Command_DeleteArrow { + optional sint32 arrow_id = 1; +} + +message Command_SetCardAttr { + optional string zone = 1; + optional sint32 card_id = 2; + optional string attr_name = 3; + optional string attr_value = 4; +} + +message Command_SetCardCounter { + optional string zone = 1; + optional sint32 card_id = 2; + optional sint32 counter_id = 3; + optional sint32 counter_value = 4; +} + +message Command_IncCardCounter { + optional string zone = 1; + optional sint32 card_id = 2; + optional sint32 counter_id = 3; + optional sint32 counter_delta = 4; +} + +message Command_ReadyStart { + optional bool ready = 1; +} + +message Command_Concede { +} + +message Command_IncCounter { + optional sint32 counter_id = 1; + optional sint32 delta = 2; +} + +message Command_CreateCounter { + optional string counter_name = 1; + optional color counter_color = 2; + optional uint32 radius = 3; + optional sint32 value = 4; +} + +message Command_SetCounter { + optional sint32 counter_id = 1; + optional sint32 value = 2; +} + +message Command_DelCounter { + optional sint32 counter_id = 1; +} + +message Command_NextTurn { +} + +message Command_SetActivePhase { + optional uint32 phase = 1; +} + +message Command_DumpZone { + optional sint32 player_id = 1; + optional string zone_name = 2; + optional sint32 number_cards = 3; +} + +message Command_StopDumpZone { + optional sint32 player_id = 1; + optional string zone_name = 2; +} + +message Command_RevealCards { + optional string zone_name = 1; + optional sint32 card_id = 2; + optional sint32 player_id = 3; +} + +message CardToMove { + optional sint32 card_id = 1; + optional bool face_down = 2; + optional string pt = 3; + optional bool tapped = 4; +} + +message Command_MoveCard { + optional string start_zone = 1; + repeated CardToMove cards_to_move = 2; + optional sint32 target_player_id = 3; + optional string target_zone = 4; + optional sint32 x = 5; + optional sint32 y = 6; +} + +message Command_SetSideboardPlan { + repeated MoveCard_ToZone move_list = 1; +} + +message Command_DeckSelect { + optional string deck = 1; + optional sint32 deck_id = 2; +} + +message GameCommand { + enum GameCommandType { + KICK_FROM_GAME = 1000; + LEAVE_GAME = 1001; + GAME_SAY = 1002; + SHUFFLE = 1003; + MULLIGAN = 1004; + ROLL_DIE = 1005; + DRAW_CARDS = 1006; + UNDO_DRAW = 1007; + FLIP_CARD = 1008; + ATTACH_CARD = 1009; + CREATE_TOKEN = 1010; + CREATE_ARROW = 1011; + DELETE_ARROW = 1012; + SET_CARD_ATTR = 1013; + SET_CARD_COUNTER = 1014; + INC_CARD_COUNTER = 1015; + READY_START = 1016; + CONCEDE = 1017; + INC_COUNTER = 1018; + CREATE_COUNTER = 1019; + SET_COUNTER = 1020; + DEL_COUNTER = 1021; + NEXT_TURN = 1022; + SET_ACTIVE_PHASE = 1023; + DUMP_ZONE = 1024; + STOP_DUMP_ZONE = 1025; + REVEAL_CARDS = 1026; + MOVE_CARD = 1027; + SET_SIDEBOARD_PLAN = 1028; + DECK_SELECT = 1029; + } + extensions 100 to max; +} + +extend GameCommand { + optional Command_KickFromGame command_kick_from_game = 1000; + optional Command_LeaveGame command_leave_game = 1001; + optional Command_GameSay command_game_say = 1002; + optional Command_Shuffle command_shuffle = 1003; + optional Command_Mulligan command_mulligan = 1004; + optional Command_RollDie command_roll_die = 1005; + optional Command_DrawCards command_draw_cards = 1006; + optional Command_UndoDraw command_undo_draw = 1007; + optional Command_FlipCard command_flip_card = 1008; + optional Command_AttachCard command_attach_card = 1009; + optional Command_CreateToken command_create_token = 1010; + optional Command_CreateArrow command_create_arrow = 1011; + optional Command_DeleteArrow command_delete_arrow = 1012; + optional Command_SetCardAttr command_set_card_attr = 1013; + optional Command_SetCardCounter command_set_card_counter = 1014; + optional Command_IncCardCounter command_inc_card_counter = 1015; + optional Command_ReadyStart command_ready_start = 1016; + optional Command_Concede command_concede = 1017; + optional Command_IncCounter command_inc_counter = 1018; + optional Command_CreateCounter command_create_counter = 1019; + optional Command_SetCounter command_set_counter = 1020; + optional Command_DelCounter command_del_counter = 1021; + optional Command_NextTurn command_next_turn = 1022; + optional Command_SetActivePhase command_set_active_phase = 1023; + optional Command_DumpZone command_dump_zone = 1024; + optional Command_StopDumpZone command_stop_dump_zone = 1025; + optional Command_RevealCards command_reveal_cards = 1026; + optional Command_MoveCard command_move_card = 1027; + optional Command_SetSideboardPlan command_set_sideboard_plan = 1028; + optional Command_DeckSelect command_deck_select = 1029; +} + diff --git a/common/pb/moderator_commands.proto b/common/pb/moderator_commands.proto new file mode 100644 index 00000000..61e896ce --- /dev/null +++ b/common/pb/moderator_commands.proto @@ -0,0 +1,20 @@ + + +message Command_BanFromServer { + optional string user_name = 1; + optional string address = 2; + optional uint32 minutes = 3; + optional string reason = 4; +} + +message ModeratorCommand { + enum ModeratorCommandType { + BAN_FROM_SERVER = 1000; + } + extensions 100 to max; +} + +extend ModeratorCommand { + optional Command_BanFromServer command_ban_from_server = 1000; +} + diff --git a/common/pb/move_card_to_zone.proto b/common/pb/move_card_to_zone.proto new file mode 100644 index 00000000..edb03219 --- /dev/null +++ b/common/pb/move_card_to_zone.proto @@ -0,0 +1,5 @@ +message MoveCard_ToZone { + optional string card_name = 1; + optional string start_zone = 2; + optional string target_zone = 3; +} diff --git a/common/pb/room_commands.proto b/common/pb/room_commands.proto new file mode 100644 index 00000000..23fc353c --- /dev/null +++ b/common/pb/room_commands.proto @@ -0,0 +1,46 @@ + +message Command_LeaveRoom { +} + +message Command_RoomSay { + optional string message = 1; +} + +message Command_CreateGame { + optional string description = 1; + optional string password = 2; + optional uint32 max_players = 3; + optional bool only_buddies = 4; + optional bool only_registered = 5; + optional bool spectators_allowed = 6; + optional bool spectators_need_password = 7; + optional bool spectators_can_talk = 8; + optional bool spectators_see_everything = 9; + repeated uint32 game_type_ids = 10; +} + +message Command_JoinGame { + optional uint32 game_id = 1; + optional string password = 2; + optional bool spectator = 3; + optional bool override_restrictions = 4; +} + +message RoomCommand { + enum RoomCommandType { + LEAVE_ROOM = 1000; + ROOM_SAY = 1001; + CREATE_GAME = 1002; + JOIN_GAME = 1003; + } + extensions 100 to max; +} + +extend RoomCommand { + optional Command_LeaveRoom command_leave_room = 1000; + optional Command_RoomSay command_room_say = 1001; + optional Command_CreateGame command_create_game = 1002; + optional Command_JoinGame command_join_game = 1003; +} + + diff --git a/common/pb/session_commands.proto b/common/pb/session_commands.proto new file mode 100644 index 00000000..0c19214f --- /dev/null +++ b/common/pb/session_commands.proto @@ -0,0 +1,107 @@ +message Command_Ping { +} + +message Command_Login { + optional string user_name = 1; + optional string password = 2; +} + +message Command_Message { + optional string user_name = 1; + optional string message = 2; +} + +message Command_ListUsers { +} + +message Command_GetGamesOfUser { + optional string user_name = 1; +} + +message Command_GetUserInfo { + optional string user_name = 1; +} + +message Command_AddToList { + optional string list = 1; + optional string user_name = 2; +} + +message Command_RemoveFromList { + optional string list = 1; + optional string user_name = 2; +} + +message Command_DeckList { +} + +message Command_DeckNewDir { + optional string path = 1; + optional string dir_name = 2; +} + +message Command_DeckDelDir { + optional string path = 1; +} + +message Command_DeckDel { + optional uint32 deck_id = 1; +} + +message Command_DeckDownload { + optional uint32 deck_id = 1; +} + +message Command_DeckUpload { + optional string path = 1; + optional string deck_list = 2; +} + +message Command_ListRooms { +} + +message Command_JoinRoom { + optional uint32 room_id = 1; +} + +message SessionCommand { + enum SessionCommandType { + PING = 1000; + LOGIN = 1001; + MESSAGE = 1002; + LIST_USERS = 1003; + GET_GAMES_OF_USER = 1004; + GET_USER_INFO = 1005; + ADD_TO_LIST = 1006; + REMOVE_FROM_LIST = 1007; + DECK_LIST = 1008; + DECK_NEW_DIR = 1009; + DECK_DEL_DIR = 1010; + DECK_DEL = 1011; + DECK_DOWNLOAD = 1012; + DECK_UPLOAD = 1013; + LIST_ROOMS = 1014; + JOIN_ROOM = 1015; + } + extensions 100 to max; +} + +extend SessionCommand { + optional Command_Ping command_ping = 1000; + optional Command_Login command_login = 1001; + optional Command_Message command_message = 1002; + optional Command_ListUsers command_list_users = 1003; + optional Command_GetGamesOfUser command_get_games_of_user = 1004; + optional Command_GetUserInfo command_get_user_info = 1005; + optional Command_AddToList command_add_to_list = 1006; + optional Command_RemoveFromList command_remove_from_list = 1007; + optional Command_DeckList command_deck_list = 1008; + optional Command_DeckNewDir command_deck_new_dir = 1009; + optional Command_DeckDelDir command_deck_del_dir = 1010; + optional Command_DeckDel command_deck_del = 1011; + optional Command_DeckDownload command_deck_download = 1012; + optional Command_DeckUpload command_deck_upload = 1013; + optional Command_ListRooms command_list_rooms = 1014; + optional Command_JoinRoom command_join_room = 1015; +} + diff --git a/common/protocol.cpp b/common/protocol.cpp index 23b3deb7..cdf00ba5 100644 --- a/common/protocol.cpp +++ b/common/protocol.cpp @@ -28,9 +28,9 @@ void ProtocolItem::initializeHash() registerSerializableItem("player_ping", ServerInfo_PlayerPing::newItem); registerSerializableItem("file", DeckList_File::newItem); registerSerializableItem("directory", DeckList_Directory::newItem); - registerSerializableItem("card_to_move", CardToMove::newItem); +// registerSerializableItem("card_to_move", CardToMove::newItem); registerSerializableItem("game_type_id", GameTypeId::newItem); - +/* registerSerializableItem("containercmd", CommandContainer::newItem); registerSerializableItem("containergame_event", GameEventContainer::newItem); @@ -39,7 +39,7 @@ void ProtocolItem::initializeHash() registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem); registerSerializableItem("cmdset_sideboard_plan", Command_SetSideboardPlan::newItem); registerSerializableItem("cmdmove_card", Command_MoveCard::newItem); - +*/ registerSerializableItem("resp", ProtocolResponse::newItem); ProtocolResponse::initializeHash(); registerSerializableItem("respjoin_room", Response_JoinRoom::newItem); @@ -105,6 +105,7 @@ void TopLevelProtocolItem::writeElement(QXmlStreamWriter * /*xml*/) { } +/* int CommandContainer::lastCmdId = 0; Command::Command(const QString &_itemName) @@ -138,14 +139,19 @@ void CommandContainer::processResponse(ProtocolResponse *response) for (int i = 0; i < cmdList.size(); ++i) cmdList[i]->processResponse(response); } +*/ +BlaContainer::BlaContainer() + : ProtocolItem("container", "cmd"), resp(0), gameEventQueuePublic(0), gameEventQueueOmniscient(0), gameEventQueuePrivate(0), privatePlayerId(-1) +{ +} -void CommandContainer::setResponse(ProtocolResponse *_resp) +void BlaContainer::setResponse(ProtocolResponse *_resp) { delete resp; resp = _resp; } -void CommandContainer::enqueueGameEventPublic(GameEvent *event, int gameId, GameEventContext *context) +void BlaContainer::enqueueGameEventPublic(GameEvent *event, int gameId, GameEventContext *context) { if (!gameEventQueuePublic) gameEventQueuePublic = new GameEventContainer(QList(), gameId); @@ -154,7 +160,7 @@ void CommandContainer::enqueueGameEventPublic(GameEvent *event, int gameId, Game gameEventQueuePublic->setContext(context); } -void CommandContainer::enqueueGameEventOmniscient(GameEvent *event, int gameId, GameEventContext *context) +void BlaContainer::enqueueGameEventOmniscient(GameEvent *event, int gameId, GameEventContext *context) { if (!gameEventQueueOmniscient) gameEventQueueOmniscient = new GameEventContainer(QList(), gameId); @@ -163,7 +169,7 @@ void CommandContainer::enqueueGameEventOmniscient(GameEvent *event, int gameId, gameEventQueueOmniscient->setContext(context); } -void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId, GameEventContext *context) +void BlaContainer::enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId, GameEventContext *context) { if (!gameEventQueuePrivate) gameEventQueuePrivate = new GameEventContainer(QList(), gameId); @@ -172,7 +178,7 @@ void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId, int if (context) gameEventQueuePrivate->setContext(context); } - +/* Command_CreateGame::Command_CreateGame(int _roomId, const QString &_description, const QString &_password, int _maxPlayers, const QList &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything) : RoomCommand("create_game", _roomId) { @@ -242,7 +248,7 @@ Command_MoveCard::Command_MoveCard(int _gameId, const QString &_startZone, const for (int i = 0; i < _cards.size(); ++i) itemList.append(_cards[i]); } - +*/ QHash ProtocolResponse::responseHash; ProtocolResponse::ProtocolResponse(int _cmdId, ResponseCode _responseCode, const QString &_itemName) diff --git a/common/protocol.h b/common/protocol.h index e95c2189..db9b3ae0 100644 --- a/common/protocol.h +++ b/common/protocol.h @@ -91,7 +91,7 @@ public: // ---------------- // --- COMMANDS --- // ---------------- - +/* class Command : public ProtocolItem { Q_OBJECT signals: @@ -105,17 +105,10 @@ public: QVariant getExtraData() const { return extraData; } void processResponse(ProtocolResponse *response); }; - -class CommandContainer : public ProtocolItem { +*/ +class BlaContainer : public ProtocolItem { Q_OBJECT -signals: - void finished(ProtocolResponse *response); - void finished(ResponseCode response); private: - int ticks; - static int lastCmdId; - - // XXX Move these out. They are only for processing inside the server. ProtocolResponse *resp; QList itemQueue; GameEventContext *gameEventContext; @@ -124,13 +117,8 @@ private: GameEventContainer *gameEventQueuePrivate; int privatePlayerId; public: - CommandContainer(const QList &_commandList = QList(), int _cmdId = -1); - static SerializableItem *newItem() { return new CommandContainer; } - int getItemId() const { return ItemId_CommandContainer; } - int getCmdId() const { return static_cast(itemMap.value("cmd_id"))->getData(); } - int tick() { return ++ticks; } - void processResponse(ProtocolResponse *response); - QList getCommandList() const { return typecastItemList(); } + BlaContainer(); + int getItemId() const { return 102332456; } ProtocolResponse *getResponse() const { return resp; } void setResponse(ProtocolResponse *_resp); @@ -144,7 +132,7 @@ public: void enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId = -1, GameEventContext *context = 0); int getPrivatePlayerId() const { return privatePlayerId; } }; - +/* class RoomCommand : public Command { Q_OBJECT public: @@ -186,24 +174,6 @@ public: } }; -class Command_CreateGame : public RoomCommand { - Q_OBJECT -public: - Command_CreateGame(int _roomId = -1, const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, const QList &_gameTypes = QList(), bool _onlyBuddies = false, bool _onlyRegistered = false, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, bool _spectatorsCanTalk = false, bool _spectatorsSeeEverything = false); - QString getDescription() const { return static_cast(itemMap.value("description"))->getData(); }; - QString getPassword() const { return static_cast(itemMap.value("password"))->getData(); }; - int getMaxPlayers() const { return static_cast(itemMap.value("max_players"))->getData(); }; - bool getOnlyBuddies() const { return static_cast(itemMap.value("only_buddies"))->getData(); }; - bool getOnlyRegistered() const { return static_cast(itemMap.value("only_registered"))->getData(); }; - bool getSpectatorsAllowed() const { return static_cast(itemMap.value("spectators_allowed"))->getData(); }; - bool getSpectatorsNeedPassword() const { return static_cast(itemMap.value("spectators_need_password"))->getData(); }; - bool getSpectatorsCanTalk() const { return static_cast(itemMap.value("spectators_can_talk"))->getData(); }; - bool getSpectatorsSeeEverything() const { return static_cast(itemMap.value("spectators_see_everything"))->getData(); }; - QList getGameTypes() const { return typecastItemList(); } - static SerializableItem *newItem() { return new Command_CreateGame; } - int getItemId() const { return ItemId_Command_CreateGame; } -}; - class Command_DeckUpload : public Command { Q_OBJECT public: @@ -246,7 +216,7 @@ public: static SerializableItem *newItem() { return new Command_MoveCard; } int getItemId() const { return ItemId_Command_MoveCard; } }; - +*/ // ----------------- // --- RESPONSES --- // ----------------- diff --git a/common/protocol_datastructures.cpp b/common/protocol_datastructures.cpp index 62f52182..5c8e4302 100644 --- a/common/protocol_datastructures.cpp +++ b/common/protocol_datastructures.cpp @@ -3,15 +3,6 @@ #include #include -CardToMove::CardToMove(int _cardId, bool _faceDown, const QString &_pt, bool _tapped) - : SerializableItem_Map("card_to_move") -{ - insertItem(new SerializableItem_Int("card_id", _cardId)); - insertItem(new SerializableItem_Bool("facedown", _faceDown)); - insertItem(new SerializableItem_String("pt", _pt)); - insertItem(new SerializableItem_Bool("tapped", _tapped)); -} - ServerInfo_User::ServerInfo_User(const QString &_name, int _userLevel, const QString &_address, const QString &_realName, Gender _gender, const QString &_country, const QByteArray &_avatarBmp) : SerializableItem_Map("user") { diff --git a/common/protocol_datastructures.h b/common/protocol_datastructures.h index 70522706..b26d5f1a 100644 --- a/common/protocol_datastructures.h +++ b/common/protocol_datastructures.h @@ -20,22 +20,14 @@ enum ResponseCode { RespNothing, RespOk, RespNotInRoom, RespInternalError, RespI // list index, whereas cards in any other zone are referenced by their ids. enum ZoneType { PrivateZone, PublicZone, HiddenZone }; -class CardToMove : public SerializableItem_Map { -public: - CardToMove(int _cardId = -1, bool _faceDown = false, const QString &_pt = QString(), bool _tapped = false); - static SerializableItem *newItem() { return new CardToMove; } - int getCardId() const { return static_cast(itemMap.value("card_id"))->getData(); } - bool getFaceDown() const { return static_cast(itemMap.value("facedown"))->getData(); } - QString getPT() const { return static_cast(itemMap.value("pt"))->getData(); } - bool getTapped() const { return static_cast(itemMap.value("tapped"))->getData(); } -}; - class GameTypeId : public SerializableItem_Int { public: - GameTypeId(int _gameTypeId = -1) : SerializableItem_Int("game_type_id", _gameTypeId) { } - static SerializableItem *newItem() { return new GameTypeId; } +GameTypeId(int _gameTypeId = -1) : SerializableItem_Int("game_type_id", _gameTypeId) { } +static SerializableItem *newItem() { return new GameTypeId; } }; + + class ServerInfo_User : public SerializableItem_Map { public: enum UserLevelFlags { diff --git a/common/protocol_item_ids.h b/common/protocol_item_ids.h index 0187628f..9c7856e3 100644 --- a/common/protocol_item_ids.h +++ b/common/protocol_item_ids.h @@ -1,88 +1,40 @@ enum AutoItemId { -ItemId_Command_Ping = 1001, -ItemId_Command_Login = 1002, -ItemId_Command_Message = 1003, -ItemId_Command_ListUsers = 1004, -ItemId_Command_GetGamesOfUser = 1005, -ItemId_Command_GetUserInfo = 1006, -ItemId_Command_AddToList = 1007, -ItemId_Command_RemoveFromList = 1008, -ItemId_Command_DeckList = 1009, -ItemId_Command_DeckNewDir = 1010, -ItemId_Command_DeckDelDir = 1011, -ItemId_Command_DeckDel = 1012, -ItemId_Command_DeckDownload = 1013, -ItemId_Command_ListRooms = 1014, -ItemId_Command_JoinRoom = 1015, -ItemId_Command_LeaveRoom = 1016, -ItemId_Command_RoomSay = 1017, -ItemId_Command_JoinGame = 1018, -ItemId_Command_KickFromGame = 1019, -ItemId_Command_LeaveGame = 1020, -ItemId_Command_Say = 1021, -ItemId_Command_Shuffle = 1022, -ItemId_Command_Mulligan = 1023, -ItemId_Command_RollDie = 1024, -ItemId_Command_DrawCards = 1025, -ItemId_Command_UndoDraw = 1026, -ItemId_Command_FlipCard = 1027, -ItemId_Command_AttachCard = 1028, -ItemId_Command_CreateToken = 1029, -ItemId_Command_CreateArrow = 1030, -ItemId_Command_DeleteArrow = 1031, -ItemId_Command_SetCardAttr = 1032, -ItemId_Command_SetCardCounter = 1033, -ItemId_Command_IncCardCounter = 1034, -ItemId_Command_ReadyStart = 1035, -ItemId_Command_Concede = 1036, -ItemId_Command_IncCounter = 1037, -ItemId_Command_CreateCounter = 1038, -ItemId_Command_SetCounter = 1039, -ItemId_Command_DelCounter = 1040, -ItemId_Command_NextTurn = 1041, -ItemId_Command_SetActivePhase = 1042, -ItemId_Command_DumpZone = 1043, -ItemId_Command_StopDumpZone = 1044, -ItemId_Command_RevealCards = 1045, -ItemId_Event_ConnectionStateChanged = 1046, -ItemId_Event_Say = 1047, -ItemId_Event_Leave = 1048, -ItemId_Event_GameClosed = 1049, -ItemId_Event_GameHostChanged = 1050, -ItemId_Event_Kicked = 1051, -ItemId_Event_Shuffle = 1052, -ItemId_Event_RollDie = 1053, -ItemId_Event_MoveCard = 1054, -ItemId_Event_FlipCard = 1055, -ItemId_Event_DestroyCard = 1056, -ItemId_Event_AttachCard = 1057, -ItemId_Event_CreateToken = 1058, -ItemId_Event_DeleteArrow = 1059, -ItemId_Event_SetCardAttr = 1060, -ItemId_Event_SetCardCounter = 1061, -ItemId_Event_SetCounter = 1062, -ItemId_Event_DelCounter = 1063, -ItemId_Event_SetActivePlayer = 1064, -ItemId_Event_SetActivePhase = 1065, -ItemId_Event_DumpZone = 1066, -ItemId_Event_StopDumpZone = 1067, -ItemId_Event_RemoveFromList = 1068, -ItemId_Event_ServerMessage = 1069, -ItemId_Event_ServerShutdown = 1070, -ItemId_Event_ConnectionClosed = 1071, -ItemId_Event_Message = 1072, -ItemId_Event_GameJoined = 1073, -ItemId_Event_UserLeft = 1074, -ItemId_Event_LeaveRoom = 1075, -ItemId_Event_RoomSay = 1076, -ItemId_Context_ReadyStart = 1077, -ItemId_Context_Concede = 1078, -ItemId_Context_DeckSelect = 1079, -ItemId_Context_UndoDraw = 1080, -ItemId_Context_MoveCard = 1081, -ItemId_Context_Mulligan = 1082, -ItemId_Command_UpdateServerMessage = 1083, -ItemId_Command_ShutdownServer = 1084, -ItemId_Command_BanFromServer = 1085, -ItemId_Other = 1086 +ItemId_Event_ConnectionStateChanged = 1001, +ItemId_Event_Say = 1002, +ItemId_Event_Leave = 1003, +ItemId_Event_GameClosed = 1004, +ItemId_Event_GameHostChanged = 1005, +ItemId_Event_Kicked = 1006, +ItemId_Event_Shuffle = 1007, +ItemId_Event_RollDie = 1008, +ItemId_Event_MoveCard = 1009, +ItemId_Event_FlipCard = 1010, +ItemId_Event_DestroyCard = 1011, +ItemId_Event_AttachCard = 1012, +ItemId_Event_CreateToken = 1013, +ItemId_Event_DeleteArrow = 1014, +ItemId_Event_SetCardAttr = 1015, +ItemId_Event_SetCardCounter = 1016, +ItemId_Event_SetCounter = 1017, +ItemId_Event_DelCounter = 1018, +ItemId_Event_SetActivePlayer = 1019, +ItemId_Event_SetActivePhase = 1020, +ItemId_Event_DumpZone = 1021, +ItemId_Event_StopDumpZone = 1022, +ItemId_Event_RemoveFromList = 1023, +ItemId_Event_ServerMessage = 1024, +ItemId_Event_ServerShutdown = 1025, +ItemId_Event_ConnectionClosed = 1026, +ItemId_Event_Message = 1027, +ItemId_Event_GameJoined = 1028, +ItemId_Event_UserLeft = 1029, +ItemId_Event_LeaveRoom = 1030, +ItemId_Event_RoomSay = 1031, +ItemId_Context_ReadyStart = 1032, +ItemId_Context_Concede = 1033, +ItemId_Context_DeckSelect = 1034, +ItemId_Context_UndoDraw = 1035, +ItemId_Context_MoveCard = 1036, +ItemId_Context_Mulligan = 1037, +ItemId_Other = 1038 }; diff --git a/common/protocol_items.cpp b/common/protocol_items.cpp index d46e8887..1f40f5ce 100644 --- a/common/protocol_items.cpp +++ b/common/protocol_items.cpp @@ -1,266 +1,6 @@ #include "protocol.h" #include "protocol_items.h" -Command_Ping::Command_Ping() - : Command("ping") -{ -} -Command_Login::Command_Login(const QString &_username, const QString &_password) - : Command("login") -{ - insertItem(new SerializableItem_String("username", _username)); - insertItem(new SerializableItem_String("password", _password)); -} -Command_Message::Command_Message(const QString &_userName, const QString &_text) - : Command("message") -{ - insertItem(new SerializableItem_String("user_name", _userName)); - insertItem(new SerializableItem_String("text", _text)); -} -Command_ListUsers::Command_ListUsers() - : Command("list_users") -{ -} -Command_GetGamesOfUser::Command_GetGamesOfUser(const QString &_userName) - : Command("get_games_of_user") -{ - insertItem(new SerializableItem_String("user_name", _userName)); -} -Command_GetUserInfo::Command_GetUserInfo(const QString &_userName) - : Command("get_user_info") -{ - insertItem(new SerializableItem_String("user_name", _userName)); -} -Command_AddToList::Command_AddToList(const QString &_list, const QString &_userName) - : Command("add_to_list") -{ - insertItem(new SerializableItem_String("list", _list)); - insertItem(new SerializableItem_String("user_name", _userName)); -} -Command_RemoveFromList::Command_RemoveFromList(const QString &_list, const QString &_userName) - : Command("remove_from_list") -{ - insertItem(new SerializableItem_String("list", _list)); - insertItem(new SerializableItem_String("user_name", _userName)); -} -Command_DeckList::Command_DeckList() - : Command("deck_list") -{ -} -Command_DeckNewDir::Command_DeckNewDir(const QString &_path, const QString &_dirName) - : Command("deck_new_dir") -{ - insertItem(new SerializableItem_String("path", _path)); - insertItem(new SerializableItem_String("dir_name", _dirName)); -} -Command_DeckDelDir::Command_DeckDelDir(const QString &_path) - : Command("deck_del_dir") -{ - insertItem(new SerializableItem_String("path", _path)); -} -Command_DeckDel::Command_DeckDel(int _deckId) - : Command("deck_del") -{ - insertItem(new SerializableItem_Int("deck_id", _deckId)); -} -Command_DeckDownload::Command_DeckDownload(int _deckId) - : Command("deck_download") -{ - insertItem(new SerializableItem_Int("deck_id", _deckId)); -} -Command_ListRooms::Command_ListRooms() - : Command("list_rooms") -{ -} -Command_JoinRoom::Command_JoinRoom(int _roomId) - : Command("join_room") -{ - insertItem(new SerializableItem_Int("room_id", _roomId)); -} -Command_LeaveRoom::Command_LeaveRoom(int _roomId) - : RoomCommand("leave_room", _roomId) -{ -} -Command_RoomSay::Command_RoomSay(int _roomId, const QString &_message) - : RoomCommand("room_say", _roomId) -{ - insertItem(new SerializableItem_String("message", _message)); -} -Command_JoinGame::Command_JoinGame(int _roomId, int _gameId, const QString &_password, bool _spectator, bool _overrideRestrictions) - : RoomCommand("join_game", _roomId) -{ - insertItem(new SerializableItem_Int("game_id", _gameId)); - insertItem(new SerializableItem_String("password", _password)); - insertItem(new SerializableItem_Bool("spectator", _spectator)); - insertItem(new SerializableItem_Bool("override_restrictions", _overrideRestrictions)); -} -Command_KickFromGame::Command_KickFromGame(int _gameId, int _playerId) - : GameCommand("kick_from_game", _gameId) -{ - insertItem(new SerializableItem_Int("player_id", _playerId)); -} -Command_LeaveGame::Command_LeaveGame(int _gameId) - : GameCommand("leave_game", _gameId) -{ -} -Command_Say::Command_Say(int _gameId, const QString &_message) - : GameCommand("say", _gameId) -{ - insertItem(new SerializableItem_String("message", _message)); -} -Command_Shuffle::Command_Shuffle(int _gameId) - : GameCommand("shuffle", _gameId) -{ -} -Command_Mulligan::Command_Mulligan(int _gameId) - : GameCommand("mulligan", _gameId) -{ -} -Command_RollDie::Command_RollDie(int _gameId, int _sides) - : GameCommand("roll_die", _gameId) -{ - insertItem(new SerializableItem_Int("sides", _sides)); -} -Command_DrawCards::Command_DrawCards(int _gameId, int _number) - : GameCommand("draw_cards", _gameId) -{ - insertItem(new SerializableItem_Int("number", _number)); -} -Command_UndoDraw::Command_UndoDraw(int _gameId) - : GameCommand("undo_draw", _gameId) -{ -} -Command_FlipCard::Command_FlipCard(int _gameId, const QString &_zone, int _cardId, bool _faceDown) - : GameCommand("flip_card", _gameId) -{ - insertItem(new SerializableItem_String("zone", _zone)); - insertItem(new SerializableItem_Int("card_id", _cardId)); - insertItem(new SerializableItem_Bool("face_down", _faceDown)); -} -Command_AttachCard::Command_AttachCard(int _gameId, const QString &_startZone, int _cardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId) - : GameCommand("attach_card", _gameId) -{ - insertItem(new SerializableItem_String("start_zone", _startZone)); - insertItem(new SerializableItem_Int("card_id", _cardId)); - insertItem(new SerializableItem_Int("target_player_id", _targetPlayerId)); - insertItem(new SerializableItem_String("target_zone", _targetZone)); - insertItem(new SerializableItem_Int("target_card_id", _targetCardId)); -} -Command_CreateToken::Command_CreateToken(int _gameId, const QString &_zone, const QString &_cardName, const QString &_color, const QString &_pt, const QString &_annotation, bool _destroy, int _x, int _y) - : GameCommand("create_token", _gameId) -{ - insertItem(new SerializableItem_String("zone", _zone)); - insertItem(new SerializableItem_String("card_name", _cardName)); - insertItem(new SerializableItem_String("color", _color)); - insertItem(new SerializableItem_String("pt", _pt)); - insertItem(new SerializableItem_String("annotation", _annotation)); - insertItem(new SerializableItem_Bool("destroy", _destroy)); - insertItem(new SerializableItem_Int("x", _x)); - insertItem(new SerializableItem_Int("y", _y)); -} -Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const Color &_color) - : GameCommand("create_arrow", _gameId) -{ - insertItem(new SerializableItem_Int("start_player_id", _startPlayerId)); - insertItem(new SerializableItem_String("start_zone", _startZone)); - insertItem(new SerializableItem_Int("start_card_id", _startCardId)); - insertItem(new SerializableItem_Int("target_player_id", _targetPlayerId)); - insertItem(new SerializableItem_String("target_zone", _targetZone)); - insertItem(new SerializableItem_Int("target_card_id", _targetCardId)); - insertItem(new SerializableItem_Color("color", _color)); -} -Command_DeleteArrow::Command_DeleteArrow(int _gameId, int _arrowId) - : GameCommand("delete_arrow", _gameId) -{ - insertItem(new SerializableItem_Int("arrow_id", _arrowId)); -} -Command_SetCardAttr::Command_SetCardAttr(int _gameId, const QString &_zone, int _cardId, const QString &_attrName, const QString &_attrValue) - : GameCommand("set_card_attr", _gameId) -{ - insertItem(new SerializableItem_String("zone", _zone)); - insertItem(new SerializableItem_Int("card_id", _cardId)); - insertItem(new SerializableItem_String("attr_name", _attrName)); - insertItem(new SerializableItem_String("attr_value", _attrValue)); -} -Command_SetCardCounter::Command_SetCardCounter(int _gameId, const QString &_zone, int _cardId, int _counterId, int _counterValue) - : GameCommand("set_card_counter", _gameId) -{ - insertItem(new SerializableItem_String("zone", _zone)); - insertItem(new SerializableItem_Int("card_id", _cardId)); - insertItem(new SerializableItem_Int("counter_id", _counterId)); - insertItem(new SerializableItem_Int("counter_value", _counterValue)); -} -Command_IncCardCounter::Command_IncCardCounter(int _gameId, const QString &_zone, int _cardId, int _counterId, int _counterDelta) - : GameCommand("inc_card_counter", _gameId) -{ - insertItem(new SerializableItem_String("zone", _zone)); - insertItem(new SerializableItem_Int("card_id", _cardId)); - insertItem(new SerializableItem_Int("counter_id", _counterId)); - insertItem(new SerializableItem_Int("counter_delta", _counterDelta)); -} -Command_ReadyStart::Command_ReadyStart(int _gameId, bool _ready) - : GameCommand("ready_start", _gameId) -{ - insertItem(new SerializableItem_Bool("ready", _ready)); -} -Command_Concede::Command_Concede(int _gameId) - : GameCommand("concede", _gameId) -{ -} -Command_IncCounter::Command_IncCounter(int _gameId, int _counterId, int _delta) - : GameCommand("inc_counter", _gameId) -{ - insertItem(new SerializableItem_Int("counter_id", _counterId)); - insertItem(new SerializableItem_Int("delta", _delta)); -} -Command_CreateCounter::Command_CreateCounter(int _gameId, const QString &_counterName, const Color &_color, int _radius, int _value) - : GameCommand("create_counter", _gameId) -{ - insertItem(new SerializableItem_String("counter_name", _counterName)); - insertItem(new SerializableItem_Color("color", _color)); - insertItem(new SerializableItem_Int("radius", _radius)); - insertItem(new SerializableItem_Int("value", _value)); -} -Command_SetCounter::Command_SetCounter(int _gameId, int _counterId, int _value) - : GameCommand("set_counter", _gameId) -{ - insertItem(new SerializableItem_Int("counter_id", _counterId)); - insertItem(new SerializableItem_Int("value", _value)); -} -Command_DelCounter::Command_DelCounter(int _gameId, int _counterId) - : GameCommand("del_counter", _gameId) -{ - insertItem(new SerializableItem_Int("counter_id", _counterId)); -} -Command_NextTurn::Command_NextTurn(int _gameId) - : GameCommand("next_turn", _gameId) -{ -} -Command_SetActivePhase::Command_SetActivePhase(int _gameId, int _phase) - : GameCommand("set_active_phase", _gameId) -{ - insertItem(new SerializableItem_Int("phase", _phase)); -} -Command_DumpZone::Command_DumpZone(int _gameId, int _playerId, const QString &_zoneName, int _numberCards) - : GameCommand("dump_zone", _gameId) -{ - insertItem(new SerializableItem_Int("player_id", _playerId)); - insertItem(new SerializableItem_String("zone_name", _zoneName)); - insertItem(new SerializableItem_Int("number_cards", _numberCards)); -} -Command_StopDumpZone::Command_StopDumpZone(int _gameId, int _playerId, const QString &_zoneName) - : GameCommand("stop_dump_zone", _gameId) -{ - insertItem(new SerializableItem_Int("player_id", _playerId)); - insertItem(new SerializableItem_String("zone_name", _zoneName)); -} -Command_RevealCards::Command_RevealCards(int _gameId, const QString &_zoneName, int _cardId, int _playerId) - : GameCommand("reveal_cards", _gameId) -{ - insertItem(new SerializableItem_String("zone_name", _zoneName)); - insertItem(new SerializableItem_Int("card_id", _cardId)); - insertItem(new SerializableItem_Int("player_id", _playerId)); -} Event_ConnectionStateChanged::Event_ConnectionStateChanged(int _playerId, bool _connected) : GameEvent("connection_state_changed", _playerId) { @@ -485,71 +225,8 @@ Context_Mulligan::Context_Mulligan(int _number) { insertItem(new SerializableItem_Int("number", _number)); } -Command_UpdateServerMessage::Command_UpdateServerMessage() - : AdminCommand("update_server_message") -{ -} -Command_ShutdownServer::Command_ShutdownServer(const QString &_reason, int _minutes) - : AdminCommand("shutdown_server") -{ - insertItem(new SerializableItem_String("reason", _reason)); - insertItem(new SerializableItem_Int("minutes", _minutes)); -} -Command_BanFromServer::Command_BanFromServer(const QString &_userName, const QString &_address, int _minutes, const QString &_reason) - : ModeratorCommand("ban_from_server") -{ - insertItem(new SerializableItem_String("user_name", _userName)); - insertItem(new SerializableItem_String("address", _address)); - insertItem(new SerializableItem_Int("minutes", _minutes)); - insertItem(new SerializableItem_String("reason", _reason)); -} void ProtocolItem::initializeHashAuto() { - itemNameHash.insert("cmdping", Command_Ping::newItem); - itemNameHash.insert("cmdlogin", Command_Login::newItem); - itemNameHash.insert("cmdmessage", Command_Message::newItem); - itemNameHash.insert("cmdlist_users", Command_ListUsers::newItem); - itemNameHash.insert("cmdget_games_of_user", Command_GetGamesOfUser::newItem); - itemNameHash.insert("cmdget_user_info", Command_GetUserInfo::newItem); - itemNameHash.insert("cmdadd_to_list", Command_AddToList::newItem); - itemNameHash.insert("cmdremove_from_list", Command_RemoveFromList::newItem); - itemNameHash.insert("cmddeck_list", Command_DeckList::newItem); - itemNameHash.insert("cmddeck_new_dir", Command_DeckNewDir::newItem); - itemNameHash.insert("cmddeck_del_dir", Command_DeckDelDir::newItem); - itemNameHash.insert("cmddeck_del", Command_DeckDel::newItem); - itemNameHash.insert("cmddeck_download", Command_DeckDownload::newItem); - itemNameHash.insert("cmdlist_rooms", Command_ListRooms::newItem); - itemNameHash.insert("cmdjoin_room", Command_JoinRoom::newItem); - itemNameHash.insert("cmdleave_room", Command_LeaveRoom::newItem); - itemNameHash.insert("cmdroom_say", Command_RoomSay::newItem); - itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem); - itemNameHash.insert("cmdkick_from_game", Command_KickFromGame::newItem); - itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem); - itemNameHash.insert("cmdsay", Command_Say::newItem); - itemNameHash.insert("cmdshuffle", Command_Shuffle::newItem); - itemNameHash.insert("cmdmulligan", Command_Mulligan::newItem); - itemNameHash.insert("cmdroll_die", Command_RollDie::newItem); - itemNameHash.insert("cmddraw_cards", Command_DrawCards::newItem); - itemNameHash.insert("cmdundo_draw", Command_UndoDraw::newItem); - itemNameHash.insert("cmdflip_card", Command_FlipCard::newItem); - itemNameHash.insert("cmdattach_card", Command_AttachCard::newItem); - itemNameHash.insert("cmdcreate_token", Command_CreateToken::newItem); - itemNameHash.insert("cmdcreate_arrow", Command_CreateArrow::newItem); - itemNameHash.insert("cmddelete_arrow", Command_DeleteArrow::newItem); - itemNameHash.insert("cmdset_card_attr", Command_SetCardAttr::newItem); - itemNameHash.insert("cmdset_card_counter", Command_SetCardCounter::newItem); - itemNameHash.insert("cmdinc_card_counter", Command_IncCardCounter::newItem); - itemNameHash.insert("cmdready_start", Command_ReadyStart::newItem); - itemNameHash.insert("cmdconcede", Command_Concede::newItem); - itemNameHash.insert("cmdinc_counter", Command_IncCounter::newItem); - itemNameHash.insert("cmdcreate_counter", Command_CreateCounter::newItem); - itemNameHash.insert("cmdset_counter", Command_SetCounter::newItem); - itemNameHash.insert("cmddel_counter", Command_DelCounter::newItem); - itemNameHash.insert("cmdnext_turn", Command_NextTurn::newItem); - itemNameHash.insert("cmdset_active_phase", Command_SetActivePhase::newItem); - itemNameHash.insert("cmddump_zone", Command_DumpZone::newItem); - itemNameHash.insert("cmdstop_dump_zone", Command_StopDumpZone::newItem); - itemNameHash.insert("cmdreveal_cards", Command_RevealCards::newItem); itemNameHash.insert("game_eventconnection_state_changed", Event_ConnectionStateChanged::newItem); itemNameHash.insert("game_eventsay", Event_Say::newItem); itemNameHash.insert("game_eventleave", Event_Leave::newItem); @@ -587,7 +264,4 @@ void ProtocolItem::initializeHashAuto() itemNameHash.insert("game_event_contextundo_draw", Context_UndoDraw::newItem); itemNameHash.insert("game_event_contextmove_card", Context_MoveCard::newItem); itemNameHash.insert("game_event_contextmulligan", Context_Mulligan::newItem); - itemNameHash.insert("cmdupdate_server_message", Command_UpdateServerMessage::newItem); - itemNameHash.insert("cmdshutdown_server", Command_ShutdownServer::newItem); - itemNameHash.insert("cmdban_from_server", Command_BanFromServer::newItem); } diff --git a/common/protocol_items.dat b/common/protocol_items.dat index a638db35..f92dcdc5 100644 --- a/common/protocol_items.dat +++ b/common/protocol_items.dat @@ -1,48 +1,3 @@ -0:ping -0:login:s,username:s,password -0:message:s,user_name:s,text -0:list_users -0:get_games_of_user:s,user_name -0:get_user_info:s,user_name -0:add_to_list:s,list:s,user_name -0:remove_from_list:s,list:s,user_name -0:deck_list -0:deck_new_dir:s,path:s,dir_name -0:deck_del_dir:s,path -0:deck_del:i,deck_id -0:deck_download:i,deck_id -0:list_rooms -0:join_room:i,room_id -1:leave_room -1:room_say:s,message -1:join_game:i,game_id:s,password:b,spectator:b,override_restrictions -2:kick_from_game:i,player_id -2:leave_game -2:say:s,message -2:shuffle -2:mulligan -2:roll_die:i,sides -2:draw_cards:i,number -2:undo_draw -2:flip_card:s,zone:i,card_id:b,face_down -2:attach_card:s,start_zone:i,card_id:i,target_player_id:s,target_zone:i,target_card_id -2:create_token:s,zone:s,card_name:s,color:s,pt:s,annotation:b,destroy:i,x:i,y -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:c,color -2:delete_arrow:i,arrow_id -2:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value -2:set_card_counter:s,zone:i,card_id:i,counter_id:i,counter_value -2:inc_card_counter:s,zone:i,card_id:i,counter_id:i,counter_delta -2:ready_start:b,ready -2:concede -2:inc_counter:i,counter_id:i,delta -2:create_counter:s,counter_name:c,color:i,radius:i,value -2:set_counter:i,counter_id:i,value -2:del_counter:i,counter_id -2:next_turn -2:set_active_phase:i,phase -2:dump_zone:i,player_id:s,zone_name:i,number_cards -2:stop_dump_zone:i,player_id:s,zone_name -2:reveal_cards:s,zone_name:i,card_id:i,player_id 3:connection_state_changed:b,connected 3:say:s,message 3:leave @@ -80,6 +35,3 @@ 6:undo_draw 6:move_card 6:mulligan:i,number -7:update_server_message -7:shutdown_server:s,reason:i,minutes -8:ban_from_server:s,user_name:s,address:i,minutes:s,reason diff --git a/common/protocol_items.h b/common/protocol_items.h index ac26ef71..88c900b0 100644 --- a/common/protocol_items.h +++ b/common/protocol_items.h @@ -3,401 +3,6 @@ #include "protocol.h" -class Command_Ping : public Command { - Q_OBJECT -public: - Command_Ping(); - static SerializableItem *newItem() { return new Command_Ping; } - int getItemId() const { return ItemId_Command_Ping; } -}; -class Command_Login : public Command { - Q_OBJECT -public: - Command_Login(const QString &_username = QString(), const QString &_password = QString()); - QString getUsername() const { return static_cast(itemMap.value("username"))->getData(); }; - QString getPassword() const { return static_cast(itemMap.value("password"))->getData(); }; - static SerializableItem *newItem() { return new Command_Login; } - int getItemId() const { return ItemId_Command_Login; } -}; -class Command_Message : public Command { - Q_OBJECT -public: - Command_Message(const QString &_userName = QString(), const QString &_text = QString()); - QString getUserName() const { return static_cast(itemMap.value("user_name"))->getData(); }; - QString getText() const { return static_cast(itemMap.value("text"))->getData(); }; - static SerializableItem *newItem() { return new Command_Message; } - int getItemId() const { return ItemId_Command_Message; } -}; -class Command_ListUsers : public Command { - Q_OBJECT -public: - Command_ListUsers(); - static SerializableItem *newItem() { return new Command_ListUsers; } - int getItemId() const { return ItemId_Command_ListUsers; } -}; -class Command_GetGamesOfUser : public Command { - Q_OBJECT -public: - Command_GetGamesOfUser(const QString &_userName = QString()); - QString getUserName() const { return static_cast(itemMap.value("user_name"))->getData(); }; - static SerializableItem *newItem() { return new Command_GetGamesOfUser; } - int getItemId() const { return ItemId_Command_GetGamesOfUser; } -}; -class Command_GetUserInfo : public Command { - Q_OBJECT -public: - Command_GetUserInfo(const QString &_userName = QString()); - QString getUserName() const { return static_cast(itemMap.value("user_name"))->getData(); }; - static SerializableItem *newItem() { return new Command_GetUserInfo; } - int getItemId() const { return ItemId_Command_GetUserInfo; } -}; -class Command_AddToList : public Command { - Q_OBJECT -public: - Command_AddToList(const QString &_list = QString(), const QString &_userName = QString()); - QString getList() const { return static_cast(itemMap.value("list"))->getData(); }; - QString getUserName() const { return static_cast(itemMap.value("user_name"))->getData(); }; - static SerializableItem *newItem() { return new Command_AddToList; } - int getItemId() const { return ItemId_Command_AddToList; } -}; -class Command_RemoveFromList : public Command { - Q_OBJECT -public: - Command_RemoveFromList(const QString &_list = QString(), const QString &_userName = QString()); - QString getList() const { return static_cast(itemMap.value("list"))->getData(); }; - QString getUserName() const { return static_cast(itemMap.value("user_name"))->getData(); }; - static SerializableItem *newItem() { return new Command_RemoveFromList; } - int getItemId() const { return ItemId_Command_RemoveFromList; } -}; -class Command_DeckList : public Command { - Q_OBJECT -public: - Command_DeckList(); - static SerializableItem *newItem() { return new Command_DeckList; } - int getItemId() const { return ItemId_Command_DeckList; } -}; -class Command_DeckNewDir : public Command { - Q_OBJECT -public: - Command_DeckNewDir(const QString &_path = QString(), const QString &_dirName = QString()); - QString getPath() const { return static_cast(itemMap.value("path"))->getData(); }; - QString getDirName() const { return static_cast(itemMap.value("dir_name"))->getData(); }; - static SerializableItem *newItem() { return new Command_DeckNewDir; } - int getItemId() const { return ItemId_Command_DeckNewDir; } -}; -class Command_DeckDelDir : public Command { - Q_OBJECT -public: - Command_DeckDelDir(const QString &_path = QString()); - QString getPath() const { return static_cast(itemMap.value("path"))->getData(); }; - static SerializableItem *newItem() { return new Command_DeckDelDir; } - int getItemId() const { return ItemId_Command_DeckDelDir; } -}; -class Command_DeckDel : public Command { - Q_OBJECT -public: - Command_DeckDel(int _deckId = -1); - int getDeckId() const { return static_cast(itemMap.value("deck_id"))->getData(); }; - static SerializableItem *newItem() { return new Command_DeckDel; } - int getItemId() const { return ItemId_Command_DeckDel; } -}; -class Command_DeckDownload : public Command { - Q_OBJECT -public: - Command_DeckDownload(int _deckId = -1); - int getDeckId() const { return static_cast(itemMap.value("deck_id"))->getData(); }; - static SerializableItem *newItem() { return new Command_DeckDownload; } - int getItemId() const { return ItemId_Command_DeckDownload; } -}; -class Command_ListRooms : public Command { - Q_OBJECT -public: - Command_ListRooms(); - static SerializableItem *newItem() { return new Command_ListRooms; } - int getItemId() const { return ItemId_Command_ListRooms; } -}; -class Command_JoinRoom : public Command { - Q_OBJECT -public: - Command_JoinRoom(int _roomId = -1); - int getRoomId() const { return static_cast(itemMap.value("room_id"))->getData(); }; - static SerializableItem *newItem() { return new Command_JoinRoom; } - int getItemId() const { return ItemId_Command_JoinRoom; } -}; -class Command_LeaveRoom : public RoomCommand { - Q_OBJECT -public: - Command_LeaveRoom(int _roomId = -1); - static SerializableItem *newItem() { return new Command_LeaveRoom; } - int getItemId() const { return ItemId_Command_LeaveRoom; } -}; -class Command_RoomSay : public RoomCommand { - Q_OBJECT -public: - Command_RoomSay(int _roomId = -1, const QString &_message = QString()); - QString getMessage() const { return static_cast(itemMap.value("message"))->getData(); }; - static SerializableItem *newItem() { return new Command_RoomSay; } - int getItemId() const { return ItemId_Command_RoomSay; } -}; -class Command_JoinGame : public RoomCommand { - Q_OBJECT -public: - Command_JoinGame(int _roomId = -1, int _gameId = -1, const QString &_password = QString(), bool _spectator = false, bool _overrideRestrictions = false); - int getGameId() const { return static_cast(itemMap.value("game_id"))->getData(); }; - QString getPassword() const { return static_cast(itemMap.value("password"))->getData(); }; - bool getSpectator() const { return static_cast(itemMap.value("spectator"))->getData(); }; - bool getOverrideRestrictions() const { return static_cast(itemMap.value("override_restrictions"))->getData(); }; - static SerializableItem *newItem() { return new Command_JoinGame; } - int getItemId() const { return ItemId_Command_JoinGame; } -}; -class Command_KickFromGame : public GameCommand { - Q_OBJECT -public: - Command_KickFromGame(int _gameId = -1, int _playerId = -1); - int getPlayerId() const { return static_cast(itemMap.value("player_id"))->getData(); }; - static SerializableItem *newItem() { return new Command_KickFromGame; } - int getItemId() const { return ItemId_Command_KickFromGame; } -}; -class Command_LeaveGame : public GameCommand { - Q_OBJECT -public: - Command_LeaveGame(int _gameId = -1); - static SerializableItem *newItem() { return new Command_LeaveGame; } - int getItemId() const { return ItemId_Command_LeaveGame; } -}; -class Command_Say : public GameCommand { - Q_OBJECT -public: - Command_Say(int _gameId = -1, const QString &_message = QString()); - QString getMessage() const { return static_cast(itemMap.value("message"))->getData(); }; - static SerializableItem *newItem() { return new Command_Say; } - int getItemId() const { return ItemId_Command_Say; } -}; -class Command_Shuffle : public GameCommand { - Q_OBJECT -public: - Command_Shuffle(int _gameId = -1); - static SerializableItem *newItem() { return new Command_Shuffle; } - int getItemId() const { return ItemId_Command_Shuffle; } -}; -class Command_Mulligan : public GameCommand { - Q_OBJECT -public: - Command_Mulligan(int _gameId = -1); - static SerializableItem *newItem() { return new Command_Mulligan; } - int getItemId() const { return ItemId_Command_Mulligan; } -}; -class Command_RollDie : public GameCommand { - Q_OBJECT -public: - Command_RollDie(int _gameId = -1, int _sides = -1); - int getSides() const { return static_cast(itemMap.value("sides"))->getData(); }; - static SerializableItem *newItem() { return new Command_RollDie; } - int getItemId() const { return ItemId_Command_RollDie; } -}; -class Command_DrawCards : public GameCommand { - Q_OBJECT -public: - Command_DrawCards(int _gameId = -1, int _number = -1); - int getNumber() const { return static_cast(itemMap.value("number"))->getData(); }; - static SerializableItem *newItem() { return new Command_DrawCards; } - int getItemId() const { return ItemId_Command_DrawCards; } -}; -class Command_UndoDraw : public GameCommand { - Q_OBJECT -public: - Command_UndoDraw(int _gameId = -1); - static SerializableItem *newItem() { return new Command_UndoDraw; } - int getItemId() const { return ItemId_Command_UndoDraw; } -}; -class Command_FlipCard : public GameCommand { - Q_OBJECT -public: - Command_FlipCard(int _gameId = -1, const QString &_zone = QString(), int _cardId = -1, bool _faceDown = false); - QString getZone() const { return static_cast(itemMap.value("zone"))->getData(); }; - int getCardId() const { return static_cast(itemMap.value("card_id"))->getData(); }; - bool getFaceDown() const { return static_cast(itemMap.value("face_down"))->getData(); }; - static SerializableItem *newItem() { return new Command_FlipCard; } - int getItemId() const { return ItemId_Command_FlipCard; } -}; -class Command_AttachCard : public GameCommand { - Q_OBJECT -public: - Command_AttachCard(int _gameId = -1, const QString &_startZone = QString(), int _cardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1); - QString getStartZone() const { return static_cast(itemMap.value("start_zone"))->getData(); }; - int getCardId() const { return static_cast(itemMap.value("card_id"))->getData(); }; - int getTargetPlayerId() const { return static_cast(itemMap.value("target_player_id"))->getData(); }; - QString getTargetZone() const { return static_cast(itemMap.value("target_zone"))->getData(); }; - int getTargetCardId() const { return static_cast(itemMap.value("target_card_id"))->getData(); }; - static SerializableItem *newItem() { return new Command_AttachCard; } - int getItemId() const { return ItemId_Command_AttachCard; } -}; -class Command_CreateToken : public GameCommand { - Q_OBJECT -public: - Command_CreateToken(int _gameId = -1, const QString &_zone = QString(), const QString &_cardName = QString(), const QString &_color = QString(), const QString &_pt = QString(), const QString &_annotation = QString(), bool _destroy = false, int _x = -1, int _y = -1); - QString getZone() const { return static_cast(itemMap.value("zone"))->getData(); }; - QString getCardName() const { return static_cast(itemMap.value("card_name"))->getData(); }; - QString getColor() const { return static_cast(itemMap.value("color"))->getData(); }; - QString getPt() const { return static_cast(itemMap.value("pt"))->getData(); }; - QString getAnnotation() const { return static_cast(itemMap.value("annotation"))->getData(); }; - bool getDestroy() const { return static_cast(itemMap.value("destroy"))->getData(); }; - int getX() const { return static_cast(itemMap.value("x"))->getData(); }; - int getY() const { return static_cast(itemMap.value("y"))->getData(); }; - static SerializableItem *newItem() { return new Command_CreateToken; } - int getItemId() const { return ItemId_Command_CreateToken; } -}; -class Command_CreateArrow : public GameCommand { - Q_OBJECT -public: - Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const Color &_color = Color()); - int getStartPlayerId() const { return static_cast(itemMap.value("start_player_id"))->getData(); }; - QString getStartZone() const { return static_cast(itemMap.value("start_zone"))->getData(); }; - int getStartCardId() const { return static_cast(itemMap.value("start_card_id"))->getData(); }; - int getTargetPlayerId() const { return static_cast(itemMap.value("target_player_id"))->getData(); }; - QString getTargetZone() const { return static_cast(itemMap.value("target_zone"))->getData(); }; - int getTargetCardId() const { return static_cast(itemMap.value("target_card_id"))->getData(); }; - Color getColor() const { return static_cast(itemMap.value("color"))->getData(); }; - static SerializableItem *newItem() { return new Command_CreateArrow; } - int getItemId() const { return ItemId_Command_CreateArrow; } -}; -class Command_DeleteArrow : public GameCommand { - Q_OBJECT -public: - Command_DeleteArrow(int _gameId = -1, int _arrowId = -1); - int getArrowId() const { return static_cast(itemMap.value("arrow_id"))->getData(); }; - static SerializableItem *newItem() { return new Command_DeleteArrow; } - int getItemId() const { return ItemId_Command_DeleteArrow; } -}; -class Command_SetCardAttr : public GameCommand { - Q_OBJECT -public: - Command_SetCardAttr(int _gameId = -1, const QString &_zone = QString(), int _cardId = -1, const QString &_attrName = QString(), const QString &_attrValue = QString()); - QString getZone() const { return static_cast(itemMap.value("zone"))->getData(); }; - int getCardId() const { return static_cast(itemMap.value("card_id"))->getData(); }; - QString getAttrName() const { return static_cast(itemMap.value("attr_name"))->getData(); }; - QString getAttrValue() const { return static_cast(itemMap.value("attr_value"))->getData(); }; - static SerializableItem *newItem() { return new Command_SetCardAttr; } - int getItemId() const { return ItemId_Command_SetCardAttr; } -}; -class Command_SetCardCounter : public GameCommand { - Q_OBJECT -public: - Command_SetCardCounter(int _gameId = -1, const QString &_zone = QString(), int _cardId = -1, int _counterId = -1, int _counterValue = -1); - QString getZone() const { return static_cast(itemMap.value("zone"))->getData(); }; - int getCardId() const { return static_cast(itemMap.value("card_id"))->getData(); }; - int getCounterId() const { return static_cast(itemMap.value("counter_id"))->getData(); }; - int getCounterValue() const { return static_cast(itemMap.value("counter_value"))->getData(); }; - static SerializableItem *newItem() { return new Command_SetCardCounter; } - int getItemId() const { return ItemId_Command_SetCardCounter; } -}; -class Command_IncCardCounter : public GameCommand { - Q_OBJECT -public: - Command_IncCardCounter(int _gameId = -1, const QString &_zone = QString(), int _cardId = -1, int _counterId = -1, int _counterDelta = -1); - QString getZone() const { return static_cast(itemMap.value("zone"))->getData(); }; - int getCardId() const { return static_cast(itemMap.value("card_id"))->getData(); }; - int getCounterId() const { return static_cast(itemMap.value("counter_id"))->getData(); }; - int getCounterDelta() const { return static_cast(itemMap.value("counter_delta"))->getData(); }; - static SerializableItem *newItem() { return new Command_IncCardCounter; } - int getItemId() const { return ItemId_Command_IncCardCounter; } -}; -class Command_ReadyStart : public GameCommand { - Q_OBJECT -public: - Command_ReadyStart(int _gameId = -1, bool _ready = false); - bool getReady() const { return static_cast(itemMap.value("ready"))->getData(); }; - static SerializableItem *newItem() { return new Command_ReadyStart; } - int getItemId() const { return ItemId_Command_ReadyStart; } -}; -class Command_Concede : public GameCommand { - Q_OBJECT -public: - Command_Concede(int _gameId = -1); - static SerializableItem *newItem() { return new Command_Concede; } - int getItemId() const { return ItemId_Command_Concede; } -}; -class Command_IncCounter : public GameCommand { - Q_OBJECT -public: - Command_IncCounter(int _gameId = -1, int _counterId = -1, int _delta = -1); - int getCounterId() const { return static_cast(itemMap.value("counter_id"))->getData(); }; - int getDelta() const { return static_cast(itemMap.value("delta"))->getData(); }; - static SerializableItem *newItem() { return new Command_IncCounter; } - int getItemId() const { return ItemId_Command_IncCounter; } -}; -class Command_CreateCounter : public GameCommand { - Q_OBJECT -public: - Command_CreateCounter(int _gameId = -1, const QString &_counterName = QString(), const Color &_color = Color(), int _radius = -1, int _value = -1); - QString getCounterName() const { return static_cast(itemMap.value("counter_name"))->getData(); }; - Color getColor() const { return static_cast(itemMap.value("color"))->getData(); }; - int getRadius() const { return static_cast(itemMap.value("radius"))->getData(); }; - int getValue() const { return static_cast(itemMap.value("value"))->getData(); }; - static SerializableItem *newItem() { return new Command_CreateCounter; } - int getItemId() const { return ItemId_Command_CreateCounter; } -}; -class Command_SetCounter : public GameCommand { - Q_OBJECT -public: - Command_SetCounter(int _gameId = -1, int _counterId = -1, int _value = -1); - int getCounterId() const { return static_cast(itemMap.value("counter_id"))->getData(); }; - int getValue() const { return static_cast(itemMap.value("value"))->getData(); }; - static SerializableItem *newItem() { return new Command_SetCounter; } - int getItemId() const { return ItemId_Command_SetCounter; } -}; -class Command_DelCounter : public GameCommand { - Q_OBJECT -public: - Command_DelCounter(int _gameId = -1, int _counterId = -1); - int getCounterId() const { return static_cast(itemMap.value("counter_id"))->getData(); }; - static SerializableItem *newItem() { return new Command_DelCounter; } - int getItemId() const { return ItemId_Command_DelCounter; } -}; -class Command_NextTurn : public GameCommand { - Q_OBJECT -public: - Command_NextTurn(int _gameId = -1); - static SerializableItem *newItem() { return new Command_NextTurn; } - int getItemId() const { return ItemId_Command_NextTurn; } -}; -class Command_SetActivePhase : public GameCommand { - Q_OBJECT -public: - Command_SetActivePhase(int _gameId = -1, int _phase = -1); - int getPhase() const { return static_cast(itemMap.value("phase"))->getData(); }; - static SerializableItem *newItem() { return new Command_SetActivePhase; } - int getItemId() const { return ItemId_Command_SetActivePhase; } -}; -class Command_DumpZone : public GameCommand { - Q_OBJECT -public: - Command_DumpZone(int _gameId = -1, int _playerId = -1, const QString &_zoneName = QString(), int _numberCards = -1); - int getPlayerId() const { return static_cast(itemMap.value("player_id"))->getData(); }; - QString getZoneName() const { return static_cast(itemMap.value("zone_name"))->getData(); }; - int getNumberCards() const { return static_cast(itemMap.value("number_cards"))->getData(); }; - static SerializableItem *newItem() { return new Command_DumpZone; } - int getItemId() const { return ItemId_Command_DumpZone; } -}; -class Command_StopDumpZone : public GameCommand { - Q_OBJECT -public: - Command_StopDumpZone(int _gameId = -1, int _playerId = -1, const QString &_zoneName = QString()); - int getPlayerId() const { return static_cast(itemMap.value("player_id"))->getData(); }; - QString getZoneName() const { return static_cast(itemMap.value("zone_name"))->getData(); }; - static SerializableItem *newItem() { return new Command_StopDumpZone; } - int getItemId() const { return ItemId_Command_StopDumpZone; } -}; -class Command_RevealCards : public GameCommand { - Q_OBJECT -public: - Command_RevealCards(int _gameId = -1, const QString &_zoneName = QString(), int _cardId = -1, int _playerId = -1); - QString getZoneName() const { return static_cast(itemMap.value("zone_name"))->getData(); }; - int getCardId() const { return static_cast(itemMap.value("card_id"))->getData(); }; - int getPlayerId() const { return static_cast(itemMap.value("player_id"))->getData(); }; - static SerializableItem *newItem() { return new Command_RevealCards; } - int getItemId() const { return ItemId_Command_RevealCards; } -}; class Event_ConnectionStateChanged : public GameEvent { Q_OBJECT public: @@ -733,32 +338,5 @@ public: static SerializableItem *newItem() { return new Context_Mulligan; } int getItemId() const { return ItemId_Context_Mulligan; } }; -class Command_UpdateServerMessage : public AdminCommand { - Q_OBJECT -public: - Command_UpdateServerMessage(); - static SerializableItem *newItem() { return new Command_UpdateServerMessage; } - int getItemId() const { return ItemId_Command_UpdateServerMessage; } -}; -class Command_ShutdownServer : public AdminCommand { - Q_OBJECT -public: - Command_ShutdownServer(const QString &_reason = QString(), int _minutes = -1); - QString getReason() const { return static_cast(itemMap.value("reason"))->getData(); }; - int getMinutes() const { return static_cast(itemMap.value("minutes"))->getData(); }; - static SerializableItem *newItem() { return new Command_ShutdownServer; } - int getItemId() const { return ItemId_Command_ShutdownServer; } -}; -class Command_BanFromServer : public ModeratorCommand { - Q_OBJECT -public: - Command_BanFromServer(const QString &_userName = QString(), const QString &_address = QString(), int _minutes = -1, const QString &_reason = QString()); - QString getUserName() const { return static_cast(itemMap.value("user_name"))->getData(); }; - QString getAddress() const { return static_cast(itemMap.value("address"))->getData(); }; - int getMinutes() const { return static_cast(itemMap.value("minutes"))->getData(); }; - QString getReason() const { return static_cast(itemMap.value("reason"))->getData(); }; - static SerializableItem *newItem() { return new Command_BanFromServer; } - int getItemId() const { return ItemId_Command_BanFromServer; } -}; #endif diff --git a/common/server_cardzone.cpp b/common/server_cardzone.cpp index dd1db3ee..efa66faf 100644 --- a/common/server_cardzone.cpp +++ b/common/server_cardzone.cpp @@ -24,6 +24,7 @@ #include #include #include "server_game.h" +#include "pb/game_commands.pb.h" Server_CardZone::Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ZoneType _type) : player(_player), name(_name), has_coords(_has_coords), type(_type), cardsBeingLookedAt(0) @@ -159,20 +160,21 @@ bool Server_CardZone::isColumnEmpty(int x, int y) const return !coordMap.contains((x / 3) * 3); } -void Server_CardZone::moveCard(CommandContainer *cont, QMap &coordMap, Server_Card *card, int x, int y) +void Server_CardZone::moveCard(BlaContainer *bla, QMap &coordMap, Server_Card *card, int x, int y) { QMutexLocker locker(&player->getGame()->gameMutex); coordMap.remove(card->getY() * 10000 + card->getX()); - CardToMove *cardToMove = new CardToMove(card->getId()); - player->moveCard(cont, this, QList() << cardToMove, this, x, y, card->getFaceDown(), false); + CardToMove *cardToMove = new CardToMove; + cardToMove->set_card_id(card->getId()); + player->moveCard(bla, this, QList() << cardToMove, this, x, y, card->getFaceDown(), false); delete cardToMove; coordMap.insert(y * 10000 + x, card); } -void Server_CardZone::fixFreeSpaces(CommandContainer *cont) +void Server_CardZone::fixFreeSpaces(BlaContainer *bla) { QMutexLocker locker(&player->getGame()->gameMutex); @@ -191,15 +193,15 @@ void Server_CardZone::fixFreeSpaces(CommandContainer *cont) if (!coordMap.contains(y * 10000 + baseX)) { if (coordMap.contains(y * 10000 + baseX + 1)) - moveCard(cont, coordMap, coordMap.value(y * 10000 + baseX + 1), baseX, y); + moveCard(bla, coordMap, coordMap.value(y * 10000 + baseX + 1), baseX, y); else if (coordMap.contains(y * 10000 + baseX + 2)) { - moveCard(cont, coordMap, coordMap.value(y * 10000 + baseX + 2), baseX, y); + moveCard(bla, coordMap, coordMap.value(y * 10000 + baseX + 2), baseX, y); continue; } else continue; } if (!coordMap.contains(y * 10000 + baseX + 1) && coordMap.contains(y * 10000 + baseX + 2)) - moveCard(cont, coordMap, coordMap.value(y * 10000 + baseX + 2), baseX + 1, y); + moveCard(bla, coordMap, coordMap.value(y * 10000 + baseX + 2), baseX + 1, y); } } diff --git a/common/server_cardzone.h b/common/server_cardzone.h index 898e89c7..1744d52f 100644 --- a/common/server_cardzone.h +++ b/common/server_cardzone.h @@ -27,7 +27,7 @@ class Server_Card; class Server_Player; class Server_Game; -class CommandContainer; +class BlaContainer; class Server_CardZone { private: @@ -53,8 +53,8 @@ public: int getFreeGridColumn(int x, int y, const QString &cardName) const; bool isColumnEmpty(int x, int y) const; bool isColumnStacked(int x, int y) const; - void fixFreeSpaces(CommandContainer *cont); - void moveCard(CommandContainer *cont, QMap &coordMap, Server_Card *card, int x, int y); + void fixFreeSpaces(BlaContainer *bla); + void moveCard(BlaContainer *bla, QMap &coordMap, Server_Card *card, int x, int y); QList cards; void insertCard(Server_Card *card, int x, int y); void shuffle(); diff --git a/common/server_player.cpp b/common/server_player.cpp index fe977bb6..01a43aa2 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -8,6 +8,7 @@ #include "protocol.h" #include "protocol_items.h" #include "decklist.h" +#include "pb/game_commands.pb.h" #include Server_Player::Server_Player(Server_Game *_game, int _playerId, ServerInfo_User *_userInfo, bool _spectator, Server_ProtocolHandler *_handler) @@ -243,7 +244,7 @@ bool Server_Player::deleteCounter(int counterId) return true; } -ResponseCode Server_Player::drawCards(CommandContainer *cont, int number) +ResponseCode Server_Player::drawCards(BlaContainer *bla, int number) { QMutexLocker locker(&game->gameMutex); @@ -261,14 +262,14 @@ ResponseCode Server_Player::drawCards(CommandContainer *cont, int number) cardListPrivate.append(new ServerInfo_Card(card->getId(), card->getName())); cardListOmniscient.append(new ServerInfo_Card(card->getId(), card->getName())); } - cont->enqueueGameEventPrivate(new Event_DrawCards(playerId, cardListPrivate.size(), cardListPrivate), game->getGameId()); - cont->enqueueGameEventOmniscient(new Event_DrawCards(playerId, cardListOmniscient.size(), cardListOmniscient), game->getGameId()); - cont->enqueueGameEventPublic(new Event_DrawCards(playerId, cardListPrivate.size()), game->getGameId()); + bla->enqueueGameEventPrivate(new Event_DrawCards(playerId, cardListPrivate.size(), cardListPrivate), game->getGameId()); + bla->enqueueGameEventOmniscient(new Event_DrawCards(playerId, cardListOmniscient.size(), cardListOmniscient), game->getGameId()); + bla->enqueueGameEventPublic(new Event_DrawCards(playerId, cardListPrivate.size()), game->getGameId()); return RespOk; } -ResponseCode Server_Player::undoDraw(CommandContainer *cont) +ResponseCode Server_Player::undoDraw(BlaContainer *bla) { QMutexLocker locker(&game->gameMutex); @@ -276,13 +277,14 @@ ResponseCode Server_Player::undoDraw(CommandContainer *cont) return RespContextError; ResponseCode retVal; - CardToMove *cardToMove = new CardToMove(lastDrawList.takeLast()); - retVal = moveCard(cont, zones.value("hand"), QList() << cardToMove, zones.value("deck"), 0, 0, false, true); + CardToMove *cardToMove = new CardToMove; + cardToMove->set_card_id(lastDrawList.takeLast()); + retVal = moveCard(bla, zones.value("hand"), QList() << cardToMove, zones.value("deck"), 0, 0, false, true); delete cardToMove; return retVal; } -ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_startZone, const QList &_cards, int targetPlayerId, const QString &_targetZone, int x, int y) +ResponseCode Server_Player::moveCard(BlaContainer *bla, const QString &_startZone, const QList &_cards, int targetPlayerId, const QString &_targetZone, int x, int y) { QMutexLocker locker(&game->gameMutex); @@ -294,7 +296,7 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_sta if ((!startzone) || (!targetzone)) return RespNameNotFound; - return moveCard(cont, startzone, _cards, targetzone, x, y); + return moveCard(bla, startzone, _cards, targetzone, x, y); } class Server_Player::MoveCardCompareFunctor { @@ -318,7 +320,7 @@ public: } }; -ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces, bool undoingDraw) +ResponseCode Server_Player::moveCard(BlaContainer *bla, Server_CardZone *startzone, const QList &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces, bool undoingDraw) { QMutexLocker locker(&game->gameMutex); @@ -330,10 +332,10 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st x = targetzone->cards.size(); QList > cardsToMove; - QMap cardProperties; + QMap cardProperties; for (int i = 0; i < _cards.size(); ++i) { int position; - Server_Card *card = startzone->getCard(_cards[i]->getCardId(), &position); + Server_Card *card = startzone->getCard(_cards[i]->card_id(), &position); if (!card) return RespNameNotFound; if (!card->getAttachedCards().isEmpty() && !targetzone->isColumnEmpty(x, y)) @@ -349,7 +351,7 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st int xIndex = -1; for (int cardIndex = 0; cardIndex < cardsToMove.size(); ++cardIndex) { Server_Card *card = cardsToMove[cardIndex].first; - CardToMove *thisCardProperties = cardProperties.value(card); + const CardToMove *thisCardProperties = cardProperties.value(card); int originalPosition = cardsToMove[cardIndex].second; int position = startzone->removeCard(card); if (startzone->getName() == "hand") { @@ -380,7 +382,7 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st // Make a copy of the list because the original one gets modified during the loop QList attachedCards = card->getAttachedCards(); for (int i = 0; i < attachedCards.size(); ++i) - attachedCards[i]->getZone()->getPlayer()->unattachCard(cont, attachedCards[i]); + attachedCards[i]->getZone()->getPlayer()->unattachCard(bla, attachedCards[i]); } if (startzone != targetzone) { @@ -400,9 +402,9 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st } if (card->getDestroyOnZoneChange() && (startzone->getName() != targetzone->getName())) { - cont->enqueueGameEventPrivate(new Event_DestroyCard(getPlayerId(), startzone->getName(), card->getId()), game->getGameId(), -1, new Context_MoveCard); - cont->enqueueGameEventOmniscient(new Event_DestroyCard(getPlayerId(), startzone->getName(), card->getId()), game->getGameId(), new Context_MoveCard); - cont->enqueueGameEventPublic(new Event_DestroyCard(getPlayerId(), startzone->getName(), card->getId()), game->getGameId(), new Context_MoveCard); + bla->enqueueGameEventPrivate(new Event_DestroyCard(getPlayerId(), startzone->getName(), card->getId()), game->getGameId(), -1, new Context_MoveCard); + bla->enqueueGameEventOmniscient(new Event_DestroyCard(getPlayerId(), startzone->getName(), card->getId()), game->getGameId(), new Context_MoveCard); + bla->enqueueGameEventPublic(new Event_DestroyCard(getPlayerId(), startzone->getName(), card->getId()), game->getGameId(), new Context_MoveCard); card->deleteLater(); } else { if (!targetzone->hasCoords()) { @@ -416,8 +418,8 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st bool targetBeingLookedAt = (targetzone->getType() != HiddenZone) || (targetzone->getCardsBeingLookedAt() > newX) || (targetzone->getCardsBeingLookedAt() == -1); bool sourceBeingLookedAt = (startzone->getType() != HiddenZone) || (startzone->getCardsBeingLookedAt() > position) || (startzone->getCardsBeingLookedAt() == -1); - bool targetHiddenToPlayer = thisCardProperties->getFaceDown() || !targetBeingLookedAt; - bool targetHiddenToOthers = thisCardProperties->getFaceDown() || (targetzone->getType() != PublicZone); + bool targetHiddenToPlayer = thisCardProperties->face_down() || !targetBeingLookedAt; + bool targetHiddenToOthers = thisCardProperties->face_down() || (targetzone->getType() != PublicZone); bool sourceHiddenToPlayer = card->getFaceDown() || !sourceBeingLookedAt; bool sourceHiddenToOthers = card->getFaceDown() || (startzone->getType() != PublicZone); @@ -428,9 +430,9 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st publicCardName = card->getName(); int oldCardId = card->getId(); - if (thisCardProperties->getFaceDown() || (targetzone->getPlayer() != startzone->getPlayer())) + if (thisCardProperties->face_down() || (targetzone->getPlayer() != startzone->getPlayer())) card->setId(targetzone->getPlayer()->newCardId()); - card->setFaceDown(thisCardProperties->getFaceDown()); + card->setFaceDown(thisCardProperties->face_down()); // 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. @@ -444,8 +446,8 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st int privatePosition = -1; if (startzone->getType() == HiddenZone) privatePosition = position; - cont->enqueueGameEventPrivate(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, thisCardProperties->getFaceDown()), game->getGameId(), -1, undoingDraw ? static_cast(new Context_UndoDraw) : static_cast(new Context_MoveCard)); - cont->enqueueGameEventOmniscient(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, thisCardProperties->getFaceDown()), game->getGameId(), undoingDraw ? static_cast(new Context_UndoDraw) : static_cast(new Context_MoveCard)); + bla->enqueueGameEventPrivate(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, thisCardProperties->face_down()), game->getGameId(), -1, undoingDraw ? static_cast(new Context_UndoDraw) : static_cast(new Context_MoveCard)); + bla->enqueueGameEventOmniscient(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, thisCardProperties->face_down()), game->getGameId(), undoingDraw ? static_cast(new Context_UndoDraw) : static_cast(new Context_MoveCard)); // 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, @@ -459,38 +461,40 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st newX = -1; if ((startzone->getType() == PublicZone) || (targetzone->getType() == PublicZone)) - cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, card->getId(), thisCardProperties->getFaceDown()), game->getGameId(), undoingDraw ? static_cast(new Context_UndoDraw) : static_cast(new Context_MoveCard)); + bla->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, card->getId(), thisCardProperties->face_down()), game->getGameId(), undoingDraw ? static_cast(new Context_UndoDraw) : static_cast(new Context_MoveCard)); else - cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, -1, false), game->getGameId(), undoingDraw ? static_cast(new Context_UndoDraw) : static_cast(new Context_MoveCard)); + bla->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, -1, false), game->getGameId(), undoingDraw ? static_cast(new Context_UndoDraw) : static_cast(new Context_MoveCard)); - if (thisCardProperties->getTapped()) - setCardAttrHelper(cont, targetzone->getName(), card->getId(), "tapped", "1"); - if (!thisCardProperties->getPT().isEmpty() && !thisCardProperties->getFaceDown()) - setCardAttrHelper(cont, targetzone->getName(), card->getId(), "pt", thisCardProperties->getPT()); + if (thisCardProperties->tapped()) + setCardAttrHelper(bla, targetzone->getName(), card->getId(), "tapped", "1"); + QString ptString = QString::fromStdString(thisCardProperties->pt()); + if (!ptString.isEmpty() && !thisCardProperties->face_down()) + setCardAttrHelper(bla, targetzone->getName(), card->getId(), "pt", ptString); } } if (startzone->hasCoords() && fixFreeSpaces) - startzone->fixFreeSpaces(cont); + startzone->fixFreeSpaces(bla); return RespOk; } -void Server_Player::unattachCard(CommandContainer *cont, Server_Card *card) +void Server_Player::unattachCard(BlaContainer *bla, Server_Card *card) { QMutexLocker locker(&game->gameMutex); Server_CardZone *zone = card->getZone(); card->setParentCard(0); - cont->enqueueGameEventPrivate(new Event_AttachCard(getPlayerId(), zone->getName(), card->getId(), -1, QString(), -1), game->getGameId()); - cont->enqueueGameEventPublic(new Event_AttachCard(getPlayerId(), zone->getName(), card->getId(), -1, QString(), -1), game->getGameId()); + bla->enqueueGameEventPrivate(new Event_AttachCard(getPlayerId(), zone->getName(), card->getId(), -1, QString(), -1), game->getGameId()); + bla->enqueueGameEventPublic(new Event_AttachCard(getPlayerId(), zone->getName(), card->getId(), -1, QString(), -1), game->getGameId()); - CardToMove *cardToMove = new CardToMove(card->getId()); - moveCard(cont, zone, QList() << cardToMove, zone, -1, card->getY(), card->getFaceDown()); + CardToMove *cardToMove = new CardToMove; + cardToMove->set_card_id(card->getId()); + moveCard(bla, zone, QList() << cardToMove, zone, -1, card->getY(), card->getFaceDown()); delete cardToMove; } -ResponseCode Server_Player::setCardAttrHelper(CommandContainer *cont, const QString &zoneName, int cardId, const QString &attrName, const QString &attrValue) +ResponseCode Server_Player::setCardAttrHelper(BlaContainer *bla, const QString &zoneName, int cardId, const QString &attrName, const QString &attrValue) { QMutexLocker locker(&game->gameMutex); @@ -516,9 +520,9 @@ ResponseCode Server_Player::setCardAttrHelper(CommandContainer *cont, const QStr if (result.isNull()) return RespInvalidCommand; } - cont->enqueueGameEventPrivate(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId()); - cont->enqueueGameEventPublic(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId()); - cont->enqueueGameEventOmniscient(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId()); + bla->enqueueGameEventPrivate(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId()); + bla->enqueueGameEventPublic(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId()); + bla->enqueueGameEventOmniscient(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId()); return RespOk; } diff --git a/common/server_player.h b/common/server_player.h index 64f99add..f211ae7f 100644 --- a/common/server_player.h +++ b/common/server_player.h @@ -19,6 +19,8 @@ class ProtocolItem; class ServerInfo_User; class ServerInfo_PlayerProperties; class CommandContainer; +class CardToMove; +class BlaContainer; class Server_Player : public Server_ArrowTarget { Q_OBJECT @@ -79,12 +81,12 @@ public: void clearZones(); void setupZones(); - ResponseCode drawCards(CommandContainer *cont, int number); - ResponseCode undoDraw(CommandContainer *cont); - ResponseCode moveCard(CommandContainer *cont, const QString &_startZone, const QList &_cards, int _targetPlayer, const QString &_targetZone, int _x, int _y); - ResponseCode moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces = true, bool undoingDraw = false); - void unattachCard(CommandContainer *cont, Server_Card *card); - ResponseCode setCardAttrHelper(CommandContainer *cont, const QString &zone, int cardId, const QString &attrName, const QString &attrValue); + ResponseCode drawCards(BlaContainer *bla, int number); + ResponseCode undoDraw(BlaContainer *bla); + ResponseCode moveCard(BlaContainer *bla, const QString &_startZone, const QList &_cards, int _targetPlayer, const QString &_targetZone, int _x, int _y); + ResponseCode moveCard(BlaContainer *bla, Server_CardZone *startzone, const QList &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces = true, bool undoingDraw = false); + void unattachCard(BlaContainer *bla, Server_Card *card); + ResponseCode setCardAttrHelper(BlaContainer *bla, const QString &zone, int cardId, const QString &attrName, const QString &attrValue); void sendProtocolItem(ProtocolItem *item, bool deleteItem = true); }; diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index bdb887c8..20027aa5 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -12,6 +12,8 @@ #include "server_player.h" #include "decklist.h" #include +#include "pb/commands.pb.h" +#include Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent) : QObject(parent), server(_server), authState(PasswordWrong), acceptsUserListChanges(false), acceptsRoomListChanges(false), userInfo(0), sessionId(-1), timeRunning(0), lastDataReceived(0), gameListMutex(QMutex::Recursive) @@ -70,149 +72,231 @@ void Server_ProtocolHandler::playerRemovedFromGame(Server_Game *game) games.remove(game->getGameId()); } -ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, CommandContainer *cont) +ResponseCode Server_ProtocolHandler::processSessionCommandContainer(CommandContainer *cont, BlaContainer *bla) { - RoomCommand *roomCommand = qobject_cast(command); - if (roomCommand) { - qDebug() << "received RoomCommand: roomId =" << roomCommand->getRoomId(); - if (authState == PasswordWrong) - return RespLoginNeeded; + ResponseCode finalResponseCode = RespOk; + for (int i = cont->session_command_size() - 1; i >= 0; --i) { + ResponseCode resp; + const SessionCommand &sc = cont->session_command(i); + std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; + sc.GetReflection()->ListFields(sc, &fieldList); + int num = 0; + for (unsigned int j = 0; j < fieldList.size(); ++j) + if (fieldList[j]->number() >= 100) { + num = fieldList[j]->number(); + break; + } + switch ((SessionCommand::SessionCommandType) num) { + case SessionCommand::PING: resp = cmdPing(sc.GetExtension(command_ping), cont); break; + case SessionCommand::LOGIN: resp = cmdLogin(sc.GetExtension(command_login), cont, bla); break; + case SessionCommand::MESSAGE: resp = cmdMessage(sc.GetExtension(command_message), cont, bla); break; + case SessionCommand::ADD_TO_LIST: resp = cmdAddToList(sc.GetExtension(command_add_to_list), cont); break; + case SessionCommand::REMOVE_FROM_LIST: resp = cmdRemoveFromList(sc.GetExtension(command_remove_from_list), cont); break; + case SessionCommand::DECK_LIST: resp = cmdDeckList(sc.GetExtension(command_deck_list), cont); break; + case SessionCommand::DECK_NEW_DIR: resp = cmdDeckNewDir(sc.GetExtension(command_deck_new_dir), cont); break; + case SessionCommand::DECK_DEL_DIR: resp = cmdDeckDelDir(sc.GetExtension(command_deck_del_dir), cont); break; + case SessionCommand::DECK_DEL: resp = cmdDeckDel(sc.GetExtension(command_deck_del), cont); break; + case SessionCommand::DECK_UPLOAD: resp = cmdDeckUpload(sc.GetExtension(command_deck_upload), cont); break; + case SessionCommand::DECK_DOWNLOAD: resp = cmdDeckDownload(sc.GetExtension(command_deck_download), cont); break; + case SessionCommand::GET_GAMES_OF_USER: resp = cmdGetGamesOfUser(sc.GetExtension(command_get_games_of_user), cont, bla); break; + case SessionCommand::GET_USER_INFO: resp = cmdGetUserInfo(sc.GetExtension(command_get_user_info), cont, bla); break; + case SessionCommand::LIST_ROOMS: resp = cmdListRooms(sc.GetExtension(command_list_rooms), cont, bla); break; + case SessionCommand::JOIN_ROOM: resp = cmdJoinRoom(sc.GetExtension(command_join_room), cont, bla); break; + case SessionCommand::LIST_USERS: resp = cmdListUsers(sc.GetExtension(command_list_users), cont, bla); break; + } + if ((resp != RespOk) && (resp != RespNothing)) + finalResponseCode = resp; + } + return finalResponseCode; +} + +ResponseCode Server_ProtocolHandler::processRoomCommandContainer(CommandContainer *cont, BlaContainer *bla) +{ + if (authState == PasswordWrong) + return RespLoginNeeded; + + Server_Room *room = rooms.value(cont->room_id(), 0); + if (!room) + return RespNotInRoom; - Server_Room *room = rooms.value(roomCommand->getRoomId(), 0); - if (!room) - return RespNotInRoom; - - QMutexLocker locker(&room->roomMutex); - - switch (command->getItemId()) { - case ItemId_Command_LeaveRoom: return cmdLeaveRoom(static_cast(command), cont, room); - case ItemId_Command_RoomSay: return cmdRoomSay(static_cast(command), cont, room); - case ItemId_Command_CreateGame: return cmdCreateGame(static_cast(command), cont, room); - case ItemId_Command_JoinGame: return cmdJoinGame(static_cast(command), cont, room); - default: return RespInvalidCommand; + QMutexLocker locker(&room->roomMutex); + + ResponseCode finalResponseCode = RespOk; + for (int i = cont->room_command_size() - 1; i >= 0; --i) { + ResponseCode resp; + const RoomCommand &sc = cont->room_command(i); + std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; + sc.GetReflection()->ListFields(sc, &fieldList); + int num = 0; + for (unsigned int j = 0; j < fieldList.size(); ++j) + if (fieldList[j]->number() >= 100) { + num = fieldList[j]->number(); + break; + } + switch ((RoomCommand::RoomCommandType) num) { + case RoomCommand::LEAVE_ROOM: resp = cmdLeaveRoom(sc.GetExtension(command_leave_room), cont, room); break; + case RoomCommand::ROOM_SAY: resp = cmdRoomSay(sc.GetExtension(command_room_say), cont, room); break; + case RoomCommand::CREATE_GAME: resp = cmdCreateGame(sc.GetExtension(command_create_game), cont, room); break; + case RoomCommand::JOIN_GAME: resp = cmdJoinGame(sc.GetExtension(command_join_game), cont, room); break; } + if ((resp != RespOk) && (resp != RespNothing)) + finalResponseCode = resp; } - GameCommand *gameCommand = qobject_cast(command); - if (gameCommand) { - qDebug() << "received GameCommand: game =" << gameCommand->getGameId(); - if (authState == PasswordWrong) - return RespLoginNeeded; - - gameListMutex.lock(); - if (!games.contains(gameCommand->getGameId())) { - qDebug() << "invalid game"; - return RespNotInRoom; + return finalResponseCode; +} + +ResponseCode Server_ProtocolHandler::processGameCommandContainer(CommandContainer *cont, BlaContainer *bla) +{ + if (authState == PasswordWrong) + return RespLoginNeeded; + + gameListMutex.lock(); + if (!games.contains(cont->game_id())) { + qDebug() << "invalid game"; + return RespNotInRoom; + } + QPair gamePair = games.value(cont->game_id()); + Server_Game *game = gamePair.first; + Server_Player *player = gamePair.second; + + QMutexLocker locker(&game->gameMutex); + gameListMutex.unlock(); + + ResponseCode finalResponseCode = RespOk; + for (int i = cont->game_command_size() - 1; i >= 0; --i) { + ResponseCode resp; + const GameCommand &sc = cont->game_command(i); + std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; + sc.GetReflection()->ListFields(sc, &fieldList); + int num = 0; + for (unsigned int j = 0; j < fieldList.size(); ++j) + if (fieldList[j]->number() >= 100) { + num = fieldList[j]->number(); + break; + } + switch ((GameCommand::GameCommandType) num) { + case GameCommand::KICK_FROM_GAME: resp = cmdKickFromGame(sc.GetExtension(command_kick_from_game), cont, game, player, bla); break; + case GameCommand::LEAVE_GAME: resp = cmdLeaveGame(sc.GetExtension(command_leave_game), cont, game, player, bla); break; + case GameCommand::GAME_SAY: resp = cmdGameSay(sc.GetExtension(command_game_say), cont, game, player, bla); break; + case GameCommand::SHUFFLE: resp = cmdShuffle(sc.GetExtension(command_shuffle), cont, game, player, bla); break; + case GameCommand::MULLIGAN: resp = cmdMulligan(sc.GetExtension(command_mulligan), cont, game, player, bla); break; + case GameCommand::ROLL_DIE: resp = cmdRollDie(sc.GetExtension(command_roll_die), cont, game, player, bla); break; + case GameCommand::DRAW_CARDS: resp = cmdDrawCards(sc.GetExtension(command_draw_cards), cont, game, player, bla); break; + case GameCommand::UNDO_DRAW: resp = cmdUndoDraw(sc.GetExtension(command_undo_draw), cont, game, player, bla); break; + case GameCommand::FLIP_CARD: resp = cmdFlipCard(sc.GetExtension(command_flip_card), cont, game, player, bla); break; + case GameCommand::ATTACH_CARD: resp = cmdAttachCard(sc.GetExtension(command_attach_card), cont, game, player, bla); break; + case GameCommand::CREATE_TOKEN: resp = cmdCreateToken(sc.GetExtension(command_create_token), cont, game, player, bla); break; + case GameCommand::CREATE_ARROW: resp = cmdCreateArrow(sc.GetExtension(command_create_arrow), cont, game, player, bla); break; + case GameCommand::DELETE_ARROW: resp = cmdDeleteArrow(sc.GetExtension(command_delete_arrow), cont, game, player, bla); break; + case GameCommand::SET_CARD_ATTR: resp = cmdSetCardAttr(sc.GetExtension(command_set_card_attr), cont, game, player, bla); break; + case GameCommand::SET_CARD_COUNTER: resp = cmdSetCardCounter(sc.GetExtension(command_set_card_counter), cont, game, player, bla); break; + case GameCommand::INC_CARD_COUNTER: resp = cmdIncCardCounter(sc.GetExtension(command_inc_card_counter), cont, game, player, bla); break; + case GameCommand::READY_START: resp = cmdReadyStart(sc.GetExtension(command_ready_start), cont, game, player, bla); break; + case GameCommand::CONCEDE: resp = cmdConcede(sc.GetExtension(command_concede), cont, game, player, bla); break; + case GameCommand::INC_COUNTER: resp = cmdIncCounter(sc.GetExtension(command_inc_counter), cont, game, player, bla); break; + case GameCommand::CREATE_COUNTER: resp = cmdCreateCounter(sc.GetExtension(command_create_counter), cont, game, player, bla); break; + case GameCommand::SET_COUNTER: resp = cmdSetCounter(sc.GetExtension(command_set_counter), cont, game, player, bla); break; + case GameCommand::DEL_COUNTER: resp = cmdDelCounter(sc.GetExtension(command_del_counter), cont, game, player, bla); break; + case GameCommand::NEXT_TURN: resp = cmdNextTurn(sc.GetExtension(command_next_turn), cont, game, player, bla); break; + case GameCommand::SET_ACTIVE_PHASE: resp = cmdSetActivePhase(sc.GetExtension(command_set_active_phase), cont, game, player, bla); break; + case GameCommand::DUMP_ZONE: resp = cmdDumpZone(sc.GetExtension(command_dump_zone), cont, game, player, bla); break; + case GameCommand::STOP_DUMP_ZONE: resp = cmdStopDumpZone(sc.GetExtension(command_stop_dump_zone), cont, game, player, bla); break; + case GameCommand::REVEAL_CARDS: resp = cmdRevealCards(sc.GetExtension(command_reveal_cards), cont, game, player, bla); break; + case GameCommand::MOVE_CARD: resp = cmdMoveCard(sc.GetExtension(command_move_card), cont, game, player, bla); break; + case GameCommand::SET_SIDEBOARD_PLAN: resp = cmdSetSideboardPlan(sc.GetExtension(command_set_sideboard_plan), cont, game, player, bla); break; + case GameCommand::DECK_SELECT: resp = cmdDeckSelect(sc.GetExtension(command_deck_select), cont, game, player, bla); break; } - QPair gamePair = games.value(gameCommand->getGameId()); - Server_Game *game = gamePair.first; - Server_Player *player = gamePair.second; - - QMutexLocker locker(&game->gameMutex); - gameListMutex.unlock(); - - switch (command->getItemId()) { - case ItemId_Command_DeckSelect: return cmdDeckSelect(static_cast(command), cont, game, player); - case ItemId_Command_SetSideboardPlan: return cmdSetSideboardPlan(static_cast(command), cont, game, player); - case ItemId_Command_LeaveGame: return cmdLeaveGame(static_cast(command), cont, game, player); - case ItemId_Command_KickFromGame: return cmdKickFromGame(static_cast(command), cont, game, player); - case ItemId_Command_ReadyStart: return cmdReadyStart(static_cast(command), cont, game, player); - case ItemId_Command_Concede: return cmdConcede(static_cast(command), cont, game, player); - case ItemId_Command_Say: return cmdSay(static_cast(command), cont, game, player); - case ItemId_Command_Shuffle: return cmdShuffle(static_cast(command), cont, game, player); - case ItemId_Command_Mulligan: return cmdMulligan(static_cast(command), cont, game, player); - case ItemId_Command_RollDie: return cmdRollDie(static_cast(command), cont, game, player); - case ItemId_Command_DrawCards: return cmdDrawCards(static_cast(command), cont, game, player); - case ItemId_Command_UndoDraw: return cmdUndoDraw(static_cast(command), cont, game, player); - case ItemId_Command_MoveCard: return cmdMoveCard(static_cast(command), cont, game, player); - case ItemId_Command_FlipCard: return cmdFlipCard(static_cast(command), cont, game, player); - case ItemId_Command_AttachCard: return cmdAttachCard(static_cast(command), cont, game, player); - case ItemId_Command_CreateToken: return cmdCreateToken(static_cast(command), cont, game, player); - case ItemId_Command_CreateArrow: return cmdCreateArrow(static_cast(command), cont, game, player); - case ItemId_Command_DeleteArrow: return cmdDeleteArrow(static_cast(command), cont, game, player); - case ItemId_Command_SetCardAttr: return cmdSetCardAttr(static_cast(command), cont, game, player); - case ItemId_Command_SetCardCounter: return cmdSetCardCounter(static_cast(command), cont, game, player); - case ItemId_Command_IncCardCounter: return cmdIncCardCounter(static_cast(command), cont, game, player); - case ItemId_Command_IncCounter: return cmdIncCounter(static_cast(command), cont, game, player); - case ItemId_Command_CreateCounter: return cmdCreateCounter(static_cast(command), cont, game, player); - case ItemId_Command_SetCounter: return cmdSetCounter(static_cast(command), cont, game, player); - case ItemId_Command_DelCounter: return cmdDelCounter(static_cast(command), cont, game, player); - case ItemId_Command_NextTurn: return cmdNextTurn(static_cast(command), cont, game, player); - case ItemId_Command_SetActivePhase: return cmdSetActivePhase(static_cast(command), cont, game, player); - case ItemId_Command_DumpZone: return cmdDumpZone(static_cast(command), cont, game, player); - case ItemId_Command_StopDumpZone: return cmdStopDumpZone(static_cast(command), cont, game, player); - case ItemId_Command_RevealCards: return cmdRevealCards(static_cast(command), cont, game, player); - default: return RespInvalidCommand; + if ((resp != RespOk) && (resp != RespNothing)) + finalResponseCode = resp; + } + return finalResponseCode; +} + +ResponseCode Server_ProtocolHandler::processModeratorCommandContainer(CommandContainer *cont, BlaContainer *bla) +{ + if (!(userInfo->getUserLevel() & ServerInfo_User::IsModerator)) + return RespLoginNeeded; + + ResponseCode finalResponseCode = RespOk; + for (int i = cont->moderator_command_size() - 1; i >= 0; --i) { + ResponseCode resp; + const ModeratorCommand &sc = cont->moderator_command(i); + std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; + sc.GetReflection()->ListFields(sc, &fieldList); + int num = 0; + for (unsigned int j = 0; j < fieldList.size(); ++j) + if (fieldList[j]->number() >= 100) { + num = fieldList[j]->number(); + break; + } + switch ((ModeratorCommand::ModeratorCommandType) num) { + case ModeratorCommand::BAN_FROM_SERVER: resp = cmdBanFromServer(sc.GetExtension(command_ban_from_server), cont); break; } + if ((resp != RespOk) && (resp != RespNothing)) + finalResponseCode = resp; } - ModeratorCommand *moderatorCommand = qobject_cast(command); - if (moderatorCommand) { - qDebug() << "received ModeratorCommand"; - if (!(userInfo->getUserLevel() & ServerInfo_User::IsModerator)) - return RespLoginNeeded; - - switch (command->getItemId()) { - case ItemId_Command_BanFromServer: return cmdBanFromServer(static_cast(command), cont); - default: return RespInvalidCommand; + return finalResponseCode; +} + +ResponseCode Server_ProtocolHandler::processAdminCommandContainer(CommandContainer *cont, BlaContainer *bla) +{ + if (!(userInfo->getUserLevel() & ServerInfo_User::IsAdmin)) + return RespLoginNeeded; + + ResponseCode finalResponseCode = RespOk; + for (int i = cont->admin_command_size() - 1; i >= 0; --i) { + ResponseCode resp; + const AdminCommand &sc = cont->admin_command(i); + std::vector< const ::google::protobuf::FieldDescriptor * > fieldList; + sc.GetReflection()->ListFields(sc, &fieldList); + int num = 0; + for (unsigned int j = 0; j < fieldList.size(); ++j) + if (fieldList[j]->number() >= 100) { + num = fieldList[j]->number(); + break; + } + switch ((AdminCommand::AdminCommandType) num) { + case AdminCommand::SHUTDOWN_SERVER: resp = cmdShutdownServer(sc.GetExtension(command_shutdown_server), cont); break; + case AdminCommand::UPDATE_SERVER_MESSAGE: resp = cmdUpdateServerMessage(sc.GetExtension(command_update_server_message), cont); break; } + if ((resp != RespOk) && (resp != RespNothing)) + finalResponseCode = resp; } - AdminCommand *adminCommand = qobject_cast(command); - if (adminCommand) { - qDebug() << "received AdminCommand"; - if (!(userInfo->getUserLevel() & ServerInfo_User::IsAdmin)) - return RespLoginNeeded; - - switch (command->getItemId()) { - case ItemId_Command_ShutdownServer: return cmdShutdownServer(static_cast(command), cont); - case ItemId_Command_UpdateServerMessage: return cmdUpdateServerMessage(static_cast(command), cont); - default: return RespInvalidCommand; - } - } - switch (command->getItemId()) { - case ItemId_Command_Ping: return cmdPing(static_cast(command), cont); - case ItemId_Command_Login: return cmdLogin(static_cast(command), cont); - case ItemId_Command_Message: return cmdMessage(static_cast(command), cont); - case ItemId_Command_AddToList: return cmdAddToList(static_cast(command), cont); - case ItemId_Command_RemoveFromList: return cmdRemoveFromList(static_cast(command), cont); - case ItemId_Command_DeckList: return cmdDeckList(static_cast(command), cont); - case ItemId_Command_DeckNewDir: return cmdDeckNewDir(static_cast(command), cont); - case ItemId_Command_DeckDelDir: return cmdDeckDelDir(static_cast(command), cont); - case ItemId_Command_DeckDel: return cmdDeckDel(static_cast(command), cont); - case ItemId_Command_DeckUpload: return cmdDeckUpload(static_cast(command), cont); - case ItemId_Command_DeckDownload: return cmdDeckDownload(static_cast(command), cont); - case ItemId_Command_GetGamesOfUser: return cmdGetGamesOfUser(static_cast(command), cont); - case ItemId_Command_GetUserInfo: return cmdGetUserInfo(static_cast(command), cont); - case ItemId_Command_ListRooms: return cmdListRooms(static_cast(command), cont); - case ItemId_Command_JoinRoom: return cmdJoinRoom(static_cast(command), cont); - case ItemId_Command_ListUsers: return cmdListUsers(static_cast(command), cont); - default: return RespInvalidCommand; - } + return finalResponseCode; } void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont) { lastDataReceived = timeRunning; - const QList &cmdList = cont->getCommandList(); - ResponseCode finalResponseCode = RespOk; - for (int i = 0; i < cmdList.size(); ++i) { - ResponseCode resp = processCommandHelper(cmdList[i], cont); - if ((resp != RespOk) && (resp != RespNothing)) - finalResponseCode = resp; + BlaContainer *bla = new BlaContainer; + ResponseCode finalResponseCode; + + if (cont->game_command_size()) { + finalResponseCode = processGameCommandContainer(cont, bla); + } else if (cont->room_command_size()) { + finalResponseCode = processRoomCommandContainer(cont, bla); + } else if (cont->session_command_size()) { + finalResponseCode = processSessionCommandContainer(cont, bla); + } else if (cont->moderator_command_size()) { + finalResponseCode = processModeratorCommandContainer(cont, bla); + } else if (cont->admin_command_size()) { + finalResponseCode = processAdminCommandContainer(cont, bla); } - ProtocolResponse *pr = cont->getResponse(); + ProtocolResponse *pr = bla->getResponse(); if (!pr) - pr = new ProtocolResponse(cont->getCmdId(), finalResponseCode); + pr = new ProtocolResponse(cont->cmd_id(), finalResponseCode); gameListMutex.lock(); - GameEventContainer *gQPublic = cont->getGameEventQueuePublic(); + GameEventContainer *gQPublic = bla->getGameEventQueuePublic(); if (gQPublic) { QPair gamePlayerPair = games.value(gQPublic->getGameId()); if (gamePlayerPair.first) { - GameEventContainer *gQPrivate = cont->getGameEventQueuePrivate(); - GameEventContainer *gQOmniscient = cont->getGameEventQueueOmniscient(); + GameEventContainer *gQPrivate = bla->getGameEventQueuePrivate(); + GameEventContainer *gQOmniscient = bla->getGameEventQueueOmniscient(); if (gQPrivate) { - int privatePlayerId = cont->getPrivatePlayerId(); + int privatePlayerId = bla->getPrivatePlayerId(); Server_Player *privatePlayer; if (privatePlayerId == -1) privatePlayer = gamePlayerPair.second; @@ -230,7 +314,7 @@ void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont) } gameListMutex.unlock(); - const QList &iQ = cont->getItemQueue(); + const QList &iQ = bla->getItemQueue(); for (int i = 0; i < iQ.size(); ++i) sendProtocolItem(iQ[i]); @@ -239,7 +323,7 @@ void Server_ProtocolHandler::processCommandContainer(CommandContainer *cont) while (!itemQueue.isEmpty()) sendProtocolItem(itemQueue.takeFirst()); - if (cont->getReceiverMayDelete()) +// if (cont->getReceiverMayDelete()) delete cont; } @@ -272,17 +356,17 @@ QPair Server_ProtocolHandler::getGame(int gameId return QPair(0, 0); } -ResponseCode Server_ProtocolHandler::cmdPing(Command_Ping * /*cmd*/, CommandContainer * /*cont*/) +ResponseCode Server_ProtocolHandler::cmdPing(const Command_Ping & /*cmd*/, CommandContainer * /*cont*/) { return RespOk; } -ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContainer *cont) +ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd, CommandContainer *cont, BlaContainer *bla) { - QString userName = cmd->getUsername().simplified(); + QString userName = QString::fromStdString(cmd.user_name()).simplified(); if (userName.isEmpty() || (userInfo != 0)) return RespContextError; - authState = server->loginUser(this, userName, cmd->getPassword()); + authState = server->loginUser(this, userName, QString::fromStdString(cmd.password())); if (authState == PasswordWrong) return RespWrongPassword; if (authState == WouldOverwriteOldSession) @@ -337,19 +421,19 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain } server->serverMutex.unlock(); - ProtocolResponse *resp = new Response_Login(cont->getCmdId(), RespOk, new ServerInfo_User(userInfo, true), _buddyList, _ignoreList); + ProtocolResponse *resp = new Response_Login(cont->cmd_id(), RespOk, new ServerInfo_User(userInfo, true), _buddyList, _ignoreList); if (getCompressionSupport()) resp->setCompressed(true); - cont->setResponse(resp); + bla->setResponse(resp); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdMessage(Command_Message *cmd, CommandContainer *cont) +ResponseCode Server_ProtocolHandler::cmdMessage(const Command_Message &cmd, CommandContainer *cont, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; - QString receiver = cmd->getUserName(); + QString receiver = QString::fromStdString(cmd.user_name()); Server_ProtocolHandler *userHandler = server->getUsers().value(receiver); qDebug() << "cmdMessage: recv=" << receiver << (userHandler == 0 ? "not found" : "found"); if (!userHandler) @@ -357,18 +441,19 @@ ResponseCode Server_ProtocolHandler::cmdMessage(Command_Message *cmd, CommandCon if (userHandler->getIgnoreList().contains(userInfo->getName())) return RespInIgnoreList; - cont->enqueueItem(new Event_Message(userInfo->getName(), receiver, cmd->getText())); - userHandler->sendProtocolItem(new Event_Message(userInfo->getName(), receiver, cmd->getText())); + QString message = QString::fromStdString(cmd.message()); + bla->enqueueItem(new Event_Message(userInfo->getName(), receiver, message)); + userHandler->sendProtocolItem(new Event_Message(userInfo->getName(), receiver, message)); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(Command_GetGamesOfUser *cmd, CommandContainer *cont) +ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, CommandContainer *cont, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; server->serverMutex.lock(); - if (!server->getUsers().contains(cmd->getUserName())) + if (!server->getUsers().contains(QString::fromStdString(cmd.user_name()))) return RespNameNotFound; QList roomList; @@ -378,38 +463,39 @@ ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(Command_GetGamesOfUser *c Server_Room *room = roomIterator.next().value(); room->roomMutex.lock(); roomList.append(room->getInfo(false, true)); - gameList << room->getGamesOfUser(cmd->getUserName()); + gameList << room->getGamesOfUser(QString::fromStdString(cmd.user_name())); room->roomMutex.unlock(); } server->serverMutex.unlock(); - ProtocolResponse *resp = new Response_GetGamesOfUser(cont->getCmdId(), RespOk, roomList, gameList); + ProtocolResponse *resp = new Response_GetGamesOfUser(cont->cmd_id(), RespOk, roomList, gameList); if (getCompressionSupport()) resp->setCompressed(true); - cont->setResponse(resp); + bla->setResponse(resp); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdGetUserInfo(Command_GetUserInfo *cmd, CommandContainer *cont) +ResponseCode Server_ProtocolHandler::cmdGetUserInfo(const Command_GetUserInfo &cmd, CommandContainer *cont, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; + QString userName = QString::fromStdString(cmd.user_name()); ServerInfo_User *result; - if (cmd->getUserName().isEmpty()) + if (userName.isEmpty()) result = new ServerInfo_User(userInfo); else { - Server_ProtocolHandler *handler = server->getUsers().value(cmd->getUserName()); + Server_ProtocolHandler *handler = server->getUsers().value(userName); if (!handler) return RespNameNotFound; result = new ServerInfo_User(handler->getUserInfo(), true, userInfo->getUserLevel() & ServerInfo_User::IsModerator); } - cont->setResponse(new Response_GetUserInfo(cont->getCmdId(), RespOk, result)); + bla->setResponse(new Response_GetUserInfo(cont->cmd_id(), RespOk, result)); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdListRooms(Command_ListRooms * /*cmd*/, CommandContainer *cont) +ResponseCode Server_ProtocolHandler::cmdListRooms(const Command_ListRooms & /*cmd*/, CommandContainer *cont, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -418,21 +504,21 @@ ResponseCode Server_ProtocolHandler::cmdListRooms(Command_ListRooms * /*cmd*/, C QMapIterator roomIterator(server->getRooms()); while (roomIterator.hasNext()) eventRoomList.append(roomIterator.next().value()->getInfo(false)); - cont->enqueueItem(new Event_ListRooms(eventRoomList)); + bla->enqueueItem(new Event_ListRooms(eventRoomList)); acceptsRoomListChanges = true; return RespOk; } -ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandContainer *cont) +ResponseCode Server_ProtocolHandler::cmdJoinRoom(const Command_JoinRoom &cmd, CommandContainer *cont, BlaContainer *bla) { if (authState == PasswordWrong) return RespLoginNeeded; - if (rooms.contains(cmd->getRoomId())) + if (rooms.contains(cmd.room_id())) return RespContextError; - Server_Room *r = server->getRooms().value(cmd->getRoomId(), 0); + Server_Room *r = server->getRooms().value(cmd.room_id(), 0); if (!r) return RespNameNotFound; @@ -446,20 +532,39 @@ ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandC ServerInfo_Room *info = r->getInfo(true); if (getCompressionSupport()) info->setCompressed(true); - cont->setResponse(new Response_JoinRoom(cont->getCmdId(), RespOk, info)); + bla->setResponse(new Response_JoinRoom(cont->cmd_id(), RespOk, info)); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdLeaveRoom(Command_LeaveRoom * /*cmd*/, CommandContainer * /*cont*/, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdListUsers(const Command_ListUsers & /*cmd*/, CommandContainer *cont, BlaContainer *bla) +{ + if (authState == PasswordWrong) + return RespLoginNeeded; + + QList resultList; + QMapIterator userIterator = server->getUsers(); + while (userIterator.hasNext()) + resultList.append(new ServerInfo_User(userIterator.next().value()->getUserInfo(), false)); + + acceptsUserListChanges = true; + + ProtocolResponse *resp = new Response_ListUsers(cont->cmd_id(), RespOk, resultList); + if (getCompressionSupport()) + resp->setCompressed(true); + bla->setResponse(resp); + return RespNothing; +} + +ResponseCode Server_ProtocolHandler::cmdLeaveRoom(const Command_LeaveRoom & /*cmd*/, CommandContainer * /*cont*/, Server_Room *room) { rooms.remove(room->getId()); room->removeClient(this); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdRoomSay(Command_RoomSay *cmd, CommandContainer * /*cont*/, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdRoomSay(const Command_RoomSay &cmd, CommandContainer * /*cont*/, Server_Room *room) { - QString msg = cmd->getMessage(); + QString msg = QString::fromStdString(cmd.message()); if (server->getMessageCountingInterval() > 0) { int totalSize = 0, totalCount = 0; @@ -484,26 +589,7 @@ ResponseCode Server_ProtocolHandler::cmdRoomSay(Command_RoomSay *cmd, CommandCon return RespOk; } -ResponseCode Server_ProtocolHandler::cmdListUsers(Command_ListUsers * /*cmd*/, CommandContainer *cont) -{ - if (authState == PasswordWrong) - return RespLoginNeeded; - - QList resultList; - QMapIterator userIterator = server->getUsers(); - while (userIterator.hasNext()) - resultList.append(new ServerInfo_User(userIterator.next().value()->getUserInfo(), false)); - - acceptsUserListChanges = true; - - ProtocolResponse *resp = new Response_ListUsers(cont->getCmdId(), RespOk, resultList); - if (getCompressionSupport()) - resp->setCompressed(true); - cont->setResponse(resp); - return RespNothing; -} - -ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer * /*cont*/, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdCreateGame(const Command_CreateGame &cmd, CommandContainer * /*cont*/, Server_Room *room) { if (authState == PasswordWrong) return RespLoginNeeded; @@ -513,14 +599,13 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm return RespContextError; QList gameTypes; - QList gameTypeList = cmd->getGameTypes(); - for (int i = 0; i < gameTypeList.size(); ++i) - gameTypes.append(gameTypeList[i]->getData()); + for (int i = cmd.game_type_ids_size() - 1; i >= 0; --i) + gameTypes.append(cmd.game_type_ids(i)); - QString description = cmd->getDescription(); + QString description = QString::fromStdString(cmd.description()); if (description.size() > 60) description = description.left(60); - Server_Game *game = room->createGame(description, cmd->getPassword(), cmd->getMaxPlayers(), gameTypes, cmd->getOnlyBuddies(), cmd->getOnlyRegistered(), cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this); + Server_Game *game = room->createGame(description, QString::fromStdString(cmd.password()), cmd.max_players(), gameTypes, cmd.only_buddies(), cmd.only_registered(), cmd.spectators_allowed(), cmd.spectators_need_password(), cmd.spectators_can_talk(), cmd.spectators_see_everything(), this); Server_Player *creator = game->getPlayers().values().first(); @@ -535,62 +620,62 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm return RespOk; } -ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer * /*cont*/, Server_Room *room) +ResponseCode Server_ProtocolHandler::cmdJoinGame(const Command_JoinGame &cmd, CommandContainer * /*cont*/, Server_Room *room) { if (authState == PasswordWrong) return RespLoginNeeded; QMutexLocker gameListLocker(&gameListMutex); - if (games.contains(cmd->getGameId())) + if (games.contains(cmd.game_id())) return RespContextError; - Server_Game *g = room->getGames().value(cmd->getGameId()); + Server_Game *g = room->getGames().value(cmd.game_id()); if (!g) return RespNameNotFound; QMutexLocker locker(&g->gameMutex); - ResponseCode result = g->checkJoin(userInfo, cmd->getPassword(), cmd->getSpectator(), cmd->getOverrideRestrictions()); + ResponseCode result = g->checkJoin(userInfo, QString::fromStdString(cmd.password()), cmd.spectator(), cmd.override_restrictions()); if (result == RespOk) { - Server_Player *player = g->addPlayer(this, cmd->getSpectator()); - games.insert(cmd->getGameId(), QPair(g, player)); - enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), g->getDescription(), g->getHostId(), player->getPlayerId(), cmd->getSpectator(), g->getSpectatorsCanTalk(), g->getSpectatorsSeeEverything(), false)); - enqueueProtocolItem(GameEventContainer::makeNew(new Event_GameStateChanged(g->getGameStarted(), g->getActivePlayer(), g->getActivePhase(), g->getGameState(player)), cmd->getGameId())); + Server_Player *player = g->addPlayer(this, cmd.spectator()); + games.insert(cmd.game_id(), QPair(g, player)); + enqueueProtocolItem(new Event_GameJoined(cmd.game_id(), g->getDescription(), g->getHostId(), player->getPlayerId(), cmd.spectator(), g->getSpectatorsCanTalk(), g->getSpectatorsSeeEverything(), false)); + enqueueProtocolItem(GameEventContainer::makeNew(new Event_GameStateChanged(g->getGameStarted(), g->getActivePlayer(), g->getActivePhase(), g->getGameState(player)), cmd.game_id())); } return result; } -ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdLeaveGame(const Command_LeaveGame & /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { game->removePlayer(player); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdKickFromGame(Command_KickFromGame *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdKickFromGame(const Command_KickFromGame &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if ((game->getHostId() != player->getPlayerId()) && !(userInfo->getUserLevel() & ServerInfo_User::IsModerator)) return RespFunctionNotAllowed; - if (!game->kickPlayer(cmd->getPlayerId())) + if (!game->kickPlayer(cmd.player_id())) return RespNameNotFound; return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdDeckSelect(const Command_DeckSelect &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; DeckList *deck; - if (cmd->getDeckId() == -1) { - if (!cmd->getDeck()) - return RespInvalidData; - deck = new DeckList(cmd->getDeck()); + if (cmd.deck_id() == -1) { +// if (!cmd->getDeck()) +// return RespInvalidData; +// deck = new DeckList(cmd->getDeck()); } else { try { - deck = getDeckFromDatabase(cmd->getDeckId()); + deck = getDeckFromDatabase(cmd.deck_id()); } catch(ResponseCode r) { return r; } @@ -599,11 +684,11 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Comm game->sendGameEvent(new Event_PlayerPropertiesChanged(player->getPlayerId(), player->getProperties()), new Context_DeckSelect(deck->getDeckHash())); - cont->setResponse(new Response_DeckDownload(cont->getCmdId(), RespOk, new DeckList(deck))); + bla->setResponse(new Response_DeckDownload(cont->cmd_id(), RespOk, new DeckList(deck))); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(Command_SetSideboardPlan *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -614,11 +699,19 @@ ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(Command_SetSideboardPla if (!deck) return RespContextError; - deck->setCurrentSideboardPlan(cmd->getMoveList()); + QList sideboardPlan; + for (int i = 0; i < cmd.move_list_size(); ++i) { + const MoveCard_ToZone &temp = cmd.move_list(i); + sideboardPlan.append(new MoveCardToZone(QString::fromStdString(temp.card_name()), QString::fromStdString(temp.start_zone()), QString::fromStdString(temp.target_zone()))); + } + deck->setCurrentSideboardPlan(sideboardPlan); + for (int i = 0; i < sideboardPlan.size(); ++i) + delete sideboardPlan[i]; + // TEMPORARY HACK return RespOk; } -ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdConcede(const Command_Concede & /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -638,7 +731,7 @@ ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, Comma return RespOk; } -ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdReadyStart(const Command_ReadyStart &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -646,25 +739,25 @@ ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart *cmd, Comm if (!player->getDeck() || game->getGameStarted()) return RespContextError; - if (player->getReadyStart() == cmd->getReady()) + if (player->getReadyStart() == cmd.ready()) return RespContextError; - player->setReadyStart(cmd->getReady()); + player->setReadyStart(cmd.ready()); game->sendGameEvent(new Event_PlayerPropertiesChanged(player->getPlayerId(), player->getProperties()), new Context_ReadyStart); game->startGameIfReady(); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdGameSay(const Command_GameSay &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator() && !game->getSpectatorsCanTalk() && !(userInfo->getUserLevel() & ServerInfo_User::IsModerator)) return RespFunctionNotAllowed; - game->sendGameEvent(new Event_Say(player->getPlayerId(), cmd->getMessage())); + game->sendGameEvent(new Event_Say(player->getPlayerId(), QString::fromStdString(cmd.message()))); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdShuffle(const Command_Shuffle & /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -679,7 +772,7 @@ ResponseCode Server_ProtocolHandler::cmdShuffle(Command_Shuffle * /*cmd*/, Comma return RespOk; } -ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdMulligan(const Command_Mulligan & /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -694,39 +787,40 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com Server_CardZone *deck = player->getZones().value("deck"); while (!hand->cards.isEmpty()) { - CardToMove *cardToMove = new CardToMove(hand->cards.first()->getId()); - player->moveCard(cont, hand, QList() << cardToMove, deck, 0, 0, false); + CardToMove *cardToMove = new CardToMove; + cardToMove->set_card_id(hand->cards.first()->getId()); + player->moveCard(bla, hand, QList() << cardToMove, deck, 0, 0, false); delete cardToMove; } deck->shuffle(); - cont->enqueueGameEventPrivate(new Event_Shuffle(player->getPlayerId()), game->getGameId()); - cont->enqueueGameEventOmniscient(new Event_Shuffle(player->getPlayerId()), game->getGameId()); - cont->enqueueGameEventPublic(new Event_Shuffle(player->getPlayerId()), game->getGameId()); + bla->enqueueGameEventPrivate(new Event_Shuffle(player->getPlayerId()), game->getGameId()); + bla->enqueueGameEventOmniscient(new Event_Shuffle(player->getPlayerId()), game->getGameId()); + bla->enqueueGameEventPublic(new Event_Shuffle(player->getPlayerId()), game->getGameId()); - player->drawCards(cont, number); + player->drawCards(bla, number); if (number == player->getInitialCards()) number = -1; - cont->getGameEventQueuePrivate()->setContext(new Context_Mulligan(number)); - cont->getGameEventQueuePublic()->setContext(new Context_Mulligan(number)); - cont->getGameEventQueueOmniscient()->setContext(new Context_Mulligan(number)); + bla->getGameEventQueuePrivate()->setContext(new Context_Mulligan(number)); + bla->getGameEventQueuePublic()->setContext(new Context_Mulligan(number)); + bla->getGameEventQueueOmniscient()->setContext(new Context_Mulligan(number)); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdRollDie(const Command_RollDie &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; if (player->getConceded()) return RespContextError; - game->sendGameEvent(new Event_RollDie(player->getPlayerId(), cmd->getSides(), rng->getNumber(1, cmd->getSides()))); + game->sendGameEvent(new Event_RollDie(player->getPlayerId(), cmd.sides(), rng->getNumber(1, cmd.sides()))); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdDrawCards(const Command_DrawCards &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -736,10 +830,10 @@ ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, Comman if (player->getConceded()) return RespContextError; - return player->drawCards(cont, cmd->getNumber()); + return player->drawCards(bla, cmd.number()); } -ResponseCode Server_ProtocolHandler::cmdUndoDraw(Command_UndoDraw * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdUndoDraw(const Command_UndoDraw & /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -749,10 +843,10 @@ ResponseCode Server_ProtocolHandler::cmdUndoDraw(Command_UndoDraw * /*cmd*/, Com if (player->getConceded()) return RespContextError; - return player->undoDraw(cont); + return player->undoDraw(bla); } -ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdMoveCard(const Command_MoveCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -762,10 +856,14 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandC if (player->getConceded()) return RespContextError; - return player->moveCard(cont, cmd->getStartZone(), cmd->getCards(), cmd->getTargetPlayerId(), cmd->getTargetZone(), cmd->getX(), cmd->getY()); + QList cardsToMove; + for (int i = 0; i < cmd.cards_to_move_size(); ++i) + cardsToMove.append(&cmd.cards_to_move(i)); + + return player->moveCard(bla, QString::fromStdString(cmd.start_zone()), cardsToMove, cmd.target_player_id(), QString::fromStdString(cmd.target_zone()), cmd.x(), cmd.y()); } -ResponseCode Server_ProtocolHandler::cmdFlipCard(Command_FlipCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdFlipCard(const Command_FlipCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -775,28 +873,28 @@ ResponseCode Server_ProtocolHandler::cmdFlipCard(Command_FlipCard *cmd, CommandC if (player->getConceded()) return RespContextError; - Server_CardZone *zone = player->getZones().value(cmd->getZone()); + Server_CardZone *zone = player->getZones().value(QString::fromStdString(cmd.zone())); if (!zone) return RespNameNotFound; if (!zone->hasCoords()) return RespContextError; - Server_Card *card = zone->getCard(cmd->getCardId()); + Server_Card *card = zone->getCard(cmd.card_id()); if (!card) return RespNameNotFound; - const bool faceDown = cmd->getFaceDown(); + const bool faceDown = cmd.face_down(); if (faceDown == card->getFaceDown()) return RespContextError; card->setFaceDown(faceDown); - cont->enqueueGameEventPrivate(new Event_FlipCard(player->getPlayerId(), zone->getName(), card->getId(), card->getName(), faceDown), game->getGameId()); - cont->enqueueGameEventPublic(new Event_FlipCard(player->getPlayerId(), zone->getName(), card->getId(), card->getName(), faceDown), game->getGameId()); + bla->enqueueGameEventPrivate(new Event_FlipCard(player->getPlayerId(), zone->getName(), card->getId(), card->getName(), faceDown), game->getGameId()); + bla->enqueueGameEventPublic(new Event_FlipCard(player->getPlayerId(), zone->getName(), card->getId(), card->getName(), faceDown), game->getGameId()); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdAttachCard(const Command_AttachCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -806,33 +904,33 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm if (player->getConceded()) return RespContextError; - Server_CardZone *startzone = player->getZones().value(cmd->getStartZone()); + Server_CardZone *startzone = player->getZones().value(QString::fromStdString(cmd.start_zone())); if (!startzone) return RespNameNotFound; - Server_Card *card = startzone->getCard(cmd->getCardId()); + Server_Card *card = startzone->getCard(cmd.card_id()); if (!card) return RespNameNotFound; - int playerId = cmd->getTargetPlayerId(); + int playerId = cmd.target_player_id(); Server_Player *targetPlayer = 0; Server_CardZone *targetzone = 0; Server_Card *targetCard = 0; if (playerId != -1) { - targetPlayer = game->getPlayer(cmd->getTargetPlayerId()); + targetPlayer = game->getPlayer(cmd.target_player_id()); if (!targetPlayer) return RespNameNotFound; } else if (!card->getParentCard()) return RespContextError; if (targetPlayer) - targetzone = targetPlayer->getZones().value(cmd->getTargetZone()); + targetzone = targetPlayer->getZones().value(QString::fromStdString(cmd.target_zone())); if (targetzone) { // This is currently enough to make sure cards don't get attached to a card that is not on the table. // Possibly a flag will have to be introduced for this sometime. if (!targetzone->hasCoords()) return RespContextError; - targetCard = targetzone->getCard(cmd->getTargetCardId()); + targetCard = targetzone->getCard(cmd.target_card_id()); if (targetCard) if (targetCard->getParentCard()) return RespContextError; @@ -853,8 +951,8 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm toDelete.append(a); } for (int i = 0; i < toDelete.size(); ++i) { - cont->enqueueGameEventPrivate(new Event_DeleteArrow(p->getPlayerId(), toDelete[i]->getId()), game->getGameId()); - cont->enqueueGameEventPublic(new Event_DeleteArrow(p->getPlayerId(), toDelete[i]->getId()), game->getGameId()); + bla->enqueueGameEventPrivate(new Event_DeleteArrow(p->getPlayerId(), toDelete[i]->getId()), game->getGameId()); + bla->enqueueGameEventPublic(new Event_DeleteArrow(p->getPlayerId(), toDelete[i]->getId()), game->getGameId()); p->deleteArrow(toDelete[i]->getId()); } } @@ -864,26 +962,27 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm // Make a copy of the list because its contents change during the loop otherwise. QList attachedList = card->getAttachedCards(); for (int i = 0; i < attachedList.size(); ++i) - attachedList[i]->getZone()->getPlayer()->unattachCard(cont, attachedList[i]); + attachedList[i]->getZone()->getPlayer()->unattachCard(bla, attachedList[i]); if (targetzone->isColumnStacked(targetCard->getX(), targetCard->getY())) { - CardToMove *cardToMove = new CardToMove(targetCard->getId()); - targetPlayer->moveCard(cont, targetzone, QList() << cardToMove, targetzone, targetzone->getFreeGridColumn(-2, targetCard->getY(), targetCard->getName()), targetCard->getY(), targetCard->getFaceDown()); + CardToMove *cardToMove = new CardToMove; + cardToMove->set_card_id(targetCard->getId()); + targetPlayer->moveCard(bla, targetzone, QList() << cardToMove, targetzone, targetzone->getFreeGridColumn(-2, targetCard->getY(), targetCard->getName()), targetCard->getY(), targetCard->getFaceDown()); delete cardToMove; } card->setParentCard(targetCard); card->setCoords(-1, card->getY()); - cont->enqueueGameEventPrivate(new Event_AttachCard(player->getPlayerId(), startzone->getName(), card->getId(), targetPlayer->getPlayerId(), targetzone->getName(), targetCard->getId()), game->getGameId()); - cont->enqueueGameEventPublic(new Event_AttachCard(player->getPlayerId(), startzone->getName(), card->getId(), targetPlayer->getPlayerId(), targetzone->getName(), targetCard->getId()), game->getGameId()); - startzone->fixFreeSpaces(cont); + bla->enqueueGameEventPrivate(new Event_AttachCard(player->getPlayerId(), startzone->getName(), card->getId(), targetPlayer->getPlayerId(), targetzone->getName(), targetCard->getId()), game->getGameId()); + bla->enqueueGameEventPublic(new Event_AttachCard(player->getPlayerId(), startzone->getName(), card->getId(), targetPlayer->getPlayerId(), targetzone->getName(), targetCard->getId()), game->getGameId()); + startzone->fixFreeSpaces(bla); } else - player->unattachCard(cont, card); + player->unattachCard(bla, card); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdCreateToken(const Command_CreateToken &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -893,33 +992,34 @@ ResponseCode Server_ProtocolHandler::cmdCreateToken(Command_CreateToken *cmd, Co if (player->getConceded()) return RespContextError; - Server_CardZone *zone = player->getZones().value(cmd->getZone()); + Server_CardZone *zone = player->getZones().value(QString::fromStdString(cmd.zone())); if (!zone) return RespNameNotFound; - int x = cmd->getX(); - int y = cmd->getY(); + QString cardName = QString::fromStdString(cmd.card_name()); + int x = cmd.x(); + int y = cmd.y(); if (zone->hasCoords()) - x = zone->getFreeGridColumn(x, y, cmd->getCardName()); + x = zone->getFreeGridColumn(x, y, cardName); if (x < 0) x = 0; if (y < 0) y = 0; - Server_Card *card = new Server_Card(cmd->getCardName(), player->newCardId(), x, y); + Server_Card *card = new Server_Card(cardName, player->newCardId(), x, y); card->moveToThread(player->thread()); - card->setPT(cmd->getPt()); - card->setColor(cmd->getColor()); - card->setAnnotation(cmd->getAnnotation()); - card->setDestroyOnZoneChange(cmd->getDestroy()); + card->setPT(QString::fromStdString(cmd.pt())); + card->setColor(QString::fromStdString(cmd.color())); + card->setAnnotation(QString::fromStdString(cmd.annotation())); + card->setDestroyOnZoneChange(cmd.destroy_on_zone_change()); zone->insertCard(card, x, y); - game->sendGameEvent(new Event_CreateToken(player->getPlayerId(), zone->getName(), card->getId(), card->getName(), cmd->getColor(), cmd->getPt(), cmd->getAnnotation(), cmd->getDestroy(), x, y)); + game->sendGameEvent(new Event_CreateToken(player->getPlayerId(), zone->getName(), card->getId(), card->getName(), card->getColor(), card->getPT(), card->getAnnotation(), card->getDestroyOnZoneChange(), x, y)); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdCreateArrow(const Command_CreateArrow &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -929,27 +1029,29 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Co if (player->getConceded()) return RespContextError; - Server_Player *startPlayer = game->getPlayer(cmd->getStartPlayerId()); - Server_Player *targetPlayer = game->getPlayer(cmd->getTargetPlayerId()); + Server_Player *startPlayer = game->getPlayer(cmd.start_player_id()); + Server_Player *targetPlayer = game->getPlayer(cmd.target_player_id()); if (!startPlayer || !targetPlayer) return RespNameNotFound; - Server_CardZone *startZone = startPlayer->getZones().value(cmd->getStartZone()); - bool playerTarget = cmd->getTargetZone().isEmpty(); + QString startZoneName = QString::fromStdString(cmd.start_zone()); + Server_CardZone *startZone = startPlayer->getZones().value(startZoneName); + QString targetZoneName = QString::fromStdString(cmd.target_zone()); + bool playerTarget = targetZoneName.isEmpty(); Server_CardZone *targetZone = 0; if (!playerTarget) - targetZone = targetPlayer->getZones().value(cmd->getTargetZone()); + targetZone = targetPlayer->getZones().value(targetZoneName); if (!startZone || (!targetZone && !playerTarget)) return RespNameNotFound; if (startZone->getType() != PublicZone) return RespContextError; - Server_Card *startCard = startZone->getCard(cmd->getStartCardId()); + Server_Card *startCard = startZone->getCard(cmd.start_card_id()); if (!startCard) return RespNameNotFound; Server_Card *targetCard = 0; if (!playerTarget) { if (targetZone->getType() != PublicZone) return RespContextError; - targetCard = targetZone->getCard(cmd->getTargetCardId()); + targetCard = targetZone->getCard(cmd.target_card_id()); } Server_ArrowTarget *targetItem; @@ -967,22 +1069,22 @@ ResponseCode Server_ProtocolHandler::cmdCreateArrow(Command_CreateArrow *cmd, Co return RespContextError; } - Server_Arrow *arrow = new Server_Arrow(player->newArrowId(), startCard, targetItem, cmd->getColor()); + Server_Arrow *arrow = new Server_Arrow(player->newArrowId(), startCard, targetItem, cmd.arrow_color()); player->addArrow(arrow); game->sendGameEvent(new Event_CreateArrows(player->getPlayerId(), QList() << new ServerInfo_Arrow( arrow->getId(), startPlayer->getPlayerId(), - startZone->getName(), + startZoneName, startCard->getId(), targetPlayer->getPlayerId(), - cmd->getTargetZone(), - cmd->getTargetCardId(), - cmd->getColor() + targetZoneName, + cmd.target_card_id(), + cmd.arrow_color() ))); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdDeleteArrow(const Command_DeleteArrow &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -992,14 +1094,14 @@ ResponseCode Server_ProtocolHandler::cmdDeleteArrow(Command_DeleteArrow *cmd, Co if (player->getConceded()) return RespContextError; - if (!player->deleteArrow(cmd->getArrowId())) + if (!player->deleteArrow(cmd.arrow_id())) return RespNameNotFound; - game->sendGameEvent(new Event_DeleteArrow(player->getPlayerId(), cmd->getArrowId())); + game->sendGameEvent(new Event_DeleteArrow(player->getPlayerId(), cmd.arrow_id())); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdSetCardAttr(const Command_SetCardAttr &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1009,10 +1111,10 @@ ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Co if (player->getConceded()) return RespContextError; - return player->setCardAttrHelper(cont, cmd->getZone(), cmd->getCardId(), cmd->getAttrName(), cmd->getAttrValue()); + return player->setCardAttrHelper(bla, QString::fromStdString(cmd.zone()), cmd.card_id(), QString::fromStdString(cmd.attr_name()), QString::fromStdString(cmd.attr_value())); } -ResponseCode Server_ProtocolHandler::cmdSetCardCounter(Command_SetCardCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdSetCardCounter(const Command_SetCardCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1022,24 +1124,24 @@ ResponseCode Server_ProtocolHandler::cmdSetCardCounter(Command_SetCardCounter *c if (player->getConceded()) return RespContextError; - Server_CardZone *zone = player->getZones().value(cmd->getZone()); + Server_CardZone *zone = player->getZones().value(QString::fromStdString(cmd.zone())); if (!zone) return RespNameNotFound; if (!zone->hasCoords()) return RespContextError; - Server_Card *card = zone->getCard(cmd->getCardId()); + Server_Card *card = zone->getCard(cmd.card_id()); if (!card) return RespNameNotFound; - card->setCounter(cmd->getCounterId(), cmd->getCounterValue()); + card->setCounter(cmd.counter_id(), cmd.counter_value()); - cont->enqueueGameEventPrivate(new Event_SetCardCounter(player->getPlayerId(), zone->getName(), card->getId(), cmd->getCounterId(), cmd->getCounterValue()), game->getGameId()); - cont->enqueueGameEventPublic(new Event_SetCardCounter(player->getPlayerId(), zone->getName(), card->getId(), cmd->getCounterId(), cmd->getCounterValue()), game->getGameId()); + bla->enqueueGameEventPrivate(new Event_SetCardCounter(player->getPlayerId(), zone->getName(), card->getId(), cmd.counter_id(), cmd.counter_value()), game->getGameId()); + bla->enqueueGameEventPublic(new Event_SetCardCounter(player->getPlayerId(), zone->getName(), card->getId(), cmd.counter_id(), cmd.counter_value()), game->getGameId()); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdIncCardCounter(Command_IncCardCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdIncCardCounter(const Command_IncCardCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1049,25 +1151,25 @@ ResponseCode Server_ProtocolHandler::cmdIncCardCounter(Command_IncCardCounter *c if (player->getConceded()) return RespContextError; - Server_CardZone *zone = player->getZones().value(cmd->getZone()); + Server_CardZone *zone = player->getZones().value(QString::fromStdString(cmd.zone())); if (!zone) return RespNameNotFound; if (!zone->hasCoords()) return RespContextError; - Server_Card *card = zone->getCard(cmd->getCardId()); + Server_Card *card = zone->getCard(cmd.card_id()); if (!card) return RespNameNotFound; - int newValue = card->getCounter(cmd->getCounterId()) + cmd->getCounterDelta(); - card->setCounter(cmd->getCounterId(), newValue); + int newValue = card->getCounter(cmd.counter_id()) + cmd.counter_delta(); + card->setCounter(cmd.counter_id(), newValue); - cont->enqueueGameEventPrivate(new Event_SetCardCounter(player->getPlayerId(), zone->getName(), card->getId(), cmd->getCounterId(), newValue), game->getGameId()); - cont->enqueueGameEventPublic(new Event_SetCardCounter(player->getPlayerId(), zone->getName(), card->getId(), cmd->getCounterId(), newValue), game->getGameId()); + bla->enqueueGameEventPrivate(new Event_SetCardCounter(player->getPlayerId(), zone->getName(), card->getId(), cmd.counter_id(), newValue), game->getGameId()); + bla->enqueueGameEventPublic(new Event_SetCardCounter(player->getPlayerId(), zone->getName(), card->getId(), cmd.counter_id(), newValue), game->getGameId()); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdIncCounter(const Command_IncCounter &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1078,16 +1180,16 @@ ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Comm return RespContextError; const QMap counters = player->getCounters(); - Server_Counter *c = counters.value(cmd->getCounterId(), 0); + Server_Counter *c = counters.value(cmd.counter_id(), 0); if (!c) return RespNameNotFound; - c->setCount(c->getCount() + cmd->getDelta()); + c->setCount(c->getCount() + cmd.delta()); game->sendGameEvent(new Event_SetCounter(player->getPlayerId(), c->getId(), c->getCount())); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdCreateCounter(const Command_CreateCounter &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1097,14 +1199,14 @@ ResponseCode Server_ProtocolHandler::cmdCreateCounter(Command_CreateCounter *cmd if (player->getConceded()) return RespContextError; - Server_Counter *c = new Server_Counter(player->newCounterId(), cmd->getCounterName(), cmd->getColor(), cmd->getRadius(), cmd->getValue()); + Server_Counter *c = new Server_Counter(player->newCounterId(), QString::fromStdString(cmd.counter_name()), cmd.counter_color(), cmd.radius(), cmd.value()); player->addCounter(c); game->sendGameEvent(new Event_CreateCounters(player->getPlayerId(), QList() << new ServerInfo_Counter(c->getId(), c->getName(), c->getColor(), c->getRadius(), c->getCount()))); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdSetCounter(const Command_SetCounter &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1114,16 +1216,16 @@ ResponseCode Server_ProtocolHandler::cmdSetCounter(Command_SetCounter *cmd, Comm if (player->getConceded()) return RespContextError; - Server_Counter *c = player->getCounters().value(cmd->getCounterId(), 0);; + Server_Counter *c = player->getCounters().value(cmd.counter_id(), 0);; if (!c) return RespNameNotFound; - c->setCount(cmd->getValue()); + c->setCount(cmd.value()); game->sendGameEvent(new Event_SetCounter(player->getPlayerId(), c->getId(), c->getCount())); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdDelCounter(const Command_DelCounter &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1133,13 +1235,13 @@ ResponseCode Server_ProtocolHandler::cmdDelCounter(Command_DelCounter *cmd, Comm if (player->getConceded()) return RespContextError; - if (!player->deleteCounter(cmd->getCounterId())) + if (!player->deleteCounter(cmd.counter_id())) return RespNameNotFound; - game->sendGameEvent(new Event_DelCounter(player->getPlayerId(), cmd->getCounterId())); + game->sendGameEvent(new Event_DelCounter(player->getPlayerId(), cmd.counter_id())); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdNextTurn(const Command_NextTurn & /*cmd*/, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1153,7 +1255,7 @@ ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, Com return RespOk; } -ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdSetActivePhase(const Command_SetActivePhase &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1165,26 +1267,26 @@ ResponseCode Server_ProtocolHandler::cmdSetActivePhase(Command_SetActivePhase *c if (game->getActivePlayer() != player->getPlayerId()) return RespContextError; - game->setActivePhase(cmd->getPhase()); + game->setActivePhase(cmd.phase()); return RespOk; } -ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdDumpZone(const Command_DumpZone &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (!game->getGameStarted()) return RespGameNotStarted; - Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId()); + Server_Player *otherPlayer = game->getPlayer(cmd.player_id()); if (!otherPlayer) return RespNameNotFound; - Server_CardZone *zone = otherPlayer->getZones().value(cmd->getZoneName()); + Server_CardZone *zone = otherPlayer->getZones().value(QString::fromStdString(cmd.zone_name())); if (!zone) return RespNameNotFound; if (!((zone->getType() == PublicZone) || (player == otherPlayer))) return RespContextError; - int numberCards = cmd->getNumberCards(); + int numberCards = cmd.number_cards(); QList respCardList; for (int i = 0; (i < zone->cards.size()) && (i < numberCards || numberCards == -1); ++i) { Server_Card *card = zone->cards[i]; @@ -1215,32 +1317,32 @@ ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, CommandC zone->setCardsBeingLookedAt(numberCards); game->sendGameEvent(new Event_DumpZone(player->getPlayerId(), otherPlayer->getPlayerId(), zone->getName(), numberCards)); } - cont->setResponse(new Response_DumpZone(cont->getCmdId(), RespOk, new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), numberCards < zone->cards.size() ? zone->cards.size() : numberCards, respCardList))); + bla->setResponse(new Response_DumpZone(cont->cmd_id(), RespOk, new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), numberCards < zone->cards.size() ? zone->cards.size() : numberCards, respCardList))); return RespNothing; } -ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdStopDumpZone(const Command_StopDumpZone &cmd, CommandContainer * /*cont*/, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (!game->getGameStarted()) return RespGameNotStarted; if (player->getConceded()) return RespContextError; - Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId()); + Server_Player *otherPlayer = game->getPlayer(cmd.player_id()); if (!otherPlayer) return RespNameNotFound; - Server_CardZone *zone = otherPlayer->getZones().value(cmd->getZoneName()); + Server_CardZone *zone = otherPlayer->getZones().value(QString::fromStdString(cmd.zone_name())); if (!zone) return RespNameNotFound; if (zone->getType() == HiddenZone) { zone->setCardsBeingLookedAt(0); - game->sendGameEvent(new Event_StopDumpZone(player->getPlayerId(), cmd->getPlayerId(), zone->getName())); + game->sendGameEvent(new Event_StopDumpZone(player->getPlayerId(), cmd.player_id(), zone->getName())); } return RespOk; } -ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) +ResponseCode Server_ProtocolHandler::cmdRevealCards(const Command_RevealCards &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla) { if (player->getSpectator()) return RespFunctionNotAllowed; @@ -1251,24 +1353,24 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, Co return RespContextError; Server_Player *otherPlayer = 0; - if (cmd->getPlayerId() != -1) { - otherPlayer = game->getPlayer(cmd->getPlayerId()); + if (cmd.player_id() != -1) { + otherPlayer = game->getPlayer(cmd.player_id()); if (!otherPlayer) return RespNameNotFound; } - Server_CardZone *zone = player->getZones().value(cmd->getZoneName()); + Server_CardZone *zone = player->getZones().value(QString::fromStdString(cmd.zone_name())); if (!zone) return RespNameNotFound; QList cardsToReveal; - if (cmd->getCardId() == -1) + if (cmd.card_id() == -1) cardsToReveal = zone->cards; - else if (cmd->getCardId() == -2) { + else if (cmd.card_id() == -2) { if (zone->cards.isEmpty()) return RespContextError; cardsToReveal.append(zone->cards.at(rng->getNumber(0, zone->cards.size() - 1))); } else { - Server_Card *card = zone->getCard(cmd->getCardId()); + Server_Card *card = zone->getCard(cmd.card_id()); if (!card) return RespNameNotFound; cardsToReveal.append(card); @@ -1295,17 +1397,17 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, Co attachCardId = card->getParentCard()->getId(); } - if (cmd->getPlayerId() != -1) + if (cmd.player_id() != -1) respCardListPrivate.append(new ServerInfo_Card(card->getId(), card->getName(), card->getX(), card->getY(), card->getFaceDown(), card->getTapped(), card->getAttacking(), card->getColor(), card->getPT(), card->getAnnotation(), card->getDestroyOnZoneChange(), card->getDoesntUntap(), cardCounterListPrivate, attachPlayerId, attachZone, attachCardId)); respCardListOmniscient.append(new ServerInfo_Card(card->getId(), card->getName(), card->getX(), card->getY(), card->getFaceDown(), card->getTapped(), card->getAttacking(), card->getColor(), card->getPT(), card->getAnnotation(), card->getDestroyOnZoneChange(), card->getDoesntUntap(), cardCounterListOmniscient, attachPlayerId, attachZone, attachCardId)); } - if (cmd->getPlayerId() == -1) - cont->enqueueGameEventPublic(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd->getCardId(), -1, respCardListOmniscient), game->getGameId()); + if (cmd.player_id() == -1) + bla->enqueueGameEventPublic(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd.card_id(), -1, respCardListOmniscient), game->getGameId()); else { - cont->enqueueGameEventPublic(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd->getCardId(), otherPlayer->getPlayerId()), game->getGameId()); - cont->enqueueGameEventPrivate(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd->getCardId(), otherPlayer->getPlayerId(), respCardListPrivate), game->getGameId(), otherPlayer->getPlayerId()); - cont->enqueueGameEventOmniscient(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd->getCardId(), otherPlayer->getPlayerId(), respCardListOmniscient), game->getGameId()); + bla->enqueueGameEventPublic(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd.card_id(), otherPlayer->getPlayerId()), game->getGameId()); + bla->enqueueGameEventPrivate(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd.card_id(), otherPlayer->getPlayerId(), respCardListPrivate), game->getGameId(), otherPlayer->getPlayerId()); + bla->enqueueGameEventOmniscient(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd.card_id(), otherPlayer->getPlayerId(), respCardListOmniscient), game->getGameId()); } return RespOk; diff --git a/common/server_protocolhandler.h b/common/server_protocolhandler.h index 05b07ce2..cfcfa94d 100644 --- a/common/server_protocolhandler.h +++ b/common/server_protocolhandler.h @@ -13,6 +13,63 @@ class ServerInfo_User; class Server_Room; class QTimer; +class CommandContainer; +class Command_Ping; +class Command_Login; +class Command_Message; +class Command_ListUsers; +class Command_GetGamesOfUser; +class Command_GetUserInfo; +class Command_AddToList; +class Command_RemoveFromList; +class Command_DeckList; +class Command_DeckNewDir; +class Command_DeckDelDir; +class Command_DeckDel; +class Command_DeckDownload; +class Command_DeckUpload; +class Command_ListRooms; +class Command_JoinRoom; +class Command_LeaveRoom; +class Command_RoomSay; +class Command_CreateGame; +class Command_JoinGame; + +class Command_KickFromGame; +class Command_LeaveGame; +class Command_GameSay; +class Command_Shuffle; +class Command_Mulligan; +class Command_RollDie; +class Command_DrawCards; +class Command_UndoDraw; +class Command_FlipCard; +class Command_AttachCard; +class Command_CreateToken; +class Command_CreateArrow; +class Command_DeleteArrow; +class Command_SetCardAttr; +class Command_SetCardCounter; +class Command_IncCardCounter; +class Command_ReadyStart; +class Command_Concede; +class Command_IncCounter; +class Command_CreateCounter; +class Command_SetCounter; +class Command_DelCounter; +class Command_NextTurn; +class Command_SetActivePhase; +class Command_DumpZone; +class Command_StopDumpZone; +class Command_RevealCards; +class Command_MoveCard; +class Command_SetSideboardPlan; +class Command_DeckSelect; + +class Command_BanFromServer; +class Command_UpdateServerMessage; +class Command_ShutdownServer; + class Server_ProtocolHandler : public QObject { Q_OBJECT protected: @@ -40,61 +97,65 @@ private: virtual DeckList *getDeckFromDatabase(int deckId) = 0; - ResponseCode cmdPing(Command_Ping *cmd, CommandContainer *cont); - ResponseCode cmdLogin(Command_Login *cmd, CommandContainer *cont); - ResponseCode cmdMessage(Command_Message *cmd, CommandContainer *cont); - virtual ResponseCode cmdAddToList(Command_AddToList *cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdRemoveFromList(Command_RemoveFromList *cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckList(Command_DeckList *cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckNewDir(Command_DeckNewDir *cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckDel(Command_DeckDel *cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont) = 0; - ResponseCode cmdGetGamesOfUser(Command_GetGamesOfUser *cmd, CommandContainer *cont); - ResponseCode cmdGetUserInfo(Command_GetUserInfo *cmd, CommandContainer *cont); - ResponseCode cmdListRooms(Command_ListRooms *cmd, CommandContainer *cont); - ResponseCode cmdJoinRoom(Command_JoinRoom *cmd, CommandContainer *cont); - ResponseCode cmdLeaveRoom(Command_LeaveRoom *cmd, CommandContainer *cont, Server_Room *room); - ResponseCode cmdRoomSay(Command_RoomSay *cmd, CommandContainer *cont, Server_Room *room); - ResponseCode cmdListUsers(Command_ListUsers *cmd, CommandContainer *cont); - ResponseCode cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont, Server_Room *room); - ResponseCode cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont, Server_Room *room); - ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdKickFromGame(Command_KickFromGame *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdConcede(Command_Concede *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdReadyStart(Command_ReadyStart *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdDeckSelect(Command_DeckSelect *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdSetSideboardPlan(Command_SetSideboardPlan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdSay(Command_Say *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdShuffle(Command_Shuffle *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdMulligan(Command_Mulligan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdRollDie(Command_RollDie *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdDrawCards(Command_DrawCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdUndoDraw(Command_UndoDraw *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdMoveCard(Command_MoveCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdFlipCard(Command_FlipCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdAttachCard(Command_AttachCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdCreateToken(Command_CreateToken *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdSetCardCounter(Command_SetCardCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdIncCardCounter(Command_IncCardCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdIncCounter(Command_IncCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdCreateCounter(Command_CreateCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdSetCounter(Command_SetCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdDelCounter(Command_DelCounter *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdNextTurn(Command_NextTurn *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdSetActivePhase(Command_SetActivePhase *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdDumpZone(Command_DumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - ResponseCode cmdRevealCards(Command_RevealCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player); - virtual ResponseCode cmdBanFromServer(Command_BanFromServer *cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdShutdownServer(Command_ShutdownServer *cmd, CommandContainer *cont) = 0; - virtual ResponseCode cmdUpdateServerMessage(Command_UpdateServerMessage *cmd, CommandContainer *cont) = 0; + ResponseCode cmdPing(const Command_Ping &cmd, CommandContainer *cont); + ResponseCode cmdLogin(const Command_Login &cmd, CommandContainer *cont, BlaContainer *bla); + ResponseCode cmdMessage(const Command_Message &cmd, CommandContainer *cont, BlaContainer *bla); + virtual ResponseCode cmdAddToList(const Command_AddToList &cmd, CommandContainer *cont) = 0; + virtual ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, CommandContainer *cont) = 0; + virtual ResponseCode cmdDeckList(const Command_DeckList &cmd, CommandContainer *cont) = 0; + virtual ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, CommandContainer *cont) = 0; + virtual ResponseCode cmdDeckDelDir(const Command_DeckDelDir &cmd, CommandContainer *cont) = 0; + virtual ResponseCode cmdDeckDel(const Command_DeckDel &cmd, CommandContainer *cont) = 0; + virtual ResponseCode cmdDeckUpload(const Command_DeckUpload &cmd, CommandContainer *cont) = 0; + virtual ResponseCode cmdDeckDownload(const Command_DeckDownload &cmd, CommandContainer *cont) = 0; + ResponseCode cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, CommandContainer *cont, BlaContainer *bla); + ResponseCode cmdGetUserInfo(const Command_GetUserInfo &cmd, CommandContainer *cont, BlaContainer *bla); + ResponseCode cmdListRooms(const Command_ListRooms &cmd, CommandContainer *cont, BlaContainer *bla); + ResponseCode cmdJoinRoom(const Command_JoinRoom &cmd, CommandContainer *cont, BlaContainer *bla); + ResponseCode cmdListUsers(const Command_ListUsers &cmd, CommandContainer *cont, BlaContainer *bla); + ResponseCode cmdLeaveRoom(const Command_LeaveRoom &cmd, CommandContainer *cont, Server_Room *room); + ResponseCode cmdRoomSay(const Command_RoomSay &cmd, CommandContainer *cont, Server_Room *room); + ResponseCode cmdCreateGame(const Command_CreateGame &cmd, CommandContainer *cont, Server_Room *room); + ResponseCode cmdJoinGame(const Command_JoinGame &cmd, CommandContainer *cont, Server_Room *room); + ResponseCode cmdLeaveGame(const Command_LeaveGame &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdKickFromGame(const Command_KickFromGame &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdConcede(const Command_Concede &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdReadyStart(const Command_ReadyStart &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdDeckSelect(const Command_DeckSelect &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdGameSay(const Command_GameSay &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdShuffle(const Command_Shuffle &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdMulligan(const Command_Mulligan &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdRollDie(const Command_RollDie &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdDrawCards(const Command_DrawCards &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdMoveCard(const Command_MoveCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdFlipCard(const Command_FlipCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdAttachCard(const Command_AttachCard &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdCreateToken(const Command_CreateToken &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdCreateArrow(const Command_CreateArrow &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdDeleteArrow(const Command_DeleteArrow &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdSetCardAttr(const Command_SetCardAttr &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdSetCardCounter(const Command_SetCardCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdIncCardCounter(const Command_IncCardCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdIncCounter(const Command_IncCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdCreateCounter(const Command_CreateCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdSetCounter(const Command_SetCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdDelCounter(const Command_DelCounter &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdNextTurn(const Command_NextTurn &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdSetActivePhase(const Command_SetActivePhase &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdDumpZone(const Command_DumpZone &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdStopDumpZone(const Command_StopDumpZone &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + ResponseCode cmdRevealCards(const Command_RevealCards &cmd, CommandContainer *cont, Server_Game *game, Server_Player *player, BlaContainer *bla); + virtual ResponseCode cmdBanFromServer(const Command_BanFromServer &cmd, CommandContainer *cont) = 0; + virtual ResponseCode cmdShutdownServer(const Command_ShutdownServer &cmd, CommandContainer *cont) = 0; + virtual ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage &cmd, CommandContainer *cont) = 0; - ResponseCode processCommandHelper(Command *command, CommandContainer *cont); + ResponseCode processSessionCommandContainer(CommandContainer *cont, BlaContainer *bla); + ResponseCode processRoomCommandContainer(CommandContainer *cont, BlaContainer *bla); + ResponseCode processGameCommandContainer(CommandContainer *cont, BlaContainer *bla); + ResponseCode processModeratorCommandContainer(CommandContainer *cont, BlaContainer *bla); + ResponseCode processAdminCommandContainer(CommandContainer *cont, BlaContainer *bla); private slots: void pingClockTimeout(); public: diff --git a/servatrice/servatrice.pro b/servatrice/servatrice.pro index ab7dc853..4e5c9721 100755 --- a/servatrice/servatrice.pro +++ b/servatrice/servatrice.pro @@ -8,7 +8,7 @@ DEPENDPATH += . src ../common INCLUDEPATH += . src ../common MOC_DIR = build OBJECTS_DIR = build -LIBS += -lgcrypt +LIBS += -lgcrypt -lprotobuf CONFIG += qt debug QT += network sql @@ -37,7 +37,16 @@ HEADERS += src/main.h \ ../common/server_game.h \ ../common/server_player.h \ ../common/server_protocolhandler.h \ - ../common/server_arrowtarget.h + ../common/server_arrowtarget.h \ + ../common/pb/commands.pb.h \ + ../common/pb/color.pb.h \ + ../common/pb/move_card_to_zone.pb.h \ + ../common/pb/game_commands.pb.h \ + ../common/pb/room_commands.pb.h \ + ../common/pb/session_commands.pb.h \ + ../common/pb/moderator_commands.pb.h \ + ../common/pb/admin_commands.pb.h + SOURCES += src/main.cpp \ src/servatrice.cpp \ @@ -59,4 +68,13 @@ SOURCES += src/main.cpp \ ../common/server_room.cpp \ ../common/server_game.cpp \ ../common/server_player.cpp \ - ../common/server_protocolhandler.cpp + ../common/server_protocolhandler.cpp \ + ../common/pb/commands.pb.cc \ + ../common/pb/color.pb.cc \ + ../common/pb/move_card_to_zone.pb.cc \ + ../common/pb/game_commands.pb.cc \ + ../common/pb/room_commands.pb.cc \ + ../common/pb/session_commands.pb.cc \ + ../common/pb/moderator_commands.pb.cc \ + ../common/pb/admin_commands.pb.cc + diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index ecd1c000..d3f53a5c 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -32,6 +32,10 @@ #include "main.h" #include "server_logger.h" +#include "pb/commands.pb.h" +#include +#include + ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent) : Server_ProtocolHandler(_server, parent), servatrice(_server), socket(_socket), topLevelItem(0), compressionSupport(false) { @@ -72,15 +76,6 @@ ServerSocketInterface::~ServerSocketInterface() delete topLevelItem; } -void ServerSocketInterface::processProtocolItem(ProtocolItem *item) -{ - CommandContainer *cont = qobject_cast(item); - if (!cont) - sendProtocolItem(new ProtocolResponse(cont->getCmdId(), RespInvalidCommand)); - else - processCommandContainer(cont); -} - void ServerSocketInterface::flushXmlBuffer() { QMutexLocker locker(&xmlBufferMutex); @@ -96,7 +91,29 @@ void ServerSocketInterface::readClient() { QByteArray data = socket->readAll(); servatrice->incRxBytes(data.size()); - if (!data.contains("= 4) { + messageLength = (int) (((quint32) inputBuffer[0]) << 24) + (((quint32) inputBuffer[1]) << 16) + (((quint32) inputBuffer[2]) << 8) + ((quint32) inputBuffer[3]); + inputBuffer.remove(0, 4); + messageInProgress = true; + } else + return; + } + if (inputBuffer.size() < messageLength) + return; + + CommandContainer *newCommandContainer = new CommandContainer; + newCommandContainer->ParseFromArray(inputBuffer.data(), messageLength); + inputBuffer.remove(0, messageLength); + messageInProgress = false; + + processCommandContainer(newCommandContainer); + } while (!inputBuffer.isEmpty()); + +/* if (!data.contains("logMessage(QString(data), this); xmlReader->addData(data); @@ -111,6 +128,7 @@ void ServerSocketInterface::readClient() connect(topLevelItem, SIGNAL(protocolItemReceived(ProtocolItem *)), this, SLOT(processProtocolItem(ProtocolItem *))); } } +*/ } void ServerSocketInterface::catchSocketError(QAbstractSocket::SocketError socketError) @@ -144,13 +162,13 @@ int ServerSocketInterface::getUserIdInDB(const QString &name) const return query.value(0).toInt(); } -ResponseCode ServerSocketInterface::cmdAddToList(Command_AddToList *cmd, CommandContainer *cont) +ResponseCode ServerSocketInterface::cmdAddToList(const Command_AddToList &cmd, CommandContainer *cont) { if (authState != PasswordRight) return RespFunctionNotAllowed; - QString list = cmd->getList(); - QString user = cmd->getUserName(); + QString list = QString::fromStdString(cmd.list()); + QString user = QString::fromStdString(cmd.user_name()); if ((list != "buddy") && (list != "ignore")) return RespContextError; @@ -181,17 +199,17 @@ ResponseCode ServerSocketInterface::cmdAddToList(Command_AddToList *cmd, Command else if (list == "ignore") ignoreList.insert(info->getName(), info); - cont->enqueueItem(new Event_AddToList(list, new ServerInfo_User(info))); + //cont->enqueueItem(new Event_AddToList(list, new ServerInfo_User(info))); return RespOk; } -ResponseCode ServerSocketInterface::cmdRemoveFromList(Command_RemoveFromList *cmd, CommandContainer *cont) +ResponseCode ServerSocketInterface::cmdRemoveFromList(const Command_RemoveFromList &cmd, CommandContainer *cont) { if (authState != PasswordRight) return RespFunctionNotAllowed; - QString list = cmd->getList(); - QString user = cmd->getUserName(); + QString list = QString::fromStdString(cmd.list()); + QString user = QString::fromStdString(cmd.user_name()); if ((list != "buddy") && (list != "ignore")) return RespContextError; @@ -222,7 +240,7 @@ ResponseCode ServerSocketInterface::cmdRemoveFromList(Command_RemoveFromList *cm ignoreList.remove(user); } - cont->enqueueItem(new Event_RemoveFromList(list, user)); + //cont->enqueueItem(new Event_RemoveFromList(list, user)); return RespOk; } @@ -289,7 +307,7 @@ bool ServerSocketInterface::deckListHelper(DeckList_Directory *folder) // CHECK AUTHENTICATION! // Also check for every function that data belonging to other users cannot be accessed. -ResponseCode ServerSocketInterface::cmdDeckList(Command_DeckList * /*cmd*/, CommandContainer *cont) +ResponseCode ServerSocketInterface::cmdDeckList(const Command_DeckList & /*cmd*/, CommandContainer *cont) { if (authState != PasswordRight) return RespFunctionNotAllowed; @@ -301,22 +319,22 @@ ResponseCode ServerSocketInterface::cmdDeckList(Command_DeckList * /*cmd*/, Comm if (!deckListHelper(root)) return RespContextError; - ProtocolResponse *resp = new Response_DeckList(cont->getCmdId(), RespOk, root); + ProtocolResponse *resp = new Response_DeckList(cont->cmd_id(), RespOk, root); if (getCompressionSupport()) resp->setCompressed(true); - cont->setResponse(resp); +// cont->setResponse(resp); return RespNothing; } -ResponseCode ServerSocketInterface::cmdDeckNewDir(Command_DeckNewDir *cmd, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdDeckNewDir(const Command_DeckNewDir &cmd, CommandContainer * /*cont*/) { if (authState != PasswordRight) return RespFunctionNotAllowed; servatrice->checkSql(); - int folderId = getDeckPathId(cmd->getPath()); + int folderId = getDeckPathId(QString::fromStdString(cmd.path())); if (folderId == -1) return RespNameNotFound; @@ -325,7 +343,7 @@ ResponseCode ServerSocketInterface::cmdDeckNewDir(Command_DeckNewDir *cmd, Comma query.prepare("insert into " + servatrice->getDbPrefix() + "_decklist_folders (id_parent, user, name) values(:id_parent, :user, :name)"); query.bindValue(":id_parent", folderId); query.bindValue(":user", userInfo->getName()); - query.bindValue(":name", cmd->getDirName()); + query.bindValue(":name", QString::fromStdString(cmd.dir_name())); if (!servatrice->execSqlQuery(query)) return RespContextError; return RespOk; @@ -353,21 +371,21 @@ void ServerSocketInterface::deckDelDirHelper(int basePathId) servatrice->execSqlQuery(query); } -ResponseCode ServerSocketInterface::cmdDeckDelDir(Command_DeckDelDir *cmd, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdDeckDelDir(const Command_DeckDelDir &cmd, CommandContainer * /*cont*/) { if (authState != PasswordRight) return RespFunctionNotAllowed; servatrice->checkSql(); - int basePathId = getDeckPathId(cmd->getPath()); + int basePathId = getDeckPathId(QString::fromStdString(cmd.path())); if (basePathId == -1) return RespNameNotFound; deckDelDirHelper(basePathId); return RespOk; } -ResponseCode ServerSocketInterface::cmdDeckDel(Command_DeckDel *cmd, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdDeckDel(const Command_DeckDel &cmd, CommandContainer * /*cont*/) { if (authState != PasswordRight) return RespFunctionNotAllowed; @@ -378,26 +396,26 @@ ResponseCode ServerSocketInterface::cmdDeckDel(Command_DeckDel *cmd, CommandCont QSqlQuery query; query.prepare("select id from " + servatrice->getDbPrefix() + "_decklist_files where id = :id and user = :user"); - query.bindValue(":id", cmd->getDeckId()); + query.bindValue(":id", cmd.deck_id()); query.bindValue(":user", userInfo->getName()); servatrice->execSqlQuery(query); if (!query.next()) return RespNameNotFound; query.prepare("delete from " + servatrice->getDbPrefix() + "_decklist_files where id = :id"); - query.bindValue(":id", cmd->getDeckId()); + query.bindValue(":id", cmd.deck_id()); servatrice->execSqlQuery(query); return RespOk; } -ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont) +ResponseCode ServerSocketInterface::cmdDeckUpload(const Command_DeckUpload &cmd, CommandContainer *cont) { if (authState != PasswordRight) return RespFunctionNotAllowed; servatrice->checkSql(); - +/* if (!cmd->getDeck()) return RespInvalidData; int folderId = getDeckPathId(cmd->getPath()); @@ -423,8 +441,8 @@ ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd, Comma query.bindValue(":content", deckContents); servatrice->execSqlQuery(query); - cont->setResponse(new Response_DeckUpload(cont->getCmdId(), RespOk, new DeckList_File(deckName, query.lastInsertId().toInt(), QDateTime::currentDateTime()))); - return RespNothing; + cont->setResponse(new Response_DeckUpload(cont->cmd_id(), RespOk, new DeckList_File(deckName, query.lastInsertId().toInt(), QDateTime::currentDateTime()))); +*/ return RespNothing; } DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId) @@ -448,29 +466,29 @@ DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId) return deck; } -ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont) +ResponseCode ServerSocketInterface::cmdDeckDownload(const Command_DeckDownload &cmd, CommandContainer *cont) { if (authState != PasswordRight) return RespFunctionNotAllowed; DeckList *deck; try { - deck = getDeckFromDatabase(cmd->getDeckId()); + deck = getDeckFromDatabase(cmd.deck_id()); } catch(ResponseCode r) { return r; } - cont->setResponse(new Response_DeckDownload(cont->getCmdId(), RespOk, deck)); + //cont->setResponse(new Response_DeckDownload(cont->cmd_id(), RespOk, deck)); return RespNothing; } // MODERATOR FUNCTIONS. // May be called by admins and moderators. Permission is checked by the calling function. -ResponseCode ServerSocketInterface::cmdBanFromServer(Command_BanFromServer *cmd, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_BanFromServer &cmd, CommandContainer * /*cont*/) { - QString userName = cmd->getUserName(); - QString address = cmd->getAddress(); - int minutes = cmd->getMinutes(); + QString userName = QString::fromStdString(cmd.user_name()); + QString address = QString::fromStdString(cmd.address()); + int minutes = cmd.minutes(); servatrice->dbMutex.lock(); QSqlQuery query; @@ -479,7 +497,7 @@ ResponseCode ServerSocketInterface::cmdBanFromServer(Command_BanFromServer *cmd, query.bindValue(":ip_address", address); query.bindValue(":id_admin", getUserIdInDB(userInfo->getName())); query.bindValue(":minutes", minutes); - query.bindValue(":reason", cmd->getReason() + "\n"); + query.bindValue(":reason", QString::fromStdString(cmd.reason()) + "\n"); servatrice->execSqlQuery(query); servatrice->dbMutex.unlock(); @@ -495,14 +513,14 @@ ResponseCode ServerSocketInterface::cmdBanFromServer(Command_BanFromServer *cmd, // ADMIN FUNCTIONS. // Permission is checked by the calling function. -ResponseCode ServerSocketInterface::cmdUpdateServerMessage(Command_UpdateServerMessage * /*cmd*/, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdUpdateServerMessage(const Command_UpdateServerMessage & /*cmd*/, CommandContainer * /*cont*/) { servatrice->updateLoginMessage(); return RespOk; } -ResponseCode ServerSocketInterface::cmdShutdownServer(Command_ShutdownServer *cmd, CommandContainer * /*cont*/) +ResponseCode ServerSocketInterface::cmdShutdownServer(const Command_ShutdownServer &cmd, CommandContainer * /*cont*/) { - servatrice->scheduleShutdown(cmd->getReason(), cmd->getMinutes()); + servatrice->scheduleShutdown(QString::fromStdString(cmd.reason()), cmd.minutes()); return RespOk; } diff --git a/servatrice/src/serversocketinterface.h b/servatrice/src/serversocketinterface.h index fad934ea..3580e868 100644 --- a/servatrice/src/serversocketinterface.h +++ b/servatrice/src/serversocketinterface.h @@ -39,7 +39,7 @@ class ServerSocketInterface : public Server_ProtocolHandler private slots: void readClient(); void catchSocketError(QAbstractSocket::SocketError socketError); - void processProtocolItem(ProtocolItem *item); +// void processProtocolItem(ProtocolItem *item); void flushXmlBuffer(); signals: void xmlBufferChanged(); @@ -52,24 +52,29 @@ private: QString xmlBuffer; TopLevelProtocolItem *topLevelItem; bool compressionSupport; + + QByteArray inputBuffer; + bool messageInProgress; + int messageLength; + int getUserIdInDB(const QString &name) const; - ResponseCode cmdAddToList(Command_AddToList *cmd, CommandContainer *cont); - ResponseCode cmdRemoveFromList(Command_RemoveFromList *cmd, CommandContainer *cont); + ResponseCode cmdAddToList(const Command_AddToList &cmd, CommandContainer *cont); + ResponseCode cmdRemoveFromList(const Command_RemoveFromList &cmd, CommandContainer *cont); int getDeckPathId(int basePathId, QStringList path); int getDeckPathId(const QString &path); bool deckListHelper(DeckList_Directory *folder); - ResponseCode cmdDeckList(Command_DeckList *cmd, CommandContainer *cont); - ResponseCode cmdDeckNewDir(Command_DeckNewDir *cmd, CommandContainer *cont); + ResponseCode cmdDeckList(const Command_DeckList &cmd, CommandContainer *cont); + ResponseCode cmdDeckNewDir(const Command_DeckNewDir &cmd, CommandContainer *cont); void deckDelDirHelper(int basePathId); - ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd, CommandContainer *cont); - ResponseCode cmdDeckDel(Command_DeckDel *cmd, CommandContainer *cont); - ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont); + ResponseCode cmdDeckDelDir(const Command_DeckDelDir &cmd, CommandContainer *cont); + ResponseCode cmdDeckDel(const Command_DeckDel &cmd, CommandContainer *cont); + ResponseCode cmdDeckUpload(const Command_DeckUpload &cmd, CommandContainer *cont); DeckList *getDeckFromDatabase(int deckId); - ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont); - ResponseCode cmdBanFromServer(Command_BanFromServer *cmd, CommandContainer *cont); - ResponseCode cmdShutdownServer(Command_ShutdownServer *cmd, CommandContainer *cont); - ResponseCode cmdUpdateServerMessage(Command_UpdateServerMessage *cmd, CommandContainer *cont); + ResponseCode cmdDeckDownload(const Command_DeckDownload &cmd, CommandContainer *cont); + ResponseCode cmdBanFromServer(const Command_BanFromServer &cmd, CommandContainer *cont); + ResponseCode cmdShutdownServer(const Command_ShutdownServer &cmd, CommandContainer *cont); + ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage &cmd, CommandContainer *cont); protected: bool getCompressionSupport() const { return compressionSupport; } public: