diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index 4f964907..cda8281a 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -64,12 +64,20 @@ namespace Netch.Controllers try { - if (!await Task.Run(() => StartServer(server, mode, ref _serverController))) + if (!ModeHelper.SkipServerController(server, mode)) { - throw new StartFailedException(); - } + if (!await Task.Run(() => StartServer(server, mode, ref _serverController))) + { + throw new StartFailedException(); + } - StatusPortInfoText.UpdateShareLan(); + StatusPortInfoText.UpdateShareLan(); + } + else + { + _serverController = ServerHelper.GetUtilByTypeName(server.Type).GetController(); + _serverController.Server = server; + } if (!await StartMode(server, mode)) { @@ -134,7 +142,7 @@ namespace Netch.Controllers if (server is Socks5 socks5) { - if (socks5.Auth() && !mode.SupportSocks5Auth) + if (socks5.Auth()) UsingPorts.Add(StatusPortInfoText.Socks5Port = controller.Socks5LocalPort()); } else diff --git a/Netch/Models/Mode.cs b/Netch/Models/Mode.cs index 7a781013..d6b688b7 100644 --- a/Netch/Models/Mode.cs +++ b/Netch/Models/Mode.cs @@ -33,12 +33,7 @@ namespace Netch.Models /// public int Type = 0; - public bool SupportSocks5Auth => Type switch - { - 0 => true, - _ => false - }; - + /// 是否会转发 UDP public bool TestNatRequired => Type is 0 or 1 or 2; /// diff --git a/Netch/Servers/Shadowsocks/SSController.cs b/Netch/Servers/Shadowsocks/SSController.cs index eb0fc5a8..5681fd9f 100644 --- a/Netch/Servers/Shadowsocks/SSController.cs +++ b/Netch/Servers/Shadowsocks/SSController.cs @@ -22,9 +22,6 @@ namespace Netch.Servers.Shadowsocks Server = s; var server = (Shadowsocks) s; - if (mode.Type == 0 && !server.HasPlugin()) - return true; - DllFlag = Global.Settings.BootShadowsocksFromDLL && mode.Type is 0 or 1 or 2 && !server.HasPlugin(); //从DLL启动Shaowsocks diff --git a/Netch/Servers/Socks5/S5Controller.cs b/Netch/Servers/Socks5/S5Controller.cs index 7c7d2142..523cc3ce 100644 --- a/Netch/Servers/Socks5/S5Controller.cs +++ b/Netch/Servers/Socks5/S5Controller.cs @@ -14,7 +14,7 @@ namespace Netch.Servers.Socks5 { Server = s; var server = (Socks5) s; - if (server.Auth() && !mode.SupportSocks5Auth) + if (server.Auth()) { File.WriteAllText("data\\last.json", V2rayConfigUtils.GenerateClientConfig(s, mode)); if (StartInstanceAuto("-config ..\\data\\last.json")) diff --git a/Netch/Utils/ModeHelper.cs b/Netch/Utils/ModeHelper.cs index 4c6152ff..fcf90bc9 100644 --- a/Netch/Utils/ModeHelper.cs +++ b/Netch/Utils/ModeHelper.cs @@ -5,6 +5,8 @@ using System.Linq; using Netch.Controllers; using Netch.Forms; using Netch.Models; +using Netch.Servers.Shadowsocks; +using Netch.Servers.Socks5; namespace Netch.Utils { @@ -135,6 +137,20 @@ namespace Netch.Utils Global.MainForm.InitMode(); } + public static bool SkipServerController(Server server, Mode mode) + { + return mode.Type switch + { + 0 => server switch + { + Socks5 => true, + Shadowsocks shadowsocks when !shadowsocks.HasPlugin() => true, + _ => false + }, + _ => false + }; + } + public static IModeController GetModeControllerByType(int type, out ushort? port, out string portName, out PortType portType) { IModeController modeController;