]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sanick.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_sanick.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 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 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) 2004, 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 /SANICK
29  */
30 class CommandSanick : public Command
31 {
32  public:
33         CommandSanick(Module* Creator) : Command(Creator,"SANICK", 2)
34         {
35                 allow_empty_last_param = false;
36                 flags_needed = 'o';
37                 syntax = "<nick> <newnick>";
38                 TRANSLATE2(TR_NICK, TR_TEXT);
39         }
40
41         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
42         {
43                 User* target = ServerInstance->FindNick(parameters[0]);
44
45                 /* Do local sanity checks and bails */
46                 if (IS_LOCAL(user))
47                 {
48                         if (target && target->server->IsULine())
49                         {
50                                 user->WriteNumeric(ERR_NOPRIVILEGES, "Cannot use an SA command on a U-lined client");
51                                 return CMD_FAILURE;
52                         }
53
54                         if ((!target) || (target->registered != REG_ALL))
55                         {
56                                 user->WriteNotice("*** No such nickname: '" + parameters[0] + "'");
57                                 return CMD_FAILURE;
58                         }
59
60                         if (!ServerInstance->IsNick(parameters[1]))
61                         {
62                                 user->WriteNotice("*** Invalid nickname: '" + parameters[1] + "'");
63                                 return CMD_FAILURE;
64                         }
65                 }
66
67                 /* Have we hit target's server yet? */
68                 if (target && IS_LOCAL(target))
69                 {
70                         const std::string oldnick = target->nick;
71                         const std::string newnick = parameters[1];
72                         if (!ServerInstance->FindNickOnly(newnick) && target->ChangeNick(newnick))
73                         {
74                                 ServerInstance->SNO->WriteGlobalSno('a', user->nick + " used SANICK to change " + oldnick + " to " + newnick);
75                         }
76                         else
77                         {
78                                 ServerInstance->SNO->WriteGlobalSno('a', user->nick + " failed SANICK (from " + oldnick + " to " + newnick + ")");
79                         }
80                 }
81
82                 return CMD_SUCCESS;
83         }
84
85         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
86         {
87                 return ROUTE_OPT_UCAST(parameters[0]);
88         }
89 };
90
91
92 class ModuleSanick : public Module
93 {
94         CommandSanick cmd;
95  public:
96         ModuleSanick()
97                 : cmd(this)
98         {
99         }
100
101         Version GetVersion() CXX11_OVERRIDE
102         {
103                 return Version("Adds the /SANICK command which allows server operators to change the nickname of a user.", VF_OPTCOMMON | VF_VENDOR);
104         }
105 };
106
107 MODULE_INIT(ModuleSanick)