Support interval range

This commit is contained in:
DHR60 2026-02-05 19:18:25 +08:00
parent e47dc40488
commit 6810483c8f
7 changed files with 30 additions and 13 deletions

View file

@ -722,7 +722,7 @@ public static class ConfigHandler
SalamanderPass = profileItem.GetProtocolExtra().SalamanderPass?.TrimEx(), SalamanderPass = profileItem.GetProtocolExtra().SalamanderPass?.TrimEx(),
UpMbps = profileItem.GetProtocolExtra().UpMbps is null or < 0 ? config.HysteriaItem.UpMbps : profileItem.GetProtocolExtra().UpMbps, UpMbps = profileItem.GetProtocolExtra().UpMbps is null or < 0 ? config.HysteriaItem.UpMbps : profileItem.GetProtocolExtra().UpMbps,
DownMbps = profileItem.GetProtocolExtra().DownMbps is null or < 0 ? config.HysteriaItem.DownMbps : profileItem.GetProtocolExtra().DownMbps, DownMbps = profileItem.GetProtocolExtra().DownMbps is null or < 0 ? config.HysteriaItem.DownMbps : profileItem.GetProtocolExtra().DownMbps,
HopInterval = profileItem.GetProtocolExtra().HopInterval is null or <= 5 ? Global.Hysteria2DefaultHopInt : profileItem.GetProtocolExtra().HopInterval, HopInterval = profileItem.GetProtocolExtra().HopInterval?.TrimEx(),
}); });
await AddServerCommon(config, profileItem, toFile); await AddServerCommon(config, profileItem, toFile);

View file

@ -329,7 +329,7 @@ public sealed class AppManager
Ports = item.Ports.NullIfEmpty(), Ports = item.Ports.NullIfEmpty(),
UpMbps = _config.HysteriaItem.UpMbps, UpMbps = _config.HysteriaItem.UpMbps,
DownMbps = _config.HysteriaItem.DownMbps, DownMbps = _config.HysteriaItem.DownMbps,
HopInterval = _config.HysteriaItem.HopInterval HopInterval = _config.HysteriaItem.HopInterval.ToString(),
}; };
break; break;
case EConfigType.TUIC: case EConfigType.TUIC:

View file

@ -30,7 +30,7 @@ public record ProtocolExtraItem
public int? UpMbps { get; init; } public int? UpMbps { get; init; }
public int? DownMbps { get; init; } public int? DownMbps { get; init; }
public string? Ports { get; init; } public string? Ports { get; init; }
public int? HopInterval { get; init; } public string? HopInterval { get; init; }
// group profile // group profile
public string? GroupType { get; init; } public string? GroupType { get; init; }

View file

@ -473,7 +473,7 @@ public class HysteriaSettings4Ray
public class HysteriaUdpHop4Ray public class HysteriaUdpHop4Ray
{ {
public string? ports { get; set; } public string? ports { get; set; }
public int? interval { get; set; } public string? interval { get; set; }
} }
public class FinalMask4Ray public class FinalMask4Ray

View file

@ -166,9 +166,24 @@ public partial class CoreConfigSingboxService
return port.Contains(':') ? port : $"{port}:{port}"; return port.Contains(':') ? port : $"{port}:{port}";
}) })
.ToList(); .ToList();
outbound.hop_interval = protocolExtra?.HopInterval is { } hi and >= 5 outbound.hop_interval = _config.HysteriaItem.HopInterval >= 5
? $"{hi}s" ? $"{_config.HysteriaItem.HopInterval}s"
: _config.HysteriaItem.HopInterval >= 5 ? $"{_config.HysteriaItem.HopInterval}s" : $"{Global.Hysteria2DefaultHopInt}s"; : $"{Global.Hysteria2DefaultHopInt}s";
if (int.TryParse(protocolExtra.HopInterval, out var hiResult))
{
outbound.hop_interval = hiResult >= 5 ? $"{hiResult}s" : outbound.hop_interval;
}
else if (protocolExtra.HopInterval?.Contains('-') ?? false)
{
// may be a range like 5-10
var parts = protocolExtra.HopInterval.Split('-');
if (parts.Length == 2 && int.TryParse(parts[0], out var hiL) &&
int.TryParse(parts[0], out var hiH))
{
var hi = (hiL + hiH) / 2;
outbound.hop_interval = hi >= 5 ? $"{hi}s" : outbound.hop_interval;
}
}
} }
break; break;

View file

@ -518,9 +518,11 @@ public partial class CoreConfigV2rayService
int? downMbps = protocolExtra?.DownMbps is { } sd and >= 0 int? downMbps = protocolExtra?.DownMbps is { } sd and >= 0
? sd ? sd
: _config.HysteriaItem.UpMbps; : _config.HysteriaItem.UpMbps;
var hopInterval = protocolExtra?.HopInterval is { } hi and >= 5 var hopInterval = !protocolExtra.HopInterval.IsNullOrEmpty()
? hi ? protocolExtra.HopInterval
: _config.HysteriaItem.HopInterval >= 5 ? _config.HysteriaItem.HopInterval : Global.Hysteria2DefaultHopInt; : (_config.HysteriaItem.HopInterval >= 5
? _config.HysteriaItem.HopInterval
: Global.Hysteria2DefaultHopInt).ToString();
HysteriaUdpHop4Ray? udpHop = null; HysteriaUdpHop4Ray? udpHop = null;
if (!ports.IsNullOrEmpty() && if (!ports.IsNullOrEmpty() &&
(ports.Contains(':') || ports.Contains('-') || ports.Contains(','))) (ports.Contains(':') || ports.Contains('-') || ports.Contains(',')))

View file

@ -33,7 +33,7 @@ public class AddServerViewModel : MyReactiveObject
public int DownMbps { get; set; } public int DownMbps { get; set; }
[Reactive] [Reactive]
public int HopInterval { get; set; } public string HopInterval { get; set; }
[Reactive] [Reactive]
public string Flow { get; set; } public string Flow { get; set; }
@ -115,7 +115,7 @@ public class AddServerViewModel : MyReactiveObject
SalamanderPass = protocolExtra?.SalamanderPass ?? string.Empty; SalamanderPass = protocolExtra?.SalamanderPass ?? string.Empty;
UpMbps = protocolExtra?.UpMbps ?? _config.HysteriaItem.UpMbps; UpMbps = protocolExtra?.UpMbps ?? _config.HysteriaItem.UpMbps;
DownMbps = protocolExtra?.DownMbps ?? _config.HysteriaItem.DownMbps; DownMbps = protocolExtra?.DownMbps ?? _config.HysteriaItem.DownMbps;
HopInterval = protocolExtra?.HopInterval ?? Global.Hysteria2DefaultHopInt; HopInterval = protocolExtra?.HopInterval.IsNullOrEmpty() ?? true ? Global.Hysteria2DefaultHopInt.ToString() : protocolExtra.HopInterval;
VmessSecurity = protocolExtra?.VmessSecurity?.IsNullOrEmpty() == false ? protocolExtra.VmessSecurity : Global.DefaultSecurity; VmessSecurity = protocolExtra?.VmessSecurity?.IsNullOrEmpty() == false ? protocolExtra.VmessSecurity : Global.DefaultSecurity;
VlessEncryption = protocolExtra?.VlessEncryption.IsNullOrEmpty() == false ? protocolExtra.VlessEncryption : Global.None; VlessEncryption = protocolExtra?.VlessEncryption.IsNullOrEmpty() == false ? protocolExtra.VlessEncryption : Global.None;
SsMethod = protocolExtra?.SsMethod ?? string.Empty; SsMethod = protocolExtra?.SsMethod ?? string.Empty;
@ -178,7 +178,7 @@ public class AddServerViewModel : MyReactiveObject
SalamanderPass = SalamanderPass.NullIfEmpty(), SalamanderPass = SalamanderPass.NullIfEmpty(),
UpMbps = UpMbps >= 0 ? UpMbps : null, UpMbps = UpMbps >= 0 ? UpMbps : null,
DownMbps = DownMbps >= 0 ? DownMbps : null, DownMbps = DownMbps >= 0 ? DownMbps : null,
HopInterval = HopInterval >= 5 ? HopInterval : null, HopInterval = HopInterval.NullIfEmpty(),
VmessSecurity = VmessSecurity.NullIfEmpty(), VmessSecurity = VmessSecurity.NullIfEmpty(),
VlessEncryption = VlessEncryption.NullIfEmpty(), VlessEncryption = VlessEncryption.NullIfEmpty(),
SsMethod = SsMethod.NullIfEmpty(), SsMethod = SsMethod.NullIfEmpty(),