mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
implemented direct chat
This commit is contained in:
parent
a8e166b609
commit
e597325ec3
24 changed files with 821 additions and 335 deletions
|
|
@ -37,12 +37,14 @@ void ProtocolItem::initializeHash()
|
|||
|
||||
registerSerializableItem("resp", ProtocolResponse::newItem);
|
||||
ProtocolResponse::initializeHash();
|
||||
registerSerializableItem("resplist_users", Response_ListUsers::newItem);
|
||||
registerSerializableItem("respdeck_list", Response_DeckList::newItem);
|
||||
registerSerializableItem("respdeck_download", Response_DeckDownload::newItem);
|
||||
registerSerializableItem("respdeck_upload", Response_DeckUpload::newItem);
|
||||
registerSerializableItem("respdump_zone", Response_DumpZone::newItem);
|
||||
|
||||
registerSerializableItem("generic_eventlist_games", Event_ListGames::newItem);
|
||||
registerSerializableItem("generic_eventuser_joined", Event_UserJoined::newItem);
|
||||
registerSerializableItem("generic_eventlist_chat_channels", Event_ListChatChannels::newItem);
|
||||
registerSerializableItem("game_eventjoin", Event_Join::newItem);
|
||||
registerSerializableItem("game_eventgame_state_changed", Event_GameStateChanged::newItem);
|
||||
|
|
@ -215,6 +217,13 @@ void ProtocolResponse::initializeHash()
|
|||
responseHash.insert("spectators_not_allowed", RespSpectatorsNotAllowed);
|
||||
}
|
||||
|
||||
Response_ListUsers::Response_ListUsers(int _cmdId, ResponseCode _responseCode, const QList<ServerInfo_User *> &_userList)
|
||||
: ProtocolResponse(_cmdId, _responseCode, "list_users")
|
||||
{
|
||||
for (int i = 0; i < _userList.size(); ++i)
|
||||
itemList.append(_userList[i]);
|
||||
}
|
||||
|
||||
Response_DeckList::Response_DeckList(int _cmdId, ResponseCode _responseCode, DeckList_Directory *_root)
|
||||
: ProtocolResponse(_cmdId, _responseCode, "deck_list")
|
||||
{
|
||||
|
|
@ -298,6 +307,14 @@ Event_ListGames::Event_ListGames(const QList<ServerInfo_Game *> &_gameList)
|
|||
itemList.append(_gameList[i]);
|
||||
}
|
||||
|
||||
Event_UserJoined::Event_UserJoined(ServerInfo_User *_userInfo)
|
||||
: GenericEvent("user_joined")
|
||||
{
|
||||
if (!_userInfo)
|
||||
_userInfo = new ServerInfo_User;
|
||||
insertItem(_userInfo);
|
||||
}
|
||||
|
||||
Event_Join::Event_Join(ServerInfo_PlayerProperties *player)
|
||||
: GameEvent("join", -1)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,17 +29,19 @@ enum ItemId {
|
|||
ItemId_Event_ChatListPlayers = ItemId_Other + 201,
|
||||
ItemId_Event_ChatJoinChannel = ItemId_Other + 202,
|
||||
ItemId_Event_ListGames = ItemId_Other + 203,
|
||||
ItemId_Event_GameStateChanged = ItemId_Other + 204,
|
||||
ItemId_Event_PlayerPropertiesChanged = ItemId_Other + 205,
|
||||
ItemId_Event_CreateArrows = ItemId_Other + 206,
|
||||
ItemId_Event_CreateCounters = ItemId_Other + 207,
|
||||
ItemId_Event_DrawCards = ItemId_Other + 208,
|
||||
ItemId_Event_Join = ItemId_Other + 209,
|
||||
ItemId_Event_Ping = ItemId_Other + 210,
|
||||
ItemId_Response_DeckList = ItemId_Other + 300,
|
||||
ItemId_Response_DeckDownload = ItemId_Other + 301,
|
||||
ItemId_Response_DeckUpload = ItemId_Other + 302,
|
||||
ItemId_Response_DumpZone = ItemId_Other + 303,
|
||||
ItemId_Event_UserJoined = ItemId_Other + 204,
|
||||
ItemId_Event_GameStateChanged = ItemId_Other + 205,
|
||||
ItemId_Event_PlayerPropertiesChanged = ItemId_Other + 206,
|
||||
ItemId_Event_CreateArrows = ItemId_Other + 207,
|
||||
ItemId_Event_CreateCounters = ItemId_Other + 208,
|
||||
ItemId_Event_DrawCards = ItemId_Other + 209,
|
||||
ItemId_Event_Join = ItemId_Other + 210,
|
||||
ItemId_Event_Ping = ItemId_Other + 211,
|
||||
ItemId_Response_ListUsers = ItemId_Other + 300,
|
||||
ItemId_Response_DeckList = ItemId_Other + 301,
|
||||
ItemId_Response_DeckDownload = ItemId_Other + 302,
|
||||
ItemId_Response_DeckUpload = ItemId_Other + 303,
|
||||
ItemId_Response_DumpZone = ItemId_Other + 304,
|
||||
ItemId_Invalid = ItemId_Other + 1000
|
||||
};
|
||||
|
||||
|
|
@ -199,6 +201,15 @@ public:
|
|||
ResponseCode getResponseCode() const { return responseHash.value(static_cast<SerializableItem_String *>(itemMap.value("response_code"))->getData(), RespOk); }
|
||||
};
|
||||
|
||||
class Response_ListUsers : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Response_ListUsers(int _cmdId = -1, ResponseCode _responseCode = RespOk, const QList<ServerInfo_User *> &_userList = QList<ServerInfo_User *>());
|
||||
int getItemId() const { return ItemId_Response_ListUsers; }
|
||||
static SerializableItem *newItem() { return new Response_ListUsers; }
|
||||
QList<ServerInfo_User *> getUserList() const { return typecastItemList<ServerInfo_User *>(); }
|
||||
};
|
||||
|
||||
class Response_DeckList : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
@ -323,6 +334,15 @@ public:
|
|||
QList<ServerInfo_Game *> getGameList() const { return typecastItemList<ServerInfo_Game *>(); }
|
||||
};
|
||||
|
||||
class Event_UserJoined : public GenericEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_UserJoined(ServerInfo_User *_userInfo = 0);
|
||||
int getItemId() const { return ItemId_Event_UserJoined; }
|
||||
static SerializableItem *newItem() { return new Event_UserJoined; }
|
||||
ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
|
||||
};
|
||||
|
||||
class Event_Join : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -1,68 +1,72 @@
|
|||
enum AutoItemId {
|
||||
ItemId_Command_Ping = 1001,
|
||||
ItemId_Command_Login = 1002,
|
||||
ItemId_Command_DeckList = 1003,
|
||||
ItemId_Command_DeckNewDir = 1004,
|
||||
ItemId_Command_DeckDelDir = 1005,
|
||||
ItemId_Command_DeckDel = 1006,
|
||||
ItemId_Command_DeckDownload = 1007,
|
||||
ItemId_Command_ListChatChannels = 1008,
|
||||
ItemId_Command_ChatJoinChannel = 1009,
|
||||
ItemId_Command_ChatLeaveChannel = 1010,
|
||||
ItemId_Command_ChatSay = 1011,
|
||||
ItemId_Command_ListGames = 1012,
|
||||
ItemId_Command_CreateGame = 1013,
|
||||
ItemId_Command_JoinGame = 1014,
|
||||
ItemId_Command_LeaveGame = 1015,
|
||||
ItemId_Command_Say = 1016,
|
||||
ItemId_Command_Shuffle = 1017,
|
||||
ItemId_Command_Mulligan = 1018,
|
||||
ItemId_Command_RollDie = 1019,
|
||||
ItemId_Command_DrawCards = 1020,
|
||||
ItemId_Command_MoveCard = 1021,
|
||||
ItemId_Command_FlipCard = 1022,
|
||||
ItemId_Command_AttachCard = 1023,
|
||||
ItemId_Command_CreateToken = 1024,
|
||||
ItemId_Command_CreateArrow = 1025,
|
||||
ItemId_Command_DeleteArrow = 1026,
|
||||
ItemId_Command_SetCardAttr = 1027,
|
||||
ItemId_Command_SetCardCounter = 1028,
|
||||
ItemId_Command_IncCardCounter = 1029,
|
||||
ItemId_Command_ReadyStart = 1030,
|
||||
ItemId_Command_Concede = 1031,
|
||||
ItemId_Command_IncCounter = 1032,
|
||||
ItemId_Command_CreateCounter = 1033,
|
||||
ItemId_Command_SetCounter = 1034,
|
||||
ItemId_Command_DelCounter = 1035,
|
||||
ItemId_Command_NextTurn = 1036,
|
||||
ItemId_Command_SetActivePhase = 1037,
|
||||
ItemId_Command_DumpZone = 1038,
|
||||
ItemId_Command_StopDumpZone = 1039,
|
||||
ItemId_Event_Say = 1040,
|
||||
ItemId_Event_Leave = 1041,
|
||||
ItemId_Event_GameClosed = 1042,
|
||||
ItemId_Event_Shuffle = 1043,
|
||||
ItemId_Event_RollDie = 1044,
|
||||
ItemId_Event_MoveCard = 1045,
|
||||
ItemId_Event_FlipCard = 1046,
|
||||
ItemId_Event_DestroyCard = 1047,
|
||||
ItemId_Event_AttachCard = 1048,
|
||||
ItemId_Event_CreateToken = 1049,
|
||||
ItemId_Event_DeleteArrow = 1050,
|
||||
ItemId_Event_SetCardAttr = 1051,
|
||||
ItemId_Event_SetCardCounter = 1052,
|
||||
ItemId_Event_SetCounter = 1053,
|
||||
ItemId_Event_DelCounter = 1054,
|
||||
ItemId_Event_SetActivePlayer = 1055,
|
||||
ItemId_Event_SetActivePhase = 1056,
|
||||
ItemId_Event_DumpZone = 1057,
|
||||
ItemId_Event_StopDumpZone = 1058,
|
||||
ItemId_Event_ServerMessage = 1059,
|
||||
ItemId_Event_GameJoined = 1060,
|
||||
ItemId_Event_ChatLeaveChannel = 1061,
|
||||
ItemId_Event_ChatSay = 1062,
|
||||
ItemId_Context_ReadyStart = 1063,
|
||||
ItemId_Context_Concede = 1064,
|
||||
ItemId_Context_DeckSelect = 1065,
|
||||
ItemId_Other = 1066
|
||||
ItemId_Command_Message = 1003,
|
||||
ItemId_Command_DeckList = 1004,
|
||||
ItemId_Command_DeckNewDir = 1005,
|
||||
ItemId_Command_DeckDelDir = 1006,
|
||||
ItemId_Command_DeckDel = 1007,
|
||||
ItemId_Command_DeckDownload = 1008,
|
||||
ItemId_Command_ListChatChannels = 1009,
|
||||
ItemId_Command_ChatJoinChannel = 1010,
|
||||
ItemId_Command_ChatLeaveChannel = 1011,
|
||||
ItemId_Command_ChatSay = 1012,
|
||||
ItemId_Command_ListGames = 1013,
|
||||
ItemId_Command_ListUsers = 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_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_ChatLeaveChannel = 1065,
|
||||
ItemId_Event_ChatSay = 1066,
|
||||
ItemId_Context_ReadyStart = 1067,
|
||||
ItemId_Context_Concede = 1068,
|
||||
ItemId_Context_DeckSelect = 1069,
|
||||
ItemId_Other = 1070
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@ Command_Login::Command_Login(const QString &_username, const QString &_password)
|
|||
insertItem(new SerializableItem_String("username", _username));
|
||||
insertItem(new SerializableItem_String("password", _password));
|
||||
}
|
||||
Command_Message::Command_Message(const QString &_userName, const QString &_text)
|
||||
: Command("message")
|
||||
{
|
||||
insertItem(new SerializableItem_String("user_name", _userName));
|
||||
insertItem(new SerializableItem_String("text", _text));
|
||||
}
|
||||
Command_DeckList::Command_DeckList()
|
||||
: Command("deck_list")
|
||||
{
|
||||
|
|
@ -58,6 +64,10 @@ 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")
|
||||
{
|
||||
|
|
@ -370,6 +380,13 @@ Event_ServerMessage::Event_ServerMessage(const QString &_message)
|
|||
{
|
||||
insertItem(new SerializableItem_String("message", _message));
|
||||
}
|
||||
Event_Message::Event_Message(const QString &_senderName, const QString &_receiverName, const QString &_text)
|
||||
: GenericEvent("message")
|
||||
{
|
||||
insertItem(new SerializableItem_String("sender_name", _senderName));
|
||||
insertItem(new SerializableItem_String("receiver_name", _receiverName));
|
||||
insertItem(new SerializableItem_String("text", _text));
|
||||
}
|
||||
Event_GameJoined::Event_GameJoined(int _gameId, const QString &_gameDescription, int _playerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming)
|
||||
: GenericEvent("game_joined")
|
||||
{
|
||||
|
|
@ -381,6 +398,11 @@ Event_GameJoined::Event_GameJoined(int _gameId, const QString &_gameDescription,
|
|||
insertItem(new SerializableItem_Bool("spectators_see_everything", _spectatorsSeeEverything));
|
||||
insertItem(new SerializableItem_Bool("resuming", _resuming));
|
||||
}
|
||||
Event_UserLeft::Event_UserLeft(const QString &_userName)
|
||||
: GenericEvent("user_left")
|
||||
{
|
||||
insertItem(new SerializableItem_String("user_name", _userName));
|
||||
}
|
||||
Event_ChatLeaveChannel::Event_ChatLeaveChannel(const QString &_channel, const QString &_playerName)
|
||||
: ChatEvent("chat_leave_channel", _channel)
|
||||
{
|
||||
|
|
@ -409,6 +431,7 @@ void ProtocolItem::initializeHashAuto()
|
|||
{
|
||||
itemNameHash.insert("cmdping", Command_Ping::newItem);
|
||||
itemNameHash.insert("cmdlogin", Command_Login::newItem);
|
||||
itemNameHash.insert("cmdmessage", Command_Message::newItem);
|
||||
itemNameHash.insert("cmddeck_list", Command_DeckList::newItem);
|
||||
itemNameHash.insert("cmddeck_new_dir", Command_DeckNewDir::newItem);
|
||||
itemNameHash.insert("cmddeck_del_dir", Command_DeckDelDir::newItem);
|
||||
|
|
@ -419,6 +442,7 @@ void ProtocolItem::initializeHashAuto()
|
|||
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("cmdcreate_game", Command_CreateGame::newItem);
|
||||
itemNameHash.insert("cmdjoin_game", Command_JoinGame::newItem);
|
||||
itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem);
|
||||
|
|
@ -466,7 +490,9 @@ void ProtocolItem::initializeHashAuto()
|
|||
itemNameHash.insert("game_eventdump_zone", Event_DumpZone::newItem);
|
||||
itemNameHash.insert("game_eventstop_dump_zone", Event_StopDumpZone::newItem);
|
||||
itemNameHash.insert("generic_eventserver_message", Event_ServerMessage::newItem);
|
||||
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("game_event_contextready_start", Context_ReadyStart::newItem);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
0:ping
|
||||
0:login:s,username:s,password
|
||||
0:message:s,user_name:s,text
|
||||
0:deck_list
|
||||
0:deck_new_dir:s,path:s,dir_name
|
||||
0:deck_del_dir:s,path
|
||||
|
|
@ -10,6 +11,7 @@
|
|||
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
|
||||
2:leave_game
|
||||
|
|
@ -57,7 +59,9 @@
|
|||
3:dump_zone:i,zone_owner_id:s,zone:i,number_cards
|
||||
3:stop_dump_zone:i,zone_owner_id:s,zone
|
||||
4:server_message:s,message
|
||||
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
|
||||
6:ready_start
|
||||
|
|
|
|||
|
|
@ -19,6 +19,15 @@ public:
|
|||
static SerializableItem *newItem() { return new Command_Login; }
|
||||
int getItemId() const { return ItemId_Command_Login; }
|
||||
};
|
||||
class Command_Message : public Command {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_Message(const QString &_userName = QString(), const QString &_text = QString());
|
||||
QString getUserName() const { return static_cast<SerializableItem_String *>(itemMap.value("user_name"))->getData(); };
|
||||
QString getText() const { return static_cast<SerializableItem_String *>(itemMap.value("text"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Command_Message; }
|
||||
int getItemId() const { return ItemId_Command_Message; }
|
||||
};
|
||||
class Command_DeckList : public Command {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
@ -96,6 +105,13 @@ public:
|
|||
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:
|
||||
|
|
@ -549,6 +565,16 @@ public:
|
|||
static SerializableItem *newItem() { return new Event_ServerMessage; }
|
||||
int getItemId() const { return ItemId_Event_ServerMessage; }
|
||||
};
|
||||
class Event_Message : public GenericEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_Message(const QString &_senderName = QString(), const QString &_receiverName = QString(), const QString &_text = QString());
|
||||
QString getSenderName() const { return static_cast<SerializableItem_String *>(itemMap.value("sender_name"))->getData(); };
|
||||
QString getReceiverName() const { return static_cast<SerializableItem_String *>(itemMap.value("receiver_name"))->getData(); };
|
||||
QString getText() const { return static_cast<SerializableItem_String *>(itemMap.value("text"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_Message; }
|
||||
int getItemId() const { return ItemId_Event_Message; }
|
||||
};
|
||||
class Event_GameJoined : public GenericEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
@ -563,6 +589,14 @@ public:
|
|||
static SerializableItem *newItem() { return new Event_GameJoined; }
|
||||
int getItemId() const { return ItemId_Event_GameJoined; }
|
||||
};
|
||||
class Event_UserLeft : public GenericEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_UserLeft(const QString &_userName = QString());
|
||||
QString getUserName() const { return static_cast<SerializableItem_String *>(itemMap.value("user_name"))->getData(); };
|
||||
static SerializableItem *newItem() { return new Event_UserLeft; }
|
||||
int getItemId() const { return ItemId_Event_UserLeft; }
|
||||
};
|
||||
class Event_ChatLeaveChannel : public ChatEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -62,6 +62,12 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
|||
|
||||
users.insert(name, session);
|
||||
|
||||
Event_UserJoined *event = new Event_UserJoined(new ServerInfo_User(data));
|
||||
for (int i = 0; i < clients.size(); ++i)
|
||||
if (clients[i]->getAcceptsUserListChanges())
|
||||
clients[i]->sendProtocolItem(event, false);
|
||||
delete event;
|
||||
|
||||
return authState;
|
||||
}
|
||||
|
||||
|
|
@ -85,8 +91,15 @@ void Server::removeClient(Server_ProtocolHandler *client)
|
|||
{
|
||||
clients.removeAt(clients.indexOf(client));
|
||||
ServerInfo_User *data = client->getUserInfo();
|
||||
if (data)
|
||||
if (data) {
|
||||
Event_UserLeft *event = new Event_UserLeft(data->getName());
|
||||
for (int i = 0; i < clients.size(); ++i)
|
||||
if (clients[i]->getAcceptsUserListChanges())
|
||||
clients[i]->sendProtocolItem(event, false);
|
||||
delete event;
|
||||
|
||||
users.remove(data->getName());
|
||||
}
|
||||
qDebug() << "Server::removeClient: " << clients.size() << "clients; " << users.size() << "users left";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public:
|
|||
const QMap<QString, Server_ChatChannel *> &getChatChannels() { return chatChannels; }
|
||||
void broadcastGameListUpdate(Server_Game *game);
|
||||
|
||||
const QMap<QString, Server_ProtocolHandler *> &getUsers() const { return users; }
|
||||
void addClient(Server_ProtocolHandler *player);
|
||||
void removeClient(Server_ProtocolHandler *player);
|
||||
virtual QString getLoginMessage() const = 0;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include <QDateTime>
|
||||
|
||||
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent)
|
||||
: QObject(parent), server(_server), authState(PasswordWrong), acceptsGameListChanges(false), userInfo(0), lastCommandTime(QDateTime::currentDateTime())
|
||||
: QObject(parent), server(_server), authState(PasswordWrong), acceptsGameListChanges(false), acceptsUserListChanges(false), acceptsChatChannelListChanges(false), userInfo(0), lastCommandTime(QDateTime::currentDateTime())
|
||||
{
|
||||
connect(server, SIGNAL(pingClockTimeout()), this, SLOT(pingClockTimeout()));
|
||||
}
|
||||
|
|
@ -116,6 +116,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
|
|||
switch (command->getItemId()) {
|
||||
case ItemId_Command_Ping: return cmdPing(qobject_cast<Command_Ping *>(command), cont);
|
||||
case ItemId_Command_Login: return cmdLogin(qobject_cast<Command_Login *>(command), cont);
|
||||
case ItemId_Command_Message: return cmdMessage(qobject_cast<Command_Message *>(command), cont);
|
||||
case ItemId_Command_DeckList: return cmdDeckList(qobject_cast<Command_DeckList *>(command), cont);
|
||||
case ItemId_Command_DeckNewDir: return cmdDeckNewDir(qobject_cast<Command_DeckNewDir *>(command), cont);
|
||||
case ItemId_Command_DeckDelDir: return cmdDeckDelDir(qobject_cast<Command_DeckDelDir *>(command), cont);
|
||||
|
|
@ -124,6 +125,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
|
|||
case ItemId_Command_DeckDownload: return cmdDeckDownload(qobject_cast<Command_DeckDownload *>(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_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);
|
||||
|
|
@ -229,6 +231,21 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdMessage(Command_Message *cmd, CommandContainer *cont)
|
||||
{
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
||||
QString receiver = cmd->getUserName();
|
||||
Server_ProtocolHandler *userHandler = server->getUsers().value(receiver);
|
||||
if (!userHandler)
|
||||
return RespNameNotFound;
|
||||
|
||||
cont->enqueueItem(new Event_Message(userInfo->getName(), receiver, cmd->getText()));
|
||||
userHandler->sendProtocolItem(new Event_Message(userInfo->getName(), receiver, cmd->getText()));
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdListChatChannels(Command_ListChatChannels * /*cmd*/, CommandContainer *cont)
|
||||
{
|
||||
if (authState == PasswordWrong)
|
||||
|
|
@ -277,6 +294,22 @@ ResponseCode Server_ProtocolHandler::cmdChatSay(Command_ChatSay *cmd, CommandCon
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdListUsers(Command_ListUsers * /*cmd*/, CommandContainer *cont)
|
||||
{
|
||||
if (authState == PasswordWrong)
|
||||
return RespLoginNeeded;
|
||||
|
||||
QList<ServerInfo_User *> resultList;
|
||||
QMapIterator<QString, Server_ProtocolHandler *> userIterator = server->getUsers();
|
||||
while (userIterator.hasNext())
|
||||
resultList.append(new ServerInfo_User(userIterator.next().value()->getUserInfo()));
|
||||
|
||||
acceptsUserListChanges = true;
|
||||
|
||||
cont->setResponse(new Response_ListUsers(cont->getCmdId(), RespOk, resultList));
|
||||
return RespNothing;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/, CommandContainer *cont)
|
||||
{
|
||||
if (authState == PasswordWrong)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ protected:
|
|||
|
||||
AuthenticationResult authState;
|
||||
bool acceptsGameListChanges;
|
||||
bool acceptsUserListChanges;
|
||||
bool acceptsChatChannelListChanges;
|
||||
ServerInfo_User *userInfo;
|
||||
|
||||
|
|
@ -36,6 +37,7 @@ private:
|
|||
|
||||
ResponseCode cmdPing(Command_Ping *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdLogin(Command_Login *cmd, CommandContainer *cont);
|
||||
ResponseCode cmdMessage(Command_Message *cmd, CommandContainer *cont);
|
||||
virtual ResponseCode cmdDeckList(Command_DeckList *cmd, CommandContainer *cont) = 0;
|
||||
virtual ResponseCode cmdDeckNewDir(Command_DeckNewDir *cmd, CommandContainer *cont) = 0;
|
||||
virtual ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd, CommandContainer *cont) = 0;
|
||||
|
|
@ -46,6 +48,7 @@ private:
|
|||
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 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);
|
||||
|
|
@ -91,6 +94,7 @@ public:
|
|||
void playerRemovedFromGame(Server_Game *game);
|
||||
|
||||
bool getAcceptsGameListChanges() const { return acceptsGameListChanges; }
|
||||
bool getAcceptsUserListChanges() const { return acceptsUserListChanges; }
|
||||
bool getAcceptsChatChannelListChanges() const { return acceptsChatChannelListChanges; }
|
||||
ServerInfo_User *getUserInfo() const { return userInfo; }
|
||||
void setUserInfo(ServerInfo_User *_userInfo) { userInfo = _userInfo; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue