1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
24 /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
26 class ModuleHostChange : public Module
37 // We must create an instance of the Server class to work with
39 Conf = new ConfigReader;
40 MySuffix = Conf->ReadValue("host","suffix",0);
43 virtual ~ModuleHostChange()
45 // not really neccessary, but free it anyway
50 virtual void OnRehash()
53 Conf = new ConfigReader;
54 MySuffix = Conf->ReadValue("host","suffix",0);
57 virtual Version GetVersion()
59 // returns the version number of the module to be
61 return Version(1,0,0,1,VF_VENDOR);
64 virtual void OnUserConnect(userrec* user)
66 for (int index = 0; index < Conf->Enumerate("hostchange"); index++)
68 std::string mask = Conf->ReadValue("hostchange","mask",index);
69 if (Srv->MatchText(std::string(user->ident)+"@"+std::string(user->host),mask))
71 std::string newhost = "";
72 // host of new user matches a hostchange tag's mask
73 std::string action = Conf->ReadValue("hostchange","action",index);
76 newhost = Conf->ReadValue("hostchange","value",index);
78 else if (action == "suffix")
82 else if (action == "addnick")
84 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
85 std::string complete = "";
86 std::string old = user->nick;
87 for (unsigned int j = 0; j < old.length(); j++)
89 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
90 ((old[j] >= 'a') && (old[j] <= 'z')) ||
91 ((old[j] >= '0') && (old[j] <= '9')) ||
94 complete = complete + old[j];
98 complete = "i-have-a-lame-nick";
99 newhost = complete + "." + MySuffix;
103 Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your VHost: " + newhost);
104 Srv->ChangeHost(user,newhost);
112 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
114 class ModuleHostChangeFactory : public ModuleFactory
117 ModuleHostChangeFactory()
121 ~ModuleHostChangeFactory()
125 virtual Module * CreateModule()
127 return new ModuleHostChange;
133 extern "C" void * init_module( void )
135 return new ModuleHostChangeFactory;