From 0a52a79fa0e0d81b2f137e17d49235a741f54d3f Mon Sep 17 00:00:00 2001 From: DHR60 Date: Thu, 2 Apr 2026 01:33:07 +0000 Subject: [PATCH] Support interval range (#5440) --- .../java/com/v2ray/ang/fmt/Hysteria2Fmt.kt | 36 +++++++++++++++---- .../java/com/v2ray/ang/ui/ServerActivity.kt | 2 +- .../res/layout/activity_server_hysteria2.xml | 3 +- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/Hysteria2Fmt.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/Hysteria2Fmt.kt index 8115ae70..5e3a9671 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/Hysteria2Fmt.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/fmt/Hysteria2Fmt.kt @@ -72,14 +72,36 @@ object Hysteria2Fmt : FmtBase() { dicQuery["mport"] = config.portHopping.orEmpty() } if (config.portHoppingInterval.isNotNullEmpty()) { - var portHoppingInterval = config.portHoppingInterval.orEmpty() - if (portHoppingInterval.contains('-')) { - // interval range - portHoppingInterval = portHoppingInterval.substringBefore('-') + val rawInterval = config.portHoppingInterval?.trim().nullIfBlank() + val interval = if (rawInterval == null) { + null + } else { + val singleValue = rawInterval.toIntOrNull() + if (singleValue != null) { + if (singleValue < 5) { + null + } else { + rawInterval + } + } else { + val parts = rawInterval.split('-') + if (parts.size == 2) { + val start = parts[0].trim().toIntOrNull() + val end = parts[1].trim().toIntOrNull() + if (start != null && end != null) { + val minStart = maxOf(5, start) + val minEnd = maxOf(minStart, end) + (minStart + minEnd) / 2 + } else { + null + } + } else { + null + } + } } - val trimmedPortHoppingInterval = portHoppingInterval.trim() - if (trimmedPortHoppingInterval.isNotEmpty()) { - dicQuery["mportHopInt"] = trimmedPortHoppingInterval + if (interval != null) { + dicQuery["mportHopInt"] = interval.toString() } } if (config.pinnedCA256.isNotNullEmpty()) { diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt index 54909e90..33e788c2 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/ServerActivity.kt @@ -543,7 +543,7 @@ class ServerActivity : BaseActivity() { } else if (config.configType == EConfigType.HYSTERIA2) { config.obfsPassword = et_obfs_password?.text?.toString() config.portHopping = et_port_hop?.text?.toString() - config.portHoppingInterval = et_port_hop_interval?.text?.toString() + config.portHoppingInterval = et_port_hop_interval?.text?.toString()?.trim() config.bandwidthDown = et_bandwidth_down?.text?.toString() config.bandwidthUp = et_bandwidth_up?.text?.toString() } diff --git a/V2rayNG/app/src/main/res/layout/activity_server_hysteria2.xml b/V2rayNG/app/src/main/res/layout/activity_server_hysteria2.xml index 86df50ef..10e5b951 100644 --- a/V2rayNG/app/src/main/res/layout/activity_server_hysteria2.xml +++ b/V2rayNG/app/src/main/res/layout/activity_server_hysteria2.xml @@ -85,8 +85,7 @@ + android:layout_height="wrap_content" />