Optimized 1.4.11
This commit is contained in:
@@ -529,51 +529,66 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) {
|
||||
CMD_CHK_AND_INC_FLOOD_POINTS(25);
|
||||
CMD_CHK_PARM_COUNT(1);
|
||||
|
||||
//TODO: Use for this here the cache as well!
|
||||
auto permission_cache = make_shared<CalculateCache>();
|
||||
if (cmd[0].has("cpid") && cmd["cpid"].as<uint64_t>() != 0) ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_child, 1, permission_cache);
|
||||
if (cmd[0].has("channel_order")) ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_with_sortorder, 1, permission_cache);
|
||||
|
||||
if(!cmd[0].has("channel_flag_permanent")) cmd[0]["channel_flag_permanent"] = false;
|
||||
if(!cmd[0].has("channel_flag_semi_permanent")) cmd[0]["channel_flag_semi_permanent"] = false;
|
||||
if(!cmd[0].has("channel_flag_default")) cmd[0]["channel_flag_default"] = false;
|
||||
if(!cmd[0].has("channel_flag_password")) cmd[0]["channel_flag_password"] = false;
|
||||
|
||||
if (cmd[0]["channel_flag_permanent"].as<bool>()) ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_permanent, 1, permission_cache);
|
||||
else if (cmd[0]["channel_flag_semi_permanent"].as<bool>()) ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_semi_permanent, 1, permission_cache);
|
||||
else ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_temporary, 1, permission_cache);
|
||||
|
||||
if (!cmd[0]["channel_flag_permanent"].as<bool>() && !this->server) return command_result{error::parameter_invalid, "You can only create a permanent channel"};
|
||||
|
||||
if (cmd[0]["channel_flag_default"].as<bool>()) ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_with_default, 1, permission_cache);
|
||||
if (cmd[0]["channel_flag_password"].as<bool>()) ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_with_password, 1, permission_cache);
|
||||
else if(permission::v2::permission_granted(1, this->calculate_permission(permission::b_channel_create_modify_with_force_password, 0, false, permission_cache)))
|
||||
return command_result{permission::b_channel_create_modify_with_force_password};
|
||||
|
||||
if(cmd[0].has("channel_password") && this->getType() == ClientType::CLIENT_QUERY)
|
||||
cmd["channel_password"] = base64::decode(digest::sha1(cmd["channel_password"].string()));
|
||||
if (cmd[0].has("channel_description")) ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_with_description, 1, permission_cache);
|
||||
if (cmd[0].has("channel_maxclients") || (cmd[0].has("channel_flag_maxclients_unlimited") && !cmd["channel_flag_maxclients_unlimited"].as<bool>())) {
|
||||
ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_with_maxclients, 1, permission_cache);
|
||||
if(!cmd[0]["channel_flag_permanent"].as<bool>() && !cmd[0]["channel_flag_semi_permanent"].as<bool>()) {
|
||||
cmd["channel_maxclients"] = -1;
|
||||
cmd["channel_flag_maxclients_unlimited"] = 1;
|
||||
}
|
||||
}
|
||||
if (cmd[0].has("channel_maxfamilyclients")) ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_with_maxfamilyclients, 1, permission_cache);
|
||||
if (cmd[0].has("channel_needed_talk_power")) ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_with_needed_talk_power, 1, permission_cache);
|
||||
if (cmd[0].has("channel_topic")) ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_with_topic, 1, permission_cache);
|
||||
std::shared_ptr<TreeView::LinkedTreeEntry> parent = nullptr;
|
||||
std::shared_ptr<BasicChannel> created_channel = nullptr, old_default_channel;
|
||||
|
||||
auto target_tree = this->server ? this->server->channelTree : serverInstance->getChannelTree().get();
|
||||
auto& tree_lock = this->server ? this->server->channel_tree_lock : serverInstance->getChannelTreeLock();
|
||||
unique_lock tree_channel_lock(tree_lock);
|
||||
|
||||
if (cmd[0].has("cpid") && cmd["cpid"].as<ChannelId>() != 0 && cmd["cpid"].as<int>() != -1) {
|
||||
parent = target_tree->findLinkedChannel(cmd["cpid"].as<ChannelId>());
|
||||
if (!parent) return command_result{error::channel_invalid_id, "Cant resolve parent channel"};
|
||||
}
|
||||
ChannelId parent_channel_id = parent ? parent->entry->channelId() : 0;
|
||||
|
||||
#define test_permission(required, permission_type) \
|
||||
do {\
|
||||
if(!permission::v2::permission_granted(required, this->calculate_permission(permission_type, parent_channel_id, false, permission_cache))) \
|
||||
return command_result{permission_type};\
|
||||
} while(0)
|
||||
|
||||
|
||||
//TODO: Use for this here the cache as well!
|
||||
auto permission_cache = make_shared<CalculateCache>();
|
||||
if(parent) test_permission(1, permission::b_channel_create_child);
|
||||
if (cmd[0].has("channel_order")) test_permission(1, permission::b_channel_create_with_sortorder);
|
||||
if(!cmd[0].has("channel_flag_permanent")) cmd[0]["channel_flag_permanent"] = false;
|
||||
if(!cmd[0].has("channel_flag_semi_permanent")) cmd[0]["channel_flag_semi_permanent"] = false;
|
||||
if(!cmd[0].has("channel_flag_default")) cmd[0]["channel_flag_default"] = false;
|
||||
if(!cmd[0].has("channel_flag_password")) cmd[0]["channel_flag_password"] = false;
|
||||
|
||||
if (cmd[0]["channel_flag_permanent"].as<bool>()) test_permission(1, permission::b_channel_create_permanent);
|
||||
else if (cmd[0]["channel_flag_semi_permanent"].as<bool>()) test_permission(1, permission::b_channel_create_semi_permanent);
|
||||
else test_permission(1, permission::b_channel_create_temporary);
|
||||
|
||||
if (!cmd[0]["channel_flag_permanent"].as<bool>() && !this->server) return command_result{error::parameter_invalid, "You can only create a permanent channel"};
|
||||
|
||||
if (cmd[0]["channel_flag_default"].as<bool>()) test_permission(1, permission::b_channel_create_with_default);
|
||||
if (cmd[0]["channel_flag_password"].as<bool>()) test_permission(1, permission::b_channel_create_with_password);
|
||||
else if(permission::v2::permission_granted(1, this->calculate_permission(permission::b_channel_create_modify_with_force_password, parent_channel_id, false, permission_cache)))
|
||||
return command_result{permission::b_channel_create_modify_with_force_password};
|
||||
|
||||
if(cmd[0].has("channel_password") && this->getType() == ClientType::CLIENT_QUERY)
|
||||
cmd["channel_password"] = base64::decode(digest::sha1(cmd["channel_password"].string()));
|
||||
if (cmd[0].has("channel_description")) test_permission(1, permission::b_channel_create_with_description);
|
||||
if (cmd[0].has("channel_maxclients") || (cmd[0].has("channel_flag_maxclients_unlimited") && !cmd["channel_flag_maxclients_unlimited"].as<bool>())) {
|
||||
test_permission(1, permission::b_channel_create_with_maxclients);
|
||||
if(!cmd[0]["channel_flag_permanent"].as<bool>() && !cmd[0]["channel_flag_semi_permanent"].as<bool>()) {
|
||||
cmd["channel_maxclients"] = -1;
|
||||
cmd["channel_flag_maxclients_unlimited"] = 1;
|
||||
}
|
||||
}
|
||||
if (cmd[0].has("channel_maxfamilyclients")) test_permission(1, permission::b_channel_create_with_maxfamilyclients);
|
||||
if (cmd[0].has("channel_needed_talk_power")) test_permission(1,permission::b_channel_create_with_needed_talk_power);
|
||||
if (cmd[0].has("channel_topic")) test_permission(1,permission::b_channel_create_with_topic);
|
||||
|
||||
if(cmd[0].has("channel_conversation_history_length")) {
|
||||
auto value = cmd["channel_conversation_history_length"].as<int64_t>();
|
||||
if(value == 0) {
|
||||
ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::b_channel_create_modify_conversation_history_unlimited, 1, permission_cache);
|
||||
test_permission(1, permission::b_channel_create_modify_conversation_history_unlimited);
|
||||
} else {
|
||||
ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::i_channel_create_modify_conversation_history_length, 1, permission_cache);
|
||||
test_permission(1, permission::i_channel_create_modify_conversation_history_length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,9 +600,10 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) {
|
||||
else
|
||||
cmd["channel_delete_delay"] = 0;
|
||||
} else {
|
||||
ACTION_REQUIRES_GLOBAL_PERMISSION_CACHED(permission::i_channel_create_modify_with_temp_delete_delay, cmd["channel_delete_delay"].as<permission::PermissionValue>(), permission_cache);
|
||||
test_permission(cmd["channel_delete_delay"].as<permission::PermissionValue>(), permission::i_channel_create_modify_with_temp_delete_delay);
|
||||
}
|
||||
}
|
||||
#undef test_permission
|
||||
|
||||
{
|
||||
size_t created_total = 0, created_tmp = 0, created_semi = 0, created_perm = 0;
|
||||
@@ -607,14 +623,14 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) {
|
||||
if(this->server && created_total >= this->server->properties()[property::VIRTUALSERVER_MAX_CHANNELS].as<uint64_t>())
|
||||
return command_result{error::channel_limit_reached};
|
||||
|
||||
auto max_channels = this->calculate_permission(permission::i_client_max_channels, 0, false, permission_cache);
|
||||
auto max_channels = this->calculate_permission(permission::i_client_max_channels, parent_channel_id, false, permission_cache);
|
||||
if(max_channels.has_value) {
|
||||
if(!permission::v2::permission_granted(created_perm + created_semi + created_tmp + 1, max_channels))
|
||||
return command_result{permission::i_client_max_channels};
|
||||
}
|
||||
|
||||
if (cmd[0]["channel_flag_permanent"].as<bool>()) {
|
||||
max_channels = this->calculate_permission(permission::i_client_max_permanent_channels, 0, false, permission_cache);
|
||||
max_channels = this->calculate_permission(permission::i_client_max_permanent_channels, parent_channel_id, false, permission_cache);
|
||||
|
||||
if(max_channels.has_value) {
|
||||
if(!permission::v2::permission_granted(created_perm + 1, max_channels))
|
||||
@@ -622,7 +638,7 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) {
|
||||
}
|
||||
}
|
||||
else if (cmd[0]["channel_flag_semi_permanent"].as<bool>()) {
|
||||
max_channels = this->calculate_permission(permission::i_client_max_semi_channels, 0, false, permission_cache);
|
||||
max_channels = this->calculate_permission(permission::i_client_max_semi_channels, parent_channel_id, false, permission_cache);
|
||||
|
||||
if(max_channels.has_value) {
|
||||
if(!permission::v2::permission_granted(created_semi + 1, max_channels))
|
||||
@@ -630,7 +646,7 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
max_channels = this->calculate_permission(permission::i_client_max_temporary_channels, 0, false, permission_cache);
|
||||
max_channels = this->calculate_permission(permission::i_client_max_temporary_channels, parent_channel_id, false, permission_cache);
|
||||
|
||||
if(max_channels.has_value) {
|
||||
if(!permission::v2::permission_granted(created_tmp + 1, max_channels))
|
||||
@@ -640,20 +656,12 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) {
|
||||
}
|
||||
|
||||
//TODO check voice (opus etc)
|
||||
std::shared_ptr<TreeView::LinkedTreeEntry> parent = nullptr;
|
||||
std::shared_ptr<BasicChannel> created_channel = nullptr, old_default_channel;
|
||||
|
||||
//bool enforce_permanent_parent = cmd[0]["channel_flag_default"].as<bool>(); //TODO check parents here
|
||||
{ //Checkout the parent(s)
|
||||
if (cmd[0].has("cpid") && cmd["cpid"].as<ChannelId>() != 0 && cmd["cpid"].as<int>() != -1) {
|
||||
parent = target_tree->findLinkedChannel(cmd["cpid"].as<ChannelId>());
|
||||
if (!parent) return command_result{error::channel_invalid_id, "Cant resolve parent channel"};
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
auto min_channel_deep = this->calculate_permission(permission::i_channel_min_depth, 0, false, permission_cache);
|
||||
auto max_channel_deep = this->calculate_permission(permission::i_channel_max_depth, 0, false, permission_cache);
|
||||
auto min_channel_deep = this->calculate_permission(permission::i_channel_min_depth, parent_channel_id, false, permission_cache);
|
||||
auto max_channel_deep = this->calculate_permission(permission::i_channel_max_depth, parent_channel_id, false, permission_cache);
|
||||
|
||||
if(min_channel_deep.has_value || max_channel_deep.has_value) {
|
||||
auto channel_deep = 0;
|
||||
@@ -704,8 +712,8 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) {
|
||||
created_channel->properties()[property::CHANNEL_CREATED_BY] = this->getClientDatabaseId();
|
||||
|
||||
{
|
||||
auto default_modify_power = this->calculate_permission(permission::i_channel_modify_power, 0, false, permission_cache);
|
||||
auto default_delete_power = this->calculate_permission(permission::i_channel_delete_power, 0, false, permission_cache);
|
||||
auto default_modify_power = this->calculate_permission(permission::i_channel_modify_power, parent_channel_id, false, permission_cache);
|
||||
auto default_delete_power = this->calculate_permission(permission::i_channel_delete_power, parent_channel_id, false, permission_cache);
|
||||
|
||||
auto permission_manager = created_channel->permissions();
|
||||
permission_manager->set_permission(
|
||||
|
||||
Reference in New Issue
Block a user