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 * ---------------------------------------------------
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)
46 virtual ~ModuleHostChange()
48 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
57 return (Priority)ServerInstance->Modules->PriorityAfter("m_cloaking.so");
60 void Implements(char* List)
62 List[I_OnRehash] = List[I_OnUserConnect] = 1;
65 virtual void OnRehash(User* user, const std::string ¶meter)
67 ConfigReader Conf(ServerInstance);
68 MySuffix = Conf.ReadValue("host","suffix",0);
69 MyPrefix = Conf.ReadValue("host","prefix","",0);
70 MySeparator = Conf.ReadValue("host","separator",".",0);
71 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
76 for (int index = 0; index < Conf.Enumerate("hostchange"); index++)
78 std::string mask = Conf.ReadValue("hostchange", "mask", index);
79 std::string ports = Conf.ReadValue("hosthange", "ports", index);
80 std::string action = Conf.ReadValue("hostchange", "action", index);
81 std::string newhost = Conf.ReadValue("hostchange", "value", index);
86 hostchanges[mask] = x;
90 virtual Version GetVersion()
92 // returns the version number of the module to be
94 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
97 virtual void OnUserConnect(User* user)
99 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
101 if (((match(user->MakeHost(),i->first.c_str(),true)) || (match(user->MakeHostIP(),i->first.c_str()))))
105 if (!h->ports.empty())
107 irc::portparser portrange(h->ports, false);
109 bool foundany = false;
111 while ((portno = portrange.GetToken()))
112 if (portno == user->GetPort())
119 // host of new user matches a hostchange tag's mask
121 if (h->action == "set")
123 newhost = h->newhost;
125 else if (h->action == "suffix")
129 else if (h->action == "addnick")
131 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
132 std::string complete;
133 std::string old = user->nick;
134 for (unsigned int j = 0; j < old.length(); j++)
136 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
137 ((old[j] >= 'a') && (old[j] <= 'z')) ||
138 ((old[j] >= '0') && (old[j] <= '9')) ||
141 complete = complete + old[j];
144 if (complete.empty())
145 complete = "i-have-a-lame-nick";
147 if (!MyPrefix.empty())
148 newhost = MyPrefix + MySeparator + complete;
150 newhost = complete + MySeparator + MySuffix;
152 if (!newhost.empty())
154 user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
155 if (!user->ChangeDisplayedHost(newhost.c_str()))
156 user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
164 MODULE_INIT(ModuleHostChange)