summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-09-03 15:11:27 +0200
committerAttila Molnar <attilamolnar@hush.com>2014-09-03 15:11:27 +0200
commitf55703b2fb7590333d06008add5294a6bd711339 (patch)
tree398b6efe9747c068b661d63bed83cb220dc2ebac
parentc6c43eaf60b966870acaf152721e89b5289281b3 (diff)
Add a ModeParser::Process() overload that can process an entire Modes::ChangeList
This is a wrapper that calls ProcessSingle() repeatedly until the entire changelist is processed
-rw-r--r--include/mode.h11
-rw-r--r--src/mode.cpp13
2 files changed, 24 insertions, 0 deletions
diff --git a/include/mode.h b/include/mode.h
index fbc880129..7dc718a27 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -680,6 +680,17 @@ class CoreExport ModeParser : public fakederef<ModeParser>
*/
void Process(const std::vector<std::string>& parameters, User* user, ModeProcessFlag flags = MODE_NONE);
+ /** Process a list of mode changes entirely. If the mode changes do not fit into one MODE line
+ * then multiple MODE lines are generated.
+ * @param user The source of the mode change, can be a server user.
+ * @param targetchannel Channel to apply the mode change on. NULL if changing modes on a channel.
+ * @param targetuser User to apply the mode change on. NULL if changing modes on a user.
+ * @param changelist Modes to change in form of a Modes::ChangeList.
+ * @param flags Optional flags controlling how the mode change is processed,
+ * defaults to MODE_NONE.
+ */
+ void Process(User* user, Channel* targetchannel, User* targetuser, Modes::ChangeList& changelist, ModeProcessFlag flags = MODE_NONE);
+
/** Process a single MODE line's worth of mode changes, taking max modes and line length limits
* into consideration. Return value indicates how many modes were processed.
* @param user The source of the mode change, can be a server user.
diff --git a/src/mode.cpp b/src/mode.cpp
index c44942bd6..2c22a6c65 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -486,6 +486,19 @@ static bool ShouldApplyMergedMode(Channel* chan, Modes::Change& item)
return mh->ResolveModeConflict(item.param, ours, chan);
}
+void ModeParser::Process(User* user, Channel* targetchannel, User* targetuser, Modes::ChangeList& changelist, ModeProcessFlag flags)
+{
+ // Call ProcessSingle until the entire list is processed, but at least once to ensure
+ // LastParse and LastChangeList are cleared
+ unsigned int processed = 0;
+ do
+ {
+ unsigned int n = ProcessSingle(user, targetchannel, targetuser, changelist, flags, processed);
+ processed += n;
+ }
+ while (processed < changelist.size());
+}
+
unsigned int ModeParser::ProcessSingle(User* user, Channel* targetchannel, User* targetuser, Modes::ChangeList& changelist, ModeProcessFlag flags, unsigned int beginindex)
{
LastParse.clear();