initial commit for rooms
This commit is contained in:
parent
76a13be3c3
commit
d8d4563292
22 changed files with 428 additions and 452 deletions
|
@ -78,7 +78,7 @@ HEADERS += src/counter.h \
|
|||
../common/server_arrow.h \
|
||||
../common/server_card.h \
|
||||
../common/server_cardzone.h \
|
||||
../common/server_chatchannel.h \
|
||||
../common/server_room.h \
|
||||
../common/server_counter.h \
|
||||
../common/server_game.h \
|
||||
../common/server_player.h \
|
||||
|
@ -154,7 +154,7 @@ SOURCES += src/counter.cpp \
|
|||
../common/server.cpp \
|
||||
../common/server_card.cpp \
|
||||
../common/server_cardzone.cpp \
|
||||
../common/server_chatchannel.cpp \
|
||||
../common/server_room.cpp \
|
||||
../common/server_game.cpp \
|
||||
../common/server_player.cpp \
|
||||
../common/server_protocolhandler.cpp
|
||||
|
|
|
@ -14,7 +14,7 @@ void ProtocolItem::initializeHash()
|
|||
initializeHashAuto();
|
||||
|
||||
registerSerializableItem("move_card_to_zone", MoveCardToZone::newItem);
|
||||
registerSerializableItem("chat_channel", ServerInfo_ChatChannel::newItem);
|
||||
registerSerializableItem("room", ServerInfo_Room::newItem);
|
||||
registerSerializableItem("user", ServerInfo_User::newItem);
|
||||
registerSerializableItem("game", ServerInfo_Game::newItem);
|
||||
registerSerializableItem("card_counter", ServerInfo_CardCounter::newItem);
|
||||
|
@ -44,9 +44,10 @@ void ProtocolItem::initializeHash()
|
|||
registerSerializableItem("respdeck_upload", Response_DeckUpload::newItem);
|
||||
registerSerializableItem("respdump_zone", Response_DumpZone::newItem);
|
||||
|
||||
registerSerializableItem("generic_eventlist_games", Event_ListGames::newItem);
|
||||
registerSerializableItem("room_eventlist_games", Event_ListGames::newItem);
|
||||
registerSerializableItem("room_eventjoin_room", Event_JoinRoom::newItem);
|
||||
registerSerializableItem("generic_eventuser_joined", Event_UserJoined::newItem);
|
||||
registerSerializableItem("generic_eventlist_chat_channels", Event_ListChatChannels::newItem);
|
||||
registerSerializableItem("generic_eventlist_rooms", Event_ListRooms::newItem);
|
||||
registerSerializableItem("game_eventjoin", Event_Join::newItem);
|
||||
registerSerializableItem("game_eventgame_state_changed", Event_GameStateChanged::newItem);
|
||||
registerSerializableItem("game_eventplayer_properties_changed", Event_PlayerPropertiesChanged::newItem);
|
||||
|
@ -55,8 +56,6 @@ void ProtocolItem::initializeHash()
|
|||
registerSerializableItem("game_eventdraw_cards", Event_DrawCards::newItem);
|
||||
registerSerializableItem("game_eventreveal_cards", Event_RevealCards::newItem);
|
||||
registerSerializableItem("game_eventping", Event_Ping::newItem);
|
||||
registerSerializableItem("chat_eventchat_list_players", Event_ChatListPlayers::newItem);
|
||||
registerSerializableItem("chat_eventchat_join_channel", Event_ChatJoinChannel::newItem);
|
||||
}
|
||||
|
||||
TopLevelProtocolItem::TopLevelProtocolItem()
|
||||
|
@ -284,36 +283,29 @@ GameEventContext::GameEventContext(const QString &_contextName)
|
|||
{
|
||||
}
|
||||
|
||||
ChatEvent::ChatEvent(const QString &_eventName, const QString &_channel)
|
||||
: ProtocolItem("chat_event", _eventName)
|
||||
RoomEvent::RoomEvent(const QString &_eventName, int _roomId)
|
||||
: ProtocolItem("room_event", _eventName)
|
||||
{
|
||||
insertItem(new SerializableItem_String("channel", _channel));
|
||||
insertItem(new SerializableItem_Int("room_id", _roomId));
|
||||
}
|
||||
|
||||
Event_ListChatChannels::Event_ListChatChannels(const QList<ServerInfo_ChatChannel *> &_channelList)
|
||||
: GenericEvent("list_chat_channels")
|
||||
Event_ListRooms::Event_ListRooms(const QList<ServerInfo_Room *> &_roomList)
|
||||
: GenericEvent("list_rooms")
|
||||
{
|
||||
for (int i = 0; i < _channelList.size(); ++i)
|
||||
itemList.append(_channelList[i]);
|
||||
for (int i = 0; i < _roomList.size(); ++i)
|
||||
itemList.append(_roomList[i]);
|
||||
}
|
||||
|
||||
Event_ChatListPlayers::Event_ChatListPlayers(const QString &_channel, const QList<ServerInfo_User *> &_playerList)
|
||||
: ChatEvent("chat_list_players", _channel)
|
||||
{
|
||||
for (int i = 0; i < _playerList.size(); ++i)
|
||||
itemList.append(_playerList[i]);
|
||||
}
|
||||
|
||||
Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, ServerInfo_User *_info)
|
||||
: ChatEvent("chat_join_channel", _channel)
|
||||
Event_JoinRoom::Event_JoinRoom(int _roomId, ServerInfo_User *_info)
|
||||
: RoomEvent("join_room", _roomId)
|
||||
{
|
||||
if (!_info)
|
||||
_info = new ServerInfo_User;
|
||||
insertItem(_info);
|
||||
}
|
||||
|
||||
Event_ListGames::Event_ListGames(const QList<ServerInfo_Game *> &_gameList)
|
||||
: GenericEvent("list_games")
|
||||
Event_ListGames::Event_ListGames(int _roomId, const QList<ServerInfo_Game *> &_gameList)
|
||||
: RoomEvent("list_games", _roomId)
|
||||
{
|
||||
for (int i = 0; i < _gameList.size(); ++i)
|
||||
itemList.append(_gameList[i]);
|
||||
|
|
|
@ -25,9 +25,8 @@ enum ItemId {
|
|||
ItemId_Command_DeckUpload = ItemId_Other + 100,
|
||||
ItemId_Command_DeckSelect = ItemId_Other + 101,
|
||||
ItemId_Command_SetSideboardPlan = ItemId_Other + 102,
|
||||
ItemId_Event_ListChatChannels = ItemId_Other + 200,
|
||||
ItemId_Event_ChatListPlayers = ItemId_Other + 201,
|
||||
ItemId_Event_ChatJoinChannel = ItemId_Other + 202,
|
||||
ItemId_Event_ListRooms = ItemId_Other + 200,
|
||||
ItemId_Event_JoinRoom = ItemId_Other + 201,
|
||||
ItemId_Event_ListGames = ItemId_Other + 203,
|
||||
ItemId_Event_UserJoined = ItemId_Other + 204,
|
||||
ItemId_Event_GameStateChanged = ItemId_Other + 205,
|
||||
|
@ -136,15 +135,15 @@ public:
|
|||
int getPrivatePlayerId() const { return privatePlayerId; }
|
||||
};
|
||||
|
||||
class ChatCommand : public Command {
|
||||
class RoomCommand : public Command {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ChatCommand(const QString &_cmdName, const QString &_channel)
|
||||
RoomCommand(const QString &_cmdName, int _roomId)
|
||||
: Command(_cmdName)
|
||||
{
|
||||
insertItem(new SerializableItem_String("channel", _channel));
|
||||
insertItem(new SerializableItem_Int("room_id", _roomId));
|
||||
}
|
||||
QString getChannel() const { return static_cast<SerializableItem_String *>(itemMap.value("channel"))->getData(); }
|
||||
int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); }
|
||||
};
|
||||
|
||||
class GameCommand : public Command {
|
||||
|
@ -304,44 +303,35 @@ public:
|
|||
void setGameId(int _gameId) { static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->setData(_gameId); }
|
||||
};
|
||||
|
||||
class ChatEvent : public ProtocolItem {
|
||||
class RoomEvent : public ProtocolItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ChatEvent(const QString &_eventName, const QString &_channel);
|
||||
QString getChannel() const { return static_cast<SerializableItem_String *>(itemMap.value("channel"))->getData(); }
|
||||
RoomEvent(const QString &_eventName, int _roomId);
|
||||
int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_id"))->getData(); }
|
||||
};
|
||||
|
||||
class Event_ListChatChannels : public GenericEvent {
|
||||
class Event_ListRooms : public GenericEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_ListChatChannels(const QList<ServerInfo_ChatChannel *> &_channelList = QList<ServerInfo_ChatChannel *>());
|
||||
int getItemId() const { return ItemId_Event_ListChatChannels; }
|
||||
static SerializableItem *newItem() { return new Event_ListChatChannels; }
|
||||
QList<ServerInfo_ChatChannel *> getChannelList() const { return typecastItemList<ServerInfo_ChatChannel *>(); }
|
||||
Event_ListRooms(const QList<ServerInfo_Room *> &_roomList = QList<ServerInfo_Room *>());
|
||||
int getItemId() const { return ItemId_Event_ListRooms; }
|
||||
static SerializableItem *newItem() { return new Event_ListRooms; }
|
||||
QList<ServerInfo_Room *> getRoomList() const { return typecastItemList<ServerInfo_Room *>(); }
|
||||
};
|
||||
|
||||
class Event_ChatListPlayers : public ChatEvent {
|
||||
class Event_JoinRoom : public RoomEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_ChatListPlayers(const QString &_channel = QString(), const QList<ServerInfo_User *> &_playerList = QList<ServerInfo_User *>());
|
||||
int getItemId() const { return ItemId_Event_ChatListPlayers; }
|
||||
static SerializableItem *newItem() { return new Event_ChatListPlayers; }
|
||||
QList<ServerInfo_User *> getPlayerList() const { return typecastItemList<ServerInfo_User *>(); }
|
||||
};
|
||||
|
||||
class Event_ChatJoinChannel : public ChatEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_ChatJoinChannel(const QString &_channel = QString(), ServerInfo_User *_info = 0);
|
||||
int getItemId() const { return ItemId_Event_ChatJoinChannel; }
|
||||
static SerializableItem *newItem() { return new Event_ChatJoinChannel; }
|
||||
Event_JoinRoom(int _roomId = -1, ServerInfo_User *_info = 0);
|
||||
int getItemId() const { return ItemId_Event_JoinRoom; }
|
||||
static SerializableItem *newItem() { return new Event_JoinRoom; }
|
||||
ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
|
||||
};
|
||||
|
||||
class Event_ListGames : public GenericEvent {
|
||||
class Event_ListGames : public RoomEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_ListGames(const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>());
|
||||
Event_ListGames(int _roomId = -1, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>());
|
||||
int getItemId() const { return ItemId_Event_ListGames; }
|
||||
static SerializableItem *newItem() { return new Event_ListGames; }
|
||||
QList<ServerInfo_Game *> getGameList() const { return typecastItemList<ServerInfo_Game *>(); }
|
||||
|
|
|
@ -3,11 +3,13 @@
|
|||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
ServerInfo_ChatChannel::ServerInfo_ChatChannel(const QString &_name, const QString &_description, int _playerCount, bool _autoJoin)
|
||||
: SerializableItem_Map("chat_channel")
|
||||
ServerInfo_Room::ServerInfo_Room(int _roomId, const QString &_name, const QString &_description, int _gameCount, int _playerCount, bool _autoJoin)
|
||||
: SerializableItem_Map("room")
|
||||
{
|
||||
insertItem(new SerializableItem_Int("room_id", _roomId));
|
||||
insertItem(new SerializableItem_String("name", _name));
|
||||
insertItem(new SerializableItem_String("description", _description));
|
||||
insertItem(new SerializableItem_Int("game_count", _gameCount));
|
||||
insertItem(new SerializableItem_Int("player_count", _playerCount));
|
||||
insertItem(new SerializableItem_Bool("auto_join", _autoJoin));
|
||||
}
|
||||
|
|
|
@ -20,12 +20,14 @@ enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespInvalidData, Re
|
|||
// list index, whereas cards in any other zone are referenced by their ids.
|
||||
enum ZoneType { PrivateZone, PublicZone, HiddenZone };
|
||||
|
||||
class ServerInfo_ChatChannel : public SerializableItem_Map {
|
||||
class ServerInfo_Room : public SerializableItem_Map {
|
||||
public:
|
||||
ServerInfo_ChatChannel(const QString &_name = QString(), const QString &_description = QString(), int _playerCount = -1, bool _autoJoin = false);
|
||||
static SerializableItem *newItem() { return new ServerInfo_ChatChannel; }
|
||||
ServerInfo_Room(int _id = -1, const QString &_name = QString(), const QString &_description = QString(), int _gameCount = -1, int _playerCount = -1, bool _autoJoin = false);
|
||||
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(); }
|
||||
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
|
||||
int getGameCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_count"))->getData(); }
|
||||
int getPlayerCount() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_count"))->getData(); }
|
||||
bool getAutoJoin() const { return static_cast<SerializableItem_Bool *>(itemMap.value("auto_join"))->getData(); }
|
||||
};
|
||||
|
|
|
@ -2,73 +2,72 @@ enum AutoItemId {
|
|||
ItemId_Command_Ping = 1001,
|
||||
ItemId_Command_Login = 1002,
|
||||
ItemId_Command_Message = 1003,
|
||||
ItemId_Command_GetUserInfo = 1004,
|
||||
ItemId_Command_DeckList = 1005,
|
||||
ItemId_Command_DeckNewDir = 1006,
|
||||
ItemId_Command_DeckDelDir = 1007,
|
||||
ItemId_Command_DeckDel = 1008,
|
||||
ItemId_Command_DeckDownload = 1009,
|
||||
ItemId_Command_ListChatChannels = 1010,
|
||||
ItemId_Command_ChatJoinChannel = 1011,
|
||||
ItemId_Command_ChatLeaveChannel = 1012,
|
||||
ItemId_Command_ChatSay = 1013,
|
||||
ItemId_Command_ListGames = 1014,
|
||||
ItemId_Command_ListUsers = 1015,
|
||||
ItemId_Command_CreateGame = 1016,
|
||||
ItemId_Command_JoinGame = 1017,
|
||||
ItemId_Command_LeaveGame = 1018,
|
||||
ItemId_Command_Say = 1019,
|
||||
ItemId_Command_Shuffle = 1020,
|
||||
ItemId_Command_Mulligan = 1021,
|
||||
ItemId_Command_RollDie = 1022,
|
||||
ItemId_Command_DrawCards = 1023,
|
||||
ItemId_Command_MoveCard = 1024,
|
||||
ItemId_Command_FlipCard = 1025,
|
||||
ItemId_Command_AttachCard = 1026,
|
||||
ItemId_Command_CreateToken = 1027,
|
||||
ItemId_Command_CreateArrow = 1028,
|
||||
ItemId_Command_DeleteArrow = 1029,
|
||||
ItemId_Command_SetCardAttr = 1030,
|
||||
ItemId_Command_SetCardCounter = 1031,
|
||||
ItemId_Command_IncCardCounter = 1032,
|
||||
ItemId_Command_ReadyStart = 1033,
|
||||
ItemId_Command_Concede = 1034,
|
||||
ItemId_Command_IncCounter = 1035,
|
||||
ItemId_Command_CreateCounter = 1036,
|
||||
ItemId_Command_SetCounter = 1037,
|
||||
ItemId_Command_DelCounter = 1038,
|
||||
ItemId_Command_NextTurn = 1039,
|
||||
ItemId_Command_SetActivePhase = 1040,
|
||||
ItemId_Command_DumpZone = 1041,
|
||||
ItemId_Command_StopDumpZone = 1042,
|
||||
ItemId_Command_RevealCards = 1043,
|
||||
ItemId_Event_Say = 1044,
|
||||
ItemId_Event_Leave = 1045,
|
||||
ItemId_Event_GameClosed = 1046,
|
||||
ItemId_Event_Shuffle = 1047,
|
||||
ItemId_Event_RollDie = 1048,
|
||||
ItemId_Event_MoveCard = 1049,
|
||||
ItemId_Event_FlipCard = 1050,
|
||||
ItemId_Event_DestroyCard = 1051,
|
||||
ItemId_Event_AttachCard = 1052,
|
||||
ItemId_Event_CreateToken = 1053,
|
||||
ItemId_Event_DeleteArrow = 1054,
|
||||
ItemId_Event_SetCardAttr = 1055,
|
||||
ItemId_Event_SetCardCounter = 1056,
|
||||
ItemId_Event_SetCounter = 1057,
|
||||
ItemId_Event_DelCounter = 1058,
|
||||
ItemId_Event_SetActivePlayer = 1059,
|
||||
ItemId_Event_SetActivePhase = 1060,
|
||||
ItemId_Event_DumpZone = 1061,
|
||||
ItemId_Event_StopDumpZone = 1062,
|
||||
ItemId_Event_ServerMessage = 1063,
|
||||
ItemId_Event_Message = 1064,
|
||||
ItemId_Event_GameJoined = 1065,
|
||||
ItemId_Event_UserLeft = 1066,
|
||||
ItemId_Event_ChatLeaveChannel = 1067,
|
||||
ItemId_Event_ChatSay = 1068,
|
||||
ItemId_Context_ReadyStart = 1069,
|
||||
ItemId_Context_Concede = 1070,
|
||||
ItemId_Context_DeckSelect = 1071,
|
||||
ItemId_Other = 1072
|
||||
ItemId_Command_ListUsers = 1004,
|
||||
ItemId_Command_GetUserInfo = 1005,
|
||||
ItemId_Command_DeckList = 1006,
|
||||
ItemId_Command_DeckNewDir = 1007,
|
||||
ItemId_Command_DeckDelDir = 1008,
|
||||
ItemId_Command_DeckDel = 1009,
|
||||
ItemId_Command_DeckDownload = 1010,
|
||||
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_MoveCard = 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_Other = 1071
|
||||
};
|
||||
|
|
|
@ -17,6 +17,10 @@ Command_Message::Command_Message(const QString &_userName, const QString &_text)
|
|||
insertItem(new SerializableItem_String("user_name", _userName));
|
||||
insertItem(new SerializableItem_String("text", _text));
|
||||
}
|
||||
Command_ListUsers::Command_ListUsers()
|
||||
: Command("list_users")
|
||||
{
|
||||
}
|
||||
Command_GetUserInfo::Command_GetUserInfo(const QString &_userName)
|
||||
: Command("get_user_info")
|
||||
{
|
||||
|
@ -47,34 +51,26 @@ Command_DeckDownload::Command_DeckDownload(int _deckId)
|
|||
{
|
||||
insertItem(new SerializableItem_Int("deck_id", _deckId));
|
||||
}
|
||||
Command_ListChatChannels::Command_ListChatChannels()
|
||||
: Command("list_chat_channels")
|
||||
Command_ListRooms::Command_ListRooms()
|
||||
: Command("list_rooms")
|
||||
{
|
||||
}
|
||||
Command_ChatJoinChannel::Command_ChatJoinChannel(const QString &_channel)
|
||||
: Command("chat_join_channel")
|
||||
Command_JoinRoom::Command_JoinRoom(int _roomId)
|
||||
: Command("join_room")
|
||||
{
|
||||
insertItem(new SerializableItem_String("channel", _channel));
|
||||
insertItem(new SerializableItem_Int("room_id", _roomId));
|
||||
}
|
||||
Command_ChatLeaveChannel::Command_ChatLeaveChannel(const QString &_channel)
|
||||
: ChatCommand("chat_leave_channel", _channel)
|
||||
Command_LeaveRoom::Command_LeaveRoom(int _roomId)
|
||||
: RoomCommand("leave_room", _roomId)
|
||||
{
|
||||
}
|
||||
Command_ChatSay::Command_ChatSay(const QString &_channel, const QString &_message)
|
||||
: ChatCommand("chat_say", _channel)
|
||||
Command_RoomSay::Command_RoomSay(int _roomId, const QString &_message)
|
||||
: RoomCommand("room_say", _roomId)
|
||||
{
|
||||
insertItem(new SerializableItem_String("message", _message));
|
||||
}
|
||||
Command_ListGames::Command_ListGames()
|
||||
: Command("list_games")
|
||||
{
|
||||
}
|
||||
Command_ListUsers::Command_ListUsers()
|
||||
: Command("list_users")
|
||||
{
|
||||
}
|
||||
Command_CreateGame::Command_CreateGame(const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything)
|
||||
: Command("create_game")
|
||||
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));
|
||||
|
@ -84,8 +80,8 @@ Command_CreateGame::Command_CreateGame(const QString &_description, const QStrin
|
|||
insertItem(new SerializableItem_Bool("spectators_can_talk", _spectatorsCanTalk));
|
||||
insertItem(new SerializableItem_Bool("spectators_see_everything", _spectatorsSeeEverything));
|
||||
}
|
||||
Command_JoinGame::Command_JoinGame(int _gameId, const QString &_password, bool _spectator)
|
||||
: Command("join_game")
|
||||
Command_JoinGame::Command_JoinGame(int _roomId, int _gameId, const QString &_password, bool _spectator)
|
||||
: RoomCommand("join_game", _roomId)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("game_id", _gameId));
|
||||
insertItem(new SerializableItem_String("password", _password));
|
||||
|
@ -417,13 +413,13 @@ Event_UserLeft::Event_UserLeft(const QString &_userName)
|
|||
{
|
||||
insertItem(new SerializableItem_String("user_name", _userName));
|
||||
}
|
||||
Event_ChatLeaveChannel::Event_ChatLeaveChannel(const QString &_channel, const QString &_playerName)
|
||||
: ChatEvent("chat_leave_channel", _channel)
|
||||
Event_LeaveRoom::Event_LeaveRoom(int _roomId, const QString &_playerName)
|
||||
: RoomEvent("leave_room", _roomId)
|
||||
{
|
||||
insertItem(new SerializableItem_String("player_name", _playerName));
|
||||
}
|
||||
Event_ChatSay::Event_ChatSay(const QString &_channel, const QString &_playerName, const QString &_message)
|
||||
: ChatEvent("chat_say", _channel)
|
||||
Event_RoomSay::Event_RoomSay(int _roomId, const QString &_playerName, const QString &_message)
|
||||
: RoomEvent("room_say", _roomId)
|
||||
{
|
||||
insertItem(new SerializableItem_String("player_name", _playerName));
|
||||
insertItem(new SerializableItem_String("message", _message));
|
||||
|
@ -446,18 +442,17 @@ 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_user_info", Command_GetUserInfo::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_chat_channels", Command_ListChatChannels::newItem);
|
||||
itemNameHash.insert("cmdchat_join_channel", Command_ChatJoinChannel::newItem);
|
||||
itemNameHash.insert("cmdchat_leave_channel", Command_ChatLeaveChannel::newItem);
|
||||
itemNameHash.insert("cmdchat_say", Command_ChatSay::newItem);
|
||||
itemNameHash.insert("cmdlist_games", Command_ListGames::newItem);
|
||||
itemNameHash.insert("cmdlist_users", Command_ListUsers::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("cmdcreate_game", Command_CreateGame::newItem);
|
||||
itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem);
|
||||
itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem);
|
||||
|
@ -509,8 +504,8 @@ void ProtocolItem::initializeHashAuto()
|
|||
itemNameHash.insert("generic_eventmessage", Event_Message::newItem);
|
||||
itemNameHash.insert("generic_eventgame_joined", Event_GameJoined::newItem);
|
||||
itemNameHash.insert("generic_eventuser_left", Event_UserLeft::newItem);
|
||||
itemNameHash.insert("chat_eventchat_leave_channel", Event_ChatLeaveChannel::newItem);
|
||||
itemNameHash.insert("chat_eventchat_say", Event_ChatSay::newItem);
|
||||
itemNameHash.insert("room_eventleave_room", Event_LeaveRoom::newItem);
|
||||
itemNameHash.insert("room_eventroom_say", Event_RoomSay::newItem);
|
||||
itemNameHash.insert("game_event_contextready_start", Context_ReadyStart::newItem);
|
||||
itemNameHash.insert("game_event_contextconcede", Context_Concede::newItem);
|
||||
itemNameHash.insert("game_event_contextdeck_select", Context_DeckSelect::newItem);
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
0:ping
|
||||
0:login:s,username:s,password
|
||||
0:message:s,user_name:s,text
|
||||
0:list_users
|
||||
0:get_user_info: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_chat_channels
|
||||
0:chat_join_channel:s,channel
|
||||
1:chat_leave_channel
|
||||
1:chat_say:s,message
|
||||
0:list_games
|
||||
0:list_users
|
||||
0:create_game:s,description:s,password:i,max_players:b,spectators_allowed:b,spectators_need_password:b,spectators_can_talk:b,spectators_see_everything
|
||||
0:join_game:i,game_id:s,password:b,spectator
|
||||
0:list_rooms
|
||||
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
|
||||
2:shuffle
|
||||
|
@ -64,8 +63,8 @@
|
|||
4:message:s,sender_name:s,receiver_name:s,text
|
||||
4:game_joined:i,game_id:s,game_description:i,player_id:b,spectator:b,spectators_can_talk:b,spectators_see_everything:b,resuming
|
||||
4:user_left:s,user_name
|
||||
5:chat_leave_channel:s,player_name
|
||||
5:chat_say:s,player_name:s,message
|
||||
5:leave_room:s,player_name
|
||||
5:room_say:s,player_name:s,message
|
||||
6:ready_start
|
||||
6:concede
|
||||
6:deck_select:i,deck_id
|
||||
|
|
|
@ -28,6 +28,13 @@ public:
|
|||
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_GetUserInfo : public Command {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -76,54 +83,40 @@ public:
|
|||
static SerializableItem *newItem() { return new Command_DeckDownload; }
|
||||
int getItemId() const { return ItemId_Command_DeckDownload; }
|
||||
};
|
||||
class Command_ListChatChannels : public Command {
|
||||
class Command_ListRooms : public Command {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_ListChatChannels();
|
||||
static SerializableItem *newItem() { return new Command_ListChatChannels; }
|
||||
int getItemId() const { return ItemId_Command_ListChatChannels; }
|
||||
Command_ListRooms();
|
||||
static SerializableItem *newItem() { return new Command_ListRooms; }
|
||||
int getItemId() const { return ItemId_Command_ListRooms; }
|
||||
};
|
||||
class Command_ChatJoinChannel : public Command {
|
||||
class Command_JoinRoom : public Command {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_ChatJoinChannel(const QString &_channel = QString());
|
||||
QString getChannel() const { return static_cast<SerializableItem_String *>(itemMap.value("channel"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Command_ChatJoinChannel; }
|
||||
int getItemId() const { return ItemId_Command_ChatJoinChannel; }
|
||||
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_ChatLeaveChannel : public ChatCommand {
|
||||
class Command_LeaveRoom : public RoomCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_ChatLeaveChannel(const QString &_channel = QString());
|
||||
static SerializableItem *newItem() { return new Command_ChatLeaveChannel; }
|
||||
int getItemId() const { return ItemId_Command_ChatLeaveChannel; }
|
||||
Command_LeaveRoom(int _roomId = -1);
|
||||
static SerializableItem *newItem() { return new Command_LeaveRoom; }
|
||||
int getItemId() const { return ItemId_Command_LeaveRoom; }
|
||||
};
|
||||
class Command_ChatSay : public ChatCommand {
|
||||
class Command_RoomSay : public RoomCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_ChatSay(const QString &_channel = QString(), const QString &_message = QString());
|
||||
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_ChatSay; }
|
||||
int getItemId() const { return ItemId_Command_ChatSay; }
|
||||
static SerializableItem *newItem() { return new Command_RoomSay; }
|
||||
int getItemId() const { return ItemId_Command_RoomSay; }
|
||||
};
|
||||
class Command_ListGames : public Command {
|
||||
class Command_CreateGame : public RoomCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_ListGames();
|
||||
static SerializableItem *newItem() { return new Command_ListGames; }
|
||||
int getItemId() const { return ItemId_Command_ListGames; }
|
||||
};
|
||||
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_CreateGame : public Command {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_CreateGame(const QString &_description = QString(), const QString &_password = QString(), int _maxPlayers = -1, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, bool _spectatorsCanTalk = false, bool _spectatorsSeeEverything = false);
|
||||
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(); };
|
||||
|
@ -134,10 +127,10 @@ public:
|
|||
static SerializableItem *newItem() { return new Command_CreateGame; }
|
||||
int getItemId() const { return ItemId_Command_CreateGame; }
|
||||
};
|
||||
class Command_JoinGame : public Command {
|
||||
class Command_JoinGame : public RoomCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_JoinGame(int _gameId = -1, const QString &_password = QString(), bool _spectator = false);
|
||||
Command_JoinGame(int _roomId = -1, int _gameId = -1, const QString &_password = QString(), bool _spectator = 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(); };
|
||||
|
@ -617,22 +610,22 @@ public:
|
|||
static SerializableItem *newItem() { return new Event_UserLeft; }
|
||||
int getItemId() const { return ItemId_Event_UserLeft; }
|
||||
};
|
||||
class Event_ChatLeaveChannel : public ChatEvent {
|
||||
class Event_LeaveRoom : public RoomEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_ChatLeaveChannel(const QString &_channel = QString(), const QString &_playerName = QString());
|
||||
Event_LeaveRoom(int _roomId = -1, const QString &_playerName = QString());
|
||||
QString getPlayerName() const { return static_cast<SerializableItem_String *>(itemMap.value("player_name"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_ChatLeaveChannel; }
|
||||
int getItemId() const { return ItemId_Event_ChatLeaveChannel; }
|
||||
static SerializableItem *newItem() { return new Event_LeaveRoom; }
|
||||
int getItemId() const { return ItemId_Event_LeaveRoom; }
|
||||
};
|
||||
class Event_ChatSay : public ChatEvent {
|
||||
class Event_RoomSay : public RoomEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_ChatSay(const QString &_channel = QString(), const QString &_playerName = QString(), const QString &_message = QString());
|
||||
Event_RoomSay(int _roomId = -1, const QString &_playerName = QString(), const QString &_message = QString());
|
||||
QString getPlayerName() const { return static_cast<SerializableItem_String *>(itemMap.value("player_name"))->getData(); };
|
||||
QString getMessage() const { return static_cast<SerializableItem_String *>(itemMap.value("message"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_ChatSay; }
|
||||
int getItemId() const { return ItemId_Event_ChatSay; }
|
||||
static SerializableItem *newItem() { return new Event_RoomSay; }
|
||||
int getItemId() const { return ItemId_Event_RoomSay; }
|
||||
};
|
||||
class Context_ReadyStart : public GameEventContext {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -34,10 +34,10 @@ while (<file>) {
|
|||
} elsif ($type == 1) {
|
||||
$type = 'cmd';
|
||||
$namePrefix = 'Command';
|
||||
$baseClass = 'ChatCommand';
|
||||
$parentConstructorCall = "$baseClass(\"$name1\", _channel)";
|
||||
$constructorParamsH = "const QString &_channel = QString()";
|
||||
$constructorParamsCpp = "const QString &_channel";
|
||||
$baseClass = 'RoomCommand';
|
||||
$parentConstructorCall = "$baseClass(\"$name1\", _roomId)";
|
||||
$constructorParamsH = "int _roomId = -1";
|
||||
$constructorParamsCpp = "int _roomId";
|
||||
} elsif ($type == 2) {
|
||||
$type = 'cmd';
|
||||
$namePrefix = 'Command';
|
||||
|
@ -60,12 +60,12 @@ while (<file>) {
|
|||
$constructorParamsH = "";
|
||||
$constructorParamsCpp = "";
|
||||
} elsif ($type == 5) {
|
||||
$type = 'chat_event';
|
||||
$type = 'room_event';
|
||||
$namePrefix = 'Event';
|
||||
$baseClass = 'ChatEvent';
|
||||
$parentConstructorCall = "$baseClass(\"$name1\", _channel)";
|
||||
$constructorParamsH = "const QString &_channel = QString()";
|
||||
$constructorParamsCpp = "const QString &_channel";
|
||||
$baseClass = 'RoomEvent';
|
||||
$parentConstructorCall = "$baseClass(\"$name1\", _roomId)";
|
||||
$constructorParamsH = "int _roomId = -1";
|
||||
$constructorParamsCpp = "int _roomId";
|
||||
} elsif ($type == 6) {
|
||||
$type = 'game_event_context';
|
||||
$namePrefix = 'Context';
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "server.h"
|
||||
#include "server_game.h"
|
||||
#include "server_counter.h"
|
||||
#include "server_chatchannel.h"
|
||||
#include "server_room.h"
|
||||
#include "server_protocolhandler.h"
|
||||
#include "protocol_datastructures.h"
|
||||
#include <QDebug>
|
||||
|
@ -69,17 +69,6 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
|||
return authState;
|
||||
}
|
||||
|
||||
Server_Game *Server::createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator)
|
||||
{
|
||||
Server_Game *newGame = new Server_Game(creator, nextGameId++, description, password, maxPlayers, spectatorsAllowed, spectatorsNeedPassword, spectatorsCanTalk, spectatorsSeeEverything, this);
|
||||
games.insert(newGame->getGameId(), newGame);
|
||||
connect(newGame, SIGNAL(gameClosing()), this, SLOT(gameClosing()));
|
||||
|
||||
broadcastGameListUpdate(newGame);
|
||||
|
||||
return newGame;
|
||||
}
|
||||
|
||||
void Server::addClient(Server_ProtocolHandler *client)
|
||||
{
|
||||
clients << client;
|
||||
|
@ -106,56 +95,29 @@ Server_Game *Server::getGame(int gameId) const
|
|||
return games.value(gameId);
|
||||
}
|
||||
|
||||
void Server::broadcastGameListUpdate(Server_Game *game)
|
||||
void Server::broadcastRoomUpdate()
|
||||
{
|
||||
QList<ServerInfo_Game *> eventGameList;
|
||||
if (game->getPlayerCount())
|
||||
// Game is open
|
||||
eventGameList.append(new ServerInfo_Game(
|
||||
game->getGameId(),
|
||||
game->getDescription(),
|
||||
!game->getPassword().isEmpty(),
|
||||
game->getPlayerCount(),
|
||||
game->getMaxPlayers(),
|
||||
new ServerInfo_User(game->getCreatorInfo()),
|
||||
game->getSpectatorsAllowed(),
|
||||
game->getSpectatorsNeedPassword(),
|
||||
game->getSpectatorCount()
|
||||
));
|
||||
else
|
||||
// Game is closing
|
||||
eventGameList.append(new ServerInfo_Game(game->getGameId(), QString(), false, 0, game->getMaxPlayers(), 0, false, 0));
|
||||
Event_ListGames *event = new Event_ListGames(eventGameList);
|
||||
|
||||
for (int i = 0; i < clients.size(); i++)
|
||||
if (clients[i]->getAcceptsGameListChanges())
|
||||
clients[i]->sendProtocolItem(event, false);
|
||||
delete event;
|
||||
}
|
||||
|
||||
void Server::broadcastChannelUpdate()
|
||||
{
|
||||
Server_ChatChannel *channel = static_cast<Server_ChatChannel *>(sender());
|
||||
QList<ServerInfo_ChatChannel *> eventChannelList;
|
||||
eventChannelList.append(new ServerInfo_ChatChannel(channel->getName(), channel->getDescription(), channel->size(), channel->getAutoJoin()));
|
||||
Event_ListChatChannels *event = new Event_ListChatChannels(eventChannelList);
|
||||
Server_Room *room = static_cast<Server_Room *>(sender());
|
||||
QList<ServerInfo_Room *> eventRoomList;
|
||||
eventRoomList.append(new ServerInfo_Room(room->getId(), room->getName(), room->getDescription(), room->getGames().size(), room->size(), room->getAutoJoin()));
|
||||
Event_ListRooms *event = new Event_ListRooms(eventRoomList);
|
||||
|
||||
for (int i = 0; i < clients.size(); ++i)
|
||||
if (clients[i]->getAcceptsChatChannelListChanges())
|
||||
if (clients[i]->getAcceptsRoomListChanges())
|
||||
clients[i]->sendProtocolItem(event, false);
|
||||
delete event;
|
||||
}
|
||||
|
||||
void Server::gameClosing()
|
||||
void Server::gameClosing(int gameId)
|
||||
{
|
||||
qDebug("Server::gameClosing");
|
||||
Server_Game *game = static_cast<Server_Game *>(sender());
|
||||
broadcastGameListUpdate(game);
|
||||
games.remove(games.key(game));
|
||||
games.remove(gameId);
|
||||
}
|
||||
|
||||
void Server::addChatChannel(Server_ChatChannel *newChannel)
|
||||
void Server::addRoom(Server_Room *newRoom)
|
||||
{
|
||||
chatChannels.insert(newChannel->getName(), newChannel);
|
||||
connect(newChannel, SIGNAL(channelInfoChanged()), this, SLOT(broadcastChannelUpdate()));
|
||||
rooms.insert(newRoom->getId(), newRoom);
|
||||
connect(newRoom, SIGNAL(roomInfoChanged()), this, SLOT(broadcastRoomUpdate()));
|
||||
connect(newRoom, SIGNAL(gameCreated(Server_Game *)), this, SLOT(gameCreated(Server_Game *)));
|
||||
connect(newRoom, SIGNAL(gameClosing(int)), this, SLOT(gameClosing(int)));
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <QMap>
|
||||
|
||||
class Server_Game;
|
||||
class Server_ChatChannel;
|
||||
class Server_Room;
|
||||
class Server_ProtocolHandler;
|
||||
class ServerInfo_User;
|
||||
|
||||
|
@ -18,22 +18,21 @@ class Server : public QObject
|
|||
signals:
|
||||
void pingClockTimeout();
|
||||
private slots:
|
||||
void gameClosing();
|
||||
void broadcastChannelUpdate();
|
||||
void gameClosing(int gameId);
|
||||
void broadcastRoomUpdate();
|
||||
public:
|
||||
Server(QObject *parent = 0);
|
||||
~Server();
|
||||
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password);
|
||||
QList<Server_Game *> getGames() const { return games.values(); }
|
||||
Server_Game *getGame(int gameId) const;
|
||||
const QMap<QString, Server_ChatChannel *> &getChatChannels() { return chatChannels; }
|
||||
void broadcastGameListUpdate(Server_Game *game);
|
||||
const QMap<int, Server_Room *> &getRooms() { return rooms; }
|
||||
int getNextGameId() { return nextGameId++; }
|
||||
|
||||
const QMap<QString, Server_ProtocolHandler *> &getUsers() const { return users; }
|
||||
void addClient(Server_ProtocolHandler *player);
|
||||
void removeClient(Server_ProtocolHandler *player);
|
||||
virtual QString getLoginMessage() const = 0;
|
||||
Server_Game *createGame(const QString &description, const QString &password, int maxPlayers, bool spectatorsAllowed, bool spectatorsNeedPassword, bool spectatorsCanTalk, bool spectatorsSeeEverything, Server_ProtocolHandler *creator);
|
||||
|
||||
virtual bool getGameShouldPing() const = 0;
|
||||
virtual int getMaxGameInactivityTime() const = 0;
|
||||
|
@ -42,12 +41,12 @@ protected:
|
|||
QMap<int, Server_Game *> games;
|
||||
QList<Server_ProtocolHandler *> clients;
|
||||
QMap<QString, Server_ProtocolHandler *> users;
|
||||
QMap<QString, Server_ChatChannel *> chatChannels;
|
||||
QMap<int, Server_Room *> rooms;
|
||||
|
||||
virtual AuthenticationResult checkUserPassword(const QString &user, const QString &password) = 0;
|
||||
virtual ServerInfo_User *getUserData(const QString &name) = 0;
|
||||
int nextGameId;
|
||||
void addChatChannel(Server_ChatChannel *newChannel);
|
||||
void addRoom(Server_Room *newRoom);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
#include "server_chatchannel.h"
|
||||
#include "server_protocolhandler.h"
|
||||
|
||||
Server_ChatChannel::Server_ChatChannel(const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage)
|
||||
: name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage)
|
||||
{
|
||||
}
|
||||
|
||||
void Server_ChatChannel::addClient(Server_ProtocolHandler *client)
|
||||
{
|
||||
sendChatEvent(new Event_ChatJoinChannel(name, new ServerInfo_User(client->getUserInfo())));
|
||||
append(client);
|
||||
|
||||
QList<ServerInfo_User *> eventUserList;
|
||||
for (int i = 0; i < size(); ++i)
|
||||
eventUserList.append(new ServerInfo_User(at(i)->getUserInfo()));
|
||||
Event_ChatListPlayers *eventCLP = new Event_ChatListPlayers(name, eventUserList);
|
||||
client->enqueueProtocolItem(eventCLP);
|
||||
|
||||
client->enqueueProtocolItem(new Event_ChatSay(name, QString(), joinMessage));
|
||||
|
||||
emit channelInfoChanged();
|
||||
}
|
||||
|
||||
void Server_ChatChannel::removeClient(Server_ProtocolHandler *client)
|
||||
{
|
||||
removeAt(indexOf(client));
|
||||
sendChatEvent(new Event_ChatLeaveChannel(name, client->getUserInfo()->getName()));
|
||||
emit channelInfoChanged();
|
||||
}
|
||||
|
||||
void Server_ChatChannel::say(Server_ProtocolHandler *client, const QString &s)
|
||||
{
|
||||
sendChatEvent(new Event_ChatSay(name, client->getUserInfo()->getName(), s));
|
||||
}
|
||||
|
||||
void Server_ChatChannel::sendChatEvent(ChatEvent *event)
|
||||
{
|
||||
for (int i = 0; i < size(); ++i)
|
||||
at(i)->sendProtocolItem(event, false);
|
||||
delete event;
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
#ifndef CHATCHANNEL_H
|
||||
#define CHATCHANNEL_H
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
class Server_ProtocolHandler;
|
||||
class ChatEvent;
|
||||
|
||||
class Server_ChatChannel : public QObject, public QList<Server_ProtocolHandler *> {
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void channelInfoChanged();
|
||||
private:
|
||||
QString name;
|
||||
QString description;
|
||||
bool autoJoin;
|
||||
QString joinMessage;
|
||||
public:
|
||||
Server_ChatChannel(const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage);
|
||||
QString getName() const { return name; }
|
||||
QString getDescription() const { return description; }
|
||||
bool getAutoJoin() const { return autoJoin; }
|
||||
void addClient(Server_ProtocolHandler *client);
|
||||
void removeClient(Server_ProtocolHandler *client);
|
||||
void say(Server_ProtocolHandler *client, const QString &s);
|
||||
|
||||
void sendChatEvent(ChatEvent *event);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,6 +18,7 @@
|
|||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "server.h"
|
||||
#include "server_room.h"
|
||||
#include "server_game.h"
|
||||
#include "server_protocolhandler.h"
|
||||
#include "server_arrow.h"
|
||||
|
@ -27,12 +28,12 @@
|
|||
#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 *parent)
|
||||
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)
|
||||
{
|
||||
addPlayer(_creator, false, false);
|
||||
|
||||
if (parent->getGameShouldPing()) {
|
||||
if (parent->getServer()->getGameShouldPing()) {
|
||||
pingClock = new QTimer(this);
|
||||
connect(pingClock, SIGNAL(timeout()), this, SLOT(pingClockTimeout()));
|
||||
pingClock->start(1000);
|
||||
|
@ -71,7 +72,7 @@ void Server_Game::pingClockTimeout()
|
|||
}
|
||||
sendGameEvent(new Event_Ping(pingList));
|
||||
|
||||
const int maxTime = static_cast<Server *>(parent())->getMaxGameInactivityTime();
|
||||
const int maxTime = static_cast<Server_Room *>(parent())->getServer()->getMaxGameInactivityTime();
|
||||
if (allPlayersInactive) {
|
||||
if ((++inactivityCounter >= maxTime) && (maxTime > 0))
|
||||
deleteLater();
|
||||
|
@ -193,7 +194,7 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec
|
|||
players.insert(playerId, newPlayer);
|
||||
|
||||
if (broadcastUpdate)
|
||||
qobject_cast<Server *>(parent())->broadcastGameListUpdate(this);
|
||||
qobject_cast<Server_Room *>(parent())->broadcastGameListUpdate(this);
|
||||
|
||||
return newPlayer;
|
||||
}
|
||||
|
@ -231,7 +232,7 @@ void Server_Game::removePlayer(Server_Player *player)
|
|||
deleteLater();
|
||||
else if (!spectator)
|
||||
stopGameIfFinished();
|
||||
qobject_cast<Server *>(parent())->broadcastGameListUpdate(this);
|
||||
qobject_cast<Server_Room *>(parent())->broadcastGameListUpdate(this);
|
||||
}
|
||||
|
||||
void Server_Game::setActivePlayer(int _activePlayer)
|
||||
|
@ -391,3 +392,23 @@ void Server_Game::sendGameEventToPlayer(Server_Player *player, GameEvent *event)
|
|||
{
|
||||
player->sendProtocolItem(new GameEventContainer(QList<GameEvent *>() << event, gameId));
|
||||
}
|
||||
|
||||
ServerInfo_Game *Server_Game::getInfo() const
|
||||
{
|
||||
if (players.isEmpty())
|
||||
// Game is open
|
||||
return new ServerInfo_Game(getGameId(), QString(), false, 0, getMaxPlayers(), 0, false, 0);
|
||||
else
|
||||
// Game is closing
|
||||
return new ServerInfo_Game(
|
||||
getGameId(),
|
||||
getDescription(),
|
||||
!getPassword().isEmpty(),
|
||||
getPlayerCount(),
|
||||
getMaxPlayers(),
|
||||
new ServerInfo_User(getCreatorInfo()),
|
||||
getSpectatorsAllowed(),
|
||||
getSpectatorsNeedPassword(),
|
||||
getSpectatorCount()
|
||||
);
|
||||
}
|
|
@ -27,7 +27,7 @@
|
|||
#include "protocol.h"
|
||||
|
||||
class QTimer;
|
||||
class Server;
|
||||
class Server_Room;
|
||||
class ServerInfo_User;
|
||||
|
||||
class Server_Game : public QObject {
|
||||
|
@ -52,8 +52,9 @@ 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 *parent);
|
||||
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();
|
||||
ServerInfo_Game *getInfo() const;
|
||||
ServerInfo_User *getCreatorInfo() const { return creatorInfo; }
|
||||
bool getGameStarted() const { return gameStarted; }
|
||||
int getPlayerCount() const;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "server_protocolhandler.h"
|
||||
#include "protocol.h"
|
||||
#include "protocol_items.h"
|
||||
#include "server_chatchannel.h"
|
||||
#include "server_room.h"
|
||||
#include "server_card.h"
|
||||
#include "server_arrow.h"
|
||||
#include "server_cardzone.h"
|
||||
|
@ -14,7 +14,7 @@
|
|||
#include <QDateTime>
|
||||
|
||||
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent)
|
||||
: QObject(parent), server(_server), authState(PasswordWrong), acceptsGameListChanges(false), acceptsUserListChanges(false), acceptsChatChannelListChanges(false), userInfo(0), lastCommandTime(QDateTime::currentDateTime())
|
||||
: QObject(parent), server(_server), authState(PasswordWrong), acceptsUserListChanges(false), acceptsRoomListChanges(false), userInfo(0), lastCommandTime(QDateTime::currentDateTime())
|
||||
{
|
||||
connect(server, SIGNAL(pingClockTimeout()), this, SLOT(pingClockTimeout()));
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
|
|||
p->setProtocolHandler(0);
|
||||
}
|
||||
|
||||
QMapIterator<QString, Server_ChatChannel *> chatChannelIterator(chatChannels);
|
||||
while (chatChannelIterator.hasNext())
|
||||
chatChannelIterator.next().value()->removeClient(this);
|
||||
QMapIterator<int, Server_Room *> roomIterator(rooms);
|
||||
while (roomIterator.hasNext())
|
||||
roomIterator.next().value()->removeClient(this);
|
||||
|
||||
delete userInfo;
|
||||
}
|
||||
|
@ -54,20 +54,22 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
|
|||
{
|
||||
lastCommandTime = QDateTime::currentDateTime();
|
||||
|
||||
ChatCommand *chatCommand = qobject_cast<ChatCommand *>(command);
|
||||
RoomCommand *roomCommand = qobject_cast<RoomCommand *>(command);
|
||||
GameCommand *gameCommand = qobject_cast<GameCommand *>(command);
|
||||
if (chatCommand) {
|
||||
qDebug() << "received ChatCommand: channel =" << chatCommand->getChannel();
|
||||
if (roomCommand) {
|
||||
qDebug() << "received RoomCommand: roomId =" << roomCommand->getRoomId();
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
||||
Server_ChatChannel *channel = chatChannels.value(chatCommand->getChannel(), 0);
|
||||
if (!channel)
|
||||
Server_Room *room = rooms.value(roomCommand->getRoomId(), 0);
|
||||
if (!room)
|
||||
return RespNameNotFound;
|
||||
|
||||
switch (command->getItemId()) {
|
||||
case ItemId_Command_ChatLeaveChannel: return cmdChatLeaveChannel(qobject_cast<Command_ChatLeaveChannel *>(command), cont, channel);
|
||||
case ItemId_Command_ChatSay: return cmdChatSay(qobject_cast<Command_ChatSay *>(command), cont, channel);
|
||||
case ItemId_Command_LeaveRoom: return cmdLeaveRoom(qobject_cast<Command_LeaveRoom *>(command), cont, room);
|
||||
case ItemId_Command_RoomSay: return cmdRoomSay(qobject_cast<Command_RoomSay *>(command), cont, room);
|
||||
case ItemId_Command_CreateGame: return cmdCreateGame(qobject_cast<Command_CreateGame *>(command), cont, room);
|
||||
case ItemId_Command_JoinGame: return cmdJoinGame(qobject_cast<Command_JoinGame *>(command), cont, room);
|
||||
}
|
||||
} else if (gameCommand) {
|
||||
qDebug() << "received GameCommand: game =" << gameCommand->getGameId();
|
||||
|
@ -125,12 +127,9 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
|
|||
case ItemId_Command_DeckUpload: return cmdDeckUpload(qobject_cast<Command_DeckUpload *>(command), cont);
|
||||
case ItemId_Command_DeckDownload: return cmdDeckDownload(qobject_cast<Command_DeckDownload *>(command), cont);
|
||||
case ItemId_Command_GetUserInfo: return cmdGetUserInfo(qobject_cast<Command_GetUserInfo *>(command), cont);
|
||||
case ItemId_Command_ListChatChannels: return cmdListChatChannels(qobject_cast<Command_ListChatChannels *>(command), cont);
|
||||
case ItemId_Command_ChatJoinChannel: return cmdChatJoinChannel(qobject_cast<Command_ChatJoinChannel *>(command), cont);
|
||||
case ItemId_Command_ListRooms: return cmdListRooms(qobject_cast<Command_ListRooms *>(command), cont);
|
||||
case ItemId_Command_JoinRoom: return cmdJoinRoom(qobject_cast<Command_JoinRoom *>(command), cont);
|
||||
case ItemId_Command_ListUsers: return cmdListUsers(qobject_cast<Command_ListUsers *>(command), cont);
|
||||
case ItemId_Command_ListGames: return cmdListGames(qobject_cast<Command_ListGames *>(command), cont);
|
||||
case ItemId_Command_CreateGame: return cmdCreateGame(qobject_cast<Command_CreateGame *>(command), cont);
|
||||
case ItemId_Command_JoinGame: return cmdJoinGame(qobject_cast<Command_JoinGame *>(command), cont);
|
||||
}
|
||||
}
|
||||
return RespInvalidCommand;
|
||||
|
@ -273,51 +272,50 @@ ResponseCode Server_ProtocolHandler::cmdGetUserInfo(Command_GetUserInfo *cmd, Co
|
|||
return RespNothing;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdListChatChannels(Command_ListChatChannels * /*cmd*/, CommandContainer *cont)
|
||||
ResponseCode Server_ProtocolHandler::cmdListRooms(Command_ListRooms * /*cmd*/, CommandContainer *cont)
|
||||
{
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
||||
QList<ServerInfo_ChatChannel *> eventChannelList;
|
||||
QMapIterator<QString, Server_ChatChannel *> channelIterator(server->getChatChannels());
|
||||
while (channelIterator.hasNext()) {
|
||||
Server_ChatChannel *c = channelIterator.next().value();
|
||||
eventChannelList.append(new ServerInfo_ChatChannel(c->getName(), c->getDescription(), c->size(), c->getAutoJoin()));
|
||||
QList<ServerInfo_Room *> eventRoomList;
|
||||
QMapIterator<int, Server_Room *> roomIterator(server->getRooms());
|
||||
while (roomIterator.hasNext()) {
|
||||
Server_Room *r = roomIterator.next().value();
|
||||
eventRoomList.append(new ServerInfo_Room(r->getId(), r->getName(), r->getDescription(), r->getGames().size(), r->size(), r->getAutoJoin()));
|
||||
}
|
||||
cont->enqueueItem(new Event_ListChatChannels(eventChannelList));
|
||||
cont->enqueueItem(new Event_ListRooms(eventRoomList));
|
||||
|
||||
acceptsChatChannelListChanges = true;
|
||||
acceptsRoomListChanges = true;
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdChatJoinChannel(Command_ChatJoinChannel *cmd, CommandContainer *cont)
|
||||
ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandContainer *cont)
|
||||
{
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
||||
if (chatChannels.contains(cmd->getChannel()))
|
||||
if (rooms.contains(cmd->getRoomId()))
|
||||
return RespContextError;
|
||||
|
||||
QMap<QString, Server_ChatChannel *> allChannels = server->getChatChannels();
|
||||
Server_ChatChannel *c = allChannels.value(cmd->getChannel(), 0);
|
||||
if (!c)
|
||||
Server_Room *r = server->getRooms().value(cmd->getRoomId(), 0);
|
||||
if (!r)
|
||||
return RespNameNotFound;
|
||||
|
||||
c->addClient(this);
|
||||
chatChannels.insert(cmd->getChannel(), c);
|
||||
r->addClient(this);
|
||||
rooms.insert(r->getId(), r);
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdChatLeaveChannel(Command_ChatLeaveChannel * /*cmd*/, CommandContainer *cont, Server_ChatChannel *channel)
|
||||
ResponseCode Server_ProtocolHandler::cmdLeaveRoom(Command_LeaveRoom * /*cmd*/, CommandContainer *cont, Server_Room *room)
|
||||
{
|
||||
chatChannels.remove(channel->getName());
|
||||
channel->removeClient(this);
|
||||
rooms.remove(room->getId());
|
||||
room->removeClient(this);
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, CommandContainer *cont, Server_ChatChannel *channel)
|
||||
ResponseCode Server_ProtocolHandler::cmdRoomSay(Command_RoomSay *cmd, CommandContainer *cont, Server_Room *room)
|
||||
{
|
||||
channel->say(this, cmd->getMessage());
|
||||
room->say(this, cmd->getMessage());
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
|
@ -337,39 +335,12 @@ ResponseCode Server_ProtocolHandler::cmdListUsers(Command_ListUsers * /*cmd*/, C
|
|||
return RespNothing;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/, CommandContainer *cont)
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont, Server_Room *room)
|
||||
{
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
||||
const QList<Server_Game *> &gameList = server->getGames();
|
||||
QList<ServerInfo_Game *> eventGameList;
|
||||
for (int i = 0; i < gameList.size(); ++i) {
|
||||
Server_Game *g = gameList[i];
|
||||
eventGameList.append(new ServerInfo_Game(
|
||||
g->getGameId(),
|
||||
g->getDescription(),
|
||||
!g->getPassword().isEmpty(),
|
||||
g->getPlayerCount(),
|
||||
g->getMaxPlayers(),
|
||||
new ServerInfo_User(g->getCreatorInfo()),
|
||||
g->getSpectatorsAllowed(),
|
||||
g->getSpectatorsNeedPassword(),
|
||||
g->getSpectatorCount()
|
||||
));
|
||||
}
|
||||
cont->enqueueItem(new Event_ListGames(eventGameList));
|
||||
|
||||
acceptsGameListChanges = true;
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont)
|
||||
{
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
||||
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), cmd->getSpectatorsNeedPassword(), cmd->getSpectatorsCanTalk(), cmd->getSpectatorsSeeEverything(), this);
|
||||
Server_Game *game = room->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), 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));
|
||||
|
||||
|
@ -378,7 +349,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont)
|
||||
ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandContainer *cont, Server_Room *room)
|
||||
{
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
@ -386,7 +357,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandC
|
|||
if (games.contains(cmd->getGameId()))
|
||||
return RespContextError;
|
||||
|
||||
Server_Game *g = server->getGame(cmd->getGameId());
|
||||
Server_Game *g = room->getGames().value(cmd->getGameId());
|
||||
if (!g)
|
||||
return RespNameNotFound;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
class Server_Player;
|
||||
class Server_Card;
|
||||
class ServerInfo_User;
|
||||
class Server_Room;
|
||||
class QTimer;
|
||||
|
||||
class Server_ProtocolHandler : public QObject {
|
||||
|
@ -17,15 +18,14 @@ class Server_ProtocolHandler : public QObject {
|
|||
protected:
|
||||
Server *server;
|
||||
QMap<int, QPair<Server_Game *, Server_Player *> > games;
|
||||
QMap<QString, Server_ChatChannel *> chatChannels;
|
||||
QMap<int, Server_Room *> rooms;
|
||||
|
||||
Server *getServer() const { return server; }
|
||||
QPair<Server_Game *, Server_Player *> getGame(int gameId) const;
|
||||
|
||||
AuthenticationResult authState;
|
||||
bool acceptsGameListChanges;
|
||||
bool acceptsUserListChanges;
|
||||
bool acceptsChatChannelListChanges;
|
||||
bool acceptsRoomListChanges;
|
||||
ServerInfo_User *userInfo;
|
||||
|
||||
private:
|
||||
|
@ -45,14 +45,13 @@ private:
|
|||
virtual ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont) = 0;
|
||||
virtual ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont) = 0;
|
||||
ResponseCode cmdGetUserInfo(Command_GetUserInfo *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdListChatChannels(Command_ListChatChannels *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, CommandContainer *cont, Server_ChatChannel *channel);
|
||||
ResponseCode cmdChatSay(Command_ChatSay *cmd, CommandContainer *cont, Server_ChatChannel *channel);
|
||||
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 cmdListGames(Command_ListGames *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdCreateGame(Command_CreateGame *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdJoinGame(Command_JoinGame *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 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);
|
||||
|
@ -91,9 +90,8 @@ public:
|
|||
~Server_ProtocolHandler();
|
||||
void playerRemovedFromGame(Server_Game *game);
|
||||
|
||||
bool getAcceptsGameListChanges() const { return acceptsGameListChanges; }
|
||||
bool getAcceptsUserListChanges() const { return acceptsUserListChanges; }
|
||||
bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; }
|
||||
bool getAcceptsRoomListChanges() const { return acceptsRoomListChanges; }
|
||||
ServerInfo_User *getUserInfo() const { return userInfo; }
|
||||
void setUserInfo(ServerInfo_User *_userInfo) { userInfo = _userInfo; }
|
||||
const QDateTime &getLastCommandTime() const { return lastCommandTime; }
|
||||
|
|
76
common/server_room.cpp
Normal file
76
common/server_room.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include "server_room.h"
|
||||
#include "server_protocolhandler.h"
|
||||
#include "server_game.h"
|
||||
|
||||
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 *Server_Room::getServer() const
|
||||
{
|
||||
return static_cast<Server *>(parent());
|
||||
}
|
||||
|
||||
QList<ServerInfo_User *> Server_Room::addClient(Server_ProtocolHandler *client)
|
||||
{
|
||||
sendRoomEvent(new Event_JoinRoom(id, new ServerInfo_User(client->getUserInfo())));
|
||||
append(client);
|
||||
|
||||
QList<ServerInfo_User *> eventUserList;
|
||||
for (int i = 0; i < size(); ++i)
|
||||
eventUserList.append(new ServerInfo_User(at(i)->getUserInfo()));
|
||||
|
||||
emit roomInfoChanged();
|
||||
return eventUserList;
|
||||
}
|
||||
|
||||
void Server_Room::removeClient(Server_ProtocolHandler *client)
|
||||
{
|
||||
removeAt(indexOf(client));
|
||||
sendRoomEvent(new Event_LeaveRoom(id, client->getUserInfo()->getName()));
|
||||
emit roomInfoChanged();
|
||||
}
|
||||
|
||||
void Server_Room::say(Server_ProtocolHandler *client, const QString &s)
|
||||
{
|
||||
sendRoomEvent(new Event_RoomSay(id, client->getUserInfo()->getName(), s));
|
||||
}
|
||||
|
||||
void Server_Room::sendRoomEvent(RoomEvent *event)
|
||||
{
|
||||
for (int i = 0; i < size(); ++i)
|
||||
at(i)->sendProtocolItem(event, false);
|
||||
delete event;
|
||||
}
|
||||
|
||||
void Server_Room::broadcastGameListUpdate(Server_Game *game)
|
||||
{
|
||||
Event_ListGames *event = new Event_ListGames(id, QList<ServerInfo_Game *>() << game->getInfo());
|
||||
|
||||
for (int i = 0; i < size(); i++)
|
||||
at(i)->sendProtocolItem(event, false);
|
||||
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 *newGame = new Server_Game(creator, static_cast<Server *>(parent())->getNextGameId(), description, password, maxPlayers, spectatorsAllowed, spectatorsNeedPassword, spectatorsCanTalk, spectatorsSeeEverything, this);
|
||||
games.insert(newGame->getGameId(), newGame);
|
||||
connect(newGame, SIGNAL(gameClosing()), this, SLOT(removeGame()));
|
||||
|
||||
broadcastGameListUpdate(newGame);
|
||||
|
||||
emit gameCreated(newGame);
|
||||
|
||||
return newGame;
|
||||
}
|
||||
|
||||
void Server_Room::removeGame()
|
||||
{
|
||||
Server_Game *game = static_cast<Server_Game *>(sender());
|
||||
broadcastGameListUpdate(game);
|
||||
games.remove(game->getGameId());
|
||||
|
||||
emit gameClosing(game->getGameId());
|
||||
}
|
48
common/server_room.h
Normal file
48
common/server_room.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef SERVER_ROOM_H
|
||||
#define SERVER_ROOM_H
|
||||
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
class Server_ProtocolHandler;
|
||||
class RoomEvent;
|
||||
class ServerInfo_User;
|
||||
class Server_Game;
|
||||
class Server;
|
||||
|
||||
class Server_Room : public QObject, public QList<Server_ProtocolHandler *> {
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void roomInfoChanged();
|
||||
void gameCreated(Server_Game *game);
|
||||
void gameClosing(int gameId);
|
||||
private:
|
||||
int id;
|
||||
QString name;
|
||||
QString description;
|
||||
bool autoJoin;
|
||||
QString joinMessage;
|
||||
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);
|
||||
int getId() const { return id; }
|
||||
QString getName() const { return name; }
|
||||
QString getDescription() const { return description; }
|
||||
bool getAutoJoin() const { return autoJoin; }
|
||||
const QMap<int, Server_Game *> &getGames() const { return games; }
|
||||
Server *getServer() const;
|
||||
|
||||
QList<ServerInfo_User *> addClient(Server_ProtocolHandler *client);
|
||||
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);
|
||||
|
||||
void sendRoomEvent(RoomEvent *event);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -27,7 +27,7 @@ HEADERS += src/servatrice.h \
|
|||
../common/server_arrow.h \
|
||||
../common/server_card.h \
|
||||
../common/server_cardzone.h \
|
||||
../common/server_chatchannel.h \
|
||||
../common/server_room.h \
|
||||
../common/server_counter.h \
|
||||
../common/server_game.h \
|
||||
../common/server_player.h \
|
||||
|
@ -48,7 +48,7 @@ SOURCES += src/main.cpp \
|
|||
../common/server.cpp \
|
||||
../common/server_card.cpp \
|
||||
../common/server_cardzone.cpp \
|
||||
../common/server_chatchannel.cpp \
|
||||
../common/server_room.cpp \
|
||||
../common/server_game.cpp \
|
||||
../common/server_player.cpp \
|
||||
../common/server_protocolhandler.cpp
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <QDebug>
|
||||
#include <iostream>
|
||||
#include "servatrice.h"
|
||||
#include "server_chatchannel.h"
|
||||
#include "server_room.h"
|
||||
#include "serversocketinterface.h"
|
||||
#include "protocol.h"
|
||||
|
||||
|
@ -49,16 +49,18 @@ Servatrice::Servatrice(QObject *parent)
|
|||
if (dbType == "mysql")
|
||||
openDatabase();
|
||||
|
||||
int size = settings->beginReadArray("chatchannels");
|
||||
int size = settings->beginReadArray("rooms");
|
||||
for (int i = 0; i < size; ++i) {
|
||||
settings->setArrayIndex(i);
|
||||
Server_ChatChannel *newChannel = new Server_ChatChannel(
|
||||
Server_Room *newRoom = new Server_Room(
|
||||
i,
|
||||
settings->value("name").toString(),
|
||||
settings->value("description").toString(),
|
||||
settings->value("autojoin").toBool(),
|
||||
settings->value("joinmessage").toString()
|
||||
settings->value("joinmessage").toString(),
|
||||
this
|
||||
);
|
||||
addChatChannel(newChannel);
|
||||
addRoom(newRoom);
|
||||
}
|
||||
settings->endArray();
|
||||
|
||||
|
|
Loading…
Reference in a new issue