diff options
Diffstat (limited to '')
-rw-r--r-- | source/Server.cpp | 104 |
1 files changed, 21 insertions, 83 deletions
diff --git a/source/Server.cpp b/source/Server.cpp index 39d790aa1..7a41352ab 100644 --- a/source/Server.cpp +++ b/source/Server.cpp @@ -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 } |