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