2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "modules/exemption.h"
24 /** Handles channel mode +X
26 class ExemptChanOps : public ListModeBase
29 ExemptChanOps(Module* Creator) : ListModeBase(Creator, "exemptchanops", 'X', "End of channel exemptchanops list", 954, 953, false, "exemptchanops") { }
31 bool ValidateParam(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE {
32 std::string::size_type p = word.find(':');
33 if (p == std::string::npos)
35 user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Invalid exemptchanops entry, format is <restriction>:<prefix>"));
39 std::string restriction(word, 0, p);
40 // If there is a '-' in the restriction string ignore it and everything after it
41 // to support "auditorium-vis" and "auditorium-see" in m_auditorium
42 p = restriction.find('-');
43 if (p != std::string::npos)
46 if (!ServerInstance->Modes->FindMode(restriction, MODETYPE_CHANNEL))
48 user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Unknown restriction"));
55 void TellListTooLong(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE
57 user->WriteNumeric(959, chan->name, word, "Channel exemptchanops list is full");
60 void TellAlreadyOnList(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE
62 user->WriteNumeric(957, chan->name, InspIRCd::Format("The word %s is already on the exemptchanops list", word.c_str()));
65 void TellNotSet(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE
67 user->WriteNumeric(958, chan->name, "No such exemptchanops word is set");
71 class ExemptHandler : public CheckExemption::EventListener
75 ExemptHandler(Module* me)
76 : CheckExemption::EventListener(me)
81 PrefixMode* FindMode(const std::string& mid)
83 if (mid.length() == 1)
84 return ServerInstance->Modes->FindPrefixMode(mid[0]);
86 ModeHandler* mh = ServerInstance->Modes->FindMode(mid, MODETYPE_CHANNEL);
87 return mh ? mh->IsPrefixMode() : NULL;
90 ModResult OnCheckExemption(User* user, Channel* chan, const std::string& restriction) CXX11_OVERRIDE
92 unsigned int mypfx = chan->GetPrefixValue(user);
95 ListModeBase::ModeList* list = ec.GetList(chan);
99 for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); ++i)
101 std::string::size_type pos = (*i).mask.find(':');
102 if (pos == std::string::npos)
104 if (!i->mask.compare(0, pos, restriction))
105 minmode.assign(i->mask, pos + 1, std::string::npos);
109 PrefixMode* mh = FindMode(minmode);
110 if (mh && mypfx >= mh->GetPrefixRank())
111 return MOD_RES_ALLOW;
112 if (mh || minmode == "*")
115 return MOD_RES_PASSTHRU;
119 class ModuleExemptChanOps : public Module
124 ModuleExemptChanOps() : eh(this)
128 Version GetVersion() CXX11_OVERRIDE
130 return Version("Provides the ability to allow channel operators to be exempt from certain modes.",VF_VENDOR);
133 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
139 MODULE_INIT(ModuleExemptChanOps)