74 lines
2.5 KiB
C++
74 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <PermissionRegister.h>
|
|
|
|
namespace ts::server {
|
|
namespace groups {
|
|
class ServerGroup;
|
|
class ChannelGroup;
|
|
}
|
|
namespace vserver {
|
|
class VirtualServerBase;
|
|
}
|
|
}
|
|
|
|
namespace ts::server::permissions {
|
|
struct CalculateCache {
|
|
ClientDbId client_database_id{0};
|
|
ClientType client_type{ClientType::UNKNOWN};
|
|
|
|
std::shared_ptr<permission::v2::PermissionRegister> client_permissions;
|
|
std::vector<std::shared_ptr<groups::ServerGroup>> assignment_server_groups;
|
|
bool assignment_server_groups_set{false};
|
|
|
|
ChannelId assignment_channel_group_channel{0};
|
|
std::shared_ptr<groups::ChannelGroup> assignment_channel_group{};
|
|
|
|
std::shared_ptr<BasicChannel> server_channel;
|
|
ChannelId last_server_channel{0};
|
|
};
|
|
|
|
enum struct PermissionResetResult {
|
|
SUCCESS
|
|
};
|
|
|
|
class PermissionService {
|
|
public:
|
|
explicit PermissionService(vserver::VirtualServerBase*);
|
|
~PermissionService() = default;
|
|
|
|
bool initialize(std::string& /* error */);
|
|
|
|
bool load_data(std::string& /* error */);
|
|
void unload_data();
|
|
|
|
PermissionResetResult reset_server_permissions();
|
|
|
|
permission::v2::PermissionFlaggedValue calculate_client_permission(
|
|
permission::PermissionType,
|
|
ClientDbId,
|
|
ClientType type,
|
|
ChannelId channel,
|
|
bool granted,
|
|
std::shared_ptr<CalculateCache> cache = nullptr
|
|
);
|
|
|
|
std::vector<std::pair<permission::PermissionType, permission::v2::PermissionFlaggedValue>> calculate_client_permissions(
|
|
const std::deque<permission::PermissionType>&,
|
|
ClientDbId,
|
|
ClientType type,
|
|
ChannelId channel,
|
|
bool granted,
|
|
std::shared_ptr<CalculateCache> cache = nullptr
|
|
);
|
|
private:
|
|
vserver::VirtualServerBase* virtual_server_{nullptr};
|
|
|
|
[[nodiscard]] ServerId get_server_id() const;
|
|
|
|
void load_group_assignments(const std::shared_ptr<CalculateCache>&);
|
|
void load_channel_assignment(const std::shared_ptr<CalculateCache>&, ChannelId /* channel id */);
|
|
void load_server_channel(const std::shared_ptr<CalculateCache>&, ChannelId /* channel id */);
|
|
};
|
|
} |