mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 16:24:45 -07:00
implemented game types
This commit is contained in:
parent
7116382a96
commit
04742f6fb9
23 changed files with 249 additions and 127 deletions
|
|
@ -17,6 +17,7 @@ void ProtocolItem::initializeHash()
|
|||
registerSerializableItem("room", ServerInfo_Room::newItem);
|
||||
registerSerializableItem("user", ServerInfo_User::newItem);
|
||||
registerSerializableItem("game", ServerInfo_Game::newItem);
|
||||
registerSerializableItem("game_type", ServerInfo_GameType::newItem);
|
||||
registerSerializableItem("card_counter", ServerInfo_CardCounter::newItem);
|
||||
registerSerializableItem("card", ServerInfo_Card::newItem);
|
||||
registerSerializableItem("zone", ServerInfo_Zone::newItem);
|
||||
|
|
@ -28,10 +29,12 @@ void ProtocolItem::initializeHash()
|
|||
registerSerializableItem("file", DeckList_File::newItem);
|
||||
registerSerializableItem("directory", DeckList_Directory::newItem);
|
||||
registerSerializableItem("card_id", CardId::newItem);
|
||||
registerSerializableItem("game_type_id", GameTypeId::newItem);
|
||||
|
||||
registerSerializableItem("containercmd", CommandContainer::newItem);
|
||||
registerSerializableItem("containergame_event", GameEventContainer::newItem);
|
||||
|
||||
registerSerializableItem("cmdcreate_game", Command_CreateGame::newItem);
|
||||
registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem);
|
||||
registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem);
|
||||
registerSerializableItem("cmdset_sideboard_plan", Command_SetSideboardPlan::newItem);
|
||||
|
|
@ -166,6 +169,21 @@ void CommandContainer::enqueueGameEventPrivate(GameEvent *event, int gameId, int
|
|||
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("deck_upload")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class MoveCardToZone;
|
|||
enum ItemId {
|
||||
ItemId_CommandContainer = ItemId_Other + 50,
|
||||
ItemId_GameEventContainer = ItemId_Other + 51,
|
||||
ItemId_Command_CreateGame = ItemId_Other + 99,
|
||||
ItemId_Command_DeckUpload = ItemId_Other + 100,
|
||||
ItemId_Command_DeckSelect = ItemId_Other + 101,
|
||||
ItemId_Command_SetSideboardPlan = ItemId_Other + 102,
|
||||
|
|
@ -173,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 {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ ServerInfo_User::ServerInfo_User(const ServerInfo_User *other, bool complete)
|
|||
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")
|
||||
{
|
||||
insertItem(new SerializableItem_Int("game_id", _gameId));
|
||||
|
|
@ -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_need_password", _spectatorsNeedPassword));
|
||||
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")
|
||||
{
|
||||
insertItem(new SerializableItem_Int("room_id", _roomId));
|
||||
|
|
@ -55,6 +65,9 @@ ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QStrin
|
|||
userList = _userList;
|
||||
for (int i = 0; i < _userList.size(); ++i)
|
||||
itemList.append(_userList[i]);
|
||||
gameTypeList = _gameTypeList;
|
||||
for (int i = 0; i < _gameTypeList.size(); ++i)
|
||||
itemList.append(_gameTypeList[i]);
|
||||
}
|
||||
|
||||
void ServerInfo_Room::extractData()
|
||||
|
|
@ -70,6 +83,11 @@ void ServerInfo_Room::extractData()
|
|||
gameList.append(game);
|
||||
continue;
|
||||
}
|
||||
ServerInfo_GameType *gameType = dynamic_cast<ServerInfo_GameType *>(itemList[i]);
|
||||
if (gameType) {
|
||||
gameTypeList.append(gameType);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ public:
|
|||
CardId(int _cardId = -1) : SerializableItem_Int("card_id", _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 {
|
||||
public:
|
||||
|
|
@ -48,27 +53,37 @@ public:
|
|||
|
||||
class ServerInfo_Game : public SerializableItem_Map {
|
||||
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; }
|
||||
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(); }
|
||||
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 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")); }
|
||||
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(); }
|
||||
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 {
|
||||
private:
|
||||
QList<ServerInfo_Game *> gameList;
|
||||
QList<ServerInfo_User *> userList;
|
||||
QList<ServerInfo_GameType *> gameTypeList;
|
||||
protected:
|
||||
void extractData();
|
||||
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; }
|
||||
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(); }
|
||||
|
|
@ -78,6 +93,7 @@ public:
|
|||
bool getAutoJoin() const { return static_cast<SerializableItem_Bool *>(itemMap.value("auto_join"))->getData(); }
|
||||
const QList<ServerInfo_Game *> &getGameList() const { return gameList; }
|
||||
const QList<ServerInfo_User *> &getUserList() const { return userList; }
|
||||
const QList<ServerInfo_GameType *> &getGameTypeList() const { return gameTypeList; }
|
||||
};
|
||||
|
||||
class ServerInfo_CardCounter : public SerializableItem_Map {
|
||||
|
|
|
|||
|
|
@ -13,63 +13,62 @@ ItemId_Command_ListRooms = 1011,
|
|||
ItemId_Command_JoinRoom = 1012,
|
||||
ItemId_Command_LeaveRoom = 1013,
|
||||
ItemId_Command_RoomSay = 1014,
|
||||
ItemId_Command_CreateGame = 1015,
|
||||
ItemId_Command_JoinGame = 1016,
|
||||
ItemId_Command_LeaveGame = 1017,
|
||||
ItemId_Command_Say = 1018,
|
||||
ItemId_Command_Shuffle = 1019,
|
||||
ItemId_Command_Mulligan = 1020,
|
||||
ItemId_Command_RollDie = 1021,
|
||||
ItemId_Command_DrawCards = 1022,
|
||||
ItemId_Command_UndoDraw = 1023,
|
||||
ItemId_Command_FlipCard = 1024,
|
||||
ItemId_Command_AttachCard = 1025,
|
||||
ItemId_Command_CreateToken = 1026,
|
||||
ItemId_Command_CreateArrow = 1027,
|
||||
ItemId_Command_DeleteArrow = 1028,
|
||||
ItemId_Command_SetCardAttr = 1029,
|
||||
ItemId_Command_SetCardCounter = 1030,
|
||||
ItemId_Command_IncCardCounter = 1031,
|
||||
ItemId_Command_ReadyStart = 1032,
|
||||
ItemId_Command_Concede = 1033,
|
||||
ItemId_Command_IncCounter = 1034,
|
||||
ItemId_Command_CreateCounter = 1035,
|
||||
ItemId_Command_SetCounter = 1036,
|
||||
ItemId_Command_DelCounter = 1037,
|
||||
ItemId_Command_NextTurn = 1038,
|
||||
ItemId_Command_SetActivePhase = 1039,
|
||||
ItemId_Command_DumpZone = 1040,
|
||||
ItemId_Command_StopDumpZone = 1041,
|
||||
ItemId_Command_RevealCards = 1042,
|
||||
ItemId_Event_Say = 1043,
|
||||
ItemId_Event_Leave = 1044,
|
||||
ItemId_Event_GameClosed = 1045,
|
||||
ItemId_Event_Shuffle = 1046,
|
||||
ItemId_Event_RollDie = 1047,
|
||||
ItemId_Event_MoveCard = 1048,
|
||||
ItemId_Event_FlipCard = 1049,
|
||||
ItemId_Event_DestroyCard = 1050,
|
||||
ItemId_Event_AttachCard = 1051,
|
||||
ItemId_Event_CreateToken = 1052,
|
||||
ItemId_Event_DeleteArrow = 1053,
|
||||
ItemId_Event_SetCardAttr = 1054,
|
||||
ItemId_Event_SetCardCounter = 1055,
|
||||
ItemId_Event_SetCounter = 1056,
|
||||
ItemId_Event_DelCounter = 1057,
|
||||
ItemId_Event_SetActivePlayer = 1058,
|
||||
ItemId_Event_SetActivePhase = 1059,
|
||||
ItemId_Event_DumpZone = 1060,
|
||||
ItemId_Event_StopDumpZone = 1061,
|
||||
ItemId_Event_ServerMessage = 1062,
|
||||
ItemId_Event_Message = 1063,
|
||||
ItemId_Event_GameJoined = 1064,
|
||||
ItemId_Event_UserLeft = 1065,
|
||||
ItemId_Event_LeaveRoom = 1066,
|
||||
ItemId_Event_RoomSay = 1067,
|
||||
ItemId_Context_ReadyStart = 1068,
|
||||
ItemId_Context_Concede = 1069,
|
||||
ItemId_Context_DeckSelect = 1070,
|
||||
ItemId_Context_UndoDraw = 1071,
|
||||
ItemId_Command_UpdateServerMessage = 1072,
|
||||
ItemId_Other = 1073
|
||||
ItemId_Command_JoinGame = 1015,
|
||||
ItemId_Command_LeaveGame = 1016,
|
||||
ItemId_Command_Say = 1017,
|
||||
ItemId_Command_Shuffle = 1018,
|
||||
ItemId_Command_Mulligan = 1019,
|
||||
ItemId_Command_RollDie = 1020,
|
||||
ItemId_Command_DrawCards = 1021,
|
||||
ItemId_Command_UndoDraw = 1022,
|
||||
ItemId_Command_FlipCard = 1023,
|
||||
ItemId_Command_AttachCard = 1024,
|
||||
ItemId_Command_CreateToken = 1025,
|
||||
ItemId_Command_CreateArrow = 1026,
|
||||
ItemId_Command_DeleteArrow = 1027,
|
||||
ItemId_Command_SetCardAttr = 1028,
|
||||
ItemId_Command_SetCardCounter = 1029,
|
||||
ItemId_Command_IncCardCounter = 1030,
|
||||
ItemId_Command_ReadyStart = 1031,
|
||||
ItemId_Command_Concede = 1032,
|
||||
ItemId_Command_IncCounter = 1033,
|
||||
ItemId_Command_CreateCounter = 1034,
|
||||
ItemId_Command_SetCounter = 1035,
|
||||
ItemId_Command_DelCounter = 1036,
|
||||
ItemId_Command_NextTurn = 1037,
|
||||
ItemId_Command_SetActivePhase = 1038,
|
||||
ItemId_Command_DumpZone = 1039,
|
||||
ItemId_Command_StopDumpZone = 1040,
|
||||
ItemId_Command_RevealCards = 1041,
|
||||
ItemId_Event_Say = 1042,
|
||||
ItemId_Event_Leave = 1043,
|
||||
ItemId_Event_GameClosed = 1044,
|
||||
ItemId_Event_Shuffle = 1045,
|
||||
ItemId_Event_RollDie = 1046,
|
||||
ItemId_Event_MoveCard = 1047,
|
||||
ItemId_Event_FlipCard = 1048,
|
||||
ItemId_Event_DestroyCard = 1049,
|
||||
ItemId_Event_AttachCard = 1050,
|
||||
ItemId_Event_CreateToken = 1051,
|
||||
ItemId_Event_DeleteArrow = 1052,
|
||||
ItemId_Event_SetCardAttr = 1053,
|
||||
ItemId_Event_SetCardCounter = 1054,
|
||||
ItemId_Event_SetCounter = 1055,
|
||||
ItemId_Event_DelCounter = 1056,
|
||||
ItemId_Event_SetActivePlayer = 1057,
|
||||
ItemId_Event_SetActivePhase = 1058,
|
||||
ItemId_Event_DumpZone = 1059,
|
||||
ItemId_Event_StopDumpZone = 1060,
|
||||
ItemId_Event_ServerMessage = 1061,
|
||||
ItemId_Event_Message = 1062,
|
||||
ItemId_Event_GameJoined = 1063,
|
||||
ItemId_Event_UserLeft = 1064,
|
||||
ItemId_Event_LeaveRoom = 1065,
|
||||
ItemId_Event_RoomSay = 1066,
|
||||
ItemId_Context_ReadyStart = 1067,
|
||||
ItemId_Context_Concede = 1068,
|
||||
ItemId_Context_DeckSelect = 1069,
|
||||
ItemId_Context_UndoDraw = 1070,
|
||||
ItemId_Command_UpdateServerMessage = 1071,
|
||||
ItemId_Other = 1072
|
||||
};
|
||||
|
|
|
|||
|
|
@ -69,17 +69,6 @@ Command_RoomSay::Command_RoomSay(int _roomId, const QString &_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)
|
||||
: RoomCommand("join_game", _roomId)
|
||||
{
|
||||
|
|
@ -453,7 +442,6 @@ void ProtocolItem::initializeHashAuto()
|
|||
itemNameHash.insert("cmdjoin_room", Command_JoinRoom::newItem);
|
||||
itemNameHash.insert("cmdleave_room", Command_LeaveRoom::newItem);
|
||||
itemNameHash.insert("cmdroom_say", Command_RoomSay::newItem);
|
||||
itemNameHash.insert("cmdcreate_game", Command_CreateGame::newItem);
|
||||
itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem);
|
||||
itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem);
|
||||
itemNameHash.insert("cmdsay", Command_Say::newItem);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
0:join_room:i,room_id
|
||||
1:leave_room
|
||||
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
|
||||
2:leave_game
|
||||
2:say:s,message
|
||||
|
|
|
|||
|
|
@ -113,20 +113,6 @@ public:
|
|||
static SerializableItem *newItem() { return new 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 {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@
|
|||
#include <QTimer>
|
||||
#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)
|
||||
: 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)
|
||||
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), gameTypes(_gameTypes), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), secondsElapsed(0)
|
||||
{
|
||||
addPlayer(_creator, false, false);
|
||||
|
||||
|
|
@ -399,18 +399,25 @@ ServerInfo_Game *Server_Game::getInfo() const
|
|||
{
|
||||
if (players.isEmpty())
|
||||
// Game is closing
|
||||
return new ServerInfo_Game(getGameId(), QString(), false, 0, getMaxPlayers(), 0, false, 0);
|
||||
else
|
||||
return new ServerInfo_Game(getGameId(), QString(), false, 0, getMaxPlayers(), QList<GameTypeId *>(), 0, false, 0);
|
||||
else {
|
||||
// Game is open
|
||||
|
||||
QList<GameTypeId *> gameTypeList;
|
||||
for (int i = 0; i < gameTypes.size(); ++i)
|
||||
gameTypeList.append(new GameTypeId(gameTypes[i]));
|
||||
|
||||
return new ServerInfo_Game(
|
||||
getGameId(),
|
||||
getDescription(),
|
||||
!getPassword().isEmpty(),
|
||||
getPlayerCount(),
|
||||
getMaxPlayers(),
|
||||
gameTypeList,
|
||||
new ServerInfo_User(getCreatorInfo(), false),
|
||||
getSpectatorsAllowed(),
|
||||
getSpectatorsNeedPassword(),
|
||||
getSpectatorCount()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@ private:
|
|||
QString description;
|
||||
QString password;
|
||||
int maxPlayers;
|
||||
QList<int> gameTypes;
|
||||
int activePlayer, activePhase;
|
||||
bool spectatorsAllowed;
|
||||
bool spectatorsNeedPassword;
|
||||
|
|
@ -53,7 +54,7 @@ signals:
|
|||
private slots:
|
||||
void pingClockTimeout();
|
||||
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();
|
||||
ServerInfo_Game *getInfo() const;
|
||||
ServerInfo_User *getCreatorInfo() const { return creatorInfo; }
|
||||
|
|
|
|||
|
|
@ -356,7 +356,12 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm
|
|||
if (authState == PasswordWrong)
|
||||
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();
|
||||
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator));
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
#include "server_game.h"
|
||||
#include <QDebug>
|
||||
|
||||
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, Server *parent)
|
||||
: QObject(parent), id(_id), name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage)
|
||||
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
|
||||
: QObject(parent), id(_id), name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -17,6 +17,7 @@ ServerInfo_Room *Server_Room::getInfo(bool complete) const
|
|||
{
|
||||
QList<ServerInfo_Game *> gameList;
|
||||
QList<ServerInfo_User *> userList;
|
||||
QList<ServerInfo_GameType *> gameTypeList;
|
||||
if (complete) {
|
||||
QMapIterator<int, Server_Game *> gameIterator(games);
|
||||
while (gameIterator.hasNext())
|
||||
|
|
@ -24,9 +25,12 @@ ServerInfo_Room *Server_Room::getInfo(bool complete) const
|
|||
|
||||
for (int i = 0; i < size(); ++i)
|
||||
userList.append(new ServerInfo_User(at(i)->getUserInfo(), false));
|
||||
|
||||
for (int i = 0; i < gameTypes.size(); ++i)
|
||||
gameTypeList.append(new ServerInfo_GameType(i, gameTypes[i]));
|
||||
}
|
||||
|
||||
return new ServerInfo_Room(id, name, description, games.size(), size(), autoJoin, gameList, userList);
|
||||
return new ServerInfo_Room(id, name, description, games.size(), size(), autoJoin, gameList, userList, gameTypeList);
|
||||
}
|
||||
|
||||
void Server_Room::addClient(Server_ProtocolHandler *client)
|
||||
|
|
@ -64,9 +68,9 @@ void Server_Room::broadcastGameListUpdate(Server_Game *game)
|
|||
delete event;
|
||||
}
|
||||
|
||||
Server_Game *Server_Room::createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator)
|
||||
Server_Game *Server_Room::createGame(const QString &description, const QString &password, int maxPlayers, const QList<int> &gameTypes, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator)
|
||||
{
|
||||
Server_Game *newGame = new Server_Game(creator, static_cast<Server *>(parent())->getNextGameId(), description, password, maxPlayers, spectatorsAllowed, spectatorsNeedPassword, spectatorsCanTalk, spectatorsSeeEverything, this);
|
||||
Server_Game *newGame = new Server_Game(creator, static_cast<Server *>(parent())->getNextGameId(), description, password, maxPlayers, gameTypes, spectatorsAllowed, spectatorsNeedPassword, spectatorsCanTalk, spectatorsSeeEverything, this);
|
||||
games.insert(newGame->getGameId(), newGame);
|
||||
connect(newGame, SIGNAL(gameClosing()), this, SLOT(removeGame()));
|
||||
|
||||
|
|
|
|||
|
|
@ -25,11 +25,12 @@ private:
|
|||
QString description;
|
||||
bool autoJoin;
|
||||
QString joinMessage;
|
||||
QStringList gameTypes;
|
||||
QMap<int, Server_Game *> games;
|
||||
private slots:
|
||||
void removeGame();
|
||||
public:
|
||||
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, Server *parent);
|
||||
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
|
||||
int getId() const { return id; }
|
||||
QString getName() const { return name; }
|
||||
QString getDescription() const { return description; }
|
||||
|
|
@ -43,7 +44,7 @@ public:
|
|||
void removeClient(Server_ProtocolHandler *client);
|
||||
void say(Server_ProtocolHandler *client, const QString &s);
|
||||
void broadcastGameListUpdate(Server_Game *game);
|
||||
Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator);
|
||||
Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, const QList<int> &_gameTypes, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator);
|
||||
|
||||
void sendRoomEvent(RoomEvent *event);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue