2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013 Daniel Vassdal <shutter@canternet.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/>.
25 class CommandRMode : public Command
28 CommandRMode(Module* Creator) : Command(Creator,"RMODE", 2, 3)
30 allow_empty_last_param = false;
31 syntax = "<channel> <mode> [<pattern>]";
34 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
37 Channel* chan = ServerInstance->FindChan(parameters[0]);
38 char modeletter = parameters[1][0];
42 user->WriteNotice("The channel " + parameters[0] + " does not exist.");
46 mh = ServerInstance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
47 if (mh == NULL || parameters[1].size() > 1)
49 user->WriteNotice(parameters[1] + " is not a valid channel mode.");
53 if (chan->GetPrefixValue(user) < mh->GetLevelRequired(false))
55 user->WriteNotice("You do not have access to unset " + ConvToStr(modeletter) + " on " + chan->name + ".");
59 std::string pattern = parameters.size() > 2 ? parameters[2] : "*";
62 ListModeBase::ModeList* ml;
63 Modes::ChangeList changelist;
65 if ((pm = mh->IsPrefixMode()))
67 // As user prefix modes don't have a GetList() method, let's iterate through the channel's users.
68 const Channel::MemberMap& users = chan->GetUsers();
69 for (Channel::MemberMap::const_iterator it = users.begin(); it != users.end(); ++it)
71 if (!InspIRCd::Match(it->first->nick, pattern))
73 if (it->second->HasMode(pm) && !((it->first == user) && (pm->GetPrefixRank() > VOICE_VALUE)))
74 changelist.push_remove(mh, it->first->nick);
77 else if ((lm = mh->IsListModeBase()) && ((ml = lm->GetList(chan)) != NULL))
79 for (ListModeBase::ModeList::iterator it = ml->begin(); it != ml->end(); ++it)
81 if (!InspIRCd::Match(it->mask, pattern))
83 changelist.push_remove(mh, it->mask);
88 if (chan->IsModeSet(mh))
89 changelist.push_remove(mh);
92 ServerInstance->Modes->Process(user, chan, NULL, changelist);
97 class ModuleRMode : public Module
102 ModuleRMode() : cmd(this) { }
104 Version GetVersion() CXX11_OVERRIDE
106 return Version("Allows glob-based removal of list modes", VF_VENDOR);
110 MODULE_INIT(ModuleRMode)