]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_mlock.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_mlock.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2017 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
6  *   Copyright (C) 2012, 2014-2015 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012 Ariadne Conill <ariadne@dereferenced.org>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #include "inspircd.h"
24
25 enum
26 {
27         // From Charybdis.
28         ERR_MLOCKRESTRICTED = 742
29 };
30
31 class ModuleMLock : public Module
32 {
33         StringExtItem mlock;
34
35  public:
36         ModuleMLock()
37                 : mlock("mlock", ExtensionItem::EXT_CHANNEL, this)
38         {
39         }
40
41         Version GetVersion() CXX11_OVERRIDE
42         {
43                 return Version("Allows services to lock channel modes so that they can not be changed.", VF_VENDOR);
44         }
45
46         ModResult OnRawMode(User* source, Channel* channel, ModeHandler* mh, const std::string& parameter, bool adding) CXX11_OVERRIDE
47         {
48                 if (!channel)
49                         return MOD_RES_PASSTHRU;
50
51                 if (!IS_LOCAL(source))
52                         return MOD_RES_PASSTHRU;
53
54                 std::string *mlock_str = mlock.get(channel);
55                 if (!mlock_str)
56                         return MOD_RES_PASSTHRU;
57
58                 const char mode = mh->GetModeChar();
59                 std::string::size_type p = mlock_str->find(mode);
60                 if (p != std::string::npos)
61                 {
62                         source->WriteNumeric(ERR_MLOCKRESTRICTED, channel->name, mode, *mlock_str, "MODE cannot be set due to the channel having an active MLOCK restriction policy");
63                         return MOD_RES_DENY;
64                 }
65
66                 return MOD_RES_PASSTHRU;
67         }
68 };
69
70 MODULE_INIT(ModuleMLock)