1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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(Module* Creator, char* hmap) : Command(Creator,"SETHOST", 1), hostmap(hmap)
27 flags_needed = 'o'; syntax = "<new-hostname>";
28 TRANSLATE2(TR_TEXT, TR_END);
31 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
34 for (std::string::const_iterator x = parameters[0].begin(); x != parameters[0].end(); x++, len++)
36 if (!hostmap[(const unsigned char)*x])
38 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** SETHOST: Invalid characters in hostname");
44 user->WriteServ("NOTICE %s :*** SETHOST: Host must be specified", user->nick.c_str());
49 user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick.c_str());
53 if (user->ChangeDisplayedHost(parameters[0].c_str()))
55 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick)+" used SETHOST to change their displayed host to "+user->dhost);
64 class ModuleSetHost : public Module
69 ModuleSetHost(InspIRCd* Me)
70 : Module(Me), cmd(this, hostmap)
73 ServerInstance->AddCommand(&cmd);
74 Implementation eventlist[] = { I_OnRehash };
75 ServerInstance->Modules->Attach(eventlist, this, 1);
79 void OnRehash(User* user)
81 ConfigReader Conf(ServerInstance);
82 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
85 hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
87 memset(hostmap, 0, sizeof(hostmap));
88 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
89 hostmap[(unsigned char)*n] = 1;
92 virtual ~ModuleSetHost()
96 virtual Version GetVersion()
98 return Version("$Id$", VF_VENDOR, API_VERSION);
103 MODULE_INIT(ModuleSetHost)