summaryrefslogtreecommitdiffstats
path: root/source/Server.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-11-13 20:40:18 +0100
committermadmaxoft <github@xoft.cz>2013-11-13 20:40:18 +0100
commit5ebbdb4d51288e3c472df407ac15f516d259d823 (patch)
treed77c37056096028e7b2df9e9373ad03ab5e10e1f /source/Server.cpp
parentConsole "reload" command implemented in MCServer, rather than in a plugin. (diff)
downloadcuberite-5ebbdb4d51288e3c472df407ac15f516d259d823.tar
cuberite-5ebbdb4d51288e3c472df407ac15f516d259d823.tar.gz
cuberite-5ebbdb4d51288e3c472df407ac15f516d259d823.tar.bz2
cuberite-5ebbdb4d51288e3c472df407ac15f516d259d823.tar.lz
cuberite-5ebbdb4d51288e3c472df407ac15f516d259d823.tar.xz
cuberite-5ebbdb4d51288e3c472df407ac15f516d259d823.tar.zst
cuberite-5ebbdb4d51288e3c472df407ac15f516d259d823.zip
Diffstat (limited to '')
-rw-r--r--source/Server.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/source/Server.cpp b/source/Server.cpp
index 7af575157..fe8076631 100644
--- a/source/Server.cpp
+++ b/source/Server.cpp
@@ -514,7 +514,39 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
void cServer::PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & a_Output)
{
- // TODO
+ typedef std::pair<AString, AString> AStringPair;
+ typedef std::vector<AStringPair> AStringPairs;
+
+ class cCallback :
+ public cPluginManager::cCommandEnumCallback
+ {
+ public:
+ cCallback(void) : m_MaxLen(0) {}
+
+ virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) override
+ {
+ if (!a_HelpString.empty())
+ {
+ m_Commands.push_back(AStringPair(a_Command, a_HelpString));
+ if (m_MaxLen < a_Command.length())
+ {
+ m_MaxLen = a_Command.length();
+ }
+ }
+ return false;
+ }
+
+ AStringPairs m_Commands;
+ size_t m_MaxLen;
+ } Callback;
+ cPluginManager::Get()->ForEachConsoleCommand(Callback);
+ std::sort(Callback.m_Commands.begin(), Callback.m_Commands.end());
+ for (AStringPairs::const_iterator itr = Callback.m_Commands.begin(), end = Callback.m_Commands.end(); itr != end; ++itr)
+ {
+ const AStringPair & cmd = *itr;
+ a_Output.Out(Printf("%-*s%s\n", Callback.m_MaxLen, cmd.first.c_str(), cmd.second.c_str()));
+ } // for itr - Callback.m_Commands[]
+ a_Output.Finished();
}