]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
A few more I missed.
[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)+" :*** SETHOST: Invalid characters in hostname");
42                                 return CMD_FAILURE;
43                         }
44                 }
45                 if (len == 0)
46                 {
47                         user->WriteServ("NOTICE %s :*** SETHOST: Host must be specified", user->nick);
48                         return CMD_FAILURE;
49                 }
50                 if (len > 64)
51                 {
52                         user->WriteServ("NOTICE %s :*** SETHOST: Host too long",user->nick);
53                         return CMD_FAILURE;
54                 }
55                 if (user->ChangeDisplayedHost(parameters[0]))
56                 {
57                         ServerInstance->WriteOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+user->dhost);
58                         return CMD_SUCCESS;
59                 }
60
61                 return CMD_FAILURE;
62         }
63 };
64
65
66 class ModuleSetHost : public Module
67 {
68         cmd_sethost* mycommand;
69         char hostmap[256];
70  public:
71         ModuleSetHost(InspIRCd* Me)
72                 : Module(Me)
73         {       
74                 OnRehash(NULL,"");
75                 mycommand = new cmd_sethost(ServerInstance, hostmap);
76                 ServerInstance->AddCommand(mycommand);
77         }
78
79         void Implements(char* List)
80         {
81                 List[I_OnRehash] = 1;
82         }
83
84         void OnRehash(userrec* user, const std::string &parameter)
85         {
86                 ConfigReader Conf(ServerInstance);
87                 std::string hmap = Conf.ReadValue("hostname", "charmap", 0);
88
89                 if (hmap.empty())
90                         hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789";
91
92                 memset(&hostmap, 0, 255);
93                 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
94                         hostmap[(unsigned char)*n] = 1;
95         }
96
97         virtual ~ModuleSetHost()
98         {
99         }
100         
101         virtual Version GetVersion()
102         {
103                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
104         }
105         
106 };
107
108 MODULE_INIT(ModuleSetHost)