From 257c5a1a54396a3610f63bf469d6cf50ec76aef5 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 12 Jun 2016 18:11:40 +0200 Subject: cPluginManager: Use a callback for command handler registration. --- src/Server.cpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'src/Server.cpp') diff --git a/src/Server.cpp b/src/Server.cpp index 5548e77d1..8405109de 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -607,18 +607,35 @@ void cServer::PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & void cServer::BindBuiltInConsoleCommands(void) { + // Create an empty handler - the actual handling for the commands is performed before they are handed off to cPluginManager + class cEmptyHandler: + public cPluginManager::cCommandHandler + { + virtual bool ExecuteCommand( + const AStringVector & a_Split, + cPlayer * a_Player, + const AString & a_Command, + cCommandOutputCallback * a_Output = nullptr + ) override + { + return false; + } + }; + auto handler = std::make_shared(); + + // Register internal commands: cPluginManager * PlgMgr = cPluginManager::Get(); - PlgMgr->BindConsoleCommand("help", nullptr, "Shows the available commands"); - PlgMgr->BindConsoleCommand("reload", nullptr, "Reloads all plugins"); - PlgMgr->BindConsoleCommand("restart", nullptr, "Restarts the server cleanly"); - PlgMgr->BindConsoleCommand("stop", nullptr, "Stops the server cleanly"); - PlgMgr->BindConsoleCommand("chunkstats", nullptr, "Displays detailed chunk memory statistics"); - PlgMgr->BindConsoleCommand("load ", nullptr, "Adds and enables the specified plugin"); - PlgMgr->BindConsoleCommand("unload ", nullptr, "Disables the specified plugin"); - PlgMgr->BindConsoleCommand("destroyentities", nullptr, "Destroys all entities in all worlds"); + PlgMgr->BindConsoleCommand("help", nullptr, handler, "Shows the available commands"); + PlgMgr->BindConsoleCommand("reload", nullptr, handler, "Reloads all plugins"); + PlgMgr->BindConsoleCommand("restart", nullptr, handler, "Restarts the server cleanly"); + PlgMgr->BindConsoleCommand("stop", nullptr, handler, "Stops the server cleanly"); + PlgMgr->BindConsoleCommand("chunkstats", nullptr, handler, "Displays detailed chunk memory statistics"); + PlgMgr->BindConsoleCommand("load", nullptr, handler, "Adds and enables the specified plugin"); + PlgMgr->BindConsoleCommand("unload", nullptr, handler, "Disables the specified plugin"); + PlgMgr->BindConsoleCommand("destroyentities", nullptr, handler, "Destroys all entities in all worlds"); #if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER) - PlgMgr->BindConsoleCommand("dumpmem", nullptr, " - Dumps all used memory blocks together with their callstacks into memdump.xml"); + PlgMgr->BindConsoleCommand("dumpmem", nullptr, handler, " - Dumps all used memory blocks together with their callstacks into memdump.xml"); #endif } -- cgit v1.2.3