1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
16 /* $ModDesc: Provides support for the SETHOST command */
20 class CommandSethost : public Command
25 CommandSethost (InspIRCd* Instance, char* hmap) : Command(Instance,"SETHOST","o",1), hostmap(hmap)
27 this->source = "m_sethost.so";
28 syntax = "<new-hostname>";
29 TRANSLATE2(TR_TEXT, TR_END);
32 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
35 for (std::string::const_iterator x = parameters[0].begin(); x != parameters[0].end(); x++, len++)
37 if (!hostmap[(const unsigned char)*x])
39 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** SETHOST: Invalid characters in hostname");
45 user->WriteServ("NOTICE %s :*** SETHOST: Host must be specified", user->nick.c_str());
50 user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick.c_str());
54 if (user->ChangeDisplayedHost(parameters[0].c_str()))
56 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used SETHOST to change their displayed host to "+user->dhost);
65 class ModuleSetHost : public Module
67 CommandSethost* mycommand;
70 ModuleSetHost(InspIRCd* Me)
74 mycommand = new CommandSethost(ServerInstance, hostmap);
75 ServerInstance->AddCommand(mycommand);
76 Implementation eventlist[] = { I_OnRehash };
77 ServerInstance->Modules->Attach(eventlist, this, 1);
81 void OnRehash(User* user, const std::string ¶meter)
83 ConfigReader Conf(ServerInstance);
84 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
87 hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
89 memset(hostmap, 0, sizeof(hostmap));
90 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
91 hostmap[(unsigned char)*n] = 1;
94 virtual ~ModuleSetHost()
98 virtual Version GetVersion()
100 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
105 MODULE_INIT(ModuleSetHost)