summaryrefslogtreecommitdiff
path: root/src/modules/m_alias.cpp
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/modules/m_alias.cpp
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/modules/m_alias.cpp')
-rw-r--r--src/modules/m_alias.cpp94
1 files changed, 51 insertions, 43 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)