summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2013-09-02 12:25:54 +0200
committerattilamolnar <attilamolnar@hush.com>2013-09-12 14:44:17 +0200
commit52e4d9c96c83ca4bbbeb487966ac2897a384907d (patch)
treebf97357669eb566d1adab2b9824feeda75e71ad9
parente35772f19024fb12edda9cff19d3812272f444db (diff)
Add ModeHandler::IsListModeBase() and MC_LIST
-rw-r--r--include/mode.h16
-rw-r--r--src/listmode.cpp2
-rw-r--r--src/modules/m_rmode.cpp13
3 files changed, 20 insertions, 11 deletions
diff --git a/include/mode.h b/include/mode.h
index e20815549..bfe4041b9 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -85,6 +85,7 @@ enum ParamSpec
};
class PrefixMode;
+class ListModeBase;
/** Each mode is implemented by ONE ModeHandler class.
* You must derive ModeHandler and add the child class to
@@ -106,6 +107,7 @@ class CoreExport ModeHandler : public ServiceProvider
enum Class
{
MC_PREFIX,
+ MC_LIST,
MC_OTHER
};
@@ -178,11 +180,18 @@ class CoreExport ModeHandler : public ServiceProvider
bool IsListMode() const { return list; }
/**
- * Returns a PrefixMode* if this mode is a prefix mode, NULL otherwise
+ * Check whether this mode is a prefix mode
+ * @return non-NULL if this mode is a prefix mode, NULL otherwise
*/
PrefixMode* IsPrefixMode();
/**
+ * Check whether this mode handler inherits from ListModeBase
+ * @return non-NULL if this mode handler inherits from ListModeBase, NULL otherwise
+ */
+ ListModeBase* IsListModeBase();
+
+ /**
* Returns the mode's type
*/
inline ModeType GetModeType() const { return m_type; }
@@ -678,3 +687,8 @@ inline PrefixMode* ModeHandler::IsPrefixMode()
{
return (this->type_id == MC_PREFIX ? static_cast<PrefixMode*>(this) : NULL);
}
+
+inline ListModeBase* ModeHandler::IsListModeBase()
+{
+ return (this->type_id == MC_LIST ? reinterpret_cast<ListModeBase*>(this) : NULL);
+}
diff --git a/src/listmode.cpp b/src/listmode.cpp
index f7890f9ad..4ab15b2dc 100644
--- a/src/listmode.cpp
+++ b/src/listmode.cpp
@@ -20,7 +20,7 @@
#include "listmode.h"
ListModeBase::ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string &eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy, const std::string &ctag)
- : ModeHandler(Creator, Name, modechar, PARAM_ALWAYS, MODETYPE_CHANNEL),
+ : ModeHandler(Creator, Name, modechar, PARAM_ALWAYS, MODETYPE_CHANNEL, MC_LIST),
listnumeric(lnum), endoflistnumeric(eolnum), endofliststring(eolstr), tidy(autotidy),
configtag(ctag), extItem("listbase_mode_" + name + "_list", Creator)
{
diff --git a/src/modules/m_rmode.cpp b/src/modules/m_rmode.cpp
index 6d17820a5..dde9f496e 100644
--- a/src/modules/m_rmode.cpp
+++ b/src/modules/m_rmode.cpp
@@ -62,12 +62,7 @@ class CommandRMode : public Command
ListModeBase::ModeList* ml;
irc::modestacker modestack(false);
- if (!mh->IsListMode())
- {
- if (chan->IsModeSet(mh))
- modestack.Push(modeletter);
- }
- else if ((pm = mh->IsPrefixMode()))
+ if ((pm = mh->IsPrefixMode()))
{
// 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)
@@ -78,7 +73,7 @@ class CommandRMode : public Command
modestack.Push(modeletter, it->first->nick);
}
}
- else if (((lm = dynamic_cast<ListModeBase*>(mh)) != NULL) && ((ml = lm->GetList(chan)) != NULL))
+ else if ((lm = mh->IsListModeBase()) && ((ml = lm->GetList(chan)) != NULL))
{
for (ListModeBase::ModeList::iterator it = ml->begin(); it != ml->end(); ++it)
{
@@ -89,8 +84,8 @@ class CommandRMode : public Command
}
else
{
- user->WriteNotice("Could not remove channel mode " + ConvToStr(modeletter));
- return CMD_FAILURE;
+ if (chan->IsModeSet(mh))
+ modestack.Push(modeletter);
}
parameterlist stackresult;