Port Android server runtime to GaCy Go

This commit is contained in:
CAtlas0784 committed 2026-11-02 02:39:37 +07:00
1 parent 92a4b4f545
commit 3c1186c781
20 files changed
+830 -798

No files matched your search

@@ -1,5 +1,7 @@
package com.gacy.android.model
import java.net.URI
enum class ServerExecutionMode(val displayNameTh: String, val displayNameEn: String) {
LOCAL_EMBEDDED("รันในเครื่อง (Local Embedded)", "Local Embedded Runtime"),
REMOTE_SERVER("เชื่อมต่อเซิร์ฟเวอร์ภายนอก (Remote Server)", "Remote Server Connection")
@@ -22,7 +24,19 @@ data class ServerConfig(
val sendHotfix: Boolean = true
) {
val dispatchUrl: String
get() = "http://$remoteHost:$dispatchPort"
get() = "http://${if (executionMode == ServerExecutionMode.LOCAL_EMBEDDED) "127.0.0.1" else remoteHost}:$dispatchPort"
/** Parse the host and ports the same way they will be used by the server. */
fun withNetworkInput(mode: ServerExecutionMode, host: String, sdkPort: String, gamePort: String): ServerConfig? {
val cleanHost = host.trim()
val sdk = sdkPort.toIntOrNull()?.takeIf { it in 1..65535 } ?: return null
val game = gamePort.toIntOrNull()?.takeIf { it in 1..65535 } ?: return null
val address = try { URI("http://$cleanHost") } catch (_: Exception) { return null }
if (address.host.isNullOrBlank() || address.port != -1 || address.userInfo != null ||
!address.rawPath.isNullOrEmpty() || address.rawQuery != null || address.rawFragment != null ||
cleanHost.contains(':') || cleanHost == "0.0.0.0") return null
return copy(executionMode = mode, remoteHost = cleanHost, dispatchPort = sdk, gameserverPort = game)
}
}
data class GmCommandResult(