]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_helpop.cpp
Mode +b stuff, probably wont work yet
[user/henk/code/inspircd.git] / src / modules / m_helpop.cpp
index 9af6d6dc41917616239a13f3540275c1fdcebcb9..b6c723ca79e1cd126a1054d90cc1d39322497bf5 100644 (file)
@@ -22,9 +22,8 @@ using namespace std;
 #include "helperfuncs.h"
 
 // Global Vars
-/* XXX - should all this be marked static? clear the global namespace, etc. */
-ConfigReader *helpop;
-Server *Srv;
+static ConfigReader *helpop;
+static Server *Srv;
 
 void handle_helpop(char**, int, userrec*);
 bool do_helpop(char**, int, userrec*);
@@ -35,7 +34,7 @@ void sendtohelpop(userrec*, int, char**);
 class cmd_helpop : public command_t
 {
  public:
-        cmd_helpop () : command_t("HELPOP",0,0)
+        cmd_helpop () : command_t("HELPOP",0,1)
         {
                 this->source = "m_helpop.so";
         }
@@ -106,10 +105,9 @@ bool do_helpop(char **parameters, int pcnt, userrec *src)
        char *search;
        std::string output = " "; // a fix bought to you by brain :p
        char a[MAXBUF];
-       char lower[MAXBUF];
        int nlines = 0;
 
-       if (!parameters)
+       if (!pcnt)
        {
                search = "start";
        }
@@ -123,16 +121,12 @@ bool do_helpop(char **parameters, int pcnt, userrec *src)
                search++;
        }
 
-       /* XXX - don't we have an strtolower()? if not, might pay to add one.. that works on char *, preferably.. */
-       strlcpy(lower, search, MAXBUF);
-       for (unsigned int t = 0; t < strlen(lower); t++)
-               lower[t] = tolower(lower[t]);
-
+       strlower(search);
 
        for (int i = 1; output != ""; i++)
        {
                snprintf(a,MAXBUF,"line%d",i);
-               output = helpop->ReadValue(lower, a, 0);
+               output = helpop->ReadValue(search, a, 0);
                if (output != "")
                {
                        Srv->SendTo(NULL,src,"290 "+std::string(src->nick)+" :"+output);
@@ -160,6 +154,15 @@ void sendtohelpop(userrec *src, int pcnt, char **params)
        Srv->SendToModeMask("oh",WM_AND,line);
 }
 
+class HelpopException : public ModuleException
+{
+ private:
+       std::string err;
+ public:
+       HelpopException(std::string message) : err(message) { }
+       virtual const char* GetReason() { return err.c_str(); }
+};
+
 class ModuleHelpop : public Module
 {
        private:
@@ -192,8 +195,8 @@ class ModuleHelpop : public Module
                        if (h_file == "")
                        {
                                helpop = NULL;
-                               log(DEFAULT,"m_helpop: Helpop file not Specified.");
-                               return;
+                               HelpopException e("Missing helpop file");
+                               throw(e);
                        }
 
                        helpop = new ConfigReader(h_file);
@@ -201,8 +204,8 @@ class ModuleHelpop : public Module
                                (helpop->ReadValue("nohelpo", "line1", 0) == "") ||
                                (helpop->ReadValue("start",   "line1", 0) == ""))
                        {
-                               log(DEFAULT,"m_helpop: Helpop file is missing important entries. Please check the example conf.");
-                               return;
+                               HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf.");
+                               throw(e);
                        }
                }
 
@@ -211,11 +214,11 @@ class ModuleHelpop : public Module
                        List[I_OnRehash] = List[I_OnExtendedMode] = List[I_OnWhois] = 1;
                }
 
-               virtual void OnRehash(std::string parameter)
+               virtual void OnRehash(const std::string &parameter)
                {
-                       delete conf;
+                       DELETE(conf);
                        if (helpop)
-                               delete helpop;
+                               DELETE(helpop);
 
                        ReadConfig();
                }
@@ -239,8 +242,8 @@ class ModuleHelpop : public Module
 
                virtual ~ModuleHelpop()
                {
-                       delete conf;
-                       delete helpop;
+                       DELETE(conf);
+                       DELETE(helpop);
                }
        
                virtual Version GetVersion()