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 * ---------------------------------------------------
16 /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
18 /** Holds information on a host set by m_hostchange
20 class Host : public classbase
28 typedef std::map<std::string,Host*> hostchanges_t;
30 class ModuleHostChange : public Module
33 hostchanges_t hostchanges;
36 std::string MySeparator;
39 ModuleHostChange(InspIRCd* Me)
43 Implementation eventlist[] = { I_OnRehash, I_OnUserConnect };
44 ServerInstance->Modules->Attach(eventlist, this, 2);
47 virtual ~ModuleHostChange()
49 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
58 Module* cloak = ServerInstance->Modules->Find("m_cloaking.so");
59 ServerInstance->Modules->SetPriority(this, I_OnUserConnect, PRIO_AFTER, &cloak);
63 virtual void OnRehash(User* user, const std::string ¶meter)
65 ConfigReader Conf(ServerInstance);
66 MySuffix = Conf.ReadValue("host","suffix",0);
67 MyPrefix = Conf.ReadValue("host","prefix","",0);
68 MySeparator = Conf.ReadValue("host","separator",".",0);
69 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
74 for (int index = 0; index < Conf.Enumerate("hostchange"); index++)
76 std::string mask = Conf.ReadValue("hostchange", "mask", index);
77 std::string ports = Conf.ReadValue("hosthange", "ports", index);
78 std::string action = Conf.ReadValue("hostchange", "action", index);
79 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,2,0,1,VF_VENDOR,API_VERSION);
95 virtual void OnUserConnect(User* user)
97 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
99 if (((InspIRCd::MatchCIDR(user->MakeHost(), i->first)) || (InspIRCd::MatchCIDR(user->MakeHostIP(), i->first))))
103 if (!h->ports.empty())
105 irc::portparser portrange(h->ports, false);
107 bool foundany = false;
109 while ((portno = portrange.GetToken()))
110 if (portno == user->GetPort())
117 // host of new user matches a hostchange tag's mask
119 if (h->action == "set")
121 newhost = h->newhost;
123 else if (h->action == "suffix")
127 else if (h->action == "addnick")
129 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
130 std::string complete;
131 std::string old = user->nick;
132 for (unsigned int j = 0; j < old.length(); j++)
134 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
135 ((old[j] >= 'a') && (old[j] <= 'z')) ||
136 ((old[j] >= '0') && (old[j] <= '9')) ||
139 complete = complete + old[j];
142 if (complete.empty())
143 complete = "i-have-a-lame-nick";
145 if (!MyPrefix.empty())
146 newhost = MyPrefix + MySeparator + complete;
148 newhost = complete + MySeparator + MySuffix;
150 if (!newhost.empty())
152 user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
153 if (!user->ChangeDisplayedHost(newhost.c_str()))
154 user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
162 MODULE_INIT(ModuleHostChange)