Example #1
0
        /// <summary>
        /// Add a packet to a sequence based on the server timestamp
        /// </summary>
        /// <param name="packet">The packet to be added</param>
        /// <param name="packetCompleteHandle">The method to call and pass the data to when a sequence is complete</param>
        public void AddPacket(UDPPacket packet, BaseUDP.PacketComplete packetCompleteHandle, NetWorker networker)
        {
            // Don't process packets that have a timestep within a specified range
            //if (Time.Milliseconds - packet.timeStep > MAX_ACCEPT_TIME_WINDOW)
            //{
            // TODO:  Send an event for old message received or packet rejected
            //	return;
            //}

            // Removal of packets from this lookup is done on a separate thread
            lock (packets)
            {
                // Check to see if we have already started this sequence
                if (!packets.ContainsKey(packet.uniqueId))
                {
                    packets.Add(packet.uniqueId, new UDPPacketSequence());
                }
            }

            // Cache the sequence so we don't repeatedly look it up
            UDPPacketSequence sequence = packets[packet.uniqueId];

            // Do not continue to add the packet if the sequence is already complete
            if (sequence.Done)
            {
                return;
            }

            if (sequence.AddPacket(packet))
            {
                // The packet sequence is complete
                CompleteSequence(packet.uniqueId, sequence, packetCompleteHandle, networker);
            }
        }
        /// <summary>
        /// Add a packet to a sequence based on the server timestamp
        /// </summary>
        /// <param name="packet">The packet to be added</param>
        /// <param name="packetCompleteHandle">The method to call and pass the data to when a sequence is complete</param>
        /// <summary>
        ///根据服务器时间戳添加一个数据包到一个序列
        /// </ summary>
        /// <param name =“packet”>要添加的数据包</ param>
        /// <param name =“packetCompleteHandle”>在序列完成时调用和传递数据的方法</ param>
        public void AddPacket(UDPPacket packet, BaseUDP.PacketComplete packetCompleteHandle, NetWorker networker)
        {
            //不要处理具有指定范围内时间步长的数据包
            // Don't process packets that have a timestep within a specified range
            //if (Time.Milliseconds - packet.timeStep > MAX_ACCEPT_TIME_WINDOW)
            //{
            // TODO:  Send an event for old message received or packet rejected
            //	return;
            //}

            //从这个查询中删除数据包是在一个单独的线程上完成的
            // Removal of packets from this lookup is done on a separate thread
            lock (packets)
            {
                // 检查,看看我们是否已经开始这个序列
                // Check to see if we have already started this sequence
                if (!packets.ContainsKey(packet.uniqueId))
                {
                    packets.Add(packet.uniqueId, new UDPPacketSequence());
                }
            }

            //缓存序列,所以我们不要反复查找它
            // Cache the sequence so we don't repeatedly look it up
            UDPPacketSequence sequence = packets[packet.uniqueId];

            //如果序列已经完成,则不要继续添加数据包
            // Do not continue to add the packet if the sequence is already complete
            if (sequence.Done)
            {
                return;
            }

            // 返回true是完整的数据包
            if (sequence.AddPacket(packet))
            {
                //数据包序列完整
                // The packet sequence is complete
                CompleteSequence(packet.uniqueId, sequence, packetCompleteHandle, networker);
            }
        }