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 CHGHOST command */
20 class CommandChghost : public Command
25 CommandChghost (InspIRCd* Instance, char* hmap) : Command(Instance,"CHGHOST","o",2), hostmap(hmap)
27 this->source = "m_chghost.so";
28 syntax = "<nick> <newhost>";
29 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
32 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
34 const char * x = parameters[1].c_str();
38 if (!hostmap[(unsigned char)*x])
40 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** CHGHOST: Invalid characters in hostname");
44 if (parameters[0].empty())
46 user->WriteServ("NOTICE %s :*** CHGHOST: Host must be specified", user->nick.c_str());
50 if ((parameters[1].c_str() - x) > 63)
52 user->WriteServ("NOTICE %s :*** CHGHOST: Host too long", user->nick.c_str());
55 User* dest = ServerInstance->FindNick(parameters[0]);
59 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
65 if ((dest->ChangeDisplayedHost(parameters[1].c_str())) && (!ServerInstance->ULine(user->server)))
67 // fix by brain - ulines set hosts silently
68 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost);
71 /* ChangeDisplayedHost fixes it for us */
82 class ModuleChgHost : public Module
84 CommandChghost* mycommand;
87 ModuleChgHost(InspIRCd* Me)
91 mycommand = new CommandChghost(ServerInstance, hostmap);
92 ServerInstance->AddCommand(mycommand);
93 Implementation eventlist[] = { I_OnRehash };
94 ServerInstance->Modules->Attach(eventlist, this, 1);
98 void OnRehash(User* user, const std::string ¶meter)
100 ConfigReader Conf(ServerInstance);
101 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
104 hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
106 memset(hostmap, 0, sizeof(hostmap));
107 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
108 hostmap[(unsigned char)*n] = 1;
117 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
122 MODULE_INIT(ModuleChgHost)