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") } enum class ServerStatus { STOPPED, STARTING, RUNNING, STOPPING, ERROR } data class ServerConfig( val executionMode: ServerExecutionMode = ServerExecutionMode.LOCAL_EMBEDDED, val remoteHost: String = "127.0.0.1", val dispatchPort: Int = 21000, val gameserverPort: Int = 23301, val serverKey: String = "", val sendHotfix: Boolean = true ) { val dispatchUrl: String 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( val success: Boolean, val message: String, val timestamp: Long = System.currentTimeMillis() )