diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-21 20:33:32 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-21 20:33:32 +0000 |
commit | 0fad2325b495aea5302abce3d9c3f0bd0720281e (patch) | |
tree | f2ee4065b8232fa9b976141aa9aa83aa04177d68 /src/modules | |
parent | f337934f333df779b9703eb5e7de2ddbd77535ce (diff) |
Improved m_alias to only capture complete commands and rewrite them (bug #92 as reported by strike)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2601 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_alias.cpp | 94 | ||||
-rw-r--r-- | src/modules/m_conn_lusers.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_spanningtree.cpp | 6 |
3 files changed, 57 insertions, 45 deletions
diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index e0c202eed..18bf503ed 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -19,6 +19,7 @@ using namespace std; #include "users.h" #include "channels.h" #include "modules.h" +#include "helperfuncs.h" #include <vector> /* $ModDesc: Provides aliases of commands. */ @@ -26,7 +27,7 @@ using namespace std; class Alias { public: - std::string text; + irc::string text; std::string replace_with; std::string requires; bool uline; @@ -48,7 +49,9 @@ class ModuleAlias : public Module for (int i = 0; i < MyConf->Enumerate("alias"); i++) { Alias a; - a.text = MyConf->ReadValue("alias", "text", i); + std::string txt; + txt = MyConf->ReadValue("alias", "text", i); + a.text = txt.c_str(); a.replace_with = MyConf->ReadValue("alias", "replace", i); a.requires = MyConf->ReadValue("alias", "requires", i); @@ -81,57 +84,62 @@ class ModuleAlias : public Module return Version(1,0,0,1,VF_VENDOR); } - - virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user) + virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user) { - char data[MAXBUF]; - char *dptr; userrec *u = NULL; - - if (inbound) - { - strncpy(data, raw.c_str(),MAXBUF); - dptr = data; + irc::string c = command.c_str(); - for (unsigned int i = 0; i < Aliases.size(); i++) + for (unsigned int i = 0; i < Aliases.size(); i++) + { + log(DEBUG,"Check against alias %s: %s",Aliases[i].text.c_str(),c.c_str()); + if (Aliases[i].text == c) { - if (!strncasecmp(Aliases[i].text.c_str(),data,Aliases[i].text.length())) + if (Aliases[i].requires != "") { - if (Aliases[i].requires != "") - { - u = Srv->FindNick(Aliases[i].requires); - } - - if ((Aliases[i].requires != "") && (!u)) - { - Srv->SendServ(user->fd,"401 "+std::string(user->nick)+" "+Aliases[i].requires+" :is currently unavailable. Please try again later."); - raw = "PONG :"+Srv->GetServerName(); - return; - } - if (Aliases[i].uline) - { - if (!Srv->IsUlined(u->server)) - { - Srv->SendOpers("*** NOTICE -- Service "+Aliases[i].requires+" required by alias "+Aliases[i].text+" is not on a u-lined server, possibly underhanded antics detected!"); - Srv->SendServ(user->fd,"401 "+std::string(user->nick)+" "+Aliases[i].requires+" :is an imposter! Please inform an IRC operator as soon as possible."); - raw = "PONG :"+Srv->GetServerName(); - return; - } - } - - dptr += Aliases[i].text.length(); - if (strlen(dptr)) - { - raw = Aliases[i].replace_with + std::string(dptr); - } - else + u = Srv->FindNick(Aliases[i].requires); + } + + if ((Aliases[i].requires != "") && (!u)) + { + Srv->SendServ(user->fd,"401 "+std::string(user->nick)+" "+Aliases[i].requires+" :is currently unavailable. Please try again later."); + return 1; + } + if (Aliases[i].uline) + { + if (!Srv->IsUlined(u->server)) { - raw = Aliases[i].replace_with; + Srv->SendOpers("*** NOTICE -- Service "+Aliases[i].requires+" required by alias "+std::string(Aliases[i].text.c_str())+" is not on a u-lined server, possibly underhanded antics detected!"); + Srv->SendServ(user->fd,"401 "+std::string(user->nick)+" "+Aliases[i].requires+" :is an imposter! Please inform an IRC operator as soon as possible."); + return 1; } - return; } + + std::stringstream stuff(Aliases[i].replace_with); + for (int j = 1; j < pcnt; j++) + { + if (j) + stuff << " "; + stuff << parameters[j]; + } + + std::vector<std::string> items; + while (!stuff.eof()) + { + std::string data; + stuff >> data; + items.push_back(data); + } + + char* para[127]; + + for (unsigned int j = 1; j < items.size(); j++) + para[j-1] = (char*)items[j].c_str(); + + Srv->CallCommandHandler(items[0],para,items.size()-1,user); + return 1; } } + return 0; } virtual void OnRehash(std::string parameter) diff --git a/src/modules/m_conn_lusers.cpp b/src/modules/m_conn_lusers.cpp index 8a468c96a..245bd3c38 100644 --- a/src/modules/m_conn_lusers.cpp +++ b/src/modules/m_conn_lusers.cpp @@ -58,7 +58,7 @@ class ModuleConnLUSERS : public Module Module* Proto = Srv->FindModule("m_spanningtree.so"); if (Proto) { - Proto->OnPreCommand("LUSERS", NULL, 0, user); + Proto->OnPreCommand("LUSERS", NULL, 0, user, true); } else { diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index 604c081d8..a4b34f689 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -2635,8 +2635,12 @@ class ModuleSpanningTree : public Module return false; } - virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user) + virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user, bool validated) { + /* If the command doesnt appear to be valid, we dont want to mess with it. */ + if (!validated) + return; + if (command == "CONNECT") { return this->HandleConnect(parameters,pcnt,user); |