]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chghost.cpp
db8094aa25a4ce2f2e237b109e708ac39fa6d2de
[user/henk/code/inspircd.git] / src / modules / m_chghost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 cmd_chghost : public Command
21 {
22  private:
23         char* hostmap;
24  public:
25         cmd_chghost (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 char** parameters, int pcnt, userrec *user)
33         {
34                 const char * x = parameters[1];
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])
45                 {
46                         user->WriteServ("NOTICE %s :*** CHGHOST: Host must be specified", user->nick);
47                         return CMD_FAILURE;
48                 }
49                 
50                 if ((parameters[1] - x) > 63)
51                 {
52                         user->WriteServ("NOTICE %s :*** CHGHOST: Host too long", user->nick);
53                         return CMD_FAILURE;
54                 }
55                 userrec* dest = ServerInstance->FindNick(parameters[0]);
56
57                 if (!dest)
58                 {
59                         user->WriteServ("401 %s %s :No such nick/channel", user->nick, parameters[0]);
60                         return CMD_FAILURE;
61                 }
62
63                 if ((dest->ChangeDisplayedHost(parameters[1])) && (!ServerInstance->ULine(user->server)))
64                 {
65                         // fix by brain - ulines set hosts silently
66                         ServerInstance->WriteOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost);
67                 }
68
69                 /* route it! */
70                 return CMD_SUCCESS;
71
72         }
73 };
74
75
76 class ModuleChgHost : public Module
77 {
78         cmd_chghost* mycommand;
79         char hostmap[256];
80  public:
81         ModuleChgHost(InspIRCd* Me)
82                 : Module(Me)
83         {
84                 OnRehash(NULL,"");
85                 mycommand = new cmd_chghost(ServerInstance, hostmap);
86                 ServerInstance->AddCommand(mycommand);
87         }
88
89         void Implements(char* List)
90         {
91                 List[I_OnRehash] = 1;
92         }
93         
94         void OnRehash(userrec* user, const std::string &parameter)
95         {
96                 ConfigReader Conf(ServerInstance);
97                 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
98
99                 if (hmap.empty())
100                         hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
101
102                 memset(&hostmap, 0, 255);
103                 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
104                         hostmap[(unsigned char)*n] = 1;
105         }
106
107         ~ModuleChgHost()
108         {
109         }
110         
111         Version GetVersion()
112         {
113                 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
114         }
115         
116 };
117
118 MODULE_INIT(ModuleChgHost)