Exemplo n.º 1
0
        public bool TryAddMessagePart(MessagePart messagePart, int mtuSize)
        {
            byte[] bytes = messagePart.Encode();
            if (_currentSize + bytes.Length > (mtuSize - RaknetHandler.UdpHeaderSize))
            {
                return(false);
            }

            if (messagePart.ReliabilityHeader.PartCount > 0 && messagePart.ReliabilityHeader.PartIndex > 0)
            {
                Header.IsContinuousSend = true;
            }

            //TODO: Get rid of this stuff.
            if (FirstMessageId == 0)
            {
                FirstMessageId = messagePart.ContainedMessageId;
            }

            MessageParts.Add(messagePart);

            _currentSize += bytes.Length;

            return(true);
        }
Exemplo n.º 2
0
        public bool TryAddMessagePart(MessagePart messagePart, int mtuSize)
        {
            byte[] bytes = messagePart.Encode();
            if (bytes.Length + _currentSize > mtuSize)
            {
                return(false);
            }

            if (messagePart.ReliabilityHeader.HasSplit && MessageParts.Count > 0)
            {
                //if (Log.IsDebugEnabled)
                //	Log.Warn($"Message has split and count > 0: {MessageParts.Count}, MTU: {mtuSize}");
                return(false);
            }
            //if (Header.isContinuousSend) return false;

            if (messagePart.ReliabilityHeader.PartCount > 0 && messagePart.ReliabilityHeader.PartIndex > 0)
            {
                Header.IsContinuousSend = true;
            }

            if (FirstMessageId == 0)
            {
                FirstMessageId = messagePart.ContainedMessageId;
            }

            MessageParts.Add(messagePart);
            _currentSize = _currentSize + bytes.Length;

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parses the <paramref name="rawBody"/> Byte array as a MultiPart message.<br/>
        /// It is not valid to call this method if <see cref="IsMultiPart"/> returned <see langword="false"/>.<br/>
        /// Fills the <see cref="MessageParts"/> property of this <see cref="MessagePart"/>.
        /// </summary>
        /// <param name="rawBody">The Byte array which is to be parsed as a MultiPart message</param>
        private void ParseMultiPartBody(Byte[] rawBody)
        {
            // Fetch out the boundary used to delimit the messages within the body
            String multipartBoundary = ContentType.Boundary;

            // Fetch the individual MultiPart message parts using the MultiPart boundary
            List <Byte[]> bodyParts = GetMultiPartParts(rawBody, multipartBoundary);

            // Initialize the MessageParts property, with room to as many bodies as we have found
            MessageParts = new List <MessagePart> withCapacity(bodyParts.Count);

            // Now parse each Byte array as a message body and add it the the MessageParts property
            foreach (Byte[] bodyPart in bodyParts)
            {
                MessagePart messagePart = GetMessagePart(bodyPart);
                MessageParts.Add(messagePart);
            }
        }