示例#1
0
 public void ReadFrom(ref ENetPacketReader reader)
 {
     Header.ReadFrom(ref reader);
     PacketThrottleInterval     = reader.ReadNetUInt32();
     PacketThrottleAcceleration = reader.ReadNetUInt32();
     PacketThrottleDeceleration = reader.ReadNetUInt32();
 }
示例#2
0
        public void TryReadFrom_ReturnsFalseWhenSentTimeIsNotPresent()
        {
            var packetWriter = new ENetPacketWriter();

            packetWriter.WriteNetEndian((ushort)ENET_PROTOCOL_HEADER_FLAG_SENT_TIME);

            var packetReader = new ENetPacketReader(packetWriter.GetWrittenBuffer().Span);

            Assert.IsFalse(ENetProtocolHeader.TryReadFrom(ref packetReader, out var _));
        }
示例#3
0
 public void ReadFrom(ref ENetPacketReader reader)
 {
     Header.ReadFrom(ref reader);
     StartSequenceNumber = reader.ReadNetUInt16();
     DataLength          = reader.ReadNetUInt16();
     FragmentCount       = reader.ReadNetUInt32();
     FragmentNumber      = reader.ReadNetUInt32();
     TotalLength         = reader.ReadNetUInt32();
     FragmentOffset      = reader.ReadNetUInt32();
 }
示例#4
0
        public void TryReadFrom_DoesNotReadSentTimeWhenFlagIsNotSet()
        {
            var packetWriter = new ENetPacketWriter();

            packetWriter.WriteValue <ushort>(0);
            packetWriter.WriteValue <ushort>(0);

            var packetReader = new ENetPacketReader(packetWriter.GetWrittenBuffer().Span);

            Assert.IsTrue(ENetProtocolHeader.TryReadFrom(ref packetReader, out var header));
            Assert.AreEqual(2, packetReader.Left.Length);
        }
示例#5
0
        public void TryReadFrom_ReadsSentTimeWhenFlagIsSet()
        {
            const ushort sentTime = 0b1100_1100_0011_1010;

            var packetWriter = new ENetPacketWriter();

            packetWriter.WriteNetEndian((ushort)ENET_PROTOCOL_HEADER_FLAG_SENT_TIME);
            packetWriter.WriteNetEndian((ushort)sentTime);

            var packetReader = new ENetPacketReader(packetWriter.GetWrittenBuffer().Span);

            Assert.IsTrue(ENetProtocolHeader.TryReadFrom(ref packetReader, out var header));
            Assert.AreEqual(sentTime, header.SentTime);
        }
 public void ReadFrom(ref ENetPacketReader reader)
 {
     Header.ReadFrom(ref reader);
     OutgoingPeerID    = reader.ReadNetUInt16();
     IncomingSessionID = reader.ReadByte();
     OutgoingSessionID = reader.ReadByte();
     MTU                        = reader.ReadNetUInt32();
     WindowSize                 = reader.ReadNetUInt32();
     ChannelCount               = reader.ReadNetUInt32();
     IncomingBandwidth          = reader.ReadNetUInt32();
     OutgoingBandwidth          = reader.ReadNetUInt32();
     PacketThrottleInterval     = reader.ReadNetUInt32();
     PacketThrottleAcceleration = reader.ReadNetUInt32();
     PacketThrottleDeceleration = reader.ReadNetUInt32();
     ConnectID                  = reader.ReadNetUInt32();
 }
示例#7
0
        public void WriteTo_WritesSentTimeWhenFlagIsSet()
        {
            var writeHeader = new ENetProtocolHeader()
            {
                Flags    = ENET_PROTOCOL_HEADER_FLAG_SENT_TIME,
                SentTime = 123,
            };

            var packetWriter = new ENetPacketWriter();

            writeHeader.WriteTo(packetWriter);

            var packetReader = new ENetPacketReader(packetWriter.GetWrittenBuffer().Span);

            Assert.True(ENetProtocolHeader.TryReadFrom(ref packetReader, out var readHeader));

            Assert.AreEqual(writeHeader.Flags, readHeader.Flags);
            Assert.AreEqual(writeHeader.SentTime, readHeader.SentTime);
        }
示例#8
0
        public static bool TryReadFrom(ref ENetPacketReader packetReader, out ENetProtocolHeader header)
        {
            if (packetReader.Left.Length < MinSize)
            {
                header = default;
                return(false);
            }

            var peerID    = packetReader.ReadNetUInt16();
            var sessionID = unchecked ((byte)((peerID & ENET_PROTOCOL_HEADER_SESSION_MASK) >> ENET_PROTOCOL_HEADER_SESSION_SHIFT));
            var flags     = unchecked ((ushort)(peerID & ENET_PROTOCOL_HEADER_FLAG_MASK));

            peerID = unchecked ((ushort)(peerID & ~(ENET_PROTOCOL_HEADER_FLAG_MASK | ENET_PROTOCOL_HEADER_SESSION_MASK)));
            ushort sentTime = 0;

            if ((flags & ENET_PROTOCOL_HEADER_FLAG_SENT_TIME) != 0)
            {
                if (packetReader.Left.Length < SizeWithSentTime - sizeof(ushort))
                {
                    header = default;
                    return(false);
                }

                sentTime = packetReader.ReadNetUInt16();
            }
            else
            {
                sentTime = 0;
            }

            header = new()
            {
                PeerId    = peerID,
                SentTime  = sentTime,
                Flags     = flags,
                SessionId = sessionID,
            };

            return(true);
        }
示例#9
0
        public void BasicReadWriteTest()
        {
            var writeHeader = new ENetProtocolHeader()
            {
                Flags     = ENET_PROTOCOL_HEADER_FLAG_SENT_TIME | ENET_PROTOCOL_HEADER_FLAG_COMPRESSED,
                PeerId    = 0b101010_010101, // 12bit
                SentTime  = ushort.MaxValue, // 2byte
                SessionId = 0b11,            // 2bit
            };

            var packetWriter = new ENetPacketWriter();

            writeHeader.WriteTo(packetWriter);

            var packetReader = new ENetPacketReader(packetWriter.GetWrittenBuffer().Span);

            Assert.IsTrue(ENetProtocolHeader.TryReadFrom(ref packetReader, out var readHeader));
            Assert.AreEqual(writeHeader.Flags, readHeader.Flags);
            Assert.AreEqual(writeHeader.PeerId, readHeader.PeerId);
            Assert.AreEqual(writeHeader.SentTime, readHeader.SentTime);
            Assert.AreEqual(writeHeader.SessionId, readHeader.SessionId);
        }
示例#10
0
        public void TryReadFrom_ReturnsFalseWhenBufferIsSmall()
        {
            var packetReader = new ENetPacketReader(new byte[1]);

            Assert.IsFalse(ENetProtocolHeader.TryReadFrom(ref packetReader, out _));
        }
示例#11
0
 public void ReadFrom(ref ENetPacketReader reader)
 {
     Header.ReadFrom(ref reader);
     ReceivedReliableSequenceNumber = reader.ReadNetUInt16();
     ReceivedSentTime = reader.ReadNetUInt16();
 }
 public void ReadFrom(ref ENetPacketReader reader)
 {
     Header.ReadFrom(ref reader);
     UnreliableSequenceNumber = reader.ReadNetUInt16();
     DataLength = reader.ReadNetUInt16();
 }
示例#13
0
 public void ReadFrom(ref ENetPacketReader reader)
 {
     Command   = reader.ReadByte();
     ChannelID = reader.ReadByte();
     ReliableSequenceNumber = reader.ReadNetUInt16();
 }
 public void ReadFrom(ref ENetPacketReader reader)
 {
     Header.ReadFrom(ref reader);
     IncomingBandwidth = reader.ReadNetUInt32();
     OutgoingBandwidth = reader.ReadNetUInt32();
 }
示例#15
0
 public void ReadFrom(ref ENetPacketReader reader)
 {
     Header.ReadFrom(ref reader);
     Data = reader.ReadNetUInt32();
 }
示例#16
0
 public void ReadFrom(ref ENetPacketReader reader)
 {
     Header.ReadFrom(ref reader);
     DataLength = reader.ReadNetUInt16();
 }
示例#17
0
 public void ReadFrom(ref ENetPacketReader reader)
 {
     Header.ReadFrom(ref reader);
 }