Commit a1b6f31b authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files
parents b3f96f94 fd6c27a2
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -17,6 +17,7 @@ void ProtocolItem::initializeHash() ...@@ -17,6 +17,7 @@ void ProtocolItem::initializeHash()
registerSerializableItem("room", ServerInfo_Room::newItem); registerSerializableItem("room", ServerInfo_Room::newItem);
registerSerializableItem("user", ServerInfo_User::newItem); registerSerializableItem("user", ServerInfo_User::newItem);
registerSerializableItem("game", ServerInfo_Game::newItem); registerSerializableItem("game", ServerInfo_Game::newItem);
registerSerializableItem("game_type", ServerInfo_GameType::newItem);
registerSerializableItem("card_counter", ServerInfo_CardCounter::newItem); registerSerializableItem("card_counter", ServerInfo_CardCounter::newItem);
registerSerializableItem("card", ServerInfo_Card::newItem); registerSerializableItem("card", ServerInfo_Card::newItem);
registerSerializableItem("zone", ServerInfo_Zone::newItem); registerSerializableItem("zone", ServerInfo_Zone::newItem);
...@@ -28,10 +29,12 @@ void ProtocolItem::initializeHash() ...@@ -28,10 +29,12 @@ void ProtocolItem::initializeHash()
registerSerializableItem("file", DeckList_File::newItem); registerSerializableItem("file", DeckList_File::newItem);
registerSerializableItem("directory", DeckList_Directory::newItem); registerSerializableItem("directory", DeckList_Directory::newItem);
registerSerializableItem("card_id", CardId::newItem); registerSerializableItem("card_id", CardId::newItem);
registerSerializableItem("game_type_id", GameTypeId::newItem);
registerSerializableItem("containercmd", CommandContainer::newItem); registerSerializableItem("containercmd", CommandContainer::newItem);
registerSerializableItem("containergame_event", GameEventContainer::newItem); registerSerializableItem("containergame_event", GameEventContainer::newItem);
registerSerializableItem("cmdcreate_game", Command_CreateGame::newItem);
registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem); registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem);
registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem); registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem);
registerSerializableItem("cmdset_sideboard_plan", Command_SetSideboardPlan::newItem); registerSerializableItem("cmdset_sideboard_plan", Command_SetSideboardPlan::newItem);
...@@ -138,26 +141,47 @@ void CommandContainer::setResponse(ProtocolResponse *_resp) ...@@ -138,26 +141,47 @@ void CommandContainer::setResponse(ProtocolResponse *_resp)
resp = _resp; resp = _resp;
} }
void CommandContainer::enqueueGameEventPublic(GameEvent *event, int gameId) void CommandContainer::enqueueGameEventPublic(GameEvent *event, int gameId, GameEventContext *context)
{ {
if (!gameEventQueuePublic) if (!gameEventQueuePublic)
gameEventQueuePublic = new GameEventContainer(QList<GameEvent *>(), gameId); gameEventQueuePublic = new GameEventContainer(QList<GameEvent *>(), gameId);
gameEventQueuePublic->addGameEvent(event); gameEventQueuePublic->addGameEvent(event);
if (context)
gameEventQueuePublic->setContext(context);
} }
void CommandContainer::enqueueGameEventOmniscient(GameEvent *event, int gameId) void CommandContainer::enqueueGameEventOmniscient(GameEvent *event, int gameId, GameEventContext *context)
{ {
if (!gameEventQueueOmniscient) if (!gameEventQueueOmniscient)
gameEventQueueOmniscient = new GameEventContainer(QList<GameEvent *>(), gameId); gameEventQueueOmniscient = new GameEventContainer(QList<GameEvent *>(), gameId);
gameEventQueueOmniscient->addGameEvent(event); gameEventQueueOmniscient->addGameEvent(event);
if (context)
gameEventQueueOmniscient->setContext(context);
} }
void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId) void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId, GameEventContext *context)
{ {
if (!gameEventQueuePrivate) if (!gameEventQueuePrivate)
gameEventQueuePrivate = new GameEventContainer(QList<GameEvent *>(), gameId); gameEventQueuePrivate = new GameEventContainer(QList<GameEvent *>(), gameId);
gameEventQueuePrivate->addGameEvent(event); gameEventQueuePrivate->addGameEvent(event);
privatePlayerId = playerId; privatePlayerId = playerId;
if (context)
gameEventQueuePrivate->setContext(context);
}
Command_CreateGame::Command_CreateGame(int _roomId, const QString &_description, const QString &_password, int _maxPlayers, const QList<GameTypeId *> &_gameTypes, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything)
: RoomCommand("create_game", _roomId)
{
insertItem(new SerializableItem_String("description", _description));
insertItem(new SerializableItem_String("password", _password));
insertItem(new SerializableItem_Int("max_players", _maxPlayers));
insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword));
insertItem(new SerializableItem_Bool("spectators_can_talk", _spectatorsCanTalk));
insertItem(new SerializableItem_Bool("spectators_see_everything", _spectatorsSeeEverything));
for (int i = 0; i < _gameTypes.size(); ++i)
itemList.append(_gameTypes[i]);
} }
Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path) Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path)
......
...@@ -17,11 +17,13 @@ class ProtocolResponse; ...@@ -17,11 +17,13 @@ class ProtocolResponse;
class DeckList; class DeckList;
class GameEvent; class GameEvent;
class GameEventContainer; class GameEventContainer;
class GameEventContext;
class MoveCardToZone; class MoveCardToZone;
enum ItemId { enum ItemId {
ItemId_CommandContainer = ItemId_Other + 50, ItemId_CommandContainer = ItemId_Other + 50,
ItemId_GameEventContainer = ItemId_Other + 51, ItemId_GameEventContainer = ItemId_Other + 51,
ItemId_Command_CreateGame = ItemId_Other + 99,
ItemId_Command_DeckUpload = ItemId_Other + 100, ItemId_Command_DeckUpload = ItemId_Other + 100,
ItemId_Command_DeckSelect = ItemId_Other + 101, ItemId_Command_DeckSelect = ItemId_Other + 101,
ItemId_Command_SetSideboardPlan = ItemId_Other + 102, ItemId_Command_SetSideboardPlan = ItemId_Other + 102,
...@@ -55,7 +57,7 @@ private: ...@@ -55,7 +57,7 @@ private:
static void initializeHashAuto(); static void initializeHashAuto();
bool receiverMayDelete; bool receiverMayDelete;
public: public:
static const int protocolVersion = 11; static const int protocolVersion = 12;
static void initializeHash(); static void initializeHash();
virtual int getItemId() const = 0; virtual int getItemId() const = 0;
bool getReceiverMayDelete() const { return receiverMayDelete; } bool getReceiverMayDelete() const { return receiverMayDelete; }
...@@ -132,11 +134,11 @@ public: ...@@ -132,11 +134,11 @@ public:
const QList<ProtocolItem *> &getItemQueue() const { return itemQueue; } const QList<ProtocolItem *> &getItemQueue() const { return itemQueue; }
void enqueueItem(ProtocolItem *item) { itemQueue.append(item); } void enqueueItem(ProtocolItem *item) { itemQueue.append(item); }
GameEventContainer *getGameEventQueuePublic() const { return gameEventQueuePublic; } GameEventContainer *getGameEventQueuePublic() const { return gameEventQueuePublic; }
void enqueueGameEventPublic(GameEvent *event, int gameId); void enqueueGameEventPublic(GameEvent *event, int gameId, GameEventContext *context = 0);
GameEventContainer *getGameEventQueueOmniscient() const { return gameEventQueueOmniscient; } GameEventContainer *getGameEventQueueOmniscient() const { return gameEventQueueOmniscient; }
void enqueueGameEventOmniscient(GameEvent *event, int gameId); void enqueueGameEventOmniscient(GameEvent *event, int gameId, GameEventContext *context = 0);
GameEventContainer *getGameEventQueuePrivate() const { return gameEventQueuePrivate; } GameEventContainer *getGameEventQueuePrivate() const { return gameEventQueuePrivate; }
void enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId = -1); void enqueueGameEventPrivate(GameEvent *event, int gameId, int playerId = -1, GameEventContext *context = 0);
int getPrivatePlayerId() const { return privatePlayerId; } int getPrivatePlayerId() const { return privatePlayerId; }
}; };
...@@ -172,6 +174,22 @@ public: ...@@ -172,6 +174,22 @@ 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 _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 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 { class Command_DeckUpload : public Command {
Q_OBJECT Q_OBJECT
public: public:
......
...@@ -23,7 +23,7 @@ ServerInfo_User::ServerInfo_User(const ServerInfo_User *other, bool complete) ...@@ -23,7 +23,7 @@ ServerInfo_User::ServerInfo_User(const ServerInfo_User *other, bool complete)
insertItem(new SerializableItem_ByteArray("avatar_bmp", complete ? other->getAvatarBmp() : QByteArray())); insertItem(new SerializableItem_ByteArray("avatar_bmp", complete ? other->getAvatarBmp() : QByteArray()));
} }
ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, ServerInfo_User *_creatorInfo, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount) ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QList<GameTypeId *> &_gameTypes, ServerInfo_User *_creatorInfo, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount)
: SerializableItem_Map("game") : SerializableItem_Map("game")
{ {
insertItem(new SerializableItem_Int("game_id", _gameId)); insertItem(new SerializableItem_Int("game_id", _gameId));
...@@ -37,9 +37,19 @@ ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool ...@@ -37,9 +37,19 @@ ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool
insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed)); insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword)); insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword));
insertItem(new SerializableItem_Int("spectator_count", _spectatorCount)); insertItem(new SerializableItem_Int("spectator_count", _spectatorCount));
for (int i = 0; i < _gameTypes.size(); ++i)
itemList.append(_gameTypes[i]);
} }
ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QString &_description, int _gameCount, int _playerCount, bool _autoJoin, const QList<ServerInfo_Game *> &_gameList, const QList<ServerInfo_User *> &_userList) ServerInfo_GameType::ServerInfo_GameType(int _gameTypeId, const QString &_description)
: SerializableItem_Map("game_type")
{
insertItem(new SerializableItem_Int("game_type_id", _gameTypeId));
insertItem(new SerializableItem_String("description", _description));
}
ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QString &_description, int _gameCount, int _playerCount, bool _autoJoin, const QList<ServerInfo_Game *> &_gameList, const QList<ServerInfo_User *> &_userList, const QList<ServerInfo_GameType *> &_gameTypeList)
: SerializableItem_Map("room") : SerializableItem_Map("room")
{ {
insertItem(new SerializableItem_Int("room_id", _roomId)); insertItem(new SerializableItem_Int("room_id", _roomId));
...@@ -55,6 +65,9 @@ ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QStrin ...@@ -55,6 +65,9 @@ ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QStrin
userList = _userList; userList = _userList;
for (int i = 0; i < _userList.size(); ++i) for (int i = 0; i < _userList.size(); ++i)
itemList.append(_userList[i]); itemList.append(_userList[i]);
gameTypeList = _gameTypeList;
for (int i = 0; i < _gameTypeList.size(); ++i)
itemList.append(_gameTypeList[i]);
} }
void ServerInfo_Room::extractData() void ServerInfo_Room::extractData()
...@@ -70,6 +83,11 @@ void ServerInfo_Room::extractData() ...@@ -70,6 +83,11 @@ void ServerInfo_Room::extractData()
gameList.append(game); gameList.append(game);
continue; continue;
} }
ServerInfo_GameType *gameType = dynamic_cast<ServerInfo_GameType *>(itemList[i]);
if (gameType) {
gameTypeList.append(gameType);
continue;
}
} }
} }
......
...@@ -25,6 +25,11 @@ public: ...@@ -25,6 +25,11 @@ public:
CardId(int _cardId = -1) : SerializableItem_Int("card_id", _cardId) { } CardId(int _cardId = -1) : SerializableItem_Int("card_id", _cardId) { }
static SerializableItem *newItem() { return new CardId; } static SerializableItem *newItem() { return new CardId; }
}; };
class GameTypeId : public SerializableItem_Int {
public:
GameTypeId(int _gameTypeId = -1) : SerializableItem_Int("game_type_id", _gameTypeId) { }
static SerializableItem *newItem() { return new GameTypeId; }
};
class ServerInfo_User : public SerializableItem_Map { class ServerInfo_User : public SerializableItem_Map {
public: public:
...@@ -48,27 +53,37 @@ public: ...@@ -48,27 +53,37 @@ public:
class ServerInfo_Game : public SerializableItem_Map { class ServerInfo_Game : public SerializableItem_Map {
public: public:
ServerInfo_Game(int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, ServerInfo_User *creatorInfo = 0, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1); ServerInfo_Game(int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, const QList<GameTypeId *> &_gameTypes = QList<GameTypeId *>(), ServerInfo_User *creatorInfo = 0, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1);
static SerializableItem *newItem() { return new ServerInfo_Game; } static SerializableItem *newItem() { return new ServerInfo_Game; }
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); } int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); } QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
bool getHasPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("has_password"))->getData(); } bool getHasPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("has_password"))->getData(); }
int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); } int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); }
int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); } int getMaxPlayers() const { return static_cast<SerializableItem_Int *>(itemMap.value("max_players"))->getData(); }
QList<GameTypeId *> getGameTypes() const { return typecastItemList<GameTypeId *>(); }
ServerInfo_User *getCreatorInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); } ServerInfo_User *getCreatorInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
bool getSpectatorsAllowed() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_allowed"))->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 getSpectatorsNeedPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectators_need_password"))->getData(); }
int getSpectatorCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("spectator_count"))->getData(); } int getSpectatorCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("spectator_count"))->getData(); }
}; };
class ServerInfo_GameType : public SerializableItem_Map {
public:
ServerInfo_GameType(int _gameTypeId = -1, const QString &_description = QString());
static SerializableItem *newItem() { return new ServerInfo_GameType; }
int getGameTypeId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_type_id"))->getData(); }
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
};
class ServerInfo_Room : public SerializableItem_Map { class ServerInfo_Room : public SerializableItem_Map {
private: private:
QList<ServerInfo_Game *> gameList; QList<ServerInfo_Game *> gameList;
QList<ServerInfo_User *> userList; QList<ServerInfo_User *> userList;
QList<ServerInfo_GameType *> gameTypeList;
protected: protected:
void extractData(); void extractData();
public: public:
ServerInfo_Room(int _id = -1, const QString &_name = QString(), const QString &_description = QString(), int _gameCount = -1, int _playerCount = -1, bool _autoJoin = false, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>(), const QList<ServerInfo_User *> &_userList = QList<ServerInfo_User *>()); ServerInfo_Room(int _id = -1, const QString &_name = QString(), const QString &_description = QString(), int _gameCount = -1, int _playerCount = -1, bool _autoJoin = false, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>(), const QList<ServerInfo_User *> &_userList = QList<ServerInfo_User *>(), const QList<ServerInfo_GameType *> &_gameTypeList = QList<ServerInfo_GameType *>());
static SerializableItem *newItem() { return new ServerInfo_Room; } static SerializableItem *newItem() { return new ServerInfo_Room; }
int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); } int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); }
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); } QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
...@@ -78,6 +93,7 @@ public: ...@@ -78,6 +93,7 @@ public:
bool getAutoJoin() const { return static_cast<SerializableItem_Bool *>(itemMap.value("auto_join"))->getData(); } bool getAutoJoin() const { return static_cast<SerializableItem_Bool *>(itemMap.value("auto_join"))->getData(); }
const QList<ServerInfo_Game *> &getGameList() const { return gameList; } const QList<ServerInfo_Game *> &getGameList() const { return gameList; }
const QList<ServerInfo_User *> &getUserList() const { return userList; } const QList<ServerInfo_User *> &getUserList() const { return userList; }
const QList<ServerInfo_GameType *> &getGameTypeList() const { return gameTypeList; }
}; };
class ServerInfo_CardCounter : public SerializableItem_Map { class ServerInfo_CardCounter : public SerializableItem_Map {
......
...@@ -13,14 +13,14 @@ ItemId_Command_ListRooms = 1011, ...@@ -13,14 +13,14 @@ ItemId_Command_ListRooms = 1011,
ItemId_Command_JoinRoom = 1012, ItemId_Command_JoinRoom = 1012,
ItemId_Command_LeaveRoom = 1013, ItemId_Command_LeaveRoom = 1013,
ItemId_Command_RoomSay = 1014, ItemId_Command_RoomSay = 1014,
ItemId_Command_CreateGame = 1015, ItemId_Command_JoinGame = 1015,
ItemId_Command_JoinGame = 1016, ItemId_Command_LeaveGame = 1016,
ItemId_Command_LeaveGame = 1017, ItemId_Command_Say = 1017,
ItemId_Command_Say = 1018, ItemId_Command_Shuffle = 1018,
ItemId_Command_Shuffle = 1019, ItemId_Command_Mulligan = 1019,
ItemId_Command_Mulligan = 1020, ItemId_Command_RollDie = 1020,
ItemId_Command_RollDie = 1021, ItemId_Command_DrawCards = 1021,
ItemId_Command_DrawCards = 1022, ItemId_Command_UndoDraw = 1022,
ItemId_Command_FlipCard = 1023, ItemId_Command_FlipCard = 1023,
ItemId_Command_AttachCard = 1024, ItemId_Command_AttachCard = 1024,
ItemId_Command_CreateToken = 1025, ItemId_Command_CreateToken = 1025,
...@@ -68,6 +68,7 @@ ItemId_Event_RoomSay = 1066, ...@@ -68,6 +68,7 @@ ItemId_Event_RoomSay = 1066,
ItemId_Context_ReadyStart = 1067, ItemId_Context_ReadyStart = 1067,
ItemId_Context_Concede = 1068, ItemId_Context_Concede = 1068,
ItemId_Context_DeckSelect = 1069, ItemId_Context_DeckSelect = 1069,
ItemId_Command_UpdateServerMessage = 1070, ItemId_Context_UndoDraw = 1070,
ItemId_Other = 1071 ItemId_Command_UpdateServerMessage = 1071,
ItemId_Other = 1072
}; };
...@@ -69,17 +69,6 @@ Command_RoomSay::Command_RoomSay(int _roomId, const QString &_message) ...@@ -69,17 +69,6 @@ Command_RoomSay::Command_RoomSay(int _roomId, const QString &_message)
{ {
insertItem(new SerializableItem_String("message", _message)); insertItem(new SerializableItem_String("message", _message));
} }
Command_CreateGame::Command_CreateGame(int _roomId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything)
: RoomCommand("create_game", _roomId)
{
insertItem(new SerializableItem_String("description", _description));
insertItem(new SerializableItem_String("password", _password));
insertItem(new SerializableItem_Int("max_players", _maxPlayers));
insertItem(new SerializableItem_Bool("spectators_allowed", _spectatorsAllowed));
insertItem(new SerializableItem_Bool("spectators_need_password", _spectatorsNeedPassword));
insertItem(new SerializableItem_Bool("spectators_can_talk", _spectatorsCanTalk));
insertItem(new SerializableItem_Bool("spectators_see_everything", _spectatorsSeeEverything));
}
Command_JoinGame::Command_JoinGame(int _roomId, int _gameId, const QString &_password, bool _spectator) Command_JoinGame::Command_JoinGame(int _roomId, int _gameId, const QString &_password, bool _spectator)
: RoomCommand("join_game", _roomId) : RoomCommand("join_game", _roomId)
{ {
...@@ -114,6 +103,10 @@ Command_DrawCards::Command_DrawCards(int _gameId, int _number) ...@@ -114,6 +103,10 @@ Command_DrawCards::Command_DrawCards(int _gameId, int _number)
{ {
insertItem(new SerializableItem_Int("number", _number)); 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) Command_FlipCard::Command_FlipCard(int _gameId, const QString &_zone, int _cardId, bool _faceDown)
: GameCommand("flip_card", _gameId) : GameCommand("flip_card", _gameId)
{ {
...@@ -425,6 +418,10 @@ Context_DeckSelect::Context_DeckSelect(int _deckId) ...@@ -425,6 +418,10 @@ Context_DeckSelect::Context_DeckSelect(int _deckId)
{ {
insertItem(new SerializableItem_Int("deck_id", _deckId)); insertItem(new SerializableItem_Int("deck_id", _deckId));
} }
Context_UndoDraw::Context_UndoDraw()
: GameEventContext("undo_draw")
{
}
Command_UpdateServerMessage::Command_UpdateServerMessage() Command_UpdateServerMessage::Command_UpdateServerMessage()
: AdminCommand("update_server_message") : AdminCommand("update_server_message")
{ {
...@@ -445,7 +442,6 @@ void ProtocolItem::initializeHashAuto() ...@@ -445,7 +442,6 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("cmdjoin_room", Command_JoinRoom::newItem); itemNameHash.insert("cmdjoin_room", Command_JoinRoom::newItem);
itemNameHash.insert("cmdleave_room", Command_LeaveRoom::newItem); itemNameHash.insert("cmdleave_room", Command_LeaveRoom::newItem);
itemNameHash.insert("cmdroom_say", Command_RoomSay::newItem); itemNameHash.insert("cmdroom_say", Command_RoomSay::newItem);
itemNameHash.insert("cmdcreate_game", Command_CreateGame::newItem);
itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem); itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem);
itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem); itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem);
itemNameHash.insert("cmdsay", Command_Say::newItem); itemNameHash.insert("cmdsay", Command_Say::newItem);
...@@ -453,6 +449,7 @@ void ProtocolItem::initializeHashAuto() ...@@ -453,6 +449,7 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("cmdmulligan", Command_Mulligan::newItem); itemNameHash.insert("cmdmulligan", Command_Mulligan::newItem);
itemNameHash.insert("cmdroll_die", Command_RollDie::newItem); itemNameHash.insert("cmdroll_die", Command_RollDie::newItem);
itemNameHash.insert("cmddraw_cards", Command_DrawCards::newItem); itemNameHash.insert("cmddraw_cards", Command_DrawCards::newItem);
itemNameHash.insert("cmdundo_draw", Command_UndoDraw::newItem);
itemNameHash.insert("cmdflip_card", Command_FlipCard::newItem); itemNameHash.insert("cmdflip_card", Command_FlipCard::newItem);
itemNameHash.insert("cmdattach_card", Command_AttachCard::newItem); itemNameHash.insert("cmdattach_card", Command_AttachCard::newItem);
itemNameHash.insert("cmdcreate_token", Command_CreateToken::newItem); itemNameHash.insert("cmdcreate_token", Command_CreateToken::newItem);
...@@ -500,5 +497,6 @@ void ProtocolItem::initializeHashAuto() ...@@ -500,5 +497,6 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("game_event_contextready_start", Context_ReadyStart::newItem); itemNameHash.insert("game_event_contextready_start", Context_ReadyStart::newItem);
itemNameHash.insert("game_event_contextconcede", Context_Concede::newItem); itemNameHash.insert("game_event_contextconcede", Context_Concede::newItem);
itemNameHash.insert("game_event_contextdeck_select", Context_DeckSelect::newItem); itemNameHash.insert("game_event_contextdeck_select", Context_DeckSelect::newItem);
itemNameHash.insert("game_event_contextundo_draw", Context_UndoDraw::newItem);
itemNameHash.insert("cmdupdate_server_message", Command_UpdateServerMessage::newItem); itemNameHash.insert("cmdupdate_server_message", Command_UpdateServerMessage::newItem);
} }
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
0:join_room:i,room_id 0:join_room:i,room_id
1:leave_room 1:leave_room
1:room_say:s,message 1:room_say:s,message
1:create_game:s,description:s,password:i,max_players:b,spectators_allowed:b,spectators_need_password:b,spectators_can_talk:b,spectators_see_everything
1:join_game:i,game_id:s,password:b,spectator 1:join_game:i,game_id:s,password:b,spectator
2:leave_game 2:leave_game
2:say:s,message 2:say:s,message
...@@ -20,6 +19,7 @@ ...@@ -20,6 +19,7 @@
2:mulligan 2:mulligan
2:roll_die:i,sides 2:roll_die:i,sides
2:draw_cards:i,number 2:draw_cards:i,number
2:undo_draw
2:flip_card:s,zone:i,card_id:b,face_down 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: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_token:s,zone:s,card_name:s,color:s,pt:s,annotation:b,destroy:i,x:i,y
...@@ -67,4 +67,5 @@ ...@@ -67,4 +67,5 @@
6:ready_start 6:ready_start
6:concede 6:concede
6:deck_select:i,deck_id 6:deck_select:i,deck_id
6:undo_draw
7:update_server_message 7:update_server_message
...@@ -113,20 +113,6 @@ public: ...@@ -113,20 +113,6 @@ public:
static SerializableItem *newItem() { return new Command_RoomSay; } static SerializableItem *newItem() { return new Command_RoomSay; }
int getItemId() const { return ItemId_Command_RoomSay; } int getItemId() const { return ItemId_Command_RoomSay; }
}; };
class Command_CreateGame : public RoomCommand {
Q_OBJECT
public:
Command_CreateGame(int _roomId = -1, const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, 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 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(); };
static SerializableItem *newItem() { return new Command_CreateGame; }
int getItemId() const { return ItemId_Command_CreateGame; }
};
class Command_JoinGame : public RoomCommand { class Command_JoinGame : public RoomCommand {
Q_OBJECT Q_OBJECT
public: public:
...@@ -182,6 +168,13 @@ public: ...@@ -182,6 +168,13 @@ public:
static SerializableItem *newItem() { return new Command_DrawCards; } static SerializableItem *newItem() { return new Command_DrawCards; }
int getItemId() const { return ItemId_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 { class Command_FlipCard : public GameCommand {
Q_OBJECT Q_OBJECT
public: public:
...@@ -634,6 +627,13 @@ public: ...@@ -634,6 +627,13 @@ public:
static SerializableItem *newItem() { return new Context_DeckSelect; } static SerializableItem *newItem() { return new Context_DeckSelect; }
int getItemId() const { return ItemId_Context_DeckSelect; } int getItemId() const { return ItemId_Context_DeckSelect; }
}; };
class Context_UndoDraw : public GameEventContext {
Q_OBJECT
public:
Context_UndoDraw();
static SerializableItem *newItem() { return new Context_UndoDraw; }
int getItemId() const { return ItemId_Context_UndoDraw; }
};
class Command_UpdateServerMessage : public AdminCommand { class Command_UpdateServerMessage : public AdminCommand {
Q_OBJECT Q_OBJECT
public: public:
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
#include <QTimer> #include <QTimer>
#include <QDebug> #include <QDebug>
Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent) Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent)
: QObject(parent), creatorInfo(new ServerInfo_User(_creator->getUserInfo())), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), secondsElapsed(0) : QObject(parent), creatorInfo(new ServerInfo_User(_creator->getUserInfo())), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), gameTypes(_gameTypes), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), secondsElapsed(0)
{ {
addPlayer(_creator, false, false); addPlayer(_creator, false, false);
...@@ -399,18 +399,25 @@ ServerInfo_Game *Server_Game::getInfo() const ...@@ -399,18 +399,25 @@ ServerInfo_Game *Server_Game::getInfo() const
{ {
if (players.isEmpty()) if (players.isEmpty())
// Game is closing // Game is closing
return new ServerInfo_Game(getGameId(), QString(), false, 0, getMaxPlayers(), 0, false, 0); return new ServerInfo_Game(getGameId(), QString(), false, 0, getMaxPlayers(), QList<GameTypeId *>(), 0, false, 0);
else else {
// Game is open // Game is open
QList<GameTypeId *> gameTypeList;
for (int i = 0; i < gameTypes.size(); ++i)
gameTypeList.append(new GameTypeId(gameTypes[i]));
return new ServerInfo_Game( return new ServerInfo_Game(
getGameId(), getGameId(),
getDescription(), getDescription(),
!getPassword().isEmpty(), !getPassword().isEmpty(),
getPlayerCount(), getPlayerCount(),
getMaxPlayers(), getMaxPlayers(),
gameTypeList,
new ServerInfo_User(getCreatorInfo(), false), new ServerInfo_User(getCreatorInfo(), false),
getSpectatorsAllowed(), getSpectatorsAllowed(),
getSpectatorsNeedPassword(), getSpectatorsNeedPassword(),
getSpectatorCount() getSpectatorCount()
); );
}
} }
\ No newline at end of file
...@@ -40,6 +40,7 @@ private: ...@@ -40,6 +40,7 @@ private:
QString description; QString description;
QString password; QString password;
int maxPlayers; int maxPlayers;
QList<int> gameTypes;
int activePlayer, activePhase; int activePlayer, activePhase;
bool spectatorsAllowed; bool spectatorsAllowed;
bool spectatorsNeedPassword; bool spectatorsNeedPassword;
...@@ -53,7 +54,7 @@ signals: ...@@ -53,7 +54,7 @@ signals:
private slots: private slots:
void pingClockTimeout(); void pingClockTimeout();
public: public:
Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent); Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
~Server_Game(); ~Server_Game();
ServerInfo_Game *getInfo() const; ServerInfo_Game *getInfo() const;
ServerInfo_User *getCreatorInfo() const { return creatorInfo; } ServerInfo_User *getCreatorInfo() const { return creatorInfo; }
......
...@@ -150,6 +150,8 @@ void Server_Player::clearZones() ...@@ -150,6 +150,8 @@ void Server_Player::clearZones()
while (arrowIterator.hasNext()) while (arrowIterator.hasNext())
delete arrowIterator.next().value(); delete arrowIterator.next().value();
arrows.clear(); arrows.clear();
lastDrawList.clear();
} }
ServerInfo_PlayerProperties *Server_Player::getProperties() ServerInfo_PlayerProperties *Server_Player::getProperties()
...@@ -199,6 +201,37 @@ bool Server_Player::deleteCounter(int counterId) ...@@ -199,6 +201,37 @@ bool Server_Player::deleteCounter(int counterId)
return true; return true;
} }
ResponseCode Server_Player::drawCards(CommandContainer *cont, int number)
{
Server_CardZone *deckZone = zones.value("deck");
Server_CardZone *handZone = zones.value("hand");
if (deckZone->cards.size() < number)
number = deckZone->cards.size();
QList<ServerInfo_Card *> cardListPrivate;
QList<ServerInfo_Card *> cardListOmniscient;
for (int i = 0; i < number; ++i) {
Server_Card *card = deckZone->cards.takeFirst();
handZone->cards.append(card);
lastDrawList.append(card->getId());
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());
return RespOk;
}
ResponseCode Server_Player::undoDraw(CommandContainer *cont)
{
if (lastDrawList.isEmpty())
return RespContextError;
return moveCard(cont, zones.value("hand"), QList<int>() << lastDrawList.takeLast(), zones.value("deck"), 0, 0, false, false, false, true);
}
ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_startZone, const QList<int> &_cardIds, int targetPlayerId, const QString &_targetZone, int x, int y, bool faceDown, bool tapped) ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_startZone, const QList<int> &_cardIds, int targetPlayerId, const QString &_targetZone, int x, int y, bool faceDown, bool tapped)
{ {
Server_CardZone *startzone = getZones().value(_startZone); Server_CardZone *startzone = getZones().value(_startZone);
...@@ -233,7 +266,7 @@ public: ...@@ -233,7 +266,7 @@ public:
} }
}; };
ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<int> &_cardIds, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped, bool fixFreeSpaces) ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<int> &_cardIds, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped, bool fixFreeSpaces, bool undoingDraw)
{ {
// Disallow controller change to other zones than the table. // Disallow controller change to other zones than the table.
if (((targetzone->getType() != PublicZone) || !targetzone->hasCoords()) && (startzone->getPlayer() != targetzone->getPlayer())) if (((targetzone->getType() != PublicZone) || !targetzone->hasCoords()) && (startzone->getPlayer() != targetzone->getPlayer()))
...@@ -262,6 +295,13 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st ...@@ -262,6 +295,13 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
Server_Card *card = cardsToMove[cardIndex].first; Server_Card *card = cardsToMove[cardIndex].first;
int originalPosition = cardsToMove[cardIndex].second; int originalPosition = cardsToMove[cardIndex].second;
int position = startzone->removeCard(card); int position = startzone->removeCard(card);
if (startzone->getName() == "hand") {
if (undoingDraw)
lastDrawList.removeAt(lastDrawList.indexOf(card->getId()));
else if (lastDrawList.contains(card->getId()))
lastDrawList.clear();
}
if ((startzone == targetzone) && !startzone->hasCoords()) { if ((startzone == targetzone) && !startzone->hasCoords()) {
if (!secondHalf && (originalPosition < x)) { if (!secondHalf && (originalPosition < x)) {
xIndex = -1; xIndex = -1;
...@@ -346,8 +386,8 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st ...@@ -346,8 +386,8 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
int privatePosition = -1; int privatePosition = -1;
if (startzone->getType() == HiddenZone) if (startzone->getType() == HiddenZone)
privatePosition = position; privatePosition = position;
cont->enqueueGameEventPrivate(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, faceDown), game->getGameId()); cont->enqueueGameEventPrivate(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, faceDown), game->getGameId(), -1, undoingDraw ? new Context_UndoDraw : 0);
cont->enqueueGameEventOmniscient(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, faceDown), game->getGameId()); cont->enqueueGameEventOmniscient(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, faceDown), game->getGameId(), undoingDraw ? new Context_UndoDraw : 0);
// Other players do not get to see the start and/or target position of the card if the respective // 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, // part of the zone is being looked at. The information is not needed anyway because in hidden zones,
...@@ -361,9 +401,9 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st ...@@ -361,9 +401,9 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
newX = -1; newX = -1;
if ((startzone->getType() == PublicZone) || (targetzone->getType() == PublicZone)) 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(), faceDown), game->getGameId()); cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, card->getId(), faceDown), game->getGameId(), undoingDraw ? new Context_UndoDraw : 0);
else else
cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, -1, false), game->getGameId()); cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, -1, false), game->getGameId(), undoingDraw ? new Context_UndoDraw : 0);
if (tapped) if (tapped)
setCardAttrHelper(cont, targetzone->getName(), card->getId(), "tapped", "1"); setCardAttrHelper(cont, targetzone->getName(), card->getId(), "tapped", "1");
......
...@@ -30,6 +30,7 @@ private: ...@@ -30,6 +30,7 @@ private:
QMap<QString, Server_CardZone *> zones; QMap<QString, Server_CardZone *> zones;
QMap<int, Server_Counter *> counters; QMap<int, Server_Counter *> counters;
QMap<int, Server_Arrow *> arrows; QMap<int, Server_Arrow *> arrows;
QList<int> lastDrawList;
int playerId; int playerId;
bool spectator; bool spectator;
int initialCards; int initialCards;
...@@ -75,8 +76,10 @@ public: ...@@ -75,8 +76,10 @@ public:
void clearZones(); void clearZones();
void setupZones(); void setupZones();
ResponseCode drawCards(CommandContainer *cont, int number);
ResponseCode undoDraw(CommandContainer *cont);
ResponseCode moveCard(CommandContainer *cont, const QString &_startZone, const QList<int> &_cardId, int _targetPlayer, const QString &_targetZone, int _x, int _y, bool _faceDown, bool _tapped); ResponseCode moveCard(CommandContainer *cont, const QString &_startZone, const QList<int> &_cardId, int _targetPlayer, const QString &_targetZone, int _x, int _y, bool _faceDown, bool _tapped);
ResponseCode moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<int> &_cardId, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped, bool fixFreeSpaces = true); ResponseCode moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<int> &_cardId, Server_CardZone *targetzone, int x, int y, bool faceDown, bool tapped, bool fixFreeSpaces = true, bool undoingDraw = false);
void unattachCard(CommandContainer *cont, Server_Card *card); void unattachCard(CommandContainer *cont, Server_Card *card);
ResponseCode setCardAttrHelper(CommandContainer *cont, const QString &zone, int cardId, const QString &attrName, const QString &attrValue); ResponseCode setCardAttrHelper(CommandContainer *cont, const QString &zone, int cardId, const QString &attrName, const QString &attrValue);
......
...@@ -97,6 +97,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm ...@@ -97,6 +97,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
case ItemId_Command_Mulligan: return cmdMulligan(static_cast<Command_Mulligan *>(command), cont, game, player); case ItemId_Command_Mulligan: return cmdMulligan(static_cast<Command_Mulligan *>(command), cont, game, player);
case ItemId_Command_RollDie: return cmdRollDie(static_cast<Command_RollDie *>(command), cont, game, player); case ItemId_Command_RollDie: return cmdRollDie(static_cast<Command_RollDie *>(command), cont, game, player);
case ItemId_Command_DrawCards: return cmdDrawCards(static_cast<Command_DrawCards *>(command), cont, game, player); case ItemId_Command_DrawCards: return cmdDrawCards(static_cast<Command_DrawCards *>(command), cont, game, player);
case ItemId_Command_UndoDraw: return cmdUndoDraw(static_cast<Command_UndoDraw *>(command), cont, game, player);
case ItemId_Command_MoveCard: return cmdMoveCard(static_cast<Command_MoveCard *>(command), cont, game, player); case ItemId_Command_MoveCard: return cmdMoveCard(static_cast<Command_MoveCard *>(command), cont, game, player);
case ItemId_Command_FlipCard: return cmdFlipCard(static_cast<Command_FlipCard *>(command), cont, game, player); case ItemId_Command_FlipCard: return cmdFlipCard(static_cast<Command_FlipCard *>(command), cont, game, player);
case ItemId_Command_AttachCard: return cmdAttachCard(static_cast<Command_AttachCard *>(command), cont, game, player); case ItemId_Command_AttachCard: return cmdAttachCard(static_cast<Command_AttachCard *>(command), cont, game, player);
...@@ -355,7 +356,12 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm ...@@ -355,7 +356,12 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm
if (authState == PasswordWrong) if (authState == PasswordWrong)
return RespLoginNeeded; return RespLoginNeeded;
Server_Game *game = room->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this); QList<int> gameTypes;
QList<GameTypeId *> gameTypeList = cmd->getGameTypes();
for (int i = 0; i < gameTypeList.size(); ++i)
gameTypes.append(gameTypeList[i]->getData());
Server_Game *game = room->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), gameTypes, cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this);
Server_Player *creator = game->getPlayers().values().first(); Server_Player *creator = game->getPlayers().values().first();
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator)); games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator));
...@@ -501,7 +507,7 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com ...@@ -501,7 +507,7 @@ ResponseCode Server_ProtocolHandler::cmdMulligan(Command_Mulligan * /*cmd*/, Com
cont->enqueueGameEventPrivate(new Event_Shuffle(player->getPlayerId()), game->getGameId()); cont->enqueueGameEventPrivate(new Event_Shuffle(player->getPlayerId()), game->getGameId());
cont->enqueueGameEventPublic(new Event_Shuffle(player->getPlayerId()), game->getGameId()); cont->enqueueGameEventPublic(new Event_Shuffle(player->getPlayerId()), game->getGameId());
drawCards(game, player, cont, number); player->drawCards(cont, number);
return RespOk; return RespOk;
} }
...@@ -515,7 +521,7 @@ ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, CommandCon ...@@ -515,7 +521,7 @@ ResponseCode Server_ProtocolHandler::cmdRollDie(Command_RollDie *cmd, CommandCon
return RespOk; return RespOk;
} }
ResponseCode Server_ProtocolHandler::drawCards(Server_Game *game, Server_Player *player, CommandContainer *cont, int number) ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
{ {
if (player->getSpectator()) if (player->getSpectator())
return RespFunctionNotAllowed; return RespFunctionNotAllowed;
...@@ -523,33 +529,20 @@ ResponseCode Server_ProtocolHandler::drawCards(Server_Game *game, Server_Player ...@@ -523,33 +529,20 @@ ResponseCode Server_ProtocolHandler::drawCards(Server_Game *game, Server_Player
if (!game->getGameStarted()) if (!game->getGameStarted())
return RespGameNotStarted; return RespGameNotStarted;
Server_CardZone *deck = player->getZones().value("deck"); return player->drawCards(cont, cmd->getNumber());
Server_CardZone *hand = player->getZones().value("hand");
if (deck->cards.size() < number)
number = deck->cards.size();
QList<ServerInfo_Card *> cardListPrivate;
QList<ServerInfo_Card *> cardListOmniscient;
for (int i = 0; i < number; ++i) {
Server_Card *card = deck->cards.takeFirst();
hand->cards.append(card);
cardListPrivate.append(new ServerInfo_Card(card->getId(), card->getName()));
cardListOmniscient.append(new ServerInfo_Card(card->getId(), card->getName()));
}
cont->enqueueGameEventPrivate(new Event_DrawCards(player->getPlayerId(), cardListPrivate.size(), cardListPrivate), game->getGameId());
cont->enqueueGameEventOmniscient(new Event_DrawCards(player->getPlayerId(), cardListOmniscient.size(), cardListOmniscient), game->getGameId());
cont->enqueueGameEventPublic(new Event_DrawCards(player->getPlayerId(), cardListPrivate.size()), game->getGameId());
return RespOk;
} }
ResponseCode Server_ProtocolHandler::cmdUndoDraw(Command_UndoDraw *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
ResponseCode Server_ProtocolHandler::cmdDrawCards(Command_DrawCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
{ {
return drawCards(game, player, cont, cmd->getNumber()); if (player->getSpectator())
return RespFunctionNotAllowed;
if (!game->getGameStarted())
return RespGameNotStarted;
return player->undoDraw(cont);
} }
ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player) ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
{ {
if (player->getSpectator()) if (player->getSpectator())
......
...@@ -61,8 +61,8 @@ private: ...@@ -61,8 +61,8 @@ private:
ResponseCode cmdShuffle(Command_Shuffle *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 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 cmdRollDie(Command_RollDie *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode drawCards(Server_Game *game, Server_Player *player, CommandContainer *cont, int number);
ResponseCode cmdDrawCards(Command_DrawCards *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 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 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 cmdAttachCard(Command_AttachCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment