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