summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2017-10-20 06:24:19 +0100
committerPeter Powell <petpow@saberuk.com>2017-11-06 10:55:56 +0000
commit8281315255d30d7cad6da4936cf9276b7f58a4dc (patch)
tree4e2f6a1293c87037a69a9219154d4a5e05ad7dd1
parent257bf752fc6b87fa35bfa8cf95fc37730c3d55c6 (diff)
Move depriv from m_customprefix into PrefixMode.
-rw-r--r--include/builtinmodes.h1
-rw-r--r--include/mode.h19
-rw-r--r--src/mode.cpp11
-rw-r--r--src/modules/m_customprefix.cpp10
4 files changed, 31 insertions, 10 deletions
diff --git a/include/builtinmodes.h b/include/builtinmodes.h
index 922a86f0e..49198b650 100644
--- a/include/builtinmodes.h
+++ b/include/builtinmodes.h
@@ -78,6 +78,7 @@ class ModeChannelVoice : public PrefixMode
ModeChannelVoice()
: PrefixMode(NULL, "voice", 'v', VOICE_VALUE, '+')
{
+ selfremove = false;
ranktoset = ranktounset = HALFOP_VALUE;
}
};
diff --git a/include/mode.h b/include/mode.h
index 5cfbe4015..30b28a6b0 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -359,6 +359,9 @@ class CoreExport PrefixMode : public ModeHandler
*/
unsigned int prefixrank;
+ /** Whether a client with this prefix can remove it from themself. */
+ bool selfremove;
+
public:
/**
* Constructor
@@ -371,6 +374,16 @@ class CoreExport PrefixMode : public ModeHandler
PrefixMode(Module* Creator, const std::string& Name, char ModeLetter, unsigned int Rank = 0, char PrefixChar = 0);
/**
+ * Called when a channel mode change access check for your mode occurs.
+ * @param source Contains the user setting the mode.
+ * @param channel contains the destination channel the modes are being set on.
+ * @param parameter The parameter for your mode. This is modifiable.
+ * @param adding This value is true when the mode is being set, or false when it is being unset.
+ * @return allow, deny, or passthru to check against the required level
+ */
+ ModResult AccessCheck(User* source, Channel* channel, std::string &parameter, bool adding) CXX11_OVERRIDE;
+
+ /**
* Handles setting and unsetting the prefix mode.
* Finds the given member of the given channel, if it's not found an error message is sent to 'source'
* and MODEACTION_DENY is returned. Otherwise the mode change is attempted.
@@ -392,6 +405,12 @@ class CoreExport PrefixMode : public ModeHandler
*/
void RemoveMode(Channel* channel, Modes::ChangeList& changelist);
+
+ /**
+ * Determines whether a user with this prefix mode can remove it.
+ */
+ bool CanSelfRemove() const { return selfremove; }
+
/**
* Mode prefix or 0. If this is defined, you should
* also implement GetPrefixRank() to return an integer
diff --git a/src/mode.cpp b/src/mode.cpp
index cff625c46..fd25a9a9f 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -162,11 +162,20 @@ void ModeWatcher::AfterMode(User*, User*, Channel*, const std::string&, bool)
PrefixMode::PrefixMode(Module* Creator, const std::string& Name, char ModeLetter, unsigned int Rank, char PrefixChar)
: ModeHandler(Creator, Name, ModeLetter, PARAM_ALWAYS, MODETYPE_CHANNEL, MC_PREFIX)
- , prefix(PrefixChar), prefixrank(Rank)
+ , prefix(PrefixChar)
+ , prefixrank(Rank)
+ , selfremove(true)
{
list = true;
}
+ModResult PrefixMode::AccessCheck(User* src, Channel*, std::string& value, bool adding)
+{
+ if (!adding && src->nick == value && selfremove)
+ return MOD_RES_ALLOW;
+ return MOD_RES_PASSTHRU;
+}
+
ModeAction PrefixMode::OnModeChange(User* source, User*, Channel* chan, std::string& parameter, bool adding)
{
User* target;
diff --git a/src/modules/m_customprefix.cpp b/src/modules/m_customprefix.cpp
index 1be9676b5..7e162c72a 100644
--- a/src/modules/m_customprefix.cpp
+++ b/src/modules/m_customprefix.cpp
@@ -23,7 +23,6 @@ class CustomPrefixMode : public PrefixMode
{
public:
reference<ConfigTag> tag;
- bool depriv;
CustomPrefixMode(Module* parent, ConfigTag* Tag)
: PrefixMode(parent, Tag->getString("name"), 0, Tag->getInt("rank"))
@@ -35,14 +34,7 @@ class CustomPrefixMode : public PrefixMode
mode = v.c_str()[0];
ranktoset = tag->getInt("ranktoset", prefixrank, prefixrank, UINT_MAX);
ranktounset = tag->getInt("ranktounset", ranktoset, ranktoset, UINT_MAX);
- depriv = tag->getBool("depriv", true);
- }
-
- ModResult AccessCheck(User* src, Channel*, std::string& value, bool adding)
- {
- if (!adding && src->nick == value && depriv)
- return MOD_RES_ALLOW;
- return MOD_RES_PASSTHRU;
+ selfremove = tag->getBool("depriv", true);
}
};