]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
Update copyright headers.
[user/henk/code/inspircd.git] / src / modules / m_inviteexception.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2017-2020 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012-2013 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
9  *   Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
10  *
11  * This file is part of InspIRCd.  InspIRCd is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation, version 2.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  */
23
24
25 #include "inspircd.h"
26 #include "listmode.h"
27
28 enum
29 {
30         // From RFC 2812.
31         RPL_INVEXLIST = 346,
32         RPL_ENDOFINVEXLIST = 347
33 };
34
35 class InviteException : public ListModeBase
36 {
37  public:
38         InviteException(Module* Creator)
39                 : ListModeBase(Creator, "invex", 'I', "End of Channel Invite Exception List", RPL_INVEXLIST, RPL_ENDOFINVEXLIST, true)
40         {
41                 syntax = "<mask>";
42         }
43 };
44
45 class ModuleInviteException : public Module
46 {
47         bool invite_bypass_key;
48         InviteException ie;
49 public:
50         ModuleInviteException() : ie(this)
51         {
52         }
53
54         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
55         {
56                 tokens["INVEX"] = ConvToStr(ie.GetModeChar());
57         }
58
59         ModResult OnCheckInvite(User* user, Channel* chan) CXX11_OVERRIDE
60         {
61                 ListModeBase::ModeList* list = ie.GetList(chan);
62                 if (list)
63                 {
64                         for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
65                         {
66                                 if (chan->CheckBan(user, it->mask))
67                                 {
68                                         return MOD_RES_ALLOW;
69                                 }
70                         }
71                 }
72
73                 return MOD_RES_PASSTHRU;
74         }
75
76         ModResult OnCheckKey(User* user, Channel* chan, const std::string& key) CXX11_OVERRIDE
77         {
78                 if (invite_bypass_key)
79                         return OnCheckInvite(user, chan);
80                 return MOD_RES_PASSTHRU;
81         }
82
83         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
84         {
85                 ie.DoRehash();
86                 invite_bypass_key = ServerInstance->Config->ConfValue("inviteexception")->getBool("bypasskey", true);
87         }
88
89         Version GetVersion() CXX11_OVERRIDE
90         {
91                 return Version("Adds channel mode I (invex) which allows channel operators to exempt user masks from the i (inviteonly) channel mode.", VF_VENDOR);
92         }
93 };
94
95 MODULE_INIT(ModuleInviteException)