public static IEnumerable <Server> ParseVUri(string text) { var scheme = ShareLink.GetUriScheme(text).ToLower(); var server = scheme switch { "vmess" => new VMess.VMess(), "vless" => new VLESS.VLESS(), _ => throw new ArgumentOutOfRangeException() }; if (text.Contains("#")) { server.Remark = Uri.UnescapeDataString(text.Split('#')[1]); text = text.Split('#')[0]; } if (text.Contains("?")) { var parameter = HttpUtility.ParseQueryString(text.Split('?')[1]); text = text.Substring(0, text.IndexOf("?", StringComparison.Ordinal)); server.TransferProtocol = parameter.Get("type") ?? "tcp"; server.EncryptMethod = parameter.Get("encryption") ?? scheme switch { "vless" => "none", _ => "auto" }; switch (server.TransferProtocol) { case "tcp": break; case "kcp": server.FakeType = parameter.Get("headerType") ?? "none"; server.Path = Uri.UnescapeDataString(parameter.Get("seed") ?? ""); break; case "ws": server.Path = Uri.UnescapeDataString(parameter.Get("path") ?? "/"); server.Host = Uri.UnescapeDataString(parameter.Get("host") ?? ""); break; case "h2": server.Path = Uri.UnescapeDataString(parameter.Get("path") ?? "/"); server.Host = Uri.UnescapeDataString(parameter.Get("host") ?? ""); break; case "quic": server.QUICSecure = parameter.Get("quicSecurity") ?? "none"; server.QUICSecret = parameter.Get("key") ?? ""; server.FakeType = parameter.Get("headerType") ?? "none"; break; } server.TLSSecureType = parameter.Get("security") ?? "none"; if (server.TLSSecureType != "none") { server.Host = parameter.Get("sni") ?? ""; if (server.TLSSecureType == "xtls") { ((VLESS.VLESS)server).Flow = parameter.Get("flow") ?? ""; } } } var finder = new Regex(@$ "^{scheme}://(?<guid>.+?)@(?<server>.+):(?<port>\d+)"); var match = finder.Match(text.Split('?')[0]); if (!match.Success) { throw new FormatException(); } server.UserID = match.Groups["guid"].Value; server.Hostname = match.Groups["server"].Value; server.Port = ushort.Parse(match.Groups["port"].Value); return(new[] { server }); }