From eaca25ea30f9052f0f86acc7ab0996f19f69e418 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Thu, 26 Nov 2020 10:45:30 +0100 Subject: [PATCH] Fixed disconnect due to max characters --- server/src/client/command_handler/channel.cpp | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/server/src/client/command_handler/channel.cpp b/server/src/client/command_handler/channel.cpp index 2cc5dc2..851e658 100644 --- a/server/src/client/command_handler/channel.cpp +++ b/server/src/client/command_handler/channel.cpp @@ -774,7 +774,17 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { } - if (cmd["channel_name"].string().length() < 1) return command_result{error::channel_name_inuse, "Invalid channel name"}; + if (cmd["channel_name"].string().length() < 1) { + return command_result{error::channel_name_invalid}; + } + + if (cmd[0].has("channel_name") && count_characters(cmd["channel_name"]) > 40) { + return command_result{error::channel_name_invalid}; + } + + if (count_characters(cmd["channel_name_phonetic"]) > 40) { + return command_result{error::channel_name_invalid}; + } { if (target_tree->findChannel(cmd["channel_name"].as(), parent ? dynamic_pointer_cast(parent->entry) : nullptr)) return command_result{error::channel_name_inuse, "Name already in use"}; @@ -1013,13 +1023,18 @@ command_result ConnectedClient::handleCommandChannelEdit(Command &cmd) { require_write_lock = true; } 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}; - if (count_characters(cmd["channel_name"]) > 40) - return command_result{error::channel_name_invalid}; + if (count_characters(cmd["channel_name"]) < 1) { + return command_result{error::channel_name_invalid}; + } + if (count_characters(cmd["channel_name"]) > 40) { + 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"}; + } 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);