2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2005-2007 Craig Edwards <craigedwards@brainbox.cc>
5 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
26 /** Holds information on a host set by m_hostchange
36 typedef std::map<std::string,Host*> hostchanges_t;
38 class ModuleHostChange : public Module
41 hostchanges_t hostchanges;
44 std::string MySeparator;
50 Implementation eventlist[] = { I_OnRehash, I_OnUserConnect };
51 ServerInstance->Modules->Attach(eventlist, this, 2);
54 virtual ~ModuleHostChange()
56 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
65 Module* cloak = ServerInstance->Modules->Find("m_cloaking.so");
66 ServerInstance->Modules->SetPriority(this, I_OnUserConnect, PRIORITY_AFTER, &cloak);
70 virtual void OnRehash(User* user)
73 MySuffix = Conf.ReadValue("host","suffix",0);
74 MyPrefix = Conf.ReadValue("host","prefix","",0);
75 MySeparator = Conf.ReadValue("host","separator",".",0);
76 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
81 for (int index = 0; index < Conf.Enumerate("hostchange"); index++)
83 std::string mask = Conf.ReadValue("hostchange", "mask", index);
84 std::string ports = Conf.ReadValue("hostchange", "ports", index);
85 std::string action = Conf.ReadValue("hostchange", "action", index);
86 std::string newhost = Conf.ReadValue("hostchange", "value", index);
91 hostchanges[mask] = x;
95 virtual Version GetVersion()
97 // returns the version number of the module to be
99 return Version("Provides masking of user hostnames in a different way to m_cloaking", VF_VENDOR);
102 virtual void OnUserConnect(LocalUser* user)
104 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
106 if (((InspIRCd::MatchCIDR(user->MakeHost(), i->first)) || (InspIRCd::MatchCIDR(user->MakeHostIP(), i->first))))
110 if (!h->ports.empty())
112 irc::portparser portrange(h->ports, false);
114 bool foundany = false;
116 while ((portno = portrange.GetToken()))
117 if (portno == user->GetServerPort())
124 // host of new user matches a hostchange tag's mask
126 if (h->action == "set")
128 newhost = h->newhost;
130 else if (h->action == "suffix")
134 else if (h->action == "addnick")
136 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
137 std::string complete;
138 std::string old = user->nick;
139 for (unsigned int j = 0; j < old.length(); j++)
141 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
142 ((old[j] >= 'a') && (old[j] <= 'z')) ||
143 ((old[j] >= '0') && (old[j] <= '9')) ||
146 complete = complete + old[j];
149 if (complete.empty())
150 complete = "i-have-a-lame-nick";
152 if (!MyPrefix.empty())
153 newhost = MyPrefix + MySeparator + complete;
155 newhost = complete + MySeparator + MySuffix;
157 if (!newhost.empty())
159 user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
160 if (!user->ChangeDisplayedHost(newhost.c_str()))
161 user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
169 MODULE_INIT(ModuleHostChange)