mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
finished getGamesOfUser function
This commit is contained in:
parent
d5de76ec4a
commit
abd5425796
24 changed files with 1221 additions and 1051 deletions
|
|
@ -257,6 +257,7 @@ void ProtocolResponse::initializeHash()
|
|||
{
|
||||
responseHash.insert(QString(), RespNothing);
|
||||
responseHash.insert("ok", RespOk);
|
||||
responseHash.insert("not_in_room", RespNotInRoom);
|
||||
responseHash.insert("internal_error", RespInternalError);
|
||||
responseHash.insert("invalid_command", RespInvalidCommand);
|
||||
responseHash.insert("name_not_found", RespNameNotFound);
|
||||
|
|
@ -297,12 +298,34 @@ Response_DeckList::Response_DeckList(int _cmdId, ResponseCode _responseCode, Dec
|
|||
insertItem(_root);
|
||||
}
|
||||
|
||||
Response_GetGamesOfUser::Response_GetGamesOfUser(int _cmdId, ResponseCode _responseCode, const QList<ServerInfo_Game *> &_gameList)
|
||||
Response_GetGamesOfUser::Response_GetGamesOfUser(int _cmdId, ResponseCode _responseCode, const QList<ServerInfo_Room *> &_roomList, const QList<ServerInfo_Game *> &_gameList)
|
||||
: ProtocolResponse(_cmdId, _responseCode, "get_games_of_user")
|
||||
{
|
||||
roomList = _roomList;
|
||||
for (int i = 0; i < _roomList.size(); ++i)
|
||||
itemList.append(_roomList[i]);
|
||||
|
||||
gameList = _gameList;
|
||||
for (int i = 0; i < _gameList.size(); ++i)
|
||||
itemList.append(_gameList[i]);
|
||||
}
|
||||
|
||||
void Response_GetGamesOfUser::extractData()
|
||||
{
|
||||
for (int i = 0; i < itemList.size(); ++i) {
|
||||
ServerInfo_Room *room = dynamic_cast<ServerInfo_Room *>(itemList[i]);
|
||||
if (room) {
|
||||
roomList.append(room);
|
||||
continue;
|
||||
}
|
||||
ServerInfo_Game *game = dynamic_cast<ServerInfo_Game *>(itemList[i]);
|
||||
if (game) {
|
||||
gameList.append(game);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Response_GetUserInfo::Response_GetUserInfo(int _cmdId, ResponseCode _responseCode, ServerInfo_User *_user)
|
||||
: ProtocolResponse(_cmdId, _responseCode, "get_user_info")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -285,11 +285,17 @@ public:
|
|||
|
||||
class Response_GetGamesOfUser : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<ServerInfo_Game *> gameList;
|
||||
QList<ServerInfo_Room *> roomList;
|
||||
protected:
|
||||
void extractData();
|
||||
public:
|
||||
Response_GetGamesOfUser(int _cmdId = -1, ResponseCode _responseCode = RespOk, const QList<ServerInfo_Game *> &_gameList = QList<ServerInfo_Game *>());
|
||||
Response_GetGamesOfUser(int _cmdId = -1, ResponseCode _responseCode = RespOk, const QList<ServerInfo_Room *> &_roomList = QList<ServerInfo_Room *>(), 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 *>(); }
|
||||
QList<ServerInfo_Room *> getRoomList() const { return roomList; }
|
||||
QList<ServerInfo_Game *> getGameList() const { return gameList; }
|
||||
};
|
||||
|
||||
class Response_GetUserInfo : public ProtocolResponse {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
class DeckList;
|
||||
|
||||
enum ResponseCode { RespNothing, RespOk, RespInternalError, RespInvalidCommand, RespInvalidData, RespNameNotFound, RespLoginNeeded, RespFunctionNotAllowed, RespGameNotStarted, RespGameFull, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed, RespOnlyBuddies, RespUserLevelTooLow, RespInIgnoreList, RespWouldOverwriteOldSession, RespChatFlood };
|
||||
enum ResponseCode { RespNothing, RespOk, RespNotInRoom, RespInternalError, RespInvalidCommand, RespInvalidData, RespNameNotFound, RespLoginNeeded, RespFunctionNotAllowed, RespGameNotStarted, RespGameFull, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed, RespOnlyBuddies, RespUserLevelTooLow, RespInIgnoreList, RespWouldOverwriteOldSession, RespChatFlood };
|
||||
|
||||
// PrivateZone: Contents of the zone are always visible to the owner,
|
||||
// but not to anyone else.
|
||||
|
|
@ -71,6 +71,7 @@ class ServerInfo_Game : public SerializableItem_Map {
|
|||
public:
|
||||
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; }
|
||||
int getRoomId() const { return static_cast<SerializableItem_Int *>(itemMap.value("room_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(); }
|
||||
bool getHasPassword() const { return static_cast<SerializableItem_Bool *>(itemMap.value("has_password"))->getData(); }
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
|
|||
|
||||
Server_Room *room = rooms.value(roomCommand->getRoomId(), 0);
|
||||
if (!room)
|
||||
return RespNameNotFound;
|
||||
return RespNotInRoom;
|
||||
|
||||
QMutexLocker locker(&room->roomMutex);
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
|
|||
gameListMutex.lock();
|
||||
if (!games.contains(gameCommand->getGameId())) {
|
||||
qDebug() << "invalid game";
|
||||
return RespNameNotFound;
|
||||
return RespNotInRoom;
|
||||
}
|
||||
QPair<Server_Game *, Server_Player *> gamePair = games.value(gameCommand->getGameId());
|
||||
Server_Game *game = gamePair.first;
|
||||
|
|
@ -340,13 +340,19 @@ ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(Command_GetGamesOfUser *c
|
|||
if (!server->getUsers().contains(cmd->getUserName()))
|
||||
return RespNameNotFound;
|
||||
|
||||
QList<ServerInfo_Room *> roomList;
|
||||
QList<ServerInfo_Game *> gameList;
|
||||
QMapIterator<int, Server_Room *> roomIterator(server->getRooms());
|
||||
while (roomIterator.hasNext())
|
||||
gameList.append(roomIterator.next().value()->getGamesOfUser(cmd->getUserName()));
|
||||
while (roomIterator.hasNext()) {
|
||||
Server_Room *room = roomIterator.next().value();
|
||||
room->roomMutex.lock();
|
||||
roomList.append(room->getInfo(false, true));
|
||||
gameList.append(room->getGamesOfUser(cmd->getUserName()));
|
||||
room->roomMutex.unlock();
|
||||
}
|
||||
server->serverMutex.unlock();
|
||||
|
||||
ProtocolResponse *resp = new Response_GetGamesOfUser(cont->getCmdId(), RespOk, gameList);
|
||||
ProtocolResponse *resp = new Response_GetGamesOfUser(cont->getCmdId(), RespOk, roomList, gameList);
|
||||
if (getCompressionSupport())
|
||||
resp->setCompressed(true);
|
||||
cont->setResponse(resp);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ Server *Server_Room::getServer() const
|
|||
return static_cast<Server *>(parent());
|
||||
}
|
||||
|
||||
ServerInfo_Room *Server_Room::getInfo(bool complete) const
|
||||
ServerInfo_Room *Server_Room::getInfo(bool complete, bool showGameTypes) const
|
||||
{
|
||||
QMutexLocker locker(&roomMutex);
|
||||
|
||||
|
|
@ -40,10 +40,10 @@ ServerInfo_Room *Server_Room::getInfo(bool complete) const
|
|||
|
||||
for (int i = 0; i < size(); ++i)
|
||||
userList.append(new ServerInfo_User(at(i)->getUserInfo(), false));
|
||||
|
||||
}
|
||||
if (complete || showGameTypes)
|
||||
for (int i = 0; i < gameTypes.size(); ++i)
|
||||
gameTypeList.append(new ServerInfo_GameType(i, gameTypes[i]));
|
||||
}
|
||||
|
||||
return new ServerInfo_Room(id, name, description, games.size(), size(), autoJoin, gameList, userList, gameTypeList);
|
||||
}
|
||||
|
|
@ -133,8 +133,6 @@ int Server_Room::getGamesCreatedByUser(const QString &userName) const
|
|||
|
||||
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()) {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public:
|
|||
QString getJoinMessage() const { return joinMessage; }
|
||||
const QMap<int, Server_Game *> &getGames() const { return games; }
|
||||
Server *getServer() const;
|
||||
ServerInfo_Room *getInfo(bool complete) const;
|
||||
ServerInfo_Room *getInfo(bool complete, bool showGameTypes = false) const;
|
||||
int getGamesCreatedByUser(const QString &name) const;
|
||||
QList<ServerInfo_Game *> getGamesOfUser(const QString &name) const;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue