mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-19 08:04:40 +03:00
677e81f9a7
* Refactor * Add hysteria2 bandwidth and hop interval support * Upgrade config version and rename * Refactor id and security * Refactor flow * Fix hy2 bbr * Fix warning CS0618 * Remove unused code * Fix hy2 migrate * Fix * Refactor * Refactor ProfileItem protocol extra handling * Refactor, use record instead of class * Hy2 SalamanderPass * Fix Tuic * Fix group * Fix Tuic * Fix hy2 Brutal Bandwidth * Clean Code * Fix * Support interval range * Add Username --------- Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com>
61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
namespace ServiceLib.Handler.Fmt;
|
|
|
|
public class VLESSFmt : BaseFmt
|
|
{
|
|
public static ProfileItem? Resolve(string str, out string msg)
|
|
{
|
|
msg = ResUI.ConfigurationFormatIncorrect;
|
|
|
|
ProfileItem item = new()
|
|
{
|
|
ConfigType = EConfigType.VLESS,
|
|
};
|
|
|
|
var url = Utils.TryUri(str);
|
|
if (url == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
item.Address = url.IdnHost;
|
|
item.Port = url.Port;
|
|
item.Remarks = url.GetComponents(UriComponents.Fragment, UriFormat.Unescaped);
|
|
item.Password = Utils.UrlDecode(url.UserInfo);
|
|
|
|
var query = Utils.ParseQueryString(url.Query);
|
|
item.SetProtocolExtra(item.GetProtocolExtra() with
|
|
{
|
|
VlessEncryption = GetQueryValue(query, "encryption", Global.None),
|
|
Flow = GetQueryValue(query, "flow")
|
|
});
|
|
item.StreamSecurity = GetQueryValue(query, "security");
|
|
ResolveUriQuery(query, ref item);
|
|
|
|
return item;
|
|
}
|
|
|
|
public static string? ToUri(ProfileItem? item)
|
|
{
|
|
if (item == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var remark = string.Empty;
|
|
if (item.Remarks.IsNotEmpty())
|
|
{
|
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
|
}
|
|
var dicQuery = new Dictionary<string, string>();
|
|
dicQuery.Add("encryption",
|
|
!item.GetProtocolExtra().VlessEncryption.IsNullOrEmpty() ? item.GetProtocolExtra().VlessEncryption : Global.None);
|
|
if (!item.GetProtocolExtra().Flow.IsNullOrEmpty())
|
|
{
|
|
dicQuery.Add("flow", item.GetProtocolExtra().Flow);
|
|
}
|
|
ToUriQuery(item, Global.None, ref dicQuery);
|
|
|
|
return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Password, dicQuery, remark);
|
|
}
|
|
}
|