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
38 hostchanges_t hostchanges;
42 ModuleHostChange(InspIRCd* Me)
45 Conf = new ConfigReader(ServerInstance);
49 virtual ~ModuleHostChange()
56 return (Priority)ServerInstance->PriorityAfter("m_cloaking.so");
59 void Implements(char* List)
61 List[I_OnRehash] = List[I_OnUserConnect] = 1;
64 virtual void OnRehash(userrec* user, const std::string ¶meter)
67 Conf = new ConfigReader(ServerInstance);
68 MySuffix = Conf->ReadValue("host","suffix",0);
69 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
74 for (int index = 0; index < Conf->Enumerate("hostchange"); index++)
76 std::string mask = Conf->ReadValue("hostchange","mask",index);
77 std::string action = Conf->ReadValue("hostchange","action",index);
78 std::string newhost = Conf->ReadValue("hostchange","value",index);
82 hostchanges[mask] = x;
86 virtual Version GetVersion()
88 // returns the version number of the module to be
90 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
93 virtual void OnUserConnect(userrec* user)
95 for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
97 if (ServerInstance->MatchText(std::string(user->ident)+"@"+std::string(user->host),i->first))
99 Host* h = (Host*)i->second;
100 // host of new user matches a hostchange tag's mask
101 std::string newhost = "";
102 if (h->action == "set")
104 newhost = h->newhost;
106 else if (h->action == "suffix")
110 else if (h->action == "addnick")
112 // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
113 std::string complete = "";
114 std::string old = user->nick;
115 for (unsigned int j = 0; j < old.length(); j++)
117 if (((old[j] >= 'A') && (old[j] <= 'Z')) ||
118 ((old[j] >= 'a') && (old[j] <= 'z')) ||
119 ((old[j] >= '0') && (old[j] <= '9')) ||
122 complete = complete + old[j];
126 complete = "i-have-a-lame-nick";
127 newhost = complete + "." + MySuffix;
131 user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
132 if (!user->ChangeDisplayedHost(newhost.c_str()))
133 user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
141 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
143 class ModuleHostChangeFactory : public ModuleFactory
146 ModuleHostChangeFactory()
150 ~ModuleHostChangeFactory()
154 virtual Module * CreateModule(InspIRCd* Me)
156 return new ModuleHostChange(Me);
162 extern "C" DllExport void * init_module( void )
164 return new ModuleHostChangeFactory;