/** Invoked when a connection is closed */ @Override public final void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) { GameSession session = (GameSession) ctx.getAttachment(); if (session != null) { synchronized (LogicService.getWorkerThread()) { World.getSingleton().unregisterPlayer(session.getPlayer()); } } ctx.getChannel().close(); }
/** Invoked when a packet is received */ @Override public final void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { GameSession session = (GameSession) ctx.getAttachment(); if (e.getMessage() instanceof Message) { if (session != null) { synchronized (LogicService.getWorkerThread()) { Message packet = (Message) e.getMessage(); session.pushPacket(packet); } } } if (e.getMessage() instanceof ChannelBuffer) { ctx.getChannel().write(ctx); } }