Some more work for the new group manager

This commit is contained in:
WolverinDEV
2021-03-07 19:17:20 +01:00
parent 449df23a4b
commit 2d0b9da08d
19 changed files with 956 additions and 834 deletions
+30 -42
View File
@@ -8,6 +8,7 @@
#include <misc/sassert.h>
#include <src/manager/ActionLogger.h>
#include "InstanceHandler.h"
#include "./groups/GroupManager.h"
using namespace std;
using namespace ts::server;
@@ -264,33 +265,6 @@ void VirtualServer::testBanStateChange(const std::shared_ptr<ConnectedClient>& i
});
}
bool VirtualServer::could_default_create_channel() {
{
auto default_group = this->group_manager()->defaultGroup(GroupTarget::GROUPTARGET_SERVER);
if(default_group) {
auto flag = default_group->permissions()->permission_value_flagged(permission::b_channel_create_temporary).value == 1;
flag = flag ? flag : default_group->permissions()->permission_value_flagged(permission::b_channel_create_semi_permanent).value == 1;
flag = flag ? flag : default_group->permissions()->permission_value_flagged(permission::b_channel_create_permanent).value == 1;
if(flag)
return true;
}
}
{
auto default_group = this->group_manager()->defaultGroup(GroupTarget::GROUPTARGET_CHANNEL);
if(default_group) {
auto flag = default_group->permissions()->permission_value_flagged(permission::b_channel_create_temporary).value == 1;
flag = flag ? flag : default_group->permissions()->permission_value_flagged(permission::b_channel_create_semi_permanent).value == 1;
flag = flag ? flag : default_group->permissions()->permission_value_flagged(permission::b_channel_create_permanent).value == 1;
if(flag)
return true;
}
}
return false;
}
void VirtualServer::notify_client_ban(const shared_ptr<ConnectedClient> &target, const std::shared_ptr<ts::server::ConnectedClient> &invoker, const std::string &reason, size_t time) {
/* the target is not allowed to execute anything; Must before channel tree lock because the target may waits for us to finish the channel stuff */
lock_guard command_lock(target->command_lock);
@@ -394,11 +368,13 @@ void VirtualServer::delete_channel(shared_ptr<ts::ServerChannel> channel, const
command_locks.push_back(move(unique_lock(client->command_lock)));
}
for(const auto& client : clients)
for(const auto& client : clients) {
this->client_move(client, default_channel, invoker, kick_message, ViewReasonId::VREASON_CHANNEL_KICK, true, tree_lock);
}
if(!tree_lock.owns_lock())
if(!tree_lock.owns_lock()) {
tree_lock.lock(); /* no clients left within that tree */
}
command_locks.clear();
auto deleted_channels = this->channelTree->delete_channel_root(channel);
@@ -412,7 +388,25 @@ void VirtualServer::delete_channel(shared_ptr<ts::ServerChannel> channel, const
client->notifyChannelDeleted(client->channels->delete_channel_root(channel), invoker);
});
this->tokenManager->handle_channel_deleted(channel->channelId());
{
std::vector<ChannelId> deleted_channel_ids{};
deleted_channel_ids.reserve(deleted_channels.size());
for(const auto& deleted_channel : deleted_channels) {
deleted_channel_ids.push_back(deleted_channel->channelId());
}
auto ref_self = this->ref();
task_id task_id{};
serverInstance->general_task_executor()->schedule(task_id, "database cleanup after channel delete", [ref_self, deleted_channel_ids]{
for(const auto& deleted_channel_id : deleted_channel_ids) {
ref_self->tokenManager->handle_channel_deleted(deleted_channel_id);
}
for(const auto& deleted_channel_id : deleted_channel_ids) {
ref_self->group_manager()->assignments().handle_channel_deleted(deleted_channel_id);
}
});
}
}
void VirtualServer::client_move(
@@ -450,10 +444,6 @@ void VirtualServer::client_move(
s_target_channel = dynamic_pointer_cast<ServerChannel>(target_channel);
assert(s_target_channel);
}
/* update the group properties here already, so for all enter views we could just send the new props directly */
changed_groups = this->groups->update_server_group_property(target, true, s_target_channel);
client_updates.insert(client_updates.end(), changed_groups.begin(), changed_groups.end()); //TODO: Only update for clients which have no enter?
}
auto l_target_channel = s_target_channel ? this->channelTree->findLinkedChannel(s_target_channel->channelId()) : nullptr;
auto l_source_channel = s_source_channel ? this->channelTree->findLinkedChannel(s_source_channel->channelId()) : nullptr;
@@ -560,12 +550,7 @@ void VirtualServer::client_move(
if (s_source_channel) {
s_source_channel->properties()[property::CHANNEL_LAST_LEFT] = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
auto source_channel_group = this->groups->getChannelGroupExact(target->getClientDatabaseId(), s_source_channel, false);
if(source_channel_group) {
auto default_data = source_channel_group->group->permissions()->permission_value_flagged(permission::b_group_is_permanent);
if(!default_data.has_value || default_data.value != 1)
this->groups->setChannelGroup(target->getClientDatabaseId(), nullptr, s_source_channel);
}
this->group_manager()->assignments().cleanup_channel_temporary_assignment(target->getClientDatabaseId(), s_source_channel->channelId());
auto update = target->properties()[property::CLIENT_IS_TALKER].as_or<bool>(false) ||
target->properties()[property::CLIENT_TALK_REQUEST].as_or<int64_t>(0) > 0;
@@ -582,15 +567,18 @@ void VirtualServer::client_move(
if (s_target_channel) {
target->task_update_needed_permissions.enqueue();
target->task_update_displayed_groups.enqueue();
TIMING_STEP(timings, "perm gr upd");
if(s_source_channel) {
deque<ChannelId> deleted;
for(const auto& channel : target->channels->test_channel(l_source_channel, l_target_channel))
for(const auto& channel : target->channels->test_channel(l_source_channel, l_target_channel)) {
deleted.push_back(channel->channelId());
}
if(!deleted.empty())
if(!deleted.empty()) {
target->notifyChannelHide(deleted, false);
}
auto i_source_channel = s_source_channel->channelId();
if(std::find(deleted.begin(), deleted.end(), i_source_channel) == deleted.end()) {