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