summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-09-17 14:35:21 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-09-17 14:35:21 +0000
commit66bf2588e01d7af9872bee6fb9c6ebfaad3ac8e5 (patch)
treeef407acc92d3f9543009100edc5980a7a8a2814d /src/modules
parent81fda049c16575a0e5d10a20c334ab4fe01d7a6d (diff)
New m_alias, this probably doesnt work yet
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5268 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_alias.cpp68
1 files changed, 53 insertions, 15 deletions
diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp
index 26ab8eae7..d1c119feb 100644
--- a/src/modules/m_alias.cpp
+++ b/src/modules/m_alias.cpp
@@ -43,6 +43,7 @@ class ModuleAlias : public Module
{
private:
std::vector<Alias> Aliases;
+ std::vector<std::string> pars;
virtual void ReadAliases()
{
@@ -71,6 +72,7 @@ class ModuleAlias : public Module
: Module::Module(Me)
{
ReadAliases();
+ pars.resize(127);
}
void Implements(char* List)
@@ -87,6 +89,31 @@ class ModuleAlias : public Module
return Version(1,0,0,1,VF_VENDOR);
}
+ std::string GetVar(std::string varname, const std::string &original_line)
+ {
+ irc::spacesepstream ss(original_line);
+ varname.erase(varname.begin());
+ int index = *(varname.begin()) - 48;
+ varname.erase(varname.begin());
+ bool everything_after = (varname == "-");
+ std::string word = "";
+
+ for (int j = 0; j < index; j++)
+ word = ss.GetToken();
+
+ if (everything_after)
+ {
+ std::string more = "*";
+ while ((more = ss.GetToken()) != "")
+ {
+ word.append(" ");
+ word.append(more);
+ }
+ }
+
+ return word;
+ }
+
virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
{
userrec *u = NULL;
@@ -120,23 +147,34 @@ class ModuleAlias : public Module
return 1;
}
}
- std::string n = "";
- for (int j = 0; j < pcnt; j++)
+
+ /* 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;
+
+ for (int var = 1; var < 10; var++)
+ {
+ std::string var = "$" + ConvToStr(var) + "-";
+ 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));
+ }
+ }
+
+ irc::tokenstream ss(newline);
+ const char* parv[127];
+ int x = 0;
+
+ while ((pars[x] = ss.GetToken()) != "")
{
- if (j)
- n = n + " ";
- n = n + parameters[j];
+ parv[x] = pars[x].c_str();
+ x++;
}
- /* Final param now in n as one string */
- std::stringstream stuff(Aliases[i].replace_with);
- std::string cmd = "";
- std::string target = "";
- stuff >> cmd;
- stuff >> target;
- const char* para[2];
- para[0] = target.c_str();
- para[1] = n.c_str();
- ServerInstance->CallCommandHandler(cmd,para,2,user);
+
+ ServerInstance->CallCommandHandler(parv[0], &parv[1], x-2, user);
return 1;
}
}