Advertisement
Guest User

Untitled

a guest
Jan 14th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. package com.murion.engine.network.protocol.connection.decoder.login;
  2.  
  3. import java.util.List;
  4.  
  5. import com.murion.engine.network.protocol.connection.event.login.WorldPullEvent;
  6. import com.murion.engine.network.utilities.Base37Utils;
  7. import com.murion.engine.network.utilities.ByteBufUtils;
  8. import com.murion.engine.network.utilities.LoginUtils;
  9. import com.murion.game.world.node.actor.player.manager.InterfaceManager.Screen;
  10. import com.murion.util.security.IsaacGroup;
  11.  
  12. import io.netty.buffer.ByteBuf;
  13. import io.netty.channel.ChannelHandlerContext;
  14. import io.netty.handler.codec.ByteToMessageDecoder;
  15.  
  16. /**
  17.  * @author _Jordan <jordan.abraham1997@gmail.com>
  18.  */
  19. public class WorldDecoder extends ByteToMessageDecoder {
  20.  
  21.     /*
  22.      * (non-Javadoc)
  23.      *
  24.      * @see io.netty.handler.codec.ByteToMessageDecoder#decode(io.netty.channel.ChannelHandlerContext,
  25.      * io.netty.buffer.ByteBuf, java.util.List)
  26.      */
  27.     @Override
  28.     protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
  29.         if (!in.isReadable()) {
  30.             ctx.pipeline().remove(this);
  31.             return;
  32.         }
  33.  
  34.         in.readUnsignedByte();
  35.         ByteBuf block = LoginUtils.getRSABlock(in);
  36.         int blockId = block.readUnsignedByte();
  37.         if (blockId != 10) {
  38.             ctx.channel().disconnect().sync();
  39.             return;
  40.         }
  41.         int[] isaacSeed = LoginUtils.setIsaacSeeds(block, new int[4]);
  42.         block.readLong();
  43.         String password = ByteBufUtils.readString(block);
  44.         block.readLong();
  45.         block.readLong();
  46.         block = LoginUtils.getXTEABlock(in, isaacSeed);
  47.         String username = block.readByte() == 1 ? ByteBufUtils.readString(block) : Base37Utils.decodeBase37(block.readLong());
  48.         int screenSizeId = block.readUnsignedByte();
  49.         block.readUnsignedShort();// width
  50.         block.readUnsignedShort();// height
  51.         block.readUnsignedByte();
  52.         for (int i = 0; i < 24; i++) {
  53.             block.readByte();
  54.         }
  55.         ByteBufUtils.readString(block);
  56.         IsaacGroup group = LoginUtils.getIsaacGroup(isaacSeed);
  57.         out.add(new WorldPullEvent(username, password, group, Screen.get(screenSizeId)));
  58.     }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement