Merge branch 'master' of ssh://129.217.164.162/home/brukie/cockatrice
This commit is contained in:
commit
d5de76ec4a
15 changed files with 183 additions and 91 deletions
|
@ -219,6 +219,7 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
||||||
aUserName->setEnabled(false);
|
aUserName->setEnabled(false);
|
||||||
QAction *aDetails = new QAction(tr("User &details"), this);
|
QAction *aDetails = new QAction(tr("User &details"), this);
|
||||||
QAction *aChat = new QAction(tr("Direct &chat"), this);
|
QAction *aChat = new QAction(tr("Direct &chat"), this);
|
||||||
|
QAction *aShowGames = new QAction(tr("Show this user's &games"), this);
|
||||||
QAction *aAddToBuddyList = new QAction(tr("Add to &buddy list"), this);
|
QAction *aAddToBuddyList = new QAction(tr("Add to &buddy list"), this);
|
||||||
QAction *aRemoveFromBuddyList = new QAction(tr("Remove from &buddy list"), this);
|
QAction *aRemoveFromBuddyList = new QAction(tr("Remove from &buddy list"), this);
|
||||||
QAction *aAddToIgnoreList = new QAction(tr("Add to &ignore list"), this);
|
QAction *aAddToIgnoreList = new QAction(tr("Add to &ignore list"), this);
|
||||||
|
@ -257,7 +258,11 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
||||||
client->sendCommand(new Command_AddToList("buddy", userName));
|
client->sendCommand(new Command_AddToList("buddy", userName));
|
||||||
else if (actionClicked == aRemoveFromBuddyList)
|
else if (actionClicked == aRemoveFromBuddyList)
|
||||||
client->sendCommand(new Command_RemoveFromList("buddy", userName));
|
client->sendCommand(new Command_RemoveFromList("buddy", userName));
|
||||||
else if (actionClicked == aAddToIgnoreList)
|
else if (actionClicked == aShowGames) {
|
||||||
|
Command *cmd = new Command_GetGamesOfUser(userName);
|
||||||
|
connect(cmd, SIGNAL(responseReceived(ProtocolResponse *)), this, SLOT(gamesOfUserReceived(ProtocolResponse *)));
|
||||||
|
client->sendCommand(cmd);
|
||||||
|
} else if (actionClicked == aAddToIgnoreList)
|
||||||
client->sendCommand(new Command_AddToList("ignore", userName));
|
client->sendCommand(new Command_AddToList("ignore", userName));
|
||||||
else if (actionClicked == aRemoveFromIgnoreList)
|
else if (actionClicked == aRemoveFromIgnoreList)
|
||||||
client->sendCommand(new Command_RemoveFromList("ignore", userName));
|
client->sendCommand(new Command_RemoveFromList("ignore", userName));
|
||||||
|
|
|
@ -44,6 +44,7 @@ void ProtocolItem::initializeHash()
|
||||||
ProtocolResponse::initializeHash();
|
ProtocolResponse::initializeHash();
|
||||||
registerSerializableItem("respjoin_room", Response_JoinRoom::newItem);
|
registerSerializableItem("respjoin_room", Response_JoinRoom::newItem);
|
||||||
registerSerializableItem("resplist_users", Response_ListUsers::newItem);
|
registerSerializableItem("resplist_users", Response_ListUsers::newItem);
|
||||||
|
registerSerializableItem("respget_games_of_user", Response_GetGamesOfUser::newItem);
|
||||||
registerSerializableItem("respget_user_info", Response_GetUserInfo::newItem);
|
registerSerializableItem("respget_user_info", Response_GetUserInfo::newItem);
|
||||||
registerSerializableItem("respdeck_list", Response_DeckList::newItem);
|
registerSerializableItem("respdeck_list", Response_DeckList::newItem);
|
||||||
registerSerializableItem("respdeck_download", Response_DeckDownload::newItem);
|
registerSerializableItem("respdeck_download", Response_DeckDownload::newItem);
|
||||||
|
@ -296,6 +297,12 @@ Response_DeckList::Response_DeckList(int _cmdId, ResponseCode _responseCode, Dec
|
||||||
insertItem(_root);
|
insertItem(_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Response_GetGamesOfUser::Response_GetGamesOfUser(int _cmdId, ResponseCode _responseCode, const QList<ServerInfo_Game *> &_gameList)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _gameList.size(); ++i)
|
||||||
|
itemList.append(_gameList[i]);
|
||||||
|
}
|
||||||
|
|
||||||
Response_GetUserInfo::Response_GetUserInfo(int _cmdId, ResponseCode _responseCode, ServerInfo_User *_user)
|
Response_GetUserInfo::Response_GetUserInfo(int _cmdId, ResponseCode _responseCode, ServerInfo_User *_user)
|
||||||
: ProtocolResponse(_cmdId, _responseCode, "get_user_info")
|
: ProtocolResponse(_cmdId, _responseCode, "get_user_info")
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,13 +42,14 @@ enum ItemId {
|
||||||
ItemId_Event_Ping = ItemId_Other + 212,
|
ItemId_Event_Ping = ItemId_Other + 212,
|
||||||
ItemId_Event_AddToList = ItemId_Other + 213,
|
ItemId_Event_AddToList = ItemId_Other + 213,
|
||||||
ItemId_Response_ListUsers = ItemId_Other + 300,
|
ItemId_Response_ListUsers = ItemId_Other + 300,
|
||||||
ItemId_Response_GetUserInfo = ItemId_Other + 301,
|
ItemId_Response_GetGamesOfUser = ItemId_Other + 301,
|
||||||
ItemId_Response_DeckList = ItemId_Other + 302,
|
ItemId_Response_GetUserInfo = ItemId_Other + 302,
|
||||||
ItemId_Response_DeckDownload = ItemId_Other + 303,
|
ItemId_Response_DeckList = ItemId_Other + 303,
|
||||||
ItemId_Response_DeckUpload = ItemId_Other + 304,
|
ItemId_Response_DeckDownload = ItemId_Other + 304,
|
||||||
ItemId_Response_DumpZone = ItemId_Other + 305,
|
ItemId_Response_DeckUpload = ItemId_Other + 305,
|
||||||
ItemId_Response_JoinRoom = ItemId_Other + 306,
|
ItemId_Response_DumpZone = ItemId_Other + 306,
|
||||||
ItemId_Response_Login = ItemId_Other + 307,
|
ItemId_Response_JoinRoom = ItemId_Other + 307,
|
||||||
|
ItemId_Response_Login = ItemId_Other + 308,
|
||||||
ItemId_Invalid = ItemId_Other + 1000
|
ItemId_Invalid = ItemId_Other + 1000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -282,6 +283,15 @@ public:
|
||||||
QList<ServerInfo_User *> getUserList() const { return typecastItemList<ServerInfo_User *>(); }
|
QList<ServerInfo_User *> getUserList() const { return typecastItemList<ServerInfo_User *>(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Response_GetGamesOfUser : public ProtocolResponse {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Response_GetGamesOfUser(int _cmdId = -1, ResponseCode _responseCode = RespOk, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>());
|
||||||
|
int getItemId() const { return ItemId_Response_GetGamesOfUser; }
|
||||||
|
static SerializableItem *newItem() { return new Response_GetGamesOfUser; }
|
||||||
|
QList<ServerInfo_Game *> getGameList() const { return typecastItemList<ServerInfo_Game *>(); }
|
||||||
|
};
|
||||||
|
|
||||||
class Response_GetUserInfo : public ProtocolResponse {
|
class Response_GetUserInfo : public ProtocolResponse {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -40,9 +40,10 @@ ServerInfo_UserList::ServerInfo_UserList(const QString &_itemType, const QList<S
|
||||||
itemList.append(_userList[i]);
|
itemList.append(_userList[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QList<GameTypeId *> &_gameTypes, ServerInfo_User *_creatorInfo, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount)
|
ServerInfo_Game::ServerInfo_Game(int _roomId, int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, const QList<GameTypeId *> &_gameTypes, ServerInfo_User *_creatorInfo, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount)
|
||||||
: SerializableItem_Map("game")
|
: SerializableItem_Map("game")
|
||||||
{
|
{
|
||||||
|
insertItem(new SerializableItem_Int("room_id", _roomId));
|
||||||
insertItem(new SerializableItem_Int("game_id", _gameId));
|
insertItem(new SerializableItem_Int("game_id", _gameId));
|
||||||
insertItem(new SerializableItem_String("description", _description));
|
insertItem(new SerializableItem_String("description", _description));
|
||||||
insertItem(new SerializableItem_Bool("has_password", _hasPassword));
|
insertItem(new SerializableItem_Bool("has_password", _hasPassword));
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
|
|
||||||
class ServerInfo_Game : public SerializableItem_Map {
|
class ServerInfo_Game : public SerializableItem_Map {
|
||||||
public:
|
public:
|
||||||
ServerInfo_Game(int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, const QList<GameTypeId *> &_gameTypes = QList<GameTypeId *>(), ServerInfo_User *creatorInfo = 0, bool _onlyBuddies = false, bool _onlyRegistered = false, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1);
|
ServerInfo_Game(int _roomId = -1, int _gameId = -1, const QString &_description = QString(), bool _hasPassword = false, int _playerCount = -1, int _maxPlayers = -1, const QList<GameTypeId *> &_gameTypes = QList<GameTypeId *>(), ServerInfo_User *creatorInfo = 0, bool _onlyBuddies = false, bool _onlyRegistered = false, bool _spectatorsAllowed = false, bool _spectatorsNeedPassword = false, int _spectatorCount = -1);
|
||||||
static SerializableItem *newItem() { return new ServerInfo_Game; }
|
static SerializableItem *newItem() { return new ServerInfo_Game; }
|
||||||
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
|
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); }
|
||||||
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
|
QString getDescription() const { return static_cast<SerializableItem_String *>(itemMap.value("description"))->getData(); }
|
||||||
|
|
|
@ -3,84 +3,85 @@ ItemId_Command_Ping = 1001,
|
||||||
ItemId_Command_Login = 1002,
|
ItemId_Command_Login = 1002,
|
||||||
ItemId_Command_Message = 1003,
|
ItemId_Command_Message = 1003,
|
||||||
ItemId_Command_ListUsers = 1004,
|
ItemId_Command_ListUsers = 1004,
|
||||||
ItemId_Command_GetUserInfo = 1005,
|
ItemId_Command_GetGamesOfUser = 1005,
|
||||||
ItemId_Command_AddToList = 1006,
|
ItemId_Command_GetUserInfo = 1006,
|
||||||
ItemId_Command_RemoveFromList = 1007,
|
ItemId_Command_AddToList = 1007,
|
||||||
ItemId_Command_DeckList = 1008,
|
ItemId_Command_RemoveFromList = 1008,
|
||||||
ItemId_Command_DeckNewDir = 1009,
|
ItemId_Command_DeckList = 1009,
|
||||||
ItemId_Command_DeckDelDir = 1010,
|
ItemId_Command_DeckNewDir = 1010,
|
||||||
ItemId_Command_DeckDel = 1011,
|
ItemId_Command_DeckDelDir = 1011,
|
||||||
ItemId_Command_DeckDownload = 1012,
|
ItemId_Command_DeckDel = 1012,
|
||||||
ItemId_Command_ListRooms = 1013,
|
ItemId_Command_DeckDownload = 1013,
|
||||||
ItemId_Command_JoinRoom = 1014,
|
ItemId_Command_ListRooms = 1014,
|
||||||
ItemId_Command_LeaveRoom = 1015,
|
ItemId_Command_JoinRoom = 1015,
|
||||||
ItemId_Command_RoomSay = 1016,
|
ItemId_Command_LeaveRoom = 1016,
|
||||||
ItemId_Command_JoinGame = 1017,
|
ItemId_Command_RoomSay = 1017,
|
||||||
ItemId_Command_KickFromGame = 1018,
|
ItemId_Command_JoinGame = 1018,
|
||||||
ItemId_Command_LeaveGame = 1019,
|
ItemId_Command_KickFromGame = 1019,
|
||||||
ItemId_Command_Say = 1020,
|
ItemId_Command_LeaveGame = 1020,
|
||||||
ItemId_Command_Shuffle = 1021,
|
ItemId_Command_Say = 1021,
|
||||||
ItemId_Command_Mulligan = 1022,
|
ItemId_Command_Shuffle = 1022,
|
||||||
ItemId_Command_RollDie = 1023,
|
ItemId_Command_Mulligan = 1023,
|
||||||
ItemId_Command_DrawCards = 1024,
|
ItemId_Command_RollDie = 1024,
|
||||||
ItemId_Command_UndoDraw = 1025,
|
ItemId_Command_DrawCards = 1025,
|
||||||
ItemId_Command_FlipCard = 1026,
|
ItemId_Command_UndoDraw = 1026,
|
||||||
ItemId_Command_AttachCard = 1027,
|
ItemId_Command_FlipCard = 1027,
|
||||||
ItemId_Command_CreateToken = 1028,
|
ItemId_Command_AttachCard = 1028,
|
||||||
ItemId_Command_CreateArrow = 1029,
|
ItemId_Command_CreateToken = 1029,
|
||||||
ItemId_Command_DeleteArrow = 1030,
|
ItemId_Command_CreateArrow = 1030,
|
||||||
ItemId_Command_SetCardAttr = 1031,
|
ItemId_Command_DeleteArrow = 1031,
|
||||||
ItemId_Command_SetCardCounter = 1032,
|
ItemId_Command_SetCardAttr = 1032,
|
||||||
ItemId_Command_IncCardCounter = 1033,
|
ItemId_Command_SetCardCounter = 1033,
|
||||||
ItemId_Command_ReadyStart = 1034,
|
ItemId_Command_IncCardCounter = 1034,
|
||||||
ItemId_Command_Concede = 1035,
|
ItemId_Command_ReadyStart = 1035,
|
||||||
ItemId_Command_IncCounter = 1036,
|
ItemId_Command_Concede = 1036,
|
||||||
ItemId_Command_CreateCounter = 1037,
|
ItemId_Command_IncCounter = 1037,
|
||||||
ItemId_Command_SetCounter = 1038,
|
ItemId_Command_CreateCounter = 1038,
|
||||||
ItemId_Command_DelCounter = 1039,
|
ItemId_Command_SetCounter = 1039,
|
||||||
ItemId_Command_NextTurn = 1040,
|
ItemId_Command_DelCounter = 1040,
|
||||||
ItemId_Command_SetActivePhase = 1041,
|
ItemId_Command_NextTurn = 1041,
|
||||||
ItemId_Command_DumpZone = 1042,
|
ItemId_Command_SetActivePhase = 1042,
|
||||||
ItemId_Command_StopDumpZone = 1043,
|
ItemId_Command_DumpZone = 1043,
|
||||||
ItemId_Command_RevealCards = 1044,
|
ItemId_Command_StopDumpZone = 1044,
|
||||||
ItemId_Event_ConnectionStateChanged = 1045,
|
ItemId_Command_RevealCards = 1045,
|
||||||
ItemId_Event_Say = 1046,
|
ItemId_Event_ConnectionStateChanged = 1046,
|
||||||
ItemId_Event_Leave = 1047,
|
ItemId_Event_Say = 1047,
|
||||||
ItemId_Event_GameClosed = 1048,
|
ItemId_Event_Leave = 1048,
|
||||||
ItemId_Event_Kicked = 1049,
|
ItemId_Event_GameClosed = 1049,
|
||||||
ItemId_Event_Shuffle = 1050,
|
ItemId_Event_Kicked = 1050,
|
||||||
ItemId_Event_RollDie = 1051,
|
ItemId_Event_Shuffle = 1051,
|
||||||
ItemId_Event_MoveCard = 1052,
|
ItemId_Event_RollDie = 1052,
|
||||||
ItemId_Event_FlipCard = 1053,
|
ItemId_Event_MoveCard = 1053,
|
||||||
ItemId_Event_DestroyCard = 1054,
|
ItemId_Event_FlipCard = 1054,
|
||||||
ItemId_Event_AttachCard = 1055,
|
ItemId_Event_DestroyCard = 1055,
|
||||||
ItemId_Event_CreateToken = 1056,
|
ItemId_Event_AttachCard = 1056,
|
||||||
ItemId_Event_DeleteArrow = 1057,
|
ItemId_Event_CreateToken = 1057,
|
||||||
ItemId_Event_SetCardAttr = 1058,
|
ItemId_Event_DeleteArrow = 1058,
|
||||||
ItemId_Event_SetCardCounter = 1059,
|
ItemId_Event_SetCardAttr = 1059,
|
||||||
ItemId_Event_SetCounter = 1060,
|
ItemId_Event_SetCardCounter = 1060,
|
||||||
ItemId_Event_DelCounter = 1061,
|
ItemId_Event_SetCounter = 1061,
|
||||||
ItemId_Event_SetActivePlayer = 1062,
|
ItemId_Event_DelCounter = 1062,
|
||||||
ItemId_Event_SetActivePhase = 1063,
|
ItemId_Event_SetActivePlayer = 1063,
|
||||||
ItemId_Event_DumpZone = 1064,
|
ItemId_Event_SetActivePhase = 1064,
|
||||||
ItemId_Event_StopDumpZone = 1065,
|
ItemId_Event_DumpZone = 1065,
|
||||||
ItemId_Event_RemoveFromList = 1066,
|
ItemId_Event_StopDumpZone = 1066,
|
||||||
ItemId_Event_ServerMessage = 1067,
|
ItemId_Event_RemoveFromList = 1067,
|
||||||
ItemId_Event_ServerShutdown = 1068,
|
ItemId_Event_ServerMessage = 1068,
|
||||||
ItemId_Event_ConnectionClosed = 1069,
|
ItemId_Event_ServerShutdown = 1069,
|
||||||
ItemId_Event_Message = 1070,
|
ItemId_Event_ConnectionClosed = 1070,
|
||||||
ItemId_Event_GameJoined = 1071,
|
ItemId_Event_Message = 1071,
|
||||||
ItemId_Event_UserLeft = 1072,
|
ItemId_Event_GameJoined = 1072,
|
||||||
ItemId_Event_LeaveRoom = 1073,
|
ItemId_Event_UserLeft = 1073,
|
||||||
ItemId_Event_RoomSay = 1074,
|
ItemId_Event_LeaveRoom = 1074,
|
||||||
ItemId_Context_ReadyStart = 1075,
|
ItemId_Event_RoomSay = 1075,
|
||||||
ItemId_Context_Concede = 1076,
|
ItemId_Context_ReadyStart = 1076,
|
||||||
ItemId_Context_DeckSelect = 1077,
|
ItemId_Context_Concede = 1077,
|
||||||
ItemId_Context_UndoDraw = 1078,
|
ItemId_Context_DeckSelect = 1078,
|
||||||
ItemId_Context_MoveCard = 1079,
|
ItemId_Context_UndoDraw = 1079,
|
||||||
ItemId_Context_Mulligan = 1080,
|
ItemId_Context_MoveCard = 1080,
|
||||||
ItemId_Command_UpdateServerMessage = 1081,
|
ItemId_Context_Mulligan = 1081,
|
||||||
ItemId_Command_ShutdownServer = 1082,
|
ItemId_Command_UpdateServerMessage = 1082,
|
||||||
ItemId_Command_BanFromServer = 1083,
|
ItemId_Command_ShutdownServer = 1083,
|
||||||
ItemId_Other = 1084
|
ItemId_Command_BanFromServer = 1084,
|
||||||
|
ItemId_Other = 1085
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,11 @@ Command_ListUsers::Command_ListUsers()
|
||||||
: Command("list_users")
|
: Command("list_users")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Command_GetGamesOfUser::Command_GetGamesOfUser(const QString &_userName)
|
||||||
|
: Command("get_games_of_user")
|
||||||
|
{
|
||||||
|
insertItem(new SerializableItem_String("user_name", _userName));
|
||||||
|
}
|
||||||
Command_GetUserInfo::Command_GetUserInfo(const QString &_userName)
|
Command_GetUserInfo::Command_GetUserInfo(const QString &_userName)
|
||||||
: Command("get_user_info")
|
: Command("get_user_info")
|
||||||
{
|
{
|
||||||
|
@ -497,6 +502,7 @@ void ProtocolItem::initializeHashAuto()
|
||||||
itemNameHash.insert("cmdlogin", Command_Login::newItem);
|
itemNameHash.insert("cmdlogin", Command_Login::newItem);
|
||||||
itemNameHash.insert("cmdmessage", Command_Message::newItem);
|
itemNameHash.insert("cmdmessage", Command_Message::newItem);
|
||||||
itemNameHash.insert("cmdlist_users", Command_ListUsers::newItem);
|
itemNameHash.insert("cmdlist_users", Command_ListUsers::newItem);
|
||||||
|
itemNameHash.insert("cmdget_games_of_user", Command_GetGamesOfUser::newItem);
|
||||||
itemNameHash.insert("cmdget_user_info", Command_GetUserInfo::newItem);
|
itemNameHash.insert("cmdget_user_info", Command_GetUserInfo::newItem);
|
||||||
itemNameHash.insert("cmdadd_to_list", Command_AddToList::newItem);
|
itemNameHash.insert("cmdadd_to_list", Command_AddToList::newItem);
|
||||||
itemNameHash.insert("cmdremove_from_list", Command_RemoveFromList::newItem);
|
itemNameHash.insert("cmdremove_from_list", Command_RemoveFromList::newItem);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
0:login:s,username:s,password
|
0:login:s,username:s,password
|
||||||
0:message:s,user_name:s,text
|
0:message:s,user_name:s,text
|
||||||
0:list_users
|
0:list_users
|
||||||
|
0:get_games_of_user:s,user_name
|
||||||
0:get_user_info:s,user_name
|
0:get_user_info:s,user_name
|
||||||
0:add_to_list:s,list:s,user_name
|
0:add_to_list:s,list:s,user_name
|
||||||
0:remove_from_list:s,list:s,user_name
|
0:remove_from_list:s,list:s,user_name
|
||||||
|
|
|
@ -35,6 +35,14 @@ public:
|
||||||
static SerializableItem *newItem() { return new Command_ListUsers; }
|
static SerializableItem *newItem() { return new Command_ListUsers; }
|
||||||
int getItemId() const { return ItemId_Command_ListUsers; }
|
int getItemId() const { return ItemId_Command_ListUsers; }
|
||||||
};
|
};
|
||||||
|
class Command_GetGamesOfUser : public Command {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Command_GetGamesOfUser(const QString &_userName = QString());
|
||||||
|
QString getUserName() const { return static_cast<SerializableItem_String *>(itemMap.value("user_name"))->getData(); };
|
||||||
|
static SerializableItem *newItem() { return new Command_GetGamesOfUser; }
|
||||||
|
int getItemId() const { return ItemId_Command_GetGamesOfUser; }
|
||||||
|
};
|
||||||
class Command_GetUserInfo : public Command {
|
class Command_GetUserInfo : public Command {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -214,6 +214,17 @@ ResponseCode Server_Game::checkJoin(ServerInfo_User *user, const QString &_passw
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Server_Game::containsUser(const QString &userName) const
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&gameMutex);
|
||||||
|
|
||||||
|
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||||
|
while (playerIterator.hasNext())
|
||||||
|
if (playerIterator.next().value()->getUserInfo()->getName() == userName)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate)
|
Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&gameMutex);
|
QMutexLocker locker(&gameMutex);
|
||||||
|
@ -479,7 +490,7 @@ ServerInfo_Game *Server_Game::getInfo() const
|
||||||
|
|
||||||
if (players.isEmpty())
|
if (players.isEmpty())
|
||||||
// Game is closing
|
// Game is closing
|
||||||
return new ServerInfo_Game(getGameId(), QString(), false, 0, getMaxPlayers(), QList<GameTypeId *>(), 0, false, 0);
|
return new ServerInfo_Game(room->getId(), getGameId(), QString(), false, 0, getMaxPlayers(), QList<GameTypeId *>(), 0, false, 0);
|
||||||
else {
|
else {
|
||||||
// Game is open
|
// Game is open
|
||||||
|
|
||||||
|
@ -488,6 +499,7 @@ ServerInfo_Game *Server_Game::getInfo() const
|
||||||
gameTypeList.append(new GameTypeId(gameTypes[i]));
|
gameTypeList.append(new GameTypeId(gameTypes[i]));
|
||||||
|
|
||||||
return new ServerInfo_Game(
|
return new ServerInfo_Game(
|
||||||
|
room->getId(),
|
||||||
getGameId(),
|
getGameId(),
|
||||||
getDescription(),
|
getDescription(),
|
||||||
!getPassword().isEmpty(),
|
!getPassword().isEmpty(),
|
||||||
|
|
|
@ -77,6 +77,7 @@ public:
|
||||||
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
|
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
|
||||||
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
|
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
|
||||||
ResponseCode checkJoin(ServerInfo_User *user, const QString &_password, bool spectator);
|
ResponseCode checkJoin(ServerInfo_User *user, const QString &_password, bool spectator);
|
||||||
|
bool containsUser(const QString &userName) const;
|
||||||
Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate = true);
|
Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate = true);
|
||||||
void removePlayer(Server_Player *player);
|
void removePlayer(Server_Player *player);
|
||||||
void removeArrowsToPlayer(Server_Player *player);
|
void removeArrowsToPlayer(Server_Player *player);
|
||||||
|
|
|
@ -179,6 +179,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
|
||||||
case ItemId_Command_DeckDel: return cmdDeckDel(static_cast<Command_DeckDel *>(command), cont);
|
case ItemId_Command_DeckDel: return cmdDeckDel(static_cast<Command_DeckDel *>(command), cont);
|
||||||
case ItemId_Command_DeckUpload: return cmdDeckUpload(static_cast<Command_DeckUpload *>(command), cont);
|
case ItemId_Command_DeckUpload: return cmdDeckUpload(static_cast<Command_DeckUpload *>(command), cont);
|
||||||
case ItemId_Command_DeckDownload: return cmdDeckDownload(static_cast<Command_DeckDownload *>(command), cont);
|
case ItemId_Command_DeckDownload: return cmdDeckDownload(static_cast<Command_DeckDownload *>(command), cont);
|
||||||
|
case ItemId_Command_GetGamesOfUser: return cmdGetGamesOfUser(static_cast<Command_GetGamesOfUser *>(command), cont);
|
||||||
case ItemId_Command_GetUserInfo: return cmdGetUserInfo(static_cast<Command_GetUserInfo *>(command), cont);
|
case ItemId_Command_GetUserInfo: return cmdGetUserInfo(static_cast<Command_GetUserInfo *>(command), cont);
|
||||||
case ItemId_Command_ListRooms: return cmdListRooms(static_cast<Command_ListRooms *>(command), cont);
|
case ItemId_Command_ListRooms: return cmdListRooms(static_cast<Command_ListRooms *>(command), cont);
|
||||||
case ItemId_Command_JoinRoom: return cmdJoinRoom(static_cast<Command_JoinRoom *>(command), cont);
|
case ItemId_Command_JoinRoom: return cmdJoinRoom(static_cast<Command_JoinRoom *>(command), cont);
|
||||||
|
@ -330,6 +331,28 @@ ResponseCode Server_ProtocolHandler::cmdMessage(Command_Message *cmd, CommandCon
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(Command_GetGamesOfUser *cmd, CommandContainer *cont)
|
||||||
|
{
|
||||||
|
if (authState == PasswordWrong)
|
||||||
|
return RespLoginNeeded;
|
||||||
|
|
||||||
|
server->serverMutex.lock();
|
||||||
|
if (!server->getUsers().contains(cmd->getUserName()))
|
||||||
|
return RespNameNotFound;
|
||||||
|
|
||||||
|
QList<ServerInfo_Game *> gameList;
|
||||||
|
QMapIterator<int, Server_Room *> roomIterator(server->getRooms());
|
||||||
|
while (roomIterator.hasNext())
|
||||||
|
gameList.append(roomIterator.next().value()->getGamesOfUser(cmd->getUserName()));
|
||||||
|
server->serverMutex.unlock();
|
||||||
|
|
||||||
|
ProtocolResponse *resp = new Response_GetGamesOfUser(cont->getCmdId(), RespOk, gameList);
|
||||||
|
if (getCompressionSupport())
|
||||||
|
resp->setCompressed(true);
|
||||||
|
cont->setResponse(resp);
|
||||||
|
return RespNothing;
|
||||||
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdGetUserInfo(Command_GetUserInfo *cmd, CommandContainer *cont)
|
ResponseCode Server_ProtocolHandler::cmdGetUserInfo(Command_GetUserInfo *cmd, CommandContainer *cont)
|
||||||
{
|
{
|
||||||
if (authState == PasswordWrong)
|
if (authState == PasswordWrong)
|
||||||
|
|
|
@ -50,6 +50,7 @@ private:
|
||||||
virtual ResponseCode cmdDeckDel(Command_DeckDel *cmd, CommandContainer *cont) = 0;
|
virtual ResponseCode cmdDeckDel(Command_DeckDel *cmd, CommandContainer *cont) = 0;
|
||||||
virtual ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont) = 0;
|
virtual ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont) = 0;
|
||||||
virtual ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont) = 0;
|
virtual ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont) = 0;
|
||||||
|
ResponseCode cmdGetGamesOfUser(Command_GetGamesOfUser *cmd, CommandContainer *cont);
|
||||||
ResponseCode cmdGetUserInfo(Command_GetUserInfo *cmd, CommandContainer *cont);
|
ResponseCode cmdGetUserInfo(Command_GetUserInfo *cmd, CommandContainer *cont);
|
||||||
ResponseCode cmdListRooms(Command_ListRooms *cmd, CommandContainer *cont);
|
ResponseCode cmdListRooms(Command_ListRooms *cmd, CommandContainer *cont);
|
||||||
ResponseCode cmdJoinRoom(Command_JoinRoom *cmd, CommandContainer *cont);
|
ResponseCode cmdJoinRoom(Command_JoinRoom *cmd, CommandContainer *cont);
|
||||||
|
|
|
@ -130,3 +130,17 @@ int Server_Room::getGamesCreatedByUser(const QString &userName) const
|
||||||
++result;
|
++result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<ServerInfo_Game *> Server_Room::getGamesOfUser(const QString &userName) const
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&roomMutex);
|
||||||
|
|
||||||
|
QList<ServerInfo_Game *> result;
|
||||||
|
QMapIterator<int, Server_Game *> gamesIterator(games);
|
||||||
|
while (gamesIterator.hasNext()) {
|
||||||
|
Server_Game *game = gamesIterator.next().value();
|
||||||
|
if (game->containsUser(userName))
|
||||||
|
result.append(game->getInfo());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ class Server_ProtocolHandler;
|
||||||
class RoomEvent;
|
class RoomEvent;
|
||||||
class ServerInfo_User;
|
class ServerInfo_User;
|
||||||
class ServerInfo_Room;
|
class ServerInfo_Room;
|
||||||
|
class ServerInfo_Game;
|
||||||
class Server_Game;
|
class Server_Game;
|
||||||
class Server;
|
class Server;
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@ public:
|
||||||
Server *getServer() const;
|
Server *getServer() const;
|
||||||
ServerInfo_Room *getInfo(bool complete) const;
|
ServerInfo_Room *getInfo(bool complete) const;
|
||||||
int getGamesCreatedByUser(const QString &name) const;
|
int getGamesCreatedByUser(const QString &name) const;
|
||||||
|
QList<ServerInfo_Game *> getGamesOfUser(const QString &name) const;
|
||||||
|
|
||||||
void addClient(Server_ProtocolHandler *client);
|
void addClient(Server_ProtocolHandler *client);
|
||||||
void removeClient(Server_ProtocolHandler *client);
|
void removeClient(Server_ProtocolHandler *client);
|
||||||
|
|
Loading…
Reference in a new issue