2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
31 ERR_CANTJOINOPERSONLY = 520
34 class ModuleOperChans : public Module
37 SimpleChannelModeHandler oc;
39 std::string underscore;
43 : oc(this, "operonly", 'O', true)
49 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
51 if (chan && chan->IsModeSet(oc) && !user->IsOper())
53 user->WriteNumeric(ERR_CANTJOINOPERSONLY, chan->name, InspIRCd::Format("Only server operators may join %s (+O is set)", chan->name.c_str()));
56 return MOD_RES_PASSTHRU;
59 ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask) CXX11_OVERRIDE
61 // Check whether the entry is an extban.
62 if (mask.length() <= 2 || mask[0] != 'O' || mask[1] != ':')
63 return MOD_RES_PASSTHRU;
65 // If the user is not an oper they can't match this.
67 return MOD_RES_PASSTHRU;
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)))
75 return MOD_RES_PASSTHRU;
78 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
80 tokens["EXTBAN"].push_back('O');
83 Version GetVersion() CXX11_OVERRIDE
85 return Version("Adds channel mode O (operonly) which prevents non-server operators from joining the channel.", VF_VENDOR);
89 MODULE_INIT(ModuleOperChans)