X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_exemptchanops.cpp;h=ba5b7696732abb2a31bf6bfce453a2b498ff997a;hb=e2b0f3dc9ef4d56c71d7abda13e6139ca092e387;hp=411d0dd1568113f77f552ce3fb84d52dbe6ff411;hpb=a5b9f37d62670a49e81c5a53f93bdf485aace4a6;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_exemptchanops.cpp b/src/modules/m_exemptchanops.cpp index 411d0dd15..ba5b76967 100644 --- a/src/modules/m_exemptchanops.cpp +++ b/src/modules/m_exemptchanops.cpp @@ -1,6 +1,10 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2013-2015 Attila Molnar + * Copyright (C) 2013, 2017-2020 Sadie Powell + * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2010 Craig Edwards * Copyright (C) 2009-2010 Daniel De Graaf * * This file is part of InspIRCd. InspIRCd is free software: you can @@ -21,45 +25,90 @@ #include "listmode.h" #include "modules/exemption.h" -/** Handles channel mode +X - */ +enum +{ + RPL_ENDOFEXEMPTIONLIST = 953, + RPL_EXEMPTIONLIST = 954 +}; + class ExemptChanOps : public ListModeBase { public: - ExemptChanOps(Module* Creator) : ListModeBase(Creator, "exemptchanops", 'X', "End of channel exemptchanops list", 954, 953, false, "exemptchanops") { } + ExemptChanOps(Module* Creator) + : ListModeBase(Creator, "exemptchanops", 'X', "End of channel exemptchanops list", RPL_EXEMPTIONLIST, RPL_ENDOFEXEMPTIONLIST, false) + { + syntax = ":"; + } + + static PrefixMode* FindMode(const std::string& mode) + { + if (mode.length() == 1) + return ServerInstance->Modes->FindPrefixMode(mode[0]); + + ModeHandler* mh = ServerInstance->Modes->FindMode(mode, MODETYPE_CHANNEL); + return mh ? mh->IsPrefixMode() : NULL; + } + + static bool ParseEntry(const std::string& entry, std::string& restriction, std::string& prefix) + { + // The entry must be in the format :. + std::string::size_type colon = entry.find(':'); + if (colon == std::string::npos || colon == entry.length()-1) + return false; + + restriction.assign(entry, 0, colon); + prefix.assign(entry, colon + 1, std::string::npos); + return true; + } + + ModResult AccessCheck(User* source, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE + { + std::string restriction; + std::string prefix; + if (!ParseEntry(parameter, restriction, prefix)) + return MOD_RES_PASSTHRU; + + PrefixMode* pm = FindMode(prefix); + if (!pm) + return MOD_RES_PASSTHRU; - bool ValidateParam(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE { - std::string::size_type p = word.find(':'); - if (p == std::string::npos) + if (channel->GetPrefixValue(source) >= pm->GetLevelRequired(adding)) + return MOD_RES_PASSTHRU; + + source->WriteNumeric(ERR_CHANOPRIVSNEEDED, channel->name, InspIRCd::Format("You must be able to %s mode %c (%s) to %s a restriction containing it", + adding ? "set" : "unset", pm->GetModeChar(), pm->name.c_str(), adding ? "add" : "remove")); + return MOD_RES_DENY; + } + + bool ValidateParam(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE + { + std::string restriction; + std::string prefix; + if (!ParseEntry(word, restriction, prefix)) { - user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Invalid exemptchanops entry, format is :")); + user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word)); return false; } - std::string restriction(word, 0, p); // If there is a '-' in the restriction string ignore it and everything after it // to support "auditorium-vis" and "auditorium-see" in m_auditorium - p = restriction.find('-'); - if (p != std::string::npos) - restriction.erase(p); + std::string::size_type dash = restriction.find('-'); + if (dash != std::string::npos) + restriction.erase(dash); if (!ServerInstance->Modes->FindMode(restriction, MODETYPE_CHANNEL)) { - user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Unknown restriction")); + user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Unknown restriction.")); return false; } - return true; - } - - void TellAlreadyOnList(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE - { - user->WriteNumeric(957, chan->name, InspIRCd::Format("The word %s is already on the exemptchanops list", word.c_str())); - } + if (prefix != "*" && !FindMode(prefix)) + { + user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Unknown prefix mode.")); + return false; + } - void TellNotSet(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE - { - user->WriteNumeric(958, chan->name, "No such exemptchanops word is set"); + return true; } }; @@ -73,15 +122,6 @@ class ExemptHandler : public CheckExemption::EventListener { } - PrefixMode* FindMode(const std::string& mid) - { - if (mid.length() == 1) - return ServerInstance->Modes->FindPrefixMode(mid[0]); - - ModeHandler* mh = ServerInstance->Modes->FindMode(mid, MODETYPE_CHANNEL); - return mh ? mh->IsPrefixMode() : NULL; - } - ModResult OnCheckExemption(User* user, Channel* chan, const std::string& restriction) CXX11_OVERRIDE { unsigned int mypfx = chan->GetPrefixValue(user); @@ -101,7 +141,7 @@ class ExemptHandler : public CheckExemption::EventListener } } - PrefixMode* mh = FindMode(minmode); + PrefixMode* mh = ExemptChanOps::FindMode(minmode); if (mh && mypfx >= mh->GetPrefixRank()) return MOD_RES_ALLOW; if (mh || minmode == "*") @@ -122,7 +162,7 @@ class ModuleExemptChanOps : public Module Version GetVersion() CXX11_OVERRIDE { - return Version("Provides the ability to allow channel operators to be exempt from certain modes.",VF_VENDOR); + return Version("Adds channel mode X (exemptchanops) which allows channel operators to grant exemptions to various channel-level restrictions.", VF_VENDOR); } void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE