]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chghost.cpp
1ce2856011552357f70ff52de5522e49bab65926
[user/henk/code/inspircd.git] / src / modules / m_chghost.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013-2014, 2017-2018, 2020 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012-2014, 2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009, 2012 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
9  *   Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2006 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 /CHGHOST
29  */
30 class CommandChghost : public Command
31 {
32  public:
33         std::bitset<UCHAR_MAX> hostmap;
34
35         CommandChghost(Module* Creator)
36                 : Command(Creator,"CHGHOST", 2)
37         {
38                 allow_empty_last_param = false;
39                 flags_needed = 'o';
40                 syntax = "<nick> <host>";
41                 TRANSLATE2(TR_NICK, TR_TEXT);
42         }
43
44         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
45         {
46                 if (parameters[1].length() > ServerInstance->Config->Limits.MaxHost)
47                 {
48                         user->WriteNotice("*** CHGHOST: Host too long");
49                         return CMD_FAILURE;
50                 }
51
52                 for (std::string::const_iterator x = parameters[1].begin(); x != parameters[1].end(); x++)
53                 {
54                         if (!hostmap.test(static_cast<unsigned char>(*x)))
55                         {
56                                 user->WriteNotice("*** CHGHOST: Invalid characters in hostname");
57                                 return CMD_FAILURE;
58                         }
59                 }
60
61                 User* dest = ServerInstance->FindNick(parameters[0]);
62
63                 // Allow services to change the host of unregistered users
64                 if ((!dest) || ((dest->registered != REG_ALL) && (!user->server->IsULine())))
65                 {
66                         user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
67                         return CMD_FAILURE;
68                 }
69
70                 if (IS_LOCAL(dest))
71                 {
72                         if ((dest->ChangeDisplayedHost(parameters[1])) && (!user->server->IsULine()))
73                         {
74                                 // fix by brain - ulines set hosts silently
75                                 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->GetDisplayedHost());
76                         }
77                 }
78
79                 return CMD_SUCCESS;
80         }
81
82         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
83         {
84                 return ROUTE_OPT_UCAST(parameters[0]);
85         }
86 };
87
88
89 class ModuleChgHost : public Module
90 {
91         CommandChghost cmd;
92
93  public:
94         ModuleChgHost()
95                 : cmd(this)
96         {
97         }
98
99         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
100         {
101                 ConfigTag* tag = ServerInstance->Config->ConfValue("hostname");
102                 const std::string hmap = tag->getString("charmap", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789", 1);
103
104                 cmd.hostmap.reset();
105                 for (std::string::const_iterator n = hmap.begin(); n != hmap.end(); n++)
106                         cmd.hostmap.set(static_cast<unsigned char>(*n));
107         }
108
109         Version GetVersion() CXX11_OVERRIDE
110         {
111                 return Version("Adds the /CHGHOST command which allows server operators to change the displayed hostname of a user.", VF_OPTCOMMON | VF_VENDOR);
112         }
113 };
114
115 MODULE_INIT(ModuleChgHost)