Files
netch/Netch/Servers/ShadowsocksR/SSRController.cs
2021-03-19 03:56:54 +08:00

92 lines
2.4 KiB
C#

using System.Collections.Generic;
using System.IO;
using System.Text;
using Netch.Controllers;
using Netch.Models;
namespace Netch.Servers.ShadowsocksR
{
public class SSRController : Guard, IServerController
{
public override string MainFile { get; protected set; } = "ShadowsocksR.exe";
protected override IEnumerable<string> StartedKeywords { get; } = new[] {"listening at"};
protected override IEnumerable<string> StoppedKeywords { get; } = new[] {"Invalid config path", "usage"};
public override string Name { get; } = "ShadowsocksR";
public ushort? Socks5LocalPort { get; set; }
public string? LocalAddress { get; set; }
public void Start(in Server s, in Mode mode)
{
var server = (ShadowsocksR) s;
var command = new SSRParameter
{
s = server.AutoResolveHostname(),
p = server.Port,
k = server.Password,
m = server.EncryptMethod,
t = "120",
O = server.Protocol,
G = server.ProtocolParam,
o = server.OBFS,
g = server.OBFSParam,
b = this.LocalAddress(),
l = this.Socks5LocalPort(),
u = true
};
if (mode.BypassChina)
command.acl = $"{Path.GetFullPath(File.Exists(Global.UserACL) ? Global.UserACL : Global.BuiltinACL)}";
StartInstanceAuto(command.ToString());
}
[Verb]
class SSRParameter : ParameterBase
{
public string? s { get; set; }
public ushort? p { get; set; }
[Quote]
public string? k { get; set; }
public string? m { get; set; }
public string? t { get; set; }
[Optional]
public string? O { get; set; }
[Optional]
public string? G { get; set; }
[Optional]
public string? o { get; set; }
[Optional]
public string? g { get; set; }
public string? b { get; set; }
public ushort? l { get; set; }
public bool u { get; set; }
[Full]
[Quote]
[Optional]
public string? acl { get; set; }
}
public override void Stop()
{
StopInstance();
}
}
}