* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
* E-mail:
* <brain@chatspike.net>
* <Craig@chatspike.net>
/* $ModDesc: Provides aliases of commands. */
-class Alias
+class Alias : public classbase
{
public:
irc::string text;
ConfigReader *MyConf;
std::vector<Alias> Aliases;
- /* XXX - small issue, why is this marked public when it's not (really) intended for external use
- * Fixed 30/11/05 by Brain as suggestion by w00t */
virtual void ReadAliases()
{
Aliases.clear();
MyConf = new ConfigReader;
ReadAliases();
}
+
+ void Implements(char* List)
+ {
+ List[I_OnPreCommand] = List[I_OnRehash] = 1;
+ }
virtual ~ModuleAlias()
{
- delete MyConf;
+ DELETE(MyConf);
}
virtual Version GetVersion()
return Version(1,0,0,1,VF_VENDOR);
}
- virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user)
+ virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated)
{
userrec *u = NULL;
irc::string c = command.c_str();
+
+ /* If the command is valid, we dont want to know,
+ * and if theyre not registered yet, we dont want
+ * to know either
+ */
+ if ((validated) || (user->registered != REG_ALL))
+ return 0;
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 (Aliases[i].requires != "")
{
u = Srv->FindNick(Aliases[i].requires);
+ if (!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].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 ((u != NULL) && (Aliases[i].requires != "") && (Aliases[i].uline))
{
if (!Srv->IsUlined(u->server))
{
}
}
- std::stringstream stuff(Aliases[i].replace_with);
- for (int j = 1; j < pcnt; j++)
+ std::string n = "";
+ for (int j = 0; 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);
+ n = n + " ";
+ n = n + parameters[j];
}
+ /* Final param now in n as one string */
+ std::stringstream stuff(Aliases[i].replace_with);
- char* para[127];
+ std::string cmd = "";
+ std::string target = "";
+ stuff >> cmd;
+ stuff >> target;
- for (unsigned int j = 1; j < items.size(); j++)
- para[j-1] = (char*)items[j].c_str();
+ const char* para[2];
+ para[0] = target.c_str();
+ para[1] = n.c_str();
- Srv->CallCommandHandler(items[0],para,items.size()-1,user);
+ Srv->CallCommandHandler(cmd,para,2,user);
return 1;
}
}
return 0;
}
- virtual void OnRehash(std::string parameter)
+ virtual void OnRehash(const std::string ¶meter)
{
- delete MyConf;
+ DELETE(MyConf);
MyConf = new ConfigReader;
ReadAliases();