]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_helpop.cpp
Expand searching in m_httpd_stats, add global handling of GET parameters (#1566)
[user/henk/code/inspircd.git] / src / modules / m_helpop.cpp
index 2fe958a71c2c96fa4c7bc71be7e0741a4c667c48..f913140d626b8b597d442bd38e7fa709204d0873 100644 (file)
 
 
 #include "inspircd.h"
+#include "modules/whois.h"
+
+enum
+{
+       // From UnrealIRCd.
+       RPL_WHOISHELPOP = 310,
+
+       // From ircd-ratbox.
+       ERR_HELPNOTFOUND = 524,
+       RPL_HELPSTART = 704,
+       RPL_HELPTXT = 705,
+       RPL_ENDOFHELP = 706
+};
 
 typedef std::map<std::string, std::string, irc::insensitive_swo> HelpopMap;
 static HelpopMap helpop_map;
@@ -41,8 +54,12 @@ class Helpop : public SimpleUserModeHandler
  */
 class CommandHelpop : public Command
 {
+ private:
        const std::string startkey;
+
  public:
+       std::string nohelp;
+
        CommandHelpop(Module* Creator)
                : Command(Creator, "HELPOP", 0)
                , startkey("start")
@@ -50,58 +67,56 @@ class CommandHelpop : public Command
                syntax = "<any-text>";
        }
 
-       CmdResult Handle (const std::vector<std::string> &parameters, User *user)
+       CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
        {
                const std::string& parameter = (!parameters.empty() ? parameters[0] : startkey);
 
                if (parameter == "index")
                {
                        /* iterate over all helpop items */
-                       user->WriteNumeric(290, ":HELPOP topic index");
+                       user->WriteNumeric(RPL_HELPSTART, parameter, "HELPOP topic index");
                        for (HelpopMap::const_iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
-                               user->WriteNumeric(292, ":  %s", iter->first.c_str());
-                       user->WriteNumeric(292, ":*** End of HELPOP topic index");
+                               user->WriteNumeric(RPL_HELPTXT, parameter, InspIRCd::Format("  %s", iter->first.c_str()));
+                       user->WriteNumeric(RPL_ENDOFHELP, parameter, "*** End of HELPOP topic index");
                }
                else
                {
-                       user->WriteNumeric(290, ":*** HELPOP for %s", parameter.c_str());
-                       user->WriteNumeric(292, ": -");
-
                        HelpopMap::const_iterator iter = helpop_map.find(parameter);
-
                        if (iter == helpop_map.end())
                        {
-                               iter = helpop_map.find("nohelp");
+                               user->WriteNumeric(ERR_HELPNOTFOUND, parameter, nohelp);
+                               return CMD_FAILURE;
                        }
 
                        const std::string& value = iter->second;
-                       irc::sepstream stream(value, '\n');
+                       irc::sepstream stream(value, '\n', true);
                        std::string token = "*";
 
+                       user->WriteNumeric(RPL_HELPSTART, parameter, InspIRCd::Format("*** HELPOP for %s", parameter.c_str()));
                        while (stream.GetToken(token))
                        {
                                // Writing a blank line will not work with some clients
                                if (token.empty())
-                                       user->WriteNumeric(292, ": ");
+                                       user->WriteNumeric(RPL_HELPTXT, parameter, ' ');
                                else
-                                       user->WriteNumeric(292, ":%s", token.c_str());
+                                       user->WriteNumeric(RPL_HELPTXT, parameter, token);
                        }
-
-                       user->WriteNumeric(292, ": -");
-                       user->WriteNumeric(292, ":*** End of HELPOP");
+                       user->WriteNumeric(RPL_ENDOFHELP, parameter, "*** End of HELPOP");
                }
                return CMD_SUCCESS;
        }
 };
 
-class ModuleHelpop : public Module
+class ModuleHelpop : public Module, public Whois::EventListener
 {
                CommandHelpop cmd;
                Helpop ho;
 
        public:
                ModuleHelpop()
-                       : cmd(this), ho(this)
+                       : Whois::EventListener(this)
+                       , cmd(this)
+                       , ho(this)
                {
                }
 
@@ -130,20 +145,18 @@ class ModuleHelpop : public Module
                                // error!
                                throw ModuleException("m_helpop: Helpop file is missing important entry 'start'. Please check the example conf.");
                        }
-                       else if (help.find("nohelp") == help.end())
-                       {
-                               // error!
-                               throw ModuleException("m_helpop: Helpop file is missing important entry 'nohelp'. Please check the example conf.");
-                       }
 
                        helpop_map.swap(help);
+
+                       ConfigTag* tag = ServerInstance->Config->ConfValue("helpmsg");
+                       cmd.nohelp = tag->getString("nohelp", "There is no help for the topic you searched for. Please try again.", 1);
                }
 
-               void OnWhois(User* src, User* dst) CXX11_OVERRIDE
+               void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
                {
-                       if (dst->IsModeSet(ho))
+                       if (whois.GetTarget()->IsModeSet(ho))
                        {
-                               ServerInstance->SendWhoisLine(src, dst, 310, dst->nick+" :is available for help.");
+                               whois.SendLine(RPL_WHOISHELPOP, "is available for help.");
                        }
                }