X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_hostchange.cpp;h=3d036621424b7a3ea2af363de3ee4639735e0b31;hb=2e52ff280dca14d1598b84fab7a8c2e93fa30910;hp=a3e839cadbaadbe62d37c0a89a31fd03ac7b9a15;hpb=f96ddd39748f283768217fb1a3cdd3a7cbde353a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index a3e839cad..3d0366214 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,66 +20,101 @@ 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 */ +/** Holds information on a host set by m_hostchange + */ +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"); + } + + void Implements(char* List) + { + List[I_OnRehash] = List[I_OnUserConnect] = 1; } - virtual void OnRehash() + virtual void OnRehash(const std::string ¶meter) { - delete Conf; - Conf = new ConfigReader; + 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() { // returns the version number of the module to be // listed in /MODULES - return Version(1,0,0,1,VF_VENDOR); + return Version(1,1,0,1,VF_VENDOR,API_VERSION); } 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); } };