ModResult OnPreCommand(std::string &command, std::vector<std::string> ¶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.
*/
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)
{
return MOD_RES_DENY;
}
}
-
- i++;
}
// If we made it here, no aliases actually matched.
// 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)
{
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())
{
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.");
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;
{
pars.push_back(token);
}
- ServerInstance->Parser->CallHandler(command, pars, user);
+ ServerInstance->Parser.CallHandler(command, pars, user);
}
void Prioritize()