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 // TODO actually make sure there's a prop for this
33 if ((word.length() > 35) || (word.empty()))
35 user->WriteNumeric(955, "%s %s %s :word is too %s for exemptchanops list",user->nick.c_str(), chan->name.c_str(), word.c_str(), (word.empty() ? "short" : "long"));
42 void TellListTooLong(User* user, Channel* chan, std::string &word)
44 user->WriteNumeric(959, "%s %s %s :Channel exemptchanops list is full", user->nick.c_str(), chan->name.c_str(), word.c_str());
47 void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
49 user->WriteNumeric(957, "%s %s :The word %s is already on the exemptchanops list",user->nick.c_str(), chan->name.c_str(), word.c_str());
52 void TellNotSet(User* user, Channel* chan, std::string &word)
54 user->WriteNumeric(958, "%s %s :No such exemptchanops word is set",user->nick.c_str(), chan->name.c_str());
58 class ExemptHandler : public HandlerBase3<ModResult, User*, Channel*, const std::string&>
62 ExemptHandler(Module* me) : ec(me) {}
64 PrefixMode* FindMode(const std::string& mid)
66 if (mid.length() == 1)
67 return ServerInstance->Modes->FindPrefixMode(mid[0]);
69 const ModeParser::PrefixModeList& pmlist = ServerInstance->Modes->GetPrefixModes();
70 for (ModeParser::PrefixModeList::const_iterator i = pmlist.begin(); i != pmlist.end(); ++i)
79 ModResult Call(User* user, Channel* chan, const std::string& restriction)
81 unsigned int mypfx = chan->GetPrefixValue(user);
84 ListModeBase::ModeList* list = ec.GetList(chan);
88 for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); ++i)
90 std::string::size_type pos = (*i).mask.find(':');
91 if (pos == std::string::npos)
93 if ((*i).mask.substr(0,pos) == restriction)
94 minmode = (*i).mask.substr(pos + 1);
98 PrefixMode* mh = FindMode(minmode);
99 if (mh && mypfx >= mh->GetPrefixRank())
100 return MOD_RES_ALLOW;
101 if (mh || minmode == "*")
104 return ServerInstance->HandleOnCheckExemption.Call(user, chan, restriction);
108 class ModuleExemptChanOps : public Module
110 std::string defaults;
114 ModuleExemptChanOps() : eh(this)
118 void init() CXX11_OVERRIDE
120 ServerInstance->OnCheckExemption = &eh;
123 ~ModuleExemptChanOps()
125 ServerInstance->OnCheckExemption = &ServerInstance->HandleOnCheckExemption;
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
138 void OnSyncChannel(Channel* chan, Module* proto, void* opaque) CXX11_OVERRIDE
140 eh.ec.DoSyncChannel(chan, proto, opaque);
144 MODULE_INIT(ModuleExemptChanOps)