]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Let callers customize the begin/end positions for ModeParser::ModeParamsToChangeList()
authorAttila Molnar <attilamolnar@hush.com>
Thu, 4 Sep 2014 10:27:04 +0000 (12:27 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Thu, 4 Sep 2014 10:27:04 +0000 (12:27 +0200)
This helps spanningtree when it deals with a vector of parameters where the modes begin at different positions

include/mode.h
src/mode.cpp

index 868f3437da92eddceed8e1535e3e072942bcff5c..de92e8ec5d94f981459224fdbd8140d7941d76eb 100644 (file)
@@ -716,8 +716,12 @@ class CoreExport ModeParser : public fakederef<ModeParser>
         * @param parameters List of strings describing the mode change to convert to a ChangeList.
         * Must be using the same format as the parameters of a MODE command.
         * @param changelist ChangeList object to populate.
+        * @param beginindex Index of the first element that is part of the MODE list in the parameters
+        * container. Defaults to 1.
+        * @param endindex Index of the first element that is not part of the MODE list. By default,
+        * the entire container is considered part of the MODE list.
         */
-       void ModeParamsToChangeList(User* user, ModeType type, const std::vector<std::string>& parameters, Modes::ChangeList& changelist);
+       void ModeParamsToChangeList(User* user, ModeType type, const std::vector<std::string>& parameters, Modes::ChangeList& changelist, unsigned int beginindex = 1, unsigned int endindex = UINT_MAX);
 
        /** Find the mode handler for a given mode name and type.
         * @param modename The mode name to search for.
index d9dba196d4419ff9e3fe9f575ec948811b3ad8ac..770e6a2e2bddbbd8548d0ea203858664c1170f68 100644 (file)
@@ -425,12 +425,15 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User* user,
        }
 }
 
-void ModeParser::ModeParamsToChangeList(User* user, ModeType type, const std::vector<std::string>& parameters, Modes::ChangeList& changelist)
+void ModeParser::ModeParamsToChangeList(User* user, ModeType type, const std::vector<std::string>& parameters, Modes::ChangeList& changelist, unsigned int beginindex, unsigned int endindex)
 {
-       const std::string& mode_sequence = parameters[1];
+       if (endindex > parameters.size())
+               endindex = parameters.size();
+
+       const std::string& mode_sequence = parameters[beginindex];
 
        bool adding = true;
-       unsigned int param_at = 2;
+       unsigned int param_at = beginindex+1;
 
        for (std::string::const_iterator letter = mode_sequence.begin(); letter != mode_sequence.end(); letter++)
        {
@@ -450,7 +453,7 @@ void ModeParser::ModeParamsToChangeList(User* user, ModeType type, const std::ve
                }
 
                std::string parameter;
-               if (mh->GetNumParams(adding) && param_at < parameters.size())
+               if (mh->GetNumParams(adding) && param_at < endindex)
                        parameter = parameters[param_at++];
 
                changelist.push(mh, adding, parameter);