mirror of
https://github.com/netchx/netch.git
synced 2026-03-26 18:49:46 +08:00
refactor: mode handle supported server
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -33,12 +33,7 @@ namespace Netch.Models
|
||||
/// </summary>
|
||||
public int Type = 0;
|
||||
|
||||
public bool SupportSocks5Auth => Type switch
|
||||
{
|
||||
0 => true,
|
||||
_ => false
|
||||
};
|
||||
|
||||
/// 是否会转发 UDP
|
||||
public bool TestNatRequired => Type is 0 or 1 or 2;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user