Scripts/Commands: New argument parsing methodology (PR #22363)

- Detect the arguments accepted by the command handler
- Tokenize out those arguments automatically and feed them to the handler
- Unmatched rest of the string can be accepted by trailing char const* or CommandArgs*
This commit is contained in:
Aokromes committed 2018-09-09 14:31:14 +02:00
1 parent 88e1b344cb
commit 6815c24be1
14 files changed
+1043 -405

No files matched your search

+2 -7
View File
@@ -35,11 +35,6 @@
#include "World.h"
#include <boost/algorithm/string/replace.hpp>
ChatCommand::ChatCommand(char const* name, uint32 permission, bool allowConsole, pHandler handler, std::string help, std::vector<ChatCommand> childCommands /*= std::vector<ChatCommand>()*/)
: Name(ASSERT_NOTNULL(name)), Permission(permission), AllowConsole(allowConsole), Handler(handler), Help(std::move(help)), ChildCommands(std::move(childCommands))
{
}
// Lazy loading of the command table cache from commands and the
// ScriptMgr should be thread safe since the player commands,
// cli commands and ScriptMgr updates are all dispatched one after
@@ -306,12 +301,12 @@ bool ChatHandler::ExecuteCommandInTable(std::vector<ChatCommand> const& table, c
}
// must be available and have handler
if (!table[i].Handler || !isAvailable(table[i]))
if (!table[i].HasHandler() || !isAvailable(table[i]))
continue;
SetSentErrorMessage(false);
// table[i].Name == "" is special case: send original command to handler
if ((table[i].Handler)(this, table[i].Name[0] != '\0' ? text : oldtext))
if (table[i](this, table[i].Name[0] != '\0' ? text : oldtext))
{
if (!m_session) // ignore console
return true;