]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
18ca6c6bbcb46fa56aac66ff52f6f1ecdd4f650e
[user/henk/code/inspircd.git] / src / modules / m_sethost.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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 std::vector<std::string>& parameters, User *user)
33         {
34                 size_t len = 0;
35                 for (std::string::const_iterator x = parameters[0].begin(); x != parameters[0].end(); x++, len++)
36                 {
37                         if (!hostmap[(const 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.c_str());
46                         return CMD_FAILURE;
47                 }
48                 if (len > 64)
49                 {
50                         user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick.c_str());
51                         return CMD_FAILURE;
52                 }
53
54                 if (user->ChangeDisplayedHost(parameters[0].c_str()))
55                 {
56                         ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used SETHOST to change their displayed host to "+user->dhost);
57                         return CMD_LOCALONLY;
58                 }
59
60                 return CMD_FAILURE;
61         }
62 };
63
64
65 class ModuleSetHost : public Module
66 {
67         CommandSethost* mycommand;
68         char hostmap[256];
69  public:
70         ModuleSetHost(InspIRCd* Me)
71                 : Module(Me)
72         {
73                 OnRehash(NULL,"");
74                 mycommand = new CommandSethost(ServerInstance, hostmap);
75                 ServerInstance->AddCommand(mycommand);
76                 Implementation eventlist[] = { I_OnRehash };
77                 ServerInstance->Modules->Attach(eventlist, this, 1);
78         }
79
80
81         void OnRehash(User* 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, sizeof(hostmap));
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("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
101         }
102
103 };
104
105 MODULE_INIT(ModuleSetHost)