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