1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
20 /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
22 /** Holds information on a host set by m_hostchange
24 class Host : public classbase
31 typedef std::map<std::string,Host*> hostchanges_t;
33 class ModuleHostChange : public Module
39 hostchanges_t hostchanges;
43 ModuleHostChange(InspIRCd* Me)
46 Conf = new ConfigReader(ServerInstance);
50 virtual ~ModuleHostChange()
57 return (Priority)ServerInstance->PriorityAfter("m_cloaking.so");
60 void Implements(char* List)
62 List[I_OnRehash] = List[I_OnUserConnect] = 1;
65 virtual void OnRehash(userrec* user, const std::string ¶meter)
68 Conf = new ConfigReader(ServerInstance);
69 MySuffix = Conf->ReadValue("host","suffix",0);
70 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
75 for (int index = 0; index < Conf->Enumerate("hostchange"); index++)
77 std::string mask = Conf->ReadValue("hostchange","mask",index);
78 std::string action = Conf->ReadValue("hostchange","action",index);
79 std::string newhost = Conf->ReadValue("hostchange","value",index);
83 hostchanges[mask] = x;
87 virtual Version GetVersion()
89 // returns the version number of the module to be
91 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
94 virtual void OnUserConnect(userrec* user)
96 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
98 if (ServerInstance->MatchText(std::string(user->ident)+"@"+std::string(user->host),i->first))
100 Host* h = (Host*)i->second;
101 // host of new user matches a hostchange tag's mask
102 std::string newhost = "";
103 if (h->action == "set")
105 newhost = h->newhost;
107 else if (h->action == "suffix")
111 else if (h->action == "addnick")
113 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
114 std::string complete = "";
115 std::string old = user->nick;
116 for (unsigned int j = 0; j < old.length(); j++)
118 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
119 ((old[j] >= 'a') && (old[j] <= 'z')) ||
120 ((old[j] >= '0') && (old[j] <= '9')) ||
123 complete = complete + old[j];
127 complete = "i-have-a-lame-nick";
128 newhost = complete + "." + MySuffix;
132 user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
133 if (!user->ChangeDisplayedHost(newhost.c_str()))
134 user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
142 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
144 class ModuleHostChangeFactory : public ModuleFactory
147 ModuleHostChangeFactory()
151 ~ModuleHostChangeFactory()
155 virtual Module * CreateModule(InspIRCd* Me)
157 return new ModuleHostChange(Me);
163 extern "C" void * init_module( void )
165 return new ModuleHostChangeFactory;