more work on buddy&ignore
This commit is contained in:
parent
4149f78001
commit
0afdbc7222
9 changed files with 28 additions and 21 deletions
|
@ -21,8 +21,8 @@ public:
|
|||
protected:
|
||||
bool userExists(const QString & /*name*/) { return false; }
|
||||
ServerInfo_User *getUserData(const QString &name);
|
||||
QList<ServerInfo_User *> getBuddyList(const QString & /*name*/) { return QList<ServerInfo_User *>(); }
|
||||
QList<ServerInfo_User *> getIgnoreList(const QString & /*name*/) { return QList<ServerInfo_User *>(); }
|
||||
QMap<QString, ServerInfo_User *> getBuddyList(const QString & /*name*/) { return QMap<QString, ServerInfo_User *>(); }
|
||||
QMap<QString, ServerInfo_User *> getIgnoreList(const QString & /*name*/) { return QMap<QString, ServerInfo_User *>(); }
|
||||
};
|
||||
|
||||
#endif
|
|
@ -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: ;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -39,8 +39,8 @@ public:
|
|||
virtual int getMaxGameInactivityTime() const = 0;
|
||||
virtual int getMaxPlayerInactivityTime() const = 0;
|
||||
|
||||
virtual QList<ServerInfo_User *> getBuddyList(const QString &name) = 0;
|
||||
virtual QList<ServerInfo_User *> getIgnoreList(const QString &name) = 0;
|
||||
virtual QMap<QString, ServerInfo_User *> getBuddyList(const QString &name) = 0;
|
||||
virtual QMap<QString, ServerInfo_User *> getIgnoreList(const QString &name) = 0;
|
||||
protected:
|
||||
QMap<int, Server_Game *> games;
|
||||
QList<Server_ProtocolHandler *> clients;
|
||||
|
|
|
@ -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<Server_Room *>(parent())->getServer()->getBuddyList(creatorInfo->getName()).contains(user->getName()))
|
||||
return RespOnlyBuddies;
|
||||
if (static_cast<Server_Room *>(parent())->getServer()->getIgnoreList(creatorInfo->getName()).contains(user->getName()))
|
||||
return RespOnIgnoreList;
|
||||
if (spectator) {
|
||||
if (!spectatorsAllowed)
|
||||
return RespSpectatorsNotAllowed;
|
||||
|
|
|
@ -241,12 +241,8 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain
|
|||
enqueueProtocolItem(new Event_ServerMessage(server->getLoginMessage()));
|
||||
|
||||
if (authState == PasswordRight) {
|
||||
QList<ServerInfo_User *> _buddyList = server->getBuddyList(userInfo->getName());
|
||||
for (int i = 0; i < _buddyList.size(); ++i)
|
||||
buddyList.insert(_buddyList[i]->getName(), _buddyList[i]);
|
||||
QList<ServerInfo_User *> _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<Server_Game *> &serverGames = server->getGames();
|
||||
|
|
|
@ -228,9 +228,9 @@ ServerInfo_User *Servatrice::getUserData(const QString &name)
|
|||
return new ServerInfo_User(name, ServerInfo_User::IsUser);
|
||||
}
|
||||
|
||||
QList<ServerInfo_User *> Servatrice::getBuddyList(const QString &name)
|
||||
QMap<QString, ServerInfo_User *> Servatrice::getBuddyList(const QString &name)
|
||||
{
|
||||
QList<ServerInfo_User *> result;
|
||||
QMap<QString, ServerInfo_User *> result;
|
||||
|
||||
const QString method = settings->value("authentication/method").toString();
|
||||
if (method == "sql") {
|
||||
|
@ -242,15 +242,17 @@ QList<ServerInfo_User *> 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<ServerInfo_User *> Servatrice::getIgnoreList(const QString &name)
|
||||
QMap<QString, ServerInfo_User *> Servatrice::getIgnoreList(const QString &name)
|
||||
{
|
||||
QList<ServerInfo_User *> result;
|
||||
QMap<QString, ServerInfo_User *> result;
|
||||
|
||||
const QString method = settings->value("authentication/method").toString();
|
||||
if (method == "sql") {
|
||||
|
@ -262,8 +264,10 @@ QList<ServerInfo_User *> 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;
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ public:
|
|||
protected:
|
||||
bool userExists(const QString &user);
|
||||
AuthenticationResult checkUserPassword(const QString &user, const QString &password);
|
||||
QList<ServerInfo_User *> getBuddyList(const QString &name);
|
||||
QList<ServerInfo_User *> getIgnoreList(const QString &name);
|
||||
QMap<QString, ServerInfo_User *> getBuddyList(const QString &name);
|
||||
QMap<QString, ServerInfo_User *> getIgnoreList(const QString &name);
|
||||
private:
|
||||
QTimer *pingClock, *statusUpdateClock;
|
||||
QTcpServer *tcpServer;
|
||||
|
|
Loading…
Reference in a new issue