#pragma once #include #include #include #include namespace ts { class BasicChannel; } namespace ts::server { class DataClient; class VirtualServer; namespace groups { class ChannelGroup; class ServerGroup; class GroupManager; } /** * Helper for calculating the client permissions for a certain channel. * Note: All functions are not thread save! */ class ClientPermissionCalculator { public: explicit ClientPermissionCalculator(DataClient* /* client */, const std::shared_ptr& /* target channel */); explicit ClientPermissionCalculator(DataClient* /* client */, ChannelId /* target channel id */); explicit ClientPermissionCalculator( const std::shared_ptr& /* server */, ClientDbId /* client database id */, ClientType /* client type */, ChannelId /* target channel id */ ); /** * Calculate the given permissions. * This method can be called from everywhere without any locking needed. * @param granted * @return */ permission::v2::PermissionFlaggedValue calculate_permission( permission::PermissionType, bool granted = false ); /** * Calculate the given permissions. * This method can be called from everywhere without any locking needed. * @param channel * @param calculate_granted * @return */ std::vector> calculate_permissions( const std::deque&, bool calculate_granted = false ); private: /* given fields */ ServerId virtual_server_id; ClientDbId client_database_id; ClientType client_type; ChannelId channel_id_; std::shared_ptr group_manager_{}; std::shared_ptr channel_permissions{}; std::function()> default_channel_group{[]{ return nullptr; }}; /* fields which will be set when calculating permissions */ std::shared_ptr client_permissions{}; bool global_skip{false}; bool global_skip_set{false}; std::optional> assigned_channel_group_{}; std::optional>> assigned_server_groups_{}; void initialize_client(DataClient* /* client */); [[nodiscard]] const std::vector>& assigned_server_groups(); [[nodiscard]] const std::shared_ptr& assigned_channel_group(); }; }