]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treesocket2.cpp
m_connectban Switch to OnSetUserIP hook to handle cgiirc users properly, ignore e...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
index 4582eb4c52b78ebcfbc8bfbb344258df9eec0a93..04ca9edb145f072e036dc74b7eadefb5e510672e 100644 (file)
@@ -129,7 +129,7 @@ void TreeSocket::ProcessLine(std::string &line)
                        }
                        else
                        {
-                               this->SendError(std::string("Invalid command in negotiation phase: ") + command.c_str());
+                               this->SendError("Invalid command in negotiation phase: " + command);
                        }
                break;
                case WAIT_AUTH_2:
@@ -165,12 +165,19 @@ void TreeSocket::ProcessLine(std::string &line)
                                        }
                                }
                                this->LinkState = CONNECTED;
-
                                Utils->timeoutlist.erase(this);
-                               parameterlist sparams;
-                               Utils->DoOneToAllButSender(MyRoot->GetID(), "BURST", params, MyRoot->GetName());
+
                                MyRoot->bursting = true;
                                this->DoBurst(MyRoot);
+
+                               parameterlist sparams;
+                               sparams.push_back(MyRoot->GetName());
+                               sparams.push_back("*");
+                               sparams.push_back("0");
+                               sparams.push_back(MyRoot->GetID());
+                               sparams.push_back(":" + MyRoot->GetDesc());
+                               Utils->DoOneToAllButSender(ServerInstance->Config->GetSID(), "SERVER", sparams, MyRoot->GetName());
+                               Utils->DoOneToAllButSender(MyRoot->GetID(), "BURST", params, MyRoot->GetName());
                        }
                        else if (command == "ERROR")
                        {
@@ -237,9 +244,25 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                         * due to various race conditions such as the KILL message for a user somehow
                         * crossing the users QUIT further upstream from the server. Thanks jilles!
                         */
-                       ServerInstance->Logs->Log("m_spanningtree", DEBUG, "Command '%s' from unknown prefix '%s'! Dropping entire command.",
-                               command.c_str(), prefix.c_str());
-                       return;
+
+                       if ((prefix.length() == UUID_LENGTH-1) && (isdigit(prefix[0])) &&
+                               ((command == "FMODE") || (command == "MODE") || (command == "KICK") || (command == "TOPIC") || (command == "KILL") || (command == "ADDLINE") || (command == "DELLINE")))
+                       {
+                               /* Special case, we cannot drop these commands as they've been committed already on a
+                                * part of the network by the time we receive them, so in this scenario pretend the
+                                * command came from a server to avoid desync.
+                                */
+
+                               who = ServerInstance->FindUUID(prefix.substr(0, 3));
+                               if (!who)
+                                       who = this->MyRoot->ServerUser;
+                       }
+                       else
+                       {
+                               ServerInstance->Logs->Log("m_spanningtree", DEBUG, "Command '%s' from unknown prefix '%s'! Dropping entire command.",
+                                       command.c_str(), prefix.c_str());
+                               return;
+                       }
                }
        }
 
@@ -387,7 +410,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        {
                if (params.size() != 2)
                {
-                       SendError("Protocol violation: NICK message without TS - :"+std::string(who->uuid)+" NICK "+params[0]);
+                       SendError("Protocol violation: Wrong number of parameters for NICK message");
                        return;
                }
 
@@ -397,6 +420,12 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                        return;
                }
 
+               if ((isdigit(params[0][0])) && (params[0] != who->uuid))
+               {
+                       SendError("Protocol violation: User changing nick to an invalid UID - " + params[0]);
+                       return;
+               }
+
                /* Update timestamp on user when they change nicks */
                who->age = atoi(params[1].c_str());
 
@@ -433,6 +462,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                        ServerInstance->Logs->Log("m_spanningtree", SPARSE, "Unrecognised S2S command :%s %s %s",
                                who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
                        SendError("Unrecognised command '" + command + "' -- possibly loaded mismatched modules");
+                       return;
                }
 
                if (params.size() < cmd->min_params)
@@ -441,6 +471,15 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                        ServerInstance->Logs->Log("m_spanningtree", SPARSE, "Insufficient parameters for S2S command :%s %s %s",
                                who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
                        SendError("Insufficient parameters for command '" + command + "'");
+                       return;
+               }
+
+               if ((!params.empty()) && (params.back().empty()) && (!cmd->allow_empty_last_param))
+               {
+                       // the last param is empty and the command handler doesn't allow that, check if there will be enough params if we drop the last
+                       if (params.size()-1 < cmd->min_params)
+                               return;
+                       params.pop_back();
                }
 
                CmdResult res = cmd->Handle(params, who);
@@ -452,7 +491,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                                who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
                        SendError("Error handling '" + command + "' -- possibly loaded mismatched modules");
                }
-               if (res == CMD_SUCCESS)
+               else if (res == CMD_SUCCESS)
                        Utils->RouteCommand(route_back_again, command, params, who);
        }
 }
@@ -475,13 +514,16 @@ void TreeSocket::Close()
        if (MyRoot)
                Squit(MyRoot,getError());
 
-       if (!linkID.empty())
+       if (!ConnectionFailureShown)
        {
+               ConnectionFailureShown = true;
                ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' failed.",linkID.c_str());
 
                time_t server_uptime = ServerInstance->Time() - this->age;
                if (server_uptime)
-                       ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' was established for %s", linkID.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
-               linkID.clear();
+               {
+                       std::string timestr = Utils->Creator->TimeToStr(server_uptime);
+                       ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' was established for %s", linkID.c_str(), timestr.c_str());
+               }
        }
 }