Example usage for io.netty.buffer ByteBuf readInt

List of usage examples for io.netty.buffer ByteBuf readInt

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf readInt.

Prototype

public abstract int readInt();

Source Link

Document

Gets a 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.

Usage

From source file:com.vethrfolnir.game.network.login.received.ReceivedNewId.java

License:Open Source License

@Override
public void read(NetworkClient context, ByteBuf buff, Object... params) {
    Corax.config().setProperty("LoginServer.ServerId", buff.readInt());
}

From source file:com.vethrfolnir.game.network.mu.crypt.MuCryptUtils.java

License:Open Source License

public static final long readRing(ByteBuf converter, short[] shift) {
    for (int i = 0; i < shift.length; i++) {
        converter.writeByte(shift[i]);// ww  w .j  ava 2s.c o  m
    }

    long uInt = converter.readInt();
    converter.clear();
    return uInt;
}

From source file:com.vethrfolnir.game.network.mu.crypt.MuDecoder.java

License:Open Source License

/**
 * @param decrypted/*from   w  ww  . j av  a2s .  c o m*/
 * @param encrypted
 * @param decServerKeys
 * @return
 */
private static int BlockDecode(ByteBuf decrypted, short[] InBuf, ByteBuf converter, long[] Keys) {

    long[] Ring = new long[4];
    short[] Shift = new short[4];

    ShiftBytes(Shift, 0x00, InBuf, 0x00, 0x10);
    ShiftBytes(Shift, 0x16, InBuf, 0x10, 0x02);

    writeByteArray(converter, Shift);
    flushArray(Shift, 0, 4);

    ShiftBytes(Shift, 0x00, InBuf, 0x12, 0x10);
    ShiftBytes(Shift, 0x16, InBuf, 0x22, 0x02);

    writeByteArray(converter, Shift);
    flushArray(Shift, 0, 4);

    ShiftBytes(Shift, 0x00, InBuf, 0x24, 0x10);
    ShiftBytes(Shift, 0x16, InBuf, 0x34, 0x02);

    writeByteArray(converter, Shift);
    flushArray(Shift, 0, 4);

    ShiftBytes(Shift, 0x00, InBuf, 0x36, 0x10);
    ShiftBytes(Shift, 0x16, InBuf, 0x46, 0x02);

    writeByteArray(converter, Shift);
    flushArray(Shift, 0, 4);

    // for (int i = 0; i < Ring.length; i++) {
    // System.err.print(Integer.toHexString((int) Ring[i])+" ");;
    // }

    // System.err.println();

    for (int i = 0; i < Ring.length; i++) {
        Ring[i] = converter.readInt();
    }
    converter.clear();

    Ring[2] = Ring[2] ^ Keys[10] ^ (Ring[3] & 0xFFFF);
    Ring[1] = Ring[1] ^ Keys[9] ^ (Ring[2] & 0xFFFF);
    Ring[0] = Ring[0] ^ Keys[8] ^ (Ring[1] & 0xFFFF);

    //       System.err.println("Finished Ring: ");
    //       for (int i = 0; i < Ring.length; i++) {
    //       System.err.print(Integer.toHexString((int) Ring[i])+" ");;
    //       }
    //       System.err.println();
    int[] CryptBuf = new int[4];

    // Had ushort cast here.
    CryptBuf[0] = (int) (Keys[8] ^ ((Ring[0] * Keys[4]) % Keys[0]));

    CryptBuf[1] = (int) (Keys[9] ^ ((Ring[1] * Keys[5]) % Keys[1]) ^ (Ring[0] & 0xFFFF));
    CryptBuf[2] = (int) (Keys[10] ^ ((Ring[2] * Keys[6]) % Keys[2]) ^ (Ring[1] & 0xFFFF));
    CryptBuf[3] = (int) (Keys[11] ^ ((Ring[3] * Keys[7]) % Keys[3]) ^ (Ring[2] & 0xFFFF));

    //      System.err.println("Pre done: " + PrintData.printData(CryptBuf));

    short[] Finale = new short[2];
    ShiftBytes(Finale, 0x00, InBuf, 0x48, 0x10);
    Finale[0] ^= Finale[1];
    Finale[0] ^= 0x3D;

    converter.clear();
    for (int i = 0; i < CryptBuf.length; i++) {
        converter.writeShort(CryptBuf[i]);
    }

    decrypted.writeBytes(converter, Finale[0]);
    converter.clear();

    //System.out.println(PrintData.printData(decrypted.nioBuffer()));

    // System.err.println("Finale: "+ Finale[0]);

    short Check = 0xF8;
    for (int i = 0; i < Finale[0]; ++i)
        Check = (short) (Check ^ decrypted.getUnsignedByte(i));

    if (Finale[1] == Check)
        return Finale[0];

    //System.err.println("Finale["+Finale[0]+"] And done: "+PrintData.printData(decrypted.nioBuffer()));

    return Finale[0];
}

From source file:com.vethrfolnir.login.network.game.GameChannelHandler.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    ByteBuf buff = (ByteBuf) msg;

    int opcode = buff.readUnsignedByte();

    switch (opcode) {
    case 0x0A: // first registration
        ServerRegistration.read(null, buff, nameService, ctx);
        break;/*from  www  .j a v a2  s .  co  m*/
    case 0x0B: {
        nameService.getServer(ctx.channel()).setOnlinePlayers(buff.readInt());
        ;
    }
    default:
        log.warn("Unknown packet[opcode = 0x" + PrintData.fillHex(opcode, 2) + "]");
        break;
    }
    buff.release();
}

From source file:com.vethrfolnir.network.ReadPacket.java

License:Open Source License

protected int readD(ByteBuf buff) {
    return buff.readInt();
}

From source file:com.weibo.api.motan.transport.netty.NettyDecoder.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {

    if (in.readableBytes() <= MotanConstants.NETTY_HEADER) {
        return;/*from ww  w . j a  v  a2  s .c o  m*/
    }

    in.markReaderIndex();

    short type = in.readShort();

    if (type != MotanConstants.NETTY_MAGIC_TYPE) {
        in.resetReaderIndex();
        throw new MotanFrameworkException("NettyDecoder transport header not support, type: " + type);
    }

    byte messageType = (byte) in.readShort();
    long requestId = in.readLong();

    int dataLength = in.readInt();

    // FIXME dataLength?
    if (in.readableBytes() < dataLength) {
        in.resetReaderIndex();
        return;
    }

    if (maxContentLength > 0 && dataLength > maxContentLength) {
        LoggerUtil.warn(
                "NettyDecoder transport data content length over of limit, size: {}  > {}. remote={} local={}",
                dataLength, maxContentLength, ctx.channel().remoteAddress(), ctx.channel().localAddress());
        Exception e = new MotanServiceException(
                "NettyDecoder transport data content length over of limit, size: " + dataLength + " > "
                        + maxContentLength);

        if (messageType == MotanConstants.FLAG_REQUEST) {
            Response response = buildExceptionResponse(requestId, e);
            ctx.channel().writeAndFlush(response);
            throw e;
        } else {
            throw e;
        }
    }

    byte[] data = new byte[dataLength];

    in.readBytes(data);

    try {
        String remoteIp = getRemoteIp(ctx.channel());
        out.add(codec.decode(client, remoteIp, data));
    } catch (Exception e) {
        //????
        if (messageType == MotanConstants.FLAG_REQUEST) {
            Response response = buildExceptionResponse(requestId, e);
            ctx.channel().writeAndFlush(response);
            return;
        } else {
            out.add(buildExceptionResponse(requestId, e));
            return;
        }
    }
}

From source file:com.xx_dev.apn.proxy.ApnProxyAESDecoder.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    switch (this.state()) {
    case READ_MAGIC_NUMBER: {
        int magicNumber = in.readInt();
        if (magicNumber != 0x34ed2b11) {
            throw new Exception("Wrong magic number!");
        }/* w w  w. ja v  a  2 s  .c o m*/
        this.checkpoint(STATE.READ_LENGTH);
    }
    case READ_LENGTH: {
        length = in.readInt();
        if (length > 1024 * 512 + 1000) {
            ctx.close();
        }
        this.checkpoint(STATE.READ_CONTENT);
    }
    case READ_CONTENT: {
        c1.init(Cipher.DECRYPT_MODE, securekey, iv);
        byte[] data = new byte[length];
        in.readBytes(data, 0, length);
        byte[] raw = c1.doFinal(data);
        ByteBuf outBuf = ctx.alloc().buffer();
        outBuf.writeBytes(raw);
        out.add(outBuf);
        this.checkpoint(STATE.READ_MAGIC_NUMBER);
        break;
    }
    default:
        throw new Error("Shouldn't reach here.");
    }

}

From source file:com.yea.remote.netty.codec.NettyMessageDecoder.java

License:Apache License

@Override
public Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    ByteBuf frame = (ByteBuf) super.decode(ctx, in);
    if (frame == null) {
        return null;
    }/*from   w w  w . ja  va  2 s . c  o  m*/
    ISerializer serializer = serializePool.borrow();
    try {
        Message message = new Message();
        byte[] sessionID = new byte[16];
        Header header = new Header();
        header.setCrcCode(frame.readInt());
        header.setLength(frame.readInt());
        frame.readBytes(sessionID);
        header.setSessionID(sessionID);
        header.setType(frame.readByte());
        header.setPriority(frame.readByte());
        header.setResult(frame.readByte());
        RemoteConstants.CompressionAlgorithm compressionAlgorithm = RemoteConstants.CompressionAlgorithm
                .valueOf(frame.readByte());
        if (compressionAlgorithm != null && compressionAlgorithm.code() > 0) {
            //
            serializer.setCompress(new Compress().setCompressionAlgorithm(compressionAlgorithm.algorithm()));
        }
        long basedate = frame.readLong();

        int attachmentSize = frame.readByte();
        if (attachmentSize > 0) {
            attachmentSize = frame.readByte();//?Date?String?
            if (attachmentSize > 0) {
                byte[] keyArray = null;
                byte[] valueArray = null;
                for (int i = 0; i < attachmentSize; i++) {
                    keyArray = new byte[frame.readShort()];
                    frame.readBytes(keyArray);
                    valueArray = new byte[frame.readShort()];
                    frame.readBytes(valueArray);

                    header.addAttachment(new String(keyArray, "ISO-8859-1"),
                            serializer.deserialize(valueArray));
                }
            }
            attachmentSize = frame.readByte();//Date?
            if (attachmentSize > 0) {
                byte[] keyArray = null;
                byte length = 0;
                for (int i = 0; i < attachmentSize; i++) {
                    keyArray = new byte[frame.readShort()];
                    frame.readBytes(keyArray);
                    length = frame.readByte();
                    if (length == 1) {
                        header.addAttachment(new String(keyArray, "ISO-8859-1"),
                                new Date(basedate - frame.readByte()));
                    } else if (length == 2) {
                        header.addAttachment(new String(keyArray, "ISO-8859-1"),
                                new Date(basedate - frame.readShort()));
                    } else if (length == 4) {
                        header.addAttachment(new String(keyArray, "ISO-8859-1"),
                                new Date(basedate - frame.readInt()));
                    } else {
                        header.addAttachment(new String(keyArray, "ISO-8859-1"),
                                new Date(basedate - frame.readLong()));
                    }
                }
            }
            attachmentSize = frame.readByte();//String?
            if (attachmentSize > 0) {
                byte[] keyArray = null;
                byte[] valueArray = null;
                for (int i = 0; i < attachmentSize; i++) {
                    keyArray = new byte[frame.readShort()];
                    frame.readBytes(keyArray);
                    valueArray = new byte[frame.readShort()];
                    frame.readBytes(valueArray);

                    header.addAttachment(new String(keyArray, "ISO-8859-1"),
                            new String(valueArray, "ISO-8859-1"));
                }
            }
        }
        header.addAttachment(NettyConstants.MessageHeaderAttachment.SEND_DATE.value(), new Date(basedate));
        header.addAttachment(NettyConstants.MessageHeaderAttachment.RECIEVE_DATE.value(), new Date());
        message.setHeader(header);

        if (frame.readableBytes() > 4) {
            int length = frame.readInt();//Body
            byte[] objArray = new byte[length];
            frame.readBytes(objArray);
            try {
                Object body = serializer.deserialize(objArray);
                message.setBody(body);
            } catch (Exception ex) {
                if (RemoteConstants.MessageType.SERVICE_RESP.value() == message.getHeader().getType()) {
                    message.getHeader().setType(RemoteConstants.MessageType.SUSPEND_RESP.value());
                    message.getHeader().setResult(RemoteConstants.MessageResult.FAILURE.value());
                    message.setBody(ex);
                } else if (RemoteConstants.MessageType.SERVICE_REQ.value() == message.getHeader().getType()) {
                    message.getHeader().setType(RemoteConstants.MessageType.SUSPEND_REQ.value());
                    message.getHeader().setResult(RemoteConstants.MessageResult.FAILURE.value());
                    message.setBody(ex);
                } else {
                    throw ex;
                }
            }
        }

        return message;
    } finally {
        serializePool.restore(serializer);
        frame.release();
    }
}

From source file:com.yyon.grapplinghook.entities.grappleArrow.java

License:Open Source License

@Override
public void readSpawnData(ByteBuf data) {
    this.shootingEntityID = data.readInt();
    this.shootingEntity = this.worldObj.getEntityByID(this.shootingEntityID);
    this.righthand = data.readBoolean();
}

From source file:com.yyon.grapplinghook.entities.magnetArrow.java

License:Open Source License

@Override
public void readSpawnData(ByteBuf data) {
    super.readSpawnData(data);
    this.repelconf = data.readInt();
}