diff options
| author | Shauren <shauren.trinity@gmail.com> | 2015-10-22 20:26:56 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2015-10-22 20:26:56 +0200 |
| commit | 2d942ddcc528cc9fe718ebbd5903318fcbdab817 (patch) | |
| tree | 51eefc279aa09d6a8e6aa28abd0f1b0324e96cca /src/server/game/Chat/Chat.h | |
| parent | 935c93e099f534f701ff8787204ce19be2ed2df2 (diff) | |
Core/Commands: Refactored chat command script hook, fixes a crash when building with gcc 5
Closes #15616
Closes #15740
Diffstat (limited to 'src/server/game/Chat/Chat.h')
| -rw-r--r-- | src/server/game/Chat/Chat.h | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/server/game/Chat/Chat.h b/src/server/game/Chat/Chat.h index 34faac68980..cc208277ba3 100644 --- a/src/server/game/Chat/Chat.h +++ b/src/server/game/Chat/Chat.h @@ -39,13 +39,18 @@ struct GameTele; class ChatCommand { + typedef bool(*pHandler)(ChatHandler*, char const*); + public: - const char * Name; - uint32 Permission; // function pointer required correct align (use uint32) - bool AllowConsole; - bool (*Handler)(ChatHandler*, const char* args); - std::string Help; - ChatCommand* ChildCommands; + ChatCommand(char const* name, uint32 permission, bool allowConsole, pHandler handler, std::string help, std::vector<ChatCommand> childCommands = std::vector<ChatCommand>()) + : Name(name), Permission(permission), AllowConsole(allowConsole), Handler(handler), Help(std::move(help)), ChildCommands(std::move(childCommands)) { } + + char const* Name; + uint32 Permission; // function pointer required correct align (use uint32) + bool AllowConsole; + pHandler Handler; + std::string Help; + std::vector<ChatCommand> ChildCommands; }; class ChatHandler @@ -83,7 +88,7 @@ class ChatHandler bool ParseCommands(const char* text); - static ChatCommand* getCommandTable(); + static std::vector<ChatCommand> const& getCommandTable(); bool isValidChatMessage(const char* msg); void SendGlobalSysMessage(const char *str); @@ -134,12 +139,12 @@ class ChatHandler static bool LoadCommandTable() { return load_command_table; } static void SetLoadCommandTable(bool val) { load_command_table = val; } - bool ShowHelpForCommand(ChatCommand* table, const char* cmd); + bool ShowHelpForCommand(std::vector<ChatCommand> const& table, const char* cmd); protected: explicit ChatHandler() : m_session(NULL), sentErrorMessage(false) { } // for CLI subclass - static bool SetDataForCommandInTable(ChatCommand* table, const char* text, uint32 permission, std::string const& help, std::string const& fullcommand); - bool ExecuteCommandInTable(ChatCommand* table, const char* text, std::string const& fullcmd); - bool ShowHelpForSubCommands(ChatCommand* table, char const* cmd, char const* subcmd); + static bool SetDataForCommandInTable(std::vector<ChatCommand>& table, const char* text, uint32 permission, std::string const& help, std::string const& fullcommand); + bool ExecuteCommandInTable(std::vector<ChatCommand> const& table, const char* text, std::string const& fullcmd); + bool ShowHelpForSubCommands(std::vector<ChatCommand> const& table, char const* cmd, char const* subcmd); private: WorldSession* m_session; // != NULL for chat command call and NULL for CLI command |
