]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_uninvite.cpp
97ad841f12e37e09f4c2ae6619f5adb5387ed527
[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
25 /** Handle /UNINVITE
26  */
27 class CommandUninvite : public Command
28 {
29  public:
30         CommandUninvite(Module* Creator) : Command(Creator,"UNINVITE", 2)
31         {
32                 syntax = "<nick> <channel>";
33                 TRANSLATE2(TR_NICK, TR_TEXT);
34         }
35
36         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
37         {
38                 User* u;
39                 if (IS_LOCAL(user))
40                         u = ServerInstance->FindNickOnly(parameters[0]);
41                 else
42                         u = ServerInstance->FindNick(parameters[0]);
43
44                 Channel* c = ServerInstance->FindChan(parameters[1]);
45
46                 if ((!c) || (!u) || (u->registered != REG_ALL))
47                 {
48                         if (!c)
49                         {
50                                 user->WriteNumeric(401, "%s :No such nick/channel", parameters[1].c_str());
51                         }
52                         else
53                         {
54                                 user->WriteNumeric(401, "%s :No such nick/channel", parameters[0].c_str());
55                         }
56
57                         return CMD_FAILURE;
58                 }
59
60                 if (IS_LOCAL(user))
61                 {
62                         if (c->GetPrefixValue(user) < HALFOP_VALUE)
63                         {
64                                 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s :You must be a channel %soperator", c->name.c_str(), c->GetPrefixValue(u) == HALFOP_VALUE ? "" : "half-");
65                                 return CMD_FAILURE;
66                         }
67                 }
68
69                 /* Servers remember invites only for their local users, so act
70                  * only if the target is local. Otherwise the command will be
71                  * passed to the target users server.
72                  */
73                 LocalUser* lu = IS_LOCAL(u);
74                 if (lu)
75                 {
76                         if (!lu->RemoveInvite(c))
77                         {
78                                 user->SendText(":%s 505 %s %s %s :Is not invited to channel %s", user->server->GetName().c_str(), user->nick.c_str(), u->nick.c_str(), c->name.c_str(), c->name.c_str());
79                                 return CMD_FAILURE;
80                         }
81
82                         user->SendText(":%s 494 %s %s %s :Uninvited", user->server->GetName().c_str(), user->nick.c_str(), c->name.c_str(), u->nick.c_str());
83                         lu->WriteNumeric(493, ":You were uninvited from %s by %s", c->name.c_str(), user->nick.c_str());
84
85                         std::string msg = "*** " + user->nick + " uninvited " + u->nick + ".";
86                         c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE " + c->name + " :" + msg);
87                         ServerInstance->PI->SendChannelNotice(c, 0, msg);
88                 }
89
90                 return CMD_SUCCESS;
91         }
92
93         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
94         {
95                 User* u = ServerInstance->FindNick(parameters[0]);
96                 return u ? ROUTE_OPT_UCAST(u->server) : ROUTE_LOCALONLY;
97         }
98 };
99
100 class ModuleUninvite : public Module
101 {
102         CommandUninvite cmd;
103
104  public:
105
106         ModuleUninvite() : cmd(this)
107         {
108         }
109
110         Version GetVersion() CXX11_OVERRIDE
111         {
112                 return Version("Provides the UNINVITE command which lets users un-invite other users from channels", VF_VENDOR | VF_OPTCOMMON);
113         }
114 };
115
116 MODULE_INIT(ModuleUninvite)