]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
f05d2c8a45d4631adaede53f21b1e18d6e6e2ab8
[user/henk/code/inspircd.git] / src / modules / m_sethost.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 SETHOST command */
23
24 /** Handle /SETHOST
25  */
26 class cmd_sethost : public command_t
27 {
28  private:
29         char*& hostmap;
30  public:
31         cmd_sethost (InspIRCd* Instance, char*& hmap) : command_t(Instance,"SETHOST",'o',1), hostmap(hmap)
32         {
33                 this->source = "m_sethost.so";
34                 syntax = "<new-hostname>";
35         }
36
37         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
38         {
39                 size_t len = 0;
40                 for (const char* x = parameters[0]; *x; x++, len++)
41                 {
42                         if (!strchr(hostmap, *x))
43                         {
44                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
45                                 return CMD_FAILURE;
46                         }
47                 }
48                 if (len > 64)
49                 {
50                         user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick);
51                         return CMD_FAILURE;
52                 }
53                 if (user->ChangeDisplayedHost(parameters[0]))
54                 {
55                         ServerInstance->WriteOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+user->dhost);
56                         return CMD_SUCCESS;
57                 }
58
59                 return CMD_FAILURE;
60         }
61 };
62
63
64 class ModuleSetHost : public Module
65 {
66         cmd_sethost* mycommand;
67         char* hostmap;
68         std::string hmap;
69  public:
70         ModuleSetHost(InspIRCd* Me)
71                 : Module::Module(Me)
72         {       
73                 OnRehash("");
74                 mycommand = new cmd_sethost(ServerInstance, hostmap);
75                 ServerInstance->AddCommand(mycommand);
76         }
77
78         void Implements(char* List)
79         {
80                 List[I_OnRehash] = 1;
81         }
82
83         void OnRehash(const std::string &parameter)
84         {
85                 ConfigReader Conf(ServerInstance);
86                 hmap = Conf.ReadValue("hostname", "charmap", 0);
87
88                 if (hmap.empty())
89                         hostmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
90                 else
91                         hostmap = (char*)hmap.c_str();
92         }
93
94         virtual ~ModuleSetHost()
95         {
96         }
97         
98         virtual Version GetVersion()
99         {
100                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
101         }
102         
103 };
104
105 class ModuleSetHostFactory : public ModuleFactory
106 {
107  public:
108         ModuleSetHostFactory()
109         {
110         }
111         
112         ~ModuleSetHostFactory()
113         {
114         }
115         
116         virtual Module * CreateModule(InspIRCd* Me)
117         {
118                 return new ModuleSetHost(Me);
119         }
120         
121 };
122
123
124 extern "C" void * init_module( void )
125 {
126         return new ModuleSetHostFactory;
127 }
128