public void DispatchMessage(ConnectionId connectionId, ObjectId receiverObjectId, NetBuffer reader)
        {
            var messageType   = reader.ReadMessageType();
            var objectMessage = _objectMessageParser.Parse(messageType, reader);

            DispatchMessage(connectionId, messageType, receiverObjectId, objectMessage);
        }
Ejemplo n.º 2
0
        public void OnDataReceived(ConnectionId connectionId, IPEndPoint endpoint, NetBuffer reader)
        {
            _messageMetaData.SequenceNumber = reader.ReadSequenceNumber();
            _messageMetaData.ConnectionId   = connectionId;
            _messageMetaData.EndPoint       = endpoint;
            _messageMetaData.Latency        = _latencyInfo.GetLatency(connectionId);

            //Debug.Log("receiving data from " + endpoint);
            while (reader.PositionInBytes < reader.LengthBytes)
            {
                var messageSize          = reader.ReadVariableUInt32();
                var messageStartPosition = reader.PositionInBytes;
                var messageType          = reader.ReadMessageType();

                _messageMetaData.MessageType = messageType;

                Action <MessageMetaData, NetBuffer> handler;
                if (_handlers.TryGetValue(messageType, out handler))
                {
                    handler(_messageMetaData, reader);
                }
                // Skip bytes that weren't read
                var bytesRead   = reader.PositionInBytes - messageStartPosition;
                var bytesToSkip = messageSize - bytesRead;
                if (bytesRead > messageSize)
                {
                    // TODO How to handle this error?
                    throw new Exception("Error! Bytes read (" + bytesRead + ") > messageSizeInBytes (" + messageSize + ")" + ", reader posInBytes: " + reader.PositionInBytes);
                }
                reader.SkipBytes(bytesToSkip);
            }
        }
Ejemplo n.º 3
0
        public NetworkMessage <IObjectMessage> Parse(NetBuffer reader)
        {
            var messageType = reader.ReadMessageType();
            var message     = _messages[messageType];

            message.Content.Deserialize(reader);
            return(message);
        }
Ejemplo n.º 4
0
        public void OnDataReceived(IPEndPoint source, NetBuffer reader)
        {
            var messageType = reader.ReadMessageType();
            Action <IPEndPoint, NetBuffer> handler;

            if (_handlers.TryGetValue(messageType, out handler))
            {
                handler(source, reader);
            }
        }
Ejemplo n.º 5
0
        public void OnDataReceived(ConnectionId connectionId, IPEndPoint endpoint, NetBuffer reader)
        {
            while (reader.PositionInBytes < reader.LengthBytes)
            {
                var messageSize          = reader.ReadVariableUInt32();
                var messageStartPosition = reader.PositionInBytes;
                var messageType          = reader.ReadMessageType();

                Action <ConnectionId, IPEndPoint, NetBuffer> handler;
                if (_handlers.TryGetValue(messageType, out handler))
                {
                    handler(connectionId, endpoint, reader);
                }
                // Skip bytes that weren't read
                var bytesRead   = reader.PositionInBytes - messageStartPosition;
                var bytesToSkip = messageSize - bytesRead;
                if (bytesRead > messageSize)
                {
                    // TODO How to handle this error?
                    throw new Exception("Error! Bytes read (" + bytesRead + ") > messageSizeInBytes (" + messageSize + ")" + ", reader posInBytes: " + reader.PositionInBytes);
                }
                reader.SkipBytes(bytesToSkip);
            }
        }