]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/fjoin.cpp
Link m_ldap against libldap_r
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / fjoin.cpp
index 6263237a33d8fb307ef9695f9301dd4024df6e38..bfe3592d2ae03599df8039fc5364bc83ec9dfe18 100644 (file)
@@ -113,60 +113,34 @@ CmdResult CommandFJoin::Handle(User* srcuser, std::vector<std::string>& params)
        }
 
        /* First up, apply their channel modes if they won the TS war */
+       Modes::ChangeList modechangelist;
        if (apply_other_sides_modes)
        {
-               // Need to use a modestacker here due to maxmodes
-               irc::modestacker stack(true);
-               std::vector<std::string>::const_iterator paramit = params.begin() + 3;
-               const std::vector<std::string>::const_iterator lastparamit = ((params.size() > 3) ? (params.end() - 1) : params.end());
-               for (std::string::const_iterator i = params[2].begin(); i != params[2].end(); ++i)
-               {
-                       ModeHandler* mh = ServerInstance->Modes->FindMode(*i, MODETYPE_CHANNEL);
-                       if (!mh)
-                               continue;
-
-                       std::string modeparam;
-                       if ((paramit != lastparamit) && (mh->GetNumParams(true)))
-                       {
-                               modeparam = *paramit;
-                               ++paramit;
-                       }
-
-                       stack.Push(*i, modeparam);
-               }
-
-               std::vector<std::string> modelist;
-
-               // Mode parser needs to know what channel to act on.
-               modelist.push_back(params[0]);
-
-               while (stack.GetStackedLine(modelist))
-               {
-                       ServerInstance->Modes->Process(modelist, srcuser, ModeParser::MODE_LOCALONLY | ModeParser::MODE_MERGE);
-                       modelist.erase(modelist.begin() + 1, modelist.end());
-               }
+               ServerInstance->Modes.ModeParamsToChangeList(srcuser, MODETYPE_CHANNEL, params, modechangelist, 2, params.size() - 1);
+               ServerInstance->Modes->Process(srcuser, chan, NULL, modechangelist, ModeParser::MODE_LOCALONLY | ModeParser::MODE_MERGE);
+               // Reuse for prefix modes
+               modechangelist.clear();
        }
 
-       irc::modestacker modestack(true);
        TreeServer* const sourceserver = TreeServer::Get(srcuser);
 
        /* Now, process every 'modes,uuid' pair */
        irc::tokenstream users(params.back());
        std::string item;
-       irc::modestacker* modestackptr = (apply_other_sides_modes ? &modestack : NULL);
+       Modes::ChangeList* modechangelistptr = (apply_other_sides_modes ? &modechangelist : NULL);
        while (users.GetToken(item))
        {
-               ProcessModeUUIDPair(item, sourceserver, chan, modestackptr);
+               ProcessModeUUIDPair(item, sourceserver, chan, modechangelistptr);
        }
 
-       /* Flush mode stacker if we lost the FJOIN or had equal TS */
+       // Set prefix modes on their users if we lost the FJOIN or had equal TS
        if (apply_other_sides_modes)
-               CommandFJoin::ApplyModeStack(srcuser, chan, modestack);
+               ServerInstance->Modes->Process(srcuser, chan, NULL, modechangelist, ModeParser::MODE_LOCALONLY);
 
        return CMD_SUCCESS;
 }
 
-void CommandFJoin::ProcessModeUUIDPair(const std::string& item, TreeServer* sourceserver, Channel* chan, irc::modestacker* modestack)
+void CommandFJoin::ProcessModeUUIDPair(const std::string& item, TreeServer* sourceserver, Channel* chan, Modes::ChangeList* modechangelist)
 {
        std::string::size_type comma = item.find(',');
 
@@ -189,17 +163,18 @@ void CommandFJoin::ProcessModeUUIDPair(const std::string& item, TreeServer* sour
        }
 
        /* Check if the user received at least one mode */
-       if ((modestack) && (comma > 0) && (comma != std::string::npos))
+       if ((modechangelist) && (comma > 0) && (comma != std::string::npos))
        {
                /* Iterate through the modes and see if they are valid here, if so, apply */
                std::string::const_iterator commait = item.begin()+comma;
                for (std::string::const_iterator i = item.begin(); i != commait; ++i)
                {
-                       if (!ServerInstance->Modes->FindMode(*i, MODETYPE_CHANNEL))
+                       ModeHandler* mh = ServerInstance->Modes->FindMode(*i, MODETYPE_CHANNEL);
+                       if (!mh)
                                throw ProtocolException("Unrecognised mode '" + std::string(1, *i) + "'");
 
                        /* Add any modes this user had to the mode stack */
-                       modestack->Push(*i, who->nick);
+                       modechangelist->push_add(mh, who->nick);
                }
        }
 
@@ -217,7 +192,7 @@ void CommandFJoin::ProcessModeUUIDPair(const std::string& item, TreeServer* sour
 
 void CommandFJoin::RemoveStatus(Channel* c)
 {
-       irc::modestacker stack(false);
+       Modes::ChangeList changelist;
 
        const ModeParser::ModeHandlerMap& mhs = ServerInstance->Modes->GetModes(MODETYPE_CHANNEL);
        for (ModeParser::ModeHandlerMap::const_iterator i = mhs.begin(); i != mhs.end(); ++i)
@@ -228,22 +203,10 @@ void CommandFJoin::RemoveStatus(Channel* c)
                 * rather than applied immediately. Module unloads require this to be done immediately,
                 * for this function we require tidyness instead. Fixes bug #493
                 */
-               mh->RemoveMode(c, stack);
+               mh->RemoveMode(c, changelist);
        }
 
-       ApplyModeStack(ServerInstance->FakeClient, c, stack);
-}
-
-void CommandFJoin::ApplyModeStack(User* srcuser, Channel* c, irc::modestacker& stack)
-{
-       parameterlist stackresult;
-       stackresult.push_back(c->name);
-
-       while (stack.GetStackedLine(stackresult))
-       {
-               ServerInstance->Modes->Process(stackresult, srcuser, ModeParser::MODE_LOCALONLY);
-               stackresult.erase(stackresult.begin() + 1, stackresult.end());
-       }
+       ServerInstance->Modes->Process(ServerInstance->FakeClient, c, NULL, changelist, ModeParser::MODE_LOCALONLY);
 }
 
 void CommandFJoin::LowerTS(Channel* chan, time_t TS, const std::string& newname)