]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_alias.cpp
Merge tag 'v2.0.25' into master.
[user/henk/code/inspircd.git] / src / modules / m_alias.cpp
index 6bd59a78070a788eaf66b951fd84ea12dad841df..bdb242938de2d62f1c6b7ab33b04d9570ac40324 100644 (file)
@@ -42,9 +42,6 @@ class Alias
        /** Requires oper? */
        bool OperOnly;
 
-       /* is case sensitive params */
-       bool CaseSensitive;
-
        /* whether or not it may be executed via fantasy (default OFF) */
        bool ChannelCommand;
 
@@ -57,12 +54,12 @@ class Alias
 
 class ModuleAlias : public Module
 {
-       char fprefix;
+       std::string fprefix;
 
        /* We cant use a map, there may be multiple aliases with the same name.
         * We can, however, use a fancy invention: the multimap. Maps a key to one or more values.
         *              -- w00t
-     */
+        */
        typedef insp::flat_multimap<std::string, Alias, irc::insensitive_swo> AliasMap;
 
        AliasMap Aliases;
@@ -76,8 +73,7 @@ class ModuleAlias : public Module
        {
                ConfigTag* fantasy = ServerInstance->Config->ConfValue("fantasy");
                AllowBots = fantasy->getBool("allowbots", false);
-               std::string fpre = fantasy->getString("prefix", "!");
-               fprefix = fpre.empty() ? '!' : fpre[0];
+               fprefix = fantasy->getString("prefix", "!", 1, ServerInstance->Config->Limits.MaxLine);
 
                Aliases.clear();
                ConfigTagList tags = ServerInstance->Config->ConfTags("alias");
@@ -94,7 +90,6 @@ class ModuleAlias : public Module
                        a.UserCommand = tag->getBool("usercommand", true);
                        a.OperOnly = tag->getBool("operonly");
                        a.format = tag->getString("format");
-                       a.CaseSensitive = tag->getBool("matchcase");
                        Aliases.insert(std::make_pair(a.AliasedCommand, a));
                }
        }
@@ -193,26 +188,26 @@ class ModuleAlias : public Module
                irc::spacesepstream ss(text);
                ss.GetToken(scommand);
 
-               if (scommand.empty())
+               if (scommand.size() <= fprefix.size())
                {
                        return; // wtfbbq
                }
 
                // we don't want to touch non-fantasy stuff
-               if (*scommand.c_str() != fprefix)
+               if (scommand.compare(0, fprefix.size(), fprefix) != 0)
                {
                        return;
                }
 
                // nor do we give a shit about the prefix
-               scommand.erase(scommand.begin());
+               scommand.erase(0, fprefix.size());
 
                std::pair<AliasMap::iterator, AliasMap::iterator> iters = Aliases.equal_range(scommand);
                if (iters.first == iters.second)
                        return;
 
                /* The parameters for the command in their original form, with the command stripped off */
-               std::string compare(text, scommand.length() + 1);
+               std::string compare(text, scommand.length() + fprefix.size());
                while (*(compare.c_str()) == ' ')
                        compare.erase(compare.begin());
 
@@ -220,8 +215,8 @@ class ModuleAlias : public Module
                {
                        if (i->second.ChannelCommand)
                        {
-                               // We use substr(1) here to remove the fantasy prefix
-                               if (DoAlias(user, c, &(i->second), compare, text.substr(1)))
+                               // We use substr here to remove the fantasy prefix
+                               if (DoAlias(user, c, &(i->second), compare, text.substr(fprefix.size())))
                                        return;
                        }
                }
@@ -233,16 +228,8 @@ class ModuleAlias : public Module
                /* Does it match the pattern? */
                if (!a->format.empty())
                {
-                       if (a->CaseSensitive)
-                       {
-                               if (!InspIRCd::Match(compare, a->format, rfc_case_sensitive_map))
-                                       return 0;
-                       }
-                       else
-                       {
-                               if (!InspIRCd::Match(compare, a->format))
-                                       return 0;
-                       }
+                       if (!InspIRCd::Match(compare, a->format))
+                               return 0;
                }
 
                if ((a->OperOnly) && (!user->IsOper()))
@@ -253,14 +240,14 @@ class ModuleAlias : public Module
                        User* u = ServerInstance->FindNick(a->RequiredNick);
                        if (!u)
                        {
-                               user->WriteNumeric(ERR_NOSUCHNICK, a->RequiredNick + " :is currently unavailable. Please try again later.");
+                               user->WriteNumeric(ERR_NOSUCHNICK, a->RequiredNick, "is currently unavailable. Please try again later.");
                                return 1;
                        }
 
                        if ((a->ULineOnly) && (!u->server->IsULine()))
                        {
                                ServerInstance->SNO->WriteToSnoMask('a', "NOTICE -- Service "+a->RequiredNick+" required by alias "+a->AliasedCommand+" is not on a u-lined server, possibly underhanded antics detected!");
-                               user->WriteNumeric(ERR_NOSUCHNICK, a->RequiredNick + " :is an imposter! Please inform an IRC operator as soon as possible.");
+                               user->WriteNumeric(ERR_NOSUCHNICK, a->RequiredNick, "is an imposter! Please inform an IRC operator as soon as possible.");
                                return 1;
                        }
                }
@@ -271,7 +258,7 @@ class ModuleAlias : public Module
 
                if (crlf == std::string::npos)
                {
-                       DoCommand(a->ReplaceFormat, user, c, safe);
+                       DoCommand(a->ReplaceFormat, user, c, safe, a);
                        return 1;
                }
                else
@@ -280,13 +267,13 @@ class ModuleAlias : public Module
                        std::string scommand;
                        while (commands.GetToken(scommand))
                        {
-                               DoCommand(scommand, user, c, safe);
+                               DoCommand(scommand, user, c, safe, a);
                        }
                        return 1;
                }
        }
 
-       void DoCommand(const std::string& newline, User* user, Channel *chan, const std::string &original_line)
+       void DoCommand(const std::string& newline, User* user, Channel *chan, const std::string &original_line, Alias* a)
        {
                std::string result;
                result.reserve(newline.length());
@@ -309,7 +296,7 @@ class ModuleAlias : public Module
                                }
                                else if (!newline.compare(i, 5, "$host", 5))
                                {
-                                       result.append(user->host);
+                                       result.append(user->GetRealHost());
                                        i += 4;
                                }
                                else if (!newline.compare(i, 5, "$chan", 5))
@@ -325,9 +312,14 @@ class ModuleAlias : public Module
                                }
                                else if (!newline.compare(i, 6, "$vhost", 6))
                                {
-                                       result.append(user->dhost);
+                                       result.append(user->GetDisplayedHost());
                                        i += 5;
                                }
+                               else if (!newline.compare(i, 12, "$requirement", 12))
+                               {
+                                       result.append(a->RequiredNick);
+                                       i += 11;
+                               }
                                else
                                        result.push_back(c);
                        }
@@ -347,7 +339,7 @@ class ModuleAlias : public Module
                ServerInstance->Parser.CallHandler(command, pars, user);
        }
 
-       void Prioritize()
+       void Prioritize() CXX11_OVERRIDE
        {
                // Prioritise after spanningtree so that channel aliases show the alias before the effects.
                Module* linkmod = ServerInstance->Modules->Find("m_spanningtree.so");