summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-09-17 15:42:13 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-09-17 15:42:13 +0000
commitd544f077bad47d6a499a07706604e84b417ab24d (patch)
tree05942f3fcdb790205db63ec1773a3bf2c9256fce /src
parent8831a187362bb9fd4e0f4c34e808868adf90fe56 (diff)
Now supports multiple commands seperated with \n. NOTE: These \n's are translated by the config parser to REAL linefeeds! If you want the literal \n, put \\n.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5273 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/modules/m_alias.cpp101
1 files changed, 61 insertions, 40 deletions
diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp
index bf085fcc0..6ee98834d 100644
--- a/src/modules/m_alias.cpp
+++ b/src/modules/m_alias.cpp
@@ -170,57 +170,78 @@ class ModuleAlias : public Module
/* Now, search and replace in a copy of the original_line, replacing $1 through $9 and $1- etc */
- std::string newline = Aliases[i].replace_with;
+ std::string::size_type crlf = Aliases[i].replace_with.find('\n');
- for (int v = 1; v < 10; v++)
+ if (crlf == std::string::npos)
{
- std::string var = "$";
- var.append(ConvToStr(v));
- var.append("-");
- std::string::size_type x = newline.find(var);
-
- while (x != std::string::npos)
- {
- newline.erase(x, var.length());
- newline.insert(x, GetVar(var, original_line));
- x = newline.find(var);
- }
-
- var = "$";
- var.append(ConvToStr(v));
- x = newline.find(var);
-
- while (x != std::string::npos)
+ DoCommand(Aliases[i].replace_with, user, original_line);
+ return 1;
+ }
+ else
+ {
+ irc::sepstream commands(Aliases[i].replace_with, '\n');
+ std::string command = "*";
+ while ((command = commands.GetToken()) != "")
{
- newline.erase(x, var.length());
- newline.insert(x, GetVar(var, original_line));
- x = newline.find(var);
+ DoCommand(command, user, original_line);
}
+ return 1;
}
+ }
+ }
+ return 0;
+ }
- /* Special variables */
- SearchAndReplace(newline, "$nick", user->nick);
- SearchAndReplace(newline, "$ident", user->ident);
- SearchAndReplace(newline, "$host", user->host);
- SearchAndReplace(newline, "$vhost", user->dhost);
+ void DoCommand(std::string newline, userrec* user, const std::string &original_line)
+ {
+ for (int v = 1; v < 10; v++)
+ {
+ std::string var = "$";
+ var.append(ConvToStr(v));
+ var.append("-");
+ std::string::size_type x = newline.find(var);
- irc::tokenstream ss(newline);
- const char* parv[127];
- int x = 0;
+ while (x != std::string::npos)
+ {
+ newline.erase(x, var.length());
+ newline.insert(x, GetVar(var, original_line));
+ x = newline.find(var);
+ }
- while ((pars[x] = ss.GetToken()) != "")
- {
- parv[x] = pars[x].c_str();
- ServerInstance->Log(DEBUG,"Parameter %d: %s", x, parv[x]);
- x++;
- }
+ var = "$";
+ var.append(ConvToStr(v));
+ x = newline.find(var);
- ServerInstance->CallCommandHandler(parv[0], &parv[1], x-1, user);
- return 1;
+ while (x != std::string::npos)
+ {
+ newline.erase(x, var.length());
+ newline.insert(x, GetVar(var, original_line));
+ x = newline.find(var);
}
}
- return 0;
- }
+
+ /* Special variables */
+ SearchAndReplace(newline, "$nick", user->nick);
+ SearchAndReplace(newline, "$ident", user->ident);
+ SearchAndReplace(newline, "$host", user->host);
+ SearchAndReplace(newline, "$vhost", user->dhost);
+
+ irc::tokenstream ss(newline);
+ const char* parv[127];
+ int x = 0;
+
+ while ((pars[x] = ss.GetToken()) != "")
+ {
+ parv[x] = pars[x].c_str();
+ ServerInstance->Log(DEBUG,"Parameter %d: %s", x, parv[x]);
+ x++;
+ }
+
+ if (ServerInstance->CallCommandHandler(parv[0], &parv[1], x-1, user) == CMD_INVALID)
+ {
+ user->WriteServ("421 %s %s :Unknown command", user->nick, parv[0]);
+ }
+ }
virtual void OnRehash(const std::string &parameter)
{