X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_hostchange.cpp;h=de485b2c03e9c456917ab460ee3f3c4ea952d80c;hb=2330fc9ddd48c939e894e7e37e9bb2e62eafc38d;hp=36cd3ea70ec954babc31286fd0a9c603d890d5bf;hpb=ab01aaeeee9aed655df2eec2522072233fe3aa57;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index 36cd3ea70..de485b2c0 100644 --- a/src/modules/m_hostchange.cpp +++ b/src/modules/m_hostchange.cpp @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * Inspire is copyright (C) 2002-2004 ChatSpike-Dev. + * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. * E-mail: * * @@ -20,38 +20,72 @@ using namespace std; #include "users.h" #include "channels.h" #include "modules.h" +#include "inspircd.h" /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */ +class Host : public classbase +{ + public: + std::string action; + std::string newhost; +}; + +typedef std::map hostchanges_t; + class ModuleHostChange : public Module { private: Server *Srv; ConfigReader *Conf; + hostchanges_t hostchanges; std::string MySuffix; public: - ModuleHostChange() + ModuleHostChange(Server* Me) + : Module::Module(Me) { - // We must create an instance of the Server class to work with - Srv = new Server; - Conf = new ConfigReader; - MySuffix = Conf->ReadValue("host","suffix",0); + Srv = Me; + Conf = new ConfigReader; + OnRehash(""); } virtual ~ModuleHostChange() { - // not really neccessary, but free it anyway - delete Srv; - delete Conf; + DELETE(Conf); + } + + Priority Prioritize() + { + return (Priority)Srv->PriorityAfter("m_cloaking.so"); } - virtual void OnRehash() + void Implements(char* List) { - delete Conf; + List[I_OnRehash] = List[I_OnUserConnect] = 1; + } + + virtual void OnRehash(const std::string ¶meter) + { + DELETE(Conf); Conf = new ConfigReader; MySuffix = Conf->ReadValue("host","suffix",0); + for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++) + { + DELETE(i->second); + } + hostchanges.clear(); + for (int index = 0; index < Conf->Enumerate("hostchange"); index++) + { + std::string mask = Conf->ReadValue("hostchange","mask",index); + std::string action = Conf->ReadValue("hostchange","action",index); + std::string newhost = Conf->ReadValue("hostchange","value",index); + Host* x = new Host; + x->action = action; + x->newhost = newhost; + hostchanges[mask] = x; + } } virtual Version GetVersion() @@ -63,28 +97,27 @@ class ModuleHostChange : public Module virtual void OnUserConnect(userrec* user) { - for (int index = 0; index < Conf->Enumerate("hostchange"); index++) + for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++) { - std::string mask = Conf->ReadValue("hostchange","mask",index); - if (Srv->MatchText(std::string(user->ident)+"@"+std::string(user->host),mask)) + if (Srv->MatchText(std::string(user->ident)+"@"+std::string(user->host),i->first)) { - std::string newhost = ""; + Host* h = (Host*)i->second; // host of new user matches a hostchange tag's mask - std::string action = Conf->ReadValue("hostchange","action",index); - if (action == "set") + std::string newhost = ""; + if (h->action == "set") { - newhost = Conf->ReadValue("hostchange","value",index); + newhost = h->newhost; } - else if (action == "suffix") + else if (h->action == "suffix") { newhost = MySuffix; } - else if (action == "addnick") + else if (h->action == "addnick") { // first take their nick and strip out non-dns, leaving just [A-Z0-9\-] std::string complete = ""; std::string old = user->nick; - for (int j = 0; j < old.length(); j++) + for (unsigned int j = 0; j < old.length(); j++) { if (((old[j] >= 'A') && (old[j] <= 'Z')) || ((old[j] >= 'a') && (old[j] <= 'z')) || @@ -100,7 +133,7 @@ class ModuleHostChange : public Module } if (newhost != "") { - Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your VHost: " + newhost); + Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost); Srv->ChangeHost(user,newhost); return; } @@ -122,9 +155,9 @@ class ModuleHostChangeFactory : public ModuleFactory { } - virtual Module * CreateModule() + virtual Module * CreateModule(Server* Me) { - return new ModuleHostChange; + return new ModuleHostChange(Me); } };