Skip to content

Commit

Permalink
Handle any packet encoding exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
senseiwells committed Aug 29, 2024
1 parent a82ce79 commit b3132c1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/kotlin/me/senseiwells/replay/recorder/ReplayRecorder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.replaymod.replaystudio.protocol.PacketTypeRegistry
import com.replaymod.replaystudio.replay.ReplayMetaData
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import io.netty.handler.codec.EncoderException
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -199,7 +200,16 @@ abstract class ReplayRecorder(
return
}

val saved = this.encodePacket(outgoing)
val saved = try {
this.encodePacket(outgoing)
} catch (e: EncoderException) {
if (!safe) {
ServerReplay.logger.error("Failed to encode packet, liked due to being off-thread, skipping", e)
} else {
ServerReplay.logger.error("Failed to encode packet, skipping", e)
}
return
}
if (ServerReplay.config.debug) {
val type = outgoing.getDebugName()
this.packets.getOrPut(type) { DebugPacketData(type, 0, 0) }.increment(saved.buf.readableBytes())
Expand Down

0 comments on commit b3132c1

Please sign in to comment.