]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_alias.cpp
Updates, should be able to safely unload client modules with queries in progress...
[user/henk/code/inspircd.git] / src / modules / m_alias.cpp
index 18bf503ed9715224ebf38767bd33544e713a2057..869bc6a1f9c1f7a0cbe8d11ce7623f7644284574 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>
@@ -24,7 +24,7 @@ using namespace std;
 
 /* $ModDesc: Provides aliases of commands. */
 
-class Alias
+class Alias : public classbase
 {
        public:
                irc::string text;
@@ -40,8 +40,6 @@ class ModuleAlias : public Module
                ConfigReader *MyConf;
                std::vector<Alias> Aliases;
 
-               /* XXX - small issue, why is this marked public when it's not (really) intended for external use
-                * Fixed 30/11/05 by Brain as suggestion by w00t */
                virtual void ReadAliases()
                {
                        Aliases.clear();
@@ -73,10 +71,15 @@ class ModuleAlias : public Module
                        MyConf = new ConfigReader;
                        ReadAliases();
                }
+
+               void Implements(char* List)
+               {
+                       List[I_OnPreCommand] = List[I_OnRehash] = 1;
+               }
        
                virtual ~ModuleAlias()
                {
-                       delete MyConf;
+                       DELETE(MyConf);
                }
        
                virtual Version GetVersion()
@@ -84,27 +87,32 @@ class ModuleAlias : public Module
                        return Version(1,0,0,1,VF_VENDOR);
                }
 
-               virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user)
+               virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated)
                {
                        userrec *u = NULL;
                        irc::string c = command.c_str();
+
+                       /* If the command is valid, we dont want to know,
+                        * and if theyre not registered yet, we dont want
+                        * to know either
+                        */
+                       if ((validated) || (user->registered != 7))
+                               return 0;
                        
                        for (unsigned int i = 0; i < Aliases.size(); i++)
                        {
-                               log(DEBUG,"Check against alias %s: %s",Aliases[i].text.c_str(),c.c_str());
                                if (Aliases[i].text == c)
                                {
                                        if (Aliases[i].requires != "")
                                        {
                                                u = Srv->FindNick(Aliases[i].requires);
+                                               if (!u)
+                                               {
+                                                       Srv->SendServ(user->fd,"401 "+std::string(user->nick)+" "+Aliases[i].requires+" :is currently unavailable. Please try again later.");
+                                                       return 1;
+                                               }
                                        }
-                               
-                                       if ((Aliases[i].requires != "") && (!u))
-                                       {
-                                               Srv->SendServ(user->fd,"401 "+std::string(user->nick)+" "+Aliases[i].requires+" :is currently unavailable. Please try again later.");
-                                               return 1;
-                                       }
-                                       if (Aliases[i].uline)
+                                       if ((u != NULL) && (Aliases[i].requires != "") && (Aliases[i].uline))
                                        {
                                                if (!Srv->IsUlined(u->server))
                                                {
@@ -114,37 +122,35 @@ class ModuleAlias : public Module
                                                }
                                        }
 
-                                       std::stringstream stuff(Aliases[i].replace_with);
-                                       for (int j = 1; j < pcnt; j++)
+                                       std::string n = "";
+                                       for (int j = 0; j < pcnt; j++)
                                        {
                                                if (j)
-                                                       stuff << " ";
-                                               stuff << parameters[j];
-                                       }
-
-                                       std::vector<std::string> items;
-                                       while (!stuff.eof())
-                                       {
-                                               std::string data;
-                                               stuff >> data;
-                                               items.push_back(data);
+                                                       n = n + " ";
+                                               n = n + parameters[j];
                                        }
+                                       /* Final param now in n as one string */
+                                       std::stringstream stuff(Aliases[i].replace_with);
 
-                                       char* para[127];
+                                       std::string cmd = "";
+                                       std::string target = "";
+                                       stuff >> cmd;
+                                       stuff >> target;
 
-                                       for (unsigned int j = 1; j < items.size(); j++)
-                                               para[j-1] = (char*)items[j].c_str();
+                                       const char* para[2];
+                                       para[0] = target.c_str();
+                                       para[1] = n.c_str();
 
-                                       Srv->CallCommandHandler(items[0],para,items.size()-1,user);
+                                       Srv->CallCommandHandler(cmd,para,2,user);
                                        return 1;
                                }
                        }
                        return 0;
                }
   
-               virtual void OnRehash(std::string parameter)
+               virtual void OnRehash(const std::string &parameter)
                {
-                       delete MyConf;
+                       DELETE(MyConf);
                        MyConf = new ConfigReader;
                
                        ReadAliases();