if (!CheckDuplicate(capab->name, capab->sid))
return;
- this->LinkState = CONNECTED;
- Utils->timeoutlist.erase(this);
+ FinishAuth(capab->name, capab->sid, capab->description, capab->hidden);
- linkID = capab->name;
-
- MyRoot = new TreeServer(capab->name, capab->description, capab->sid, Utils->TreeRoot, this, capab->hidden);
- Utils->TreeRoot->AddChild(MyRoot);
-
- MyRoot->bursting = true;
- this->DoBurst(MyRoot);
-
- CommandServer::Builder(MyRoot).Forward(MyRoot);
CmdBuilder(MyRoot->GetID(), "BURST").insert(params).Forward(MyRoot);
}
else if (command == "ERROR")
}
}
-void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, parameterlist& params)
+User* TreeSocket::FindSource(const std::string& prefix, const std::string& command)
{
+ // Empty prefix means the source is the directly connected server that sent this command
+ if (prefix.empty())
+ return MyRoot->ServerUser;
+
+ // If the prefix string is a uuid or a sid FindUUID() returns the appropriate User object
User* who = ServerInstance->FindUUID(prefix);
+ if (who)
+ return who;
- if (!who)
- {
- TreeServer* ServerSource = Utils->FindServer(prefix);
- if (prefix.empty())
- ServerSource = MyRoot;
+ // Some implementations wrongly send a server name as prefix occasionally, handle that too for now
+ TreeServer* const server = Utils->FindServer(prefix);
+ if (server)
+ return server->ServerUser;
- if (ServerSource)
- {
- who = ServerSource->ServerUser;
- }
- else
- {
- /* It is important that we don't close the link here, unknown prefix can occur
- * 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!
- */
+ /* It is important that we don't close the link here, unknown prefix can occur
+ * 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!
+ */
- if ((prefix.length() == UIDGenerator::UUID_LENGTH) && (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.
- */
+ if ((prefix.length() == UIDGenerator::UUID_LENGTH) && (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)
+ return who;
+ return this->MyRoot->ServerUser;
+ }
- who = ServerInstance->FindUUID(prefix.substr(0, 3));
- if (!who)
- who = this->MyRoot->ServerUser;
- }
- else
- {
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Command '%s' from unknown prefix '%s'! Dropping entire command.",
- command.c_str(), prefix.c_str());
- return;
- }
- }
+ // Unknown prefix
+ return NULL;
+}
+
+void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, parameterlist& params)
+{
+ User* who = FindSource(prefix, command);
+ if (!who)
+ {
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Command '%s' from unknown prefix '%s'! Dropping entire command.", command.c_str(), prefix.c_str());
+ return;
}
/*
* a valid SID or a valid UUID, so that invalid UUID or SID never makes it
* to the higher level functions. -- B
*/
- TreeServer* route_back_again = TreeServer::Get(who)->GetRoute();
- if (route_back_again->GetSocket() != this)
+ TreeServer* const server = TreeServer::Get(who);
+ if (server->GetSocket() != this)
{
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Protocol violation: Fake direction '%s' from connection '%s'", prefix.c_str(), linkID.c_str());
return;
if (!scmd)
{
// Not a special server-to-server command
- cmd = ServerInstance->Parser->GetHandler(command);
+ cmd = ServerInstance->Parser.GetHandler(command);
if (!cmd)
{
if (command == "ERROR")
return;
}
- irc::stringjoiner pmlist(params);
- ServerInstance->Logs->Log(MODNAME, LOG_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;
+ throw ProtocolException("Unknown command");
}
cmdbase = cmd;
}
if (params.size() < cmdbase->min_params)
- {
- irc::stringjoiner pmlist(params);
- ServerInstance->Logs->Log(MODNAME, LOG_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;
- }
+ throw ProtocolException("Insufficient parameters");
if ((!params.empty()) && (params.back().empty()) && (!cmdbase->allow_empty_last_param))
{
if (scmd)
res = scmd->Handle(who, params);
else
- res = cmd->Handle(params, who);
-
- if (res == CMD_INVALID)
{
- irc::stringjoiner pmlist(params);
- ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Error handling S2S command :%s %s %s",
- who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
- SendError("Error handling '" + command + "' -- possibly loaded mismatched modules");
+ res = cmd->Handle(params, who);
+ if (res == CMD_INVALID)
+ throw ProtocolException("Error in command handler");
}
- else if (res == CMD_SUCCESS)
- Utils->RouteCommand(route_back_again, cmdbase, params, who);
+
+ if (res == CMD_SUCCESS)
+ Utils->RouteCommand(server->GetRoute(), cmdbase, params, who);
}
void TreeSocket::OnTimeout()
}
}
}
+
+void TreeSocket::FinishAuth(const std::string& remotename, const std::string& remotesid, const std::string& remotedesc, bool hidden)
+{
+ this->LinkState = CONNECTED;
+ Utils->timeoutlist.erase(this);
+
+ linkID = remotename;
+
+ MyRoot = new TreeServer(remotename, remotedesc, remotesid, Utils->TreeRoot, this, hidden);
+
+ this->DoBurst(MyRoot);
+
+ CommandServer::Builder(MyRoot).Forward(MyRoot);
+}