Beispiel #1
0
        public bool Unpack(byte[] data)
        {
            try
            {
                // This won't actually do anything by default unless some bools in NetworkSyntheticTesting are enabled manually
                data = NetworkSyntheticTesting.SyntheticCorruption_C2S(data);

                if (data.Length < PacketHeader.HeaderSize)
                {
                    return(false);
                }

                Header.Unpack(data);

                if (Header.Size > data.Length - PacketHeader.HeaderSize)
                {
                    return(false);
                }

                Data       = new MemoryStream(data, PacketHeader.HeaderSize, Header.Size, false, true);
                DataReader = new BinaryReader(Data);
                HeaderOptional.Unpack(DataReader, Header);

                if (!HeaderOptional.IsValid)
                {
                    return(false);
                }

                if (!ReadFragments())
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                packetLog.Error("Invalid packet data", ex);

                return(false);
            }
        }
Beispiel #2
0
        public bool Unpack(byte[] data)
        {
            try
            {
                if (data.Length < PacketHeader.HeaderSize)
                {
                    return(false);
                }

                Header.Unpack(data);

                if (Header.Size > data.Length - PacketHeader.HeaderSize)
                {
                    return(false);
                }

                Data       = new MemoryStream(data, PacketHeader.HeaderSize, Header.Size, false, true);
                DataReader = new BinaryReader(Data);
                HeaderOptional.Unpack(DataReader, Header);

                if (!HeaderOptional.IsValid)
                {
                    return(false);
                }

                if (!ReadFragments())
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                packetLog.Error("Invalid packet data", ex);

                return(false);
            }
        }