2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Robby <robby@chatbelgie.be>
5 * Copyright (C) 2013-2014, 2016 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2013, 2017-2018 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 class CommandRMode : public Command
31 CommandRMode(Module* Creator) : Command(Creator,"RMODE", 2, 3)
33 allow_empty_last_param = false;
34 syntax = "<channel> <mode> [<pattern>]";
37 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
40 Channel* chan = ServerInstance->FindChan(parameters[0]);
41 char modeletter = parameters[1][0];
45 user->WriteNotice("The channel " + parameters[0] + " does not exist.");
49 mh = ServerInstance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
50 if (mh == NULL || parameters[1].size() > 1)
52 user->WriteNotice(parameters[1] + " is not a valid channel mode.");
56 if (chan->GetPrefixValue(user) < mh->GetLevelRequired(false))
58 user->WriteNotice("You do not have access to unset " + ConvToStr(modeletter) + " on " + chan->name + ".");
62 std::string pattern = parameters.size() > 2 ? parameters[2] : "*";
65 ListModeBase::ModeList* ml;
66 Modes::ChangeList changelist;
68 if ((pm = mh->IsPrefixMode()))
70 // As user prefix modes don't have a GetList() method, let's iterate through the channel's users.
71 const Channel::MemberMap& users = chan->GetUsers();
72 for (Channel::MemberMap::const_iterator it = users.begin(); it != users.end(); ++it)
74 if (!InspIRCd::Match(it->first->nick, pattern))
76 if (it->second->HasMode(pm) && !((it->first == user) && (pm->GetPrefixRank() > VOICE_VALUE)))
77 changelist.push_remove(mh, it->first->nick);
80 else if ((lm = mh->IsListModeBase()) && ((ml = lm->GetList(chan)) != NULL))
82 for (ListModeBase::ModeList::iterator it = ml->begin(); it != ml->end(); ++it)
84 if (!InspIRCd::Match(it->mask, pattern))
86 changelist.push_remove(mh, it->mask);
91 if (chan->IsModeSet(mh))
92 changelist.push_remove(mh);
95 ServerInstance->Modes->Process(user, chan, NULL, changelist);
100 class ModuleRMode : public Module
105 ModuleRMode() : cmd(this) { }
107 Version GetVersion() CXX11_OVERRIDE
109 return Version("Allows glob-based removal of list modes", VF_VENDOR);
113 MODULE_INIT(ModuleRMode)