Added new console command with cleanup
This commit is contained in:
@@ -457,33 +457,34 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
|
||||
return;
|
||||
}
|
||||
|
||||
// Special handling: "stop" and "restart" are built in
|
||||
if ((split[0].compare("stop") == 0) || (split[0].compare("restart") == 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// "stop" and "restart" are handled in cRoot::ExecuteConsoleCommand, our caller, due to its access to controlling variables
|
||||
|
||||
// "help" and "reload" are to be handled by MCS, so that they work no matter what
|
||||
if (split[0] == "help")
|
||||
{
|
||||
PrintHelp(split, a_Output);
|
||||
a_Output.Finished();
|
||||
return;
|
||||
}
|
||||
if (split[0] == "reload")
|
||||
{
|
||||
cPluginManager::Get()->ReloadPlugins();
|
||||
cRoot::Get()->ReloadGroups();
|
||||
a_Output.Out("Plugins and groups reloaded");
|
||||
a_Output.Finished();
|
||||
return;
|
||||
}
|
||||
if (split[0] == "reloadplugins")
|
||||
{
|
||||
cPluginManager::Get()->ReloadPlugins();
|
||||
a_Output.Out("Plugins reloaded");
|
||||
a_Output.Finished();
|
||||
return;
|
||||
}
|
||||
if (split[0] == "reloadgroups")
|
||||
{
|
||||
cRoot::Get()->ReloadGroups();
|
||||
a_Output.Out("Groups reloaded!");
|
||||
a_Output.Out("Groups reloaded");
|
||||
a_Output.Finished();
|
||||
return;
|
||||
}
|
||||
@@ -491,31 +492,54 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
|
||||
{
|
||||
if (split.size() > 1)
|
||||
{
|
||||
cPluginManager::Get()->LoadPlugin(split[1]);
|
||||
|
||||
return;
|
||||
a_Output.Out(cPluginManager::Get()->LoadPlugin(split[1]) ? "Plugin loaded" : "Error occurred loading plugin");
|
||||
}
|
||||
else
|
||||
{
|
||||
a_Output.Out("No plugin given! Command: load <pluginname>");
|
||||
a_Output.Finished();
|
||||
return;
|
||||
a_Output.Out("Usage: load <pluginname>");
|
||||
}
|
||||
a_Output.Finished();
|
||||
return;
|
||||
}
|
||||
|
||||
if (split[0] == "unload")
|
||||
{
|
||||
if (split.size() > 1)
|
||||
{
|
||||
cPluginManager::Get()->RemovePlugin(cPluginManager::Get()->GetPlugin(split[1]));
|
||||
return;
|
||||
a_Output.Out("Plugin unloaded");
|
||||
}
|
||||
else
|
||||
{
|
||||
a_Output.Out("No plugin given! Command: unload <pluginname>");
|
||||
a_Output.Finished();
|
||||
return;
|
||||
a_Output.Out("Usage: unload <pluginname>");
|
||||
}
|
||||
a_Output.Finished();
|
||||
return;
|
||||
}
|
||||
if (split[0] == "destroyentities")
|
||||
{
|
||||
class WorldCallback : public cWorldListCallback
|
||||
{
|
||||
virtual bool Item(cWorld * a_World) override
|
||||
{
|
||||
class EntityCallback : public cEntityCallback
|
||||
{
|
||||
virtual bool Item(cEntity * a_Entity) override
|
||||
{
|
||||
if (!a_Entity->IsPlayer())
|
||||
{
|
||||
a_Entity->Destroy();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} EC;
|
||||
a_World->ForEachEntity(EC);
|
||||
return false;
|
||||
}
|
||||
} WC;
|
||||
cRoot::Get()->ForEachWorld(WC);
|
||||
a_Output.Out("Destroyed all entities");
|
||||
a_Output.Finished();
|
||||
return;
|
||||
}
|
||||
|
||||
// There is currently no way a plugin can do these (and probably won't ever be):
|
||||
@@ -610,6 +634,7 @@ void cServer::BindBuiltInConsoleCommands(void)
|
||||
PlgMgr->BindConsoleCommand("chunkstats", NULL, " - Displays detailed chunk memory statistics");
|
||||
PlgMgr->BindConsoleCommand("load <pluginname>", NULL, " - Adds and enables the specified plugin");
|
||||
PlgMgr->BindConsoleCommand("unload <pluginname>", NULL, " - Disables the specified plugin");
|
||||
PlgMgr->BindConsoleCommand("destroyentities", NULL, " - Destroys all entities in all worlds");
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER)
|
||||
PlgMgr->BindConsoleCommand("dumpmem", NULL, " - Dumps all used memory blocks together with their callstacks into memdump.xml");
|
||||
|
||||
Reference in New Issue
Block a user