Beispiel #1
0
        public void ReadData(ByteArrayReaderWriter stream)
        {
            byte addressVal = stream.ReadByte();

            // if address type is not 0 or 1, data is not valid
            if (addressVal != 0 && addressVal != 1)
            {
                throw new FormatException();
            }

            this.AddressType = (NetcodeAddressType)addressVal;

            IPAddress ip = null;

            if (this.AddressType == NetcodeAddressType.IPv4)
            {
                stream.ReadBytesIntoBuffer(tempIPV4, 4);
                ip = new IPAddress(tempIPV4);
            }
            else
            {
                stream.ReadBytesIntoBuffer(tempIPV6, 16);
                ip = new IPAddress(tempIPV6);
            }

            var port = stream.ReadUInt16();

            this.Endpoint = new IPEndPoint(ip, port);
        }
        public bool Read(ByteArrayReaderWriter stream, int length, ulong protocolID)
        {
            if (length != 13 + 8 + 8 + 8 + Defines.NETCODE_CONNECT_TOKEN_PRIVATE_BYTES)
            {
                return(false);
            }

            char[] vInfo = new char[Defines.NETCODE_VERSION_INFO_BYTES];
            stream.ReadASCIICharsIntoBuffer(vInfo, Defines.NETCODE_VERSION_INFO_BYTES);
            if (!MiscUtils.MatchChars(vInfo, Defines.NETCODE_VERSION_INFO_STR))
            {
                return(false);
            }

            if (stream.ReadUInt64() != protocolID)
            {
                return(false);
            }

            this.Expiration        = stream.ReadUInt64();
            this.TokenSequenceNum  = stream.ReadUInt64();
            this.ConnectTokenBytes = BufferPool.GetBuffer(Defines.NETCODE_CONNECT_TOKEN_PRIVATE_BYTES);
            stream.ReadBytesIntoBuffer(this.ConnectTokenBytes, Defines.NETCODE_CONNECT_TOKEN_PRIVATE_BYTES);

            return(true);
        }
 protected void processPacket(ushort seq, byte[] packetData, int packetLen)
 {
     using (ByteArrayReaderWriter byteArrayReaderWriter = ByteArrayReaderWriter.Get(packetData))
     {
         while (byteArrayReaderWriter.ReadPosition < packetLen)
         {
             ushort num  = byteArrayReaderWriter.ReadUInt16();
             ushort num2 = readVariableLengthUShort(byteArrayReaderWriter);
             if (num2 != 0)
             {
                 if (!receiveBuffer.Exists(num))
                 {
                     BufferedPacket bufferedPacket = receiveBuffer.Insert(num);
                     bufferedPacket.buffer.SetSize(num2);
                     byteArrayReaderWriter.ReadBytesIntoBuffer(bufferedPacket.buffer.InternalBuffer, num2);
                 }
                 else
                 {
                     byteArrayReaderWriter.SeekRead(byteArrayReaderWriter.ReadPosition + (int)num2);
                 }
                 while (receiveBuffer.Exists(nextReceive))
                 {
                     BufferedPacket bufferedPacket2 = receiveBuffer.Find(nextReceive);
                     ReceiveCallback(ChannelID, bufferedPacket2.buffer.InternalBuffer, bufferedPacket2.buffer.Length);
                     receiveBuffer.Remove(nextReceive);
                     nextReceive++;
                 }
             }
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Read and decrypt packet data into an output buffer
        /// </summary>
        public static int ReadPacketData(NetcodePacketHeader header, ByteArrayReaderWriter stream, int length, ulong protocolID, byte[] key, byte[] outputBuffer)
        {
            byte[] encryptedBuffer = BufferPool.GetBuffer(2048);
            stream.ReadBytesIntoBuffer(encryptedBuffer, length);

            int decryptedBytes;

            try
            {
                decryptedBytes = DecryptPacketData(header, protocolID, encryptedBuffer, length, key, outputBuffer);
            }
            catch (Exception e)
            {
                BufferPool.ReturnBuffer(encryptedBuffer);
                throw e;
            }

            return(decryptedBytes);
        }