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