]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/postcommand.cpp
Merge insp20
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / postcommand.cpp
index a059bcb5fc13283f8a066203110497502ee5ff9d..64ca729779249cd2a44e8bb8fc80db9119719d71 100644 (file)
@@ -39,23 +39,33 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, CommandBase* thiscm
 
        const bool encap = ((routing.type == ROUTE_TYPE_OPT_BCAST) || (routing.type == ROUTE_TYPE_OPT_UCAST));
        CmdBuilder params(user, encap ? "ENCAP" : command.c_str());
+       TreeServer* sdest = NULL;
 
        if (routing.type == ROUTE_TYPE_OPT_BCAST)
        {
                params.push('*');
                params.push_back(command);
        }
-       else if (routing.type == ROUTE_TYPE_OPT_UCAST)
+       else if (routing.type == ROUTE_TYPE_UNICAST || routing.type == ROUTE_TYPE_OPT_UCAST)
        {
-               TreeServer* sdest = FindServer(routing.serverdest);
+               sdest = static_cast<TreeServer*>(routing.server);
                if (!sdest)
                {
-                       ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Trying to route ENCAP to nonexistant server %s",
-                               routing.serverdest.c_str());
-                       return;
+                       // Assume the command handler already validated routing.serverdest and have only returned success if the target is something that the
+                       // user executing the command is allowed to look up e.g. target is not an uuid if user is local.
+                       sdest = FindRouteTarget(routing.serverdest);
+                       if (!sdest)
+                       {
+                               ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Trying to route %s%s to nonexistent server %s", (encap ? "ENCAP " : ""), command.c_str(), routing.serverdest.c_str());
+                               return;
+                       }
+               }
+
+               if (encap)
+               {
+                       params.push_back(sdest->GetID());
+                       params.push_back(command);
                }
-               params.push_back(sdest->GetID());
-               params.push_back(command);
        }
        else
        {
@@ -81,7 +91,7 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, CommandBase* thiscm
                if (ServerInstance->Modes->FindPrefix(dest[0]))
                {
                        pfx = dest[0];
-                       dest = dest.substr(1);
+                       dest.erase(dest.begin());
                }
                if (dest[0] == '#')
                {
@@ -100,7 +110,7 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, CommandBase* thiscm
                {
                        // user target?
                        User* d = ServerInstance->FindNick(dest);
-                       if (!d)
+                       if (!d || IS_LOCAL(d))
                                return;
                        TreeServer* tsd = TreeServer::Get(d)->GetRoute();
                        if (tsd == origin)
@@ -115,8 +125,6 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, CommandBase* thiscm
        }
        else if (routing.type == ROUTE_TYPE_UNICAST || routing.type == ROUTE_TYPE_OPT_UCAST)
        {
-               if (origin && routing.serverdest == origin->GetName())
-                       return;
-               params.Unicast(routing.serverdest);
+               params.Unicast(sdest->ServerUser);
        }
 }