]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chghost.cpp
We were already sending FMODE +nt after each channel creation to keep services happy...
[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)+" :*** Invalid characters in hostname");
43                                 return CMD_FAILURE;
44                         }
45                 }
46                 if ((parameters[1] - x) > 63)
47                 {
48                         user->WriteServ("NOTICE %s :*** CHGHOST: Host too long",user->nick);
49                         return CMD_FAILURE;
50                 }
51                 userrec* dest = ServerInstance->FindNick(parameters[0]);
52
53                 if (!dest)
54                 {
55                         /* Drop it like a hot potato. XXX - we should probably message here.. -- w00t */
56                         return CMD_FAILURE;
57                 }
58
59                 if ((dest->ChangeDisplayedHost(parameters[1])) && (!ServerInstance->ULine(user->server)))
60                 {
61                         // fix by brain - ulines set hosts silently
62                         ServerInstance->WriteOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost);
63                 }
64
65                 /* route it! */
66                 return CMD_SUCCESS;
67
68         }
69 };
70
71
72 class ModuleChgHost : public Module
73 {
74         cmd_chghost* mycommand;
75         char hostmap[256];
76  public:
77         ModuleChgHost(InspIRCd* Me)
78                 : Module(Me)
79         {
80                 OnRehash(NULL,"");
81                 mycommand = new cmd_chghost(ServerInstance, hostmap);
82                 ServerInstance->AddCommand(mycommand);
83         }
84
85         void Implements(char* List)
86         {
87                 List[I_OnRehash] = 1;
88         }
89         
90         void OnRehash(userrec* user, const std::string &parameter)
91         {
92                 ConfigReader Conf(ServerInstance);
93                 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
94
95                 if (hmap.empty())
96                         hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
97
98                 memset(&hostmap, 0, 255);
99                 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
100                         hostmap[(unsigned char)*n] = 1;
101         }
102
103         ~ModuleChgHost()
104         {
105         }
106         
107         Version GetVersion()
108         {
109                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
110         }
111         
112 };
113
114
115 class ModuleChgHostFactory : public ModuleFactory
116 {
117  public:
118         ModuleChgHostFactory()
119         {
120         }
121         
122         ~ModuleChgHostFactory()
123         {
124         }
125         
126         virtual Module * CreateModule(InspIRCd* Me)
127         {
128                 return new ModuleChgHost(Me);
129         }
130         
131 };
132
133
134 extern "C" DllExport void * init_module( void )
135 {
136         return new ModuleChgHostFactory;
137 }
138