diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 0262a2c2..84fc0fc4 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -722,7 +722,7 @@ public static class ConfigHandler SalamanderPass = profileItem.GetProtocolExtra().SalamanderPass?.TrimEx(), 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, - HopInterval = profileItem.GetProtocolExtra().HopInterval is null or <= 5 ? Global.Hysteria2DefaultHopInt : profileItem.GetProtocolExtra().HopInterval, + HopInterval = profileItem.GetProtocolExtra().HopInterval?.TrimEx(), }); await AddServerCommon(config, profileItem, toFile); diff --git a/v2rayN/ServiceLib/Manager/AppManager.cs b/v2rayN/ServiceLib/Manager/AppManager.cs index e2a108f0..6c05f155 100644 --- a/v2rayN/ServiceLib/Manager/AppManager.cs +++ b/v2rayN/ServiceLib/Manager/AppManager.cs @@ -329,7 +329,7 @@ public sealed class AppManager Ports = item.Ports.NullIfEmpty(), UpMbps = _config.HysteriaItem.UpMbps, DownMbps = _config.HysteriaItem.DownMbps, - HopInterval = _config.HysteriaItem.HopInterval + HopInterval = _config.HysteriaItem.HopInterval.ToString(), }; break; case EConfigType.TUIC: diff --git a/v2rayN/ServiceLib/Models/ProtocolExtraItem.cs b/v2rayN/ServiceLib/Models/ProtocolExtraItem.cs index 09569537..4cb95c8b 100644 --- a/v2rayN/ServiceLib/Models/ProtocolExtraItem.cs +++ b/v2rayN/ServiceLib/Models/ProtocolExtraItem.cs @@ -30,7 +30,7 @@ public record ProtocolExtraItem public int? UpMbps { get; init; } public int? DownMbps { get; init; } public string? Ports { get; init; } - public int? HopInterval { get; init; } + public string? HopInterval { get; init; } // group profile public string? GroupType { get; init; } diff --git a/v2rayN/ServiceLib/Models/V2rayConfig.cs b/v2rayN/ServiceLib/Models/V2rayConfig.cs index c752168a..34456a8e 100644 --- a/v2rayN/ServiceLib/Models/V2rayConfig.cs +++ b/v2rayN/ServiceLib/Models/V2rayConfig.cs @@ -473,7 +473,7 @@ public class HysteriaSettings4Ray public class HysteriaUdpHop4Ray { public string? ports { get; set; } - public int? interval { get; set; } + public string? interval { get; set; } } public class FinalMask4Ray diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs index ef4bbaec..b5988187 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs @@ -166,9 +166,24 @@ public partial class CoreConfigSingboxService return port.Contains(':') ? port : $"{port}:{port}"; }) .ToList(); - outbound.hop_interval = protocolExtra?.HopInterval is { } hi and >= 5 - ? $"{hi}s" - : _config.HysteriaItem.HopInterval >= 5 ? $"{_config.HysteriaItem.HopInterval}s" : $"{Global.Hysteria2DefaultHopInt}s"; + outbound.hop_interval = _config.HysteriaItem.HopInterval >= 5 + ? $"{_config.HysteriaItem.HopInterval}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; diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs index 71d27ea1..e409f806 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs @@ -518,9 +518,11 @@ public partial class CoreConfigV2rayService int? downMbps = protocolExtra?.DownMbps is { } sd and >= 0 ? sd : _config.HysteriaItem.UpMbps; - var hopInterval = protocolExtra?.HopInterval is { } hi and >= 5 - ? hi - : _config.HysteriaItem.HopInterval >= 5 ? _config.HysteriaItem.HopInterval : Global.Hysteria2DefaultHopInt; + var hopInterval = !protocolExtra.HopInterval.IsNullOrEmpty() + ? protocolExtra.HopInterval + : (_config.HysteriaItem.HopInterval >= 5 + ? _config.HysteriaItem.HopInterval + : Global.Hysteria2DefaultHopInt).ToString(); HysteriaUdpHop4Ray? udpHop = null; if (!ports.IsNullOrEmpty() && (ports.Contains(':') || ports.Contains('-') || ports.Contains(','))) diff --git a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs index 73915544..acaa5511 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs @@ -33,7 +33,7 @@ public class AddServerViewModel : MyReactiveObject public int DownMbps { get; set; } [Reactive] - public int HopInterval { get; set; } + public string HopInterval { get; set; } [Reactive] public string Flow { get; set; } @@ -115,7 +115,7 @@ public class AddServerViewModel : MyReactiveObject SalamanderPass = protocolExtra?.SalamanderPass ?? string.Empty; UpMbps = protocolExtra?.UpMbps ?? _config.HysteriaItem.UpMbps; 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; VlessEncryption = protocolExtra?.VlessEncryption.IsNullOrEmpty() == false ? protocolExtra.VlessEncryption : Global.None; SsMethod = protocolExtra?.SsMethod ?? string.Empty; @@ -178,7 +178,7 @@ public class AddServerViewModel : MyReactiveObject SalamanderPass = SalamanderPass.NullIfEmpty(), UpMbps = UpMbps >= 0 ? UpMbps : null, DownMbps = DownMbps >= 0 ? DownMbps : null, - HopInterval = HopInterval >= 5 ? HopInterval : null, + HopInterval = HopInterval.NullIfEmpty(), VmessSecurity = VmessSecurity.NullIfEmpty(), VlessEncryption = VlessEncryption.NullIfEmpty(), SsMethod = SsMethod.NullIfEmpty(),