Beispiel #1
0
        /// <summary>
        /// Checks the head of a message to see if it is an acknowledgement
        /// </summary>
        /// <param name="toCheck">The data to check</param>
        /// <returns>If the packet contained an acknowledgement head, this is stripped away and the remaining packet is returned</returns>
        private byte[] CheckReliable(byte[] toCheck)
        {
            if (toCheck.Length < Reliability.reliable.Length)
            {
                return(toCheck);
            }

            if (Reliability.isReliable(toCheck))
            {
                serverAckd = true;

                byte[] returnArray = new byte[toCheck.Length - Reliability.reliable.Length];
                Array.Copy(toCheck, Reliability.reliable.Length, returnArray, 0, returnArray.Length);
                return(returnArray);
            }
            else
            {
                return(toCheck);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Checks the head of a packet and acknowledges if required
        /// </summary>
        /// <param name="toCheck">The data packet to check</param>
        /// <param name="client">The client who sent the packet</param>
        /// <returns>If the packet contained an acknowledgement head, this is stripped away and the remaining packet is returned</returns>
        private byte[] CheckReliable(byte[] toCheck, IPEndPoint client)
        {
            if (toCheck.Length < Reliability.reliable.Length)
            {
                return(toCheck);
            }

            if (Reliability.isReliable(toCheck))
            {
                //if the head matches the reliable packet, acknowledge the message to the client
                SendBytes(toCheck, client);

                //return the packet without the head
                byte[] returnArray = new byte[toCheck.Length - Reliability.reliable.Length];
                Array.Copy(toCheck, Reliability.reliable.Length, returnArray, 0, returnArray.Length);
                return(returnArray);
            }
            else
            {
                //packet is not reliable so return as is
                return(toCheck);
            }
        }