]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
Add support for blocking tag messages with the deaf mode.
[user/henk/code/inspircd.git] / src / modules / m_operchans.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2018-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) 2009 Uli Schlachter <psychon@inspircd.org>
9  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2004, 2006, 2010 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
28 enum
29 {
30         // From UnrealIRCd.
31         ERR_CANTJOINOPERSONLY = 520
32 };
33
34 class ModuleOperChans : public Module
35 {
36  private:
37         SimpleChannelModeHandler oc;
38         std::string space;
39         std::string underscore;
40
41  public:
42         ModuleOperChans()
43                 : oc(this, "operonly", 'O', true)
44                 , space(" ")
45                 , underscore("_")
46         {
47         }
48
49         ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
50         {
51                 if (chan && chan->IsModeSet(oc) && !user->IsOper())
52                 {
53                         user->WriteNumeric(ERR_CANTJOINOPERSONLY, chan->name, InspIRCd::Format("Only server operators may join %s (+O is set)", chan->name.c_str()));
54                         return MOD_RES_DENY;
55                 }
56                 return MOD_RES_PASSTHRU;
57         }
58
59         ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask) CXX11_OVERRIDE
60         {
61                 // Check whether the entry is an extban.
62                 if (mask.length() <= 2 || mask[0] != 'O' || mask[1] != ':')
63                         return MOD_RES_PASSTHRU;
64
65                 // If the user is not an oper they can't match this.
66                 if (!user->IsOper())
67                         return MOD_RES_PASSTHRU;
68
69                 // Replace spaces with underscores as they're prohibited in mode parameters.
70                 std::string opername(user->oper->name);
71                 stdalgo::string::replace_all(opername, space, underscore);
72                 if (InspIRCd::Match(opername, mask.substr(2)))
73                         return MOD_RES_DENY;
74
75                 return MOD_RES_PASSTHRU;
76         }
77
78         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
79         {
80                 tokens["EXTBAN"].push_back('O');
81         }
82
83         Version GetVersion() CXX11_OVERRIDE
84         {
85                 return Version("Adds channel mode O (operonly) which prevents non-server operators from joining the channel.", VF_VENDOR);
86         }
87 };
88
89 MODULE_INIT(ModuleOperChans)