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 * ---------------------------------------------------
24 /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
33 typedef std::map<std::string,Host*> hostchanges_t;
35 class ModuleHostChange : public Module
41 hostchanges_t hostchanges;
45 ModuleHostChange(Server* Me)
49 Conf = new ConfigReader;
53 virtual ~ModuleHostChange()
60 return (Priority)Srv->PriorityAfter("m_cloaking.so");
63 void Implements(char* List)
65 List[I_OnRehash] = List[I_OnUserConnect] = 1;
68 virtual void OnRehash(std::string parameter)
71 Conf = new ConfigReader;
72 MySuffix = Conf->ReadValue("host","suffix",0);
73 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
78 for (int index = 0; index < Conf->Enumerate("hostchange"); index++)
80 std::string mask = Conf->ReadValue("hostchange","mask",index);
81 std::string action = Conf->ReadValue("hostchange","action",index);
82 std::string newhost = Conf->ReadValue("hostchange","value",index);
86 hostchanges[mask] = x;
90 virtual Version GetVersion()
92 // returns the version number of the module to be
94 return Version(1,0,0,1,VF_VENDOR);
97 virtual void OnUserConnect(userrec* user)
99 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
101 if (Srv->MatchText(std::string(user->ident)+"@"+std::string(user->host),i->first))
103 Host* h = (Host*)i->second;
104 // host of new user matches a hostchange tag's mask
105 std::string newhost = "";
106 if (h->action == "set")
108 newhost = h->newhost;
110 else if (h->action == "suffix")
114 else if (h->action == "addnick")
116 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
117 std::string complete = "";
118 std::string old = user->nick;
119 for (unsigned int j = 0; j < old.length(); j++)
121 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
122 ((old[j] >= 'a') && (old[j] <= 'z')) ||
123 ((old[j] >= '0') && (old[j] <= '9')) ||
126 complete = complete + old[j];
130 complete = "i-have-a-lame-nick";
131 newhost = complete + "." + MySuffix;
135 Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
136 Srv->ChangeHost(user,newhost);
144 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
146 class ModuleHostChangeFactory : public ModuleFactory
149 ModuleHostChangeFactory()
153 ~ModuleHostChangeFactory()
157 virtual Module * CreateModule(Server* Me)
159 return new ModuleHostChange(Me);
165 extern "C" void * init_module( void )
167 return new ModuleHostChangeFactory;