]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chghost.cpp
Fix some of the include guard names (requested by SaberUK)
[user/henk/code/inspircd.git] / src / modules / m_chghost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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';
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                 if (parameters[1].length() > 63)
37                 {
38                         user->WriteServ("NOTICE %s :*** CHGHOST: Host too long", user->nick.c_str());
39                         return CMD_FAILURE;
40                 }
41
42                 for (; *x; x++)
43                 {
44                         if (!hostmap[(unsigned char)*x])
45                         {
46                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** CHGHOST: Invalid characters in hostname");
47                                 return CMD_FAILURE;
48                         }
49                 }
50
51                 User* dest = ServerInstance->FindNick(parameters[0]);
52
53                 if (!dest)
54                 {
55                         user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameters[0].c_str());
56                         return CMD_FAILURE;
57                 }
58
59                 if (IS_LOCAL(dest))
60                 {
61                         if ((dest->ChangeDisplayedHost(parameters[1].c_str())) && (!ServerInstance->ULine(user->server)))
62                         {
63                                 // fix by brain - ulines set hosts silently
64                                 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost);
65                         }
66                 }
67
68                 return CMD_SUCCESS;
69         }
70
71         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
72         {
73                 User* dest = ServerInstance->FindNick(parameters[0]);
74                 if (dest)
75                         return ROUTE_OPT_UCAST(dest->server);
76                 return ROUTE_LOCALONLY;
77         }
78 };
79
80
81 class ModuleChgHost : public Module
82 {
83         CommandChghost cmd;
84         char hostmap[256];
85  public:
86         ModuleChgHost() : cmd(this, hostmap)
87         {
88                 OnRehash(NULL);
89                 ServerInstance->AddCommand(&cmd);
90                 Implementation eventlist[] = { I_OnRehash };
91                 ServerInstance->Modules->Attach(eventlist, this, 1);
92         }
93
94
95         void OnRehash(User* user)
96         {
97                 ConfigReader Conf;
98                 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
99
100                 if (hmap.empty())
101                         hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
102
103                 memset(hostmap, 0, sizeof(hostmap));
104                 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
105                         hostmap[(unsigned char)*n] = 1;
106         }
107
108         ~ModuleChgHost()
109         {
110         }
111
112         Version GetVersion()
113         {
114                 return Version("Provides support for the CHGHOST command", VF_OPTCOMMON | VF_VENDOR);
115         }
116
117 };
118
119 MODULE_INIT(ModuleChgHost)