add VmessItem indexId

pull/2077/head
2dust 2022-01-28 21:02:25 +08:00
parent 206b440966
commit 002283899f
3 changed files with 64 additions and 52 deletions

View File

@ -172,6 +172,11 @@ namespace v2rayN.Handler
{
VmessItem vmessItem = config.vmess[i];
UpgradeServerVersion(ref vmessItem);
if (string.IsNullOrEmpty(vmessItem.indexId))
{
vmessItem.indexId = Utils.GetGUID(false);
}
}
}
@ -191,7 +196,6 @@ namespace v2rayN.Handler
/// <returns></returns>
public static int AddServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
{
vmessItem.configVersion = 2;
vmessItem.configType = (int)EConfigType.Vmess;
vmessItem.address = vmessItem.address.TrimEx();
@ -203,6 +207,11 @@ namespace v2rayN.Handler
vmessItem.path = vmessItem.path.TrimEx();
vmessItem.streamSecurity = vmessItem.streamSecurity.TrimEx();
if (!Global.vmessSecuritys.Contains(vmessItem.security))
{
return -1;
}
if (index >= 0)
{
//修改
@ -214,17 +223,7 @@ namespace v2rayN.Handler
}
else
{
//添加
if (Utils.IsNullOrEmpty(vmessItem.allowInsecure))
{
vmessItem.allowInsecure = config.defAllowInsecure.ToString();
}
config.vmess.Add(vmessItem);
if (config.vmess.Count == 1)
{
config.index = 0;
Global.reloadV2ray = true;
}
AddServerCommon(ref config, vmessItem);
}
if (toFile)
@ -545,7 +544,6 @@ namespace v2rayN.Handler
/// <returns></returns>
public static int AddShadowsocksServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
{
vmessItem.configVersion = 2;
vmessItem.configType = (int)EConfigType.Shadowsocks;
vmessItem.address = vmessItem.address.TrimEx();
@ -568,13 +566,7 @@ namespace v2rayN.Handler
}
else
{
//添加
config.vmess.Add(vmessItem);
if (config.vmess.Count == 1)
{
config.index = 0;
Global.reloadV2ray = true;
}
AddServerCommon(ref config, vmessItem);
}
if (toFile)
@ -594,7 +586,6 @@ namespace v2rayN.Handler
/// <returns></returns>
public static int AddSocksServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
{
vmessItem.configVersion = 2;
vmessItem.configType = (int)EConfigType.Socks;
vmessItem.address = vmessItem.address.TrimEx();
@ -610,13 +601,7 @@ namespace v2rayN.Handler
}
else
{
//添加
config.vmess.Add(vmessItem);
if (config.vmess.Count == 1)
{
config.index = 0;
Global.reloadV2ray = true;
}
AddServerCommon(ref config, vmessItem);
}
if (toFile)
@ -637,7 +622,6 @@ namespace v2rayN.Handler
/// <returns></returns>
public static int AddTrojanServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
{
vmessItem.configVersion = 2;
vmessItem.configType = (int)EConfigType.Trojan;
vmessItem.address = vmessItem.address.TrimEx();
@ -662,13 +646,7 @@ namespace v2rayN.Handler
}
else
{
//添加
config.vmess.Add(vmessItem);
if (config.vmess.Count == 1)
{
config.index = 0;
Global.reloadV2ray = true;
}
AddServerCommon(ref config, vmessItem);
}
if (toFile)
@ -866,7 +844,7 @@ namespace v2rayN.Handler
{
if (Utils.IsNullOrEmpty(sub.id))
{
sub.id = Utils.GetGUID();
sub.id = Utils.GetGUID(false);
}
}
@ -954,7 +932,6 @@ namespace v2rayN.Handler
/// <returns></returns>
public static int AddVlessServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
{
vmessItem.configVersion = 2;
vmessItem.configType = (int)EConfigType.VLESS;
vmessItem.address = vmessItem.address.TrimEx();
@ -976,18 +953,8 @@ namespace v2rayN.Handler
}
}
else
{
//添加
if (Utils.IsNullOrEmpty(vmessItem.allowInsecure))
{
vmessItem.allowInsecure = config.defAllowInsecure.ToString();
}
config.vmess.Add(vmessItem);
if (config.vmess.Count == 1)
{
config.index = 0;
Global.reloadV2ray = true;
}
{
AddServerCommon(ref config, vmessItem);
}
if (toFile)
@ -1054,6 +1021,23 @@ namespace v2rayN.Handler
return 0;
}
public static int AddServerCommon(ref Config config, VmessItem vmessItem)
{
vmessItem.indexId = Utils.GetGUID(false);
vmessItem.configVersion = 2;
if (Utils.IsNullOrEmpty(vmessItem.allowInsecure))
{
vmessItem.allowInsecure = config.defAllowInsecure.ToString();
}
config.vmess.Add(vmessItem);
if (config.vmess.Count == 1)
{
config.index = 0;
Global.reloadV2ray = true;
}
return 0;
}
#endregion
#region UI
@ -1133,6 +1117,13 @@ namespace v2rayN.Handler
else
{
config.routings.Add(item);
int indexLocked = config.routings.FindIndex(it => it.locked == true);
if (indexLocked != -1)
{
var itemLocked = Utils.DeepCopy(config.routings[indexLocked]);
config.routings.RemoveAt(indexLocked);
config.routings.Add(itemLocked);
}
}
ToJsonFile(config);

View File

@ -366,6 +366,15 @@ namespace v2rayN.Mode
return null;
}
}
public int FindIndexId(string indexId)
{
if (string.IsNullOrEmpty(indexId))
{
return -1;
}
return vmess.FindIndex(it => it.indexId == indexId);
}
#endregion
}
@ -375,6 +384,7 @@ namespace v2rayN.Mode
{
public VmessItem()
{
indexId = string.Empty;
configVersion = 1;
address = string.Empty;
port = 0;
@ -460,6 +470,10 @@ namespace v2rayN.Mode
itemId = Utils.Base64Encode(itemId);
return itemId;
}
public string indexId
{
get; set;
}
/// <summary>
/// 版本(现在=2)

View File

@ -844,11 +844,18 @@ namespace v2rayN
/// 取得GUID
/// </summary>
/// <returns></returns>
public static string GetGUID()
public static string GetGUID(bool full = true)
{
try
{
return Guid.NewGuid().ToString("D");
if (full)
{
return Guid.NewGuid().ToString("D");
}
else
{
return BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0).ToString();
}
}
catch (Exception ex)
{