List of usage examples for io.netty.buffer ByteBuf readShort
public abstract short readShort();
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 w w . j a va 2s .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 ww . j av a 2 s. c om*/ } 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.util.buf.ByteBufUtils.java
License:Open Source License
/** * Encrypts a {@link ByteBuf} using with a exponent and modulus. * //ww w.j a v a 2 s . com * @param buffer The {@link ByteBuf} to encrypt. * @param exponent The exponent. * @param modulus The modulus. * @return The encrypted buffer. */ public static ByteBuf encipherRSA(ByteBuf buffer, BigInteger exponent, BigInteger modulus) { byte[] bytes = new byte[buffer.readShort()]; buffer.readBytes(bytes); return Unpooled.wrappedBuffer(new BigInteger(bytes).modPow(exponent, modulus).toByteArray()); }
From source file:com.rs3e.network.protocol.codec.login.LoginDecoder.java
License:Open Source License
/** * Decodes the payload of login.//from w w w. j a v a 2 s.c om * * @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 decodeConnectionType(ByteBuf buffer) { int loginType = buffer.readUnsignedByte(); if (loginType != 16 && loginType != 18 && loginType != 19) { return new LoginResponse(LoginResponse.BAD_LOGIN_PACKET); // throw new ProtocolException("Invalid login opcode: " + // loginType); }/*from www .j av a 2s . co m*/ currentLoginType = loginType == 19 ? LoginType.LOBBY : LoginType.GAME; loginSize = buffer.readShort() & 0xFFFF; state = LoginState.CLIENT_DETAILS; return null; }
From source file:com.rs3e.network.protocol.login.LoginDecoder.java
License:Open Source License
/** * Decodes the payload of login.//from ww w . jav a2 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 decodeConnectionType(ByteBuf buffer) { int loginType = buffer.readUnsignedByte(); if (loginType != 16 && loginType != 18 && loginType != 19) { return new LoginResponse(LoginResponse.BAD_LOGIN_PACKET); //throw new ProtocolException("Invalid login opcode: " + loginType); }/*from w w w . j a va 2 s . c o m*/ currentLoginType = loginType == 19 ? LoginType.LOBBY : LoginType.GAME; loginSize = buffer.readShort() & 0xFFFF; state = LoginState.CLIENT_DETAILS; return null; }
From source file:com.rs3e.network.session.impl.LoginSession.java
License:Open Source License
private void decodeLobbyLogin(ByteBuf buffer) { int secureBufferSize = buffer.readShort() & 0xFFFF; if (buffer.readableBytes() < secureBufferSize) { channel.write(new LoginResponse(LoginResponse.BAD_LOGIN_PACKET)); return;/*w w w. ja va 2 s.c om*/ } 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) { channel.write(new LoginResponse(LoginResponse.BAD_LOGIN_PACKET)); return; } int[] xteaKey = new int[4]; for (int key = 0; key < xteaKey.length; key++) { xteaKey[key] = secureBuffer.readInt(); } long vHash = secureBuffer.readLong(); if (vHash != 0L) { channel.write(new LoginResponse(LoginResponse.BAD_LOGIN_PACKET)); return; } 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); XTEA xtea = new XTEA(xteaKey); xtea.decrypt(xteaBlock, 0, xteaBlock.length); InputStream xteaBuffer = new InputStream(xteaBlock); boolean decodeAsString = xteaBuffer.readByte() == 1; String username = decodeAsString ? xteaBuffer.readString() : Base37Utils.decodeBase37(xteaBuffer.readLong()); @SuppressWarnings("unused") int gameType = xteaBuffer.readUnsignedByte(); @SuppressWarnings("unused") int languageID = xteaBuffer.readUnsignedByte(); @SuppressWarnings("unused") int displayMode = xteaBuffer.readByte(); @SuppressWarnings("unused") int screenWidth = xteaBuffer.readUnsignedShort();//Client screen width @SuppressWarnings("unused") int screenHeight = xteaBuffer.readUnsignedShort();//Client screen height @SuppressWarnings("unused") int anUnknownByte = xteaBuffer.readByte(); byte[] randomData = new byte[24]; for (int i = 0; i < randomData.length; i++) { randomData[i] = (byte) (xteaBuffer.readByte() & 0xFF); } @SuppressWarnings("unused") String clientSettings = xteaBuffer.readString(); int indexFiles = xteaBuffer.readByte() & 0xff; int[] crcValues = new int[indexFiles]; for (int i = 0; i < crcValues.length; i++) { crcValues[i] = xteaBuffer.readInt(); } int length = xteaBuffer.readUnsignedByte(); byte[] machineData = new byte[length]; for (int data = 0; data < machineData.length; data++) { machineData[data] = (byte) xteaBuffer.readUnsignedByte(); } xteaBuffer.readInt();//Packet receive count xteaBuffer.readString();//Some param string (empty) xteaBuffer.readInt();//Another param (0) xteaBuffer.readInt();//Yet another param (2036537831) String serverToken = xteaBuffer.readString(); if (!serverToken.equals(Constants.SERVER_TOKEN)) { channel.write(new LoginResponse(LoginResponse.BAD_SESSION)); return; } xteaBuffer.readByte();//Final param (2424) if (GeneralUtils.invalidAccountName(username)) { //session.getLoginPackets().sendClientPacket(3);//Invalid username or password channel.write(new LoginResponse(LoginResponse.INVALID_UN_PWD)); return; } /* if (World.getPlayers().size() >= Settings.PLAYERS_LIMIT - 10) { session.getLoginPackets().sendClientPacket(7);//World full return; } if (World.containsPlayer(username) || World.containsLobbyPlayer(username)) { session.getLoginPackets().sendClientPacket(5);//Account not logged out return; } if (AntiFlood.getSessionsIP(session.getIP()) > 3) { session.getLoginPackets().sendClientPacket(9);//Login limit exceeded return; }*/ Player player;// = new Player(new PlayerDefinition(username, password)); if (!SerializableFilesManager.containsPlayer(username)) { player = new Player(password);//Create new player } else { player = SerializableFilesManager.loadPlayer(username); if (player == null) { //session.getLoginPackets().sendClientPacket(20);//Invalid login server channel.write(new LoginResponse(LoginResponse.INVALID_LOGIN_SERVER)); return; } /*if (!SerializableFilesManager.createBackup(username)) { //session.getLoginPackets().sendClientPacket(20);//Invalid login server //return; }*/ if (!player.isCorrectPassword(password)) { //session.getLoginPackets().sendClientPacket(3); channel.write(new LoginResponse(LoginResponse.INVALID_UN_PWD)); return; } } // || player.getBanned() > Utils.currentTimeMillis() if (player.isPermBanned()) { //session.getLoginPackets().sendClientPacket(4);//Account disabled channel.write(new LoginResponse(LoginResponse.ACCOUNT_DISABLED)); return; } //24 = account does not exist player.lobbyInit(context.channel(), username); /*int returnCode = 2; if (FileManager.contains(username)) { player = (Player) FileManager.load(username); if (player == null) { returnCode = 24; } else if (!password.equals(player.getDefinition().getPassword()) && !Constants.isOwnerIP(channel.getRemoteAddress().toString().split(":")[0].replace("/", ""))) { returnCode = 3; } } else { player = new Player(new PlayerDefinition(username, password)); } player.init(channel, currentLoginType); World.getWorld().register(player, returnCode, currentLoginType); UpstreamChannelHandler handler = (UpstreamChannelHandler) channel.getPipeline().get("upHandler"); handler.setPlayer(player); context.getChannel().setAttachment(player); channel.getPipeline().replace("decoder", "decoder", new InBufferDecoder());*/ }
From source file:com.spotify.folsom.client.binary.RequestTestTemplate.java
License:Apache License
protected void assertHeader(final ByteBuf b, final int opcode, final int keyLength, final int extrasLength, final int totalLength, final int opaque, final long cas) { assertByte(0x80, b.readByte());//from ww w . j ava 2s .c o m assertByte(opcode, b.readByte()); assertShort(keyLength, b.readShort()); assertShort(extrasLength, b.readByte()); assertZeros(b, 3); assertEquals(totalLength, b.readInt()); assertEquals(opaque, b.readInt()); assertEquals(cas, b.readLong()); }
From source file:com.tesora.dve.db.mysql.libmy.MyEOFPktResponse.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { warningCount = cb.readShort(); statusFlags = cb.readShort(); }