Class MaplePacketEncoder

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelOutboundHandlerAdapter
io.netty.handler.codec.MessageToByteEncoder<Object>
server.netty.MaplePacketEncoder
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelOutboundHandler

public class MaplePacketEncoder extends io.netty.handler.codec.MessageToByteEncoder<Object>
Netty 出站處理器,負責將明文封包位元組陣列加密後寫入網路緩衝區。

繼承自 MessageToByteEncoder,對每個待發送的 byte[] 執行:

  • MapleAESOFB 取得 4 位元組封包頭(含長度與版本資訊)。
  • MapleAESOFB.crypt(byte[]) 就地加密,並在客戶端鎖(client.getLock())保護下 組合「頭+密文」後寫入 ByteBuf,確保多執行緒下的加密序列一致性。
  • ServerConstants.CUSTOM_ENCRYPTION 開啟,以隨機位元組 mtp 對全包 XOR。

當尚未建立 MapleClient(握手封包)時跳過 AES 加密,僅進行選用的 XOR。 當 ServerConstants.LOG_Handle_PACKETS 啟用時,印出 SendPacketOpcode 名稱、包頭十六進位與封包長度,並寫入已知封包日誌。

  • Nested Class Summary

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

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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    encode(io.netty.channel.ChannelHandlerContext chc, Object message, io.netty.buffer.ByteBuf buffer)
     

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

    acceptOutboundMessage, allocateBuffer, isPreferDirect, write

    Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter

    bind, close, connect, deregister, disconnect, flush, read

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharable

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    exceptionCaught, handlerAdded, handlerRemoved
  • Constructor Details

    • MaplePacketEncoder

      public MaplePacketEncoder()
  • Method Details

    • encode

      protected void encode(io.netty.channel.ChannelHandlerContext chc, Object message, io.netty.buffer.ByteBuf buffer) throws Exception
      Specified by:
      encode in class io.netty.handler.codec.MessageToByteEncoder<Object>
      Throws:
      Exception