X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_alias.cpp;h=2d4bdded30fa70515972fb827bd0034ba1a41440;hb=acccaa39641500b8a691db4136e6571102a438ed;hp=5fea846daccadcf1b8d3c1e6bf60064363583384;hpb=11916574f67962dce1d7a2fdf7ef6a3d2d1fa49f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 5fea846da..2d4bdded3 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -136,8 +136,6 @@ class ModuleAlias : public Module ModResult OnPreCommand(std::string &command, std::vector ¶meters, 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 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 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 (!u->server->IsULine()) + + 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; @@ -361,7 +344,7 @@ class ModuleAlias : public Module { pars.push_back(token); } - ServerInstance->Parser->CallHandler(command, pars, user); + ServerInstance->Parser.CallHandler(command, pars, user); } void Prioritize()