diff --git a/modules/worldengine/nucleus/src/Debugging/Errors.h b/modules/worldengine/nucleus/src/Debugging/Errors.h index 11aeebfec..81dc27c24 100644 --- a/modules/worldengine/nucleus/src/Debugging/Errors.h +++ b/modules/worldengine/nucleus/src/Debugging/Errors.h @@ -29,4 +29,10 @@ namespace Trinity #define ASSERT WPAssert +template inline T* ASSERT_NOTNULL(T* pointer) +{ + ASSERT(pointer); + return pointer; +} + #endif diff --git a/src/game/Chat/Chat.cpp b/src/game/Chat/Chat.cpp index 34946bc92..62d12c271 100644 --- a/src/game/Chat/Chat.cpp +++ b/src/game/Chat/Chat.cpp @@ -246,9 +246,6 @@ bool ChatHandler::ExecuteCommandInTable(std::vector const& table, c for (uint32 i = 0; i < table.size(); ++i) { - if (table[i].Name == nullptr) - continue; - if (!hasStringAbbr(table[i].Name, cmd.c_str())) continue; @@ -257,9 +254,6 @@ bool ChatHandler::ExecuteCommandInTable(std::vector const& table, c { for (uint32 j = 0; j < table.size(); ++j) { - if (table[j].Name == nullptr) - continue; - if (!hasStringAbbr(table[j].Name, cmd.c_str())) continue; @@ -355,7 +349,7 @@ bool ChatHandler::SetDataForCommandInTable(std::vector& table, char for (uint32 i = 0; i < table.size(); i++) { // for data fill use full explicit command names - if (table[i].Name == nullptr || table[i].Name != cmd) + if (table[i].Name != cmd) continue; // select subcommand from child commands list (including "") diff --git a/src/game/Chat/Chat.h b/src/game/Chat/Chat.h index d4f803ff9..dc0e6c65c 100644 --- a/src/game/Chat/Chat.h +++ b/src/game/Chat/Chat.h @@ -28,7 +28,7 @@ class ChatCommand public: ChatCommand(char const* name, uint32 securityLevel, bool allowConsole, pHandler handler, std::string help, std::vector childCommands = std::vector()) - : Name(name), SecurityLevel(securityLevel), AllowConsole(allowConsole), Handler(handler), Help(std::move(help)), ChildCommands(std::move(childCommands)) { } + : Name(ASSERT_NOTNULL(name)), SecurityLevel(securityLevel), AllowConsole(allowConsole), Handler(handler), Help(std::move(help)), ChildCommands(std::move(childCommands)) { } char const* Name; uint32 SecurityLevel; diff --git a/src/game/Scripting/ScriptMgr.cpp b/src/game/Scripting/ScriptMgr.cpp index 453e0b03a..55dc8c336 100644 --- a/src/game/Scripting/ScriptMgr.cpp +++ b/src/game/Scripting/ScriptMgr.cpp @@ -962,6 +962,12 @@ std::vector ScriptMgr::GetChatCommands() table.insert(table.end(), cmds.begin(), cmds.end()); } + // Sort commands in alphabetical order + std::sort(table.begin(), table.end(), [](const ChatCommand& a, const ChatCommand&b) + { + return strcmp(a.Name, b.Name) < 0; + }); + return table; } diff --git a/src/scripts/Commands/cs_debug.cpp b/src/scripts/Commands/cs_debug.cpp index 31c55bbb8..5b627d969 100644 --- a/src/scripts/Commands/cs_debug.cpp +++ b/src/scripts/Commands/cs_debug.cpp @@ -82,9 +82,8 @@ public: }; static std::vector commandTable = { - { "debug", SEC_GAMEMASTER, true, nullptr, "", debugCommandTable }, - { "wpgps", SEC_ADMINISTRATOR, false, &HandleWPGPSCommand, "", }, - { nullptr, SEC_PLAYER, false, nullptr, "", } + { "debug", SEC_GAMEMASTER, true, nullptr, "", debugCommandTable }, + { "wpgps", SEC_ADMINISTRATOR, false, &HandleWPGPSCommand, "", } }; return commandTable; }