diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs index 4198acfa..a1d736d8 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs @@ -604,21 +604,31 @@ public partial class CoreConfigSingboxService if (i != 0) { var chainStartNodes = childProfiles.Where(n => n.tag.StartsWith(currentTag)).ToList(); - var existedChainNodes = JsonUtils.DeepCopy(resultOutbounds); - resultOutbounds.Clear(); - foreach (var chainStartNode in chainStartNodes) + if (chainStartNodes.Count == 1) { - var existedChainNodesClone = JsonUtils.DeepCopy(existedChainNodes); - for (var j = 0; j < existedChainNodesClone.Count; j++) + foreach (var existedChainEndNode in resultOutbounds.Where(n => n.detour == currentTag)) { - var existedChainNode = existedChainNodesClone[j]; - var cloneTag = $"{existedChainNode.tag}-clone-{j + 1}"; - existedChainNode.tag = cloneTag; - var previousDialerProxyTag = existedChainNode.detour; - existedChainNode.detour = (previousDialerProxyTag == currentTag) - ? chainStartNode.tag - : existedChainNodesClone[j + 1].tag; - resultOutbounds.Add(existedChainNode); + existedChainEndNode.detour = chainStartNodes.First().tag; + } + } + else if (chainStartNodes.Count > 1) + { + var existedChainNodes = JsonUtils.DeepCopy(resultOutbounds); + resultOutbounds.Clear(); + foreach (var chainStartNode in chainStartNodes) + { + var existedChainNodesClone = JsonUtils.DeepCopy(existedChainNodes); + for (var j = 0; j < existedChainNodesClone.Count; j++) + { + var existedChainNode = existedChainNodesClone[j]; + var cloneTag = $"{existedChainNode.tag}-clone-{j + 1}"; + existedChainNode.tag = cloneTag; + var previousDialerProxyTag = existedChainNode.detour; + existedChainNode.detour = (previousDialerProxyTag == currentTag) + ? chainStartNode.tag + : existedChainNodesClone[j + 1].tag; + resultOutbounds.Add(existedChainNode); + } } } } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs index e50e4700..61efbfaf 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs @@ -743,22 +743,35 @@ public partial class CoreConfigV2rayService if (i != 0) { var chainStartNodes = childProfiles.Where(n => n.tag.StartsWith(currentTag)).ToList(); - var existedChainNodes = JsonUtils.DeepCopy(resultOutbounds); - resultOutbounds.Clear(); - foreach (var chainStartNode in chainStartNodes) + if (chainStartNodes.Count == 1) { - var existedChainNodesClone = JsonUtils.DeepCopy(existedChainNodes); - for (var j = 0; j < existedChainNodesClone.Count; j++) + foreach (var existedChainEndNode in resultOutbounds.Where(n => n.streamSettings?.sockopt?.dialerProxy == currentTag)) { - var existedChainNode = existedChainNodesClone[j]; - var cloneTag = $"{existedChainNode.tag}-clone-{j + 1}"; - existedChainNode.tag = cloneTag; - var previousDialerProxyTag = existedChainNode.streamSettings?.sockopt?.dialerProxy; - existedChainNode.streamSettings.sockopt = new() + existedChainEndNode.streamSettings.sockopt = new() { - dialerProxy = (previousDialerProxyTag == currentTag) ? chainStartNode.tag : existedChainNodesClone[j + 1].tag + dialerProxy = chainStartNodes.First().tag }; - resultOutbounds.Add(existedChainNode); + } + } + else if (chainStartNodes.Count > 1) + { + var existedChainNodes = JsonUtils.DeepCopy(resultOutbounds); + resultOutbounds.Clear(); + foreach (var chainStartNode in chainStartNodes) + { + var existedChainNodesClone = JsonUtils.DeepCopy(existedChainNodes); + for (var j = 0; j < existedChainNodesClone.Count; j++) + { + var existedChainNode = existedChainNodesClone[j]; + var cloneTag = $"{existedChainNode.tag}-clone-{j + 1}"; + existedChainNode.tag = cloneTag; + var previousDialerProxyTag = existedChainNode.streamSettings?.sockopt?.dialerProxy; + existedChainNode.streamSettings.sockopt = new() + { + dialerProxy = (previousDialerProxyTag == currentTag) ? chainStartNode.tag : existedChainNodesClone[j + 1].tag + }; + resultOutbounds.Add(existedChainNode); + } } } }