From 88d79cb1398180413fd73a0ad6eb4a862a59df42 Mon Sep 17 00:00:00 2001 From: ian gong <200804632@qq.com> Date: Sun, 22 May 2022 16:25:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8C=87=E5=AE=9A=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E8=B7=AF=E7=94=B1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/RoutingRuleSettingDetailsForm.cs | 11 ++++ v2rayN/v2rayN/Handler/V2rayConfigHandler.cs | 59 +++++++++++++++++-- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/v2rayN/v2rayN/Forms/RoutingRuleSettingDetailsForm.cs b/v2rayN/v2rayN/Forms/RoutingRuleSettingDetailsForm.cs index ef1e950e..ef868cbe 100644 --- a/v2rayN/v2rayN/Forms/RoutingRuleSettingDetailsForm.cs +++ b/v2rayN/v2rayN/Forms/RoutingRuleSettingDetailsForm.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Collections.Generic; using System.Windows.Forms; using v2rayN.Base; @@ -22,6 +23,7 @@ namespace v2rayN.Forms private void RoutingRuleSettingDetailsForm_Load(object sender, EventArgs e) { + LoadTagData(); if (Utils.IsNullOrEmpty(rulesItem.outboundTag)) { ClearBind(); @@ -32,6 +34,15 @@ namespace v2rayN.Forms } } + private void LoadTagData() + { + + //ID列表 // 有重复时,以第一个为准 + + var list = config.vmess.Select(v => "[" + v.remarks + "]" + "(" + v.address + ":" + v.port + ")"); + cmbOutboundTag.Items.AddRange(list.ToArray()); + } + private void EndBindingData() { if (rulesItem != null) diff --git a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs index 5c48c630..a564df63 100644 --- a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs @@ -73,6 +73,7 @@ namespace v2rayN.Handler //outbound outbound(node, ref v2rayConfig); + extraTagOutbound(config, ref v2rayConfig); //dns dns(config, ref v2rayConfig); @@ -147,7 +148,7 @@ namespace v2rayN.Handler try { v2rayConfig.inbounds = new List(); - + //socks Inbounds inbound = GetInbound(config.inbound[0], Global.InboundSocks, 0, true); v2rayConfig.inbounds.Add(inbound); @@ -175,6 +176,15 @@ namespace v2rayN.Handler inbound4.settings.accounts = new List { new AccountsItem() { user = config.inbound[0].user, pass = config.inbound[0].pass } }; } } + + //自定义TAG + //var offset = 4; + //var vmessList = config.vmess.Where(v => v.tag != null && v.tag.Trim().Length > 0).ToList(); + //foreach (var inboundConfig in vmessList) + //{ + // v2rayConfig.inbounds.Add(GetInbound(config.inbound[0], "TAG-SOCKS-" + inboundConfig.tag, offset++, true)); + // v2rayConfig.inbounds.Add(GetInbound(config.inbound[0], "TAG-HTTP-" + inboundConfig.tag, offset++, false)); + //} } catch { @@ -204,6 +214,7 @@ namespace v2rayN.Handler return inbound; } + /// /// 路由 /// @@ -228,7 +239,7 @@ namespace v2rayN.Handler { if (item.enabled) { - routingUserRule(item, ref v2rayConfig); + routingUserRule(item, ref v2rayConfig, config); } } } @@ -240,7 +251,7 @@ namespace v2rayN.Handler { foreach (var item in lockedItem.rules) { - routingUserRule(item, ref v2rayConfig); + routingUserRule(item, ref v2rayConfig, config); } } } @@ -251,10 +262,11 @@ namespace v2rayN.Handler } return 0; } - private static int routingUserRule(RulesItem rules, ref V2rayConfig v2rayConfig) + private static int routingUserRule(RulesItem rules, ref V2rayConfig v2rayConfig, Config config) { try { + if (rules == null) { return 0; @@ -351,18 +363,55 @@ namespace v2rayN.Handler return 0; } + private static int extraTagOutbound(Config config, ref V2rayConfig v2rayConfig) + { + try + { + var vmessList = config.vmess.ToList(); + var idSet = new HashSet();// 去重 ,有重复的,按第一个为准 + foreach (var v in vmessList) + { + var id = "[" + v.remarks + "]" + "(" + v.address + ":" + v.port + ")"; + if (idSet.Contains(id)) + { + continue; + } + else + { + outbound(v, ref v2rayConfig, true, id); + idSet.Add(id); + } + } + } + catch + { + + } + return 0; + } + /// /// vmess协议服务器配置 /// /// /// /// - private static int outbound(VmessItem node, ref V2rayConfig v2rayConfig) + private static int outbound(VmessItem node, ref V2rayConfig v2rayConfig, bool extraTagOutbounds = false, string extraTagOutboundTag = "") { try { var config = LazyConfig.Instance.GetConfig(); Outbounds outbound = v2rayConfig.outbounds[0]; + if (extraTagOutbounds) + { + string result = Utils.GetEmbedText(SampleClient); + //转成Json + V2rayConfig sampleV2rayConfig = Utils.FromJson(result); + outbound = sampleV2rayConfig.outbounds[0]; + //取得一个示例实例 + outbound.tag = extraTagOutboundTag; + v2rayConfig.outbounds.Add(outbound); + } if (node.configType == EConfigType.Vmess) { VnextItem vnextItem;