X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_hostchange.cpp;h=d270c74d456d021aa9c25f0207a3f08144c3d940;hb=d54fd9b1e6b31f69332a9241b5f17330c0ad61e0;hp=7bf19313f248080092cb5c983560cb5a4e821491;hpb=0739e7c099618eb1848f5a72ec4d896095033a76;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index 7bf19313f..d270c74d4 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,74 @@ 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(InspIRCd* 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); + + Conf = new ConfigReader(ServerInstance); + OnRehash(""); } virtual ~ModuleHostChange() { - // not really neccessary, but free it anyway - delete Srv; - delete Conf; + DELETE(Conf); + } + + Priority Prioritize() + { + return (Priority)ServerInstance->PriorityAfter("m_cloaking.so"); } - virtual void OnRehash(std::string parameter) + void Implements(char* List) { - delete Conf; - Conf = new ConfigReader; + List[I_OnRehash] = List[I_OnUserConnect] = 1; + } + + virtual void OnRehash(const std::string ¶meter) + { + DELETE(Conf); + Conf = new ConfigReader(ServerInstance); 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,23 +99,22 @@ 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 (ServerInstance->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 = ""; @@ -100,8 +135,9 @@ class ModuleHostChange : public Module } if (newhost != "") { - Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your VHost: " + newhost); - Srv->ChangeHost(user,newhost); + user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost); + if (!user->ChangeDisplayedHost(newhost.c_str())) + user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost); return; } } @@ -122,9 +158,9 @@ class ModuleHostChangeFactory : public ModuleFactory { } - virtual Module * CreateModule() + virtual Module * CreateModule(InspIRCd* Me) { - return new ModuleHostChange; + return new ModuleHostChange(Me); } };