Fixed invalid channel flags for changing the default channel

This commit is contained in:
WolverinDEV 2020-04-11 12:31:07 +02:00
parent 7ef77c3160
commit 0f1665c97d
2 changed files with 30 additions and 28 deletions

@ -1 +1 @@
Subproject commit 2da73d81d1ee4dcd9e4e7e06a4b7fdf2ee6074ea
Subproject commit cc874a443ac40fabf0342b410dae5ae46045fa4f

View File

@ -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<bool>() : 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<int>{cmd["channel_maxfamilyclients"].as<int>()} : std::nullopt;
//auto channel_flag_maxfamilyclients_unlimited = cmd[0].has("channel_flag_maxfamilyclients_unlimited") ? std::optional<bool>{cmd["channel_flag_maxfamilyclients_unlimited"].as<bool>()} : std::nullopt;
//auto channel_flag_maxfamilyclients_inherited = cmd[0].has("channel_flag_maxfamilyclients_inherited") ? std::optional<bool>{cmd["channel_flag_maxfamilyclients_inherited"].as<bool>()} : 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<bool>())
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<bool>())
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 */
if(cmd[0].has("channel_flag_maxfamilyclients_unlimited") && cmd["channel_flag_maxfamilyclients_unlimited"].as<bool>()) {
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<bool>()) {
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 */
}
//keep this order because this command: "channeledit cid=<x> 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<bool>();
if(flag_unlimited)
cmd["channel_flag_maxfamilyclients_inherited"] = false;
else
cmd["channel_flag_maxfamilyclients_inherited"] = cmd["channel_maxfamilyclients"].as<int>() < 0;
}
//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<bool>();
if(flag_inherited)
@ -1125,6 +1118,15 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) {
cmd["channel_flag_maxfamilyclients_unlimited"] = cmd["channel_maxfamilyclients"].as<int>() < 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<bool>();
if(flag_unlimited)
cmd["channel_flag_maxfamilyclients_inherited"] = false;
else
cmd["channel_flag_maxfamilyclients_inherited"] = cmd["channel_maxfamilyclients"].as<int>() < 0;
}
/* final checkup */
if(cmd["channel_flag_maxfamilyclients_inherited"].as<bool>() && cmd["channel_flag_maxfamilyclients_unlimited"].as<bool>())
return command_result{error::channel_invalid_flags}; /* both at the same time are not possible */