From 315d4b75b29a550e5db115b75c67368589554ca2 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 14 May 2024 13:42:42 +0800 Subject: [PATCH] Optimize code --- v2rayN/v2rayN/Handler/CoreConfigSingbox.cs | 11 ++-- v2rayN/v2rayN/Handler/CoreConfigV2ray.cs | 17 ++++--- v2rayN/v2rayN/Sample/SampleClientConfig | 51 +------------------ .../v2rayN/Sample/SingboxSampleClientConfig | 9 +--- v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs | 2 +- .../Views/RoutingRuleDetailsWindow.xaml.cs | 2 +- .../v2rayN/Views/RoutingSettingWindow.xaml.cs | 2 +- 7 files changed, 20 insertions(+), 74 deletions(-) diff --git a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs index c07d16d0..c2cd926c 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs @@ -111,7 +111,8 @@ namespace v2rayN.Handler { try { - singboxConfig.inbounds.Clear(); + var listen = "::"; + singboxConfig.inbounds = []; if (!_config.tunModeItem.enableTun || (_config.tunModeItem.enableTun && _config.tunModeItem.enableExInbound)) { @@ -146,11 +147,11 @@ namespace v2rayN.Handler if (_config.inbound[0].newPort4LAN) { var inbound3 = GetInbound(inbound, EInboundProtocol.socks2, true); - inbound3.listen = "::"; + inbound3.listen = listen; singboxConfig.inbounds.Add(inbound3); var inbound4 = GetInbound(inbound, EInboundProtocol.http2, false); - inbound4.listen = "::"; + inbound4.listen = listen; singboxConfig.inbounds.Add(inbound4); //auth @@ -162,8 +163,8 @@ namespace v2rayN.Handler } else { - inbound.listen = "::"; - inbound2.listen = "::"; + inbound.listen = listen; + inbound2.listen = listen; } } } diff --git a/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs b/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs index 64e8e4da..03dc9190 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigV2ray.cs @@ -98,7 +98,8 @@ namespace v2rayN.Handler { try { - v2rayConfig.inbounds = new List(); + var listen = "0.0.0.0"; + v2rayConfig.inbounds = []; Inbounds4Ray? inbound = GetInbound(_config.inbound[0], EInboundProtocol.socks, true); v2rayConfig.inbounds.Add(inbound); @@ -112,11 +113,11 @@ namespace v2rayN.Handler if (_config.inbound[0].newPort4LAN) { var inbound3 = GetInbound(_config.inbound[0], EInboundProtocol.socks2, true); - inbound3.listen = "0.0.0.0"; + inbound3.listen = listen; v2rayConfig.inbounds.Add(inbound3); var inbound4 = GetInbound(_config.inbound[0], EInboundProtocol.http2, false); - inbound4.listen = "0.0.0.0"; + inbound4.listen = listen; v2rayConfig.inbounds.Add(inbound4); //auth @@ -131,8 +132,8 @@ namespace v2rayN.Handler } else { - inbound.listen = "0.0.0.0"; - inbound2.listen = "0.0.0.0"; + inbound.listen = listen; + inbound2.listen = listen; } } } @@ -143,18 +144,18 @@ namespace v2rayN.Handler return 0; } - private Inbounds4Ray? GetInbound(InItem inItem, EInboundProtocol protocol, bool bSocks) + private Inbounds4Ray GetInbound(InItem inItem, EInboundProtocol protocol, bool bSocks) { string result = Utils.GetEmbedText(Global.V2raySampleInbound); if (Utils.IsNullOrEmpty(result)) { - return null; + return new(); } var inbound = JsonUtils.Deserialize(result); if (inbound == null) { - return null; + return new(); } inbound.tag = protocol.ToString(); inbound.port = inItem.localPort + (int)protocol; diff --git a/v2rayN/v2rayN/Sample/SampleClientConfig b/v2rayN/v2rayN/Sample/SampleClientConfig index a33d9bd6..98c58e0e 100644 --- a/v2rayN/v2rayN/Sample/SampleClientConfig +++ b/v2rayN/v2rayN/Sample/SampleClientConfig @@ -4,56 +4,7 @@ "error": "Verror.log", "loglevel": "warning" }, - "inbounds": [{ - "tag": "tag1", - "port": 10808, - "protocol": "socks", - "listen": "127.0.0.1", - "settings": { - "auth": "noauth", - "udp": true - }, - "sniffing": { - "enabled": true, - "destOverride": [ - "http", - "tls" - ] - } - }, - { - "tag": "tag2", - "port": 10809, - "protocol": "http", - "listen": "127.0.0.1", - "settings": { - "allowTransparent": false - }, - "sniffing": { - "enabled": true, - "destOverride": [ - "http", - "tls" - ] - } - }, - { - "tag": "tag3", - "port": 10809, - "protocol": "http", - "listen": "127.0.0.1", - "settings": { - "allowTransparent": false - }, - "sniffing": { - "enabled": true, - "destOverride": [ - "http", - "tls" - ] - } - } - ], + "inbounds": [], "outbounds": [{ "tag": "proxy", "protocol": "vmess", diff --git a/v2rayN/v2rayN/Sample/SingboxSampleClientConfig b/v2rayN/v2rayN/Sample/SingboxSampleClientConfig index 8e34738f..f88422a1 100644 --- a/v2rayN/v2rayN/Sample/SingboxSampleClientConfig +++ b/v2rayN/v2rayN/Sample/SingboxSampleClientConfig @@ -3,14 +3,7 @@ "level": "debug", "timestamp": true }, - "inbounds": [ - { - "type": "socks", - "tag": "socks", - "listen": "127.0.0.1", - "listen_port": 10000 - } - ], + "inbounds": [], "outbounds": [ { "type": "vless", diff --git a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs index 7226aa93..fc224e96 100644 --- a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs @@ -51,7 +51,7 @@ namespace v2rayN.Views private void linkDnsObjectDoc_Click(object sender, RoutedEventArgs e) { - Utils.ProcessStart("https://www.v2fly.org/config/dns.html#dnsobject"); + Utils.ProcessStart("https://xtls.github.io/config/dns.html#dnsobject"); } private void linkDnsSingboxObjectDoc_Click(object sender, RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs index 94198939..e174995d 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs @@ -83,7 +83,7 @@ namespace v2rayN.Views private void linkRuleobjectDoc_Click(object sender, RoutedEventArgs e) { - Utils.ProcessStart("https://www.v2fly.org/config/routing.html#ruleobject"); + Utils.ProcessStart("https://xtls.github.io/config/routing.html#ruleobject"); } } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs index 7ff49a5a..0673b090 100644 --- a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs @@ -127,7 +127,7 @@ namespace v2rayN.Views private void linkdomainStrategy_Click(object sender, System.Windows.RoutedEventArgs e) { - Utils.ProcessStart("https://www.v2fly.org/config/routing.html"); + Utils.ProcessStart("https://xtls.github.io/config/routing.html"); } private void linkdomainStrategy4Singbox_Click(object sender, RoutedEventArgs e)