package com.l2jserver.game.net.handler; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import com.l2jserver.game.net.Lineage2Connection; import com.l2jserver.game.net.packet.ClientPacket; /** * This handler dispatches the {@link ClientPacket#process(Lineage2Connection)} * method and creates a new {@link Lineage2Connection} once a new channel is * open. * * @author Rogiel */ public class Lineage2PacketHandler extends SimpleChannelHandler { /** * The Lineage 2 connection */ private Lineage2Connection connection; @Override public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { connection = new Lineage2Connection(e.getChannel()); connection.getPacketWriter().setConnection(connection); super.channelOpen(ctx, e); } @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { final Object msg = e.getMessage(); if (!(msg instanceof ClientPacket)) return; final ClientPacket packet = (ClientPacket) msg; packet.process(connection); super.messageReceived(ctx, e); } @Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception { super.writeRequested(ctx, e); } }