diff --git a/cockatrice/src/localserver.h b/cockatrice/src/localserver.h index 3409b1a4..b68e4f25 100644 --- a/cockatrice/src/localserver.h +++ b/cockatrice/src/localserver.h @@ -21,8 +21,8 @@ public: protected: bool userExists(const QString & /*name*/) { return false; } ServerInfo_User *getUserData(const QString &name); - QList getBuddyList(const QString & /*name*/) { return QList(); } - QList getIgnoreList(const QString & /*name*/) { return QList(); } + QMap getBuddyList(const QString & /*name*/) { return QMap(); } + QMap getIgnoreList(const QString & /*name*/) { return QMap(); } }; #endif \ No newline at end of file diff --git a/cockatrice/src/tab_room.cpp b/cockatrice/src/tab_room.cpp index 5b7ace63..46f6b0b3 100644 --- a/cockatrice/src/tab_room.cpp +++ b/cockatrice/src/tab_room.cpp @@ -80,6 +80,7 @@ void GameSelector::checkResponse(ResponseCode response) case RespNameNotFound: QMessageBox::critical(this, tr("Error"), tr("The game does not exist any more.")); break; case RespUserLevelTooLow: QMessageBox::critical(this, tr("Error"), tr("This game is only open to registered users.")); break; case RespOnlyBuddies: QMessageBox::critical(this, tr("Error"), tr("This game is only open to its creator's buddies.")); break; + case RespOnIgnoreList: QMessageBox::critical(this, tr("Error"), tr("You are being ignored by the creator of this game.")); break; default: ; } } diff --git a/common/protocol.cpp b/common/protocol.cpp index 13719bfa..717aa791 100644 --- a/common/protocol.cpp +++ b/common/protocol.cpp @@ -266,6 +266,7 @@ void ProtocolResponse::initializeHash() responseHash.insert("spectators_not_allowed", RespSpectatorsNotAllowed); responseHash.insert("only_buddies", RespOnlyBuddies); responseHash.insert("user_level_too_low", RespUserLevelTooLow); + responseHash.insert("on_ignore_list", RespOnIgnoreList); } Response_JoinRoom::Response_JoinRoom(int _cmdId, ResponseCode _responseCode, ServerInfo_Room *_roomInfo) diff --git a/common/protocol_datastructures.h b/common/protocol_datastructures.h index 48ddb445..8291dd82 100644 --- a/common/protocol_datastructures.h +++ b/common/protocol_datastructures.h @@ -8,7 +8,7 @@ class DeckList; -enum ResponseCode { RespNothing, RespOk, RespInternalError, RespInvalidCommand, RespInvalidData, RespNameNotFound, RespLoginNeeded, RespFunctionNotAllowed, RespGameNotStarted, RespGameFull, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed, RespOnlyBuddies, RespUserLevelTooLow }; +enum ResponseCode { RespNothing, RespOk, RespInternalError, RespInvalidCommand, RespInvalidData, RespNameNotFound, RespLoginNeeded, RespFunctionNotAllowed, RespGameNotStarted, RespGameFull, RespContextError, RespWrongPassword, RespSpectatorsNotAllowed, RespOnlyBuddies, RespUserLevelTooLow, RespOnIgnoreList }; // PrivateZone: Contents of the zone are always visible to the owner, // but not to anyone else. diff --git a/common/server.h b/common/server.h index 6a7ed157..2f4527b9 100644 --- a/common/server.h +++ b/common/server.h @@ -39,8 +39,8 @@ public: virtual int getMaxGameInactivityTime() const = 0; virtual int getMaxPlayerInactivityTime() const = 0; - virtual QList getBuddyList(const QString &name) = 0; - virtual QList getIgnoreList(const QString &name) = 0; + virtual QMap getBuddyList(const QString &name) = 0; + virtual QMap getIgnoreList(const QString &name) = 0; protected: QMap games; QList clients; diff --git a/common/server_game.cpp b/common/server_game.cpp index 72c2016a..e984df92 100644 --- a/common/server_game.cpp +++ b/common/server_game.cpp @@ -179,6 +179,11 @@ ResponseCode Server_Game::checkJoin(ServerInfo_User *user, const QString &_passw return RespWrongPassword; if (!(user->getUserLevel() & ServerInfo_User::IsRegistered) && onlyRegistered) return RespUserLevelTooLow; + if (onlyBuddies) + if (!static_cast(parent())->getServer()->getBuddyList(creatorInfo->getName()).contains(user->getName())) + return RespOnlyBuddies; + if (static_cast(parent())->getServer()->getIgnoreList(creatorInfo->getName()).contains(user->getName())) + return RespOnIgnoreList; if (spectator) { if (!spectatorsAllowed) return RespSpectatorsNotAllowed; diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index d45d11be..f050b9fc 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -241,12 +241,8 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain enqueueProtocolItem(new Event_ServerMessage(server->getLoginMessage())); if (authState == PasswordRight) { - QList _buddyList = server->getBuddyList(userInfo->getName()); - for (int i = 0; i < _buddyList.size(); ++i) - buddyList.insert(_buddyList[i]->getName(), _buddyList[i]); - QList _ignoreList = server->getIgnoreList(userInfo->getName()); - for (int i = 0; i < _ignoreList.size(); ++i) - ignoreList.insert(_ignoreList[i]->getName(), _ignoreList[i]); + buddyList = server->getBuddyList(userInfo->getName()); + ignoreList = server->getIgnoreList(userInfo->getName()); // This might not scale very well. Use an extra QMap if it becomes a problem. const QList &serverGames = server->getGames(); diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index 2ff0855f..15ade424 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -228,9 +228,9 @@ ServerInfo_User *Servatrice::getUserData(const QString &name) return new ServerInfo_User(name, ServerInfo_User::IsUser); } -QList Servatrice::getBuddyList(const QString &name) +QMap Servatrice::getBuddyList(const QString &name) { - QList result; + QMap result; const QString method = settings->value("authentication/method").toString(); if (method == "sql") { @@ -242,15 +242,17 @@ QList Servatrice::getBuddyList(const QString &name) if (!execSqlQuery(query)) return result; - while (query.next()) - result.append(evalUserQueryResult(query, false)); + while (query.next()) { + ServerInfo_User *temp = evalUserQueryResult(query, false); + result.insert(temp->getName(), temp); + } } return result; } -QList Servatrice::getIgnoreList(const QString &name) +QMap Servatrice::getIgnoreList(const QString &name) { - QList result; + QMap result; const QString method = settings->value("authentication/method").toString(); if (method == "sql") { @@ -262,8 +264,10 @@ QList Servatrice::getIgnoreList(const QString &name) if (!execSqlQuery(query)) return result; - while (query.next()) - result.append(evalUserQueryResult(query, false)); + while (query.next()) { + ServerInfo_User *temp = evalUserQueryResult(query, false); + result.insert(temp->getName(), temp); + } } return result; } diff --git a/servatrice/src/servatrice.h b/servatrice/src/servatrice.h index 3aad67c1..66348cdf 100644 --- a/servatrice/src/servatrice.h +++ b/servatrice/src/servatrice.h @@ -51,8 +51,8 @@ public: protected: bool userExists(const QString &user); AuthenticationResult checkUserPassword(const QString &user, const QString &password); - QList getBuddyList(const QString &name); - QList getIgnoreList(const QString &name); + QMap getBuddyList(const QString &name); + QMap getIgnoreList(const QString &name); private: QTimer *pingClock, *statusUpdateClock; QTcpServer *tcpServer;