1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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
28 typedef std::map<std::string,Host*> hostchanges_t;
30 class ModuleHostChange : public Module
33 hostchanges_t hostchanges;
36 std::string MySeparator;
42 Implementation eventlist[] = { I_OnRehash, I_OnUserConnect };
43 ServerInstance->Modules->Attach(eventlist, this, 2);
46 virtual ~ModuleHostChange()
48 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
57 Module* cloak = ServerInstance->Modules->Find("m_cloaking.so");
58 ServerInstance->Modules->SetPriority(this, I_OnUserConnect, PRIORITY_AFTER, &cloak);
62 virtual void OnRehash(User* user)
65 MySuffix = Conf.ReadValue("host","suffix",0);
66 MyPrefix = Conf.ReadValue("host","prefix","",0);
67 MySeparator = Conf.ReadValue("host","separator",".",0);
68 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
73 for (int index = 0; index < Conf.Enumerate("hostchange"); index++)
75 std::string mask = Conf.ReadValue("hostchange", "mask", index);
76 std::string ports = Conf.ReadValue("hosthange", "ports", index);
77 std::string action = Conf.ReadValue("hostchange", "action", index);
78 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("Provides masking of user hostnames in a different way to m_cloaking", VF_VENDOR);
94 virtual void OnUserConnect(LocalUser* user)
96 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
98 if (((InspIRCd::MatchCIDR(user->MakeHost(), i->first)) || (InspIRCd::MatchCIDR(user->MakeHostIP(), i->first))))
102 if (!h->ports.empty())
104 irc::portparser portrange(h->ports, false);
106 bool foundany = false;
108 while ((portno = portrange.GetToken()))
109 if (portno == user->GetServerPort())
116 // host of new user matches a hostchange tag's mask
118 if (h->action == "set")
120 newhost = h->newhost;
122 else if (h->action == "suffix")
126 else if (h->action == "addnick")
128 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
129 std::string complete;
130 std::string old = user->nick;
131 for (unsigned int j = 0; j < old.length(); j++)
133 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
134 ((old[j] >= 'a') && (old[j] <= 'z')) ||
135 ((old[j] >= '0') && (old[j] <= '9')) ||
138 complete = complete + old[j];
141 if (complete.empty())
142 complete = "i-have-a-lame-nick";
144 if (!MyPrefix.empty())
145 newhost = MyPrefix + MySeparator + complete;
147 newhost = complete + MySeparator + MySuffix;
149 if (!newhost.empty())
151 user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
152 if (!user->ChangeDisplayedHost(newhost.c_str()))
153 user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
161 MODULE_INIT(ModuleHostChange)