Exemplo n.º 1
0
        private static Server ParseNetchUri(string text)
        {
            try
            {
                text = text.Substring(8);

                var NetchLink = (JObject)JsonConvert.DeserializeObject(URLSafeBase64Decode(text));
                if (NetchLink == null)
                {
                    return(null);
                }

                if (string.IsNullOrEmpty((string)NetchLink["Hostname"]))
                {
                    return(null);
                }

                if (!ushort.TryParse((string)NetchLink["Port"], out _))
                {
                    return(null);
                }

                var type = (string)NetchLink["Type"];
                var s    = ServerHelper.GetUtilByTypeName(type).ParseJObject(NetchLink);
                return(ServerHelper.GetUtilByTypeName(s.Type).CheckServer(s) ? s : null);
            }
            catch (Exception e)
            {
                Logging.Warning(e.ToString());
                return(null);
            }
        }
Exemplo n.º 2
0
        private static IEnumerable <Server> ParseUri(string text)
        {
            var list = new List <Server>();

            try
            {
                if (text.StartsWith("tg://socks?") || text.StartsWith("https://t.me/socks?"))
                {
                    list.AddRange(ServerHelper.GetUtilByTypeName("Socks5").ParseUri(text));
                }
                else if (text.StartsWith("Netch://"))
                {
                    list.Add(ParseNetchUri(text));
                }
                else
                {
                    var scheme = GetUriScheme(text);
                    var util   = ServerHelper.GetUtilByUriScheme(scheme);
                    if (util != null)
                    {
                        list.AddRange(util.ParseUri(text));
                    }
                    else
                    {
                        Logging.Warning($"无法处理 {scheme} 协议订阅链接");
                    }
                }
            }
            catch (Exception e)
            {
                Logging.Error(e.ToString());
            }

            foreach (var node in list)
            {
                node.Remark = RemoveEmoji(node.Remark);
            }

            return(list.Where(s => s != null));
        }
Exemplo n.º 3
0
 public static string GetShareLink(Server server)
 {
     return(ServerHelper.GetUtilByTypeName(server.Type).GetShareLink(server));
 }