diff options
author | Treeston <treeston.mmoc@gmail.com> | 2020-08-30 13:45:04 +0200 |
---|---|---|
committer | Treeston <treeston.mmoc@gmail.com> | 2020-08-30 13:45:04 +0200 |
commit | 944f49d61355926e0d9e5c2d16eb4ad1af03d13c (patch) | |
tree | fe5da28c18e7eaced8f55e0402daf75a65ad322e | |
parent | 2f7d2ef3e979ecd0536f3a3713e56c8e59652a47 (diff) |
Scripts/Commands: Fix a crash in .help - closes #25360
-rw-r--r-- | src/server/game/Chat/Chat.cpp | 14 | ||||
-rw-r--r-- | src/server/scripts/Commands/cs_misc.cpp | 6 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index 7413c6ec28c..b41578717de 100644 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -154,7 +154,7 @@ bool ChatHandler::hasStringAbbr(char const* name, char const* part) while (true) { - if (!*part) + if (!*part || *part == ' ') return true; else if (!*name) return false; @@ -456,6 +456,10 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, char { if (*cmd) { + std::string subcmd; + if (size_t n = std::string_view(cmd).find(' '); n != std::string_view::npos) + subcmd.assign(cmd+n+1); + for (uint32 i = 0; i < table.size(); ++i) { // must be available (ignore handler existence to show command with possible available subcommands) @@ -466,11 +470,9 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, char continue; // have subcommand - char const* subcmd = (*cmd) ? strtok(nullptr, " ") : ""; - - if (!table[i].ChildCommands.empty() && subcmd && *subcmd) + if (!table[i].ChildCommands.empty() && !subcmd.empty()) { - if (ShowHelpForCommand(table[i].ChildCommands, subcmd)) + if (ShowHelpForCommand(table[i].ChildCommands, subcmd.c_str())) return true; } @@ -478,7 +480,7 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, char SendSysMessage(table[i].Help.c_str()); if (!table[i].ChildCommands.empty()) - if (ShowHelpForSubCommands(table[i].ChildCommands, table[i].Name, subcmd ? subcmd : "")) + if (ShowHelpForSubCommands(table[i].ChildCommands, table[i].Name, subcmd.c_str())) return true; return !table[i].Help.empty(); diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index 883dbf89b89..bc877af3697 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -689,16 +689,16 @@ public: return true; } - static bool HandleHelpCommand(ChatHandler* handler, Optional<std::string> cmdArg) + static bool HandleHelpCommand(ChatHandler* handler, Tail cmdArg) { - if (!cmdArg) + if (cmdArg.empty()) { handler->ShowHelpForCommand(ChatHandler::getCommandTable(), "help"); handler->ShowHelpForCommand(ChatHandler::getCommandTable(), ""); } else { - if (!handler->ShowHelpForCommand(ChatHandler::getCommandTable(), cmdArg->c_str())) + if (!handler->ShowHelpForCommand(ChatHandler::getCommandTable(), std::string(cmdArg).c_str())) handler->SendSysMessage(LANG_NO_HELP_CMD); } |