mirror of
https://github.com/netchx/netch.git
synced 2026-03-18 18:13:21 +08:00
refactor: Add IServerController.Server and use in ModeControllers
This commit is contained in:
@@ -32,7 +32,7 @@ namespace Netch.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
pPrivoxyController.Start(s, mode);
|
||||
pPrivoxyController.Start(MainController.ServerController.Server, mode);
|
||||
|
||||
if (mode.Type == 3) NativeMethods.SetGlobal($"127.0.0.1:{Global.Settings.HTTPLocalPort}", IEProxyExceptions);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace Netch.Controllers
|
||||
{
|
||||
public interface IServerController : IController
|
||||
{
|
||||
public Server Server { get; set; }
|
||||
|
||||
public ushort? Socks5LocalPort { get; set; }
|
||||
|
||||
public string LocalAddress { get; set; }
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Netch.Controllers
|
||||
|
||||
aio_dial((int) NameList.TYPE_ADDNAME, "NTT.exe");
|
||||
|
||||
if (s is Socks5 socks5)
|
||||
if (MainController.ServerController.Server is Socks5 socks5)
|
||||
{
|
||||
if (!socks5.Auth())
|
||||
{
|
||||
@@ -78,22 +78,18 @@ namespace Netch.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO Direct handled by redirector
|
||||
aio_dial((int) NameList.TYPE_TCPHOST, $"{socks5.AutoResolveHostname()}:{socks5.Port}");
|
||||
aio_dial((int) NameList.TYPE_UDPHOST, $"{socks5.AutoResolveHostname()}:{socks5.Port}");
|
||||
aio_dial((int) NameList.TYPE_, socks5.Username);
|
||||
aio_dial((int) NameList.TYPE_, socks5.Password);
|
||||
*/
|
||||
aio_dial((int) NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}");
|
||||
aio_dial((int) NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}");
|
||||
// TODO Socks5 Auth Direct handled by redirector
|
||||
aio_dial((int) NameList.TYPE_TCPHOST, $"127.0.0.1:{MainController.ServerController.Socks5LocalPort()}");
|
||||
aio_dial((int) NameList.TYPE_UDPHOST, $"127.0.0.1:{MainController.ServerController.Socks5LocalPort()}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aio_dial((int) NameList.TYPE_TCPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}");
|
||||
aio_dial((int) NameList.TYPE_UDPHOST, $"127.0.0.1:{Global.Settings.Socks5LocalPort}");
|
||||
aio_dial((int) NameList.TYPE_TCPHOST, $"127.0.0.1:{MainController.ServerController.Socks5LocalPort()}");
|
||||
aio_dial((int) NameList.TYPE_UDPHOST, $"127.0.0.1:{MainController.ServerController.Socks5LocalPort()}");
|
||||
}
|
||||
|
||||
|
||||
if (Global.Settings.ModifySystemDNS)
|
||||
{
|
||||
// 备份并替换系统 DNS
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Netch.Controllers
|
||||
public bool Start(Server s, Mode mode)
|
||||
{
|
||||
_savedMode = mode;
|
||||
_savedServer = s;
|
||||
_savedServer = MainController.ServerController.Server;
|
||||
|
||||
// 查询服务器 IP 地址
|
||||
_serverAddresses = DNS.Lookup(_savedServer.Hostname);
|
||||
@@ -82,8 +82,8 @@ namespace Netch.Controllers
|
||||
}
|
||||
|
||||
var argument = new StringBuilder();
|
||||
if (s is Socks5 socks5 && !socks5.Auth())
|
||||
argument.Append($"-proxyServer {_serverAddresses}:{s.Port} ");
|
||||
if (_savedServer is Socks5 socks5 && !socks5.Auth())
|
||||
argument.Append($"-proxyServer {_serverAddresses}:{_savedServer.Port} ");
|
||||
else
|
||||
argument.Append($"-proxyServer 127.0.0.1:{Global.Settings.Socks5LocalPort} ");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user