Example usage for io.netty.buffer ByteBuf readShort

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

Introduction

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

Prototype

public abstract short readShort();

Source Link

Document

Gets a 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.

Usage

From source file:net.tridentsdk.packets.play.in.PacketPlayInPlayerClickWindow.java

License:Open Source License

@Override
public Packet decode(ByteBuf buf) {
    this.windowId = (int) buf.readByte();
    this.clickedSlot = buf.readShort();
    this.clickedButton = (int) buf.readByte();

    this.actionNumber = buf.readShort();
    this.mode = buf.readShort();
    this.clickedItem = new Slot(buf);

    return this;
}

From source file:net.tridentsdk.packets.play.in.PacketPlayInPlayerConfirmTransaction.java

License:Open Source License

@Override
public Packet decode(ByteBuf buf) {
    buf.readByte(); //ignore windowId, we'd have the window the player has open anyhow

    this.actionNumber = buf.readShort();
    this.accepted = buf.readBoolean();

    return this;
}

From source file:net.tridentsdk.packets.play.in.PacketPlayInPlayerCreativeAction.java

License:Open Source License

@Override
public Packet decode(ByteBuf buf) {
    this.slot = buf.readShort();
    this.item = new Slot(buf);

    return this;
}

From source file:net.tridentsdk.packets.play.in.PacketPlayInPlayerHeldItemChange.java

License:Open Source License

@Override
public Packet decode(ByteBuf buf) {
    this.slot = buf.readShort();

    return this;
}

From source file:net.tridentsdk.server.data.Slot.java

License:Apache License

public Slot(ByteBuf buf) {
    this.id = buf.readShort();
    this.mat = Substance.fromId((byte) this.id);

    if (this.id == -1) {
        return;/*from  w w w . j  a va2  s.c om*/
    }

    this.quantity = buf.readByte();
    this.damageValue = buf.readShort();
    byte b;

    if ((b = buf.readByte()) != 0) {
        try {
            NBTDecoder builder = new NBTDecoder(new ByteBufInputStream(buf));

            this.compoundTag = builder.decode(b);
        } catch (NBTException ignored) {
            // do something
        }
    }
}

From source file:org.beaconmc.network.socket.pipeline.PacketLegacy.java

License:Open Source License

@Override
protected void messageReceived(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception {

    byteBuf.markReaderIndex();/*from w w  w.  j ava2 s .  c  o  m*/
    boolean repliedPing = true;

    try {
        short packetId = byteBuf.readUnsignedByte();
        if (packetId == 254) {
            int length = byteBuf.readableBytes();
            AsyncServerPingEvent asyncServerPingEvent = EventFactory
                    .callAsyncServerPingEvent(this.server.createServerPing());
            if (asyncServerPingEvent.getPing() != null) {
                switch (length) {
                case 0:
                    this.sendPingAndClose(channelHandlerContext,
                            this.toArray(String.format("%s%d%d",
                                    asyncServerPingEvent.getPing().getDescription().getText(),
                                    asyncServerPingEvent.getPing().getPlayers().getOnline(),
                                    asyncServerPingEvent.getPing().getPlayers().getMax())));
                    break;
                case 1:
                    if (byteBuf.readUnsignedByte() != 1) {
                        return;
                    }
                    this.sendPingAndClose(channelHandlerContext,
                            this.toArray(String.format("1\0%d\0%s\0%s\0%d\0%d", 127,
                                    asyncServerPingEvent.getPing().getVersion().getName(),
                                    asyncServerPingEvent.getPing().getDescription().getText(),
                                    asyncServerPingEvent.getPing().getPlayers().getOnline(),
                                    asyncServerPingEvent.getPing().getPlayers().getMax())));
                    break;
                default:
                    boolean checkFlag = byteBuf.readUnsignedByte() == 1;
                    checkFlag &= byteBuf.readUnsignedByte() == 250;
                    checkFlag &= "MC|PingHost".equals(
                            new String(byteBuf.readBytes(byteBuf.readShort() * 2).array(), Charsets.UTF_16));

                    int checkShort = byteBuf.readShort();

                    checkFlag &= byteBuf.readUnsignedByte() >= 73;
                    checkFlag &= 3 + byteBuf.readBytes(byteBuf.readShort() * 2).array().length
                            + 4 == checkShort;
                    checkFlag &= byteBuf.readInt() <= '\uffff';
                    checkFlag &= byteBuf.readableBytes() == 0;

                    if (!checkFlag) {
                        return;
                    }

                    this.sendPingAndClose(channelHandlerContext,
                            this.toArray(String.format("1\0%d\0%s\0%s\0%d\0%d", 127,
                                    asyncServerPingEvent.getPing().getVersion().getName(),
                                    asyncServerPingEvent.getPing().getDescription().getText(),
                                    asyncServerPingEvent.getPing().getPlayers().getOnline(),
                                    asyncServerPingEvent.getPing().getPlayers().getMax())));
                    break;
                }
            } else {
                this.close(channelHandlerContext);
            }
            repliedPing = false;
        } else if (packetId == 0x02 && byteBuf.isReadable()) {
            this.sendPingAndClose(channelHandlerContext, this.toArray(ChatColor.RED + "Outdated Client"));
            repliedPing = false;
        }
    } catch (Exception e) {
        return;
    } finally {
        if (repliedPing) {
            byteBuf.resetReaderIndex();
            channelHandlerContext.channel().pipeline().remove("legacy_ping");
            channelHandlerContext.fireChannelRead(byteBuf.retain());
        }
    }
}

From source file:org.bgp4j.netty.protocol.open.CapabilityCodec.java

License:Apache License

private static Capability decodeMultiProtocolCapability(ByteBuf buffer) {
    MultiProtocolCapability cap = new MultiProtocolCapability();

    assertFixedLength(buffer, BGPv4Constants.BGP_CAPABILITY_LENGTH_MULTIPROTOCOL);

    cap.setAfi(AddressFamily.fromCode(buffer.readShort()));
    buffer.readByte(); // reserved
    cap.setSafi(SubsequentAddressFamily.fromCode(buffer.readByte()));

    return cap;/*from   w w  w.ja  v a 2 s .c o  m*/
}

From source file:org.blockartistry.DynSurround.network.PacketThunder.java

License:MIT License

@Override
public void fromBytes(@Nonnull final ByteBuf buf) {
    this.dimension = buf.readShort();
    this.doFlash = buf.readBoolean();
    final int x = buf.readInt();
    final int y = buf.readInt();
    final int z = buf.readInt();
    this.pos = new BlockPos(x, y, z);
}

From source file:org.blockartistry.DynSurround.network.PacketWeatherUpdate.java

License:MIT License

@Override
public void fromBytes(@Nonnull final ByteBuf buf) {
    this.dimension = buf.readShort();
    this.intensity = buf.readFloat();
    this.maxIntensity = buf.readFloat();
    this.nextRainChange = buf.readInt();
    this.thunderStrength = buf.readFloat();
    this.thunderChange = buf.readInt();
    this.thunderEvent = buf.readInt();
}

From source file:org.eclipse.neoscada.protocol.iec60870.asdu.message.SetPointCommandScaledValue.java

License:Open Source License

public static SetPointCommandScaledValue parse(final ProtocolOptions options, final byte length,
        final ASDUHeader header, final ByteBuf data) {
    final InformationObjectAddress address = InformationObjectAddress.parse(options, data);

    final short value = data.readShort();

    final byte b = data.readByte();

    final byte type = (byte) (b & 0b011111111);
    final boolean execute = !((b & 0b100000000) > 0);

    return new SetPointCommandScaledValue(header, address, value, type, execute);
}