mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-30 18:43:55 -07:00
Define permission levels for rooms
This commit is contained in:
parent
5634b564e8
commit
3e94c9d283
11 changed files with 67 additions and 18 deletions
|
|
@ -12,4 +12,5 @@ message ServerInfo_Room {
|
|||
repeated ServerInfo_Game game_list = 7;
|
||||
repeated ServerInfo_User user_list = 8;
|
||||
repeated ServerInfo_GameType gametype_list = 9;
|
||||
optional string permissionlevel = 10;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -542,6 +542,24 @@ Response::ResponseCode Server_ProtocolHandler::cmdJoinRoom(const Command_JoinRoo
|
|||
if (!r)
|
||||
return Response::RespNameNotFound;
|
||||
|
||||
QString roomPermission = r->getRoomPermission().toLower();
|
||||
if (roomPermission != "none"){
|
||||
if (roomPermission == "registered") {
|
||||
if (!(userInfo->user_level() & ServerInfo_User::IsRegistered))
|
||||
return Response::RespUserLevelTooLow;
|
||||
}
|
||||
|
||||
if (roomPermission == "moderator"){
|
||||
if (!(userInfo->user_level() & ServerInfo_User::IsModerator))
|
||||
return Response::RespUserLevelTooLow;
|
||||
}
|
||||
|
||||
if (roomPermission == "administrator"){
|
||||
if (!(userInfo->user_level() & ServerInfo_User::IsAdmin))
|
||||
return Response::RespUserLevelTooLow;
|
||||
}
|
||||
}
|
||||
|
||||
r->addClient(this);
|
||||
rooms.insert(r->getId(), r);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
#include "pb/serverinfo_room.pb.h"
|
||||
#include <google/protobuf/descriptor.h>
|
||||
|
||||
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
|
||||
: QObject(parent), id(_id), name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes), gamesLock(QReadWriteLock::Recursive)
|
||||
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, const QString &_permissionLevel, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
|
||||
: QObject(parent), id(_id), name(_name), description(_description), permissionLevel(_permissionLevel), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes), gamesLock(QReadWriteLock::Recursive)
|
||||
{
|
||||
connect(this, SIGNAL(gameListChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)), Qt::QueuedConnection);
|
||||
}
|
||||
|
|
@ -46,6 +46,7 @@ const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool comple
|
|||
result.set_name(name.toStdString());
|
||||
result.set_description(description.toStdString());
|
||||
result.set_auto_join(autoJoin);
|
||||
result.set_permissionlevel(permissionLevel.toStdString());
|
||||
|
||||
gamesLock.lockForRead();
|
||||
result.set_game_count(games.size() + externalGames.size());
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ private:
|
|||
int id;
|
||||
QString name;
|
||||
QString description;
|
||||
QString permissionLevel;
|
||||
bool autoJoin;
|
||||
QString joinMessage;
|
||||
QStringList gameTypes;
|
||||
|
|
@ -44,11 +45,12 @@ private slots:
|
|||
public:
|
||||
mutable QReadWriteLock usersLock;
|
||||
mutable QReadWriteLock gamesLock;
|
||||
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
|
||||
Server_Room(int _id, const QString &_name, const QString &_description, const QString &_permissionLevel, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
|
||||
~Server_Room();
|
||||
int getId() const { return id; }
|
||||
QString getName() const { return name; }
|
||||
QString getDescription() const { return description; }
|
||||
QString getRoomPermission() const { return permissionLevel; }
|
||||
bool getAutoJoin() const { return autoJoin; }
|
||||
QString getJoinMessage() const { return joinMessage; }
|
||||
const QStringList &getGameTypes() const { return gameTypes; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue