refactor(protocols.game): resolve sonarlint findings in packet codecs (#49)
This commit is contained in:
1 parent
b58e555730
commit
32d97a47c6
9 files changed
+16
-18
No files matched your search
+1
-6
@@ -8,12 +8,7 @@ object NullMessageArg : DialogMessageArg()
|
|||||||
|
|
||||||
data class CreatureDataArg(val value: Int, val args: List<DialogMessageArg>) : DialogMessageArg()
|
data class CreatureDataArg(val value: Int, val args: List<DialogMessageArg>) : DialogMessageArg()
|
||||||
|
|
||||||
data class CreatureMovesArg(val team: Byte, val moveIds: List<Short>) : DialogMessageArg() {
|
data class CreatureMovesArg(val team: Byte, val moveIds: List<Short>) : 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 MoveAnimationArg(val sourceSlot: Byte, val targetSlot: Byte, val moveId: Short) :
|
data class MoveAnimationArg(val sourceSlot: Byte, val targetSlot: Byte, val moveId: Short) :
|
||||||
DialogMessageArg()
|
DialogMessageArg()
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ private val MatchmakingActionCodec: Codec<MatchmakingActionKind> =
|
|||||||
override fun write(buf: WriteBuffer, value: MatchmakingActionKind) {
|
override fun write(buf: WriteBuffer, value: MatchmakingActionKind) {
|
||||||
buf.writeByte(value.actionId)
|
buf.writeByte(value.actionId)
|
||||||
when (value) {
|
when (value) {
|
||||||
is TeleportAction -> {}
|
is TeleportAction -> Unit
|
||||||
is SelectTierAction -> {
|
is SelectTierAction -> {
|
||||||
var v = value.tierId
|
var v = value.tierId
|
||||||
for (i in 0 until 4) {
|
for (i in 0 until 4) {
|
||||||
|
|||||||
+6
-4
@@ -28,10 +28,12 @@ object OverworldWeatherControlPacketCodec : PacketCodec<OverworldWeatherControlP
|
|||||||
var paramC: Float? = null
|
var paramC: Float? = null
|
||||||
var paramD: Float? = null
|
var paramD: Float? = null
|
||||||
var duration: Short? = null
|
var duration: Short? = null
|
||||||
if (t == 0) {
|
when (t) {
|
||||||
|
0 -> {
|
||||||
skyId = field(S16LE) { it.skyId!! }
|
skyId = field(S16LE) { it.skyId!! }
|
||||||
skyVariant = field(S16LE) { it.skyVariant!! }
|
skyVariant = field(S16LE) { it.skyVariant!! }
|
||||||
} else if (t == 4) {
|
}
|
||||||
|
4 -> {
|
||||||
particleId = field(S16LE) { it.particleId!! }
|
particleId = field(S16LE) { it.particleId!! }
|
||||||
particleVariant = field(S16LE) { it.particleVariant!! }
|
particleVariant = field(S16LE) { it.particleVariant!! }
|
||||||
paramA = field(F32LE) { it.paramA!! }
|
paramA = field(F32LE) { it.paramA!! }
|
||||||
@@ -39,8 +41,8 @@ object OverworldWeatherControlPacketCodec : PacketCodec<OverworldWeatherControlP
|
|||||||
paramC = field(F32LE) { it.paramC!! }
|
paramC = field(F32LE) { it.paramC!! }
|
||||||
paramD = field(F32LE) { it.paramD!! }
|
paramD = field(F32LE) { it.paramD!! }
|
||||||
duration = field(S16LE) { it.duration!! }
|
duration = field(S16LE) { it.duration!! }
|
||||||
} else if (t == 5) {
|
}
|
||||||
duration = field(S16LE) { it.duration!! }
|
5 -> duration = field(S16LE) { it.duration!! }
|
||||||
}
|
}
|
||||||
return OverworldWeatherControlPacket(
|
return OverworldWeatherControlPacket(
|
||||||
effectType = effectType,
|
effectType = effectType,
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ private val ServerMessageArgCodec: Codec<ServerMessageArg> =
|
|||||||
var shortValues: List<Short>? = null
|
var shortValues: List<Short>? = null
|
||||||
when {
|
when {
|
||||||
type == 5 || type == 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! }
|
type == 5 || type == 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! }
|
||||||
type == 28 -> {}
|
type == 28 -> Unit
|
||||||
type == 30 -> longValue = field(S64LE) { it.longValue!! }
|
type == 30 -> longValue = field(S64LE) { it.longValue!! }
|
||||||
type == 9 || type == 10 || type == 17 -> intValue = field(S32LE) { it.intValue!! }
|
type == 9 || type == 10 || type == 17 -> intValue = field(S32LE) { it.intValue!! }
|
||||||
else -> shortValues = field(S16LE.listPrefixed(U8)) { it.shortValues!! }
|
else -> shortValues = field(S16LE.listPrefixed(U8)) { it.shortValues!! }
|
||||||
|
|||||||
+2
-1
@@ -16,5 +16,6 @@ object SocialActionOutcomePacketCodec : PacketCodec<SocialActionOutcomePacket>()
|
|||||||
return SocialActionOutcomePacket(action, entityId, value)
|
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
|
||||||
}
|
}
|
||||||
+1
-1
@@ -26,7 +26,7 @@ private val WorldNoticeArgCodec: Codec<WorldNoticeArg> =
|
|||||||
var stringValue: String? = null
|
var stringValue: String? = null
|
||||||
var shortValues: List<Short>? = null
|
var shortValues: List<Short>? = null
|
||||||
when (type) {
|
when (type) {
|
||||||
28 -> {}
|
28 -> Unit
|
||||||
30 -> longValue = field(S64LE) { it.longValue!! }
|
30 -> longValue = field(S64LE) { it.longValue!! }
|
||||||
9,
|
9,
|
||||||
10,
|
10,
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ internal val BattleMessageArgCodec: Codec<BattleMessageArg> =
|
|||||||
val t = value.type.toInt()
|
val t = value.type.toInt()
|
||||||
when {
|
when {
|
||||||
t == 5 -> Utf16LeNullTerminated.write(buf, (value.payload as StringArgPayload).value)
|
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 == 30 -> S64LE.write(buf, (value.payload as LongArgPayload).value)
|
||||||
t == 9 || t == 10 || t == 17 -> S32LE.write(buf, (value.payload as IntArgPayload).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)
|
t == 18 -> Utf16LeNullTerminated.write(buf, (value.payload as StringArgPayload).value)
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ internal val MessageArgCodec: Codec<MessageArg> =
|
|||||||
var stringValue: String? = null
|
var stringValue: String? = null
|
||||||
var shortValues: List<Short>? = null
|
var shortValues: List<Short>? = null
|
||||||
when (type) {
|
when (type) {
|
||||||
28 -> {}
|
28 -> Unit
|
||||||
30 -> longValue = field(S64LE) { it.longValue!! }
|
30 -> longValue = field(S64LE) { it.longValue!! }
|
||||||
9,
|
9,
|
||||||
10,
|
10,
|
||||||
|
|||||||
+2
-2
@@ -21,10 +21,10 @@ data class BattlePartyPokemon(
|
|||||||
private val BattlePartyPokemonCodec: Codec<BattlePartyPokemon> =
|
private val BattlePartyPokemonCodec: Codec<BattlePartyPokemon> =
|
||||||
object : PacketCodec<BattlePartyPokemon>() {
|
object : PacketCodec<BattlePartyPokemon>() {
|
||||||
override fun CodecScope<BattlePartyPokemon>.body(): BattlePartyPokemon {
|
override fun CodecScope<BattlePartyPokemon>.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 =
|
val flags =
|
||||||
field(U8) {
|
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.partyIndex.toInt() != -1) 8 else 0) or
|
||||||
(if (it.statusEffect != null) 16 else 0)
|
(if (it.statusEffect != null) 16 else 0)
|
||||||
|
|||||||
Reference in new issue
Block a user