]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_uninvite.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_uninvite.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
5  *   Copyright (C) 2013, 2018-2020 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2012-2016 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
10  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11  *   Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
12  *
13  * This file is part of InspIRCd.  InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26
27 #include "inspircd.h"
28 #include "modules/invite.h"
29
30 enum
31 {
32         // InspIRCd-specific.
33         ERR_INVITEREMOVED = 494,
34         ERR_NOTINVITED = 505,
35         RPL_UNINVITED = 653
36 };
37
38 /** Handle /UNINVITE
39  */
40 class CommandUninvite : public Command
41 {
42         Invite::API invapi;
43  public:
44         CommandUninvite(Module* Creator)
45                 : Command(Creator, "UNINVITE", 2)
46                 , invapi(Creator)
47         {
48                 syntax = "<nick> <channel>";
49                 TRANSLATE2(TR_NICK, TR_TEXT);
50         }
51
52         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
53         {
54                 User* u;
55                 if (IS_LOCAL(user))
56                         u = ServerInstance->FindNickOnly(parameters[0]);
57                 else
58                         u = ServerInstance->FindNick(parameters[0]);
59
60                 Channel* c = ServerInstance->FindChan(parameters[1]);
61
62                 if ((!c) || (!u) || (u->registered != REG_ALL))
63                 {
64                         if (!c)
65                         {
66                                 user->WriteNumeric(Numerics::NoSuchChannel(parameters[1]));
67                         }
68                         else
69                         {
70                                 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
71                         }
72
73                         return CMD_FAILURE;
74                 }
75
76                 if (IS_LOCAL(user))
77                 {
78                         if (c->GetPrefixValue(user) < HALFOP_VALUE)
79                         {
80                                 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, c->name, InspIRCd::Format("You must be a channel %soperator", c->GetPrefixValue(u) == HALFOP_VALUE ? "" : "half-"));
81                                 return CMD_FAILURE;
82                         }
83                 }
84
85                 /* Servers remember invites only for their local users, so act
86                  * only if the target is local. Otherwise the command will be
87                  * passed to the target users server.
88                  */
89                 LocalUser* lu = IS_LOCAL(u);
90                 if (lu)
91                 {
92                         // XXX: The source of the numeric we send must be the server of the user doing the /UNINVITE,
93                         // so they don't see where the target user is connected to
94                         if (!invapi->Remove(lu, c))
95                         {
96                                 Numeric::Numeric n(ERR_NOTINVITED);
97                                 n.SetServer(user->server);
98                                 n.push(u->nick).push(c->name).push(InspIRCd::Format("Is not invited to channel %s", c->name.c_str()));
99                                 user->WriteRemoteNumeric(n);
100                                 return CMD_FAILURE;
101                         }
102
103                         Numeric::Numeric n(ERR_INVITEREMOVED);
104                         n.SetServer(user->server);
105                         n.push(c->name).push(u->nick).push("Uninvited");
106                         user->WriteRemoteNumeric(n);
107
108                         lu->WriteNumeric(RPL_UNINVITED, InspIRCd::Format("You were uninvited from %s by %s", c->name.c_str(), user->nick.c_str()));
109                         c->WriteRemoteNotice(InspIRCd::Format("*** %s uninvited %s.", user->nick.c_str(), u->nick.c_str()));
110                 }
111
112                 return CMD_SUCCESS;
113         }
114
115         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
116         {
117                 return ROUTE_OPT_UCAST(parameters[0]);
118         }
119 };
120
121 class ModuleUninvite : public Module
122 {
123         CommandUninvite cmd;
124
125  public:
126
127         ModuleUninvite() : cmd(this)
128         {
129         }
130
131         Version GetVersion() CXX11_OVERRIDE
132         {
133                 return Version("Adds the /UNINVITE command which allows users who have invited another user to a channel to withdraw their invite.", VF_VENDOR | VF_OPTCOMMON);
134         }
135 };
136
137 MODULE_INIT(ModuleUninvite)