Fixed a mass disconnect due to too long channel names

This commit is contained in:
WolverinDEV 2020-11-26 10:47:16 +01:00
parent 818cffd368
commit 73cf372a84

View File

@ -1,32 +1,32 @@
#include <memory>
#include <bitset>
#include <algorithm>
#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 <algorithm>
#include <bitset>
#include <cstdint>
#include "helpers.h"
#include "./bulk_parsers.h"
#include "helpers.h"
#include <Properties.h>
#include <bbcode/bbcodes.h>
#include <log/LogUtils.h>
#include <misc/sassert.h>
#include <misc/base64.h>
#include <misc/digest.h>
#include <bbcode/bbcodes.h>
#include <misc/sassert.h>
using namespace std::chrono;
using namespace std;
@ -186,7 +186,8 @@ command_result ConnectedClient::handleCommandChannelGroupAdd(Command &cmd) {
});
}
}
} else return command_result{error::group_invalid_id};
} else
return command_result{error::group_invalid_id};
return command_result{error::ok};
}
@ -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};
@ -531,8 +533,7 @@ 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();
}
@ -579,8 +580,7 @@ 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();
}
@ -642,8 +642,10 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) {
if (!cmd[0].has("channel_flag_password")) cmd[0]["channel_flag_password"] = false;
if (cmd[0]["channel_flag_permanent"].as<bool>()) test_permission(1, permission::b_channel_create_permanent);
else if (cmd[0]["channel_flag_semi_permanent"].as<bool>()) test_permission(1, permission::b_channel_create_semi_permanent);
else test_permission(1, permission::b_channel_create_temporary);
else if (cmd[0]["channel_flag_semi_permanent"].as<bool>())
test_permission(1, permission::b_channel_create_semi_permanent);
else
test_permission(1, permission::b_channel_create_temporary);
if (!cmd[0]["channel_flag_permanent"].as<bool>() && !this->server) return command_result{error::parameter_invalid, "You can only create a permanent channel"};
@ -719,16 +721,14 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) {
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<bool>()) {
} else if (cmd[0]["channel_flag_semi_permanent"].as<bool>()) {
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))
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) {
@ -771,7 +771,6 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) {
if (last)
cmd["channel_order"] = last->entry->channelId();
} else {
}
if (cmd["channel_name"].string().length() < 1) {
@ -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 */
@ -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};
@ -1126,8 +1122,7 @@ 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);
@ -1568,13 +1563,11 @@ command_result ConnectedClient::handleCommandChannelMove(Command &cmd) {
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()
);
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()
);
type_update->properties()[property::CHANNEL_FLAG_SEMI_PERMANENT].value());
}
if (this->server) {
@ -1697,8 +1690,7 @@ command_result ConnectedClient::handleCommandChannelAddPerm(Command &cmd) {
log::PermissionTarget::CHANNEL,
permission::v2::PermissionUpdateType::set_value,
channelId, channel->name(),
0, ""
);
0, "");
updateClients |= ppermission.is_client_view_property();
update_join_permissions = ppermission.permission_type() == permission::i_channel_needed_join_power;
@ -1744,8 +1736,7 @@ command_result ConnectedClient::handleCommandChannelDelPerm(Command &cmd) {
log::PermissionTarget::CHANNEL,
permission::v2::PermissionUpdateType::delete_value,
channelId, channel->name(),
0, ""
);
0, "");
updateClients |= ppermission.is_client_view_property();
update_join_permissions = ppermission.permission_type() == permission::i_channel_needed_join_power;
@ -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();
}
@ -1880,7 +1870,8 @@ command_result ConnectedClient::handleCommandChannelClientDelPerm(Command &cmd)
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())
elm->notifyChannelHide(deleted, false); /* we've locked the tree before */
@ -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();
}
@ -1949,7 +1939,8 @@ command_result ConnectedClient::handleCommandChannelClientAddPerm(Command &cmd)
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())
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};
}