progress towards multi-server handling
- bump some versions - validate Factorio server ID & token -
This commit is contained in:
parent
3821996eeb
commit
4bc46f9753
28 changed files with 577 additions and 139 deletions
|
|
@ -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]+\$")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}" +
|
||||
|
|
|
|||
|
|
@ -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(***)"
|
||||
}
|
||||
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue