mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Scripts/Commands: Fix a crash in .help - closes #25360
(cherry picked from commit 944f49d613)
This commit is contained in:
@@ -159,7 +159,7 @@ bool ChatHandler::hasStringAbbr(const char* name, const char* part)
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!*part)
|
||||
if (!*part || *part == ' ')
|
||||
return true;
|
||||
else if (!*name)
|
||||
return false;
|
||||
@@ -461,6 +461,10 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, cons
|
||||
{
|
||||
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)
|
||||
@@ -471,11 +475,9 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, cons
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -483,7 +485,7 @@ bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, cons
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user