]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_alias.cpp
and a little tweak to remote MOTD too.
[user/henk/code/inspircd.git] / src / modules / m_alias.cpp
index ffa6c1e4603d52bdc7c44888b652c3e203479ee4..2ac6ad55e114d06ce434f3982753ee5d5bee85d9 100644 (file)
  * ---------------------------------------------------
  */
 
+#include "inspircd.h"
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "inspircd.h"
-#include <vector>
+#include "wildcard.h"
 
 /* $ModDesc: Provides aliases of commands. */
 
@@ -34,6 +34,8 @@ class Alias : public classbase
        bool uline;
        /** Requires oper? */
        bool operonly;
+       /* is case sensitive params */
+       bool case_sensitive;
        /** Format that must be matched for use */
        std::string format;
 };
@@ -63,6 +65,7 @@ class ModuleAlias : public Module
                        a.uline = MyConf.ReadFlag("alias", "uline", i);
                        a.operonly = MyConf.ReadFlag("alias", "operonly", i);
                        a.format = MyConf.ReadValue("alias", "format", i);
+                       a.case_sensitive = MyConf.ReadFlag("alias", "matchcase", i);
                        Aliases.push_back(a);
                        AliasMap[txt] = 1;
                }
@@ -71,7 +74,7 @@ class ModuleAlias : public Module
  public:
        
        ModuleAlias(InspIRCd* Me)
-               : Module::Module(Me)
+               : Module(Me)
        {
                ReadAliases();
                pars.resize(127);
@@ -100,8 +103,6 @@ class ModuleAlias : public Module
                bool everything_after = (varname == "-");
                std::string word = "";
 
-               ServerInstance->Log(DEBUG,"Get var %d%s", index , everything_after ? " and all after it" : "");
-
                for (int j = 0; j < index; j++)
                        word = ss.GetToken();
 
@@ -115,8 +116,6 @@ class ModuleAlias : public Module
                        }
                }
 
-               ServerInstance->Log(DEBUG,"Var is '%s'", word.c_str());
-
                return word;
        }
 
@@ -162,12 +161,13 @@ class ModuleAlias : public Module
                        if (Aliases[i].text == c)
                        {
                                /* Does it match the pattern? */
-                               if ((!Aliases[i].format.empty()) && (!ServerInstance->MatchText(compare, Aliases[i].format)))
+                               if (!Aliases[i].format.empty())
                                {
-                                       continue;
+                                       if (!match(Aliases[i].case_sensitive, compare.c_str(), Aliases[i].format.c_str()))
+                                               continue;
                                }
 
-                               if ((Aliases[i].operonly) && (!*user->oper))
+                               if ((Aliases[i].operonly) && (!IS_OPER(user)))
                                        return 0;
 
                                if (Aliases[i].requires != "")
@@ -195,18 +195,15 @@ class ModuleAlias : public Module
 
                                if (crlf == std::string::npos)
                                {
-                                       ServerInstance->Log(DEBUG,"Single line alias: '%s'", Aliases[i].replace_with.c_str());
                                        DoCommand(Aliases[i].replace_with, user, safe);
                                        return 1;
                                }
                                else
                                {
-                                       ServerInstance->Log(DEBUG,"Multi line alias: '%s'", Aliases[i].replace_with.c_str());
                                        irc::sepstream commands(Aliases[i].replace_with, '\n');
                                        std::string command = "*";
                                        while ((command = commands.GetToken()) != "")
                                        {
-                                               ServerInstance->Log(DEBUG,"Execute: '%s'", command.c_str());
                                                DoCommand(command, user, safe);
                                        }
                                        return 1;
@@ -257,23 +254,13 @@ class ModuleAlias : public Module
                const char* parv[127];
                int x = 0;
 
-               while ((pars[x] = ss.GetToken()) != "")
+               while (ss.GetToken(pars[x]))
                {
                        parv[x] = pars[x].c_str();
-                       ServerInstance->Log(DEBUG,"Parameter %d: %s", x, parv[x]);
                        x++;
                }
 
-               ServerInstance->Log(DEBUG,"Call command handler on %s", parv[0]);
-
-               if (ServerInstance->Parser->CallHandler(parv[0], &parv[1], x-1, user) == CMD_INVALID)
-               {
-                       ServerInstance->Log(DEBUG,"Unknown command or not enough parameters");
-               }
-               else
-               {
-                       ServerInstance->Log(DEBUG,"Command handler called successfully.");
-               }
+               ServerInstance->Parser->CallHandler(parv[0], &parv[1], x-1, user);
        }
  
        virtual void OnRehash(userrec* user, const std::string &parameter)
@@ -301,7 +288,7 @@ class ModuleAliasFactory : public ModuleFactory
 };
 
 
-extern "C" void * init_module( void )
+extern "C" DllExport void * init_module( void )
 {
        return new ModuleAliasFactory;
 }