Support interval range (#5440)

This commit is contained in:
DHR60
2026-04-02 01:33:07 +00:00
committed by GitHub
parent 9dc1b1f2cf
commit 0a52a79fa0
3 changed files with 31 additions and 10 deletions
@@ -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()) {
@@ -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()
}
@@ -85,8 +85,7 @@
<EditText
android:id="@+id/et_port_hop_interval"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
android:layout_height="wrap_content" />
</LinearLayout>