X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_hostchange.cpp;h=de485b2c03e9c456917ab460ee3f3c4ea952d80c;hb=2330fc9ddd48c939e894e7e37e9bb2e62eafc38d;hp=21566daac8994b22056b8c11e802aeecd69593fd;hpb=38749462c62a659b7006976c2c7c4da6ac6d0df7;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index 21566daac..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: * * @@ -14,75 +14,110 @@ * --------------------------------------------------- */ +using namespace std; + #include #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"); + } + + void Implements(char* List) + { + List[I_OnRehash] = List[I_OnUserConnect] = 1; } - virtual void OnRehash() + virtual void OnRehash(const std::string ¶meter) { - delete Conf; + 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() { // returns the version number of the module to be // listed in /MODULES - return Version(1,0,0,1); + return Version(1,0,0,1,VF_VENDOR); } 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')) || @@ -98,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; } @@ -120,9 +155,9 @@ class ModuleHostChangeFactory : public ModuleFactory { } - virtual Module * CreateModule() + virtual Module * CreateModule(Server* Me) { - return new ModuleHostChange; + return new ModuleHostChange(Me); } };