summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_alias.cpp211
1 files changed, 105 insertions, 106 deletions
diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp
index 9bb2a9df2..837750da8 100644
--- a/src/modules/m_alias.cpp
+++ b/src/modules/m_alias.cpp
@@ -1,15 +1,15 @@
-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
+/* +------------------------------------+
+ * | Inspire Internet Relay Chat Daemon |
+ * +------------------------------------+
*
* Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
- * E-mail:
- * <brain@chatspike.net>
- * <Craig@chatspike.net>
- *
+ * E-mail:
+ * <brain@chatspike.net>
+ * <Craig@chatspike.net>
+ *
* Written by Craig Edwards, Craig McLure, and others.
* This program is free but copyrighted software; see
- * the file COPYING for details.
+ *the file COPYING for details.
*
* ---------------------------------------------------
*/
@@ -21,143 +21,142 @@ using namespace std;
#include "modules.h"
#include <vector>
-/* $ModDesc: Changes the ident of connecting bottler clients to 'bottler' */
+/* $ModDesc: Provides aliases of commands. */
class Alias
{
- public:
- std::string text;
- std::string replace_with;
- std::string requires;
- bool uline;
+ public:
+ std::string text;
+ std::string replace_with;
+ std::string requires;
+ bool uline;
};
class ModuleAlias : public Module
{
- private:
-
- Server *Srv;
- ConfigReader *MyConf;
- std::vector<Alias> Aliases;
- public:
-
- virtual void ReadAliases()
- {
- Aliases.clear();
-
- for (int i = 0; i < MyConf->Enumerate("alias"); i++)
+ private:
+ Server *Srv;
+ ConfigReader *MyConf;
+ std::vector<Alias> Aliases;
+ public:
+ /* XXX - small issue, why is this marked public when it's not (really) intended for external use */
+ virtual void ReadAliases()
{
- Alias a;
- a.text = MyConf->ReadValue("alias", "text", i);
- a.replace_with = MyConf->ReadValue("alias", "replace", i);
- a.requires = MyConf->ReadValue("alias", "requires", i);
+ Aliases.clear();
+
+ for (int i = 0; i < MyConf->Enumerate("alias"); i++)
+ {
+ Alias a;
+ a.text = MyConf->ReadValue("alias", "text", i);
+ a.replace_with = MyConf->ReadValue("alias", "replace", i);
+ a.requires = MyConf->ReadValue("alias", "requires", i);
- a.uline = ((MyConf->ReadValue("alias", "uline", i) == "yes") ||
- (MyConf->ReadValue("alias", "uline", i) == "1") ||
- (MyConf->ReadValue("alias", "uline", i) == "true"));
-
- Aliases.push_back(a);
- }
+ a.uline = ((MyConf->ReadValue("alias", "uline", i) == "yes") ||
+ (MyConf->ReadValue("alias", "uline", i) == "1") ||
+ (MyConf->ReadValue("alias", "uline", i) == "true"));
+
+ Aliases.push_back(a);
+ }
- }
+ }
- ModuleAlias()
- {
- Srv = new Server;
- MyConf = new ConfigReader;
+ ModuleAlias()
+ {
+ Srv = new Server;
+ MyConf = new ConfigReader;
- ReadAliases();
- }
+ ReadAliases();
+ }
- virtual ~ModuleAlias()
- {
- delete Srv;
- delete MyConf;
- }
+ virtual ~ModuleAlias()
+ {
+ delete Srv;
+ delete MyConf;
+ }
- virtual Version GetVersion()
- {
- return Version(1,0,0,1,VF_VENDOR);
- }
+ virtual Version GetVersion()
+ {
+ return Version(1,0,0,1,VF_VENDOR);
+ }
- virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user)
- {
- if (inbound)
+ virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user)
{
char data[MAXBUF];
- strncpy(data,raw.c_str(),MAXBUF);
- char* dptr = data;
-
- for (unsigned int i = 0; i < Aliases.size(); i++)
+ char *dptr;
+ userrec *u = NULL;
+
+ if (inbound)
{
- if (!strncasecmp(Aliases[i].text.c_str(),data,Aliases[i].text.length()))
+ strncpy(data, raw.c_str(),MAXBUF);
+ dptr = data;
+
+ for (unsigned int i = 0; i < Aliases.size(); i++)
{
- userrec* u = NULL;
-
- if (Aliases[i].requires != "")
+ if (!strncasecmp(Aliases[i].text.c_str(),data,Aliases[i].text.length()))
{
- u = Srv->FindNick(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))
+ if ((Aliases[i].requires != "") && (!u))
{
- 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.");
+ 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
- {
- raw = Aliases[i].replace_with;
+ dptr += Aliases[i].text.length();
+ if (strlen(dptr))
+ {
+ raw = Aliases[i].replace_with + std::string(dptr);
+ }
+ else
+ {
+ raw = Aliases[i].replace_with;
+ }
+ return;
}
- return;
}
}
- }
- }
+ }
- virtual void OnRehash()
- {
- delete MyConf;
- MyConf = new ConfigReader;
+ virtual void OnRehash()
+ {
+ delete MyConf;
+ MyConf = new ConfigReader;
- ReadAliases();
- }
+ ReadAliases();
+ }
};
class ModuleAliasFactory : public ModuleFactory
{
- public:
- ModuleAliasFactory()
- {
- }
-
- ~ModuleAliasFactory()
- {
- }
+ public:
+ ModuleAliasFactory()
+ {
+ }
- virtual Module * CreateModule()
- {
- return new ModuleAlias;
- }
+ ~ModuleAliasFactory()
+ {
+ }
+ virtual Module * CreateModule()
+ {
+ return new ModuleAlias;
+ }
};