From e4371c74f90239ae3f9bd269a712aa31ce97b6f6 Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 17 Sep 2006 15:00:09 +0000 Subject: Now it all works :) This is pretty smart stuff... Set up an alias like this: This will replace the $3 in the replace string with the 3rd word typed on the line by the user. Use $1 through $9 for items $1 to $9, and $1- to $9- to mean first word onwards, through 9th word onwards. Also there are special variables, such as $nick, $ident, $host, $vhost which can be used in the alias replace string. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5269 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_alias.cpp | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index d1c119feb..fc07b5f2d 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -97,7 +97,9 @@ class ModuleAlias : public Module varname.erase(varname.begin()); bool everything_after = (varname == "-"); std::string word = ""; - + + ServerInstance->Log(DEBUG,"Get var %d%s", index , everything_after ? " and all after it" : ""); + for (int j = 0; j < index; j++) word = ss.GetToken(); @@ -111,9 +113,22 @@ class ModuleAlias : public Module } } + ServerInstance->Log(DEBUG,"Var is '%s'", word.c_str()); + return word; } + void SearchAndReplace(std::string& newline, const std::string &find, const std::string &replace) + { + std::string::size_type x = newline.find(find); + while (x != std::string::npos) + { + newline.erase(x, find.length()); + newline.insert(x, replace); + x = newline.find(find); + } + } + virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line) { userrec *u = NULL; @@ -152,18 +167,38 @@ class ModuleAlias : public Module std::string newline = Aliases[i].replace_with; - for (int var = 1; var < 10; var++) + for (int v = 1; v < 10; v++) { - std::string var = "$" + ConvToStr(var) + "-"; + 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) + { + newline.erase(x, var.length()); + newline.insert(x, GetVar(var, original_line)); + x = newline.find(var); } } + /* 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; @@ -171,10 +206,11 @@ class ModuleAlias : public Module while ((pars[x] = ss.GetToken()) != "") { parv[x] = pars[x].c_str(); + ServerInstance->Log(DEBUG,"Parameter %d: %s", x, parv[x]); x++; } - ServerInstance->CallCommandHandler(parv[0], &parv[1], x-2, user); + ServerInstance->CallCommandHandler(parv[0], &parv[1], x-1, user); return 1; } } -- cgit v1.2.3