]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_uninvite.cpp
Fix the chanhistory module not storing CTCP ACTIONs.
[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-2019 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         RPL_UNINVITED = 653
34 };
35
36 /** Handle /UNINVITE
37  */
38 class CommandUninvite : public Command
39 {
40         Invite::API invapi;
41  public:
42         CommandUninvite(Module* Creator)
43                 : Command(Creator, "UNINVITE", 2)
44                 , invapi(Creator)
45         {
46                 syntax = "<nick> <channel>";
47                 TRANSLATE2(TR_NICK, TR_TEXT);
48         }
49
50         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
51         {
52                 User* u;
53                 if (IS_LOCAL(user))
54                         u = ServerInstance->FindNickOnly(parameters[0]);
55                 else
56                         u = ServerInstance->FindNick(parameters[0]);
57
58                 Channel* c = ServerInstance->FindChan(parameters[1]);
59
60                 if ((!c) || (!u) || (u->registered != REG_ALL))
61                 {
62                         if (!c)
63                         {
64                                 user->WriteNumeric(Numerics::NoSuchChannel(parameters[1]));
65                         }
66                         else
67                         {
68                                 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
69                         }
70
71                         return CMD_FAILURE;
72                 }
73
74                 if (IS_LOCAL(user))
75                 {
76                         if (c->GetPrefixValue(user) < HALFOP_VALUE)
77                         {
78                                 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, c->name, InspIRCd::Format("You must be a channel %soperator", c->GetPrefixValue(u) == HALFOP_VALUE ? "" : "half-"));
79                                 return CMD_FAILURE;
80                         }
81                 }
82
83                 /* Servers remember invites only for their local users, so act
84                  * only if the target is local. Otherwise the command will be
85                  * passed to the target users server.
86                  */
87                 LocalUser* lu = IS_LOCAL(u);
88                 if (lu)
89                 {
90                         // XXX: The source of the numeric we send must be the server of the user doing the /UNINVITE,
91                         // so they don't see where the target user is connected to
92                         if (!invapi->Remove(lu, c))
93                         {
94                                 Numeric::Numeric n(505);
95                                 n.SetServer(user->server);
96                                 n.push(u->nick).push(c->name).push(InspIRCd::Format("Is not invited to channel %s", c->name.c_str()));
97                                 user->WriteRemoteNumeric(n);
98                                 return CMD_FAILURE;
99                         }
100
101                         Numeric::Numeric n(494);
102                         n.SetServer(user->server);
103                         n.push(c->name).push(u->nick).push("Uninvited");
104                         user->WriteRemoteNumeric(n);
105
106                         lu->WriteNumeric(RPL_UNINVITED, InspIRCd::Format("You were uninvited from %s by %s", c->name.c_str(), user->nick.c_str()));
107                         c->WriteRemoteNotice(InspIRCd::Format("*** %s uninvited %s.", user->nick.c_str(), u->nick.c_str()));
108                 }
109
110                 return CMD_SUCCESS;
111         }
112
113         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
114         {
115                 return ROUTE_OPT_UCAST(parameters[0]);
116         }
117 };
118
119 class ModuleUninvite : public Module
120 {
121         CommandUninvite cmd;
122
123  public:
124
125         ModuleUninvite() : cmd(this)
126         {
127         }
128
129         Version GetVersion() CXX11_OVERRIDE
130         {
131                 return Version("Provides the UNINVITE command which lets users un-invite other users from channels", VF_VENDOR | VF_OPTCOMMON);
132         }
133 };
134
135 MODULE_INIT(ModuleUninvite)