summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/conf/helpop-full.conf.example5
-rw-r--r--docs/conf/modules.conf.example7
-rw-r--r--src/modules/m_rmode.cpp129
3 files changed, 141 insertions, 0 deletions
diff --git a/docs/conf/helpop-full.conf.example b/docs/conf/helpop-full.conf.example
index ffd3761be..c972d04dd 100644
--- a/docs/conf/helpop-full.conf.example
+++ b/docs/conf/helpop-full.conf.example
@@ -97,6 +97,11 @@ Removes a user from a channel you specify. You must be at least a
channel halfoperator to remove a user. A removed user will part with
a message stating they were removed from the channel and by whom.">
+<helpop key="rmode" value="/RMODE [channel] [modeletter] {[pattern]}
+
+Removes listmodes from a channel.
+E.g. /RMODE #Chan b m:* will remove all mute extbans.">
+
<helpop key="fpart" value="/FPART [channel] [nick] {[reason]}
This behaves identically to /REMOVE, the only difference is that that
diff --git a/docs/conf/modules.conf.example b/docs/conf/modules.conf.example
index 6d0c2cbdb..d5a5d24c1 100644
--- a/docs/conf/modules.conf.example
+++ b/docs/conf/modules.conf.example
@@ -1463,6 +1463,13 @@
# so that at least \s or [[:space:]] is available.
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
+# RMODE module: Adds the /RMODE command
+# Allows channel mods to remove list modes en masse.
+# Syntax: /rmode <channel> <mode> [pattern]
+# E.g. '/rmode #Channel b m:*' will remove all mute-extbans on the channel.
+#<module name="m_rmode.so">
+
+#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# SAJOIN module: Adds the /SAJOIN command
# This module is oper-only.
# To use, SAJOIN must be in one of your oper class blocks.
diff --git a/src/modules/m_rmode.cpp b/src/modules/m_rmode.cpp
new file mode 100644
index 000000000..7b7c66da2
--- /dev/null
+++ b/src/modules/m_rmode.cpp
@@ -0,0 +1,129 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
+ *
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "inspircd.h"
+#include "listmode.h"
+
+/* $ModDesc: Provides support for the RMODE command - Makes mass removal of chan listmodes by glob pattern possible */
+
+/** Handle /RMODE
+ */
+class CommandRMode : public Command
+{
+ public:
+ CommandRMode(Module* Creator) : Command(Creator,"RMODE", 2, 3)
+ {
+ allow_empty_last_param = false;
+ syntax = "<channel> <mode> [pattern]";
+ }
+
+ CmdResult Handle(const std::vector<std::string> &parameters, User *user)
+ {
+ ModeHandler* mh;
+ Channel* chan = ServerInstance->FindChan(parameters[0]);
+ char modeletter = parameters[1][0];
+
+ if (chan == NULL)
+ {
+ user->WriteServ("NOTICE %s :The channel %s does not exist.", user->nick.c_str(), parameters[0].c_str());
+ return CMD_FAILURE;
+ }
+
+ mh = ServerInstance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
+ if (mh == NULL || parameters[1].size() > 1)
+ {
+ user->WriteServ("NOTICE %s :%s is not a valid channel mode.", user->nick.c_str(), parameters[1].c_str());
+ return CMD_FAILURE;
+ }
+
+ if (chan->GetPrefixValue(user) < mh->GetLevelRequired())
+ {
+ user->WriteServ("NOTICE %s :You do not have access to unset %c on %s.", user->nick.c_str(), modeletter, chan->name.c_str());
+ return CMD_FAILURE;
+ }
+
+ unsigned int prefixrank;
+ char prefixchar;
+ std::string pattern = parameters.size() > 2 ? parameters[2] : "*";
+ ListModeBase* lm;
+ ListModeBase::ModeList* ml;
+ irc::modestacker modestack(false);
+
+ if (!mh->IsListMode())
+ {
+ if (chan->IsModeSet(modeletter))
+ modestack.Push(modeletter);
+ }
+ else if (((prefixrank = mh->GetPrefixRank()) && (prefixchar = mh->GetPrefix())))
+ {
+ // As user prefix modes don't have a GetList() method, let's iterate through the channel's users.
+ for (UserMembIter it = chan->userlist.begin(); it != chan->userlist.end(); ++it)
+ {
+ if (!InspIRCd::Match(it->first->nick, pattern))
+ continue;
+ if (((strchr(chan->GetAllPrefixChars(user), prefixchar)) != NULL) && !(it->first == user && prefixrank > VOICE_VALUE))
+ modestack.Push(modeletter, it->first->nick);
+ }
+ }
+ else if (((lm = dynamic_cast<ListModeBase*>(mh)) != NULL) && ((ml = lm->GetList(chan)) != NULL))
+ {
+ for (ListModeBase::ModeList::iterator it = ml->begin(); it != ml->end(); ++it)
+ {
+ if (!InspIRCd::Match(it->mask, pattern))
+ continue;
+ modestack.Push(modeletter, it->mask);
+ }
+ }
+ else
+ {
+ user->WriteServ("NOTICE %s :Could not remove channel mode %c", user->nick.c_str(), modeletter);
+ return CMD_FAILURE;
+ }
+
+ parameterlist stackresult;
+ stackresult.push_back(chan->name);
+ while (modestack.GetStackedLine(stackresult))
+ {
+ ServerInstance->SendMode(stackresult, user);
+ stackresult.erase(stackresult.begin() + 1, stackresult.end());
+ }
+
+ return CMD_SUCCESS;
+ }
+};
+
+class ModuleRMode : public Module
+{
+ CommandRMode cmd;
+
+ public:
+ ModuleRMode() : cmd(this) { }
+
+ void init()
+ {
+ ServerInstance->Modules->AddService(cmd);
+ }
+
+ Version GetVersion()
+ {
+ return Version("Allows glob-based removal of list modes", VF_VENDOR);
+ }
+};
+
+MODULE_INIT(ModuleRMode)