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/>.
23 /* $ModDesc: Provides support for the RMODE command - Makes mass removal of chan listmodes by glob pattern possible */
27 class CommandRMode : public Command
30 CommandRMode(Module* Creator) : Command(Creator,"RMODE", 2, 3)
32 allow_empty_last_param = false;
33 syntax = "<channel> <mode> [pattern]";
36 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
39 Channel* chan = ServerInstance->FindChan(parameters[0]);
40 char modeletter = parameters[1][0];
44 user->WriteNotice("The channel " + parameters[0] + " does not exist.");
48 mh = ServerInstance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
49 if (mh == NULL || parameters[1].size() > 1)
51 user->WriteNotice(parameters[1] + " is not a valid channel mode.");
55 if (chan->GetPrefixValue(user) < mh->GetLevelRequired())
57 user->WriteNotice("You do not have access to unset " + ConvToStr(modeletter) + " on " + chan->name + ".");
61 unsigned int prefixrank;
63 std::string pattern = parameters.size() > 2 ? parameters[2] : "*";
65 ListModeBase::ModeList* ml;
66 irc::modestacker modestack(false);
68 if (!mh->IsListMode())
70 if (chan->IsModeSet(modeletter))
71 modestack.Push(modeletter);
73 else if (((prefixrank = mh->GetPrefixRank()) && (prefixchar = mh->GetPrefix())))
75 // As user prefix modes don't have a GetList() method, let's iterate through the channel's users.
76 for (UserMembIter it = chan->userlist.begin(); it != chan->userlist.end(); ++it)
78 if (!InspIRCd::Match(it->first->nick, pattern))
80 if (((strchr(chan->GetAllPrefixChars(user), prefixchar)) != NULL) && !(it->first == user && prefixrank > VOICE_VALUE))
81 modestack.Push(modeletter, it->first->nick);
84 else if (((lm = dynamic_cast<ListModeBase*>(mh)) != NULL) && ((ml = lm->GetList(chan)) != NULL))
86 for (ListModeBase::ModeList::iterator it = ml->begin(); it != ml->end(); ++it)
88 if (!InspIRCd::Match(it->mask, pattern))
90 modestack.Push(modeletter, it->mask);
95 user->WriteNotice("Could not remove channel mode " + ConvToStr(modeletter));
99 parameterlist stackresult;
100 stackresult.push_back(chan->name);
101 while (modestack.GetStackedLine(stackresult))
103 ServerInstance->SendMode(stackresult, user);
104 stackresult.erase(stackresult.begin() + 1, stackresult.end());
111 class ModuleRMode : public Module
116 ModuleRMode() : cmd(this) { }
118 void init() CXX11_OVERRIDE
120 ServerInstance->Modules->AddService(cmd);
123 Version GetVersion() CXX11_OVERRIDE
125 return Version("Allows glob-based removal of list modes", VF_VENDOR);
129 MODULE_INIT(ModuleRMode)