1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
25 /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
27 /** Holds information on a host set by m_hostchange
29 class Host : public classbase
36 typedef std::map<std::string,Host*> hostchanges_t;
38 class ModuleHostChange : public Module
44 hostchanges_t hostchanges;
48 ModuleHostChange(InspIRCd* Me)
52 Conf = new ConfigReader(ServerInstance);
56 virtual ~ModuleHostChange()
63 return (Priority)ServerInstance->PriorityAfter("m_cloaking.so");
66 void Implements(char* List)
68 List[I_OnRehash] = List[I_OnUserConnect] = 1;
71 virtual void OnRehash(const std::string ¶meter)
74 Conf = new ConfigReader(ServerInstance);
75 MySuffix = Conf->ReadValue("host","suffix",0);
76 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
81 for (int index = 0; index < Conf->Enumerate("hostchange"); index++)
83 std::string mask = Conf->ReadValue("hostchange","mask",index);
84 std::string action = Conf->ReadValue("hostchange","action",index);
85 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,0,0,1,VF_VENDOR);
100 virtual void OnUserConnect(userrec* user)
102 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
104 if (ServerInstance->MatchText(std::string(user->ident)+"@"+std::string(user->host),i->first))
106 Host* h = (Host*)i->second;
107 // host of new user matches a hostchange tag's mask
108 std::string newhost = "";
109 if (h->action == "set")
111 newhost = h->newhost;
113 else if (h->action == "suffix")
117 else if (h->action == "addnick")
119 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
120 std::string complete = "";
121 std::string old = user->nick;
122 for (unsigned int j = 0; j < old.length(); j++)
124 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
125 ((old[j] >= 'a') && (old[j] <= 'z')) ||
126 ((old[j] >= '0') && (old[j] <= '9')) ||
129 complete = complete + old[j];
133 complete = "i-have-a-lame-nick";
134 newhost = complete + "." + MySuffix;
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 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
150 class ModuleHostChangeFactory : public ModuleFactory
153 ModuleHostChangeFactory()
157 ~ModuleHostChangeFactory()
161 virtual Module * CreateModule(InspIRCd* Me)
163 return new ModuleHostChange(Me);
169 extern "C" void * init_module( void )
171 return new ModuleHostChangeFactory;