]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_alias.cpp
m_remove Recognize /REMOVE <chan> <nick>
[user/henk/code/inspircd.git] / src / modules / m_alias.cpp
index 78628cf067350bedc8af11db5a80f13eaf45cac2..76476109908b55065ec980436766a2373d6d3dc7 100644 (file)
@@ -136,8 +136,6 @@ class ModuleAlias : public Module
 
        ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
        {
-               AliasMap::iterator i, upperbound;
-
                /* If theyre not registered yet, we dont want
                 * to know.
                 */
@@ -145,18 +143,16 @@ class ModuleAlias : public Module
                        return MOD_RES_PASSTHRU;
 
                /* We dont have any commands looking like this? Stop processing. */
-               i = Aliases.find(command);
-               if (i == Aliases.end())
+               std::pair<AliasMap::iterator, AliasMap::iterator> iters = Aliases.equal_range(command);
+               if (iters.first == iters.second)
                        return MOD_RES_PASSTHRU;
-               /* Avoid iterating on to different aliases if no patterns match. */
-               upperbound = Aliases.upper_bound(command);
 
                /* The parameters for the command in their original form, with the command stripped off */
                std::string compare = original_line.substr(command.length());
                while (*(compare.c_str()) == ' ')
                        compare.erase(compare.begin());
 
-               while (i != upperbound)
+               for (AliasMap::iterator i = iters.first; i != iters.second; ++i)
                {
                        if (i->second.UserCommand)
                        {
@@ -165,8 +161,6 @@ class ModuleAlias : public Module
                                        return MOD_RES_DENY;
                                }
                        }
-
-                       i++;
                }
 
                // If we made it here, no aliases actually matched.
@@ -181,7 +175,7 @@ class ModuleAlias : public Module
                }
 
                // fcommands are only for local users. Spanningtree will send them back out as their original cmd.
-               if (!user || !IS_LOCAL(user))
+               if (!IS_LOCAL(user))
                {
                        return;
                }
@@ -213,21 +207,16 @@ class ModuleAlias : public Module
                // nor do we give a shit about the prefix
                scommand.erase(scommand.begin());
 
-               AliasMap::iterator i = Aliases.find(scommand);
-
-               if (i == Aliases.end())
+               std::pair<AliasMap::iterator, AliasMap::iterator> iters = Aliases.equal_range(scommand);
+               if (iters.first == iters.second)
                        return;
 
-               /* Avoid iterating on to other aliases if no patterns match */
-               AliasMap::iterator upperbound = Aliases.upper_bound(scommand);
-
-
                /* The parameters for the command in their original form, with the command stripped off */
                std::string compare = text.substr(scommand.length() + 1);
                while (*(compare.c_str()) == ' ')
                        compare.erase(compare.begin());
 
-               while (i != upperbound)
+               for (AliasMap::iterator i = iters.first; i != iters.second; ++i)
                {
                        if (i->second.ChannelCommand)
                        {
@@ -235,16 +224,12 @@ class ModuleAlias : public Module
                                if (DoAlias(user, c, &(i->second), compare, text.substr(1)))
                                        return;
                        }
-
-                       i++;
                }
        }
 
 
        int DoAlias(User *user, Channel *c, Alias *a, const std::string& compare, const std::string& safe)
        {
-               User *u = NULL;
-
                /* Does it match the pattern? */
                if (!a->format.empty())
                {
@@ -265,16 +250,14 @@ class ModuleAlias : public Module
 
                if (!a->RequiredNick.empty())
                {
-                       u = ServerInstance->FindNick(a->RequiredNick);
+                       User* u = ServerInstance->FindNick(a->RequiredNick);
                        if (!u)
                        {
                                user->WriteNumeric(ERR_NOSUCHNICK, a->RequiredNick + " :is currently unavailable. Please try again later.");
                                return 1;
                        }
-               }
-               if ((u != NULL) && (!a->RequiredNick.empty()) && (a->ULineOnly))
-               {
-                       if (!ServerInstance->ULine(u->server))
+
+                       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.");
@@ -310,37 +293,37 @@ class ModuleAlias : public Module
                for (unsigned int i = 0; i < newline.length(); i++)
                {
                        char c = newline[i];
-                       if (c == '$')
+                       if ((c == '$') && (i + 1 < newline.length()))
                        {
                                if (isdigit(newline[i+1]))
                                {
-                                       int len = (newline[i+2] == '-') ? 3 : 2;
+                                       int len = ((i + 2 < newline.length()) && (newline[i+2] == '-')) ? 3 : 2;
                                        std::string var = newline.substr(i, len);
                                        result.append(GetVar(var, original_line));
                                        i += len - 1;
                                }
-                               else if (newline.substr(i, 5) == "$nick")
+                               else if (!newline.compare(i, 5, "$nick", 5))
                                {
                                        result.append(user->nick);
                                        i += 4;
                                }
-                               else if (newline.substr(i, 5) == "$host")
+                               else if (!newline.compare(i, 5, "$host", 5))
                                {
                                        result.append(user->host);
                                        i += 4;
                                }
-                               else if (newline.substr(i, 5) == "$chan")
+                               else if (!newline.compare(i, 5, "$chan", 5))
                                {
                                        if (chan)
                                                result.append(chan->name);
                                        i += 4;
                                }
-                               else if (newline.substr(i, 6) == "$ident")
+                               else if (!newline.compare(i, 6, "$ident", 6))
                                {
                                        result.append(user->ident);
                                        i += 5;
                                }
-                               else if (newline.substr(i, 6) == "$vhost")
+                               else if (!newline.compare(i, 6, "$vhost", 6))
                                {
                                        result.append(user->dhost);
                                        i += 5;