From 477509b12f33f384945e728da40ff6e63b32c569 Mon Sep 17 00:00:00 2001
From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com>
Date: Fri, 9 Oct 2020 20:22:05 +0800
Subject: [PATCH] refactor: VMess.ParseUri - break: version 1 support - break:
mux config in uri
---
Netch/Servers/VMess/Models/VMessJObject.cs | 35 +++++-----------
Netch/Servers/VMess/VMessUtil.cs | 48 +++++++---------------
2 files changed, 25 insertions(+), 58 deletions(-)
diff --git a/Netch/Servers/VMess/Models/VMessJObject.cs b/Netch/Servers/VMess/Models/VMessJObject.cs
index a922d381..dd4fd282 100644
--- a/Netch/Servers/VMess/Models/VMessJObject.cs
+++ b/Netch/Servers/VMess/Models/VMessJObject.cs
@@ -5,72 +5,59 @@
///
public class VMessJObject
{
- ///
- /// Mux Class
- ///
- public class Mux
- {
- public object enabled;
- }
-
///
/// 链接版本
///
- public string v;
+ public string v = string.Empty;
///
/// 备注
///
- public string ps;
+ public string ps = string.Empty;
///
/// 地址
///
- public string add;
+ public string add = string.Empty;
///
/// 端口
///
- public int port;
+ public string port = string.Empty;
///
/// 用户 ID
///
- public string id;
+ public string id = string.Empty;
///
/// 额外 ID
///
- public int aid = 0;
+ public string aid = string.Empty;
///
/// 传输协议
///
- public string net;
+ public string net = string.Empty;
///
/// 伪装类型
///
- public string type;
+ public string type = string.Empty;
///
/// 伪装域名(HTTP,WS)
///
- public string host;
+ public string host = string.Empty;
///
/// 伪装路径
///
- public string path;
+ public string path = string.Empty;
///
/// 是否使用 TLS
///
- public string tls;
-
- ///
- /// Mux 多路复用
- ///
- public Mux mux;
+ public string tls = string.Empty;
}
}
\ No newline at end of file
diff --git a/Netch/Servers/VMess/VMessUtil.cs b/Netch/Servers/VMess/VMessUtil.cs
index 98c1192c..d02d4e33 100644
--- a/Netch/Servers/VMess/VMessUtil.cs
+++ b/Netch/Servers/VMess/VMessUtil.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using Netch.Controllers;
using Netch.Models;
@@ -63,26 +64,25 @@ namespace Netch.Servers.VMess
var data = new VMess();
text = text.Substring(8);
- var vmess = JsonConvert.DeserializeObject(ShareLink.URLSafeBase64Decode(text));
+ VMessJObject vmess;
+ try
+ {
+ vmess = JsonConvert.DeserializeObject(ShareLink.URLSafeBase64Decode(text));
+ }
+ catch (Exception e)
+ {
+ Logging.Warning(e.ToString());
+ return null;
+ }
data.Remark = vmess.ps;
data.Hostname = vmess.add;
- data.Port = vmess.port;
+ data.Port = ushort.Parse(vmess.port);
data.UserID = vmess.id;
- data.AlterID = vmess.aid;
+ data.AlterID = int.Parse(vmess.aid);
data.TransferProtocol = vmess.net;
data.FakeType = vmess.type;
- if (vmess.v == null || vmess.v == "1")
- {
- var info = vmess.host.Split(';');
- if (info.Length == 2)
- {
- vmess.host = info[0];
- vmess.path = info[1];
- }
- }
-
if (data.TransferProtocol == "quic")
{
if (VMessGlobal.QUIC.Contains(vmess.host))
@@ -98,28 +98,8 @@ namespace Netch.Servers.VMess
}
data.TLSSecure = vmess.tls == "tls";
-
- if (vmess.mux == null)
- {
- data.UseMux = false;
- }
- else
- {
- if (vmess.mux.enabled is bool enabled)
- {
- data.UseMux = enabled;
- }
- else if (vmess.mux.enabled is string muxEnabled)
- {
- data.UseMux = muxEnabled == "true"; // 针对使用字符串当作布尔值的情况
- }
- else
- {
- data.UseMux = false;
- }
- }
-
data.EncryptMethod = "auto"; // V2Ray 加密方式不包括在链接中,主动添加一个
+
return CheckServer(data) ? new[] {data} : null;
}