Skip to content

Commit

Permalink
vmess
Browse files Browse the repository at this point in the history
  • Loading branch information
Student Main committed Jul 20, 2020
1 parent 93b8dec commit e313e00
Showing 1 changed file with 77 additions and 3 deletions.
80 changes: 77 additions & 3 deletions v2rayN/v2rayN/Handler/V2rayConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ public static VmessItem ImportFromClipboardConfig(string clipboardData, out stri
int indexSplit = result.IndexOf("?");
if (indexSplit > 0)
{
vmessItem = ResolveVmess4Kitsunebi(result);
vmessItem = ResolveVmess4Vmess(result) ?? ResolveVmess4Kitsunebi(result);
}
else
{
Expand Down Expand Up @@ -1425,8 +1425,7 @@ private static VmessItem ResolveSip002(string result)
server.id = userInfoParts[1];

NameValueCollection queryParameters = HttpUtility.ParseQueryString(parsedUrl.Query);
string[] pluginParts = (queryParameters["plugin"] ?? "").Split(new[] { ';' }, 2);
if (pluginParts.Length > 0)
if (queryParameters["plugin"] != null)
{
return null;
}
Expand Down Expand Up @@ -1469,6 +1468,81 @@ private static VmessItem ResolveSSLegacy(string result)
return server;
}


private static VmessItem ResolveVmess4Vmess(string result)
{
VmessItem i = new VmessItem();

Uri u = new Uri(result);

var uinfo = u.UserInfo;
var uinfo12 = uinfo.Split(':');
if (uinfo12.Length != 2) return null;
var user = uinfo12[0];
var pass = uinfo12[1];
var passsp = pass.LastIndexOf('-');
var id = pass.Substring(0, passsp);
var aid = pass.Substring(passsp + 1);
i.address = u.IdnHost;
i.port = u.Port;
i.id = id;
i.alterId = int.Parse(aid);
i.remarks = u.GetComponents(UriComponents.Fragment, UriFormat.Unescaped);


var query = u.Query;

var q = HttpUtility.ParseQueryString(u.Query);

if (user.EndsWith("+tls"))
{
user = user.Split('+')[0];
i.streamSecurity = "tls";
// TODO tlsServerName
}
i.network = user;
switch (user)
{
case "tcp":
string t1 = q["type"] ?? "none";
i.headerType = t1;
// TODO t = http, parse http option


break;
case "kcp":
string t2 = q["type"] ?? "none";
i.headerType = t2;
// TODO seed
break;
case "ws":
string p1 = q["path"] ?? "/";
string h1 = q["host"] ?? "";
i.requestHost = h1;
i.path = p1;
break;

case "http":
i.network = "h2";
string p2 = q["path"] ?? "/";
string h2 = q["host"] ?? "";
i.requestHost = h2;
i.path = p2;
break;

case "quic":
string s = q["security"] ?? "none";
string k = q["key"] ?? "";
string t3 = q["type"] ?? "none";
i.headerType = t3;
i.requestHost = s;
i.path = k;
break;

}

return i;
}
#endregion

#region Gen speedtest config
Expand Down

0 comments on commit e313e00

Please sign in to comment.