mirror of
https://github.com/netchx/netch.git
synced 2026-03-14 17:43:18 +08:00
37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using System.Net;
|
|
using System.Text.Json;
|
|
using Netch.Controllers;
|
|
using Netch.Interfaces;
|
|
using Netch.Models;
|
|
|
|
namespace Netch.Servers;
|
|
|
|
public class V2rayController : Guard, IServerController
|
|
{
|
|
public V2rayController() : base("v2ray-sn.exe")
|
|
{
|
|
if (!Global.Settings.V2RayConfig.XrayCone)
|
|
Instance.StartInfo.Environment["XRAY_CONE_DISABLED"] = "true";
|
|
}
|
|
|
|
protected override IEnumerable<string> StartedKeywords => new[] { "started" };
|
|
|
|
protected override IEnumerable<string> FailedKeywords => new[] { "config file not readable", "failed to" };
|
|
|
|
public override string Name => "V2Ray (SagerNet)";
|
|
|
|
public ushort? Socks5LocalPort { get; set; }
|
|
|
|
public string? LocalAddress { get; set; }
|
|
|
|
public virtual async Task<Socks5Server> StartAsync(Server s)
|
|
{
|
|
await using (var fileStream = new FileStream(Constants.TempConfig, FileMode.Create, FileAccess.Write, FileShare.Read))
|
|
{
|
|
await JsonSerializer.SerializeAsync(fileStream, await V2rayConfigUtils.GenerateClientConfigAsync(s), Global.NewCustomJsonSerializerOptions());
|
|
}
|
|
|
|
await StartGuardAsync("-config ..\\data\\last.json");
|
|
return new Socks5Server(IPAddress.Loopback.ToString(), this.Socks5LocalPort(), s.Hostname);
|
|
}
|
|
} |