예제 #1
0
        public void HandleACK(ByteArray data, Connection <T> connection)
        {
            if (connection.destroyed)
            {
                return;
            }
            if (data.Length != 8)
            {
                return;
            }
            int recvAckReliableID = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data.data, 0));
            ReliableMessageSendTracking <T> rmst = null;

            if (sendingMessages.ContainsKey(recvAckReliableID))
            {
                rmst = sendingMessages[recvAckReliableID];
            }
            int recvAckPartID = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data.data, 4));

            if (rmst != null)
            {
                rmst.ReceiveACK(recvAckPartID);
                if (rmst.finished)
                {
                    lock (sendingMessages)
                    {
                        sendingMessages.Remove(recvAckReliableID);
                    }
                    rmst.Destroy();
                }
            }
        }
예제 #2
0
        public void Queue(NetworkMessage nm)
        {
            if (connection.destroyed)
            {
                return;
            }
            lock (sendingMessages)
            {
                ReliableMessageSendTracking <T> rmst = ReliableMessageSendTracking <T> .Create();

                rmst.Setup(nm);
                if (nm.sendType == NetworkMessageType.UNORDERED_RELIABLE)
                {
                    sendingMessages.Add(unorderedSendingID, rmst);
                    unorderedSendingID++;
                    if (unorderedSendingID == Int32.MaxValue)
                    {
                        unorderedSendingID = 1;
                    }
                }
                if (nm.sendType == NetworkMessageType.ORDERED_RELIABLE)
                {
                    sendingMessages.Add(-(orderedSendingID), rmst);
                    orderedSendingID++;
                    if (orderedSendingID == Int32.MaxValue)
                    {
                        orderedSendingID = 1;
                    }
                }
            }
        }
        public static ReliableMessageSendTracking <T> Create()
        {
            ReliableMessageSendTracking <T> rmst = Recycler <ReliableMessageSendTracking <T> > .GetObject();

            rmst.sendPartsLength = 0;
            rmst.sendPartsLeft   = 0;
            rmst.nextSendPart    = 0;
            rmst.finished        = false;
            return(rmst);
        }