From 32d97a47c6df8a983a63999f63dcf9b420338af0 Mon Sep 17 00:00:00 2001 From: Fiereu Date: Tue, 21 Jul 2026 08:06:58 +0200 Subject: [PATCH] refactor(protocols.game): resolve sonarlint findings in packet codecs (#49) --- .../net/game/packets/DialogActionPacket.kt | 7 +---- .../game/packets/MatchmakingActionPacket.kt | 2 +- .../packets/OverworldWeatherControlPacket.kt | 28 ++++++++++--------- .../net/game/packets/ServerMessagePacket.kt | 2 +- .../game/packets/SocialActionOutcomePacket.kt | 3 +- .../net/game/packets/WorldNoticeSlotPacket.kt | 2 +- .../packets/battle/BattleBulkStatePacket.kt | 2 +- .../battle/BattleDisconnectMessagePacket.kt | 2 +- .../packets/battle/BattleSidePartyPacket.kt | 6 ++-- 9 files changed, 26 insertions(+), 28 deletions(-) diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogActionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogActionPacket.kt index 2d4a40c..57c97e4 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogActionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogActionPacket.kt @@ -8,12 +8,7 @@ object NullMessageArg : DialogMessageArg() data class CreatureDataArg(val value: Int, val args: List) : DialogMessageArg() -data class CreatureMovesArg(val team: Byte, val moveIds: List) : DialogMessageArg() { - override fun equals(other: Any?): Boolean = - other is CreatureMovesArg && team == other.team && moveIds == other.moveIds - - override fun hashCode(): Int = team * 31 + moveIds.hashCode() -} +data class CreatureMovesArg(val team: Byte, val moveIds: List) : DialogMessageArg() data class MoveAnimationArg(val sourceSlot: Byte, val targetSlot: Byte, val moveId: Short) : DialogMessageArg() diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingActionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingActionPacket.kt index bcceadd..1b160b0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingActionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingActionPacket.kt @@ -46,7 +46,7 @@ private val MatchmakingActionCodec: Codec = override fun write(buf: WriteBuffer, value: MatchmakingActionKind) { buf.writeByte(value.actionId) when (value) { - is TeleportAction -> {} + is TeleportAction -> Unit is SelectTierAction -> { var v = value.tierId for (i in 0 until 4) { diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldWeatherControlPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldWeatherControlPacket.kt index 0661ce5..277d66e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldWeatherControlPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldWeatherControlPacket.kt @@ -28,19 +28,21 @@ object OverworldWeatherControlPacketCodec : PacketCodec { + skyId = field(S16LE) { it.skyId!! } + skyVariant = field(S16LE) { it.skyVariant!! } + } + 4 -> { + particleId = field(S16LE) { it.particleId!! } + particleVariant = field(S16LE) { it.particleVariant!! } + paramA = field(F32LE) { it.paramA!! } + paramB = field(F32LE) { it.paramB!! } + paramC = field(F32LE) { it.paramC!! } + paramD = field(F32LE) { it.paramD!! } + duration = field(S16LE) { it.duration!! } + } + 5 -> duration = field(S16LE) { it.duration!! } } return OverworldWeatherControlPacket( effectType = effectType, diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerMessagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerMessagePacket.kt index dbdf451..71f92e3 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerMessagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerMessagePacket.kt @@ -34,7 +34,7 @@ private val ServerMessageArgCodec: Codec = var shortValues: List? = null when { type == 5 || type == 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! } - type == 28 -> {} + type == 28 -> Unit type == 30 -> longValue = field(S64LE) { it.longValue!! } type == 9 || type == 10 || type == 17 -> intValue = field(S32LE) { it.intValue!! } else -> shortValues = field(S16LE.listPrefixed(U8)) { it.shortValues!! } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialActionOutcomePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialActionOutcomePacket.kt index 0bd13a7..539d2ed 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialActionOutcomePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialActionOutcomePacket.kt @@ -16,5 +16,6 @@ object SocialActionOutcomePacketCodec : PacketCodec() return SocialActionOutcomePacket(action, entityId, value) } - private fun resolveKind(action: Int): Int = 0 + // The action to payload-kind mapping is not reverse engineered yet, so every kind is 0. + @Suppress("kotlin:S1172") private fun resolveKind(action: Int): Int = 0 } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldNoticeSlotPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldNoticeSlotPacket.kt index 4d5e018..7dcfebf 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldNoticeSlotPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldNoticeSlotPacket.kt @@ -26,7 +26,7 @@ private val WorldNoticeArgCodec: Codec = var stringValue: String? = null var shortValues: List? = null when (type) { - 28 -> {} + 28 -> Unit 30 -> longValue = field(S64LE) { it.longValue!! } 9, 10, diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleBulkStatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleBulkStatePacket.kt index a246a0c..78a91c7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleBulkStatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleBulkStatePacket.kt @@ -58,7 +58,7 @@ internal val BattleMessageArgCodec: Codec = val t = value.type.toInt() when { t == 5 -> Utf16LeNullTerminated.write(buf, (value.payload as StringArgPayload).value) - t == 28 -> {} + t == 28 -> Unit t == 30 -> S64LE.write(buf, (value.payload as LongArgPayload).value) t == 9 || t == 10 || t == 17 -> S32LE.write(buf, (value.payload as IntArgPayload).value) t == 18 -> Utf16LeNullTerminated.write(buf, (value.payload as StringArgPayload).value) diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleDisconnectMessagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleDisconnectMessagePacket.kt index 7ecd733..d0d87f1 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleDisconnectMessagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleDisconnectMessagePacket.kt @@ -26,7 +26,7 @@ internal val MessageArgCodec: Codec = var stringValue: String? = null var shortValues: List? = null when (type) { - 28 -> {} + 28 -> Unit 30 -> longValue = field(S64LE) { it.longValue!! } 9, 10, diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleSidePartyPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleSidePartyPacket.kt index aba4386..0077e9a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleSidePartyPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/battle/BattleSidePartyPacket.kt @@ -21,11 +21,11 @@ data class BattlePartyPokemon( private val BattlePartyPokemonCodec: Codec = object : PacketCodec() { override fun CodecScope.body(): BattlePartyPokemon { + // Flag bits 1 and 2 exist in the protocol but are never written. Their fields are + // only skipped over when reading. val flags = field(U8) { - (if (false) 1 else 0) or - (if (false) 2 else 0) or - (if (it.slot.toInt() != 0) 4 else 0) or + (if (it.slot.toInt() != 0) 4 else 0) or (if (it.partyIndex.toInt() != -1) 8 else 0) or (if (it.statusEffect != null) 16 else 0) }