]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_classban.cpp
a43a256ec47523c5c9c05d5c61b36675737e048d
[user/henk/code/inspircd.git] / src / modules / m_classban.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2020 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2016 Johanna A <johanna-a@users.noreply.github.com>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22
23 class ModuleClassBan : public Module
24 {
25  private:
26         std::string space;
27         std::string underscore;
28
29  public:
30         ModuleClassBan()
31                 : space(" ")
32                 , underscore("_")
33         {
34         }
35
36         ModResult OnCheckBan(User* user, Channel* c, const std::string& mask) CXX11_OVERRIDE
37         {
38                 LocalUser* localUser = IS_LOCAL(user);
39                 if ((localUser) && (mask.length() > 2) && (mask[0] == 'n') && (mask[1] == ':'))
40                 {
41                         // Replace spaces with underscores as they're prohibited in mode parameters.
42                         std::string classname(localUser->GetClass()->name);
43                         stdalgo::string::replace_all(classname, space, underscore);
44                         if (InspIRCd::Match(classname, mask.substr(2)))
45                                 return MOD_RES_DENY;
46
47                 }
48                 return MOD_RES_PASSTHRU;
49         }
50
51         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
52         {
53                 tokens["EXTBAN"].push_back('n');
54         }
55
56         Version GetVersion() CXX11_OVERRIDE
57         {
58                 return Version("Adds extended ban n: which check whether users are in a connect class matching the specified glob pattern.", VF_VENDOR | VF_OPTCOMMON);
59         }
60 };
61
62 MODULE_INIT(ModuleClassBan)