去重加入host

现在判定两个server是不是一样的要看address port path 和 host
pull/41/head
CGQAQ 5 years ago
parent c1354600c7
commit 7459ada9c0

@ -86,7 +86,7 @@ namespace v2rayN.Forms
totalDown_ = string.Empty,
todayUp_ = string.Empty,
todayDown_ = string.Empty;
var index = statistics.FindIndex(item_ => (config.vmess[i].address == item_.address && config.vmess[i].port == item_.port && config.vmess[i].path == item_.path));
var index = statistics.FindIndex(item_ => Utils.IsIdenticalServer(item_, new ServerStatistics(config.vmess[i].remarks, config.vmess[i].address, config.vmess[i].port, config.vmess[i].path, config.vmess[i].requestHost, 0, 0, 0, 0)));
if (index != -1)
{
Func<ulong, string> human_fy = (amount) =>

@ -33,8 +33,6 @@ namespace v2rayN.Handler
public bool UpdateUI;
private StringBuilder outputBuilder_;
public ulong TotalUp { get; private set; }
public ulong TotalDown { get; private set; }
@ -62,14 +60,12 @@ namespace v2rayN.Handler
DeleteExpiredLog();
foreach (var server in config.vmess)
{
var statistic = new ServerStatistics(server.remarks, server.address, server.port, server.path, 0, 0, 0, 0);
var statistic = new ServerStatistics(server.remarks, server.address, server.port, server.path, server.requestHost, 0, 0, 0, 0);
Statistic.Add(statistic);
}
loadFromFile();
outputBuilder_ = new StringBuilder();
var fullPath = Utils.GetPath(cliName_);
if (!File.Exists(fullPath))
@ -211,7 +207,7 @@ namespace v2rayN.Handler
overallWriter.WriteLine($"DOWN {string.Format("{0:f2}", down_amount)}{down_unit} {TotalDown}");
foreach(var s in Statistic)
{
overallWriter.WriteLine($"* {s.name} {s.address} {s.port} {s.path} {s.totalUp} {s.totalDown}");
overallWriter.WriteLine($"* {s.name} {s.address} {s.port} {s.path} {s.host} {s.totalUp} {s.totalDown}");
}
}
}
@ -230,7 +226,7 @@ namespace v2rayN.Handler
dailyWriter.WriteLine($"LastUpdate {DateTime.Now.ToLongDateString()} {DateTime.Now.ToLongTimeString()}");
foreach (var s in Statistic)
{
dailyWriter.WriteLine($"* {s.name} {s.address} {s.port} {s.path} {s.todayUp} {s.todayDown}");
dailyWriter.WriteLine($"* {s.name} {s.address} {s.port} {s.path} {s.host} {s.todayUp} {s.todayDown}");
}
}
}
@ -278,15 +274,17 @@ namespace v2rayN.Handler
else if (line.StartsWith("*"))
{
var datas = line.Split(' ');
if (datas.Length < 6) return;
if (datas.Length < 8) return;
var name = datas[1];
var address = datas[2];
var port = int.Parse(datas[3]);
var path = datas[4];
var totalUp = ulong.Parse(datas[5]);
var totalDown = ulong.Parse(datas[6]);
var host = datas[5];
var totalUp = ulong.Parse(datas[6]);
var totalDown = ulong.Parse(datas[7]);
var index = Statistic.FindIndex(item => item.address == address && item.port == port);
var temp = new ServerStatistics(name, address, port, path, host, 0, 0, 0, 0);
var index = Statistic.FindIndex(item => Utils.IsIdenticalServer(item, temp));
if (index != -1)
{
Statistic[index].totalUp = totalUp;
@ -294,7 +292,7 @@ namespace v2rayN.Handler
}
else
{
var s = new Mode.ServerStatistics(name, address, port, path, totalUp, totalDown, 0, 0);
var s = new Mode.ServerStatistics(name, address, port, path, host, totalUp, totalDown, 0, 0);
Statistic.Add(s);
}
}
@ -322,15 +320,17 @@ namespace v2rayN.Handler
else if (line.StartsWith("*"))
{
var datas = line.Split(' ');
if (datas.Length < 6) return;
if (datas.Length < 8) return;
var name = datas[1];
var address = datas[2];
var port = int.Parse(datas[3]);
var path = datas[4];
var todayUp = ulong.Parse(datas[5]);
var todayDown = ulong.Parse(datas[6]);
var host = datas[5];
var todayUp = ulong.Parse(datas[6]);
var todayDown = ulong.Parse(datas[7]);
var index = Statistic.FindIndex(item => item.address == address && item.port == port);
var temp = new ServerStatistics(name, address, port, path, host, 0, 0, 0, 0);
var index = Statistic.FindIndex(item => Utils.IsIdenticalServer(item, temp));
if (index != -1)
{
Statistic[index].todayUp = todayUp;
@ -338,7 +338,7 @@ namespace v2rayN.Handler
}
else
{
var s = new Mode.ServerStatistics(name, address, port, path, 0, 0, todayUp, todayDown);
var s = new Mode.ServerStatistics(name, address, port, path, host, 0, 0, todayUp, todayDown);
Statistic.Add(s);
}
}

@ -12,18 +12,20 @@ namespace v2rayN.Mode
public string address;
public int port;
public string path;
public string host;
public ulong totalUp;
public ulong totalDown;
public ulong todayUp;
public ulong todayDown;
public ServerStatistics() { }
public ServerStatistics(string name, string addr, int port, string path, ulong totalUp, ulong totalDown, ulong todayUp, ulong todayDown)
public ServerStatistics(string name, string addr, int port, string path, string host, ulong totalUp, ulong totalDown, ulong todayUp, ulong todayDown)
{
this.name = name;
this.address = addr;
this.port = port;
this.path = path;
this.host = host;
this.totalUp = totalUp;
this.totalDown = totalDown;
this.todayUp = todayUp;

@ -316,7 +316,7 @@ namespace v2rayN
var list = new List<Mode.VmessItem>();
foreach (var item in source)
{
if(!list.Exists(i => item.address == i.address && item.port == i.port && item.path == i.path))
if(!list.Exists(i => item.address == i.address && item.port == i.port && item.path == i.path && item.requestHost == i.requestHost))
{
list.Add(item);
}
@ -434,6 +434,15 @@ namespace v2rayN
return Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase);
}
public static bool IsIdenticalServer(Mode.ServerStatistics a, Mode.ServerStatistics b)
{
return (a.address == b.address
&& a.port == b.port
&& a.path == b.path
&& a.host == b.host
);
}
#endregion
#region 开机自动启动

@ -16,6 +16,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartAction>Project</StartAction>
<StartArguments>/restart 1001</StartArguments>
<StartArguments>
</StartArguments>
</PropertyGroup>
</Project>
Loading…
Cancel
Save