server-side part of client -> server commands almost converted to ProtocolBuffers. not usable yet
This commit is contained in:
parent
ca3a7e69a1
commit
4eb9dfc5bf
26 changed files with 1233 additions and 1436 deletions
|
@ -5,10 +5,13 @@
|
|||
#include <QColor>
|
||||
#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; }
|
||||
|
|
21
common/pb/admin_commands.proto
Normal file
21
common/pb/admin_commands.proto
Normal file
|
@ -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;
|
||||
}
|
||||
|
6
common/pb/color.proto
Normal file
6
common/pb/color.proto
Normal file
|
@ -0,0 +1,6 @@
|
|||
message color {
|
||||
optional uint32 r = 1;
|
||||
optional uint32 g = 2;
|
||||
optional uint32 b = 3;
|
||||
optional uint32 a = 4;
|
||||
}
|
25
common/pb/commands.proto
Normal file
25
common/pb/commands.proto
Normal file
|
@ -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;
|
||||
}
|
237
common/pb/game_commands.proto
Normal file
237
common/pb/game_commands.proto
Normal file
|
@ -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;
|
||||
}
|
||||
|
20
common/pb/moderator_commands.proto
Normal file
20
common/pb/moderator_commands.proto
Normal file
|
@ -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;
|
||||
}
|
||||
|
5
common/pb/move_card_to_zone.proto
Normal file
5
common/pb/move_card_to_zone.proto
Normal file
|
@ -0,0 +1,5 @@
|
|||
message MoveCard_ToZone {
|
||||
optional string card_name = 1;
|
||||
optional string start_zone = 2;
|
||||
optional string target_zone = 3;
|
||||
}
|
46
common/pb/room_commands.proto
Normal file
46
common/pb/room_commands.proto
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
|
107
common/pb/session_commands.proto
Normal file
107
common/pb/session_commands.proto
Normal file
|
@ -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;
|
||||
}
|
||||
|
|
@ -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<GameEvent *>(), 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<GameEvent *>(), 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<GameEvent *>(), 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<GameTypeId *> &_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<QString, ResponseCode> ProtocolResponse::responseHash;
|
||||
|
||||
ProtocolResponse::ProtocolResponse(int _cmdId, ResponseCode _responseCode, const QString &_itemName)
|
||||
|
|
|
@ -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<ProtocolItem *> itemQueue;
|
||||
GameEventContext *gameEventContext;
|
||||
|
@ -124,13 +117,8 @@ private:
|
|||
GameEventContainer *gameEventQueuePrivate;
|
||||
int privatePlayerId;
|
||||
public:
|
||||
CommandContainer(const QList<Command *> &_commandList = QList<Command *>(), int _cmdId = -1);
|
||||
static SerializableItem *newItem() { return new CommandContainer; }
|
||||
int getItemId() const { return ItemId_CommandContainer; }
|
||||
int getCmdId() const { return static_cast<SerializableItem_Int *>(itemMap.value("cmd_id"))->getData(); }
|
||||
int tick() { return ++ticks; }
|
||||
void processResponse(ProtocolResponse *response);
|
||||
QList<Command *> getCommandList() const { return typecastItemList<Command *>(); }
|
||||
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<GameTypeId *> &_gameTypes = QList<GameTypeId *>(), bool _onlyBuddies = false, bool _onlyRegistered = false, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, bool _spectatorsCanTalk = false, bool _spectatorsSeeEverything = false);
|
||||
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); };
|
||||
QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); };
|
||||
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); };
|
||||
bool getOnlyBuddies() const { return static_cast<SerializableItem_Bool *>(itemMap.value("only_buddies"))->getData(); };
|
||||
bool getOnlyRegistered() const { return static_cast<SerializableItem_Bool *>(itemMap.value("only_registered"))->getData(); };
|
||||
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->getData(); };
|
||||
bool getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); };
|
||||
bool getSpectatorsCanTalk() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_can_talk"))->getData(); };
|
||||
bool getSpectatorsSeeEverything() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_see_everything"))->getData(); };
|
||||
QList<GameTypeId *> getGameTypes() const { return typecastItemList<GameTypeId *>(); }
|
||||
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 ---
|
||||
// -----------------
|
||||
|
|
|
@ -3,15 +3,6 @@
|
|||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
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")
|
||||
{
|
||||
|
|
|
@ -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<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); }
|
||||
bool getFaceDown() const { return static_cast<SerializableItem_Bool *>(itemMap.value("facedown"))->getData(); }
|
||||
QString getPT() const { return static_cast<SerializableItem_String *>(itemMap.value("pt"))->getData(); }
|
||||
bool getTapped() const { return static_cast<SerializableItem_Bool *>(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 {
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<SerializableItem_String *>(itemMap.value("username"))->getData(); };
|
||||
QString getPassword() const { return static_cast<SerializableItem_String *>(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<SerializableItem_String *>(itemMap.value("user_name"))->getData(); };
|
||||
QString getText() const { return static_cast<SerializableItem_String *>(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<SerializableItem_String *>(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<SerializableItem_String *>(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<SerializableItem_String *>(itemMap.value("list"))->getData(); };
|
||||
QString getUserName() const { return static_cast<SerializableItem_String *>(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<SerializableItem_String *>(itemMap.value("list"))->getData(); };
|
||||
QString getUserName() const { return static_cast<SerializableItem_String *>(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<SerializableItem_String *>(itemMap.value("path"))->getData(); };
|
||||
QString getDirName() const { return static_cast<SerializableItem_String *>(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<SerializableItem_String *>(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<SerializableItem_Int *>(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<SerializableItem_Int *>(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<SerializableItem_Int *>(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<SerializableItem_String *>(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<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); };
|
||||
QString getPassword() const { return static_cast<SerializableItem_String *>(itemMap.value("password"))->getData(); };
|
||||
bool getSpectator() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectator"))->getData(); };
|
||||
bool getOverrideRestrictions() const { return static_cast<SerializableItem_Bool *>(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<SerializableItem_Int *>(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<SerializableItem_String *>(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<SerializableItem_Int *>(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<SerializableItem_Int *>(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<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
|
||||
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
|
||||
bool getFaceDown() const { return static_cast<SerializableItem_Bool *>(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<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); };
|
||||
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
|
||||
int getTargetPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_player_id"))->getData(); };
|
||||
QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); };
|
||||
int getTargetCardId() const { return static_cast<SerializableItem_Int *>(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<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
|
||||
QString getCardName() const { return static_cast<SerializableItem_String *>(itemMap.value("card_name"))->getData(); };
|
||||
QString getColor() const { return static_cast<SerializableItem_String *>(itemMap.value("color"))->getData(); };
|
||||
QString getPt() const { return static_cast<SerializableItem_String *>(itemMap.value("pt"))->getData(); };
|
||||
QString getAnnotation() const { return static_cast<SerializableItem_String *>(itemMap.value("annotation"))->getData(); };
|
||||
bool getDestroy() const { return static_cast<SerializableItem_Bool *>(itemMap.value("destroy"))->getData(); };
|
||||
int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); };
|
||||
int getY() const { return static_cast<SerializableItem_Int *>(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<SerializableItem_Int *>(itemMap.value("start_player_id"))->getData(); };
|
||||
QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); };
|
||||
int getStartCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("start_card_id"))->getData(); };
|
||||
int getTargetPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_player_id"))->getData(); };
|
||||
QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); };
|
||||
int getTargetCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_card_id"))->getData(); };
|
||||
Color getColor() const { return static_cast<SerializableItem_Color *>(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<SerializableItem_Int *>(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<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
|
||||
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
|
||||
QString getAttrName() const { return static_cast<SerializableItem_String *>(itemMap.value("attr_name"))->getData(); };
|
||||
QString getAttrValue() const { return static_cast<SerializableItem_String *>(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<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
|
||||
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
|
||||
int getCounterId() const { return static_cast<SerializableItem_Int *>(itemMap.value("counter_id"))->getData(); };
|
||||
int getCounterValue() const { return static_cast<SerializableItem_Int *>(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<SerializableItem_String *>(itemMap.value("zone"))->getData(); };
|
||||
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
|
||||
int getCounterId() const { return static_cast<SerializableItem_Int *>(itemMap.value("counter_id"))->getData(); };
|
||||
int getCounterDelta() const { return static_cast<SerializableItem_Int *>(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<SerializableItem_Bool *>(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<SerializableItem_Int *>(itemMap.value("counter_id"))->getData(); };
|
||||
int getDelta() const { return static_cast<SerializableItem_Int *>(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<SerializableItem_String *>(itemMap.value("counter_name"))->getData(); };
|
||||
Color getColor() const { return static_cast<SerializableItem_Color *>(itemMap.value("color"))->getData(); };
|
||||
int getRadius() const { return static_cast<SerializableItem_Int *>(itemMap.value("radius"))->getData(); };
|
||||
int getValue() const { return static_cast<SerializableItem_Int *>(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<SerializableItem_Int *>(itemMap.value("counter_id"))->getData(); };
|
||||
int getValue() const { return static_cast<SerializableItem_Int *>(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<SerializableItem_Int *>(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<SerializableItem_Int *>(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<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); };
|
||||
QString getZoneName() const { return static_cast<SerializableItem_String *>(itemMap.value("zone_name"))->getData(); };
|
||||
int getNumberCards() const { return static_cast<SerializableItem_Int *>(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<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); };
|
||||
QString getZoneName() const { return static_cast<SerializableItem_String *>(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<SerializableItem_String *>(itemMap.value("zone_name"))->getData(); };
|
||||
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
|
||||
int getPlayerId() const { return static_cast<SerializableItem_Int *>(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<SerializableItem_String *>(itemMap.value("reason"))->getData(); };
|
||||
int getMinutes() const { return static_cast<SerializableItem_Int *>(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<SerializableItem_String *>(itemMap.value("user_name"))->getData(); };
|
||||
QString getAddress() const { return static_cast<SerializableItem_String *>(itemMap.value("address"))->getData(); };
|
||||
int getMinutes() const { return static_cast<SerializableItem_Int *>(itemMap.value("minutes"))->getData(); };
|
||||
QString getReason() const { return static_cast<SerializableItem_String *>(itemMap.value("reason"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Command_BanFromServer; }
|
||||
int getItemId() const { return ItemId_Command_BanFromServer; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <QSet>
|
||||
#include <QDebug>
|
||||
#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<int, Server_Card *> &coordMap, Server_Card *card, int x, int y)
|
||||
void Server_CardZone::moveCard(BlaContainer *bla, QMap<int, Server_Card *> &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 *>() << cardToMove, this, x, y, card->getFaceDown(), false);
|
||||
CardToMove *cardToMove = new CardToMove;
|
||||
cardToMove->set_card_id(card->getId());
|
||||
player->moveCard(bla, this, QList<const CardToMove *>() << 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<int, Server_Card *> &coordMap, Server_Card *card, int x, int y);
|
||||
void fixFreeSpaces(BlaContainer *bla);
|
||||
void moveCard(BlaContainer *bla, QMap<int, Server_Card *> &coordMap, Server_Card *card, int x, int y);
|
||||
QList<Server_Card *> cards;
|
||||
void insertCard(Server_Card *card, int x, int y);
|
||||
void shuffle();
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "protocol.h"
|
||||
#include "protocol_items.h"
|
||||
#include "decklist.h"
|
||||
#include "pb/game_commands.pb.h"
|
||||
#include <QDebug>
|
||||
|
||||
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 *>() << 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<const CardToMove *>() << cardToMove, zones.value("deck"), 0, 0, false, true);
|
||||
delete cardToMove;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_startZone, const QList<CardToMove *> &_cards, int targetPlayerId, const QString &_targetZone, int x, int y)
|
||||
ResponseCode Server_Player::moveCard(BlaContainer *bla, const QString &_startZone, const QList<const CardToMove *> &_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<CardToMove *> &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces, bool undoingDraw)
|
||||
ResponseCode Server_Player::moveCard(BlaContainer *bla, Server_CardZone *startzone, const QList<const CardToMove *> &_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<QPair<Server_Card *, int> > cardsToMove;
|
||||
QMap<Server_Card *, CardToMove *> cardProperties;
|
||||
QMap<Server_Card *, const CardToMove *> 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<Server_Card *> 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<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(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<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(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<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(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<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(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<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(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<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(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<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(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<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(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 *>() << cardToMove, zone, -1, card->getY(), card->getFaceDown());
|
||||
CardToMove *cardToMove = new CardToMove;
|
||||
cardToMove->set_card_id(card->getId());
|
||||
moveCard(bla, zone, QList<const CardToMove *>() << 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<CardToMove *> &_cards, int _targetPlayer, const QString &_targetZone, int _x, int _y);
|
||||
ResponseCode moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<CardToMove *> &_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<const CardToMove *> &_cards, int _targetPlayer, const QString &_targetZone, int _x, int _y);
|
||||
ResponseCode moveCard(BlaContainer *bla, Server_CardZone *startzone, const QList<const CardToMove *> &_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);
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -32,6 +32,10 @@
|
|||
#include "main.h"
|
||||
#include "server_logger.h"
|
||||
|
||||
#include "pb/commands.pb.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
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<CommandContainer *>(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("<cmd type=\"ping\""))
|
||||
inputBuffer.append(data);
|
||||
|
||||
do {
|
||||
if (!messageInProgress) {
|
||||
if (inputBuffer.size() >= 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("<cmd type=\"ping\""))
|
||||
logger->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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue