1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 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 * ---------------------------------------------------
25 /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
27 class Host : public classbase
34 typedef std::map<std::string,Host*> hostchanges_t;
36 class ModuleHostChange : public Module
42 hostchanges_t hostchanges;
46 ModuleHostChange(Server* Me)
50 Conf = new ConfigReader;
54 virtual ~ModuleHostChange()
61 return (Priority)Srv->PriorityAfter("m_cloaking.so");
64 void Implements(char* List)
66 List[I_OnRehash] = List[I_OnUserConnect] = 1;
69 virtual void OnRehash(const std::string ¶meter)
72 Conf = new ConfigReader;
73 MySuffix = Conf->ReadValue("host","suffix",0);
74 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
79 for (int index = 0; index < Conf->Enumerate("hostchange"); index++)
81 std::string mask = Conf->ReadValue("hostchange","mask",index);
82 std::string action = Conf->ReadValue("hostchange","action",index);
83 std::string newhost = Conf->ReadValue("hostchange","value",index);
87 hostchanges[mask] = x;
91 virtual Version GetVersion()
93 // returns the version number of the module to be
95 return Version(1,0,0,1,VF_VENDOR);
98 virtual void OnUserConnect(userrec* user)
100 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
102 if (Srv->MatchText(std::string(user->ident)+"@"+std::string(user->host),i->first))
104 Host* h = (Host*)i->second;
105 // host of new user matches a hostchange tag's mask
106 std::string newhost = "";
107 if (h->action == "set")
109 newhost = h->newhost;
111 else if (h->action == "suffix")
115 else if (h->action == "addnick")
117 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
118 std::string complete = "";
119 std::string old = user->nick;
120 for (unsigned int j = 0; j < old.length(); j++)
122 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
123 ((old[j] >= 'a') && (old[j] <= 'z')) ||
124 ((old[j] >= '0') && (old[j] <= '9')) ||
127 complete = complete + old[j];
131 complete = "i-have-a-lame-nick";
132 newhost = complete + "." + MySuffix;
136 Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
137 Srv->ChangeHost(user,newhost);
145 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
147 class ModuleHostChangeFactory : public ModuleFactory
150 ModuleHostChangeFactory()
154 ~ModuleHostChangeFactory()
158 virtual Module * CreateModule(Server* Me)
160 return new ModuleHostChange(Me);
166 extern "C" void * init_module( void )
168 return new ModuleHostChangeFactory;