From 1121e4fed5cf0e7785d363307fc987941bffc8ff Mon Sep 17 00:00:00 2001 From: DHR60 Date: Mon, 23 Feb 2026 21:16:18 +0800 Subject: [PATCH] Fix --- .../Singbox/SingboxConfigTemplateService.cs | 4 ++-- .../V2ray/V2rayConfigTemplateService.cs | 22 +++++++++++-------- .../CoreConfig/V2ray/V2rayRoutingService.cs | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxConfigTemplateService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxConfigTemplateService.cs index 7dd54b1f..25b29701 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxConfigTemplateService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxConfigTemplateService.cs @@ -23,7 +23,7 @@ public partial class CoreConfigSingboxService } // Process outbounds - var customOutboundsNode = fullConfigTemplateNode["outbounds"] is JsonArray outbounds ? outbounds : new JsonArray(); + var customOutboundsNode = fullConfigTemplateNode["outbounds"] is JsonArray outbounds ? outbounds : []; foreach (var outbound in _coreConfig.outbounds) { if (outbound.type.ToLower() is "direct" or "block") @@ -44,7 +44,7 @@ public partial class CoreConfigSingboxService // Process endpoints if (_coreConfig.endpoints != null && _coreConfig.endpoints.Count > 0) { - var customEndpointsNode = fullConfigTemplateNode["endpoints"] is JsonArray endpoints ? endpoints : new JsonArray(); + var customEndpointsNode = fullConfigTemplateNode["endpoints"] is JsonArray endpoints ? endpoints : []; foreach (var endpoint in _coreConfig.endpoints) { if (endpoint.detour.IsNullOrEmpty() && !fullConfigTemplate.ProxyDetour.IsNullOrEmpty()) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayConfigTemplateService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayConfigTemplateService.cs index cec9b6ea..544d1d2e 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayConfigTemplateService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayConfigTemplateService.cs @@ -19,18 +19,22 @@ public partial class CoreConfigV2rayService // Handle balancer and rules modifications (for multiple load scenarios) if (_coreConfig.routing?.balancers?.Count > 0) { - var balancer = _coreConfig.routing.balancers.First(); + var balancer = + _coreConfig.routing.balancers.FirstOrDefault(b => b.tag == Global.ProxyTag + Global.BalancerTagSuffix, null); // Modify existing rules in custom config - var rulesNode = fullConfigTemplateNode["routing"]?["rules"]; - if (rulesNode != null) + if (balancer != null) { - foreach (var rule in rulesNode.AsArray()) + var rulesNode = fullConfigTemplateNode["routing"]?["rules"]; + if (rulesNode != null) { - if (rule["outboundTag"]?.GetValue() == Global.ProxyTag) + foreach (var rule in rulesNode.AsArray()) { - rule.AsObject().Remove("outboundTag"); - rule["balancerTag"] = balancer.tag; + if (rule["outboundTag"]?.GetValue() == Global.ProxyTag) + { + rule.AsObject().Remove("outboundTag"); + rule["balancerTag"] = balancer.tag; + } } } } @@ -97,8 +101,8 @@ public partial class CoreConfigV2rayService continue; } } - else if ((!fullConfigTemplate.ProxyDetour.IsNullOrEmpty()) - && ((outbound.streamSettings?.sockopt?.dialerProxy.IsNullOrEmpty() ?? true) == true)) + else if (!fullConfigTemplate.ProxyDetour.IsNullOrEmpty() + && (outbound.streamSettings?.sockopt?.dialerProxy.IsNullOrEmpty() ?? true)) { var outboundAddress = outbound.settings?.servers?.FirstOrDefault()?.address ?? outbound.settings?.vnext?.FirstOrDefault()?.address diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs index 3d824102..1d3d1a37 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs @@ -39,9 +39,9 @@ public partial class CoreConfigV2rayService .ToList() ?? []; if (balancerTagList.Count > 0) { - foreach (var rulesItem in _coreConfig.routing.rules.Where(r => balancerTagList.Contains(r.outboundTag))) + foreach (var rulesItem in _coreConfig.routing.rules.Where(r => balancerTagList.Contains(r.outboundTag + Global.BalancerTagSuffix))) { - rulesItem.balancerTag = rulesItem.outboundTag; + rulesItem.balancerTag = rulesItem.outboundTag + Global.BalancerTagSuffix; rulesItem.outboundTag = null; } }