]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chghost.cpp
Remove InspIRCd* parameters and fields
[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://wiki.inspircd.org/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(Module* Creator, char* hmap) : Command(Creator,"CHGHOST", 2), hostmap(hmap)
26         {
27                 flags_needed = 'o'; syntax = "<nick> <newhost>";
28                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
29         }
30
31         CmdResult Handle(const std::vector<std::string> &parameters, User *user)
32         {
33                 const char * x = parameters[1].c_str();
34
35                 for (; *x; x++)
36                 {
37                         if (!hostmap[(unsigned char)*x])
38                         {
39                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** CHGHOST: Invalid characters in hostname");
40                                 return CMD_FAILURE;
41                         }
42                 }
43                 if (parameters[1].empty())
44                 {
45                         user->WriteServ("NOTICE %s :*** CHGHOST: Host must be specified", user->nick.c_str());
46                         return CMD_FAILURE;
47                 }
48
49                 if ((parameters[1].c_str() - x) > 63)
50                 {
51                         user->WriteServ("NOTICE %s :*** CHGHOST: Host too long", user->nick.c_str());
52                         return CMD_FAILURE;
53                 }
54                 User* dest = ServerInstance->FindNick(parameters[0]);
55
56                 if (!dest)
57                 {
58                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
59                         return CMD_FAILURE;
60                 }
61
62                 if (IS_LOCAL(dest))
63                 {
64                         if ((dest->ChangeDisplayedHost(parameters[1].c_str())) && (!ServerInstance->ULine(user->server)))
65                         {
66                                 // fix by brain - ulines set hosts silently
67                                 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost);
68                         }
69                 }
70
71                 return CMD_SUCCESS;
72         }
73
74         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
75         {
76                 User* dest = ServerInstance->FindNick(parameters[0]);
77                 if (dest)
78                         return ROUTE_OPT_UCAST(dest->server);
79                 return ROUTE_LOCALONLY;
80         }
81 };
82
83
84 class ModuleChgHost : public Module
85 {
86         CommandChghost cmd;
87         char hostmap[256];
88  public:
89         ModuleChgHost() : cmd(this, hostmap)
90         {
91                 OnRehash(NULL);
92                 ServerInstance->AddCommand(&cmd);
93                 Implementation eventlist[] = { I_OnRehash };
94                 ServerInstance->Modules->Attach(eventlist, this, 1);
95         }
96
97
98         void OnRehash(User* user)
99         {
100                 ConfigReader Conf;
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("Provides support for the CHGHOST command", VF_OPTCOMMON | VF_VENDOR, API_VERSION);
118         }
119
120 };
121
122 MODULE_INIT(ModuleChgHost)