114 lines
4.5 KiB
C++
114 lines
4.5 KiB
C++
#pragma once
|
|
|
|
#include "Variable.h"
|
|
#include <string>
|
|
#include <utility>
|
|
#include <query/Command.h>
|
|
#include <BasicChannel.h>
|
|
#include <Error.h>
|
|
#include <netinet/in.h>
|
|
#include "src/VirtualServer.h"
|
|
#include "../Group.h"
|
|
|
|
#define DEBUG_PERMISSION
|
|
|
|
namespace ts {
|
|
namespace music {
|
|
class MusicBotManager;
|
|
}
|
|
namespace server {
|
|
class VirtualServer;
|
|
|
|
class DataClient {
|
|
friend class VirtualServer;
|
|
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<VirtualServer>&);
|
|
virtual ~DataClient();
|
|
|
|
|
|
PropertyWrapper properties(){ return { this->_properties }; }
|
|
|
|
/* main permission calculate function */
|
|
permission::v2::PermissionFlaggedValue calculate_permission(
|
|
permission::PermissionType,
|
|
ChannelId channel,
|
|
bool granted = false,
|
|
std::shared_ptr<CalculateCache> cache = nullptr
|
|
);
|
|
|
|
std::vector<std::pair<permission::PermissionType, permission::v2::PermissionFlaggedValue>> calculate_permissions(
|
|
const std::deque<permission::PermissionType>&,
|
|
ChannelId channel,
|
|
bool granted = false,
|
|
std::shared_ptr<CalculateCache> cache = nullptr
|
|
);
|
|
|
|
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();
|
|
|
|
[[nodiscard]] inline std::shared_ptr<permission::v2::PermissionRegister> permissions() { return this->clientPermissions; }
|
|
protected:
|
|
sql::SqlManager* sql;
|
|
std::shared_ptr<VirtualServer> server;
|
|
|
|
std::shared_ptr<permission::v2::PermissionRegister> clientPermissions = nullptr;
|
|
std::shared_ptr<Properties> _properties;
|
|
|
|
/* the current channel is save to access when the server channel tree has been locked (shared or exclusively) */
|
|
std::shared_ptr<BasicChannel> currentChannel{nullptr};
|
|
};
|
|
}
|
|
} |