コード例 #1
0
        public void HandleDataPacket(DataPacket packet)
        {
            if (packet.SeqNumber < this.WindowStart || packet.SeqNumber > this.WindowEnd ||
                this.ACKQueue.ContainsKey(packet.SeqNumber))
            {
                return;
            }

            RakNetDataPacketReceiveEventArgs ev = new RakNetDataPacketReceiveEventArgs(this, packet);

            Server.Instance.Event.Network.OnRakNetDataPacketReceive(this, ev);

            if (ev.IsCancel)
            {
                return;
            }

            packet = ev.Packet;

            this.LastUpdateTime = this.LastUpdateTime = TimedOutTime;

            if (this.NACKQueue.ContainsKey(packet.SeqNumber))
            {
                int i;
                this.NACKQueue.TryRemove(packet.SeqNumber, out i);
            }

            this.ACKQueue.TryAdd(packet.SeqNumber, packet.SeqNumber);
            this.ReceivedWindow.TryAdd(packet.SeqNumber, packet.SeqNumber);

            int diff = packet.SeqNumber - this.LastSeqNumber;

            if (diff != 1)
            {
                for (int i = 0; i < diff; ++i)
                {
                    if (!this.ReceivedWindow.ContainsKey(packet.SeqNumber - i))
                    {
                        if (!this.NACKQueue.ContainsKey(packet.SeqNumber - i))
                        {
                            this.NACKQueue.TryAdd(packet.SeqNumber - i, packet.SeqNumber - i);
                        }
                    }
                }
            }

            if (diff >= 1)
            {
                this.LastSeqNumber = packet.SeqNumber;
                this.WindowStart  += diff;
                this.WindowEnd    += diff;
            }

            for (int i = 0; i < packet.Packets.Length; i++)
            {
                if (packet.Packets[i] is EncapsulatedPacket)
                {
                    this.HandleEncapsulatedPacket((EncapsulatedPacket)packet.Packets[i]);
                }
            }
        }
コード例 #2
0
 public void OnRakNetDataPacketReceive(object sender, RakNetDataPacketReceiveEventArgs e)
 {
     this.RakNetDataPacketReceive?.Invoke(sender, e);
 }