This commit is contained in:
DHR60 2026-02-06 16:31:11 +08:00
parent 437ba09d06
commit c6dd26e324
2 changed files with 55 additions and 10 deletions

View file

@ -519,7 +519,7 @@ public partial class CoreConfigSingboxService
var outUrltest = new Outbound4Sbox var outUrltest = new Outbound4Sbox
{ {
type = "urltest", type = "urltest",
tag = $"{Global.ProxyTag}-auto", tag = $"{baseTagName}-auto",
outbounds = proxyTags, outbounds = proxyTags,
interrupt_exist_connections = false, interrupt_exist_connections = false,
}; };
@ -533,7 +533,7 @@ public partial class CoreConfigSingboxService
var outSelector = new Outbound4Sbox var outSelector = new Outbound4Sbox
{ {
type = "selector", type = "selector",
tag = Global.ProxyTag, tag = baseTagName,
outbounds = JsonUtils.DeepCopy(proxyTags), outbounds = JsonUtils.DeepCopy(proxyTags),
interrupt_exist_connections = false, interrupt_exist_connections = false,
}; };
@ -613,22 +613,30 @@ public partial class CoreConfigSingboxService
} }
else if (chainStartNodes.Count > 1) else if (chainStartNodes.Count > 1)
{ {
var existedChainNodes = JsonUtils.DeepCopy(resultOutbounds); var existedChainNodes = CloneOutbounds(resultOutbounds);
resultOutbounds.Clear(); resultOutbounds.Clear();
var j = 0;
foreach (var chainStartNode in chainStartNodes) foreach (var chainStartNode in chainStartNodes)
{ {
var existedChainNodesClone = JsonUtils.DeepCopy(existedChainNodes); var existedChainNodesClone = CloneOutbounds(existedChainNodes);
for (var j = 0; j < existedChainNodesClone.Count; j++) foreach (var existedChainNode in existedChainNodesClone)
{ {
var existedChainNode = existedChainNodesClone[j];
var cloneTag = $"{existedChainNode.tag}-clone-{j + 1}"; var cloneTag = $"{existedChainNode.tag}-clone-{j + 1}";
existedChainNode.tag = cloneTag; existedChainNode.tag = cloneTag;
}
for (var k = 0; k < existedChainNodesClone.Count; k++)
{
var existedChainNode = existedChainNodesClone[k];
var previousDialerProxyTag = existedChainNode.detour; var previousDialerProxyTag = existedChainNode.detour;
var nextTag = k + 1 < existedChainNodesClone.Count
? existedChainNodesClone[k + 1].tag
: chainStartNode.tag;
existedChainNode.detour = (previousDialerProxyTag == currentTag) existedChainNode.detour = (previousDialerProxyTag == currentTag)
? chainStartNode.tag ? chainStartNode.tag
: existedChainNodesClone[j + 1].tag; : nextTag;
resultOutbounds.Add(existedChainNode); resultOutbounds.Add(existedChainNode);
} }
j++;
} }
} }
} }
@ -649,6 +657,33 @@ public partial class CoreConfigSingboxService
return resultOutbounds; return resultOutbounds;
} }
private static List<BaseServer4Sbox> CloneOutbounds(List<BaseServer4Sbox> source)
{
if (source is null || source.Count == 0)
{
return [];
}
var result = new List<BaseServer4Sbox>(source.Count);
foreach (var item in source)
{
BaseServer4Sbox? clone = null;
if (item is Outbound4Sbox outbound)
{
clone = JsonUtils.DeepCopy(outbound);
}
else if (item is Endpoints4Sbox endpoint)
{
clone = JsonUtils.DeepCopy(endpoint);
}
if (clone is not null)
{
result.Add(clone);
}
}
return result;
}
private static void FillRangeProxy(List<BaseServer4Sbox> servers, SingboxConfig singboxConfig, bool prepend = true) private static void FillRangeProxy(List<BaseServer4Sbox> servers, SingboxConfig singboxConfig, bool prepend = true)
{ {
try try

View file

@ -757,21 +757,31 @@ public partial class CoreConfigV2rayService
{ {
var existedChainNodes = JsonUtils.DeepCopy(resultOutbounds); var existedChainNodes = JsonUtils.DeepCopy(resultOutbounds);
resultOutbounds.Clear(); resultOutbounds.Clear();
var j = 0;
foreach (var chainStartNode in chainStartNodes) foreach (var chainStartNode in chainStartNodes)
{ {
var existedChainNodesClone = JsonUtils.DeepCopy(existedChainNodes); var existedChainNodesClone = JsonUtils.DeepCopy(existedChainNodes);
for (var j = 0; j < existedChainNodesClone.Count; j++) foreach (var existedChainNode in existedChainNodesClone)
{ {
var existedChainNode = existedChainNodesClone[j];
var cloneTag = $"{existedChainNode.tag}-clone-{j + 1}"; var cloneTag = $"{existedChainNode.tag}-clone-{j + 1}";
existedChainNode.tag = cloneTag; existedChainNode.tag = cloneTag;
}
for (var k = 0; k < existedChainNodesClone.Count; k++)
{
var existedChainNode = existedChainNodesClone[k];
var previousDialerProxyTag = existedChainNode.streamSettings?.sockopt?.dialerProxy; var previousDialerProxyTag = existedChainNode.streamSettings?.sockopt?.dialerProxy;
var nextTag = k + 1 < existedChainNodesClone.Count
? existedChainNodesClone[k + 1].tag
: chainStartNode.tag;
existedChainNode.streamSettings.sockopt = new() existedChainNode.streamSettings.sockopt = new()
{ {
dialerProxy = (previousDialerProxyTag == currentTag) ? chainStartNode.tag : existedChainNodesClone[j + 1].tag dialerProxy = (previousDialerProxyTag == currentTag)
? chainStartNode.tag
: nextTag
}; };
resultOutbounds.Add(existedChainNode); resultOutbounds.Add(existedChainNode);
} }
j++;
} }
} }
} }