summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-21 20:33:32 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-21 20:33:32 +0000
commit0fad2325b495aea5302abce3d9c3f0bd0720281e (patch)
treef2ee4065b8232fa9b976141aa9aa83aa04177d68 /src
parentf337934f333df779b9703eb5e7de2ddbd77535ce (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')
-rw-r--r--src/command_parse.cpp7
-rw-r--r--src/modules.cpp2
-rw-r--r--src/modules/m_alias.cpp94
-rw-r--r--src/modules/m_conn_lusers.cpp2
-rw-r--r--src/modules/m_spanningtree.cpp6
5 files changed, 64 insertions, 47 deletions
diff --git a/src/command_parse.cpp b/src/command_parse.cpp
index 6f927e89a..7c26ffe61 100644
--- a/src/command_parse.cpp
+++ b/src/command_parse.cpp
@@ -525,6 +525,11 @@ void CommandParser::ProcessCommand(userrec *user, char* cmd)
{
/* activity resets the ping pending timer */
user->nping = TIME + user->pingmax;
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(OnPreCommand(command,command_p,items,user,false));
+ if (MOD_RESULT == 1) {
+ return;
+ }
if ((items) < cmdlist[i]->min_params)
{
log(DEBUG,"not enough parameters: %s %s",user->nick,command);
@@ -581,7 +586,7 @@ void CommandParser::ProcessCommand(userrec *user, char* cmd)
}
int MOD_RESULT = 0;
- FOREACH_RESULT(OnPreCommand(command,command_p,items,user));
+ FOREACH_RESULT(OnPreCommand(command,command_p,items,user,true));
if (MOD_RESULT == 1) {
return;
}
diff --git a/src/modules.cpp b/src/modules.cpp
index e39821a62..c175d7a57 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -244,7 +244,7 @@ void Module::OnLoadModule(Module* mod,std::string name) { };
void Module::OnUnloadModule(Module* mod,std::string name) { };
void Module::OnBackgroundTimer(time_t curtime) { };
void Module::OnSendList(userrec* user, chanrec* channel, char mode) { };
-int Module::OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user) { return 0; };
+int Module::OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user, bool validated) { return 0; };
bool Module::OnCheckReady(userrec* user) { return true; };
void Module::OnUserRegister(userrec* user) { };
int Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, std::string reason) { return 0; };
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);