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 * ---------------------------------------------------
19 /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
21 /** Holds information on a host set by m_hostchange
23 class Host : public classbase
30 typedef std::map<std::string,Host*> hostchanges_t;
32 class ModuleHostChange : public Module
35 hostchanges_t hostchanges;
38 std::string MySeparator;
41 ModuleHostChange(InspIRCd* Me)
47 virtual ~ModuleHostChange()
49 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
58 return (Priority)ServerInstance->PriorityAfter("m_cloaking.so");
61 void Implements(char* List)
63 List[I_OnRehash] = List[I_OnUserConnect] = 1;
66 virtual void OnRehash(userrec* user, const std::string ¶meter)
68 ConfigReader Conf(ServerInstance);
69 MySuffix = Conf.ReadValue("host","suffix",0);
70 MyPrefix = Conf.ReadValue("host","prefix","",0);
71 MySeparator = Conf.ReadValue("host","separator",".",0);
72 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
77 for (int index = 0; index < Conf.Enumerate("hostchange"); index++)
79 std::string mask = Conf.ReadValue("hostchange","mask",index);
80 std::string action = Conf.ReadValue("hostchange","action",index);
81 std::string newhost = Conf.ReadValue("hostchange","value",index);
85 hostchanges[mask] = x;
89 virtual Version GetVersion()
91 // returns the version number of the module to be
93 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
96 virtual void OnUserConnect(userrec* user)
98 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
100 if (ServerInstance->MatchText(std::string(user->ident)+"@"+std::string(user->host),i->first))
102 Host* h = (Host*)i->second;
103 // host of new user matches a hostchange tag's mask
105 if (h->action == "set")
107 newhost = h->newhost;
109 else if (h->action == "suffix")
113 else if (h->action == "addnick")
115 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
116 std::string complete;
117 std::string old = user->nick;
118 for (unsigned int j = 0; j < old.length(); j++)
120 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
121 ((old[j] >= 'a') && (old[j] <= 'z')) ||
122 ((old[j] >= '0') && (old[j] <= '9')) ||
125 complete = complete + old[j];
128 if (complete.empty())
129 complete = "i-have-a-lame-nick";
131 if (!MyPrefix.empty())
132 newhost = MyPrefix + MySeparator + complete;
134 newhost = complete + MySeparator + MySuffix;
136 if (!newhost.empty())
138 user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
139 if (!user->ChangeDisplayedHost(newhost.c_str()))
140 user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
148 MODULE_INIT(ModuleHostChange)