]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chghost.cpp
3ce3d37bd85b471195f039658552dcbfda7cd0f6
[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 (!strchr(hostmap, *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                 if (dest)
56                 {
57                         if ((dest->ChangeDisplayedHost(parameters[1])) && (!ServerInstance->ULine(user->server)))
58                         {
59                                 // fix by brain - ulines set hosts silently
60                                 ServerInstance->WriteOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost);
61                         }
62                         return CMD_SUCCESS;
63                 }
64
65                 return CMD_FAILURE;
66         }
67 };
68
69
70 class ModuleChgHost : public Module
71 {
72         cmd_chghost* mycommand;
73         char* hostmap;
74         std::string hmap;
75  public:
76         ModuleChgHost(InspIRCd* Me)
77                 : Module::Module(Me)
78         {
79                 OnRehash("");
80                 mycommand = new cmd_chghost(ServerInstance, hostmap);
81                 ServerInstance->AddCommand(mycommand);
82         }
83
84         void Implements(char* List)
85         {
86                 List[I_OnRehash] = 1;
87         }
88         
89         void OnRehash(const std::string &parameter)
90         {
91                 ConfigReader Conf(ServerInstance);
92                 hmap = Conf.ReadValue("hostname", "charmap", 0);
93
94                 if (hmap.empty())
95                         hostmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
96                 else
97                         hostmap = (char*)hmap.c_str();
98         }
99
100         ~ModuleChgHost()
101         {
102         }
103         
104         Version GetVersion()
105         {
106                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
107         }
108         
109 };
110
111
112 class ModuleChgHostFactory : public ModuleFactory
113 {
114  public:
115         ModuleChgHostFactory()
116         {
117         }
118         
119         ~ModuleChgHostFactory()
120         {
121         }
122         
123         virtual Module * CreateModule(InspIRCd* Me)
124         {
125                 return new ModuleChgHost(Me);
126         }
127         
128 };
129
130
131 extern "C" void * init_module( void )
132 {
133         return new ModuleChgHostFactory;
134 }
135