Java Code Examples for io.netty.buffer.ByteBuf.readUnsignedShort()

The following are Jave code examples for showing how to use readUnsignedShort() of the io.netty.buffer.ByteBuf class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: reactive-pg-client   File: MessageDecoder.java   Source Code and License Vote up 6 votes
private Column[]  decodeRowDescription(ByteBuf in) {
  Column[] columns = new Column[in.readUnsignedShort()];
  for (int c = 0; c < columns.length; ++c) {
    String fieldName = Util.readCStringUTF8(in);
    int tableOID = in.readInt();
    short columnAttributeNumber = in.readShort();
    int typeOID = in.readInt();
    short typeSize = in.readShort();
    int typeModifier = in.readInt();
    int textOrBinary = in.readUnsignedShort(); // Useless for now
    Column column = new Column(
      fieldName,
      tableOID,
      columnAttributeNumber,
      DataType.valueOf(typeOID),
      typeSize,
      typeModifier,
      DataFormat.valueOf(textOrBinary)
    );
    columns[c] = column;
  }
  return columns;
}
 
Example 2
Project: sstable-adaptor   File: CBUtil.java   Source Code and License Vote up 5 votes
public static String readString(ByteBuf cb)
{
    try
    {
        int length = cb.readUnsignedShort();
        return readString(cb, length);
    }
    catch (IndexOutOfBoundsException e)
    {
        throw new ProtocolException("Not enough bytes to read an UTF8 serialized string preceded by its 2 bytes length");
    }
}
 
Example 3
Project: sstable-adaptor   File: CBUtil.java   Source Code and License Vote up 5 votes
public static byte[] readBytes(ByteBuf cb)
{
    try
    {
        int length = cb.readUnsignedShort();
        byte[] bytes = new byte[length];
        cb.readBytes(bytes);
        return bytes;
    }
    catch (IndexOutOfBoundsException e)
    {
        throw new ProtocolException("Not enough bytes to read a byte array preceded by its 2 bytes length");
    }
}
 
Example 4
Project: sstable-adaptor   File: CBUtil.java   Source Code and License Vote up 5 votes
public static Map<String, ByteBuffer> readBytesMap(ByteBuf cb)
{
    int length = cb.readUnsignedShort();
    Map<String, ByteBuffer> m = new HashMap<>(length);
    for (int i = 0; i < length; i++)
    {
        String k = readString(cb);
        ByteBuffer v = readValue(cb);
        m.put(k, v);
    }
    return m;
}
 
Example 5
Project: sstable-adaptor   File: CBUtil.java   Source Code and License Vote up 5 votes
public static List<String> readStringList(ByteBuf cb)
{
    int length = cb.readUnsignedShort();
    List<String> l = new ArrayList<String>(length);
    for (int i = 0; i < length; i++)
        l.add(readString(cb));
    return l;
}
 
Example 6
Project: CustomWorldGen   File: ByteBufUtils.java   Source Code and License Vote up 5 votes
/**
 * An extended length short. Used by custom payload packets to extend size.
 *
 * @param buf
 * @return
 */
public static int readVarShort(ByteBuf buf)
{
    int low = buf.readUnsignedShort();
    int high = 0;
    if ((low & 0x8000) != 0)
    {
        low = low & 0x7FFF;
        high = buf.readUnsignedByte();
    }
    return ((high & 0xFF) << 15) | low;
}
 
Example 7
Project: sstable-adaptor   File: CBUtil.java   Source Code and License Vote up 5 votes
public static List<ByteBuffer> readValueList(ByteBuf cb, ProtocolVersion protocolVersion)
{
    int size = cb.readUnsignedShort();
    if (size == 0)
        return Collections.<ByteBuffer>emptyList();

    List<ByteBuffer> l = new ArrayList<ByteBuffer>(size);
    for (int i = 0; i < size; i++)
        l.add(readBoundValue(cb, protocolVersion));
    return l;
}
 
Example 8
Project: sstable-adaptor   File: CBUtil.java   Source Code and License Vote up 5 votes
public static Pair<List<String>, List<ByteBuffer>> readNameAndValueList(ByteBuf cb, ProtocolVersion protocolVersion)
{
    int size = cb.readUnsignedShort();
    if (size == 0)
        return Pair.create(Collections.<String>emptyList(), Collections.<ByteBuffer>emptyList());

    List<String> s = new ArrayList<>(size);
    List<ByteBuffer> l = new ArrayList<>(size);
    for (int i = 0; i < size; i++)
    {
        s.add(readString(cb));
        l.add(readBoundValue(cb, protocolVersion));
    }
    return Pair.create(s, l);
}
 
Example 9
Project: Quavo   File: GamePacketDecoder.java   Source Code and License Vote up 5 votes
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
	if (!in.isReadable() || !player.getChannel().isRegistered()) {
		return;
	}
	int opcode = in.readUnsignedByte();
	Optional<PacketDecoderIdentifier> data = PacketDecoderIdentifier.getPacket(opcode);
	if (data.isPresent()) {
		PacketDecoderIdentifier packet = data.get();

		int size = packet.getSize();
		if (packet.getType() == PacketType.VARIABLE_BYTE) {
			if (in.readableBytes() < 1) {
				return;
			}
			size = in.readUnsignedByte();
		} else if (packet.getType() == PacketType.VARIABLE_SHORT) {
			if (in.readableBytes() < 2) {
				return;
			}
			size = in.readUnsignedShort();
		}

		if (in.readableBytes() >= size) {
			if (size < 0) {
				return;
			}

			byte[] bytes = new byte[size];
			in.readBytes(bytes, 0, size);
			out.add(new GamePacketRequest(this, player, packet.getId(), new GamePacketReader(Unpooled.wrappedBuffer(bytes))));
		}

	} else {
		System.out.println("No data present for incoming packet: " + opcode + ".");
		in.readBytes(new byte[in.readableBytes()]);
	}
}
 
Example 10
Project: Quavo   File: UpdateDecoder.java   Source Code and License Vote up 5 votes
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
	if (!in.isReadable() || in.readableBytes() < 4) {
		return;
	}

	Optional<UpdateType> request = UpdateType.getType(in.readUnsignedByte());
	if (request.isPresent()) {
		UpdateType updateType = request.get();
		switch (updateType) {
		case LOW_PRIORITY_UPDATE:
		case HIGH_PRIORITY_UPDATE:
			int uid = in.readUnsignedMedium();
			int type = (uid >> 16);
			int id = (uid & 0xffff);

			out.add(new UpdateRequest(this, type, id, updateType == UpdateType.HIGH_PRIORITY_UPDATE));
			break;
		case XOR_ENCRYPTION_UPDATE:
			int key = in.readUnsignedByte();
			in.readUnsignedShort();
			out.add(new XOREncryptionRequest(this, key));
			break;
		}
	} else {
		in.readUnsignedMedium();
	}
}
 
Example 11
Project: CustomWorldGen   File: LegacyPingHandler.java   Source Code and License Vote up 4 votes
public void channelRead(ChannelHandlerContext p_channelRead_1_, Object p_channelRead_2_) throws Exception
{
    ByteBuf bytebuf = (ByteBuf)p_channelRead_2_;
    bytebuf.markReaderIndex();
    boolean flag = true;

    try
    {
        if (bytebuf.readUnsignedByte() == 254)
        {
            InetSocketAddress inetsocketaddress = (InetSocketAddress)p_channelRead_1_.channel().remoteAddress();
            MinecraftServer minecraftserver = this.networkSystem.getServer();
            int i = bytebuf.readableBytes();

            switch (i)
            {
                case 0:
                    LOGGER.debug("Ping: (<1.3.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s2 = String.format("%s\u00a7%d\u00a7%d", new Object[] {minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s2));
                    break;
                case 1:

                    if (bytebuf.readUnsignedByte() != 1)
                    {
                        return;
                    }

                    LOGGER.debug("Ping: (1.4-1.5.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s));
                    break;
                default:
                    boolean flag1 = bytebuf.readUnsignedByte() == 1;
                    flag1 = flag1 & bytebuf.readUnsignedByte() == 250;
                    flag1 = flag1 & "MC|PingHost".equals(new String(bytebuf.readBytes(bytebuf.readShort() * 2).array(), Charsets.UTF_16BE));
                    int j = bytebuf.readUnsignedShort();
                    flag1 = flag1 & bytebuf.readUnsignedByte() >= 73;
                    flag1 = flag1 & 3 + bytebuf.readBytes(bytebuf.readShort() * 2).array().length + 4 == j;
                    flag1 = flag1 & bytebuf.readInt() <= 65535;
                    flag1 = flag1 & bytebuf.readableBytes() == 0;

                    if (!flag1)
                    {
                        return;
                    }

                    LOGGER.debug("Ping: (1.6) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s1 = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    ByteBuf bytebuf1 = this.getStringBuffer(s1);

                    try
                    {
                        this.writeAndFlush(p_channelRead_1_, bytebuf1);
                    }
                    finally
                    {
                        bytebuf1.release();
                    }
            }

            bytebuf.release();
            flag = false;
            return;
        }
    }
    catch (RuntimeException var21)
    {
        return;
    }
    finally
    {
        if (flag)
        {
            bytebuf.resetReaderIndex();
            p_channelRead_1_.channel().pipeline().remove("legacy_query");
            p_channelRead_1_.fireChannelRead(p_channelRead_2_);
        }
    }
}
 
Example 12
Project: simulacron   File: ByteBufCodec.java   Source Code and License Vote up 4 votes
@Override
public int readUnsignedShort(ByteBuf source) {
  return source.readUnsignedShort();
}
 
Example 13
Project: message-broker   File: HeaderFrame.java   Source Code and License Vote up 4 votes
public static HeaderFrame parse(ByteBuf buf, int channel) throws Exception {
    int classId = buf.readUnsignedShort();
    // ignore weight
    buf.skipBytes(2);
    long bodySize = buf.readLong();
    HeaderFrame headerFrame = new HeaderFrame(channel, classId, bodySize);

    int propertyFlags = buf.readUnsignedShort();

    // Skip other property flags if exists
    boolean hasMoreProperties = (propertyFlags & LAST_BIT_MASK) != 0;
    while (hasMoreProperties) {
        int otherPropertyFlags = buf.readUnsignedShort();
        hasMoreProperties = (otherPropertyFlags & LAST_BIT_MASK) != 0;
    }

    // read known properties
    if ((propertyFlags & CONTENT_TYPE_MASK) != 0) {
        headerFrame.setContentType(ShortString.parse(buf));
    }

    if ((propertyFlags & ENCODING_MASK) != 0) {
        headerFrame.setContentEncoding(ShortString.parse(buf));
    }

    if ((propertyFlags & HEADERS_MASK) != 0) {
        headerFrame.setHeaders(FieldTable.parse(buf));
    }

    if ((propertyFlags & DELIVERY_MODE_MASK) != 0) {
        headerFrame.setDeliveryMode(buf.readUnsignedByte());
    }

    if ((propertyFlags & PRIORITY_MASK) != 0) {
        headerFrame.setPriority(buf.readUnsignedByte());
    }

    if ((propertyFlags & CORRELATION_ID_MASK) != 0) {
        headerFrame.setCorrelationId(ShortString.parse(buf));
    }

    if ((propertyFlags & REPLY_TO_MASK) != 0) {
        headerFrame.setReplyTo(ShortString.parse(buf));
    }

    if ((propertyFlags & EXPIRATION_MASK) != 0) {
        headerFrame.setExpiration(ShortString.parse(buf));
    }

    if ((propertyFlags & MESSAGE_ID_MASK) != 0) {
        headerFrame.setMessageId(ShortString.parse(buf));
    }

    if ((propertyFlags & TIMESTAMP_MASK) != 0) {
        headerFrame.setTimestamp(buf.readLong());
    }

    if ((propertyFlags & TYPE_MASK) != 0) {
        headerFrame.setType(ShortString.parse(buf));
    }

    if ((propertyFlags & USER_ID_MASK) != 0) {
        headerFrame.setUserId(ShortString.parse(buf));
    }

    if ((propertyFlags & APPLICATION_ID_MASK) != 0) {
        headerFrame.setAppId(ShortString.parse(buf));
    }

    headerFrame.properties.add(PROPERTY_FLAGS, FieldValue.parseLongInt(propertyFlags));
    return headerFrame;
}
 
Example 14
Project: DecompiledMinecraft   File: PingResponseHandler.java   Source Code and License Vote up 4 votes
public void channelRead(ChannelHandlerContext p_channelRead_1_, Object p_channelRead_2_) throws Exception
{
    ByteBuf bytebuf = (ByteBuf)p_channelRead_2_;
    bytebuf.markReaderIndex();
    boolean flag = true;

    try
    {
        if (bytebuf.readUnsignedByte() == 254)
        {
            InetSocketAddress inetsocketaddress = (InetSocketAddress)p_channelRead_1_.channel().remoteAddress();
            MinecraftServer minecraftserver = this.networkSystem.getServer();
            int i = bytebuf.readableBytes();

            switch (i)
            {
                case 0:
                    logger.debug("Ping: (<1.3.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s2 = String.format("%s\u00a7%d\u00a7%d", new Object[] {minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s2));
                    break;

                case 1:
                    if (bytebuf.readUnsignedByte() != 1)
                    {
                        return;
                    }

                    logger.debug("Ping: (1.4-1.5.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s));
                    break;

                default:
                    boolean flag1 = bytebuf.readUnsignedByte() == 1;
                    flag1 = flag1 & bytebuf.readUnsignedByte() == 250;
                    flag1 = flag1 & "MC|PingHost".equals(new String(bytebuf.readBytes(bytebuf.readShort() * 2).array(), Charsets.UTF_16BE));
                    int j = bytebuf.readUnsignedShort();
                    flag1 = flag1 & bytebuf.readUnsignedByte() >= 73;
                    flag1 = flag1 & 3 + bytebuf.readBytes(bytebuf.readShort() * 2).array().length + 4 == j;
                    flag1 = flag1 & bytebuf.readInt() <= 65535;
                    flag1 = flag1 & bytebuf.readableBytes() == 0;

                    if (!flag1)
                    {
                        return;
                    }

                    logger.debug("Ping: (1.6) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s1 = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    ByteBuf bytebuf1 = this.getStringBuffer(s1);

                    try
                    {
                        this.writeAndFlush(p_channelRead_1_, bytebuf1);
                    }
                    finally
                    {
                        bytebuf1.release();
                    }
            }

            bytebuf.release();
            flag = false;
            return;
        }
    }
    catch (RuntimeException var21)
    {
        return;
    }
    finally
    {
        if (flag)
        {
            bytebuf.resetReaderIndex();
            p_channelRead_1_.channel().pipeline().remove("legacy_query");
            p_channelRead_1_.fireChannelRead(p_channelRead_2_);
        }
    }
}
 
Example 15
Project: DecompiledMinecraft   File: PingResponseHandler.java   Source Code and License Vote up 4 votes
public void channelRead(ChannelHandlerContext p_channelRead_1_, Object p_channelRead_2_) throws Exception
{
    ByteBuf bytebuf = (ByteBuf)p_channelRead_2_;
    bytebuf.markReaderIndex();
    boolean flag = true;

    try
    {
        if (bytebuf.readUnsignedByte() == 254)
        {
            InetSocketAddress inetsocketaddress = (InetSocketAddress)p_channelRead_1_.channel().remoteAddress();
            MinecraftServer minecraftserver = this.networkSystem.getServer();
            int i = bytebuf.readableBytes();

            switch (i)
            {
                case 0:
                    logger.debug("Ping: (<1.3.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s2 = String.format("%s\u00a7%d\u00a7%d", new Object[] {minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s2));
                    break;

                case 1:
                    if (bytebuf.readUnsignedByte() != 1)
                    {
                        return;
                    }

                    logger.debug("Ping: (1.4-1.5.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s));
                    break;

                default:
                    boolean flag1 = bytebuf.readUnsignedByte() == 1;
                    flag1 = flag1 & bytebuf.readUnsignedByte() == 250;
                    flag1 = flag1 & "MC|PingHost".equals(new String(bytebuf.readBytes(bytebuf.readShort() * 2).array(), Charsets.UTF_16BE));
                    int j = bytebuf.readUnsignedShort();
                    flag1 = flag1 & bytebuf.readUnsignedByte() >= 73;
                    flag1 = flag1 & 3 + bytebuf.readBytes(bytebuf.readShort() * 2).array().length + 4 == j;
                    flag1 = flag1 & bytebuf.readInt() <= 65535;
                    flag1 = flag1 & bytebuf.readableBytes() == 0;

                    if (!flag1)
                    {
                        return;
                    }

                    logger.debug("Ping: (1.6) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s1 = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    ByteBuf bytebuf1 = this.getStringBuffer(s1);

                    try
                    {
                        this.writeAndFlush(p_channelRead_1_, bytebuf1);
                    }
                    finally
                    {
                        bytebuf1.release();
                    }
            }

            bytebuf.release();
            flag = false;
            return;
        }
    }
    catch (RuntimeException var21)
    {
        return;
    }
    finally
    {
        if (flag)
        {
            bytebuf.resetReaderIndex();
            p_channelRead_1_.channel().pipeline().remove("legacy_query");
            p_channelRead_1_.fireChannelRead(p_channelRead_2_);
        }
    }
}
 
Example 16
Project: BaseClient   File: PingResponseHandler.java   Source Code and License Vote up 4 votes
public void channelRead(ChannelHandlerContext p_channelRead_1_, Object p_channelRead_2_) throws Exception
{
    ByteBuf bytebuf = (ByteBuf)p_channelRead_2_;
    bytebuf.markReaderIndex();
    boolean flag = true;

    try
    {
        if (bytebuf.readUnsignedByte() == 254)
        {
            InetSocketAddress inetsocketaddress = (InetSocketAddress)p_channelRead_1_.channel().remoteAddress();
            MinecraftServer minecraftserver = this.networkSystem.getServer();
            int i = bytebuf.readableBytes();

            switch (i)
            {
                case 0:
                    logger.debug("Ping: (<1.3.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s2 = String.format("%s\u00a7%d\u00a7%d", new Object[] {minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s2));
                    break;

                case 1:
                    if (bytebuf.readUnsignedByte() != 1)
                    {
                        return;
                    }

                    logger.debug("Ping: (1.4-1.5.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s));
                    break;

                default:
                    boolean flag1 = bytebuf.readUnsignedByte() == 1;
                    flag1 = flag1 & bytebuf.readUnsignedByte() == 250;
                    flag1 = flag1 & "MC|PingHost".equals(new String(bytebuf.readBytes(bytebuf.readShort() * 2).array(), Charsets.UTF_16BE));
                    int j = bytebuf.readUnsignedShort();
                    flag1 = flag1 & bytebuf.readUnsignedByte() >= 73;
                    flag1 = flag1 & 3 + bytebuf.readBytes(bytebuf.readShort() * 2).array().length + 4 == j;
                    flag1 = flag1 & bytebuf.readInt() <= 65535;
                    flag1 = flag1 & bytebuf.readableBytes() == 0;

                    if (!flag1)
                    {
                        return;
                    }

                    logger.debug("Ping: (1.6) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s1 = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    ByteBuf bytebuf1 = this.getStringBuffer(s1);

                    try
                    {
                        this.writeAndFlush(p_channelRead_1_, bytebuf1);
                    }
                    finally
                    {
                        bytebuf1.release();
                    }
            }

            bytebuf.release();
            flag = false;
            return;
        }
    }
    catch (RuntimeException var21)
    {
        return;
    }
    finally
    {
        if (flag)
        {
            bytebuf.resetReaderIndex();
            p_channelRead_1_.channel().pipeline().remove("legacy_query");
            p_channelRead_1_.fireChannelRead(p_channelRead_2_);
        }
    }
}
 
Example 17
Project: BaseClient   File: PingResponseHandler.java   Source Code and License Vote up 4 votes
public void channelRead(ChannelHandlerContext p_channelRead_1_, Object p_channelRead_2_) throws Exception
{
    ByteBuf bytebuf = (ByteBuf)p_channelRead_2_;
    bytebuf.markReaderIndex();
    boolean flag = true;

    try
    {
        if (bytebuf.readUnsignedByte() == 254)
        {
            InetSocketAddress inetsocketaddress = (InetSocketAddress)p_channelRead_1_.channel().remoteAddress();
            MinecraftServer minecraftserver = this.networkSystem.getServer();
            int i = bytebuf.readableBytes();

            switch (i)
            {
                case 0:
                    logger.debug("Ping: (<1.3.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s2 = String.format("%s\u00a7%d\u00a7%d", new Object[] {minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s2));
                    break;

                case 1:
                    if (bytebuf.readUnsignedByte() != 1)
                    {
                        return;
                    }

                    logger.debug("Ping: (1.4-1.5.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s));
                    break;

                default:
                    boolean flag1 = bytebuf.readUnsignedByte() == 1;
                    flag1 = flag1 & bytebuf.readUnsignedByte() == 250;
                    flag1 = flag1 & "MC|PingHost".equals(new String(bytebuf.readBytes(bytebuf.readShort() * 2).array(), Charsets.UTF_16BE));
                    int j = bytebuf.readUnsignedShort();
                    flag1 = flag1 & bytebuf.readUnsignedByte() >= 73;
                    flag1 = flag1 & 3 + bytebuf.readBytes(bytebuf.readShort() * 2).array().length + 4 == j;
                    flag1 = flag1 & bytebuf.readInt() <= 65535;
                    flag1 = flag1 & bytebuf.readableBytes() == 0;

                    if (!flag1)
                    {
                        return;
                    }

                    logger.debug("Ping: (1.6) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s1 = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    ByteBuf bytebuf1 = this.getStringBuffer(s1);

                    try
                    {
                        this.writeAndFlush(p_channelRead_1_, bytebuf1);
                    }
                    finally
                    {
                        bytebuf1.release();
                    }
            }

            bytebuf.release();
            flag = false;
            return;
        }
    }
    catch (RuntimeException var21)
    {
        return;
    }
    finally
    {
        if (flag)
        {
            bytebuf.resetReaderIndex();
            p_channelRead_1_.channel().pipeline().remove("legacy_query");
            p_channelRead_1_.fireChannelRead(p_channelRead_2_);
        }
    }
}
 
Example 18
Project: redis-cluster-watchdog   File: ClusterMessageDecoder.java   Source Code and License Vote up 4 votes
protected void decodeMessageV0(ClusterMessage hdr, ByteBuf in) {
    in.skipBytes(2);
    hdr.type = in.readUnsignedShort();
    hdr.count = in.readUnsignedShort();
    hdr.currentEpoch = in.readLong();
    hdr.configEpoch = in.readLong();
    hdr.offset = in.readLong();
    hdr.name = truncate(in, CLUSTER_NODE_NULL_NAME);
    in.readBytes(hdr.slots);
    hdr.master = truncate(in, CLUSTER_NODE_NULL_NAME);
    in.skipBytes(32);
    hdr.ip = null;
    hdr.port = in.readUnsignedShort();
    hdr.busPort = hdr.port + CLUSTER_PORT_INCR;
    hdr.flags = in.readUnsignedShort();
    hdr.state = valueOf(in.readByte());
    in.readBytes(hdr.messageFlags);
    switch (hdr.type) {
        case CLUSTERMSG_TYPE_PING:
        case CLUSTERMSG_TYPE_PONG:
        case CLUSTERMSG_TYPE_MEET:
            for (int i = 0; i < hdr.count; i++) {
                ClusterMessageDataGossip gossip = new ClusterMessageDataGossip();
                gossip.name = truncate(in, CLUSTER_NODE_NULL_NAME);
                gossip.pingTime = in.readInt() * 1000L;
                gossip.pongTime = in.readInt() * 1000L;
                gossip.ip = truncate(in, CLUSTER_NODE_NULL_IP);
                gossip.port = in.readUnsignedShort();
                gossip.busPort = gossip.port + CLUSTER_PORT_INCR;
                gossip.flags = in.readUnsignedShort();
                in.skipBytes(2);
                in.skipBytes(4);
                hdr.data.gossips.add(gossip);
            }
            break;
        case CLUSTERMSG_TYPE_FAIL:
            hdr.data.fail.name = truncate(in, CLUSTER_NODE_NULL_NAME);
            break;
        case CLUSTERMSG_TYPE_PUBLISH:
            hdr.data.publish.channelLength = in.readInt();
            hdr.data.publish.messageLength = in.readInt();
            in.readBytes(hdr.data.publish.bulkData);
            break;
        case CLUSTERMSG_TYPE_UPDATE:
            hdr.data.config.configEpoch = in.readLong();
            hdr.data.config.name = truncate(in, CLUSTER_NODE_NULL_NAME);
            in.readBytes(hdr.data.config.slots);
            break;
        default:
            break;
    }
}
 
Example 19
Project: Mods   File: TF2Message.java   Source Code and License Vote up 4 votes
@Override
public void fromBytes(ByteBuf buf) {
	this.port = buf.readUnsignedShort();
	this.id = buf.readShort();
}
 
Example 20
Project: Backmemed   File: LegacyPingHandler.java   Source Code and License Vote up 4 votes
public void channelRead(ChannelHandlerContext p_channelRead_1_, Object p_channelRead_2_) throws Exception
{
    ByteBuf bytebuf = (ByteBuf)p_channelRead_2_;
    bytebuf.markReaderIndex();
    boolean flag = true;

    try
    {
        if (bytebuf.readUnsignedByte() == 254)
        {
            InetSocketAddress inetsocketaddress = (InetSocketAddress)p_channelRead_1_.channel().remoteAddress();
            MinecraftServer minecraftserver = this.networkSystem.getServer();
            int i = bytebuf.readableBytes();

            switch (i)
            {
                case 0:
                    LOGGER.debug("Ping: (<1.3.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s2 = String.format("%s\u00a7%d\u00a7%d", new Object[] {minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s2));
                    break;

                case 1:
                    if (bytebuf.readUnsignedByte() != 1)
                    {
                        return;
                    }

                    LOGGER.debug("Ping: (1.4-1.5.x) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    this.writeAndFlush(p_channelRead_1_, this.getStringBuffer(s));
                    break;

                default:
                    boolean flag1 = bytebuf.readUnsignedByte() == 1;
                    flag1 = flag1 & bytebuf.readUnsignedByte() == 250;
                    flag1 = flag1 & "MC|PingHost".equals(new String(bytebuf.readBytes(bytebuf.readShort() * 2).array(), Charsets.UTF_16BE));
                    int j = bytebuf.readUnsignedShort();
                    flag1 = flag1 & bytebuf.readUnsignedByte() >= 73;
                    flag1 = flag1 & 3 + bytebuf.readBytes(bytebuf.readShort() * 2).array().length + 4 == j;
                    flag1 = flag1 & bytebuf.readInt() <= 65535;
                    flag1 = flag1 & bytebuf.readableBytes() == 0;

                    if (!flag1)
                    {
                        return;
                    }

                    LOGGER.debug("Ping: (1.6) from {}:{}", new Object[] {inetsocketaddress.getAddress(), Integer.valueOf(inetsocketaddress.getPort())});
                    String s1 = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", new Object[] {Integer.valueOf(127), minecraftserver.getMinecraftVersion(), minecraftserver.getMOTD(), Integer.valueOf(minecraftserver.getCurrentPlayerCount()), Integer.valueOf(minecraftserver.getMaxPlayers())});
                    ByteBuf bytebuf1 = this.getStringBuffer(s1);

                    try
                    {
                        this.writeAndFlush(p_channelRead_1_, bytebuf1);
                    }
                    finally
                    {
                        bytebuf1.release();
                    }
            }

            bytebuf.release();
            flag = false;
            return;
        }
    }
    catch (RuntimeException var21)
    {
        return;
    }
    finally
    {
        if (flag)
        {
            bytebuf.resetReaderIndex();
            p_channelRead_1_.channel().pipeline().remove("legacy_query");
            p_channelRead_1_.fireChannelRead(p_channelRead_2_);
        }
    }
}