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/>.
23 /** Handles channel mode +X
25 class ExemptChanOps : public ListModeBase
28 ExemptChanOps(Module* Creator) : ListModeBase(Creator, "exemptchanops", 'X', "End of channel exemptchanops list", 954, 953, false, "exemptchanops") { }
30 bool ValidateParam(User* user, Channel* chan, std::string &word)
32 std::string::size_type p = word.find(':');
33 if (p == std::string::npos)
35 user->WriteNumeric(955, chan->name, 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(955, chan->name, restriction, "Unknown restriction");
55 void TellListTooLong(User* user, Channel* chan, std::string &word)
57 user->WriteNumeric(959, chan->name, word, "Channel exemptchanops list is full");
60 void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
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)
67 user->WriteNumeric(958, chan->name, "No such exemptchanops word is set");
71 class ExemptHandler : public HandlerBase3<ModResult, User*, Channel*, const std::string&>
75 ExemptHandler(Module* me) : ec(me) {}
77 PrefixMode* FindMode(const std::string& mid)
79 if (mid.length() == 1)
80 return ServerInstance->Modes->FindPrefixMode(mid[0]);
82 ModeHandler* mh = ServerInstance->Modes->FindMode(mid, MODETYPE_CHANNEL);
83 return mh ? mh->IsPrefixMode() : NULL;
86 ModResult Call(User* user, Channel* chan, const std::string& restriction)
88 unsigned int mypfx = chan->GetPrefixValue(user);
91 ListModeBase::ModeList* list = ec.GetList(chan);
95 for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); ++i)
97 std::string::size_type pos = (*i).mask.find(':');
98 if (pos == std::string::npos)
100 if (!i->mask.compare(0, pos, restriction))
101 minmode.assign(i->mask, pos + 1, std::string::npos);
105 PrefixMode* mh = FindMode(minmode);
106 if (mh && mypfx >= mh->GetPrefixRank())
107 return MOD_RES_ALLOW;
108 if (mh || minmode == "*")
111 return ServerInstance->HandleOnCheckExemption.Call(user, chan, restriction);
115 class ModuleExemptChanOps : public Module
120 ModuleExemptChanOps() : eh(this)
124 void init() CXX11_OVERRIDE
126 ServerInstance->OnCheckExemption = &eh;
129 ~ModuleExemptChanOps()
131 ServerInstance->OnCheckExemption = &ServerInstance->HandleOnCheckExemption;
134 Version GetVersion() CXX11_OVERRIDE
136 return Version("Provides the ability to allow channel operators to be exempt from certain modes.",VF_VENDOR);
139 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
145 MODULE_INIT(ModuleExemptChanOps)