From 0f1665c97d6a1a5af2402a6eca9907e14646399b Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 11 Apr 2020 12:31:07 +0200 Subject: [PATCH] Fixed invalid channel flags for changing the default channel --- git-teaspeak | 2 +- server/src/client/command_handler/channel.cpp | 56 ++++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/git-teaspeak b/git-teaspeak index 2da73d8..cc874a4 160000 --- a/git-teaspeak +++ b/git-teaspeak @@ -1 +1 @@ -Subproject commit 2da73d81d1ee4dcd9e4e7e06a4b7fdf2ee6074ea +Subproject commit cc874a443ac40fabf0342b410dae5ae46045fa4f diff --git a/server/src/client/command_handler/channel.cpp b/server/src/client/command_handler/channel.cpp index 7277bc3..8e050d3 100644 --- a/server/src/client/command_handler/channel.cpp +++ b/server/src/client/command_handler/channel.cpp @@ -1012,7 +1012,8 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { } /* test the default channel update */ - if(cmd[0].has("channel_flag_default") || channel->defaultChannel()) { + 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) return command_result{error::channel_default_require_permanent}; /* default channel is not allowed to be non permanent */ @@ -1022,7 +1023,7 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { keys.push_back(&property::describe(property::CHANNEL_FLAG_PASSWORD)); } - if(cmd[0].has("channel_flag_default")) { + if(target_will_be_default) { cmd["channel_maxclients"] = -1; cmd["channel_flag_maxclients_unlimited"] = true; keys.push_back(&property::describe(property::CHANNEL_MAXCLIENTS)); @@ -1030,7 +1031,7 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { update_max_clients = true; cmd["channel_maxfamilyclients"] = -1; - cmd["channel_flag_maxfamilyclients_inherited"] = true; + cmd["channel_flag_maxfamilyclients_inherited"] = false; keys.push_back(&property::describe(property::CHANNEL_MAXFAMILYCLIENTS)); keys.push_back(&property::describe(property::CHANNEL_FLAG_MAXFAMILYCLIENTS_INHERITED)); update_max_family_clients = true; @@ -1091,32 +1092,24 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { /* test the max family clients parameters */ 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")) { - if(cmd["channel_flag_maxfamilyclients_unlimited"].as()) - cmd["channel_flag_maxfamilyclients_inherited"] = false; - else - cmd["channel_flag_maxfamilyclients_inherited"] = true; - keys.push_back(&property::describe(property::CHANNEL_FLAG_MAXFAMILYCLIENTS_INHERITED)); - } else if(cmd[0].has("channel_flag_maxfamilyclients_inherited")) { - if(cmd["channel_flag_maxfamilyclients_inherited"].as()) - cmd["channel_flag_maxfamilyclients_unlimited"] = false; - else - cmd["channel_flag_maxfamilyclients_unlimited"] = true; - keys.push_back(&property::describe(property::CHANNEL_FLAG_MAXFAMILYCLIENTS_UNLIMITED)); - } else /* not really possible */ - return command_result{error::parameter_missing, "channel_maxfamilyclients"}; /* family max clients must be */ - cmd["channel_maxfamilyclients"] = -1; - keys.push_back(&property::describe(property::CHANNEL_MAXFAMILYCLIENTS)); - } - //keep this order because this command: "channeledit cid= channel_maxfamilyclients=-1" should set max family clients mode to 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) - cmd["channel_flag_maxfamilyclients_inherited"] = false; - else - cmd["channel_flag_maxfamilyclients_inherited"] = cmd["channel_maxfamilyclients"].as() < 0; + 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()) { + cmd["channel_maxfamilyclients"] = -1; + keys.push_back(&property::describe(property::CHANNEL_MAXFAMILYCLIENTS)); + } else { + return command_result{error::parameter_missing, "channel_maxfamilyclients"}; /* since its not unlimited or inherited, channel_maxfamilyclients must be specified */ + } } + + //Update the flags from channel_maxfamilyclients if needed 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) @@ -1125,6 +1118,15 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { cmd["channel_flag_maxfamilyclients_unlimited"] = cmd["channel_maxfamilyclients"].as() < 0; } + 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) + 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()) return command_result{error::channel_invalid_flags}; /* both at the same time are not possible */