1
0

Plugins can now bind console commands

FS #300
Most console commands are now implemented in the Core plugin.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1214 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com
2013-02-15 13:00:59 +00:00
parent 48d30dfca2
commit 34b3c13404
16 changed files with 825 additions and 235 deletions

View File

@@ -460,7 +460,7 @@ bool cServer::Command(cClientHandle & a_Client, const AString & a_Cmd)
void cServer::ServerCommand(const AString & a_Cmd)
void cServer::ExecuteConsoleCommand(const AString & a_Cmd)
{
AStringVector split = StringSplit(a_Cmd, " ");
if (split.empty())
@@ -468,69 +468,18 @@ void cServer::ServerCommand(const AString & a_Cmd)
return;
}
if (split[0].compare( "help" ) == 0)
{
printf("================== ALL COMMANDS ===================\n");
printf("help - Shows this message\n");
printf("save-all - Saves all loaded chunks to disk\n");
printf("list - Lists all players currently in server\n");
printf("unload - Unloads all unused chunks\n");
printf("numchunks - Shows number of chunks currently loaded\n");
printf("chunkstats - Shows chunks statistics\n");
printf("say - Sends a chat message to all players\n");
printf("restart - Kicks all clients, and saves everything\n");
printf(" and clears memory\n");
printf("stop - Saves everything and closes server\n");
printf("primaryserverversion - Gets or sets server version reported to 1.4+ clients\n");
printf("===================================================\n");
return;
}
// Special handling: "stop" and "restart" are built in
if ((split[0].compare("stop") == 0) || (split[0].compare("restart") == 0))
{
return;
}
if (split[0].compare("save-all") == 0)
{
cRoot::Get()->SaveAllChunks();
return;
}
if (split[0].compare("unload") == 0)
{
LOG("Num loaded chunks before: %i", cRoot::Get()->GetTotalChunkCount() );
cRoot::Get()->GetDefaultWorld()->UnloadUnusedChunks(); // TODO: Iterate through ALL worlds
LOG("Num loaded chunks after: %i", cRoot::Get()->GetTotalChunkCount() );
return;
}
if (split[0].compare("list") == 0)
{
class cPlayerLogger : public cPlayerListCallback
{
virtual bool Item(cPlayer * a_Player) override
{
LOG("\t%s @ %s", a_Player->GetName().c_str(), a_Player->GetClientHandle()->GetIPString().c_str());
return false;
}
} Logger;
cRoot::Get()->ForEachPlayer(Logger);
return;
}
if (split[0].compare("numchunks") == 0)
{
LOG("Num loaded chunks: %i", cRoot::Get()->GetTotalChunkCount() );
return;
}
// There is currently no way a plugin can do these (and probably won't ever be):
if (split[0].compare("chunkstats") == 0)
{
cRoot::Get()->LogChunkStats();
return;
}
if (split[0].compare("monsters") == 0)
{
// TODO: cWorld::ListMonsters();
return;
}
#if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER)
if (split[0].compare("dumpmem") == 0)
{
@@ -540,38 +489,27 @@ void cServer::ServerCommand(const AString & a_Cmd)
}
#endif
if (split[0].compare("primaryserverversion") == 0)
if (cPluginManager::Get()->ExecuteConsoleCommand(split))
{
if (split.size() > 1)
{
int Version = atol(split[1].c_str());
if (Version == 0)
{
LOGWARNING("Cannot parse version \"%s\". Not setting anything.");
return;
}
cRoot::Get()->SetPrimaryServerVersion(Version);
}
LOGINFO("Primary server version: %d (%s)",
cRoot::Get()->m_PrimaryServerVersion,
cProtocolRecognizer::GetVersionTextFromInt(cRoot::Get()->m_PrimaryServerVersion).c_str()
);
return;
}
if (split.size() > 1)
{
if (split[0].compare("say") == 0)
{
AString ToSay = a_Cmd.substr(a_Cmd.find_first_of("say") + 4);
AString Message = cChatColor::Purple + "[SERVER] " + ToSay;
LOG("[SERVER]: %s", ToSay.c_str());
BroadcastChat(Message);
return;
}
}
printf("Unknown command, type 'help' for all commands.\n");
// LOG("You didn't enter anything? (%s)", a_Cmd.c_str() );
LOG("Unknown command, type 'help' for all commands.\n");
}
void cServer::BindBuiltInConsoleCommands(void)
{
cPluginManager * PlgMgr = cPluginManager::Get();
PlgMgr->BindConsoleCommand("restart", NULL, "Restarts the server cleanly");
PlgMgr->BindConsoleCommand("stop", NULL, "Stops the server cleanly");
PlgMgr->BindConsoleCommand("chunkstats", NULL, "Displays detailed chunk memory statistics");
#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");
#endif
}