@Override public void handlePacket(Message m, GameSession gs) { Player p = gs.getPlayer(); int size = m.getLength(); if (m.getOpcode() == 119) { size -= 14; } if (m.getOpcode() != 138) { gs.getPlayer().setDistancedTask(null); } gs.getPlayer().getMovement().reset(); int steps = (size - 5) / 2; int[] pathX = new int[steps]; int[] pathY = new int[steps]; // writeWordBigEndianA = writeLEShortA int firstX = m.readLEShortA() - (gs.getPlayer().getLocation().getRegionX() - 6) * 8; int firstY = m.readShortA() - (gs.getPlayer().getLocation().getRegionY() - 6) * 8; m.readByteC(); for (int i = 0; i < steps; i++) { pathX[i] = m.readByte(); pathY[i] = m.readByteS(); } p.getMovement().addToWalkingQueue(firstX, firstY); for (int i = 0; i < steps; i++) { pathX[i] += firstX; pathY[i] += firstY; p.getMovement().addToWalkingQueue(pathX[i], pathY[i]); } }
/** 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); } }