progress towards multi-server handling

- bump some versions
- validate Factorio server ID & token
-
This commit is contained in:
Adam 2022-08-28 19:37:49 +02:00
parent 3821996eeb
commit 4bc46f9753
28 changed files with 577 additions and 139 deletions

View file

@ -76,9 +76,39 @@ data class EntityIdentifiersData(
) : EntityIdentifiers
/** Friendly identifier, used in URLs. Should be human-readable. */
@Serializable
@SerialName("kafkatorio.id.FactorioServerId")
@JvmInline
value class FactorioServerId(private val id: String) {
override fun toString() = id
value class FactorioServerId(val id: String) : CharSequence by id {
init {
require(id.isNotBlank()) { "require FactorioServerId is not blank: '$id'" }
require(id.matches(validIdRegex)) { "require FactorioServerId matches $validIdRegex: '$id'" }
}
override fun toString(): String = id
companion object {
val validIdRegex = Regex("""^[a-zA-Z0-9\-_]+""" + "\$")
}
}
/** Short identifier, used in tokens. Might not be human-readable. */
@Serializable
@SerialName("kafkatorio.id.FactorioServerToken")
@JvmInline
value class FactorioServerToken(private val id: String) : CharSequence by id {
init {
require(id.isNotBlank()) { "require FactorioServerToken is not blank: '$id'" }
require(id.matches(FactorioServerId.validIdRegex)) { "require FactorioServerToken matches ${validIdRegex}: '$id'" }
}
override fun toString(): String = id
companion object {
val validIdRegex = Regex("^[a-zA-Z0-9]+\$")
}
}

View file

@ -110,7 +110,7 @@ value class ServerMapTilePngFilename(val value: String) {
chunkX: Int,
chunkY: Int,
) : this(
"servers/${serverId}" +
"servers/${serverId.id}" +
"/map" +
"/layers/${layer.dir}" +
"/s${surfaceIndex}" +

View file

@ -0,0 +1,13 @@
package dev.adamko.kafkatorio.schema.common
import kotlin.jvm.JvmInline
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
@SerialName("kafkatorio.common.MaskedValue")
@JvmInline
value class MaskedValue(val value: String) {
override fun toString(): String = "Secret(***)"
}

View file

@ -24,4 +24,16 @@ sealed class KafkatorioPacketData
data class KafkatorioPacketDataError(
val message: String? = null,
val rawValue: String? = null,
) : KafkatorioPacketData()
) : KafkatorioPacketData() {
constructor(
exception: Exception,
rawValue: String? = null
) : this(
message = """
${exception::class.qualifiedName} ${exception.message}
${exception.stackTraceToString()}
""".trimIndent(),
rawValue = rawValue,
)
}