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(const std::vector<std::string> ¶meters, User *user)
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())
55 user->WriteNotice("You do not have access to unset " + ConvToStr(modeletter) + " on " + chan->name + ".");
59 unsigned int prefixrank;
61 std::string pattern = parameters.size() > 2 ? parameters[2] : "*";
63 ListModeBase::ModeList* ml;
64 irc::modestacker modestack(false);
66 if (!mh->IsListMode())
68 if (chan->IsModeSet(mh))
69 modestack.Push(modeletter);
71 else if (((prefixrank = mh->GetPrefixRank()) && (prefixchar = mh->GetPrefix())))
73 // As user prefix modes don't have a GetList() method, let's iterate through the channel's users.
74 for (UserMembIter it = chan->userlist.begin(); it != chan->userlist.end(); ++it)
76 if (!InspIRCd::Match(it->first->nick, pattern))
78 if (((strchr(chan->GetAllPrefixChars(user), prefixchar)) != NULL) && !(it->first == user && prefixrank > VOICE_VALUE))
79 modestack.Push(modeletter, it->first->nick);
82 else if (((lm = dynamic_cast<ListModeBase*>(mh)) != NULL) && ((ml = lm->GetList(chan)) != NULL))
84 for (ListModeBase::ModeList::iterator it = ml->begin(); it != ml->end(); ++it)
86 if (!InspIRCd::Match(it->mask, pattern))
88 modestack.Push(modeletter, it->mask);
93 user->WriteNotice("Could not remove channel mode " + ConvToStr(modeletter));
97 parameterlist stackresult;
98 stackresult.push_back(chan->name);
99 while (modestack.GetStackedLine(stackresult))
101 ServerInstance->Modes->Process(stackresult, user);
102 stackresult.erase(stackresult.begin() + 1, stackresult.end());
109 class ModuleRMode : public Module
114 ModuleRMode() : cmd(this) { }
116 void init() CXX11_OVERRIDE
118 ServerInstance->Modules->AddService(cmd);
121 Version GetVersion() CXX11_OVERRIDE
123 return Version("Allows glob-based removal of list modes", VF_VENDOR);
127 MODULE_INIT(ModuleRMode)