]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
21ee2fc23139f1dfbf3876b16ad8ccf3169f5393
[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 CommandSethost : public Command
21 {
22  private:
23         char* hostmap;
24  public:
25         CommandSethost (InspIRCd* Instance, char* hmap) : Command(Instance,"SETHOST",'o',1), hostmap(hmap)
26         {
27                 this->source = "m_sethost.so";
28                 syntax = "<new-hostname>";
29                 TRANSLATE2(TR_TEXT, TR_END);
30         }
31
32         CmdResult Handle (const char** parameters, int pcnt, User *user)
33         {
34                 size_t len = 0;
35                 for (const char* x = parameters[0]; *x; x++, len++)
36                 {
37                         if (!hostmap[(unsigned char)*x])
38                         {
39                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** SETHOST: Invalid characters in hostname");
40                                 return CMD_FAILURE;
41                         }
42                 }
43                 if (len == 0)
44                 {
45                         user->WriteServ("NOTICE %s :*** SETHOST: Host must be specified", user->nick);
46                         return CMD_FAILURE;
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         CommandSethost* mycommand;
67         char hostmap[256];
68  public:
69         ModuleSetHost(InspIRCd* Me)
70                 : Module(Me)
71         {       
72                 OnRehash(NULL,"");
73                 mycommand = new CommandSethost(ServerInstance, hostmap);
74                 ServerInstance->AddCommand(mycommand);
75                 Implementation eventlist[] = { I_OnRehash };
76                 ServerInstance->Modules->Attach(eventlist, this, 1);
77         }
78
79
80         void OnRehash(User* user, const std::string &parameter)
81         {
82                 ConfigReader Conf(ServerInstance);
83                 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
84
85                 if (hmap.empty())
86                         hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
87
88                 memset(&hostmap, 0, 255);
89                 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
90                         hostmap[(unsigned char)*n] = 1;
91         }
92
93         virtual ~ModuleSetHost()
94         {
95         }
96         
97         virtual Version GetVersion()
98         {
99                 return Version(1, 1, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
100         }
101         
102 };
103
104 MODULE_INIT(ModuleSetHost)