Class PacketDecoder

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.codec.ByteToMessageDecoder
com.hypixel.hytale.protocol.io.netty.PacketDecoder
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

public class PacketDecoder extends io.netty.handler.codec.ByteToMessageDecoder
Netty decoder for the protocol. Handles length-prefixed framing and packet-level timeouts. Wire format: [4-byte payload length] [4-byte packet ID] [payload]

Timeout handling: - Tracks time since last complete packet was decoded - Reads timeout duration from channel attribute (set by server) - Fires ReadTimeoutException if no complete packet arrives within timeout - Handles both "no data" and "trickle data" scenarios

Early validation silently closes connections for obviously malformed packets to avoid exception overhead and DoS amplification via Sentry logging.

Validation order (fail-fast for DoS resistance): 1. Payload length bounds (don't wait for data if length is invalid) 2. Packet ID validity (don't wait for payload if ID is unknown) 3. Payload size vs max for this packet type

  • Nested Class Summary

    Nested classes/interfaces inherited from class io.netty.handler.codec.ByteToMessageDecoder

    io.netty.handler.codec.ByteToMessageDecoder.Cumulator

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Field Summary

    Fields inherited from class io.netty.handler.codec.ByteToMessageDecoder

    COMPOSITE_CUMULATOR, MERGE_CUMULATOR
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelActive(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    channelInactive(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
     

    Methods inherited from class io.netty.handler.codec.ByteToMessageDecoder

    channelRead, channelReadComplete, handlerRemoved, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggered

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    isSharable

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PacketDecoder

      public PacketDecoder()
  • Method Details

    • handlerAdded

      public void handlerAdded(@Nonnull io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      handlerAdded in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerAdded in class io.netty.channel.ChannelHandlerAdapter
      Throws:
      Exception
    • channelActive

      public void channelActive(@Nonnull io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelActive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • channelInactive

      public void channelInactive(@Nonnull io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelInactive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelInactive in class io.netty.handler.codec.ByteToMessageDecoder
      Throws:
      Exception