]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_banexception.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) 2008 Robin Burchell <robin+git@viroteck.net>
9  *   Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2006-2007 Craig Edwards <brain@inspircd.org>
11  *   Copyright (C) 2006 Oliver Lupton <om@inspircd.org>
12  *
13  * This file is part of InspIRCd.  InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26
27 #include "inspircd.h"
28 #include "listmode.h"
29
30 enum
31 {
32         // From RFC 2812.
33         RPL_EXCEPTLIST = 348,
34         RPL_ENDOFEXCEPTLIST = 349
35 };
36
37 class BanException : public ListModeBase
38 {
39  public:
40         BanException(Module* Creator)
41                 : ListModeBase(Creator, "banexception", 'e', "End of Channel Exception List", RPL_EXCEPTLIST, RPL_ENDOFEXCEPTLIST, true)
42         {
43                 syntax = "<mask>";
44         }
45 };
46
47 class ModuleBanException : public Module
48 {
49         BanException be;
50
51  public:
52         ModuleBanException() : be(this)
53         {
54         }
55
56         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
57         {
58                 tokens["EXCEPTS"] = ConvToStr(be.GetModeChar());
59         }
60
61         ModResult OnExtBanCheck(User *user, Channel *chan, char type) CXX11_OVERRIDE
62         {
63                 ListModeBase::ModeList* list = be.GetList(chan);
64                 if (!list)
65                         return MOD_RES_PASSTHRU;
66
67                 for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
68                 {
69                         if (it->mask.length() <= 2 || it->mask[0] != type || it->mask[1] != ':')
70                                 continue;
71
72                         if (chan->CheckBan(user, it->mask.substr(2)))
73                         {
74                                 // They match an entry on the list, so let them pass this.
75                                 return MOD_RES_ALLOW;
76                         }
77                 }
78
79                 return MOD_RES_PASSTHRU;
80         }
81
82         ModResult OnCheckChannelBan(User* user, Channel* chan) CXX11_OVERRIDE
83         {
84                 ListModeBase::ModeList* list = be.GetList(chan);
85                 if (!list)
86                 {
87                         // No list, proceed normally
88                         return MOD_RES_PASSTHRU;
89                 }
90
91                 for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
92                 {
93                         if (chan->CheckBan(user, it->mask))
94                         {
95                                 // They match an entry on the list, so let them in.
96                                 return MOD_RES_ALLOW;
97                         }
98                 }
99                 return MOD_RES_PASSTHRU;
100         }
101
102         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
103         {
104                 be.DoRehash();
105         }
106
107         Version GetVersion() CXX11_OVERRIDE
108         {
109                 return Version("Adds channel mode e (banexception) which allows channel operators to exempt user masks from the b (ban) channel mode.", VF_VENDOR);
110         }
111 };
112
113 MODULE_INIT(ModuleBanException)