]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sethost.cpp
Fix the cloaking module on C++98 compilers.
[user/henk/code/inspircd.git] / src / modules / m_sethost.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2017-2018, 2020 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012-2013 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
9  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2004, 2006, 2010 Craig Edwards <brain@inspircd.org>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27
28 /** Handle /SETHOST
29  */
30 class CommandSethost : public Command
31 {
32  public:
33         std::bitset<UCHAR_MAX> hostmap;
34
35         CommandSethost(Module* Creator)
36                 : Command(Creator,"SETHOST", 1)
37         {
38                 allow_empty_last_param = false;
39                 flags_needed = 'o';
40                 syntax = "<host>";
41         }
42
43         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
44         {
45                 if (parameters[0].length() > ServerInstance->Config->Limits.MaxHost)
46                 {
47                         user->WriteNotice("*** SETHOST: Host too long");
48                         return CMD_FAILURE;
49                 }
50
51                 for (std::string::const_iterator x = parameters[0].begin(); x != parameters[0].end(); x++)
52                 {
53                         if (!hostmap.test(static_cast<unsigned char>(*x)))
54                         {
55                                 user->WriteNotice("*** SETHOST: Invalid characters in hostname");
56                                 return CMD_FAILURE;
57                         }
58                 }
59
60                 if (user->ChangeDisplayedHost(parameters[0]))
61                 {
62                         ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used SETHOST to change their displayed host to "+user->GetDisplayedHost());
63                         return CMD_SUCCESS;
64                 }
65
66                 return CMD_FAILURE;
67         }
68 };
69
70
71 class ModuleSetHost : public Module
72 {
73         CommandSethost cmd;
74
75  public:
76         ModuleSetHost()
77                 : cmd(this)
78         {
79         }
80
81         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
82         {
83                 ConfigTag* tag = ServerInstance->Config->ConfValue("hostname");
84                 const std::string hmap = tag->getString("charmap", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789", 1);
85
86                 cmd.hostmap.reset();
87                 for (std::string::const_iterator n = hmap.begin(); n != hmap.end(); n++)
88                         cmd.hostmap.set(static_cast<unsigned char>(*n));
89         }
90
91         Version GetVersion() CXX11_OVERRIDE
92         {
93                 return Version("Adds the /SETHOST command which allows server operators to change their displayed hostname.", VF_VENDOR);
94         }
95 };
96
97 MODULE_INIT(ModuleSetHost)