]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/capab.cpp
Reset the already_sent IDs during slow garbage collection
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / capab.cpp
index e855eb49f5af2855c014287e551b347b53b0e568..1e2fe710aa9d123e1fa1a2218772eaef78216284 100644 (file)
@@ -17,6 +17,7 @@
 #include "treesocket.h"
 #include "treeserver.h"
 #include "utils.h"
+#include "link.h"
 #include "main.h"
 
 std::string TreeSocket::MyModules(int filter)
@@ -49,22 +50,24 @@ std::string TreeSocket::MyModules(int filter)
 
 static std::string BuildModeList(ModeType type)
 {
-       std::string line;
+       std::vector<std::string> modes;
        for(char c='A'; c <= 'z'; c++)
        {
                ModeHandler* mh = ServerInstance->Modes->FindMode(c, type);
                if (mh)
                {
-                       if (!line.empty())
-                               line.push_back(' ');
-                       line.append(mh->name);
-                       line.push_back('=');
+                       std::string mdesc = mh->name;
+                       mdesc.push_back('=');
                        if (mh->GetPrefix())
-                               line.push_back(mh->GetPrefix());
-                       line.push_back(c);
+                               mdesc.push_back(mh->GetPrefix());
+                       if (mh->GetModeChar())
+                               mdesc.push_back(mh->GetModeChar());
+                       modes.push_back(mdesc);
                }
        }
-       return line;
+       sort(modes.begin(), modes.end());
+       irc::stringjoiner line(" ", modes, 0, modes.size() - 1);
+       return line.GetJoined();
 }
 
 void TreeSocket::SendCapabilities(int phase)
@@ -79,42 +82,43 @@ void TreeSocket::SendCapabilities(int phase)
        if (phase < 2)
                return;
 
-       irc::commasepstream modulelist(MyModules(VF_COMMON));
-       irc::commasepstream optmodulelist(MyModules(VF_OPTCOMMON));
+       char sep = proto_version > 1201 ? ' ' : ',';
+       irc::sepstream modulelist(MyModules(VF_COMMON), sep);
+       irc::sepstream optmodulelist(MyModules(VF_OPTCOMMON), sep);
        /* Send module names, split at 509 length */
        std::string item;
-       std::string line = "CAPAB MODULES ";
+       std::string line = "CAPAB MODULES :";
        while (modulelist.GetToken(item))
        {
                if (line.length() + item.length() + 1 > 509)
                {
                        this->WriteLine(line);
-                       line = "CAPAB MODULES ";
+                       line = "CAPAB MODULES :";
                }
 
-               if (line != "CAPAB MODULES ")
-                       line.append(",");
+               if (line != "CAPAB MODULES :")
+                       line.push_back(sep);
 
                line.append(item);
        }
-       if (line != "CAPAB MODULES ")
+       if (line != "CAPAB MODULES :")
                this->WriteLine(line);
 
-       line = "CAPAB MODSUPPORT ";
+       line = "CAPAB MODSUPPORT :";
        while (optmodulelist.GetToken(item))
        {
                if (line.length() + item.length() + 1 > 509)
                {
                        this->WriteLine(line);
-                       line = "CAPAB MODSUPPORT ";
+                       line = "CAPAB MODSUPPORT :";
                }
 
-               if (line != "CAPAB MODSUPPORT ")
-                       line.append(",");
+               if (line != "CAPAB MODSUPPORT :")
+                       line.push_back(sep);
 
                line.append(item);
        }
-       if (line != "CAPAB MODSUPPORT ")
+       if (line != "CAPAB MODSUPPORT :")
                this->WriteLine(line);
 
        WriteLine("CAPAB CHANMODES :" + BuildModeList(MODETYPE_CHANNEL));
@@ -128,7 +132,7 @@ void TreeSocket::SendCapabilities(int phase)
        /* Do we have sha256 available? If so, we send a challenge */
        if (Utils->ChallengeResponse && (ServerInstance->Modules->Find("m_sha256.so")))
        {
-               this->SetOurChallenge(RandString(20));
+               SetOurChallenge(ServerInstance->GenRandomStr(20));
                extra = " CHALLENGE=" + this->GetOurChallenge();
        }
 
@@ -169,14 +173,14 @@ void TreeSocket::ListDifference(const std::string &one, const std::string &two,
        {
                if (!values.erase(item))
                {
-                       mleft.push_back(sep);
-                       mleft.append(item);
+                       mright.push_back(sep);
+                       mright.append(item);
                }
        }
        for(std::set<std::string>::iterator i = values.begin(); i != values.end(); ++i)
        {
-               mright.push_back(sep);
-               mright.append(*i);
+               mleft.push_back(sep);
+               mleft.append(*i);
        }
 }
 
@@ -218,7 +222,7 @@ bool TreeSocket::Capab(const parameterlist &params)
                if (this->capab->OptModuleList != this->MyModules(VF_OPTCOMMON) && this->capab->OptModuleList.length())
                {
                        std::string diffIneed, diffUneed;
-                       ListDifference(this->capab->ModuleList, this->MyModules(VF_OPTCOMMON), ' ', diffIneed, diffUneed);
+                       ListDifference(this->capab->OptModuleList, this->MyModules(VF_OPTCOMMON), ' ', diffIneed, diffUneed);
                        if (diffIneed.length() || diffUneed.length())
                        {
                                if (Utils->AllowOptCommon)
@@ -312,8 +316,7 @@ bool TreeSocket::Capab(const parameterlist &params)
                        if (!this->GetTheirChallenge().empty() && (this->LinkState == CONNECTING))
                        {
                                this->SendCapabilities(2);
-                               this->WriteLine(std::string("SERVER ")+ServerInstance->Config->ServerName+" "+this->MakePass(capab->OutboundPass, this->GetTheirChallenge())+" 0 "+
-                                               ServerInstance->Config->GetSID()+" :"+ServerInstance->Config->ServerDesc);
+                               this->WriteLine(std::string("SERVER ")+ServerInstance->Config->ServerName+" "+this->MakePass(capab->link->SendPass, capab->theirchallenge)+" 0 "+ServerInstance->Config->GetSID()+" :"+ServerInstance->Config->ServerDesc);
                        }
                }
                else
@@ -322,7 +325,7 @@ bool TreeSocket::Capab(const parameterlist &params)
                        if (this->LinkState == CONNECTING)
                        {
                                this->SendCapabilities(2);
-                               this->WriteLine(std::string("SERVER ")+ServerInstance->Config->ServerName+" "+capab->OutboundPass+" 0 "+ServerInstance->Config->GetSID()+" :"+ServerInstance->Config->ServerDesc);
+                               this->WriteLine(std::string("SERVER ")+ServerInstance->Config->ServerName+" "+capab->link->SendPass+" 0 "+ServerInstance->Config->GetSID()+" :"+ServerInstance->Config->ServerDesc);
                        }
                }
 
@@ -334,26 +337,26 @@ bool TreeSocket::Capab(const parameterlist &params)
        }
        else if ((params[0] == "MODULES") && (params.size() == 2))
        {
-               if (!this->capab->ModuleList.length())
+               if (!capab->ModuleList.length())
                {
-                       this->capab->ModuleList.append(params[1]);
+                       capab->ModuleList = params[1];
                }
                else
                {
-                       this->capab->ModuleList.append(",");
-                       this->capab->ModuleList.append(params[1]);
+                       capab->ModuleList.push_back(proto_version > 1201 ? ' ' : ',');
+                       capab->ModuleList.append(params[1]);
                }
        }
        else if ((params[0] == "MODSUPPORT") && (params.size() == 2))
        {
-               if (!this->capab->OptModuleList.length())
+               if (!capab->OptModuleList.length())
                {
-                       this->capab->OptModuleList.append(params[1]);
+                       capab->OptModuleList = params[1];
                }
                else
                {
-                       this->capab->OptModuleList.append(",");
-                       this->capab->OptModuleList.append(params[1]);
+                       capab->OptModuleList.push_back(' ');
+                       capab->OptModuleList.append(params[1]);
                }
        }
        else if ((params[0] == "CHANMODES") && (params.size() == 2))