]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_uninvite.cpp
Allow commands to optionally route themselves using ENCAP
[user/henk/code/inspircd.git] / src / modules / m_uninvite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* $ModDesc: Provides the UNINVITE command which lets users un-invite other users from channels (!) */
15
16 #include "inspircd.h"
17
18 /** Handle /UNINVITE
19  */
20 class CommandUninvite : public Command
21 {
22  public:
23         CommandUninvite (InspIRCd* Instance) : Command(Instance,"UNINVITE", 0, 2)
24         {
25                 this->source = "m_uninvite.so";
26                 syntax = "<nick> <channel>";
27                 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
28         }
29
30         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
31         {
32                 User* u = ServerInstance->FindNick(parameters[0]);
33                 Channel* c = ServerInstance->FindChan(parameters[1]);
34
35                 if ((!c) || (!u))
36                 {
37                         if (!c)
38                         {
39                                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[1].c_str());
40                         }
41                         else
42                         {
43                                 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
44                         }
45
46                         return CMD_FAILURE;
47                 }
48
49                 if (IS_LOCAL(user))
50                 {
51                         if (c->GetStatus(user) < STATUS_HOP)
52                         {
53                                 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator", user->nick.c_str(), c->name.c_str(), c->GetStatus(u) == STATUS_HOP ? "" : "half-");
54                                 return CMD_FAILURE;
55                         }
56                 }
57
58                 irc::string xname(c->name.c_str());
59
60                 if (!u->IsInvited(xname))
61                 {
62                         user->WriteNumeric(505, "%s %s %s :Is not invited to channel %s", user->nick.c_str(), u->nick.c_str(), c->name.c_str(), c->name.c_str());
63                         return CMD_FAILURE;
64                 }
65                 if (!c->HasUser(user))
66                 {
67                         user->WriteNumeric(492, "%s %s :You're not on that channel!",user->nick.c_str(), c->name.c_str());
68                         return CMD_FAILURE;
69                 }
70
71                 u->RemoveInvite(xname);
72                 user->WriteNumeric(494, "%s %s %s :Uninvited", user->nick.c_str(), c->name.c_str(), u->nick.c_str());
73                 u->WriteNumeric(493, "%s :You were uninvited from %s by %s", u->nick.c_str(), c->name.c_str(), user->nick.c_str());
74                 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :*** %s uninvited %s.", c->name.c_str(), user->nick.c_str(), u->nick.c_str());
75
76                 return CMD_SUCCESS;
77         }
78 };
79
80 class ModuleUninvite : public Module
81 {
82         CommandUninvite cmd;
83
84  public:
85
86         ModuleUninvite(InspIRCd* Me) : Module(Me), cmd(Me)
87         {
88                 ServerInstance->AddCommand(&cmd);
89         }
90
91         virtual ~ModuleUninvite()
92         {
93         }
94
95         virtual Version GetVersion()
96         {
97                 return Version("$Id$", VF_VENDOR | VF_COMMON, API_VERSION);
98         }
99 };
100
101 MODULE_INIT(ModuleUninvite)
102