diff --git a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacket.kt b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacket.kt deleted file mode 100644 index 02413d8..0000000 --- a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacket.kt +++ /dev/null @@ -1,68 +0,0 @@ -package dev.adamko.kafkatorio.schema.events -// -//import dev.adamko.kafkatorio.schema.SerializerProvider -//import dev.adamko.kafkatorio.schema.SerializerProviderDeserializer -//import dev.adamko.kafkatorio.schema.common.Tick -//import kotlin.reflect.KClass -//import kotlin.reflect.KType -//import kotlin.reflect.typeOf -//import kotlinx.serialization.KSerializer -//import kotlinx.serialization.Serializable -// -// -////@Serializable -////data class KafkatorioPacket( -//// val modVersion: String, -//// val tick: Tick, -//// val data: KafkatorioPacketData, -////) -// -// -//@Serializable(with = KafkatorioPacketData.JsonSerializer::class) -//sealed class KafkatorioPacketData { -// abstract val updateType: KafkatorioPacketDataType -// -// object JsonSerializer : SerializerProviderDeserializer( -// KafkatorioPacketData::class, -// KafkatorioPacketData::updateType.name, -// { json -> KafkatorioPacketDataType.entries.firstOrNull { it.name == json } } -// ) -//} -// -// -///** Discriminator for [KafkatorioPacketData] */ -//@Serializable -//enum class KafkatorioPacketDataType( -// override val serializer: KSerializer -//) : SerializerProvider { -// -// // non-keyed -// CONFIG(ConfigurationUpdate.serializer()), -// CONSOLE_CHAT(ConsoleChatUpdate.serializer()), -// CONSOLE_COMMAND(ConsoleCommandUpdate.serializer()), -// PROTOTYPES(PrototypesUpdate.serializer()), -// SURFACE(SurfaceUpdate.serializer()), -// -// // keyed -// ENTITY(EntityUpdate.serializer()), -// MAP_CHUNK(MapChunkUpdate.serializer()), -// PLAYER(PlayerUpdate.serializer()), -// ; -// -// companion object { -// val entries: Set = values().toSet() -// } -//} -// -////inline fun KafkatorioPacketDataType.isType (): KClass { -//// return when (this) { -//// KafkatorioPacketDataType.CONFIG -> ConfigurationUpdate::class -//// KafkatorioPacketDataType.CONSOLE_CHAT -> ConsoleChatUpdate::class -//// KafkatorioPacketDataType.CONSOLE_COMMAND -> ConsoleCommandUpdate::class -//// KafkatorioPacketDataType.PROTOTYPES -> PrototypesUpdate::class -//// KafkatorioPacketDataType.SURFACE -> SurfaceUpdate::class -//// KafkatorioPacketDataType.ENTITY -> EntityUpdate::class -//// KafkatorioPacketDataType.MAP_CHUNK -> MapChunkUpdate::class -//// KafkatorioPacketDataType.PLAYER -> PlayerUpdate::class -//// } -////} diff --git a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketInstant.kt b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketInstant.kt deleted file mode 100644 index 6dc03cc..0000000 --- a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketInstant.kt +++ /dev/null @@ -1,95 +0,0 @@ -package dev.adamko.kafkatorio.schema.events -// -//import dev.adamko.kafkatorio.schema.common.PlayerIndex -//import dev.adamko.kafkatorio.schema.common.SurfaceIndex -//import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype -//import kotlinx.serialization.EncodeDefault -//import kotlinx.serialization.Serializable -// -// -///** No key, no caching. Must be sent instantly. */ -//sealed class KafkatorioInstantPacketData : KafkatorioPacketData() -// -// -///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -// -// -//@Serializable -//data class ConfigurationUpdate( -// val factorioData: ConfigurationUpdateGameData, -// val allMods: List, -// val modStartupSettingsChange: Boolean, -// val migrationApplied: Boolean, -//) : KafkatorioInstantPacketData() { -// @EncodeDefault -// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.CONFIG -// -// @Serializable -// data class ConfigurationUpdateGameData( -// val oldVersion: String? = null, -// val newVersion: String? = null, -// ) -// -// @Serializable -// data class ConfigurationUpdateModData( -// val modName: String, -// val currentVersion: String? = null, -// val previousVersion: String? = null, -// ) -//} -// -// -///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -// -// -//@Serializable -//data class ConsoleChatUpdate( -// val authorPlayerIndex: PlayerIndex?, -// val content: String, -//) : KafkatorioInstantPacketData() { -// @EncodeDefault -// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.CONSOLE_CHAT -//} -// -// -///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -// -// -//@Serializable -//data class ConsoleCommandUpdate( -// val authorPlayerIndex: PlayerIndex?, -// val command: String, -// val parameters: String, -//) : KafkatorioInstantPacketData() { -// @EncodeDefault -// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.CONSOLE_COMMAND -//} -// -// -///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -// -// -//@Serializable -//data class PrototypesUpdate( -// val prototypes: List, -//) : KafkatorioInstantPacketData() { -// @EncodeDefault -// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.PROTOTYPES -//} -// -// -///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -// -// -//@Serializable -//data class SurfaceUpdate( -// val index: SurfaceIndex, -// val daytime: Double, -// val name: String, -//) : KafkatorioInstantPacketData() { -// @EncodeDefault -// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.SURFACE -//} -// -// -///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ diff --git a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketKeyed.kt b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketKeyed.kt deleted file mode 100644 index 236ac6e..0000000 --- a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketKeyed.kt +++ /dev/null @@ -1,135 +0,0 @@ -package dev.adamko.kafkatorio.schema.events - -//import dev.adamko.kafkatorio.schema.common.Colour -//import dev.adamko.kafkatorio.schema.common.EntityIdentifiers -//import dev.adamko.kafkatorio.schema.common.EntityIdentifiersData -//import dev.adamko.kafkatorio.schema.common.ForceIndex -//import dev.adamko.kafkatorio.schema.common.MapChunkPosition -//import dev.adamko.kafkatorio.schema.common.MapEntityPosition -//import dev.adamko.kafkatorio.schema.common.MapTileDictionary -//import dev.adamko.kafkatorio.schema.common.PlayerIndex -//import dev.adamko.kafkatorio.schema.common.PrototypeName -//import dev.adamko.kafkatorio.schema.common.SurfaceIndex -//import dev.adamko.kafkatorio.schema.common.Tick -//import dev.adamko.kafkatorio.schema.common.UnitNumber -//import kotlinx.serialization.EncodeDefault -//import kotlinx.serialization.Serializable -// -// -//sealed interface KafkatorioKeyedPacketKey -// -// -///** Has a key, so it can be debounced */ -//sealed class KafkatorioKeyedPacketData : KafkatorioPacketData() { -// /** Count how many events this packet is aggregating data from */ -// abstract val eventCounts: Map? -//} -// -// -///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -// -// -//sealed interface EntityUpdateKey : EntityIdentifiers, KafkatorioKeyedPacketKey { -// /** A [unitNumber] is required for caching */ -// override val unitNumber: UnitNumber -// override val name: String -// override val protoType: String -//} -// -// -//@Serializable -//data class EntityUpdate( -// override val unitNumber: UnitNumber, -// override val name: String, -// override val protoType: String, -// -// override val eventCounts: Map? = null, -// -// val chunkPosition: MapChunkPosition? = null, -// val graphicsVariation: UByte? = null, -// val health: Float? = null, -// val isActive: Boolean? = null, -// val isRotatable: Boolean? = null, -// val lastUser: UInt? = null, -// val localisedDescription: String? = null, -// val localisedName: String? = null, -// val prototype: PrototypeName? = null, -//) : KafkatorioKeyedPacketData(), EntityUpdateKey { -// @EncodeDefault -// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.ENTITY -//} -// -// -///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -// -// -//sealed interface MapChunkUpdateKey : KafkatorioKeyedPacketKey { -// val chunkPosition: MapChunkPosition -// val surfaceIndex: SurfaceIndex -//} -// -// -//@Serializable -//data class MapChunkUpdate( -// override val chunkPosition: MapChunkPosition, -// override val surfaceIndex: SurfaceIndex, -// -// override val eventCounts: Map? = null, -// -// val player: PlayerIndex? = null, -// val robot: EntityIdentifiersData? = null, -// val force: ForceIndex? = null, -// /** updated tiles - might be partial and not all tiles in the chunk */ -// val tileDictionary: MapTileDictionary? = null, -// val isDeleted: Boolean? = null, -//) : KafkatorioKeyedPacketData(), MapChunkUpdateKey { -// @EncodeDefault -// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.MAP_CHUNK -//} -// -// -///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ -// -// -//sealed interface PlayerUpdateKey : KafkatorioKeyedPacketKey { -// val index: PlayerIndex -//} -// -// -//@Serializable -//data class PlayerUpdate( -// override val index: PlayerIndex, -// -// override val eventCounts: Map? = null, -// -// val characterUnitNumber: UnitNumber? = null, -// val chatColour: Colour? = null, -// val colour: Colour? = null, -// val name: String? = null, -// -// val afkTime: Tick? = null, -// val ticksToRespawn: Tick? = null, -// val forceIndex: ForceIndex? = null, -// val isAdmin: Boolean? = null, -// val isConnected: Boolean? = null, -// val isShowOnMap: Boolean? = null, -// val isSpectator: Boolean? = null, -// val lastOnline: Tick? = null, -// val onlineTime: Tick? = null, -// val position: MapEntityPosition? = null, -// val surfaceIndex: SurfaceIndex? = null, -// val tag: String? = null, -// val diedCause: EntityIdentifiersData? = null, -// -// val bannedReason: String? = null, -// val kickedReason: String? = null, -// val disconnectReason: String? = null, -// /** `true` when a player is removed (deleted) from the game */ -// val isRemoved: Boolean? = null, -//) : KafkatorioKeyedPacketData(), PlayerUpdateKey { -// @EncodeDefault -// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.PLAYER -//} -// -// -///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ diff --git a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/prototypes/factorioPrototypes.kt b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/prototypes/factorioPrototypes.kt deleted file mode 100644 index a65c77d..0000000 --- a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/prototypes/factorioPrototypes.kt +++ /dev/null @@ -1,58 +0,0 @@ -package dev.adamko.kafkatorio.schema.prototypes -// -//import dev.adamko.kafkatorio.schema.SerializerProvider -//import dev.adamko.kafkatorio.schema.SerializerProviderDeserializer -//import dev.adamko.kafkatorio.schema.common.Colour -//import dev.adamko.kafkatorio.schema.common.PrototypeName -//import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype.PrototypeObjectName -//import kotlinx.serialization.Contextual -//import kotlinx.serialization.DeserializationStrategy -//import kotlinx.serialization.EncodeDefault -//import kotlinx.serialization.KSerializer -//import kotlinx.serialization.Serializable -//import kotlinx.serialization.json.JsonContentPolymorphicSerializer -//import kotlinx.serialization.json.JsonElement -//import kotlinx.serialization.json.contentOrNull -//import kotlinx.serialization.json.jsonObject -//import kotlinx.serialization.json.jsonPrimitive -// -// -//@Serializable(with = FactorioPrototype.JsonSerializer::class) -//sealed class FactorioPrototype { -// @EncodeDefault -// abstract val prototypeObjectName: PrototypeObjectName -// -// enum class PrototypeObjectName( -// override val serializer: KSerializer -// ) : SerializerProvider { -// LuaTilePrototype(MapTilePrototype.serializer()), -// ; -// -// companion object { -// val entries: Set = values().toSet() -// } -// } -// -// object JsonSerializer : SerializerProviderDeserializer( -// FactorioPrototype::class, -// FactorioPrototype::prototypeObjectName.name, -// { json -> PrototypeObjectName.entries.firstOrNull { it.name == json } } -// ) -//} -// -// -// -//@Serializable -//data class MapTilePrototype( -// val name: PrototypeName, -// val layer: UInt, -// val mapColour: Colour, -// @Contextual -// val collisionMasks: List, -// val order: String, -// /** Can the tile be mined for resources? */ -// val canBeMined: Boolean, -//) : FactorioPrototype() { -// @EncodeDefault -// override val prototypeObjectName: PrototypeObjectName = PrototypeObjectName.LuaTilePrototype -//} diff --git a/modules/events-server/src/main/kotlin/dev/adamko/kafkatorio/processor/KafkatorioTopology.kt b/modules/events-server/src/main/kotlin/dev/adamko/kafkatorio/processor/KafkatorioTopology.kt index dd6bc5e..9aa4332 100644 --- a/modules/events-server/src/main/kotlin/dev/adamko/kafkatorio/processor/KafkatorioTopology.kt +++ b/modules/events-server/src/main/kotlin/dev/adamko/kafkatorio/processor/KafkatorioTopology.kt @@ -40,6 +40,16 @@ internal class KafkatorioTopology( playerUpdates() } + private fun splitPackets() { + val builder = StreamsBuilder() + val packets = factorioServerPacketStream(builder) + splitFactorioServerPacketStream(packets) + + val topology = builder.build() + + launchTopology("splitPackets", topology) + } + private fun groupTilesMapChunks() { val builder = StreamsBuilder() val topology = groupMapChunks(builder) @@ -52,16 +62,6 @@ internal class KafkatorioTopology( launchTopology("saveTiles", topology) } - private fun splitPackets() { - val builder = StreamsBuilder() - val packets = factorioServerPacketStream(builder) - splitFactorioServerPacketStream(packets) - - val topology = builder.build() - - launchTopology("splitPackets", topology) - } - private fun playerUpdates() { val builder = StreamsBuilder() playerUpdatesToWsServer(websocketServer, builder)