diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 9dcf9ef9..065f9051 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -1277,26 +1277,12 @@ namespace v2rayN.Forms } ConfigHandler.SaveConfig(ref config, false); - DisplayToolStatus(); - } - private void DisplayToolStatus() - { - StringBuilder sb = new StringBuilder(); - sb.Append($"{Global.InboundSocks} {Global.Loopback}:{config.GetLocalPort(Global.InboundSocks)}"); - sb.Append(" | "); - sb.Append($"{Global.InboundHttp} {Global.Loopback}:{config.GetLocalPort(Global.InboundHttp)}"); - - if (config.sysProxyType == ESysProxyType.ForcedChange) - { - sb.Append(" | "); - sb.Append($"{ResUI.SystemProxy} {Global.Loopback}:{config.GetLocalPort(Global.InboundHttp2)}"); - } - - mainMsgControl.SetToolSslInfo("inbound", sb.ToString()); + mainMsgControl.DisplayToolStatus(config); notifyMain.Icon = MainFormHandler.Instance.GetNotifyIcon(config, this.Icon); } + #endregion diff --git a/v2rayN/v2rayN/Forms/MainMsgControl.cs b/v2rayN/v2rayN/Forms/MainMsgControl.cs index 1f948751..85a4bdde 100644 --- a/v2rayN/v2rayN/Forms/MainMsgControl.cs +++ b/v2rayN/v2rayN/Forms/MainMsgControl.cs @@ -9,6 +9,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; using v2rayN.Base; +using v2rayN.Mode; using v2rayN.Resx; namespace v2rayN.Forms @@ -78,6 +79,32 @@ namespace v2rayN.Forms }); } + public void DisplayToolStatus(Config config) + { + StringBuilder sb = new StringBuilder(); + sb.Append($"{ResUI.LabLocal}:"); + sb.Append($"[{Global.InboundSocks}:{config.GetLocalPort(Global.InboundSocks)}]"); + sb.Append(" | "); + if (config.sysProxyType == ESysProxyType.ForcedChange) + { + sb.Append($"[{Global.InboundHttp}({ResUI.SystemProxy}):{config.GetLocalPort(Global.InboundHttp)}]"); + } + else + { + sb.Append($"[{Global.InboundHttp}:{config.GetLocalPort(Global.InboundHttp)}]"); + } + + if (config.inbound[0].allowLANConn) + { + sb.Append($" {ResUI.LabLAN}:"); + sb.Append($"[{Global.InboundSocks}:{config.GetLocalPort(Global.InboundSocks2)}]"); + sb.Append(" | "); + sb.Append($"[{Global.InboundHttp}:{config.GetLocalPort(Global.InboundHttp2)}]"); + } + + SetToolSslInfo("inbound", sb.ToString()); + } + public void SetToolSslInfo(string type, string value) { switch (type) diff --git a/v2rayN/v2rayN/Global.cs b/v2rayN/v2rayN/Global.cs index a7fa67ae..42cbca68 100644 --- a/v2rayN/v2rayN/Global.cs +++ b/v2rayN/v2rayN/Global.cs @@ -65,9 +65,10 @@ namespace v2rayN /// public const string v2raySampleHttpresponseFileName = "v2rayN.Sample.SampleHttpresponse.txt"; - public const string CustomRoutingFileName = "v2rayN.Sample.custom_routing_"; + public const string v2raySampleInbound = "v2rayN.Sample.SampleInbound.txt"; + /// /// 默认加密方式 @@ -112,6 +113,7 @@ namespace v2rayN public const string InboundSocks = "socks"; public const string InboundHttp = "http"; + public const string InboundSocks2 = "socks2"; public const string InboundHttp2 = "http2"; public const string Loopback = "127.0.0.1"; public const string InboundAPITagName = "api"; diff --git a/v2rayN/v2rayN/Handler/DownloadHandle.cs b/v2rayN/v2rayN/Handler/DownloadHandle.cs index 0e4c8fd7..50ea02c1 100644 --- a/v2rayN/v2rayN/Handler/DownloadHandle.cs +++ b/v2rayN/v2rayN/Handler/DownloadHandle.cs @@ -172,7 +172,7 @@ namespace v2rayN.Handler { if (webProxy == null) { - var httpPort = LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp2); + var httpPort = LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp); webProxy = new WebProxy(Global.Loopback, httpPort); } @@ -233,7 +233,7 @@ namespace v2rayN.Handler { return null; } - var httpPort = LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp2); + var httpPort = LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp); var webProxy = new WebProxy(Global.Loopback, httpPort); if (RunAvailabilityCheck(webProxy) > 0) { diff --git a/v2rayN/v2rayN/Handler/SysProxyHandle.cs b/v2rayN/v2rayN/Handler/SysProxyHandle.cs index 326b2f78..ba752ca1 100644 --- a/v2rayN/v2rayN/Handler/SysProxyHandle.cs +++ b/v2rayN/v2rayN/Handler/SysProxyHandle.cs @@ -59,7 +59,7 @@ namespace v2rayN.Handler try { - int port = config.GetLocalPort(Global.InboundHttp2); + int port = config.GetLocalPort(Global.InboundHttp); if (port <= 0) { return false; diff --git a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs index 45b214d3..fdf8f000 100644 --- a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs @@ -146,48 +146,35 @@ namespace v2rayN.Handler { try { - Inbounds inbound = v2rayConfig.inbounds[0]; - inbound.tag = Global.InboundSocks; - inbound.port = config.inbound[0].localPort; - inbound.protocol = config.inbound[0].protocol; - if (config.inbound[0].allowLANConn) - { - inbound.listen = "0.0.0.0"; - } - else - { - inbound.listen = Global.Loopback; - } - //udp - inbound.settings.udp = config.inbound[0].udpEnabled; - inbound.sniffing.enabled = config.inbound[0].sniffingEnabled; + v2rayConfig.inbounds = new List(); + + Inbounds inbound = GetInbound(config.inbound[0], Global.InboundSocks, 0, true); + v2rayConfig.inbounds.Add(inbound); //http - Inbounds inbound2 = v2rayConfig.inbounds[1]; - inbound2.tag = Global.InboundHttp; - inbound2.port = config.GetLocalPort(Global.InboundHttp); - inbound2.protocol = Global.InboundHttp; - inbound2.listen = inbound.listen; - inbound2.settings.allowTransparent = false; - inbound2.sniffing.enabled = inbound.sniffing.enabled; + Inbounds inbound2 = GetInbound(config.inbound[0], Global.InboundHttp, 1, false); + v2rayConfig.inbounds.Add(inbound2); - //auth - if (!Utils.IsNullOrEmpty(config.inbound[0].user) && !Utils.IsNullOrEmpty(config.inbound[0].pass)) + if (config.inbound[0].allowLANConn) { - inbound.settings.auth = "password"; - inbound.settings.accounts = new List { new AccountsItem() { user = config.inbound[0].user, pass = config.inbound[0].pass } }; - inbound2.settings.auth = "password"; - inbound2.settings.accounts = new List { new AccountsItem() { user = config.inbound[0].user, pass = config.inbound[0].pass } }; - } + Inbounds inbound3 = GetInbound(config.inbound[0], Global.InboundSocks2, 2, true); + v2rayConfig.inbounds.Add(inbound3); - //http Loopback - Inbounds inbound3 = v2rayConfig.inbounds[2]; - inbound3.tag = Global.InboundHttp2; - inbound3.port = config.GetLocalPort(Global.InboundHttp2); - inbound3.protocol = Global.InboundHttp; - inbound3.listen = Global.Loopback; - inbound3.settings.allowTransparent = false; - inbound3.sniffing.enabled = inbound.sniffing.enabled; + Inbounds inbound4 = GetInbound(config.inbound[0], Global.InboundHttp2, 3, false); + v2rayConfig.inbounds.Add(inbound4); + + //auth + if (!Utils.IsNullOrEmpty(config.inbound[0].user) && !Utils.IsNullOrEmpty(config.inbound[0].pass)) + { + inbound3.listen = "0.0.0.0"; + inbound3.settings.auth = "password"; + inbound3.settings.accounts = new List { new AccountsItem() { user = config.inbound[0].user, pass = config.inbound[0].pass } }; + + inbound4.listen = "0.0.0.0"; + inbound4.settings.auth = "password"; + inbound4.settings.accounts = new List { new AccountsItem() { user = config.inbound[0].user, pass = config.inbound[0].pass } }; + } + } } catch { @@ -195,6 +182,28 @@ namespace v2rayN.Handler return 0; } + private static Inbounds GetInbound(InItem inItem, string tag, int offset, bool bSocks) + { + string result = Utils.GetEmbedText(Global.v2raySampleInbound); + if (Utils.IsNullOrEmpty(result)) + { + return null; + } + + var inbound = Utils.FromJson(result); + if (inbound == null) + { + return null; + } + inbound.tag = tag; + inbound.port = inItem.localPort + offset; + inbound.protocol = bSocks ? Global.InboundSocks : Global.InboundHttp; + inbound.settings.udp = inItem.udpEnabled; + inbound.sniffing.enabled = inItem.sniffingEnabled; + + return inbound; + } + /// /// 路由 /// @@ -958,7 +967,7 @@ namespace v2rayN.Handler break; case ECoreType.clash: case ECoreType.clash_meta: - fileContent.Add($"port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp2)}"); + fileContent.Add($"port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp)}"); fileContent.Add($"socks-port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundSocks)}"); break; } diff --git a/v2rayN/v2rayN/Mode/Config.cs b/v2rayN/v2rayN/Mode/Config.cs index e99e7be3..20913046 100644 --- a/v2rayN/v2rayN/Mode/Config.cs +++ b/v2rayN/v2rayN/Mode/Config.cs @@ -208,27 +208,27 @@ namespace v2rayN.Mode public int GetLocalPort(string protocol) { - if (protocol == Global.InboundHttp) + int localPort = inbound.FirstOrDefault(t => t.protocol == Global.InboundSocks).localPort; + + if (protocol == Global.InboundSocks) { - return GetLocalPort(Global.InboundSocks) + 1; + return localPort; + } + else if (protocol == Global.InboundHttp) + { + return localPort + 1; + } + else if (protocol == Global.InboundSocks2) + { + return localPort + 2; } else if (protocol == Global.InboundHttp2) { - return GetLocalPort(Global.InboundSocks) + 2; + return localPort + 3; } else if (protocol == "speedtest") { - return GetLocalPort(Global.InboundSocks) + 103; - } - - int localPort = 0; - foreach (InItem inItem in inbound) - { - if (inItem.protocol.Equals(protocol)) - { - localPort = inItem.localPort; - break; - } + return localPort + 103; } return localPort; } diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index 83635795..431ec5ea 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -321,6 +321,24 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 LAN 的本地化字符串。 + /// + internal static string LabLAN { + get { + return ResourceManager.GetString("LabLAN", resourceCulture); + } + } + + /// + /// 查找类似 Local 的本地化字符串。 + /// + internal static string LabLocal { + get { + return ResourceManager.GetString("LabLocal", resourceCulture); + } + } + /// /// 查找类似 Address 的本地化字符串。 /// diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index a3224bdd..e6178559 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -463,4 +463,10 @@ Too many servers, please open the main interface + + LAN + + + Local + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index a5b92d97..0f3a4ac1 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -463,4 +463,10 @@ 服务器太多,请打开主界面操作 + + 局域网 + + + 本地 + \ No newline at end of file diff --git a/v2rayN/v2rayN/Sample/SampleInbound.txt b/v2rayN/v2rayN/Sample/SampleInbound.txt new file mode 100644 index 00000000..a21452dd --- /dev/null +++ b/v2rayN/v2rayN/Sample/SampleInbound.txt @@ -0,0 +1,18 @@ +{ + "tag": "tag1", + "port": 10808, + "protocol": "socks", + "listen": "127.0.0.1", + "settings": { + "auth": "noauth", + "udp": true, + "allowTransparent": false + }, + "sniffing": { + "enabled": true, + "destOverride": [ + "http", + "tls" + ] + } +} \ No newline at end of file diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj index 8b20ff90..e5c58aef 100644 --- a/v2rayN/v2rayN/v2rayN.csproj +++ b/v2rayN/v2rayN/v2rayN.csproj @@ -474,6 +474,7 @@ +