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
32 typedef std::map<std::string,Host*> hostchanges_t;
34 class ModuleHostChange : public Module
37 hostchanges_t hostchanges;
40 std::string MySeparator;
43 ModuleHostChange(InspIRCd* Me)
49 virtual ~ModuleHostChange()
51 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
60 return (Priority)ServerInstance->PriorityAfter("m_cloaking.so");
63 void Implements(char* List)
65 List[I_OnRehash] = List[I_OnUserConnect] = 1;
68 virtual void OnRehash(userrec* user, const std::string ¶meter)
70 ConfigReader Conf(ServerInstance);
71 MySuffix = Conf.ReadValue("host","suffix",0);
72 MyPrefix = Conf.ReadValue("host","prefix","",0);
73 MySeparator = Conf.ReadValue("host","separator",".",0);
74 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
79 for (int index = 0; index < Conf.Enumerate("hostchange"); index++)
81 std::string mask = Conf.ReadValue("hostchange", "mask", index);
82 std::string ports = Conf.ReadValue("hosthange", "ports", index);
83 std::string action = Conf.ReadValue("hostchange", "action", index);
84 std::string newhost = Conf.ReadValue("hostchange", "value", index);
89 hostchanges[mask] = x;
93 virtual Version GetVersion()
95 // returns the version number of the module to be
97 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
100 virtual void OnUserConnect(userrec* user)
102 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
104 if (((match(user->MakeHost(),i->first.c_str(),true)) || (match(user->MakeHostIP(),i->first.c_str()))))
108 if (!h->ports.empty())
110 irc::portparser portrange(h->ports, false);
112 bool foundany = false;
114 while ((portno = portrange.GetToken()))
115 if (portno == user->GetPort())
122 // host of new user matches a hostchange tag's mask
124 if (h->action == "set")
126 newhost = h->newhost;
128 else if (h->action == "suffix")
132 else if (h->action == "addnick")
134 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
135 std::string complete;
136 std::string old = user->nick;
137 for (unsigned int j = 0; j < old.length(); j++)
139 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
140 ((old[j] >= 'a') && (old[j] <= 'z')) ||
141 ((old[j] >= '0') && (old[j] <= '9')) ||
144 complete = complete + old[j];
147 if (complete.empty())
148 complete = "i-have-a-lame-nick";
150 if (!MyPrefix.empty())
151 newhost = MyPrefix + MySeparator + complete;
153 newhost = complete + MySeparator + MySuffix;
155 if (!newhost.empty())
157 user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
158 if (!user->ChangeDisplayedHost(newhost.c_str()))
159 user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
167 MODULE_INIT(ModuleHostChange)