From 50ce99ce3e97f11d0c577a7d2e23c92b48c07066 Mon Sep 17 00:00:00 2001 From: Jonathan Sider Date: Wed, 12 Jul 2023 19:59:17 -0700 Subject: [PATCH] [Bug Fix] Update bot naming check and add more explanation (#3491) * Refactor my original PR Block all puncation,numbers, and _ * Add error message --- zone/bot.cpp | 7 +++++-- zone/bot_command.cpp | 9 ++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/zone/bot.cpp b/zone/bot.cpp index 89f13a64c..63b1adcbb 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -1273,8 +1273,11 @@ bool Bot::IsValidName(std::string& name) if (!isupper(name[0])) return false; - for (int i = 1; i < name.length(); ++i) { - if ((!RuleB(Bots, AllowCamelCaseNames) && !islower(name[i])) && name[i] != '_') { + for (char c : name.substr(1)) { + if (!RuleB(Bots, AllowCamelCaseNames) && !islower(c)) { + return false; + } + if (isdigit(c) || ispunct(c)) { return false; } } diff --git a/zone/bot_command.cpp b/zone/bot_command.cpp index 56e691bb2..f1c214a44 100644 --- a/zone/bot_command.cpp +++ b/zone/bot_command.cpp @@ -5501,11 +5501,6 @@ void bot_subcommand_bot_create(Client *c, const Seperator *sep) std::string bot_name = sep->arg[1]; bot_name = Strings::UcFirst(bot_name); - if (Strings::Contains(bot_name, "_")) { - c->Message(Chat::White, "Bot name cannot contain underscores!"); - return; - } - if (arguments < 2 || !sep->IsNumber(2)) { c->Message(Chat::White, "Invalid class!"); return; @@ -8858,8 +8853,8 @@ uint32 helper_bot_create(Client *bot_owner, std::string bot_name, uint8 bot_clas bot_owner->Message( Chat::White, fmt::format( - "'{}' is an invalid name. You may only use characters 'A-Z', 'a-z' and '_'.", - bot_name + "'{}' is an invalid name. You may only use characters 'A-Z' or 'a-z'. Mixed case {} allowed.", + bot_name, RuleB(Bots, AllowCamelCaseNames) ? "is" : "is not" ).c_str() ); return bot_id;