]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_helpop.cpp
Updated copyrights in headers etc using perl inplace edit
[user/henk/code/inspircd.git] / src / modules / m_helpop.cpp
index ca4b4fed3ab0e7b61f3be603f9bda21e79f60f7f..9af6d6dc41917616239a13f3540275c1fdcebcb9 100644 (file)
@@ -2,7 +2,7 @@
  *   | Inspire Internet Relay Chat Daemon |
  *   +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *   E-mail:
  *<brain@chatspike.net>
  *       <Craig@chatspike.net>
@@ -30,64 +30,76 @@ void handle_helpop(char**, int, userrec*);
 bool do_helpop(char**, int, userrec*);
 void sendtohelpop(userrec*, int, char**);
 
-
 /* $ModDesc: /helpop Command, Works like Unreal helpop */
 
-void handle_helpop(char **parameters, int pcnt, userrec *user)
+class cmd_helpop : public command_t
 {
-       char a[MAXBUF];
-       std::string output = " ";
+ public:
+        cmd_helpop () : command_t("HELPOP",0,0)
+        {
+                this->source = "m_helpop.so";
+        }
 
-       if (pcnt < 1)
+       void Handle (char **parameters, int pcnt, userrec *user)
        {
-               do_helpop(NULL,pcnt,user);
-               return;
-       }
+               char a[MAXBUF];
+               std::string output = " ";
 
-       if (parameters[0][0] == '!')
-       {
-               // Force send to all +h users
-               sendtohelpop(user, pcnt, parameters);
-       }
-       else if (parameters[0][0] == '?')
-       {
-               // Force to the helpop system with no forward if not found.
-               if (do_helpop(parameters, pcnt, user) == false)
+               if (!helpop)
+                       return;
+
+               if (pcnt < 1)
                {
-                       // Not handled by the Database, Tell the user, and bail.
-                       for (int i = 1; output != ""; i++)
-                       {
-                               snprintf(a,MAXBUF,"line%d",i);
-                               output = helpop->ReadValue("nohelp", std::string(a), 0);
+                       do_helpop(NULL,pcnt,user);
+                       return;
+               }
 
-                               if(output != "")
+               if (parameters[0][0] == '!')
+               {
+                       // Force send to all +h users
+                       sendtohelpop(user, pcnt, parameters);
+               }
+               else if (parameters[0][0] == '?')
+               {
+                       // Force to the helpop system with no forward if not found.
+                       if (do_helpop(parameters, pcnt, user) == false)
+                       {
+                               // Not handled by the Database, Tell the user, and bail.
+                               for (int i = 1; output != ""; i++)
                                {
-                                       Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
+                                       snprintf(a,MAXBUF,"line%d",i);
+                                       output = helpop->ReadValue("nohelp", std::string(a), 0);
+       
+                                       if(output != "")
+                                       {
+                                               Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
+                                       }
                                }
                        }
                }
-       }
-       else
-       {
-               // Check with the helpop database, if not found send to +h
-               if (do_helpop(parameters, pcnt, user) == false)
+               else
                {
-                       // Not handled by the Database, Tell the user, and forward.
-                       for (int i = 1; output != ""; i++)
-                       {
-                               snprintf(a,MAXBUF,"line%d",i);
-                               /* "nohelpo" for opers "nohelp" for users */
-                               output = helpop->ReadValue("nohelpo", std::string(a), 0);
-                               if (output != "")
-                               {
-                                       Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
-                               }
-                       }
-                       // Forward.
-                       sendtohelpop(user, pcnt, parameters);
+                       // Check with the helpop database, if not found send to +h
+                       if (do_helpop(parameters, pcnt, user) == false)
+                       {
+                               // Not handled by the Database, Tell the user, and forward.
+                               for (int i = 1; output != ""; i++)
+                               {
+                                       snprintf(a,MAXBUF,"line%d",i);
+                                       /* "nohelpo" for opers "nohelp" for users */
+                                       output = helpop->ReadValue("nohelpo", std::string(a), 0);
+                                       if (output != "")
+                                       {
+                                               Srv->SendTo(NULL,user,"290 "+std::string(user->nick)+" :"+output);
+                                       }
+                               }
+                               // Forward.
+                               sendtohelpop(user, pcnt, parameters);
+                       }
                }
        }
-}
+};
+
 
 bool do_helpop(char **parameters, int pcnt, userrec *src)
 {
@@ -153,11 +165,13 @@ class ModuleHelpop : public Module
        private:
                ConfigReader *conf;
                std::string  h_file;
+               cmd_helpop* mycommand;
 
        public:
-               ModuleHelpop()
+               ModuleHelpop(Server* Me)
+                       : Module::Module(Me)
                {
-                       Srv  = new Server;
+                       Srv  = Me;
 
                        ReadConfig();
                        if (!Srv->AddExtendedMode('h',MT_CLIENT,true,0,0))
@@ -166,7 +180,8 @@ class ModuleHelpop : public Module
                                return;
                        }
 
-                       Srv->AddCommand("HELPOP",handle_helpop,0,0,"m_helpop.so");
+                       mycommand = new cmd_helpop();
+                       Srv->AddCommand(mycommand);
                }
 
                virtual void ReadConfig()
@@ -176,6 +191,7 @@ class ModuleHelpop : public Module
 
                        if (h_file == "")
                        {
+                               helpop = NULL;
                                log(DEFAULT,"m_helpop: Helpop file not Specified.");
                                return;
                        }
@@ -190,11 +206,16 @@ class ModuleHelpop : public Module
                        }
                }
 
+               void Implements(char* List)
+               {
+                       List[I_OnRehash] = List[I_OnExtendedMode] = List[I_OnWhois] = 1;
+               }
 
-               virtual void OnRehash()
+               virtual void OnRehash(std::string parameter)
                {
                        delete conf;
-                       delete helpop;
+                       if (helpop)
+                               delete helpop;
 
                        ReadConfig();
                }
@@ -218,7 +239,6 @@ class ModuleHelpop : public Module
 
                virtual ~ModuleHelpop()
                {
-                       delete Srv;
                        delete conf;
                        delete helpop;
                }
@@ -240,9 +260,9 @@ class ModuleHelpopFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleHelpop;
+               return new ModuleHelpop(Me);
        }
        
 };