1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
17 /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
19 /** Holds information on a host set by m_hostchange
21 class Host : public classbase
29 typedef std::map<std::string,Host*> hostchanges_t;
31 class ModuleHostChange : public Module
34 hostchanges_t hostchanges;
37 std::string MySeparator;
40 ModuleHostChange(InspIRCd* Me)
44 Implementation eventlist[] = { I_OnRehash, I_OnUserConnect };
45 ServerInstance->Modules->Attach(eventlist, this, 2);
48 virtual ~ModuleHostChange()
50 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
59 Module* cloak = ServerInstance->Modules->Find("m_cloaking.so");
60 ServerInstance->Modules->SetPriority(this, I_OnUserConnect, PRIO_AFTER, &cloak);
64 virtual void OnRehash(User* user, const std::string ¶meter)
66 ConfigReader Conf(ServerInstance);
67 MySuffix = Conf.ReadValue("host","suffix",0);
68 MyPrefix = Conf.ReadValue("host","prefix","",0);
69 MySeparator = Conf.ReadValue("host","separator",".",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 ports = Conf.ReadValue("hosthange", "ports", index);
79 std::string action = Conf.ReadValue("hostchange", "action", index);
80 std::string newhost = Conf.ReadValue("hostchange", "value", index);
85 hostchanges[mask] = x;
89 virtual Version GetVersion()
91 // returns the version number of the module to be
93 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
96 virtual void OnUserConnect(User* user)
98 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
100 if (((match(user->MakeHost(),i->first.c_str(),true)) || (match(user->MakeHostIP(),i->first.c_str()))))
104 if (!h->ports.empty())
106 irc::portparser portrange(h->ports, false);
108 bool foundany = false;
110 while ((portno = portrange.GetToken()))
111 if (portno == user->GetPort())
118 // host of new user matches a hostchange tag's mask
120 if (h->action == "set")
122 newhost = h->newhost;
124 else if (h->action == "suffix")
128 else if (h->action == "addnick")
130 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
131 std::string complete;
132 std::string old = user->nick;
133 for (unsigned int j = 0; j < old.length(); j++)
135 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
136 ((old[j] >= 'a') && (old[j] <= 'z')) ||
137 ((old[j] >= '0') && (old[j] <= '9')) ||
140 complete = complete + old[j];
143 if (complete.empty())
144 complete = "i-have-a-lame-nick";
146 if (!MyPrefix.empty())
147 newhost = MyPrefix + MySeparator + complete;
149 newhost = complete + MySeparator + MySuffix;
151 if (!newhost.empty())
153 user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
154 if (!user->ChangeDisplayedHost(newhost.c_str()))
155 user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
163 MODULE_INIT(ModuleHostChange)