X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_operchans.cpp;h=9e30ceca2a95dc6a9b72a38ff7dc696728bedb5f;hb=dcafba95960685120b1f6d902de623ca10ed6135;hp=8484d7dcc25cc658362d4d63768b5db0330a1b4e;hpb=87b1461e2a4710a38b32186c2582da9fe9bb3804;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_operchans.cpp b/src/modules/m_operchans.cpp index 8484d7dcc..9e30ceca2 100644 --- a/src/modules/m_operchans.cpp +++ b/src/modules/m_operchans.cpp @@ -1,10 +1,13 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2013, 2018-2020 Sadie Powell + * Copyright (C) 2012-2013 Attila Molnar + * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2009-2010 Daniel De Graaf + * Copyright (C) 2009 Uli Schlachter * Copyright (C) 2007 Dennis Friis - * Copyright (C) 2007 Robin Burchell - * Copyright (C) 2004, 2006 Craig Edwards + * Copyright (C) 2004, 2006, 2010 Craig Edwards * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -28,21 +31,18 @@ enum ERR_CANTJOINOPERSONLY = 520 }; -class OperChans : public SimpleChannelModeHandler -{ - public: - /* This is an oper-only mode */ - OperChans(Module* Creator) : SimpleChannelModeHandler(Creator, "operonly", 'O') - { - oper = true; - } -}; - class ModuleOperChans : public Module { - OperChans oc; + private: + SimpleChannelModeHandler oc; + std::string space; + std::string underscore; + public: - ModuleOperChans() : oc(this) + ModuleOperChans() + : oc(this, "operonly", 'O', true) + , space(" ") + , underscore("_") { } @@ -56,13 +56,22 @@ class ModuleOperChans : public Module return MOD_RES_PASSTHRU; } - ModResult OnCheckBan(User *user, Channel *c, const std::string& mask) CXX11_OVERRIDE + ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask) CXX11_OVERRIDE { - if ((mask.length() > 2) && (mask[0] == 'O') && (mask[1] == ':')) - { - if (user->IsOper() && InspIRCd::Match(user->oper->name, mask.substr(2))) - return MOD_RES_DENY; - } + // Check whether the entry is an extban. + if (mask.length() <= 2 || mask[0] != 'O' || mask[1] != ':') + return MOD_RES_PASSTHRU; + + // If the user is not an oper they can't match this. + if (!user->IsOper()) + return MOD_RES_PASSTHRU; + + // Replace spaces with underscores as they're prohibited in mode parameters. + std::string opername(user->oper->name); + stdalgo::string::replace_all(opername, space, underscore); + if (InspIRCd::Match(opername, mask.substr(2))) + return MOD_RES_DENY; + return MOD_RES_PASSTHRU; } @@ -73,7 +82,7 @@ class ModuleOperChans : public Module Version GetVersion() CXX11_OVERRIDE { - return Version("Provides support for oper-only channels via channel mode +O and extban 'O'", VF_VENDOR); + return Version("Adds channel mode O (operonly) which prevents non-server operators from joining the channel.", VF_VENDOR); } };