X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_hostchange.cpp;h=dc45a43d46bde86c96fe05e1783b7da816e9e2d8;hb=e9d1efc1ae29ee86b3c2a42bf56531afac7add6d;hp=49dd99f67ba845e14c57d31b423ff2e9217246ac;hpb=0efd83fa4b6a03d28d1e4853ae262edb48b096b0;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index 49dd99f67..dc45a43d4 100644 --- a/src/modules/m_hostchange.cpp +++ b/src/modules/m_hostchange.cpp @@ -2,28 +2,25 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ -using namespace std; - -#include +#include "inspircd.h" #include "users.h" #include "channels.h" #include "modules.h" /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */ -class Host +/** Holds information on a host set by m_hostchange + */ +class Host : public classbase { public: std::string action; @@ -35,29 +32,30 @@ typedef std::map hostchanges_t; class ModuleHostChange : public Module { private: - - Server *Srv; - ConfigReader *Conf; hostchanges_t hostchanges; std::string MySuffix; + std::string MyPrefix; + std::string MySeparator; public: - ModuleHostChange(Server* Me) - : Module::Module(Me) + ModuleHostChange(InspIRCd* Me) + : Module(Me) { - Srv = Me; - Conf = new ConfigReader; - OnRehash(""); + OnRehash(NULL,""); } virtual ~ModuleHostChange() { - delete Conf; + for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++) + { + DELETE(i->second); + } + hostchanges.clear(); } Priority Prioritize() { - return (Priority)Srv->PriorityAfter("m_cloaking.so"); + return (Priority)ServerInstance->PriorityAfter("m_cloaking.so"); } void Implements(char* List) @@ -65,21 +63,22 @@ class ModuleHostChange : public Module List[I_OnRehash] = List[I_OnUserConnect] = 1; } - virtual void OnRehash(const std::string ¶meter) + virtual void OnRehash(userrec* user, const std::string ¶meter) { - delete Conf; - Conf = new ConfigReader; - MySuffix = Conf->ReadValue("host","suffix",0); + ConfigReader Conf(ServerInstance); + MySuffix = Conf.ReadValue("host","suffix",0); + MyPrefix = Conf.ReadValue("host","prefix","",0); + MySeparator = Conf.ReadValue("host","separator",".",0); for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++) { - delete i->second; + DELETE(i->second); } hostchanges.clear(); - for (int index = 0; index < Conf->Enumerate("hostchange"); index++) + 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); + 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; @@ -91,18 +90,18 @@ class ModuleHostChange : public Module { // 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 (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++) { - if (Srv->MatchText(std::string(user->ident)+"@"+std::string(user->host),i->first)) + if (ServerInstance->MatchText(std::string(user->ident)+"@"+std::string(user->host),i->first)) { Host* h = (Host*)i->second; // host of new user matches a hostchange tag's mask - std::string newhost = ""; + std::string newhost; if (h->action == "set") { newhost = h->newhost; @@ -114,7 +113,7 @@ class ModuleHostChange : public Module else if (h->action == "addnick") { // first take their nick and strip out non-dns, leaving just [A-Z0-9\-] - std::string complete = ""; + std::string complete; std::string old = user->nick; for (unsigned int j = 0; j < old.length(); j++) { @@ -126,14 +125,19 @@ class ModuleHostChange : public Module complete = complete + old[j]; } } - if (complete == "") + if (complete.empty()) complete = "i-have-a-lame-nick"; - newhost = complete + "." + MySuffix; + + if (!MyPrefix.empty()) + newhost = MyPrefix + MySeparator + complete; + else + newhost = complete + MySeparator + MySuffix; } - if (newhost != "") + if (!newhost.empty()) { - Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + 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; } } @@ -141,29 +145,4 @@ class ModuleHostChange : public Module } }; -// stuff down here is the module-factory stuff. For basic modules you can ignore this. - -class ModuleHostChangeFactory : public ModuleFactory -{ - public: - ModuleHostChangeFactory() - { - } - - ~ModuleHostChangeFactory() - { - } - - virtual Module * CreateModule(Server* Me) - { - return new ModuleHostChange(Me); - } - -}; - - -extern "C" void * init_module( void ) -{ - return new ModuleHostChangeFactory; -} - +MODULE_INIT(ModuleHostChange)