]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chghost.cpp
Update copyrights for 2009.
[user/henk/code/inspircd.git] / src / modules / m_chghost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides support for the CHGHOST command */
17
18 /** Handle /CHGHOST
19  */
20 class CommandChghost : public Command
21 {
22  private:
23         char* hostmap;
24  public:
25         CommandChghost (InspIRCd* Instance, char* hmap) : Command(Instance,"CHGHOST","o",2), hostmap(hmap)
26         {
27                 this->source = "m_chghost.so";
28                 syntax = "<nick> <newhost>";
29                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
30         }
31
32         CmdResult Handle(const std::vector<std::string> &parameters, User *user)
33         {
34                 const char * x = parameters[1].c_str();
35
36                 for (; *x; x++)
37                 {
38                         if (!hostmap[(unsigned char)*x])
39                         {
40                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** CHGHOST: Invalid characters in hostname");
41                                 return CMD_FAILURE;
42                         }
43                 }
44                 if (parameters[0].empty())
45                 {
46                         user->WriteServ("NOTICE %s :*** CHGHOST: Host must be specified", user->nick.c_str());
47                         return CMD_FAILURE;
48                 }
49
50                 if ((parameters[1].c_str() - x) > 63)
51                 {
52                         user->WriteServ("NOTICE %s :*** CHGHOST: Host too long", user->nick.c_str());
53                         return CMD_FAILURE;
54                 }
55                 User* dest = ServerInstance->FindNick(parameters[0]);
56
57                 if (!dest)
58                 {
59                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
60                         return CMD_FAILURE;
61                 }
62
63                 if (IS_LOCAL(dest))
64                 {
65                         if ((dest->ChangeDisplayedHost(parameters[1].c_str())) && (!ServerInstance->ULine(user->server)))
66                         {
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);
69                         }
70
71                         /* ChangeDisplayedHost fixes it for us */
72                         return CMD_LOCALONLY;
73                 }
74
75                 /* route it! */
76                 return CMD_SUCCESS;
77
78         }
79 };
80
81
82 class ModuleChgHost : public Module
83 {
84         CommandChghost* mycommand;
85         char hostmap[256];
86  public:
87         ModuleChgHost(InspIRCd* Me)
88                 : Module(Me)
89         {
90                 OnRehash(NULL,"");
91                 mycommand = new CommandChghost(ServerInstance, hostmap);
92                 ServerInstance->AddCommand(mycommand);
93                 Implementation eventlist[] = { I_OnRehash };
94                 ServerInstance->Modules->Attach(eventlist, this, 1);
95         }
96
97
98         void OnRehash(User* user, const std::string &parameter)
99         {
100                 ConfigReader Conf(ServerInstance);
101                 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
102
103                 if (hmap.empty())
104                         hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
105
106                 memset(hostmap, 0, sizeof(hostmap));
107                 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
108                         hostmap[(unsigned char)*n] = 1;
109         }
110
111         ~ModuleChgHost()
112         {
113         }
114
115         Version GetVersion()
116         {
117                 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
118         }
119
120 };
121
122 MODULE_INIT(ModuleChgHost)