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