diff --git a/server/src/client/command_handler/channel.cpp b/server/src/client/command_handler/channel.cpp index 7840118..d3588b3 100644 --- a/server/src/client/command_handler/channel.cpp +++ b/server/src/client/command_handler/channel.cpp @@ -1,32 +1,32 @@ #include -#include -#include -#include "../../build.h" -#include "../ConnectedClient.h" -#include "../InternalClient.h" -#include "../../server/VoiceServer.h" -#include "../voice/VoiceClient.h" -#include "PermissionManager.h" #include "../../InstanceHandler.h" -#include "../../server/QueryServer.h" -#include "../music/MusicClient.h" -#include "../query/QueryClient.h" -#include "../../weblist/WebListManager.h" +#include "../../build.h" +#include "../../manager/ActionLogger.h" #include "../../manager/ConversationManager.h" #include "../../manager/PermissionNameMapper.h" -#include "../../manager/ActionLogger.h" +#include "../../server/QueryServer.h" +#include "../../server/VoiceServer.h" +#include "../../weblist/WebListManager.h" +#include "../ConnectedClient.h" +#include "../InternalClient.h" +#include "../music/MusicClient.h" +#include "../query/QueryClient.h" +#include "../voice/VoiceClient.h" +#include "PermissionManager.h" +#include +#include #include -#include "helpers.h" #include "./bulk_parsers.h" +#include "helpers.h" #include +#include #include -#include #include #include -#include +#include using namespace std::chrono; using namespace std; @@ -43,9 +43,9 @@ command_result ConnectedClient::handleCommandChannelGetDescription(Command &cmd) auto channel = dynamic_pointer_cast(l_channel->entry); assert(channel); - if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_channel_ignore_description_view_power, channel->channelId()))) { + if (!permission::v2::permission_granted(1, this->calculate_permission(permission::b_channel_ignore_description_view_power, channel->channelId()))) { auto view_power = this->calculate_permission(permission::i_channel_description_view_power, channel->channelId()); - if(!channel->permission_granted(permission::i_channel_needed_description_view_power, view_power, false)) + if (!channel->permission_granted(permission::i_channel_needed_description_view_power, view_power, false)) return command_result{permission::i_channel_description_view_power}; } @@ -66,7 +66,7 @@ command_result ConnectedClient::handleCommandChannelSubscribe(Command &cmd) { for (int index = 0; index < cmd.bulkCount(); index++) { auto local_channel = this->channel_view()->find_channel(cmd[index]["cid"].as()); - if(!local_channel) + if (!local_channel) return command_result{error::channel_invalid_id, "Cant resolve channel"}; auto channel = this->server->channelTree->findChannel(cmd[index]["cid"].as()); @@ -74,13 +74,13 @@ command_result ConnectedClient::handleCommandChannelSubscribe(Command &cmd) { return command_result{error::channel_invalid_id, "Cant resolve channel"}; channels.push_back(channel); - if(!flood_points && system_clock::now() - local_channel->view_timestamp > seconds(5)) { + if (!flood_points && system_clock::now() - local_channel->view_timestamp > seconds(5)) { flood_points = true; CMD_CHK_AND_INC_FLOOD_POINTS(15); } } - if(!channels.empty()) + if (!channels.empty()) this->subscribeChannel(channels, false, false); } @@ -109,9 +109,9 @@ command_result ConnectedClient::handleCommandChannelUnsubscribe(Command &cmd) { unique_lock client_channel_lock(this->channel_lock); deque> channels; - for(int index = 0; index < cmd.bulkCount(); index++) { + for (int index = 0; index < cmd.bulkCount(); index++) { auto channel = this->server->channelTree->findChannel(cmd["cid"].as()); - if(!channel) continue; + if (!channel) continue; channels.push_front(channel); } @@ -141,23 +141,23 @@ command_result ConnectedClient::handleCommandChannelGroupAdd(Command &cmd) { auto group_manager = this->server ? this->server->getGroupManager() : serverInstance->getGroupManager().get(); log::GroupType log_group_type; - if(cmd["type"].as() == GroupType::GROUP_TYPE_QUERY) { + if (cmd["type"].as() == GroupType::GROUP_TYPE_QUERY) { ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_serverinstance_modify_querygroup, 1); log_group_type = log::GroupType::QUERY; - } else if(cmd["type"].as() == GroupType::GROUP_TYPE_TEMPLATE) { + } else if (cmd["type"].as() == GroupType::GROUP_TYPE_TEMPLATE) { ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_serverinstance_modify_templates, 1); log_group_type = log::GroupType::TEMPLATE; } else { - if(!this->server) + if (!this->server) return command_result{error::parameter_invalid, "you cant create normal groups on the template server!"}; log_group_type = log::GroupType::NORMAL; } - if(cmd["name"].string().empty()) + if (cmd["name"].string().empty()) return command_result{error::parameter_invalid, "invalid group name"}; - for(const auto& gr : group_manager->availableServerGroups(true)) - if(gr->name() == cmd["name"].string() && gr->target() == GroupTarget::GROUPTARGET_CHANNEL) + for (const auto &gr : group_manager->availableServerGroups(true)) + if (gr->name() == cmd["name"].string() && gr->target() == GroupTarget::GROUPTARGET_CHANNEL) return command_result{error::parameter_invalid, "Group already exists"}; auto group = group_manager->createGroup(GroupTarget::GROUPTARGET_CHANNEL, cmd["type"].as(), cmd["name"].string()); @@ -171,22 +171,23 @@ command_result ConnectedClient::handleCommandChannelGroupAdd(Command &cmd) { if (group) { group->permissions()->set_permission(permission::b_group_is_permanent, {1, 0}, permission::v2::set_value, permission::v2::do_nothing); - if(this->server) { - if(this->getType() == ClientType::CLIENT_QUERY) { - this->server->forEachClient([&](const std::shared_ptr& cl) { - if(cl == this) { + if (this->server) { + if (this->getType() == ClientType::CLIENT_QUERY) { + this->server->forEachClient([&](const std::shared_ptr &cl) { + if (cl == this) { return; } cl->notifyChannelGroupList(); }); } else { - this->server->forEachClient([](const std::shared_ptr& cl) { + this->server->forEachClient([](const std::shared_ptr &cl) { cl->notifyChannelGroupList(); }); } } - } else return command_result{error::group_invalid_id}; + } else + return command_result{error::group_invalid_id}; return command_result{error::ok}; } @@ -203,17 +204,17 @@ command_result ConnectedClient::handleCommandChannelGroupCopy(Command &cmd) { auto source_group_id = cmd["scgid"].as(); auto source_group = group_manager->findGroup(source_group_id); - if(!source_group || source_group->target() != GROUPTARGET_CHANNEL) + if (!source_group || source_group->target() != GROUPTARGET_CHANNEL) return command_result{error::group_invalid_id, "invalid source group"}; const auto group_type_modificable = [&](GroupType type) { - switch(type) { + switch (type) { case GroupType::GROUP_TYPE_TEMPLATE: - if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_serverinstance_modify_templates, 0))) + if (!permission::v2::permission_granted(1, this->calculate_permission(permission::b_serverinstance_modify_templates, 0))) return permission::b_serverinstance_modify_templates; break; case GroupType::GROUP_TYPE_QUERY: - if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_serverinstance_modify_querygroup, 0))) + if (!permission::v2::permission_granted(1, this->calculate_permission(permission::b_serverinstance_modify_querygroup, 0))) return permission::b_serverinstance_modify_querygroup; break; @@ -226,27 +227,27 @@ command_result ConnectedClient::handleCommandChannelGroupCopy(Command &cmd) { { auto result = group_type_modificable(source_group->type()); - if(result != permission::undefined) + if (result != permission::undefined) return command_result{result}; } auto global_update = false; - if(cmd[0].has("tcgid") && cmd["tcgid"].as() != 0) { + if (cmd[0].has("tcgid") && cmd["tcgid"].as() != 0) { //Copy an existing group auto target_group = group_manager->findGroup(cmd["tcgid"]); - if(!target_group || target_group->target() != GROUPTARGET_CHANNEL) + if (!target_group || target_group->target() != GROUPTARGET_CHANNEL) return command_result{error::group_invalid_id, "invalid target group"}; { auto result = group_type_modificable(target_group->type()); - if(result != permission::undefined) + if (result != permission::undefined) return command_result{result}; } - if(!target_group->permission_granted(permission::i_channel_group_needed_modify_power, this->calculate_permission(permission::i_channel_group_modify_power, 0), true)) + if (!target_group->permission_granted(permission::i_channel_group_needed_modify_power, this->calculate_permission(permission::i_channel_group_modify_power, 0), true)) return command_result{permission::i_channel_group_modify_power}; - if(!group_manager->copyGroupPermissions(source_group, target_group)) + if (!group_manager->copyGroupPermissions(source_group, target_group)) return command_result{error::vs_critical, "failed to copy group permissions"}; log::GroupType log_group_type; @@ -278,7 +279,7 @@ command_result ConnectedClient::handleCommandChannelGroupCopy(Command &cmd) { { auto result = group_type_modificable(target_type); - if(result != permission::undefined) + if (result != permission::undefined) return command_result{result}; } @@ -300,19 +301,19 @@ command_result ConnectedClient::handleCommandChannelGroupCopy(Command &cmd) { return command_result{error::parameter_invalid, "type"}; } - if(!ref_server && target_type == GroupType::GROUP_TYPE_NORMAL) + if (!ref_server && target_type == GroupType::GROUP_TYPE_NORMAL) return command_result{error::parameter_invalid, "You cant create normal groups on the template server!"}; - if(!group_manager->findGroup(GroupTarget::GROUPTARGET_CHANNEL, cmd["name"].string()).empty()) + if (!group_manager->findGroup(GroupTarget::GROUPTARGET_CHANNEL, cmd["name"].string()).empty()) return command_result{error::group_name_inuse, "You cant create normal groups on the template server!"}; auto target_group_id = group_manager->copyGroup(source_group, target_type, cmd["name"], target_type != GroupType::GROUP_TYPE_NORMAL ? 0 : this->getServerId()); - if(target_group_id == 0) + if (target_group_id == 0) return command_result{error::vs_critical, "failed to copy group"}; serverInstance->action_logger()->group_logger.log_group_create(target_type != GroupType::GROUP_TYPE_NORMAL ? 0 : this->getServerId(), this->ref(), log::GroupTarget::CHANNEL, log_group_type, target_group_id, cmd["name"], source_group->groupId(), source_group->name()); - if(this->getType() == ClientType::CLIENT_QUERY) { + if (this->getType() == ClientType::CLIENT_QUERY) { Command notify(""); notify["cgid"] = target_group_id; this->sendCommand(notify); @@ -321,8 +322,8 @@ command_result ConnectedClient::handleCommandChannelGroupCopy(Command &cmd) { global_update = !this->server || !group_manager->isLocalGroup(group_manager->findGroup(target_group_id)); } - for(const auto& server : (global_update ? serverInstance->getVoiceServerManager()->serverInstances() : deque>{this->server})) - if(server) + for (const auto &server : (global_update ? serverInstance->getVoiceServerManager()->serverInstances() : deque>{this->server})) + if (server) server->forEachClient([](shared_ptr cl) { cl->notifyChannelGroupList(); }); @@ -341,10 +342,10 @@ command_result ConnectedClient::handleCommandChannelGroupRename(Command &cmd) { auto type = channel_group->type(); log::GroupType log_group_type; - if(type == GroupType::GROUP_TYPE_QUERY) { + if (type == GroupType::GROUP_TYPE_QUERY) { ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_serverinstance_modify_querygroup, 1); log_group_type = log::GroupType::QUERY; - } else if(type == GroupType::GROUP_TYPE_TEMPLATE) { + } else if (type == GroupType::GROUP_TYPE_TEMPLATE) { ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_serverinstance_modify_templates, 1); log_group_type = log::GroupType::TEMPLATE; } else { @@ -355,7 +356,7 @@ command_result ConnectedClient::handleCommandChannelGroupRename(Command &cmd) { group_manager->renameGroup(channel_group, cmd["name"].string()); serverInstance->action_logger()->group_logger.log_group_rename(this->getServerId(), this->ref(), log::GroupTarget::CHANNEL, log_group_type, channel_group->groupId(), channel_group->name(), old_name); - if(this->server) + if (this->server) this->server->forEachClient([](shared_ptr cl) { cl->notifyChannelGroupList(); }); @@ -372,24 +373,24 @@ command_result ConnectedClient::handleCommandChannelGroupDel(Command &cmd) { auto channel_group = group_manager->findGroup(cmd["cgid"].as()); if (!channel_group || channel_group->target() != GROUPTARGET_CHANNEL) return command_result{error::parameter_invalid, "invalid channel group id"}; - if(this->server) { - if(this->server->properties()[property::VIRTUALSERVER_DEFAULT_CHANNEL_GROUP] == channel_group->groupId()) + if (this->server) { + if (this->server->properties()[property::VIRTUALSERVER_DEFAULT_CHANNEL_GROUP] == channel_group->groupId()) return command_result{error::parameter_invalid, "Could not delete default channel group!"}; - if(this->server->properties()[property::VIRTUALSERVER_DEFAULT_CHANNEL_ADMIN_GROUP] == channel_group->groupId()) + if (this->server->properties()[property::VIRTUALSERVER_DEFAULT_CHANNEL_ADMIN_GROUP] == channel_group->groupId()) return command_result{error::parameter_invalid, "Could not delete default channel admin group!"}; } - if(serverInstance->properties()[property::SERVERINSTANCE_TEMPLATE_CHANNELDEFAULT_GROUP] == channel_group->groupId()) + if (serverInstance->properties()[property::SERVERINSTANCE_TEMPLATE_CHANNELDEFAULT_GROUP] == channel_group->groupId()) return command_result{error::parameter_invalid, "Could not delete instance default channel group!"}; - if(serverInstance->properties()[property::SERVERINSTANCE_TEMPLATE_CHANNELADMIN_GROUP] == channel_group->groupId()) + if (serverInstance->properties()[property::SERVERINSTANCE_TEMPLATE_CHANNELADMIN_GROUP] == channel_group->groupId()) return command_result{error::parameter_invalid, "Could not delete instance default channel admin group!"}; auto type = channel_group->type(); log::GroupType log_group_type; - if(type == GroupType::GROUP_TYPE_QUERY) { + if (type == GroupType::GROUP_TYPE_QUERY) { ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_serverinstance_modify_querygroup, 1); log_group_type = log::GroupType::QUERY; - } else if(type == GroupType::GROUP_TYPE_TEMPLATE) { + } else if (type == GroupType::GROUP_TYPE_TEMPLATE) { ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_serverinstance_modify_templates, 1); log_group_type = log::GroupType::TEMPLATE; } else { @@ -402,10 +403,10 @@ command_result ConnectedClient::handleCommandChannelGroupDel(Command &cmd) { if (group_manager->deleteGroup(channel_group)) { serverInstance->action_logger()->group_logger.log_group_delete(this->getServerId(), this->ref(), log::GroupTarget::SERVER, log_group_type, channel_group->groupId(), channel_group->name()); - if(this->server) { + if (this->server) { this->server->forEachClient([&](shared_ptr cl) { - if(this->server->notifyClientPropertyUpdates(cl, this->server->groups->update_server_group_property(cl, true, cl->getChannel()))) { - if(cl->update_cached_permissions()) /* update cached calculated permissions */ + if (this->server->notifyClientPropertyUpdates(cl, this->server->groups->update_server_group_property(cl, true, cl->getChannel()))) { + if (cl->update_cached_permissions()) /* update cached calculated permissions */ cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ } cl->notifyChannelGroupList(); @@ -431,7 +432,7 @@ command_result ConnectedClient::handleCommandChannelGroupClientList(Command &cmd CMD_RESET_IDLE; CMD_CHK_AND_INC_FLOOD_POINTS(5); auto target_channel_id = cmd[0].has("cid") ? cmd["cid"].as() : 0; - if(target_channel_id > 0) { + if (target_channel_id > 0) { ACTION_REQUIRES_PERMISSION(permission::b_virtualserver_channelgroup_client_list, 1, target_channel_id); } else { ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_virtualserver_channelgroup_client_list, 1); @@ -441,9 +442,9 @@ command_result ConnectedClient::handleCommandChannelGroupClientList(Command &cmd deque variables{variable{":sid", this->getServerId()}}; string query = "SELECT `groupId`, `cldbid`, `until`, `channelId` FROM `assignedGroups` WHERE `serverId` = :sid"; - if(cmd[0].has("cgid") && cmd["cgid"].as() > 0) { + if (cmd[0].has("cgid") && cmd["cgid"].as() > 0) { auto group = this->server->getGroupManager()->findGroup(cmd["cgid"]); - if(!group || group->target() != GroupTarget::GROUPTARGET_CHANNEL) + if (!group || group->target() != GroupTarget::GROUPTARGET_CHANNEL) return command_result{error::parameter_invalid, "invalid channel group id"}; query += " AND `groupId` = :groupId"; variables.push_back({":groupId", cmd["cgid"].as()}); @@ -451,13 +452,13 @@ command_result ConnectedClient::handleCommandChannelGroupClientList(Command &cmd query += " AND `groupId` IN (SELECT `groupId` FROM `groups` WHERE `serverId` = :sid AND `target` = :target)"; variables.push_back({":target", GroupTarget::GROUPTARGET_CHANNEL}); } - if(cmd[0].has("cldbid") && cmd["cldbid"].as() > 0) { + if (cmd[0].has("cldbid") && cmd["cldbid"].as() > 0) { query += " AND `cldbid` = :cldbid"; variables.push_back({":cldbid", cmd["cldbid"].as()}); } - if(cmd[0].has("cid") && cmd["cid"].as() > 0) { + if (cmd[0].has("cid") && cmd["cid"].as() > 0) { auto channel = this->server->getChannelTree()->findChannel(cmd["cid"]); - if(!channel) + if (!channel) return command_result{error::parameter_invalid, "invalid channel id"}; query += " AND `channelId` = :cid"; variables.push_back({":cid", cmd["cid"].as()}); @@ -465,23 +466,23 @@ command_result ConnectedClient::handleCommandChannelGroupClientList(Command &cmd debugMessage(this->getServerId(), "Command channelgroupclientlist sql: {}", query); auto command = sql::command(this->sql, query); - for(const auto& variable : variables) + for (const auto &variable : variables) command.value(variable); int index = 0; - command.query([&](Command& command, int& index, int length, string* values, string* names) { + command.query([&](Command &command, int &index, int length, string *values, string *names) { GroupId group_id = 0; ChannelId channel_id = 0; ClientDbId cldbid = 0; - for(int i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { try { - if(names[i] == "groupId") + if (names[i] == "groupId") group_id = stoll(values[i]); - else if(names[i] == "cldbid") + else if (names[i] == "cldbid") cldbid = stoll(values[i]); - else if(names[i] == "channelId") + else if (names[i] == "channelId") channel_id = stoll(values[i]); - } catch(std::exception& ex) { + } catch (std::exception &ex) { logError(this->getServerId(), "Failed to parse db field {}", names[i]); } } @@ -489,7 +490,8 @@ command_result ConnectedClient::handleCommandChannelGroupClientList(Command &cmd result[index]["cgid"] = group_id; result[index]["cldbid"] = cldbid; index++; - }, result, index); + }, + result, index); if (index == 0) return command_result{error::database_empty_result}; this->sendCommand(result); return command_result{error::ok}; @@ -503,7 +505,7 @@ command_result ConnectedClient::handleCommandChannelGroupPermList(Command &cmd) if (!channelGroup || channelGroup->target() != GROUPTARGET_CHANNEL) return command_result{error::parameter_invalid, "invalid channel group id"}; if (!this->notifyGroupPermList(channelGroup, cmd.hasParm("permsid"))) return command_result{error::database_empty_result}; - if(this->getType() == ClientType::CLIENT_TEAMSPEAK && this->command_times.last_notify + this->command_times.notify_timeout < system_clock::now()) { + if (this->getType() == ClientType::CLIENT_TEAMSPEAK && this->command_times.last_notify + this->command_times.notify_timeout < system_clock::now()) { this->sendTSPermEditorWarning(); } @@ -519,11 +521,11 @@ command_result ConnectedClient::handleCommandChannelGroupAddPerm(Command &cmd) { ACTION_REQUIRES_GROUP_PERMISSION(channelGroup, permission::i_channel_group_needed_modify_power, permission::i_channel_group_modify_power, true); command::bulk_parser::PermissionBulksParser pparser{cmd}; - if(!pparser.validate(this->ref(), 0)) + if (!pparser.validate(this->ref(), 0)) return pparser.build_command_result(); bool updateList{false}; - for(const auto& ppermission : pparser.iterate_valid_permissions()) { + for (const auto &ppermission : pparser.iterate_valid_permissions()) { ppermission.apply_to(channelGroup->permissions(), permission::v2::PermissionUpdateType::set_value); ppermission.log_update(serverInstance->action_logger()->permission_logger, this->getServerId(), @@ -531,24 +533,23 @@ command_result ConnectedClient::handleCommandChannelGroupAddPerm(Command &cmd) { log::PermissionTarget::CHANNEL_GROUP, permission::v2::PermissionUpdateType::set_value, 0, "", - channelGroup->groupId(), channelGroup->name() - ); + channelGroup->groupId(), channelGroup->name()); updateList |= ppermission.is_group_property(); } - if(updateList) + if (updateList) channelGroup->apply_properties_from_permissions(); - if(this->server) { - if(updateList) + if (this->server) { + if (updateList) this->server->forEachClient([](shared_ptr cl) { cl->notifyChannelGroupList(); }); this->server->forEachClient([channelGroup](shared_ptr cl) { unique_lock client_channel_lock(cl->channel_lock); /* while we're updating groups we dont want to change anything! */ if (cl->channelGroupAssigned(channelGroup, cl->getChannel())) { - if(cl->update_cached_permissions()) + if (cl->update_cached_permissions()) cl->sendNeededPermissions(false); /* update the needed permissions */ cl->updateChannelClientProperties(false, true); cl->join_state_id++; /* join permission may changed, all channels need to be recalculate dif needed */ @@ -567,11 +568,11 @@ command_result ConnectedClient::handleCommandChannelGroupDelPerm(Command &cmd) { ACTION_REQUIRES_GROUP_PERMISSION(channelGroup, permission::i_channel_group_needed_modify_power, permission::i_channel_group_modify_power, true); command::bulk_parser::PermissionBulksParser pparser{cmd}; - if(!pparser.validate(this->ref(), 0)) + if (!pparser.validate(this->ref(), 0)) return pparser.build_command_result(); bool updateList{false}; - for(const auto& ppermission : pparser.iterate_valid_permissions()) { + for (const auto &ppermission : pparser.iterate_valid_permissions()) { ppermission.apply_to(channelGroup->permissions(), permission::v2::PermissionUpdateType::delete_value); ppermission.log_update(serverInstance->action_logger()->permission_logger, this->getServerId(), @@ -579,23 +580,22 @@ command_result ConnectedClient::handleCommandChannelGroupDelPerm(Command &cmd) { log::PermissionTarget::CHANNEL_GROUP, permission::v2::PermissionUpdateType::delete_value, 0, "", - channelGroup->groupId(), channelGroup->name() - ); + channelGroup->groupId(), channelGroup->name()); updateList |= ppermission.is_group_property(); } - if(updateList) + if (updateList) channelGroup->apply_properties_from_permissions(); - if(this->server) { - if(updateList) + if (this->server) { + if (updateList) this->server->forEachClient([](shared_ptr cl) { cl->notifyChannelGroupList(); }); this->server->forEachClient([channelGroup](shared_ptr cl) { unique_lock client_channel_lock(cl->channel_lock); /* while we're updating groups we dont want to change anything! */ if (cl->channelGroupAssigned(channelGroup, cl->getChannel())) { - if(cl->update_cached_permissions()) /* update cached calculated permissions */ + if (cl->update_cached_permissions()) /* update cached calculated permissions */ cl->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ cl->updateChannelClientProperties(false, false); cl->join_state_id++; /* join permission may changed, all channels need to be recalculate dif needed */ @@ -616,7 +616,7 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { std::shared_ptr 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(); + 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() != 0 && cmd["cpid"].as() != -1) { @@ -625,50 +625,52 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { } 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) +#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(); - if(parent) test_permission(1, permission::b_channel_create_child); + 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].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()) test_permission(1, permission::b_channel_create_permanent); - else if (cmd[0]["channel_flag_semi_permanent"].as()) test_permission(1, permission::b_channel_create_semi_permanent); - else test_permission(1, permission::b_channel_create_temporary); + else if (cmd[0]["channel_flag_semi_permanent"].as()) + 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() && !this->server) return command_result{error::parameter_invalid, "You can only create a permanent channel"}; if (cmd[0]["channel_flag_default"].as()) test_permission(1, permission::b_channel_create_with_default); if (cmd[0]["channel_flag_password"].as()) 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))) + 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) + 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())) { test_permission(1, permission::b_channel_create_with_maxclients); - if(!cmd[0]["channel_flag_permanent"].as() && !cmd[0]["channel_flag_semi_permanent"].as()) { + if (!cmd[0]["channel_flag_permanent"].as() && !cmd[0]["channel_flag_semi_permanent"].as()) { 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_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")) { + if (cmd[0].has("channel_conversation_history_length")) { auto value = cmd["channel_conversation_history_length"].as(); - if(value == 0) { + if (value == 0) { test_permission(1, permission::b_channel_create_modify_conversation_history_unlimited); } else { test_permission(1, permission::i_channel_create_modify_conversation_history_length); @@ -677,8 +679,8 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { { auto delete_delay = cmd[0].has("channel_delete_delay") ? cmd["channel_delete_delay"].as() : 0UL; - if(delete_delay == 0) { - if(this->server) + if (delete_delay == 0) { + if (this->server) cmd["channel_delete_delay"] = this->server->properties()[property::VIRTUALSERVER_CHANNEL_TEMP_DELETE_DELAY_DEFAULT].as(); else cmd["channel_delete_delay"] = 0; @@ -691,48 +693,46 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { { size_t created_total = 0, created_tmp = 0, created_semi = 0, created_perm = 0; auto own_cldbid = this->getClientDatabaseId(); - for(const auto& channel : target_tree->channels()) { + for (const auto &channel : target_tree->channels()) { created_total++; - if(channel->properties()[property::CHANNEL_CREATED_BY] == own_cldbid) { - if(channel->properties()[property::CHANNEL_FLAG_PERMANENT].as()) + if (channel->properties()[property::CHANNEL_CREATED_BY] == own_cldbid) { + if (channel->properties()[property::CHANNEL_FLAG_PERMANENT].as()) created_perm++; - else if(channel->properties()[property::CHANNEL_FLAG_SEMI_PERMANENT].as()) + else if (channel->properties()[property::CHANNEL_FLAG_SEMI_PERMANENT].as()) created_semi++; else created_tmp++; } } - if(this->server && created_total >= this->server->properties()[property::VIRTUALSERVER_MAX_CHANNELS].as()) + if (this->server && created_total >= this->server->properties()[property::VIRTUALSERVER_MAX_CHANNELS].as()) return command_result{error::channel_limit_reached}; 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)) + 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()) { 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)) + if (max_channels.has_value) { + if (!permission::v2::permission_granted(created_perm + 1, max_channels)) return command_result{permission::i_client_max_permanent_channels}; } - } - else if (cmd[0]["channel_flag_semi_permanent"].as()) { + } else if (cmd[0]["channel_flag_semi_permanent"].as()) { 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)) + if (max_channels.has_value) { + if (!permission::v2::permission_granted(created_semi + 1, max_channels)) return command_result{permission::i_client_max_semi_channels}; } - } - else { + } else { 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)) + if (max_channels.has_value) { + if (!permission::v2::permission_granted(created_tmp + 1, max_channels)) return command_result{permission::i_client_max_temporary_channels}; } } @@ -740,38 +740,37 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { //TODO check voice (opus etc) //bool enforce_permanent_parent = cmd[0]["channel_flag_default"].as(); //TODO check parents here - { //Checkout the parent(s) + {//Checkout the parent(s) { 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) { + if (min_channel_deep.has_value || max_channel_deep.has_value) { auto channel_deep = 0; auto local_parent = parent; - while(local_parent) { + while (local_parent) { channel_deep++; { const auto typed_parent = dynamic_pointer_cast(local_parent->entry); - if(typed_parent->deleted) return command_result{error::channel_is_deleted, "One of the parents has been deleted"}; + if (typed_parent->deleted) return command_result{error::channel_is_deleted, "One of the parents has been deleted"}; } local_parent = local_parent->parent.lock(); } - if(min_channel_deep.has_value && (channel_deep < min_channel_deep.value && !min_channel_deep.has_infinite_power())) return command_result{permission::i_channel_min_depth}; - if(max_channel_deep.has_value && !permission::v2::permission_granted(channel_deep, max_channel_deep)) return command_result{permission::i_channel_max_depth}; + if (min_channel_deep.has_value && (channel_deep < min_channel_deep.value && !min_channel_deep.has_infinite_power())) return command_result{permission::i_channel_min_depth}; + if (max_channel_deep.has_value && !permission::v2::permission_granted(channel_deep, max_channel_deep)) return command_result{permission::i_channel_max_depth}; } } } - if(!cmd[0].has("channel_order")) { + if (!cmd[0].has("channel_order")) { auto last = parent ? parent->child_head : target_tree->tree_head(); - while(last && last->next) + while (last && last->next) last = last->next; - if(last) + if (last) cmd["channel_order"] = last->entry->channelId(); } else { - } if (cmd["channel_name"].string().length() < 1) { @@ -779,11 +778,11 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { } if (cmd[0].has("channel_name") && count_characters(cmd["channel_name"]) > 40) { - return command_result{error::channel_name_invalid}; + return command_result{error::channel_name_invalid}; } if (count_characters(cmd["channel_name_phonetic"]) > 40) { - return command_result{error::channel_name_invalid}; + return command_result{error::channel_name_invalid}; } { @@ -813,14 +812,12 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { permission::i_channel_needed_modify_power, {default_modify_power.has_value ? default_modify_power.value : 0, 0}, permission::v2::PermissionUpdateType::set_value, - permission::v2::PermissionUpdateType::do_nothing - ); + permission::v2::PermissionUpdateType::do_nothing); permission_manager->set_permission( permission::i_channel_needed_delete_power, {default_delete_power.has_value ? default_delete_power.value : 0, 0}, permission::v2::PermissionUpdateType::set_value, - permission::v2::PermissionUpdateType::do_nothing - ); + permission::v2::PermissionUpdateType::do_nothing); } /* log channel create */ @@ -851,37 +848,37 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { if (property_name == "cid") continue; const auto &property = property::find(property_name); - if(property == property::CHANNEL_UNDEFINED) { + if (property == property::CHANNEL_UNDEFINED) { logError(this->getServerId(), "Client " + this->getDisplayName() + " tried to change a not existing channel property " + property_name); continue; } - if(!property.validate_input(cmd[property_name].as())) { + if (!property.validate_input(cmd[property_name].as())) { logError(this->getServerId(), "Client " + this->getDisplayName() + " tried to change a property to an invalid value. (Value: '" + cmd[property_name].as() + "', Property: '" + std::string{property.name} + "')"); continue; } auto prop = created_channel->properties()[property]; auto old_value = prop.value(); auto new_value = cmd[property_name].as(); - if(old_value == new_value) + if (old_value == new_value) continue; prop = new_value; serverInstance->action_logger()->channel_logger.log_channel_edit(this->getServerId(), this->ref(), created_channel->channelId(), property, old_value, new_value); } - if(created_channel->parent()) { - if(created_channel->parent()->channelType() > created_channel->channelType()) + if (created_channel->parent()) { + if (created_channel->parent()->channelType() > created_channel->channelType()) created_channel->setChannelType(created_channel->parent()->channelType()); } - if(this->server) { + if (this->server) { const auto self_lock = _this.lock(); - this->server->forEachClient([&, created_channel](const shared_ptr& client) { + this->server->forEachClient([&, created_channel](const shared_ptr &client) { unique_lock client_channel_lock(client->channel_lock); auto result = client->channels->add_channel(created_linked_channel); - if(!result) return; + if (!result) return; client->notifyChannelCreate(created_channel, result->previous_channel, self_lock); - if(client == self_lock && this->getType() == ClientType::CLIENT_QUERY) { + if (client == self_lock && this->getType() == ClientType::CLIENT_QUERY) { Command notify(""); notify["cid"] = created_channel->channelId(); this->sendCommand(notify); @@ -890,7 +887,7 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { if (client->subscribeToAll) client->subscribeChannel({created_channel}, false, true); - if(old_default_channel) { + if (old_default_channel) { //TODO: Reminder: client channel tree must be at least read locked here! client->notifyChannelEdited(old_default_channel, {property::CHANNEL_FLAG_DEFAULT}, self_lock, false); } @@ -914,8 +911,7 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { "channel created", ViewReasonId::VREASON_USER_ACTION, true, - tree_channel_lock - ); + tree_channel_lock); } return command_result{error::ok}; @@ -928,24 +924,24 @@ command_result ConnectedClient::handleCommandChannelDelete(Command &cmd) { RESOLVE_CHANNEL_W(cmd["cid"], true); auto channel = dynamic_pointer_cast(l_channel->entry); assert(channel); - if(channel->deleted) /* channel gets already removed */ + if (channel->deleted) /* channel gets already removed */ return command_result{error::ok}; ACTION_REQUIRES_CHANNEL_PERMISSION(channel, permission::i_channel_needed_delete_power, permission::i_channel_delete_power, true); - for(const auto& ch : channel_tree->channels(channel)) { - if(ch->defaultChannel()) + for (const auto &ch : channel_tree->channels(channel)) { + if (ch->defaultChannel()) return command_result{error::channel_can_not_delete_default}; } - if(this->server) { + if (this->server) { auto clients = this->server->getClientsByChannelRoot(channel, false); - if(!clients.empty()) + if (!clients.empty()) ACTION_REQUIRES_PERMISSION(permission::b_channel_delete_flag_force, 1, channel->channelId()); this->server->delete_channel(channel, this->ref(), "channel deleted", channel_tree_write_lock, false); } else { auto deleted_channel_ids = channel_tree->deleteChannelRoot(channel); - for(const auto& channelId : deleted_channel_ids) { + for (const auto &channelId : deleted_channel_ids) { serverInstance->action_logger()->channel_logger.log_channel_delete(0, this->ref(), channelId, channel->channelId() == channelId ? log::ChannelDeleteReason::USER_ACTION : log::ChannelDeleteReason::PARENT_DELETED); } this->notifyChannelDeleted(deleted_channel_ids, this->ref()); @@ -967,12 +963,12 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { RESOLVE_CHANNEL_R(cmd["cid"], true); auto channel = dynamic_pointer_cast(l_channel->entry); assert(channel); - if(channel->deleted) { + if (channel->deleted) { /* channel gets already removed */ return command_result{error::ok}; } - std::deque keys; + std::deque keys; bool require_write_lock = false; bool update_max_clients = false; bool update_max_family_clients = false; @@ -986,37 +982,37 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { ACTION_REQUIRES_CHANNEL_PERMISSION(channel, permission::i_channel_needed_modify_power, permission::i_channel_modify_power, true); for (const auto &key : cmd[0].keys()) { - if(key == "cid") + if (key == "cid") continue; - if(key == "return_code") + if (key == "return_code") continue; const auto &property = property::find(key); - if(property == property::CHANNEL_UNDEFINED) { + if (property == property::CHANNEL_UNDEFINED) { logError(this->getServerId(), R"({} Tried to edit a not existing channel property "{}" to "{}")", CLIENT_STR_LOG_PREFIX, key, cmd[key].string()); continue; } - if((property.flags & property::FLAG_USER_EDITABLE) == 0) { + if ((property.flags & property::FLAG_USER_EDITABLE) == 0) { logError(this->getServerId(), "{} Tried to change a channel property which is not changeable. (Key: {}, Value: \"{}\")", CLIENT_STR_LOG_PREFIX, key, cmd[key].string()); continue; } - if(!property.validate_input(cmd[key].as())) { + if (!property.validate_input(cmd[key].as())) { logError(this->getServerId(), "{} Tried to change a channel property to an invalid value. (Key: {}, Value: \"{}\")", CLIENT_STR_LOG_PREFIX, key, cmd[key].string()); continue; } - if(channel->properties()[property].as() == cmd[key].as()) + if (channel->properties()[property].as() == cmd[key].as()) continue; /* we dont need to update stuff which is the same */ - if(key == "channel_icon_id") { + if (key == "channel_icon_id") { ACTION_REQUIRES_CHANNEL_PERMISSION(channel, permission::i_channel_needed_permission_modify_power, permission::i_channel_permission_modify_power, true); } else if (key == "channel_order") { ACTION_REQUIRES_PERMISSION(permission::b_channel_modify_sortorder, 1, channel_id); require_write_lock = true; } else if (key == "channel_flag_default") { - if(!cmd["channel_flag_default"].as()) + if (!cmd["channel_flag_default"].as()) return command_result{error::channel_invalid_flags}; ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_channel_modify_make_default, 1); @@ -1024,35 +1020,35 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { } else if (key == "channel_name") { ACTION_REQUIRES_PERMISSION(permission::b_channel_modify_name, 1, channel_id); if (count_characters(cmd["channel_name"]) < 1) { - return command_result{error::channel_name_invalid}; + return command_result{error::channel_name_invalid}; } if (count_characters(cmd["channel_name"]) > 40) { - return command_result{error::channel_name_invalid}; + return command_result{error::channel_name_invalid}; } require_write_lock = true; update_name = true; } else if (key == "channel_name_phonetic") { if (count_characters(cmd["channel_name_phonetic"]) > 40) { - return command_result{error::parameter_invalid, "channel_name_phonetic"}; + return command_result{error::parameter_invalid, "channel_name_phonetic"}; } ACTION_REQUIRES_PERMISSION(permission::b_channel_modify_name, 1, channel_id); } else if (key == "channel_topic") { ACTION_REQUIRES_PERMISSION(permission::b_channel_modify_topic, 1, channel_id); } else if (key == "channel_description") { ACTION_REQUIRES_PERMISSION(permission::b_channel_modify_description, 1, channel_id); - if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_use_bbcode_any, channel_id))) { + if (!permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_use_bbcode_any, channel_id))) { auto bbcode_image = bbcode::sloppy::has_image(cmd[key]); auto bbcode_url = bbcode::sloppy::has_url(cmd[key]); debugMessage(this->getServerId(), "Channel description contains bb codes: Image: {} URL: {}", bbcode_image, bbcode_url); - if(bbcode_image && !permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_use_bbcode_image, channel_id))) + if (bbcode_image && !permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_use_bbcode_image, channel_id))) return command_result{permission::b_client_use_bbcode_image}; - if(bbcode_url && !permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_use_bbcode_url, channel_id))) + if (bbcode_url && !permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_use_bbcode_url, channel_id))) return command_result{permission::b_client_use_bbcode_url}; } } else if (key == "channel_codec") { ACTION_REQUIRES_PERMISSION(permission::b_channel_modify_codec, 1, channel_id); auto value = cmd[key].as(); - if(!(value >= 4 && value <= 5)) { + if (!(value >= 4 && value <= 5)) { return command_result{error::parameter_invalid, "channel_codec"}; } } else if (key == "channel_codec_quality") { @@ -1067,7 +1063,7 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { ACTION_REQUIRES_PERMISSION(permission::b_channel_modify_maxclients, 1, channel_id); require_write_lock = true; update_max_clients = true; - } else if(key == "channel_maxfamilyclients" || key == "channel_flag_maxfamilyclients_unlimited" || key == "channel_flag_maxfamilyclients_inherited") { + } else if (key == "channel_maxfamilyclients" || key == "channel_flag_maxfamilyclients_unlimited" || key == "channel_flag_maxfamilyclients_inherited") { ACTION_REQUIRES_PERMISSION(permission::b_channel_modify_maxfamilyclients, 1, channel_id); require_write_lock = true; update_max_family_clients = true; @@ -1091,14 +1087,14 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { update_password = true; } else if (key == "channel_conversation_history_length") { auto value = cmd["channel_conversation_history_length"].as(); - if(value == 0) { + if (value == 0) { ACTION_REQUIRES_PERMISSION(permission::b_channel_create_modify_conversation_history_unlimited, 1, channel_id); } else { ACTION_REQUIRES_PERMISSION(permission::i_channel_create_modify_conversation_history_length, 1, channel_id); } } else if (key == "channel_flag_conversation_private") { auto value = cmd["channel_flag_conversation_private"].as(); - if(value) { + if (value) { ACTION_REQUIRES_PERMISSION(permission::b_channel_create_modify_conversation_mode_private, 1, channel_id); cmd[property::name(property::CHANNEL_CONVERSATION_MODE)] = CHANNELCONVERSATIONMODE_PRIVATE; } else { @@ -1126,45 +1122,44 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { logCritical( this->getServerId(), "The client " + this->getDisplayName() + " tried to change a editable channel property but we haven't found a permission. Please report this error. (Channel property: {})", - key - ); + key); continue; } keys.push_back(&property); } - if(keys.empty()) + if (keys.empty()) return command_result{error::ok}; unique_lock server_channel_w_lock(this->server ? this->server->channel_tree_lock : serverInstance->getChannelTreeLock(), defer_lock); - if(require_write_lock) { + if (require_write_lock) { channel_tree_read_lock.unlock(); server_channel_w_lock.lock(); /* not that while we're waiting to edit the server the channel got deleted... fuck my english */ - if(channel->deleted) + if (channel->deleted) return command_result{error::ok}; } /* test the password parameters */ - if(update_password) { - if(!cmd[0].has("channel_password")) { - if(cmd[0].has("channel_flag_password") && cmd["channel_flag_password"].as()) + if (update_password) { + if (!cmd[0].has("channel_password")) { + if (cmd[0].has("channel_flag_password") && cmd["channel_flag_password"].as()) return command_result{error::parameter_missing}; else cmd["channel_password"] = ""; /* no password set */ keys.push_back(&property::describe(property::CHANNEL_PASSWORD)); } - if(!cmd[0].has("channel_flag_password")) { + if (!cmd[0].has("channel_flag_password")) { cmd["channel_flag_password"] = !cmd["channel_password"].string().empty(); keys.push_back(&property::describe(property::CHANNEL_FLAG_PASSWORD)); } - if(cmd["channel_flag_password"].as()) { - if(cmd["channel_password"].string().empty()) + if (cmd["channel_flag_password"].as()) { + if (cmd["channel_password"].string().empty()) return command_result{error::channel_invalid_flags}; /* we cant enable a password without a given password */ /* we've to "encode" the password */ - if(this->getType() == ClientType ::CLIENT_QUERY) + if (this->getType() == ClientType ::CLIENT_QUERY) cmd["channel_password"] = base64::encode(digest::sha1(cmd["channel_password"].string())); } else { cmd["channel_password"] = ""; /* flag password if false so we set the password to empty */ @@ -1173,17 +1168,17 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { /* test the default channel update */ const auto target_will_be_default = cmd[0].has("channel_flag_default") ? cmd["channel_flag_default"].as() : channel->defaultChannel(); - if(target_will_be_default) { - if(target_channel_type != ChannelType::permanent) + if (target_will_be_default) { + if (target_channel_type != ChannelType::permanent) return command_result{error::channel_default_require_permanent}; /* default channel is not allowed to be non permanent */ - if((cmd[0].has("channel_flag_password") && cmd["channel_flag_password"].as()) || channel->properties()[property::CHANNEL_FLAG_PASSWORD]) { + if ((cmd[0].has("channel_flag_password") && cmd["channel_flag_password"].as()) || channel->properties()[property::CHANNEL_FLAG_PASSWORD]) { cmd["channel_flag_password"] = false; cmd["channel_password"] = ""; keys.push_back(&property::describe(property::CHANNEL_FLAG_PASSWORD)); } - if(target_will_be_default) { + if (target_will_be_default) { cmd["channel_maxclients"] = -1; cmd["channel_flag_maxclients_unlimited"] = true; keys.push_back(&property::describe(property::CHANNEL_MAXCLIENTS)); @@ -1199,16 +1194,16 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { } /* "fix" max client for temporary channels */ - if(target_channel_type_changed) { - if(target_channel_type == ChannelType::temporary) { - if(channel->properties()[property::CHANNEL_MAXCLIENTS].as() != -1) { + if (target_channel_type_changed) { + if (target_channel_type == ChannelType::temporary) { + if (channel->properties()[property::CHANNEL_MAXCLIENTS].as() != -1) { cmd["channel_maxclients"] = -1; cmd["channel_flag_maxclients_unlimited"] = true; keys.push_back(&property::describe(property::CHANNEL_MAXCLIENTS)); keys.push_back(&property::describe(property::CHANNEL_FLAG_MAXCLIENTS_UNLIMITED)); update_max_clients = true; } - if(channel->properties()[property::CHANNEL_MAXFAMILYCLIENTS].as() != -1) { + if (channel->properties()[property::CHANNEL_MAXFAMILYCLIENTS].as() != -1) { cmd["channel_maxfamilyclients"] = -1; cmd["channel_flag_maxfamilyclients_inherited"] = true; keys.push_back(&property::describe(property::CHANNEL_MAXFAMILYCLIENTS)); @@ -1217,51 +1212,51 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { } } - if(target_channel_type != ChannelType::permanent) { + if (target_channel_type != ChannelType::permanent) { /* test if any child is the default channel */ - for(const auto& child : channel_tree->channels(channel)) - if(child->defaultChannel()) + for (const auto &child : channel_tree->channels(channel)) + if (child->defaultChannel()) return command_result{error::channel_default_require_permanent}; /* default channel is not allowed to be non permanent */ } auto parent = channel->parent(); - if(parent && parent->channelType() > target_channel_type) + if (parent && parent->channelType() > target_channel_type) return command_result{error::channel_parent_not_permanent}; } /* test the max clients parameters */ - if(update_max_clients) { - if(!cmd[0].has("channel_maxclients")) { - if(cmd[0].has("channel_flag_maxclients_unlimited") && cmd["channel_flag_maxclients_unlimited"].as()) + if (update_max_clients) { + if (!cmd[0].has("channel_maxclients")) { + if (cmd[0].has("channel_flag_maxclients_unlimited") && cmd["channel_flag_maxclients_unlimited"].as()) cmd["channel_maxclients"] = -1; else return command_result{error::parameter_missing, "channel_maxclients"}; /* max clients must be specified */ keys.push_back(&property::describe(property::CHANNEL_MAXCLIENTS)); } - if(!cmd[0].has("channel_flag_maxclients_unlimited")) { + if (!cmd[0].has("channel_flag_maxclients_unlimited")) { cmd["channel_flag_maxclients_unlimited"] = cmd["channel_maxclients"].as() < 0; keys.push_back(&property::describe(property::CHANNEL_FLAG_MAXCLIENTS_UNLIMITED)); } - if(cmd["channel_flag_maxclients_unlimited"].as() && cmd["channel_maxclients"].as() != -1) + if (cmd["channel_flag_maxclients_unlimited"].as() && cmd["channel_maxclients"].as() != -1) return command_result{error::channel_invalid_flags}; /* channel cant have a max client settings AND be unlimited as well */ - if(!cmd["channel_flag_maxclients_unlimited"].as() && target_channel_type == ChannelType::temporary) + if (!cmd["channel_flag_maxclients_unlimited"].as() && target_channel_type == ChannelType::temporary) return command_result{error::channel_invalid_flags}; /* temporary channels cant have a limited user count */ } /* test the max family clients parameters */ - if(update_max_family_clients) { + if (update_max_family_clients) { //auto channel_maxfamilyclients = cmd[0].has("channel_maxfamilyclients") ? std::optional{cmd["channel_maxfamilyclients"].as()} : std::nullopt; //auto channel_flag_maxfamilyclients_unlimited = cmd[0].has("channel_flag_maxfamilyclients_unlimited") ? std::optional{cmd["channel_flag_maxfamilyclients_unlimited"].as()} : std::nullopt; //auto channel_flag_maxfamilyclients_inherited = cmd[0].has("channel_flag_maxfamilyclients_inherited") ? std::optional{cmd["channel_flag_maxfamilyclients_inherited"].as()} : std::nullopt; /* update actual count from flags */ - if(!cmd[0].has("channel_maxfamilyclients")) { - if(cmd[0].has("channel_flag_maxfamilyclients_unlimited") && cmd["channel_flag_maxfamilyclients_unlimited"].as()) { + if (!cmd[0].has("channel_maxfamilyclients")) { + if (cmd[0].has("channel_flag_maxfamilyclients_unlimited") && cmd["channel_flag_maxfamilyclients_unlimited"].as()) { cmd["channel_maxfamilyclients"] = -1; keys.push_back(&property::describe(property::CHANNEL_MAXFAMILYCLIENTS)); - } else if(cmd[0].has("channel_flag_maxfamilyclients_inherited") && cmd["channel_flag_maxfamilyclients_inherited"].as()) { + } else if (cmd[0].has("channel_flag_maxfamilyclients_inherited") && cmd["channel_flag_maxfamilyclients_inherited"].as()) { cmd["channel_maxfamilyclients"] = -1; keys.push_back(&property::describe(property::CHANNEL_MAXFAMILYCLIENTS)); } else { @@ -1270,38 +1265,38 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { } //Update the flags from channel_maxfamilyclients if needed - if(!cmd[0].has("channel_flag_maxfamilyclients_unlimited")) { + if (!cmd[0].has("channel_flag_maxfamilyclients_unlimited")) { auto flag_inherited = cmd[0].has("channel_flag_maxfamilyclients_inherited") && cmd["channel_flag_maxfamilyclients_inherited"].as(); - if(flag_inherited) + if (flag_inherited) cmd["channel_flag_maxfamilyclients_unlimited"] = false; else cmd["channel_flag_maxfamilyclients_unlimited"] = cmd["channel_maxfamilyclients"].as() < 0; } - if(!cmd[0].has("channel_flag_maxfamilyclients_inherited")) { + if (!cmd[0].has("channel_flag_maxfamilyclients_inherited")) { auto flag_unlimited = cmd[0].has("channel_flag_maxfamilyclients_unlimited") && cmd["channel_flag_maxfamilyclients_unlimited"].as(); - if(flag_unlimited) + if (flag_unlimited) cmd["channel_flag_maxfamilyclients_inherited"] = false; else cmd["channel_flag_maxfamilyclients_inherited"] = cmd["channel_maxfamilyclients"].as() < 0; } /* final checkup */ - if(cmd["channel_flag_maxfamilyclients_inherited"].as() && cmd["channel_flag_maxfamilyclients_unlimited"].as()) + if (cmd["channel_flag_maxfamilyclients_inherited"].as() && cmd["channel_flag_maxfamilyclients_unlimited"].as()) return command_result{error::channel_invalid_flags}; /* both at the same time are not possible */ - if(cmd["channel_flag_maxfamilyclients_inherited"].as() && cmd["channel_maxfamilyclients"].as() != -1) + if (cmd["channel_flag_maxfamilyclients_inherited"].as() && cmd["channel_maxfamilyclients"].as() != -1) return command_result{error::channel_invalid_flags}; /* flag inherited required max users to be -1 */ - if(cmd["channel_flag_maxfamilyclients_unlimited"].as() && cmd["channel_maxfamilyclients"].as() != -1) + if (cmd["channel_flag_maxfamilyclients_unlimited"].as() && cmd["channel_maxfamilyclients"].as() != -1) return command_result{error::channel_invalid_flags}; /* flag unlimited required max users to be -1 */ - if(cmd["channel_maxfamilyclients"].as() != -1 && target_channel_type == ChannelType::temporary) + if (cmd["channel_maxfamilyclients"].as() != -1 && target_channel_type == ChannelType::temporary) return command_result{error::channel_invalid_flags}; /* temporary channels cant have a limited user count */ } /* test the channel name */ - if(update_name) { + if (update_name) { auto named_channel = channel_tree->findChannel(cmd["channel_name"].string(), channel->parent()); if (named_channel) return command_result{error::channel_name_inuse}; @@ -1310,8 +1305,8 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { auto self_ref = this->ref(); shared_ptr old_default_channel; deque> child_channel_updated; - for(const property::PropertyDescription* key : keys) { - if(*key == property::CHANNEL_ORDER) { + for (const property::PropertyDescription *key : keys) { + if (*key == property::CHANNEL_ORDER) { /* TODO: May move that up because if it fails may some other props have already be applied */ auto old_channel_order = channel->channelOrder(); if (!channel_tree->change_order(channel, cmd[std::string{key->name}])) @@ -1322,16 +1317,16 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { channel_parent, channel_parent, old_channel_order, channel->channelOrder()); - if(this->server) { + if (this->server) { auto parent = channel->hasParent() ? channel_tree->findLinkedChannel(channel->parent()->channelId()) : nullptr; auto previous = channel_tree->findLinkedChannel(channel->previousChannelId()); - this->server->forEachClient([&](const shared_ptr& cl) { + this->server->forEachClient([&](const shared_ptr &cl) { unique_lock client_channel_lock(cl->channel_lock); auto actions = cl->channels->change_order(l_channel, parent, previous); std::deque deletions; - for(const auto& action : actions) { + for (const auto &action : actions) { switch (action.first) { case ClientChannelView::NOTHING: continue; @@ -1349,23 +1344,23 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { break; } } - if(!deletions.empty()) { + if (!deletions.empty()) { cl->notifyChannelHide(deletions, false); - return; //Channel got deleted so we dont have to send the updates + return;//Channel got deleted so we dont have to send the updates } }); } /* property has already been updated as well the log has also been written */ continue; - } else if(*key == property::CHANNEL_FLAG_DEFAULT) { + } else if (*key == property::CHANNEL_FLAG_DEFAULT) { old_default_channel = channel_tree->getDefaultChannel(); - if(old_default_channel == channel) { + if (old_default_channel == channel) { old_default_channel = nullptr; continue; } - if(!cmd[std::string{key->name}].as()) { + if (!cmd[std::string{key->name}].as()) { old_default_channel = nullptr; continue; } @@ -1375,41 +1370,41 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { deque> updated_channels; shared_ptr current_channel = channel; do { - if(current_channel->channelType() == ChannelType::permanent) + if (current_channel->channelType() == ChannelType::permanent) break; current_channel->setChannelType(ChannelType::permanent); - if(current_channel != channel) + if (current_channel != channel) updated_channels.push_back(channel); } while ((current_channel = current_channel->parent())); - if(this->server && !updated_channels.empty()) { + if (this->server && !updated_channels.empty()) { std::reverse(updated_channels.begin(), updated_channels.end()); auto this_ref = this->ref(); - this->server->forEachClient([&](const shared_ptr& client) { + this->server->forEachClient([&](const shared_ptr &client) { unique_lock client_channel_lock(client->channel_lock); - for(const auto& channel : updated_channels) { + for (const auto &channel : updated_channels) { client->notifyChannelEdited(channel, {property::CHANNEL_FLAG_PERMANENT, property::CHANNEL_FLAG_SEMI_PERMANENT}, this_ref, false); } }); } - } else if(*key == property::CHANNEL_FLAG_PERMANENT || *key == property::CHANNEL_FLAG_SEMI_PERMANENT) { - if(target_channel_type_changed) { /* must be true else the key would not appere here */ + } else if (*key == property::CHANNEL_FLAG_PERMANENT || *key == property::CHANNEL_FLAG_SEMI_PERMANENT) { + if (target_channel_type_changed) { /* must be true else the key would not appere here */ target_channel_type_changed = false; /* we only need to check all subchannels once! */ { /* check channel children */ deque> channel_to_test = {channel}; - while(!channel_to_test.empty()) { + while (!channel_to_test.empty()) { auto current_channel = channel_to_test.front(); channel_to_test.pop_front(); - for(const auto& child : channel_tree->channels(current_channel, 1)) { - if(child == current_channel) + for (const auto &child : channel_tree->channels(current_channel, 1)) { + if (child == current_channel) continue; - if(child->channelType() < target_channel_type) { + if (child->channelType() < target_channel_type) { child->setChannelType(target_channel_type); channel_to_test.push_back(child); child_channel_updated.push_back(child); @@ -1418,56 +1413,56 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { } } } - } else if(*key == property::CHANNEL_CONVERSATION_HISTORY_LENGTH) { + } else if (*key == property::CHANNEL_CONVERSATION_HISTORY_LENGTH) { //channel_conversation_history_length auto conversation_manager = this->server->conversation_manager(); - if(conversation_manager) { + if (conversation_manager) { auto conversation = conversation_manager->get(channel->channelId()); - if(conversation) + if (conversation) conversation->set_history_length(cmd[std::string{key->name}]); } - } else if(*key == property::CHANNEL_NEEDED_TALK_POWER) { + } else if (*key == property::CHANNEL_NEEDED_TALK_POWER) { channel->permissions()->set_permission(permission::i_client_needed_talk_power, {cmd[key->name].as(), 0}, permission::v2::set_value, permission::v2::do_nothing); } auto prop = channel->properties()[*key]; auto old_value = prop.value(); auto new_value = cmd[std::string{key->name}].string(); - if(old_value == new_value) + if (old_value == new_value) continue; prop = new_value; serverInstance->action_logger()->channel_logger.log_channel_edit(this->getServerId(), this->ref(), channel->channelId(), *key, old_value, new_value); } - if(this->server) { + if (this->server) { vector key_vector; key_vector.reserve(keys.size()); - for(const auto& key : keys) + for (const auto &key : keys) key_vector.push_back((property::ChannelProperties) key->property_index); auto self_rev = this->ref(); - this->server->forEachClient([&](const shared_ptr& client) { + this->server->forEachClient([&](const shared_ptr &client) { unique_lock client_channel_lock(client->channel_lock); - for(const auto& channel : child_channel_updated) + for (const auto &channel : child_channel_updated) client->notifyChannelEdited(channel, {property::CHANNEL_FLAG_PERMANENT, property::CHANNEL_FLAG_SEMI_PERMANENT}, self_rev, false); client->notifyChannelEdited(channel, key_vector, self_rev, false); - if(old_default_channel) /* clients need to have one or more defualt channels... */ + if (old_default_channel) /* clients need to have one or more defualt channels... */ client->notifyChannelEdited(old_default_channel, {property::CHANNEL_FLAG_DEFAULT}, self_rev, false); }); } - if(server_channel_w_lock.owns_lock()) + if (server_channel_w_lock.owns_lock()) server_channel_w_lock.unlock(); - if(!channel_tree_read_lock.owns_lock()) + if (!channel_tree_read_lock.owns_lock()) channel_tree_read_lock.lock(); - if(update_clients_in_channel && this->server) { - for(const auto& client : this->server->getClientsByChannel(channel)) - client->updateChannelClientProperties(true, true); //TODO: May only update the talk power and not all? + if (update_clients_in_channel && this->server) { + for (const auto &client : this->server->getClientsByChannel(channel)) + client->updateChannelClientProperties(true, true);//TODO: May only update the talk power and not all? } return command_result{error::ok}; } @@ -1478,30 +1473,30 @@ command_result ConnectedClient::handleCommandChannelMove(Command &cmd) { RESOLVE_CHANNEL_W(cmd["cid"], true); auto channel = dynamic_pointer_cast(l_channel->entry); assert(channel); - if(channel->deleted) + if (channel->deleted) return command_result{error::channel_is_deleted}; - if(!cmd[0].has("order")) + if (!cmd[0].has("order")) cmd["order"] = 0; auto l_parent = channel_tree->findLinkedChannel(cmd["cpid"]); shared_ptr l_order; - if(cmd[0].has("order")) { + if (cmd[0].has("order")) { l_order = channel_tree->findLinkedChannel(cmd["order"]); if (!l_order && cmd["order"].as() != 0) return command_result{error::channel_invalid_id}; } else { l_order = l_parent ? l_parent->child_head : (this->server ? this->server->getChannelTree() : serverInstance->getChannelTree().get())->tree_head(); - while(l_order && l_order->next) + while (l_order && l_order->next) l_order = l_order->next; } auto parent = l_parent ? dynamic_pointer_cast(l_parent->entry) : nullptr; auto order = l_order ? dynamic_pointer_cast(l_order->entry) : nullptr; - if((parent && parent->deleted) || (order && order->deleted)) + if ((parent && parent->deleted) || (order && order->deleted)) return command_result{error::channel_is_deleted, "parent channel order previous channel has been deleted"}; - if(channel->parent() == parent && channel->channelOrder() == (order ? order->channelId() : 0)) + if (channel->parent() == parent && channel->channelOrder() == (order ? order->channelId() : 0)) return command_result{error::ok}; auto old_parent_channel_id = channel->parent() ? channel->parent()->channelId() : 0; @@ -1520,21 +1515,21 @@ command_result ConnectedClient::handleCommandChannelMove(Command &cmd) { auto min_channel_deep = this->calculate_permission(permission::i_channel_min_depth, 0, false); auto max_channel_deep = this->calculate_permission(permission::i_channel_max_depth, 0, false); - if(min_channel_deep.has_value || max_channel_deep.has_value) { + if (min_channel_deep.has_value || max_channel_deep.has_value) { auto channel_deep = 0; auto local_parent = l_parent; - while(local_parent) { + while (local_parent) { channel_deep++; local_parent = local_parent->parent.lock(); } - if(min_channel_deep.has_value && (channel_deep < min_channel_deep.value && !min_channel_deep.has_infinite_power())) return command_result{permission::i_channel_min_depth}; - if(max_channel_deep.has_value && !permission::v2::permission_granted(channel_deep, max_channel_deep)) return command_result{permission::i_channel_max_depth}; + if (min_channel_deep.has_value && (channel_deep < min_channel_deep.value && !min_channel_deep.has_infinite_power())) return command_result{permission::i_channel_min_depth}; + if (max_channel_deep.has_value && !permission::v2::permission_granted(channel_deep, max_channel_deep)) return command_result{permission::i_channel_max_depth}; } } { auto name = channel_tree->findChannel(channel->name(), parent); - if(name && name != channel) return command_result{error::channel_name_inuse}; + if (name && name != channel) return command_result{error::channel_name_inuse}; } debugMessage(this->getServerId(), "Moving channel {} from old [{} | {}] to [{} | {}]", channel->name(), channel->channelOrder(), channel->parent() ? channel->parent()->channelId() : 0, order ? order->channelId() : 0, parent ? parent->channelId() : 0); @@ -1545,13 +1540,13 @@ command_result ConnectedClient::handleCommandChannelMove(Command &cmd) { auto flag_default = channel->defaultChannel(); auto current_channel = channel; do { - if(flag_default) { - if(current_channel->channelType() != ChannelType::permanent) { + if (flag_default) { + if (current_channel->channelType() != ChannelType::permanent) { current_channel->setChannelType(ChannelType::permanent); channel_type_updates.push_front(current_channel); } - } else if(current_channel->hasParent()) { - if(current_channel->channelType() < current_channel->parent()->channelType()) { + } else if (current_channel->hasParent()) { + if (current_channel->channelType() < current_channel->parent()->channelType()) { current_channel->setChannelType(current_channel->parent()->channelType()); channel_type_updates.push_front(current_channel); } @@ -1564,29 +1559,27 @@ command_result ConnectedClient::handleCommandChannelMove(Command &cmd) { old_parent_channel_id, channel->parent() ? channel->parent()->channelId() : 0, old_channel_order, channel->channelOrder()); - for(const auto& type_update : channel_type_updates) { + for (const auto &type_update : channel_type_updates) { serverInstance->action_logger()->channel_logger.log_channel_edit(this->getServerId(), this->ref(), type_update->channelId(), - property::describe(property::CHANNEL_FLAG_PERMANENT), - "", - type_update->properties()[property::CHANNEL_FLAG_PERMANENT].value() - ); + property::describe(property::CHANNEL_FLAG_PERMANENT), + "", + type_update->properties()[property::CHANNEL_FLAG_PERMANENT].value()); serverInstance->action_logger()->channel_logger.log_channel_edit(this->getServerId(), this->ref(), type_update->channelId(), - property::describe(property::CHANNEL_FLAG_SEMI_PERMANENT), - "", - type_update->properties()[property::CHANNEL_FLAG_SEMI_PERMANENT].value() - ); + property::describe(property::CHANNEL_FLAG_SEMI_PERMANENT), + "", + type_update->properties()[property::CHANNEL_FLAG_SEMI_PERMANENT].value()); } - if(this->server) { + if (this->server) { auto self_rev = this->ref(); - this->server->forEachClient([&](const shared_ptr& client) { + this->server->forEachClient([&](const shared_ptr &client) { unique_lock channel_lock(client->channel_lock); - for(const auto& type_update : channel_type_updates) + for (const auto &type_update : channel_type_updates) client->notifyChannelEdited(type_update, {property::CHANNEL_FLAG_PERMANENT, property::CHANNEL_FLAG_SEMI_PERMANENT}, self_rev, false); auto actions = client->channels->change_order(l_channel, l_parent, l_order); std::deque deletions; - for(const auto& action : actions) { + for (const auto &action : actions) { switch (action.first) { case ClientChannelView::NOTHING: continue; @@ -1604,7 +1597,7 @@ command_result ConnectedClient::handleCommandChannelMove(Command &cmd) { break; } } - if(!deletions.empty()) + if (!deletions.empty()) client->notifyChannelHide(deletions, false); }); } @@ -1621,7 +1614,7 @@ command_result ConnectedClient::handleCommandChannelPermList(Command &cmd) { ACTION_REQUIRES_PERMISSION(permission::b_virtualserver_channel_permission_list, 1, channel->channelId()); - if(this->getType() == ClientType::CLIENT_TEAMSPEAK && this->command_times.last_notify + this->command_times.notify_timeout < system_clock::now()) { + if (this->getType() == ClientType::CLIENT_TEAMSPEAK && this->command_times.last_notify + this->command_times.notify_timeout < system_clock::now()) { this->sendTSPermEditorWarning(); } @@ -1635,9 +1628,9 @@ command_result ConnectedClient::handleCommandChannelPermList(Command &cmd) { auto type = this->getType(); auto permission_manager = channel->permissions(); for (const auto &permission_data : permission_manager->permissions()) { - auto& permission = std::get<1>(permission_data); - if(permission.flags.value_set) { - if(sids) { + auto &permission = std::get<1>(permission_data); + if (permission.flags.value_set) { + if (sids) { result[index]["permsid"] = permission_mapper->permission_name(type, std::get<0>(permission_data)); } else { result[index]["permid"] = std::get<0>(permission_data); @@ -1648,11 +1641,11 @@ command_result ConnectedClient::handleCommandChannelPermList(Command &cmd) { result[index]["permskip"] = permission.flags.skip; index++; } - if(permission.flags.grant_set) { - if(sids) { + if (permission.flags.grant_set) { + if (sids) { result[index]["permsid"] = permission_mapper->permission_name_grant(type, std::get<0>(permission_data)); } else { - result[index]["permid"] = (uint16_t) (std::get<0>(permission_data) | PERM_ID_GRANT); + result[index]["permid"] = (uint16_t)(std::get<0>(permission_data) | PERM_ID_GRANT); } result[index]["permvalue"] = permission.values.grant; result[index]["permnegated"] = 0; @@ -1660,7 +1653,7 @@ command_result ConnectedClient::handleCommandChannelPermList(Command &cmd) { index++; } } - if(index == 0) + if (index == 0) return command_result{error::database_empty_result}; this->sendCommand(result); @@ -1683,36 +1676,35 @@ command_result ConnectedClient::handleCommandChannelAddPerm(Command &cmd) { ACTION_REQUIRES_CHANNEL_PERMISSION(channel, permission::i_channel_needed_permission_modify_power, permission::i_channel_permission_modify_power, true); command::bulk_parser::PermissionBulksParser pparser{cmd}; - if(!pparser.validate(this->ref(), channel->channelId())) + if (!pparser.validate(this->ref(), channel->channelId())) return pparser.build_command_result(); auto permission_manager = channel->permissions(); auto updateClients = false, update_join_permissions = false, update_channel_properties = false; auto channelId = channel->channelId(); - for(const auto& ppermission : pparser.iterate_valid_permissions()) { + for (const auto &ppermission : pparser.iterate_valid_permissions()) { ppermission.apply_to(permission_manager, permission::v2::PermissionUpdateType::set_value); ppermission.log_update(serverInstance->action_logger()->permission_logger, - this->getServerId(), - this->ref(), - log::PermissionTarget::CHANNEL, - permission::v2::PermissionUpdateType::set_value, - channelId, channel->name(), - 0, "" - ); + this->getServerId(), + this->ref(), + log::PermissionTarget::CHANNEL, + permission::v2::PermissionUpdateType::set_value, + channelId, channel->name(), + 0, ""); updateClients |= ppermission.is_client_view_property(); update_join_permissions = ppermission.permission_type() == permission::i_channel_needed_join_power; update_channel_properties |= channel->permission_require_property_update(ppermission.permission_type()); } - if(update_channel_properties && this->server) + if (update_channel_properties && this->server) this->server->update_channel_from_permissions(channel, this->ref()); - if((updateClients || update_join_permissions) && this->server) { + if ((updateClients || update_join_permissions) && this->server) { this->server->forEachClient([&](std::shared_ptr cl) { - if(updateClients && cl->currentChannel == channel) + if (updateClients && cl->currentChannel == channel) cl->updateChannelClientProperties(true, true); - if(update_join_permissions) + if (update_join_permissions) cl->join_state_id++; }); } @@ -1730,36 +1722,35 @@ command_result ConnectedClient::handleCommandChannelDelPerm(Command &cmd) { ACTION_REQUIRES_CHANNEL_PERMISSION(channel, permission::i_channel_needed_permission_modify_power, permission::i_channel_permission_modify_power, true); command::bulk_parser::PermissionBulksParser pparser{cmd}; - if(!pparser.validate(this->ref(), channel->channelId())) + if (!pparser.validate(this->ref(), channel->channelId())) return pparser.build_command_result(); auto permission_manager = channel->permissions(); auto updateClients = false, update_join_permissions = false, update_channel_properties = false; auto channelId = channel->channelId(); - for(const auto& ppermission : pparser.iterate_valid_permissions()) { + for (const auto &ppermission : pparser.iterate_valid_permissions()) { ppermission.apply_to(permission_manager, permission::v2::PermissionUpdateType::delete_value); ppermission.log_update(serverInstance->action_logger()->permission_logger, - this->getServerId(), - this->ref(), - log::PermissionTarget::CHANNEL, - permission::v2::PermissionUpdateType::delete_value, - channelId, channel->name(), - 0, "" - ); + this->getServerId(), + this->ref(), + log::PermissionTarget::CHANNEL, + permission::v2::PermissionUpdateType::delete_value, + channelId, channel->name(), + 0, ""); updateClients |= ppermission.is_client_view_property(); update_join_permissions = ppermission.permission_type() == permission::i_channel_needed_join_power; update_channel_properties |= channel->permission_require_property_update(ppermission.permission_type()); } - if(update_channel_properties && this->server) + if (update_channel_properties && this->server) this->server->update_channel_from_permissions(channel, this->ref()); - if((updateClients || update_join_permissions) && this->server) { + if ((updateClients || update_join_permissions) && this->server) { this->server->forEachClient([&](std::shared_ptr cl) { - if(updateClients && cl->currentChannel == channel) + if (updateClients && cl->currentChannel == channel) cl->updateChannelClientProperties(true, true); - if(update_join_permissions) + if (update_join_permissions) cl->join_state_id++; }); } @@ -1773,16 +1764,16 @@ command_result ConnectedClient::handleCommandChannelClientPermList(Command &cmd) CMD_CHK_AND_INC_FLOOD_POINTS(5); RESOLVE_CHANNEL_R(cmd["cid"], true); auto channel = dynamic_pointer_cast(l_channel->entry); - if(!channel) return command_result{error::vs_critical}; + if (!channel) return command_result{error::vs_critical}; ACTION_REQUIRES_PERMISSION(permission::b_virtualserver_channelclient_permission_list, 1, channel_id); - if(!serverInstance->databaseHelper()->validClientDatabaseId(this->server, cmd["cldbid"])) return command_result{error::client_invalid_id}; + if (!serverInstance->databaseHelper()->validClientDatabaseId(this->server, cmd["cldbid"])) return command_result{error::client_invalid_id}; auto mgr = serverInstance->databaseHelper()->loadClientPermissionManager(this->server, cmd["cldbid"].as()); Command res(this->getExternalType() == CLIENT_TEAMSPEAK ? "notifychannelclientpermlist" : ""); auto permissions = mgr->channel_permissions(channel->channelId()); - if(permissions.empty()) + if (permissions.empty()) return command_result{error::database_empty_result}; int index = 0; @@ -1794,8 +1785,8 @@ command_result ConnectedClient::handleCommandChannelClientPermList(Command &cmd) auto type = this->getType(); for (const auto &permission_data : permissions) { - auto& permission = std::get<1>(permission_data); - if(permission.flags.value_set) { + auto &permission = std::get<1>(permission_data); + if (permission.flags.value_set) { if (sids) res[index]["permsid"] = permission_mapper->permission_name(type, get<0>(permission_data)); else @@ -1808,7 +1799,7 @@ command_result ConnectedClient::handleCommandChannelClientPermList(Command &cmd) } - if(permission.flags.grant_set) { + if (permission.flags.grant_set) { if (sids) res[index]["permsid"] = permission_mapper->permission_name_grant(type, get<0>(permission_data)); else @@ -1835,7 +1826,7 @@ command_result ConnectedClient::handleCommandChannelClientDelPerm(Command &cmd) RESOLVE_CHANNEL_R(cmd["cid"], true); auto channel = dynamic_pointer_cast(l_channel->entry); - if(!channel) return command_result{error::vs_critical}; + if (!channel) return command_result{error::vs_critical}; auto mgr = serverInstance->databaseHelper()->loadClientPermissionManager(this->server, cldbid); { @@ -1844,11 +1835,11 @@ command_result ConnectedClient::handleCommandChannelClientDelPerm(Command &cmd) } command::bulk_parser::PermissionBulksParser pparser{cmd}; - if(!pparser.validate(this->ref(), channel->channelId())) + if (!pparser.validate(this->ref(), channel->channelId())) return pparser.build_command_result(); bool update_view{false}; - for(const auto& ppermission : pparser.iterate_valid_permissions()) { + for (const auto &ppermission : pparser.iterate_valid_permissions()) { ppermission.apply_to_channel(mgr, permission::v2::PermissionUpdateType::delete_value, channel->channelId()); ppermission.log_update(serverInstance->action_logger()->permission_logger, this->getServerId(), @@ -1856,8 +1847,7 @@ command_result ConnectedClient::handleCommandChannelClientDelPerm(Command &cmd) log::PermissionTarget::CLIENT_CHANNEL, permission::v2::PermissionUpdateType::delete_value, cldbid, "", - channel->channelId(), channel->name() - ); + channel->channelId(), channel->name()); update_view |= ppermission.is_client_view_property(); } @@ -1866,23 +1856,24 @@ command_result ConnectedClient::handleCommandChannelClientDelPerm(Command &cmd) auto onlineClients = this->server->findClientsByCldbId(cldbid); if (!onlineClients.empty()) { for (const auto &elm : onlineClients) { - if(elm->update_cached_permissions()) /* update cached calculated permissions */ + if (elm->update_cached_permissions()) /* update cached calculated permissions */ elm->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ - if(elm->currentChannel == channel) { + if (elm->currentChannel == channel) { elm->updateChannelClientProperties(true, true); - } else if(update_view) { + } else if (update_view) { unique_lock client_channel_lock(this->channel_lock); auto elm_channel = elm->currentChannel; - if(elm_channel) { + if (elm_channel) { deque deleted; - for(const auto& update_entry : elm->channels->update_channel_path(l_channel, this->server->channelTree->findLinkedChannel(elm->currentChannel->channelId()))) { - if(update_entry.first) + for (const auto &update_entry : elm->channels->update_channel_path(l_channel, this->server->channelTree->findLinkedChannel(elm->currentChannel->channelId()))) { + if (update_entry.first) elm->notifyChannelShow(update_entry.second->channel(), update_entry.second->previous_channel); - else deleted.push_back(update_entry.second->channelId()); + else + deleted.push_back(update_entry.second->channelId()); } - if(!deleted.empty()) + if (!deleted.empty()) elm->notifyChannelHide(deleted, false); /* we've locked the tree before */ } } @@ -1905,18 +1896,18 @@ command_result ConnectedClient::handleCommandChannelClientAddPerm(Command &cmd) RESOLVE_CHANNEL_R(cmd["cid"], true); auto channel = dynamic_pointer_cast(l_channel->entry); - if(!channel) return command_result{error::vs_critical}; + if (!channel) return command_result{error::vs_critical}; auto mgr = serverInstance->databaseHelper()->loadClientPermissionManager(this->server, cldbid); auto required_permissions = this->server->calculate_permission(permission::i_client_needed_permission_modify_power, cmd["cldbid"], ClientType::CLIENT_TEAMSPEAK, channel_id); ACTION_REQUIRES_PERMISSION(permission::i_client_permission_modify_power, required_permissions, channel_id); command::bulk_parser::PermissionBulksParser pparser{cmd}; - if(!pparser.validate(this->ref(), channel->channelId())) + if (!pparser.validate(this->ref(), channel->channelId())) return pparser.build_command_result(); bool update_view{false}; - for(const auto& ppermission : pparser.iterate_valid_permissions()) { + for (const auto &ppermission : pparser.iterate_valid_permissions()) { ppermission.apply_to_channel(mgr, permission::v2::PermissionUpdateType::set_value, channel->channelId()); ppermission.log_update(serverInstance->action_logger()->permission_logger, this->getServerId(), @@ -1924,8 +1915,7 @@ command_result ConnectedClient::handleCommandChannelClientAddPerm(Command &cmd) log::PermissionTarget::CLIENT_CHANNEL, permission::v2::PermissionUpdateType::set_value, cldbid, "", - channel->channelId(), channel->name() - ); + channel->channelId(), channel->name()); update_view |= ppermission.is_client_view_property(); } @@ -1935,23 +1925,24 @@ command_result ConnectedClient::handleCommandChannelClientAddPerm(Command &cmd) auto onlineClients = this->server->findClientsByCldbId(cldbid); if (!onlineClients.empty()) for (const auto &elm : onlineClients) { - if (elm->update_cached_permissions()) /* update cached calculated permissions */ + if (elm->update_cached_permissions()) /* update cached calculated permissions */ elm->sendNeededPermissions(false); /* cached permissions had changed, notify the client */ - if(elm->currentChannel == channel) { + if (elm->currentChannel == channel) { elm->updateChannelClientProperties(true, true); - } else if(update_view) { + } else if (update_view) { unique_lock client_channel_lock(this->channel_lock); auto elm_channel = elm->currentChannel; - if(elm_channel) { + if (elm_channel) { deque deleted; - for(const auto& update_entry : elm->channels->update_channel_path(l_channel, this->server->channelTree->findLinkedChannel(elm->currentChannel->channelId()))) { - if(update_entry.first) + for (const auto &update_entry : elm->channels->update_channel_path(l_channel, this->server->channelTree->findLinkedChannel(elm->currentChannel->channelId()))) { + if (update_entry.first) elm->notifyChannelShow(update_entry.second->channel(), update_entry.second->previous_channel); - else deleted.push_back(update_entry.second->channelId()); + else + deleted.push_back(update_entry.second->channelId()); } - if(!deleted.empty()) + if (!deleted.empty()) elm->notifyChannelHide(deleted, false); /* we've locked the tree before */ } } @@ -2000,17 +1991,3 @@ command_result ConnectedClient::handleCommandChannelInfo(Command &cmd) { return command_result{error::ok}; } - - - - - - - - - - - - - -