Ejemplo n.º 1
0
        private void HandleIncomingData(ulong sendingClientID, byte channel, ArraySegment <byte> data, float receiveTime)
        {
            if (enableLogging)
            {
                Debug.Log("Unwrapping Data Header");
            }

            inputStreamWrapper.SetTarget(data.Array);
            inputStreamWrapper.SetLength(data.Count + data.Offset);
            inputStreamWrapper.Position = data.Offset;

            using (BitStream messageStream = MessagePacker.UnwrapMessage(inputStreamWrapper, sendingClientID, out byte messageType, out SecuritySendFlags security))
            {
                if (messageStream == null)
                {
                    Debug.LogError("Message unwrap could not be completed. Was the header corrupt? Crypto error?");
                    return;
                }
                else if (messageType == (byte)MessageType.INVALID)
                {
                    Debug.LogError("Message unwrap read an invalid messageType");
                    return;
                }

                uint headerByteSize = (uint)Arithmetic.VarIntSize(messageType);

                //if(enableLogging)
                //Debug.Log("Data Header: messageType=" + m_MessageHandler.GetMessageName(messageType) + "(" + messageType + ")");

                // Client tried to send a network message that was not the connection request before they were accepted
                if (m_PendingClientsDictionary.ContainsKey(sendingClientID) && m_PendingClientsDictionary[sendingClientID].connectionState == PendingClient.State.PendingConnection && messageType != (byte)MessageType.NETWORK_CONNECTION_REQUEST)
                {
                    Debug.LogWarning("Message received from clientID " + sendingClientID + " before it has been accepted. Message type: (" + messageType.ToString() + ") " + m_MessageHandler.GetMessageName(messageType));
                    return;
                }

                //Handle Message
                m_MessageHandler.HandleMessage(sendingClientID, messageType, messageStream, receiveTime);
            }
        }