List of usage examples for io.netty.buffer ByteBuf readInt
public abstract int readInt();
From source file:com.quavo.osrs.network.protocol.codec.handshake.HandshakeDecoder.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (!in.isReadable() || in.readableBytes() < 4) { return;/* ww w .j av a2s. co m*/ } out.add(new HandshakeRequest(this, in.readInt()));// version }
From source file:com.quavo.osrs.network.protocol.codec.login.LoginDecoder.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (!in.isReadable() || in.readableBytes() < 8) { return;// w ww . j av a2s. c o m } LoginType.getType(in.readByte()).filter(a -> in.readShort() == in.readableBytes()) .ifPresent(a -> out.add(new LoginRequest(this, a, in.readInt()))); }
From source file:com.quavo.osrs.network.protocol.codec.login.world.WorldLoginDecoder.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (!in.isReadable()) { return;/*from w w w .j ava 2 s . co m*/ } ByteBuf buffer = ByteBufUtils.encipherRSA(in, EXPONENT, MODULUS); int id = buffer.readByte(); if (id != 1) { return; } int clearanceId = buffer.readByte(); int[] clientKeys = new int[4]; for (int index = 0; index < clientKeys.length; index++) { clientKeys[index] = buffer.readInt(); } LoginClearance clearance = LoginClearance.getType(clearanceId).get().read(buffer); String password = ByteBufUtils.readString(buffer); buffer = ByteBufUtils.decipherXTEA(in, clientKeys); String username = ByteBufUtils.readString(buffer); DisplayMode mode = DisplayMode.getDisplayMode(buffer.readByte()).get(); int width = buffer.readShort(); int height = buffer.readShort(); DisplayInformation display = new DisplayInformation(mode, width, height); buffer.skipBytes(24); String token = ByteBufUtils.readString(buffer); buffer.readInt(); MachineInformation machineInformation = MachineInformation.decode(buffer); buffer.readInt(); buffer.readInt(); buffer.readInt(); buffer.readInt(); buffer.readByte(); int[] crc = new int[16]; for (int index = 0; index < crc.length; index++) { crc[index] = buffer.readInt(); } int[] serverKeys = new int[4]; for (int index = 0; index < serverKeys.length; index++) { serverKeys[index] = clientKeys[index] + 50; } IsaacRandomPair isaacPair = new IsaacRandomPair(new IsaacRandom(serverKeys), new IsaacRandom(clientKeys)); out.add(new WorldLoginRequest(this, type, username, password, clearance, display, machineInformation, crc, token, isaacPair)); }
From source file:com.quavo.osrs.network.protocol.codec.update.UpdateEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, UpdateResponse msg, ByteBuf out) throws Exception { int type = msg.getType(); int id = msg.getId(); ByteBuf container = msg.getContainer(); int compression = container.readUnsignedByte(); int length = container.readInt(); out.writeByte(type);/*from w w w. jav a 2 s . c om*/ out.writeShort(id); out.writeByte(compression); out.writeInt(length); int bytes = container.readableBytes(); if (bytes > 504) { bytes = 504; } out.writeBytes(container.readBytes(bytes)); while ((bytes = container.readableBytes()) != 0) { if (bytes == 0) { break; } else if (bytes > 511) { bytes = 511; } out.writeByte(0xff); out.writeBytes(container.readBytes(bytes)); } }
From source file:com.rs3e.network.protocol.codec.js5.UpdateDecoder.java
License:Open Source License
@Override public Object decode(ChannelHandlerContext ctx, ByteBuf buf) throws Exception { if (buf.readableBytes() < 6) return null; if (updateStage == UpdateStage.READ_VERSION) { updateStage = UpdateStage.READ_REQUEST; int length = buf.readUnsignedByte(); if (buf.readableBytes() >= length) { int version = buf.readInt(); int subVersion = buf.readInt(); String key = ByteBufUtils.readString(buf); return new UpdateVersionMessage(version, subVersion, key); }//w w w . ja v a 2 s . c o m } else { int opcode = buf.readUnsignedByte(); if (opcode == 0 || opcode == 1) { int type = buf.readUnsignedByte(); int file = buf.readInt(); return new FileRequest(opcode == 1, type, file); } else if (opcode == 4) { int key = buf.readUnsignedByte(); buf.readerIndex(buf.readerIndex() + 2); return new UpdateEncryptionMessage(key); } else { buf.readerIndex(buf.readerIndex() + 5); return null; } } return null; }
From source file:com.rs3e.network.protocol.codec.login.LoginDecoder.java
License:Open Source License
/** * Decodes the payload of login.//www. j av a 2 s.c o m * * @param ctx * The channel handler context. * @param buf * The byte buf for writing data. * @return The login message, or {@code Null}. */ /* * private Object decodePayload(ChannelHandlerContext ctx, ByteBuf buf) { * if(buf.readable()) { * * int loginType = buf.readByte(); System.out.println("Login Type: " + * loginType); } return null; } */ private Object decodeLobbyPayload(ChannelHandlerContext context, ByteBuf buffer) throws ProtocolException { int secureBufferSize = buffer.readShort() & 0xFFFF; if (buffer.readableBytes() < secureBufferSize) { throw new ProtocolException("Invalid secure buffer size."); } byte[] secureBytes = new byte[secureBufferSize]; buffer.readBytes(secureBytes); ByteBuf secureBuffer = Unpooled.wrappedBuffer( new BigInteger(secureBytes).modPow(Constants.JS5PrivateKey, Constants.JS5ModulusKey).toByteArray()); int blockOpcode = secureBuffer.readUnsignedByte(); if (blockOpcode != 10) { throw new ProtocolException("Invalid block opcode."); } int[] xteaKey = new int[4]; for (int key = 0; key < xteaKey.length; key++) { xteaKey[key] = secureBuffer.readInt(); } long vHash = secureBuffer.readLong(); if (vHash != 0L) { throw new ProtocolException("Invalid login virtual hash."); } ByteBufUtils.readString(secureBuffer); long[] loginSeeds = new long[2]; for (int seed = 0; seed < loginSeeds.length; seed++) { loginSeeds[seed] = secureBuffer.readLong(); } byte[] xteaBlock = new byte[buffer.readableBytes()]; buffer.readBytes(xteaBlock); return null; // return new LoginPayload(password, xteaKey, xteaBlock); }
From source file:com.rs3e.network.protocol.codec.login.LoginDecoder.java
License:Open Source License
private Object decodeClientDetails(ByteBuf buffer) throws ProtocolException { if (buffer.readableBytes() < loginSize) { throw new ProtocolException("Invalid login size."); }/*ww w. j av a 2s . c om*/ int version = buffer.readInt(); int subVersion = buffer.readInt(); if (version != Constants.ServerRevision && subVersion != Constants.ServerSubRevision) { return new LoginResponse(LoginResponse.GAME_UPDATED); // throw new // ProtocolException("Invalid client version/sub-version."); } /* * if (currentLoginType.equals(LoginTypes.GAME)) { buffer.readByte(); } */ byte[] payload = new byte[loginSize - 8]; buffer.readBytes(payload); return new LoginPayload(currentLoginType, payload); // state = currentLoginType.equals(LoginTypes.LOBBY) ? // LoginState.LOBBY_PAYLOAD : LoginState.GAME_PAYLOAD; // return null; }
From source file:com.rs3e.network.protocol.login.LoginDecoder.java
License:Open Source License
/** * Decodes the payload of login.//www .java 2 s .c o m * @param ctx The channel handler context. * @param buf The byte buf for writing data. * @return The login message, or {@code Null}. */ /*private Object decodePayload(ChannelHandlerContext ctx, ByteBuf buf) { if(buf.readable()) { int loginType = buf.readByte(); System.out.println("Login Type: " + loginType); } return null; }*/ private Object decodeLobbyPayload(ChannelHandlerContext context, ByteBuf buffer) throws ProtocolException { int secureBufferSize = buffer.readShort() & 0xFFFF; if (buffer.readableBytes() < secureBufferSize) { throw new ProtocolException("Invalid secure buffer size."); } byte[] secureBytes = new byte[secureBufferSize]; buffer.readBytes(secureBytes); ByteBuf secureBuffer = Unpooled.wrappedBuffer( new BigInteger(secureBytes).modPow(Constants.JS5PrivateKey, Constants.JS5ModulusKey).toByteArray()); int blockOpcode = secureBuffer.readUnsignedByte(); if (blockOpcode != 10) { throw new ProtocolException("Invalid block opcode."); } int[] xteaKey = new int[4]; for (int key = 0; key < xteaKey.length; key++) { xteaKey[key] = secureBuffer.readInt(); } long vHash = secureBuffer.readLong(); if (vHash != 0L) { throw new ProtocolException("Invalid login virtual hash."); } String password = ByteBufUtils.readString(secureBuffer); long[] loginSeeds = new long[2]; for (int seed = 0; seed < loginSeeds.length; seed++) { loginSeeds[seed] = secureBuffer.readLong(); } byte[] xteaBlock = new byte[buffer.readableBytes()]; buffer.readBytes(xteaBlock); return null; //return new LoginPayload(password, xteaKey, xteaBlock); }
From source file:com.rs3e.network.protocol.login.LoginDecoder.java
License:Open Source License
private Object decodeClientDetails(ByteBuf buffer) { if (buffer.readableBytes() < loginSize) { throw new ProtocolException("Invalid login size."); }// w ww . j a va2s. com int version = buffer.readInt(); int subVersion = buffer.readInt(); if (version != Constants.ServerRevision && subVersion != Constants.ServerSubRevision) { return new LoginResponse(LoginResponse.GAME_UPDATED); //throw new ProtocolException("Invalid client version/sub-version."); } /*if (currentLoginType.equals(LoginTypes.GAME)) { buffer.readByte(); }*/ byte[] payload = new byte[loginSize - 8]; buffer.readBytes(payload); return new LoginPayload(currentLoginType, payload); //state = currentLoginType.equals(LoginTypes.LOBBY) ? LoginState.LOBBY_PAYLOAD : LoginState.GAME_PAYLOAD; //return null; }
From source file:com.rs3e.network.protocol.worldlist.WorldListDecoder.java
License:Open Source License
@Override public WorldHandshakeMessage decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { if (in.readableBytes() < 4) return null; return new WorldHandshakeMessage(in.readInt()); }