Core/Chat: properly prevent crashes + cleaning (import from TrinityCore)
- Closes #111
This commit is contained in:
@@ -29,4 +29,10 @@ namespace Trinity
|
|||||||
|
|
||||||
#define ASSERT WPAssert
|
#define ASSERT WPAssert
|
||||||
|
|
||||||
|
template <typename T> inline T* ASSERT_NOTNULL(T* pointer)
|
||||||
|
{
|
||||||
|
ASSERT(pointer);
|
||||||
|
return pointer;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -246,9 +246,6 @@ bool ChatHandler::ExecuteCommandInTable(std::vector<ChatCommand> const& table, c
|
|||||||
|
|
||||||
for (uint32 i = 0; i < table.size(); ++i)
|
for (uint32 i = 0; i < table.size(); ++i)
|
||||||
{
|
{
|
||||||
if (table[i].Name == nullptr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!hasStringAbbr(table[i].Name, cmd.c_str()))
|
if (!hasStringAbbr(table[i].Name, cmd.c_str()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -257,9 +254,6 @@ bool ChatHandler::ExecuteCommandInTable(std::vector<ChatCommand> const& table, c
|
|||||||
{
|
{
|
||||||
for (uint32 j = 0; j < table.size(); ++j)
|
for (uint32 j = 0; j < table.size(); ++j)
|
||||||
{
|
{
|
||||||
if (table[j].Name == nullptr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!hasStringAbbr(table[j].Name, cmd.c_str()))
|
if (!hasStringAbbr(table[j].Name, cmd.c_str()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -355,7 +349,7 @@ bool ChatHandler::SetDataForCommandInTable(std::vector<ChatCommand>& table, char
|
|||||||
for (uint32 i = 0; i < table.size(); i++)
|
for (uint32 i = 0; i < table.size(); i++)
|
||||||
{
|
{
|
||||||
// for data fill use full explicit command names
|
// for data fill use full explicit command names
|
||||||
if (table[i].Name == nullptr || table[i].Name != cmd)
|
if (table[i].Name != cmd)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// select subcommand from child commands list (including "")
|
// select subcommand from child commands list (including "")
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class ChatCommand
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ChatCommand(char const* name, uint32 securityLevel, bool allowConsole, pHandler handler, std::string help, std::vector<ChatCommand> childCommands = std::vector<ChatCommand>())
|
ChatCommand(char const* name, uint32 securityLevel, bool allowConsole, pHandler handler, std::string help, std::vector<ChatCommand> childCommands = std::vector<ChatCommand>())
|
||||||
: 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;
|
char const* Name;
|
||||||
uint32 SecurityLevel;
|
uint32 SecurityLevel;
|
||||||
|
|||||||
@@ -962,6 +962,12 @@ std::vector<ChatCommand> ScriptMgr::GetChatCommands()
|
|||||||
table.insert(table.end(), cmds.begin(), cmds.end());
|
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;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,9 +82,8 @@ public:
|
|||||||
};
|
};
|
||||||
static std::vector<ChatCommand> commandTable =
|
static std::vector<ChatCommand> commandTable =
|
||||||
{
|
{
|
||||||
{ "debug", SEC_GAMEMASTER, true, nullptr, "", debugCommandTable },
|
{ "debug", SEC_GAMEMASTER, true, nullptr, "", debugCommandTable },
|
||||||
{ "wpgps", SEC_ADMINISTRATOR, false, &HandleWPGPSCommand, "", },
|
{ "wpgps", SEC_ADMINISTRATOR, false, &HandleWPGPSCommand, "", }
|
||||||
{ nullptr, SEC_PLAYER, false, nullptr, "", }
|
|
||||||
};
|
};
|
||||||
return commandTable;
|
return commandTable;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user