/// <summary>
        /// C-tor
        /// </summary>
        public AgentConfigurationErrorEventGenerator()
        {
            RemoteConfiguration remoteConfiguration = AgentConfiguration.RemoteConfiguration;

            ValidatAgentConfiguration(remoteConfiguration);
            AgentConfiguration.AgentConfigurationChanged += ValidatAgentConfiguration;
            ExternalInterfaceFacade.Instance.RemoteConfigurationProvider.FailedToParseConfiguration += CreateTypeMismatchEvent;
        }
示例#2
0
 public void LoadDefaults()
 {
     if (Translations.Messages == null)
     {
         var defaults = new RemoteConfiguration <List <DeathMessage> >("DefaultMessages.json");
         defaults.Load(success =>
         {
             if (success)
             {
                 Translations.Messages = defaults.Contents;
                 _instance.Config.WriteObject(this);
             }
         });
     }
 }
        /// <summary>
        /// Update module twin reported properites with current agent configuration
        /// </summary>
        private void UpdateReportedProperties(RemoteConfiguration remoteConfiguration)
        {
            var serializer = new JsonSerializer();

            serializer.Converters.Add(new StringEnumConverter());
            serializer.Converters.Add(new IsoTimespanConverter());

            var reportedConfiguration = new JObject();

            reportedConfiguration[ConfigSectionName] = JObject.FromObject(remoteConfiguration, serializer);

            var reportedCollection = new TwinCollection(reportedConfiguration, new JObject());

            _moduleClient.UpdateRportedPropertiesAsync(reportedCollection);
        }
        /// <summary>
        /// Validate HighPriorityIntervals is lower or equal to LowPriorityInterval
        /// </summary>
        /// <param name="remoteConfiguration">Configuration to validate</param>
        /// <param name="configurationErrorPayload"></param>
        /// <returns>true if valid</returns>
        private static bool ValidateIntervals(RemoteConfiguration remoteConfiguration, out ConfigurationErrorPayload configurationErrorPayload)
        {
            configurationErrorPayload = null;
            if (remoteConfiguration.HighPriorityMessageFrequency > remoteConfiguration.LowPriorityMessageFrequency)
            {
                configurationErrorPayload = new ConfigurationErrorPayload
                {
                    ConfigurationName = JsonUtils.GetJsonLabel(nameof(remoteConfiguration.HighPriorityMessageFrequency), typeof(RemoteConfiguration)),
                    ErrorType         = ConfigurationErrorType.Conflict,
                    UsedConfiguration = AgentConfiguration.RemoteConfiguration.HighPriorityMessageFrequency.ToString(),
                    Message           = $"High priority interval is longer than low priority interval"
                };

                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Validate maxCacheSize > maxMessageSize
        /// </summary>
        /// <param name="remoteConfiguration">Configuration to validate</param>
        /// <param name="configurationErrorPayload">configurationErrorPayload</param>
        /// <returns>true if valid</returns>
        private static bool ValidateMaxCacheSize(RemoteConfiguration remoteConfiguration, out ConfigurationErrorPayload configurationErrorPayload)
        {
            configurationErrorPayload = null;
            if (remoteConfiguration.MaxMessageSize > remoteConfiguration.MaxLocalCacheSize)
            {
                configurationErrorPayload = new ConfigurationErrorPayload
                {
                    ConfigurationName = JsonUtils.GetJsonLabel(nameof(remoteConfiguration.MaxLocalCacheSize), typeof(RemoteConfiguration)),
                    ErrorType         = ConfigurationErrorType.Conflict,
                    UsedConfiguration = AgentConfiguration.RemoteConfiguration.MaxLocalCacheSize.ToString(),
                    Message           = $"MaxLocalCacheSize is smaller than MaxMessageSize"
                };

                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Validate maxMessageSize is multiple of 4Kb
        /// </summary>
        /// <param name="remoteConfiguration">Configuration to validate</param>
        /// <param name="configurationErrorPayload">configuration error payload</param>
        /// <returns>true if valid</returns>
        private static bool ValidateMaxMessageSize(RemoteConfiguration remoteConfiguration, out ConfigurationErrorPayload configurationErrorPayload)
        {
            configurationErrorPayload = null;
            if (remoteConfiguration.MaxMessageSize % Constants.OptimalMessageSizeMultipleInKb != 0)
            {
                configurationErrorPayload = new ConfigurationErrorPayload
                {
                    ConfigurationName = JsonUtils.GetJsonLabel(nameof(remoteConfiguration.MaxMessageSize), typeof(RemoteConfiguration)),
                    ErrorType         = ConfigurationErrorType.NotOptimal,
                    UsedConfiguration = AgentConfiguration.RemoteConfiguration.MaxMessageSize.ToString(),
                    Message           = $"Message size should be multiple of {Constants.OptimalMessageSizeMultipleInKb}"
                };

                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Validates agent configuration make sense
        /// </summary>
        private void ValidatAgentConfiguration(RemoteConfiguration remoteConfiguration)
        {
            //Remove previous events, they are no longer relevant
            RemoveEvents();

            var payloads = new List <ConfigurationErrorPayload>();

            foreach (Validator validator in _validators)
            {
                if (validator(remoteConfiguration, out ConfigurationErrorPayload confErrorPayload) == false)
                {
                    payloads.Add(confErrorPayload);
                }
            }

            if (payloads.Count != 0)
            {
                _events.Add(new ConfigurationError(payloads.ToArray()));
            }
        }
示例#8
0
        // Initializes the physics scene
        /// <summary>
        /// Initializes the physics scene.
        /// </summary>
        /// <param name="meshmerizer">The mesher to be used for creating
        /// meshes from shape descriptions</param>
        /// <param name="config">The configuration settings to be used to
        /// configure the scene</param>
        /// <param name="regionExtent">The size of the scene in Open Simulator
        /// units</param>
        public override void Initialise(IMesher meshmerizer,
                                        IConfigSource config, Vector3 regionExtent)
        {
            OpenMetaverse.Vector3 gravityVector;

            // Create a configuration, which will be used for initializing the
            // scene, using the "RemotePhysics" section of the given
            // configuration file
            RemoteConfiguration.Initialize(config.Configs["RemotePhysics"]);

            // Initialize the dimensions of this scene
            m_regionExtents = regionExtent;

            // Initialize the mesher
            SceneMesher = meshmerizer;

            // Create the dictionary that will map physics objects to their
            // respective IDs
            PhysicsObjects = new Dictionary <uint, RemotePhysicsObject>();

            // Create the dictionaries that keep track of which objects have
            // collisions or don't have collisions
            ObjectsWithCollisions       = new HashSet <RemotePhysicsObject>();
            ObjectsWithNoMoreCollisions = new HashSet <RemotePhysicsObject>();

            // The simulation time has not been updated yet
            m_lastSimulatedTime = 0.0f;

            // Create the packet manager that will maintain a connection
            // with the remote physics server
            m_remotePacketManager =
                new RemotePhysicsTCPPacketManager(RemoteConfiguration);

            // Create the packet manager that will be used for UDP
            // communications with the remote physics server
            m_remoteUdpPacketManager =
                new RemotePhysicsUDPPacketManager(RemoteConfiguration);

            // Create the messaging system that will allow this scene to
            // communicate with the remote physics server
            m_remoteMessenger = new RemotePhysicsAPPMessenger();
            m_remoteMessenger.Initialize(RemoteConfiguration,
                                         m_remotePacketManager, m_remoteUdpPacketManager);
            RemoteMessenger = m_remoteMessenger;

            // Initialize the lists that will track which objects were updated
            // duing this and the last step
            m_updatedObjects     = new List <RemotePhysicsObject>();
            m_lastUpdatedObjects = new List <RemotePhysicsObject>();

            // Send the logon message
            m_remoteMessenger.Logon(RemoteConfiguration.SimulationID,
                                    RegionName);

            // Set the callbacks that listen for updates from the remote engine
            m_remoteMessenger.OnDynamicActorUpdateEvent +=
                new UpdateDynamicActorHandler(DynamicActorUpdated);
            m_remoteMessenger.OnActorsCollidedEvent +=
                new ActorsCollidedHandler(ActorsCollided);
            m_remoteMessenger.OnDynamicActorMassUpdateEvent +=
                new UpdateDynamicActorMassHandler(ActorMassUpdated);
            m_remoteMessenger.OnTimeAdvancedEvent +=
                new TimeAdvancedHandler(TimeAdvanced);

            // Send the message to the remote physics engine that creates
            // the remote scene and establishes the ground plane
            gravityVector = new OpenMetaverse.Vector3(0.0f, 0.0f,
                                                      RemoteConfiguration.Gravity);
            m_remoteMessenger.InitializeWorld(gravityVector,
                                              RemoteConfiguration.DefaultFriction,
                                              RemoteConfiguration.DefaultFriction,
                                              RemoteConfiguration.CollisionMargin,
                                              RemoteConfiguration.DefaultRestitution, m_groundPlaneID,
                                              RemoteConfiguration.GroundPlaneHeight,
                                              new OpenMetaverse.Vector3(0.0f, 0.0f, 1.0f));

            // Indicate that the scene is now initialized
            m_initialized = true;
        }