diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 88ba98b6a1..101ef86a0a 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -82,7 +82,7 @@ public static async Task Start(Server server, Mode mode) throw new StartFailedException(); } - if (mode.TestNatRequired) + if (mode.TestNatRequired()) NatTest(); return true; diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index c5a6cb9f9c..fcec9f0704 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -366,21 +366,23 @@ private void EditModePictureBox_Click(object sender, EventArgs e) return; } - var selectedMode = (Models.Mode) ModeComboBox.SelectedItem; - switch (selectedMode.Type) + var mode = (Models.Mode) ModeComboBox.SelectedItem; + if (ModifierKeys == Keys.Control) + { + Utils.Utils.Open(ModeHelper.GetFullPath(mode.RelativePath)); + return; + } + + switch (mode.Type) { case 0: - { Hide(); - new Process(selectedMode).ShowDialog(); + new Process(mode).ShowDialog(); Show(); break; - } default: - { - MessageBoxX.Show($"Current not support editing {selectedMode.TypeToString()} Mode"); + Utils.Utils.Open(ModeHelper.GetFullPath(mode.RelativePath)); break; - } } } diff --git a/Netch/Models/Mode.cs b/Netch/Models/Mode.cs index d6b688b730..8e0b92e0af 100644 --- a/Netch/Models/Mode.cs +++ b/Netch/Models/Mode.cs @@ -33,9 +33,6 @@ public class Mode /// public int Type = 0; - /// 是否会转发 UDP - public bool TestNatRequired => Type is 0 or 1 or 2; - /// /// 绕过中国(0. 不绕过 1. 绕过) /// @@ -120,44 +117,15 @@ public override string ToString() /// 模式文件字符串 public string ToFileString() { - StringBuilder fileString = new StringBuilder(); - - switch (Type) - { - case 0: - // 进程模式 - fileString.Append($"# {Remark}"); - break; - case 1: - // TUN/TAP 规则内 IP CIDR,无 Bypass China 设置 - fileString.Append($"# {Remark}, {Type}, 0"); - break; - default: - fileString.Append($"# {Remark}, {Type}, {(BypassChina ? 1 : 0)}"); - break; - } - - if (Rule.Any()) - { - fileString.Append(Global.EOF); - fileString.Append(string.Join(Global.EOF, Rule)); - } - - return fileString.ToString(); + return $"# {Remark}, {Type}, {(BypassChina ? 1 : 0)}{Global.EOF}{string.Join(Global.EOF, Rule)}"; } + } + public static class ModeExtension + { + /// 是否会转发 UDP + public static bool TestNatRequired(this Mode mode) => mode.Type is 0 or 1 or 2; - public string TypeToString() - { - return Type switch - { - 0 => "Process", - 1 => "TUNTAP", - 2 => "TUNTAP", - 3 => "SYSTEM", - 4 => "S5", - 5 => "S5+HTTP", - _ => "ERROR", - }; - } + /// Socks5 分流是否能被有效实施 + public static bool ClientRouting(this Mode mode) => mode.Type is not 1 or 2; } } \ No newline at end of file diff --git a/Netch/Servers/VMess/Utils/V2rayConfigUtils.cs b/Netch/Servers/VMess/Utils/V2rayConfigUtils.cs index fe9d53972c..daff8e9853 100644 --- a/Netch/Servers/VMess/Utils/V2rayConfigUtils.cs +++ b/Netch/Servers/VMess/Utils/V2rayConfigUtils.cs @@ -80,6 +80,7 @@ private static void routing(Server server, Mode mode, ref V2rayConfig v2rayConfi switch (mode.Type) { case 0: + directRuleObject.ip.Add("geoip:cn"); break; case 1: case 2: diff --git a/Netch/Utils/ModeHelper.cs b/Netch/Utils/ModeHelper.cs index 31d7fa50ab..4a43f1df82 100644 --- a/Netch/Utils/ModeHelper.cs +++ b/Netch/Utils/ModeHelper.cs @@ -68,17 +68,19 @@ private static void LoadModeFile(string fullName) if (i == 0) { + if (text.First() != '#') + return; try { - var splited = text.Substring(text.IndexOf('#') + 1).Split(',').Select(s => s.Trim()).ToArray(); + var splited = text.Substring(1).Split(',').Select(s => s.Trim()).ToArray(); mode.Remark = splited[0]; - var result = int.TryParse(splited.ElementAtOrDefault(1), out var type); - mode.Type = result ? type : 0; + var typeResult = int.TryParse(splited.ElementAtOrDefault(1), out var type); + mode.Type = typeResult ? type : 0; - var result1 = int.TryParse(splited.ElementAtOrDefault(2), out var bypassChina); - mode.BypassChina = result1 && bypassChina == 1; + var bypassChinaResult = int.TryParse(splited.ElementAtOrDefault(2), out var bypassChina); + mode.BypassChina = mode.ClientRouting() && bypassChinaResult && bypassChina == 1; } catch { @@ -137,6 +139,7 @@ public static void Delete(Mode mode) Global.MainForm.InitMode(); } + public static bool SkipServerController(Server server, Mode mode) { return mode.Type switch