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 if (!ServerInstance->Modes->FindMode(word, MODETYPE_CHANNEL))
34 user->WriteNumeric(955, "%s %s :Mode doesn't exist", chan->name.c_str(), word.c_str());
41 void TellListTooLong(User* user, Channel* chan, std::string &word)
43 user->WriteNumeric(959, "%s %s :Channel exemptchanops list is full", chan->name.c_str(), word.c_str());
46 void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
48 user->WriteNumeric(957, "%s :The word %s is already on the exemptchanops list", chan->name.c_str(), word.c_str());
51 void TellNotSet(User* user, Channel* chan, std::string &word)
53 user->WriteNumeric(958, "%s :No such exemptchanops word is set", chan->name.c_str());
57 class ExemptHandler : public HandlerBase3<ModResult, User*, Channel*, const std::string&>
61 ExemptHandler(Module* me) : ec(me) {}
63 PrefixMode* FindMode(const std::string& mid)
65 if (mid.length() == 1)
66 return ServerInstance->Modes->FindPrefixMode(mid[0]);
68 ModeHandler* mh = ServerInstance->Modes->FindMode(mid, MODETYPE_CHANNEL);
69 return mh ? mh->IsPrefixMode() : NULL;
72 ModResult Call(User* user, Channel* chan, const std::string& restriction)
74 unsigned int mypfx = chan->GetPrefixValue(user);
77 ListModeBase::ModeList* list = ec.GetList(chan);
81 for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); ++i)
83 std::string::size_type pos = (*i).mask.find(':');
84 if (pos == std::string::npos)
86 if (!i->mask.compare(0, pos, restriction))
87 minmode = (*i).mask.substr(pos + 1);
91 PrefixMode* mh = FindMode(minmode);
92 if (mh && mypfx >= mh->GetPrefixRank())
94 if (mh || minmode == "*")
97 return ServerInstance->HandleOnCheckExemption.Call(user, chan, restriction);
101 class ModuleExemptChanOps : public Module
106 ModuleExemptChanOps() : eh(this)
110 void init() CXX11_OVERRIDE
112 ServerInstance->OnCheckExemption = &eh;
115 ~ModuleExemptChanOps()
117 ServerInstance->OnCheckExemption = &ServerInstance->HandleOnCheckExemption;
120 Version GetVersion() CXX11_OVERRIDE
122 return Version("Provides the ability to allow channel operators to be exempt from certain modes.",VF_VENDOR);
125 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
131 MODULE_INIT(ModuleExemptChanOps)