]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sapart.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_sapart.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 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2004, 2007-2008, 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 /SAPART
29  */
30 class CommandSapart : public Command
31 {
32  public:
33         CommandSapart(Module* Creator) : Command(Creator,"SAPART", 2, 3)
34         {
35                 flags_needed = 'o';
36                 syntax = "<nick> <channel>[,<channel>]+ [:<reason>]";
37                 TRANSLATE3(TR_NICK, TR_TEXT, TR_TEXT);
38         }
39
40         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
41         {
42                 if (CommandParser::LoopCall(user, this, parameters, 1))
43                         return CMD_FAILURE;
44
45                 User* dest = ServerInstance->FindNick(parameters[0]);
46                 Channel* channel = ServerInstance->FindChan(parameters[1]);
47                 std::string reason;
48
49                 if ((dest) && (dest->registered == REG_ALL) && (channel))
50                 {
51                         if (parameters.size() > 2)
52                                 reason = parameters[2];
53
54                         if (dest->server->IsULine())
55                         {
56                                 user->WriteNumeric(ERR_NOPRIVILEGES, "Cannot use an SA command on a U-lined client");
57                                 return CMD_FAILURE;
58                         }
59
60                         if (!channel->HasUser(dest))
61                         {
62                                 user->WriteNotice("*** " + dest->nick + " is not on " + channel->name);
63                                 return CMD_FAILURE;
64                         }
65
66                         /* For local clients, directly part them generating a PART message. For remote clients,
67                          * just return CMD_SUCCESS knowing the protocol module will route the SAPART to the users
68                          * local server and that will generate the PART instead
69                          */
70                         if (IS_LOCAL(dest))
71                         {
72                                 channel->PartUser(dest, reason);
73                                 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used SAPART to make "+dest->nick+" part "+channel->name);
74                         }
75
76                         return CMD_SUCCESS;
77                 }
78                 else
79                 {
80                         user->WriteNotice("*** Invalid nickname or channel");
81                 }
82
83                 return CMD_FAILURE;
84         }
85
86         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
87         {
88                 return ROUTE_OPT_UCAST(parameters[0]);
89         }
90 };
91
92
93 class ModuleSapart : public Module
94 {
95         CommandSapart cmd;
96  public:
97         ModuleSapart()
98                 : cmd(this)
99         {
100         }
101
102         Version GetVersion() CXX11_OVERRIDE
103         {
104                 return Version("Adds the /SAPART command which allows server operators to force part users from one or more channels without having any privileges in these channels.", VF_OPTCOMMON | VF_VENDOR);
105         }
106 };
107
108 MODULE_INIT(ModuleSapart)