private static async Task <bool> StartServer(Server server, Mode mode) { if (server.IsSocks5()) { return(true); } ServerController = ServerHelper.GetUtilByTypeName(server.Type).GetController(); if (ServerController is Guard instanceController) { Utils.Utils.KillProcessByName(instanceController.MainFile); } PortCheckAndShowMessageBox(Global.Settings.Socks5LocalPort, "Socks5"); Global.MainForm.StatusText(i18N.TranslateFormat("Starting {0}", ServerController.Name)); if (await Task.Run(() => ServerController.Start(server, mode))) { UsingPorts.Add(StatusPortInfoText.Socks5Port = Global.Settings.Socks5LocalPort); StatusPortInfoText.ShareLan = Global.Settings.LocalAddress == "0.0.0.0"; return(true); } return(false); }
private static async Task <bool> StartMode(Server server, Mode mode) { var port = 0; switch (mode.Type) { case 0: ModeController = new NFController(); PortCheckAndShowMessageBox(port = Global.Settings.RedirectorTCPPort, "Redirector TCP"); break; case 1: case 2: ModeController = new TUNTAPController(); break; case 3: case 5: ModeController = new HTTPController(); PortCheckAndShowMessageBox(port = Global.Settings.HTTPLocalPort, "HTTP"); break; case 4: return(true); default: Logging.Error("Unknown mode type"); return(false); } Global.MainForm.StatusText(i18N.Translate("Starting ", ModeController.Name)); if (await Task.Run(() => ModeController.Start(server, mode))) { switch (mode.Type) { case 3: case 5: StatusPortInfoText.HttpPort = port; break; } UsingPorts.Add(port); return(true); } return(false); }
private static async Task <bool> StartServer(Server server, Mode mode) { switch (server.Type) { case "Socks5": return(true); case "SS": EncryptedProxyController = new SSController(); break; case "SSR": EncryptedProxyController = new SSRController(); break; case "VMess": EncryptedProxyController = new VMessController(); break; case "Trojan": EncryptedProxyController = new TrojanController(); break; default: Logging.Error("未知服务器类型"); return(false); } Utils.Utils.KillProcessByName(EncryptedProxyController.MainFile); PortCheckAndShowMessageBox(Global.Settings.Socks5LocalPort, "Socks5"); Global.MainForm.StatusText(i18N.Translate("Starting ", EncryptedProxyController.Name)); if (await Task.Run(() => EncryptedProxyController.Start(server, mode))) { UsingPorts.Add(StatusPortInfoText.Socks5Port = Global.Settings.Socks5LocalPort); StatusPortInfoText.ShareLan = Global.Settings.LocalAddress == "0.0.0.0"; return(true); } return(false); }