mirror of
https://github.com/2dust/v2rayN.git
synced 2025-05-03 05:38:51 +00:00
add VmessItem indexId
This commit is contained in:
parent
206b440966
commit
002283899f
3 changed files with 64 additions and 52 deletions
|
@ -172,6 +172,11 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
VmessItem vmessItem = config.vmess[i];
|
VmessItem vmessItem = config.vmess[i];
|
||||||
UpgradeServerVersion(ref vmessItem);
|
UpgradeServerVersion(ref vmessItem);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(vmessItem.indexId))
|
||||||
|
{
|
||||||
|
vmessItem.indexId = Utils.GetGUID(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +196,6 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int AddServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
|
public static int AddServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
|
||||||
{
|
{
|
||||||
vmessItem.configVersion = 2;
|
|
||||||
vmessItem.configType = (int)EConfigType.Vmess;
|
vmessItem.configType = (int)EConfigType.Vmess;
|
||||||
|
|
||||||
vmessItem.address = vmessItem.address.TrimEx();
|
vmessItem.address = vmessItem.address.TrimEx();
|
||||||
|
@ -203,6 +207,11 @@ namespace v2rayN.Handler
|
||||||
vmessItem.path = vmessItem.path.TrimEx();
|
vmessItem.path = vmessItem.path.TrimEx();
|
||||||
vmessItem.streamSecurity = vmessItem.streamSecurity.TrimEx();
|
vmessItem.streamSecurity = vmessItem.streamSecurity.TrimEx();
|
||||||
|
|
||||||
|
if (!Global.vmessSecuritys.Contains(vmessItem.security))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
{
|
{
|
||||||
//修改
|
//修改
|
||||||
|
@ -214,17 +223,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//添加
|
AddServerCommon(ref config, vmessItem);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toFile)
|
if (toFile)
|
||||||
|
@ -545,7 +544,6 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int AddShadowsocksServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
|
public static int AddShadowsocksServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
|
||||||
{
|
{
|
||||||
vmessItem.configVersion = 2;
|
|
||||||
vmessItem.configType = (int)EConfigType.Shadowsocks;
|
vmessItem.configType = (int)EConfigType.Shadowsocks;
|
||||||
|
|
||||||
vmessItem.address = vmessItem.address.TrimEx();
|
vmessItem.address = vmessItem.address.TrimEx();
|
||||||
|
@ -568,13 +566,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//添加
|
AddServerCommon(ref config, vmessItem);
|
||||||
config.vmess.Add(vmessItem);
|
|
||||||
if (config.vmess.Count == 1)
|
|
||||||
{
|
|
||||||
config.index = 0;
|
|
||||||
Global.reloadV2ray = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toFile)
|
if (toFile)
|
||||||
|
@ -594,7 +586,6 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int AddSocksServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
|
public static int AddSocksServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
|
||||||
{
|
{
|
||||||
vmessItem.configVersion = 2;
|
|
||||||
vmessItem.configType = (int)EConfigType.Socks;
|
vmessItem.configType = (int)EConfigType.Socks;
|
||||||
|
|
||||||
vmessItem.address = vmessItem.address.TrimEx();
|
vmessItem.address = vmessItem.address.TrimEx();
|
||||||
|
@ -610,13 +601,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//添加
|
AddServerCommon(ref config, vmessItem);
|
||||||
config.vmess.Add(vmessItem);
|
|
||||||
if (config.vmess.Count == 1)
|
|
||||||
{
|
|
||||||
config.index = 0;
|
|
||||||
Global.reloadV2ray = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toFile)
|
if (toFile)
|
||||||
|
@ -637,7 +622,6 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int AddTrojanServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
|
public static int AddTrojanServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
|
||||||
{
|
{
|
||||||
vmessItem.configVersion = 2;
|
|
||||||
vmessItem.configType = (int)EConfigType.Trojan;
|
vmessItem.configType = (int)EConfigType.Trojan;
|
||||||
|
|
||||||
vmessItem.address = vmessItem.address.TrimEx();
|
vmessItem.address = vmessItem.address.TrimEx();
|
||||||
|
@ -662,13 +646,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//添加
|
AddServerCommon(ref config, vmessItem);
|
||||||
config.vmess.Add(vmessItem);
|
|
||||||
if (config.vmess.Count == 1)
|
|
||||||
{
|
|
||||||
config.index = 0;
|
|
||||||
Global.reloadV2ray = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toFile)
|
if (toFile)
|
||||||
|
@ -866,7 +844,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(sub.id))
|
if (Utils.IsNullOrEmpty(sub.id))
|
||||||
{
|
{
|
||||||
sub.id = Utils.GetGUID();
|
sub.id = Utils.GetGUID(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -954,7 +932,6 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int AddVlessServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
|
public static int AddVlessServer(ref Config config, VmessItem vmessItem, int index, bool toFile = true)
|
||||||
{
|
{
|
||||||
vmessItem.configVersion = 2;
|
|
||||||
vmessItem.configType = (int)EConfigType.VLESS;
|
vmessItem.configType = (int)EConfigType.VLESS;
|
||||||
|
|
||||||
vmessItem.address = vmessItem.address.TrimEx();
|
vmessItem.address = vmessItem.address.TrimEx();
|
||||||
|
@ -976,18 +953,8 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//添加
|
AddServerCommon(ref config, vmessItem);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toFile)
|
if (toFile)
|
||||||
|
@ -1054,6 +1021,23 @@ namespace v2rayN.Handler
|
||||||
return 0;
|
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
|
#endregion
|
||||||
|
|
||||||
#region UI
|
#region UI
|
||||||
|
@ -1133,6 +1117,13 @@ namespace v2rayN.Handler
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
config.routings.Add(item);
|
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);
|
ToJsonFile(config);
|
||||||
|
|
||||||
|
|
|
@ -366,6 +366,15 @@ namespace v2rayN.Mode
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int FindIndexId(string indexId)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(indexId))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return vmess.FindIndex(it => it.indexId == indexId);
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -375,6 +384,7 @@ namespace v2rayN.Mode
|
||||||
{
|
{
|
||||||
public VmessItem()
|
public VmessItem()
|
||||||
{
|
{
|
||||||
|
indexId = string.Empty;
|
||||||
configVersion = 1;
|
configVersion = 1;
|
||||||
address = string.Empty;
|
address = string.Empty;
|
||||||
port = 0;
|
port = 0;
|
||||||
|
@ -460,6 +470,10 @@ namespace v2rayN.Mode
|
||||||
itemId = Utils.Base64Encode(itemId);
|
itemId = Utils.Base64Encode(itemId);
|
||||||
return itemId;
|
return itemId;
|
||||||
}
|
}
|
||||||
|
public string indexId
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 版本(现在=2)
|
/// 版本(现在=2)
|
||||||
|
|
|
@ -844,11 +844,18 @@ namespace v2rayN
|
||||||
/// 取得GUID
|
/// 取得GUID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetGUID()
|
public static string GetGUID(bool full = true)
|
||||||
{
|
{
|
||||||
try
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue