]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chghost.cpp
OOPS! We try again, since I'm smoking craq. LF is 0x0a NOT CR.
[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 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 /* $ModDesc: Provides support for the CHGHOST command */
20
21 /** Handle /CHGHOST
22  */
23 class cmd_chghost : public command_t
24 {
25  private:
26         char* hostmap;
27  public:
28         cmd_chghost (InspIRCd* Instance, char* hmap) : command_t(Instance,"CHGHOST",'o',2), hostmap(hmap)
29         {
30                 this->source = "m_chghost.so";
31                 syntax = "<nick> <newhost>";
32         }
33  
34         CmdResult Handle(const char** parameters, int pcnt, userrec *user)
35         {
36                 const char * x = parameters[1];
37
38                 for (; *x; x++)
39                 {
40                         if (!hostmap[(unsigned char)*x])
41                         {
42                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** CHGHOST: Invalid characters in hostname");
43                                 return CMD_FAILURE;
44                         }
45                 }
46                 if (!*parameters[0])
47                 {
48                         user->WriteServ("NOTICE %s :*** CHGHOST: Host must be specified", user->nick);
49                         return CMD_FAILURE;
50                 }
51                 
52                 if ((parameters[1] - x) > 63)
53                 {
54                         user->WriteServ("NOTICE %s :*** CHGHOST: Host too long", user->nick);
55                         return CMD_FAILURE;
56                 }
57                 userrec* dest = ServerInstance->FindNick(parameters[0]);
58
59                 if (!dest)
60                 {
61                         user->WriteServ("401 %s %s :No such nick/channel", user->nick, parameters[0]);
62                         return CMD_FAILURE;
63                 }
64
65                 if ((dest->ChangeDisplayedHost(parameters[1])) && (!ServerInstance->ULine(user->server)))
66                 {
67                         // fix by brain - ulines set hosts silently
68                         ServerInstance->WriteOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost);
69                 }
70
71                 /* route it! */
72                 return CMD_SUCCESS;
73
74         }
75 };
76
77
78 class ModuleChgHost : public Module
79 {
80         cmd_chghost* mycommand;
81         char hostmap[256];
82  public:
83         ModuleChgHost(InspIRCd* Me)
84                 : Module(Me)
85         {
86                 OnRehash(NULL,"");
87                 mycommand = new cmd_chghost(ServerInstance, hostmap);
88                 ServerInstance->AddCommand(mycommand);
89         }
90
91         void Implements(char* List)
92         {
93                 List[I_OnRehash] = 1;
94         }
95         
96         void OnRehash(userrec* user, const std::string &parameter)
97         {
98                 ConfigReader Conf(ServerInstance);
99                 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
100
101                 if (hmap.empty())
102                         hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
103
104                 memset(&hostmap, 0, 255);
105                 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
106                         hostmap[(unsigned char)*n] = 1;
107         }
108
109         ~ModuleChgHost()
110         {
111         }
112         
113         Version GetVersion()
114         {
115                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
116         }
117         
118 };
119
120 MODULE_INIT(ModuleChgHost)