+ if (!ServerInstance->Parser->IsValidCommand(command, parameters.size(), user))
+ return;
+
+ /* We know it's non-null because IsValidCommand returned true */
+ Command* thiscmd = ServerInstance->Parser->GetHandler(command);
+
+ RouteDescriptor routing = thiscmd->GetRouting(user, parameters);
+
+ std::string sent_cmd = command;
+ parameterlist params;
+
+ if (routing.type == ROUTE_TYPE_LOCALONLY)
+ {
+ /* Broadcast when it's a core command with the default route descriptor and the source is a
+ * remote user or a remote server
+ */
+
+ Version ver = thiscmd->creator->GetVersion();
+ if ((!(ver.Flags & VF_CORE)) || (IS_LOCAL(user)) || (IS_SERVER(user) == ServerInstance->FakeClient))
+ return;
+
+ routing = ROUTE_BROADCAST;
+ }
+ else if (routing.type == ROUTE_TYPE_OPT_BCAST)
+ {
+ params.push_back("*");
+ params.push_back(command);
+ sent_cmd = "ENCAP";
+ }
+ else if (routing.type == ROUTE_TYPE_OPT_UCAST)
+ {
+ TreeServer* sdest = FindServer(routing.serverdest);
+ if (!sdest)
+ {
+ ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Trying to route ENCAP to nonexistant server %s",
+ routing.serverdest.c_str());
+ return;
+ }
+ params.push_back(sdest->GetID());
+ params.push_back(command);
+ sent_cmd = "ENCAP";
+ }
+ else