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)
47 Conf = new ConfigReader(ServerInstance);
51 virtual ~ModuleHostChange()
58 return (Priority)ServerInstance->PriorityAfter("m_cloaking.so");
61 void Implements(char* List)
63 List[I_OnRehash] = List[I_OnUserConnect] = 1;
66 virtual void OnRehash(const std::string ¶meter)
69 Conf = new ConfigReader(ServerInstance);
70 MySuffix = Conf->ReadValue("host","suffix",0);
71 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
76 for (int index = 0; index < Conf->Enumerate("hostchange"); index++)
78 std::string mask = Conf->ReadValue("hostchange","mask",index);
79 std::string action = Conf->ReadValue("hostchange","action",index);
80 std::string newhost = Conf->ReadValue("hostchange","value",index);
84 hostchanges[mask] = x;
88 virtual Version GetVersion()
90 // returns the version number of the module to be
92 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
95 virtual void OnUserConnect(userrec* user)
97 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
99 if (ServerInstance->MatchText(std::string(user->ident)+"@"+std::string(user->host),i->first))
101 Host* h = (Host*)i->second;
102 // host of new user matches a hostchange tag's mask
103 std::string newhost = "";
104 if (h->action == "set")
106 newhost = h->newhost;
108 else if (h->action == "suffix")
112 else if (h->action == "addnick")
114 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
115 std::string complete = "";
116 std::string old = user->nick;
117 for (unsigned int j = 0; j < old.length(); j++)
119 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
120 ((old[j] >= 'a') && (old[j] <= 'z')) ||
121 ((old[j] >= '0') && (old[j] <= '9')) ||
124 complete = complete + old[j];
128 complete = "i-have-a-lame-nick";
129 newhost = complete + "." + MySuffix;
133 user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
134 if (!user->ChangeDisplayedHost(newhost.c_str()))
135 user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
143 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
145 class ModuleHostChangeFactory : public ModuleFactory
148 ModuleHostChangeFactory()
152 ~ModuleHostChangeFactory()
156 virtual Module * CreateModule(InspIRCd* Me)
158 return new ModuleHostChange(Me);
164 extern "C" void * init_module( void )
166 return new ModuleHostChangeFactory;