Esempio n. 1
0
        /// <summary>
        /// Read without reading compressed header
        /// </summary>
        public static byte[] ReadHandshake(Stream s)
        {
            int length     = Packet.ReadVarInt(s);
            var packetData = ReadBytes(s, length);

            return(packetData);
        }
Esempio n. 2
0
        /// <summary>
        /// Reads the handshake.
        /// Return null if we received an old server status request
        /// </summary>
        public static byte[] ReadFirstPackage(Stream s)
        {
            int first = s.ReadByte();

            Debug.WriteLine("First byte: " + first);
            if (first < 0)
            {
                throw new EndOfStreamException();
            }
            if (first == 0xFE)
            {
                return(null);
            }

            int length;

            if (first < 0x80)
            {
                length = first;
            }
            else
            {
                length = (first & 0x7f) | (Packet.ReadVarInt(s) << 7);
            }
            //Not used for Handshake packet
            //int uncompressedLength = Packet.ReadVarInt(s);
            //if (uncompressedLength != 0)
            //    throw new NotImplementedException();
            byte[] packetData = ReadBytes(s, length);
            return(packetData);
        }
Esempio n. 3
0
        public static byte[] Read(Stream s)
        {
            int compressedLength   = Packet.ReadVarInt(s);
            int uncompressedLength = Packet.ReadVarInt(s);
            var packetData         = ReadBytes(s, compressedLength - Packet.VarIntSize(uncompressedLength)); //Minus uncompressed varint

            return(packetData);
        }