2019-07-17 19:37:18 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Variable.h"
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <query/Command.h>
|
|
|
|
#include <BasicChannel.h>
|
|
|
|
#include <Error.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include "../TSServer.h"
|
|
|
|
#include "../Group.h"
|
|
|
|
|
|
|
|
#define DEBUG_PERMISSION
|
|
|
|
|
|
|
|
namespace ts {
|
|
|
|
namespace music {
|
|
|
|
class MusicBotManager;
|
|
|
|
}
|
|
|
|
namespace server {
|
|
|
|
class TSServer;
|
|
|
|
|
|
|
|
class DataClient {
|
|
|
|
friend class TSServer;
|
|
|
|
friend class QueryServer;
|
|
|
|
friend class music::MusicBotManager;
|
|
|
|
public:
|
|
|
|
struct PropertyWrapper {
|
|
|
|
std::shared_ptr<Properties> handle;
|
|
|
|
|
|
|
|
Properties* operator->() {
|
|
|
|
return handle.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Properties* operator->() const {
|
|
|
|
return handle.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class F>
|
|
|
|
std::result_of_t<F(Properties &)> operator->*(F &&f) {
|
|
|
|
return std::forward<F>(f)(*handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class F>
|
|
|
|
std::result_of_t<F(Properties const &)> operator->*(F &&f) const {
|
|
|
|
return std::forward<F>(f)(*handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
ts::PropertyWrapper operator[](T type) {
|
|
|
|
return (*handle)[type];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DataClient(sql::SqlManager*, const std::shared_ptr<TSServer>&);
|
|
|
|
virtual ~DataClient();
|
|
|
|
|
|
|
|
|
|
|
|
PropertyWrapper properties(){ return { this->_properties }; }
|
|
|
|
|
|
|
|
virtual std::deque<std::pair<permission::PermissionType, permission::PermissionValue>> permissionValues(permission::PermissionTestType test,
|
|
|
|
const std::deque<permission::PermissionType>&,
|
|
|
|
const std::shared_ptr<BasicChannel>& channel = nullptr,
|
|
|
|
std::shared_ptr<CalculateCache> cache = nullptr,
|
|
|
|
std::shared_ptr<TSServer> server = nullptr,
|
|
|
|
bool server_defined = false);
|
|
|
|
inline permission::PermissionValue permissionValue(permission::PermissionType type, const std::shared_ptr<BasicChannel>& targetChannel = nullptr) {
|
|
|
|
return this->permissionValue(permission::PERMTEST_ORDERED, type, targetChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual permission::PermissionValue permissionValue(permission::PermissionTestType test,
|
|
|
|
permission::PermissionType,
|
|
|
|
const std::shared_ptr<BasicChannel>& channel = nullptr,
|
|
|
|
std::shared_ptr<CalculateCache> cache = nullptr,
|
|
|
|
std::shared_ptr<TSServer> server = nullptr,
|
|
|
|
bool server_defined = false);
|
|
|
|
|
|
|
|
virtual bool permissionGranted(permission::PermissionTestType test,
|
|
|
|
permission::PermissionType,
|
|
|
|
permission::PermissionValue,
|
|
|
|
const std::shared_ptr<BasicChannel>& channel = nullptr,
|
|
|
|
bool required = true,
|
|
|
|
std::shared_ptr<CalculateCache> cache = nullptr,
|
|
|
|
std::shared_ptr<TSServer> server = nullptr,
|
|
|
|
bool server_defined = false);
|
|
|
|
|
|
|
|
inline permission::PermissionValue getPermissionGrantValue(permission::PermissionType type, const std::shared_ptr<BasicChannel>& targetChannel = nullptr) {
|
|
|
|
return this->getPermissionGrantValue(permission::PERMTEST_ORDERED, type, targetChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual permission::PermissionValue getPermissionGrantValue(permission::PermissionTestType test, permission::PermissionType, const std::shared_ptr<BasicChannel>& targetChannel = nullptr);
|
|
|
|
virtual bool permissionGrantGranted(permission::PermissionTestType test, permission::PermissionType, permission::PermissionValue, const std::shared_ptr<BasicChannel>& targetChannel = nullptr, bool required = true);
|
|
|
|
|
2019-10-16 21:11:54 +02:00
|
|
|
template <typename T>
|
|
|
|
inline bool permission_granted(T, permission::PermissionValue, bool = false) = delete; /* only permission values */
|
|
|
|
[[deprecated]] __always_inline bool permission_granted(ts::permission::PermissionValue value, ts::permission::PermissionValue required, bool enforce_required = true) {
|
|
|
|
return DataClient::permission_granted({value, value != permNotGranted}, required, enforce_required);
|
2019-07-17 19:37:18 +02:00
|
|
|
}
|
|
|
|
|
2019-10-16 21:11:54 +02:00
|
|
|
static inline bool permission_granted(ts::permission::v2::PermissionFlaggedValue value, ts::permission::PermissionValue required, bool enforce_required = true) {
|
|
|
|
if(required == permNotGranted || required == 0) {
|
|
|
|
if(enforce_required)
|
|
|
|
return value.value == -1 || value.value > 0;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
} else if(!value.has_value) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if(value.value == -1)
|
|
|
|
return true;
|
|
|
|
else if(value.value >= required)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-17 19:37:18 +02:00
|
|
|
virtual std::vector<std::shared_ptr<GroupAssignment>> assignedServerGroups();
|
|
|
|
virtual std::shared_ptr<GroupAssignment> assignedChannelGroup(const std::shared_ptr<BasicChannel> &);
|
|
|
|
virtual bool serverGroupAssigned(const std::shared_ptr<Group> &);
|
|
|
|
virtual bool channelGroupAssigned(const std::shared_ptr<Group> &, const std::shared_ptr<BasicChannel> &);
|
|
|
|
|
|
|
|
virtual std::string getDisplayName() { return this->properties()[property::CLIENT_NICKNAME]; }
|
|
|
|
virtual std::string getLoginName() { return this->properties()[property::CLIENT_LOGIN_NAME]; }
|
|
|
|
virtual void setDisplayName(std::string displayName) { this->properties()[property::CLIENT_NICKNAME] = displayName; }
|
|
|
|
|
|
|
|
|
|
|
|
virtual ClientType getExternalType(){
|
|
|
|
uint8_t type = this->properties()[property::CLIENT_TYPE];
|
|
|
|
return (ClientType) type;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ClientType getType(){
|
|
|
|
uint8_t type = this->properties()[property::CLIENT_TYPE_EXACT];
|
|
|
|
return (ClientType) type;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::string getUid() { return this->properties()[property::CLIENT_UNIQUE_IDENTIFIER]; }
|
|
|
|
virtual std::string getAvatarId();
|
|
|
|
virtual ClientDbId getClientDatabaseId() { return this->properties()[property::CLIENT_DATABASE_ID]; }
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool loadDataForCurrentServer();
|
|
|
|
protected:
|
|
|
|
sql::SqlManager* sql;
|
|
|
|
std::shared_ptr<TSServer> server;
|
|
|
|
|
|
|
|
std::shared_ptr<permission::v2::PermissionManager> clientPermissions = nullptr;
|
|
|
|
std::shared_ptr<Properties> _properties;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|