feat: Redirector Shadowsocks (no plugin) support

This commit is contained in:
ChsBuffer
2020-12-15 17:31:21 +08:00
parent 513d0b01a7
commit bcccb80ece
3 changed files with 17 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Threading.Tasks;
using Netch.Models;
using Netch.Servers.Shadowsocks;
using Netch.Servers.Socks5;
using Netch.Utils;
using nfapinet;
@@ -187,22 +188,29 @@ namespace Netch.Controllers
var offset = portType == PortType.UDP ? UdpNameListOffset : 0;
aio_dial((int) NameList.TYPE_TCPTYPE + offset, "Socks5");
if (controller.Server is Socks5 socks5)
{
aio_dial((int) NameList.TYPE_TCPTYPE + offset, "Socks5");
aio_dial((int) NameList.TYPE_TCPHOST + offset, $"{socks5.AutoResolveHostname()}:{socks5.Port}");
aio_dial((int) NameList.TYPE_TCPUSER + offset, socks5.Username ?? string.Empty);
aio_dial((int) NameList.TYPE_TCPPASS + offset, socks5.Password ?? string.Empty);
aio_dial((int) NameList.TYPE_TCPMETH + offset, string.Empty);
}
else if (controller.Server is Shadowsocks shadowsocks)
{
aio_dial((int) NameList.TYPE_TCPTYPE + offset, "Shadowsocks");
aio_dial((int) NameList.TYPE_TCPHOST + offset, $"{shadowsocks.AutoResolveHostname()}:{shadowsocks.Port}");
aio_dial((int) NameList.TYPE_TCPMETH + offset, shadowsocks.EncryptMethod ?? string.Empty);
aio_dial((int) NameList.TYPE_TCPPASS + offset, shadowsocks.Password ?? string.Empty);
}
else
{
aio_dial((int) NameList.TYPE_TCPTYPE + offset, "Socks5");
aio_dial((int) NameList.TYPE_TCPHOST + offset, $"127.0.0.1:{controller.Socks5LocalPort()}");
aio_dial((int) NameList.TYPE_TCPUSER + offset, string.Empty);
aio_dial((int) NameList.TYPE_TCPPASS + offset, string.Empty);
aio_dial((int) NameList.TYPE_TCPMETH + offset, string.Empty);
}
aio_dial((int) NameList.TYPE_TCPMETH + offset, string.Empty);
}
private void SetName(Mode mode)

View File

@@ -21,6 +21,10 @@ 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