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 StartedKeywords => new[] { "started" }; protected override IEnumerable 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 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("run -c ..\\data\\last.json"); return new Socks5Server(IPAddress.Loopback.ToString(), this.Socks5LocalPort(), s.Hostname); } }