]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_allowinvite.cpp
Remove $Core and $Mod* comments apart from $ModDep.
[user/henk/code/inspircd.git] / src / modules / m_allowinvite.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21
22 class AllowInvite : public SimpleChannelModeHandler
23 {
24  public:
25         AllowInvite(Module* Creator) : SimpleChannelModeHandler(Creator, "allowinvite", 'A') { }
26 };
27
28 class ModuleAllowInvite : public Module
29 {
30         AllowInvite ni;
31  public:
32
33         ModuleAllowInvite() : ni(this)
34         {
35         }
36
37         void init() CXX11_OVERRIDE
38         {
39                 ServerInstance->Modules->AddService(ni);
40                 Implementation eventlist[] = { I_OnUserPreInvite, I_On005Numeric };
41                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
42         }
43
44         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
45         {
46                 tokens["EXTBAN"].push_back('A');
47         }
48
49         ModResult OnUserPreInvite(User* user,User* dest,Channel* channel, time_t timeout) CXX11_OVERRIDE
50         {
51                 if (IS_LOCAL(user))
52                 {
53                         ModResult res = channel->GetExtBanStatus(user, 'A');
54                         if (res == MOD_RES_DENY)
55                         {
56                                 // Matching extban, explicitly deny /invite
57                                 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You are banned from using INVITE", user->nick.c_str(), channel->name.c_str());
58                                 return res;
59                         }
60                         if (channel->IsModeSet(ni) || res == MOD_RES_ALLOW)
61                         {
62                                 // Explicitly allow /invite
63                                 return MOD_RES_ALLOW;
64                         }
65                 }
66
67                 return MOD_RES_PASSTHRU;
68         }
69
70         Version GetVersion() CXX11_OVERRIDE
71         {
72                 return Version("Provides support for channel mode +A, allowing /invite freely on a channel and extban A to deny specific users it",VF_VENDOR);
73         }
74 };
75
76 MODULE_INIT(ModuleAllowInvite)