* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
* E-mail:
* <brain@chatspike.net>
* <Craig@chatspike.net>
/* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
+class Host
+{
+ public:
+ std::string action;
+ std::string newhost;
+};
+
+typedef std::map<std::string,Host*> hostchanges_t;
+
class ModuleHostChange : public Module
{
private:
Server *Srv;
ConfigReader *Conf;
+ hostchanges_t hostchanges;
std::string MySuffix;
public:
- ModuleHostChange()
+ ModuleHostChange(Server* Me)
+ : Module::Module(Me)
{
- // We must create an instance of the Server class to work with
- Srv = new Server;
+ Srv = Me;
Conf = new ConfigReader;
- MySuffix = Conf->ReadValue("host","suffix",0);
+ OnRehash("");
}
virtual ~ModuleHostChange()
{
- // not really neccessary, but free it anyway
- delete Srv;
delete Conf;
}
+ Priority Prioritize()
+ {
+ return (Priority)Srv->PriorityAfter("m_cloaking.so");
+ }
+
+ void Implements(char* List)
+ {
+ List[I_OnRehash] = List[I_OnUserConnect] = 1;
+ }
+
virtual void OnRehash(std::string parameter)
{
delete Conf;
Conf = new ConfigReader;
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()
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 (Srv->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 = "";
}
if (newhost != "")
{
- Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your VHost: " + newhost);
+ Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
Srv->ChangeHost(user,newhost);
return;
}
{
}
- virtual Module * CreateModule()
+ virtual Module * CreateModule(Server* Me)
{
- return new ModuleHostChange;
+ return new ModuleHostChange(Me);
}
};