public void Initialise(OpenSimBase openSim)
        {
            m_log.DebugFormat("[REGIONMODULES]: Initializing...");
            m_openSim = openSim;
            openSim.ApplicationRegistry.RegisterInterface <IRegionModulesController>(this);

            string id  = AddinManager.CurrentAddin.Id;
            int    pos = id.LastIndexOf(".");

            if (pos == -1)
            {
                m_name = id;
            }
            else
            {
                m_name = id.Substring(pos + 1);
            }

            //ExtensionNodeList list = AddinManager.GetExtensionNodes("/OpenSim/RegionModules");
            // load all the (new) region-module classes
            foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes("/OpenSim/RegionModules"))
            {
                // TODO why does node.Type.isSubclassOf(typeof(ISharedRegionModule)) not work?
                if (node.Type.GetInterface(typeof(ISharedRegionModule).ToString()) != null)
                {
                    m_log.DebugFormat("[REGIONMODULES]: Found shared region module {0}, class {1}", node.Id, node.Type);
                    m_sharedModules.Add(node.Type);
                }
                else if (node.Type.GetInterface(typeof(INonSharedRegionModule).ToString()) != null)
                {
                    m_log.DebugFormat("[REGIONMODULES]: Found non-shared region module {0}, class {1}", node.Id, node.Type);
                    m_nonSharedModules.Add(node.Type);
                }
                else
                {
                    m_log.DebugFormat("[REGIONMODULES]: Found unknown type of module {0}, class {1}", node.Id, node.Type);
                }
            }

            // now we've got all the region-module classes loaded, create one instance of every ISharedRegionModule,
            // initialize and postinitialize it. This Initialise we are in is called before LoadRegion.PostInitialise
            // is called (which loads the regions), so we don't have any regions in the server yet.
            foreach (Type type in m_sharedModules)
            {
                ISharedRegionModule module = (ISharedRegionModule)Activator.CreateInstance(type);
                m_sharedInstances.Add(module);
                module.Initialise(openSim.ConfigSource.Source);
            }

            foreach (ISharedRegionModule module in m_sharedInstances)
            {
                module.PostInitialise();
            }
        }
Exemple #2
0
 public void AddNode(ISharedRegionModule module)
 {
     m_sharedInstances.Add(module);
     module.Initialise(m_openSim.ConfigSource.Source);
 }
Exemple #3
0
        public void Initialise(OpenSimBase openSim)
        {
            m_openSim = openSim;
            m_openSim.ApplicationRegistry.RegisterInterface <IRegionModulesController>(this);
            m_log.DebugFormat("[Region Modules]: Initializing...");

            // Who we are
            string id = AddinManager.CurrentAddin.Id;

            // Make friendly name
            int pos = id.LastIndexOf(".");

            if (pos == -1)
            {
                m_name = id;
            }
            else
            {
                m_name = id.Substring(pos + 1);
            }

            // The [Modules] section in the ini file
            IConfig modulesConfig = m_openSim.ConfigSource.Source.Configs["Modules"];

            if (modulesConfig == null)
            {
                modulesConfig = m_openSim.ConfigSource.Source.AddConfig("Modules");
            }

            // Scan modules and load all that aren't disabled
            foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes("/OpenSim/RegionModules"))
            {
                if (node.Type.GetInterface(typeof(ISharedRegionModule).ToString()) != null)
                {
                    // Get the config string
                    string moduleString = modulesConfig.GetString("Setup_" + node.Id, String.Empty);

                    // We have a selector
                    if (moduleString != String.Empty)
                    {
                        // Allow disabling modules even if they don't have
                        // support for it
                        if (moduleString == "disabled")
                        {
                            continue;
                        }

                        // Split off port, if present
                        string[] moduleParts = moduleString.Split(new char[] { '/' }, 2);

                        // Format is [port/][class]
                        string className = moduleParts[0];

                        if (moduleParts.Length > 1)
                        {
                            className = moduleParts[1];
                        }

                        // Match the class name if given
                        if (className != String.Empty && node.Type.ToString() != className)
                        {
                            continue;
                        }
                    }

                    m_log.DebugFormat("[Region Modules]: Found shared region module {0}, class {1}", node.Id, node.Type);
                    m_sharedModules.Add(node);
                }
                else if (node.Type.GetInterface(typeof(INonSharedRegionModule).ToString()) != null)
                {
                    // Get the config string
                    string moduleString = modulesConfig.GetString("Setup_" + node.Id, String.Empty);

                    // We have a selector
                    if (moduleString != String.Empty)
                    {
                        // Allow disabling modules even if they don't have
                        // support for it
                        if (moduleString == "disabled")
                        {
                            continue;
                        }

                        // Split off port, if present
                        string[] moduleParts = moduleString.Split(new char[] { '/' }, 2);

                        // Format is [port/][class]
                        string className = moduleParts[0];

                        if (moduleParts.Length > 1)
                        {
                            className = moduleParts[1];
                        }

                        // Match the class name if given
                        if (className != String.Empty && node.Type.ToString() != className)
                        {
                            continue;
                        }
                    }

                    m_log.DebugFormat("[Region Modules]: Found non-shared region module {0}, class {1}", node.Id, node.Type);
                    m_nonSharedModules.Add(node);
                }
                else
                {
                    m_log.DebugFormat("[Region Modules]: Found unknown type of module {0}, class {1}", node.Id, node.Type);
                }
            }

            /// <summary>
            ///     Load and init the module. We try a constructor with a port
            ///     if a port was given, fall back to one without if there is
            ///     no port or the more specific constructor fails.
            ///     This will be removed, so that any module capable of using a port
            ///     must provide a constructor with a port in the future.
            ///     For now, we do this so migration is easy.
            /// </summary>
            foreach (TypeExtensionNode node in m_sharedModules)
            {
                Object[] ctorArgs = new Object[] { (uint)0 };

                // Read the config again
                string moduleString = modulesConfig.GetString("Setup_" + node.Id, String.Empty);

                // Get the port number, if there is one
                if (moduleString != String.Empty)
                {
                    // Get the port number from the string
                    string[] moduleParts = moduleString.Split(new char[] { '/' }, 2);

                    if (moduleParts.Length > 1)
                    {
                        ctorArgs[0] = Convert.ToUInt32(moduleParts[0]);
                    }
                }

                // Try loading and initilaizing the module, using the
                // port if appropriate
                ISharedRegionModule module = null;

                try
                {
                    module = (ISharedRegionModule)Activator.CreateInstance(node.Type, ctorArgs);
                }
                catch
                {
                    module = (ISharedRegionModule)Activator.CreateInstance(node.Type);
                }

                // OK, we're up and running
                m_sharedInstances.Add(module);
                module.Initialise(m_openSim.ConfigSource.Source);
            }
        }
Exemple #4
0
        public void Initialise(OpenSimBase openSim)
        {
            m_openSim = openSim;
            m_openSim.ApplicationRegistry.RegisterInterface <IRegionModulesController>(this);
            m_log.DebugFormat("[REGIONMODULES]: Initializing...");

            if (!LoadModulesFromAddins)
            {
                return;
            }

            // Who we are
            string id = AddinManager.CurrentAddin.Id;

            // Make friendly name
            int pos = id.LastIndexOf(".");

            if (pos == -1)
            {
                m_name = id;
            }
            else
            {
                m_name = id.Substring(pos + 1);
            }

            // The [Modules] section in the ini file
            IConfig modulesConfig =
                m_openSim.ConfigSource.Source.Configs["Modules"];

            if (modulesConfig == null)
            {
                modulesConfig = m_openSim.ConfigSource.Source.AddConfig("Modules");
            }

            Dictionary <RuntimeAddin, IList <int> > loadedModules = new Dictionary <RuntimeAddin, IList <int> >();

            // Scan modules and load all that aren't disabled
            foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes("/OpenSim/RegionModules"))
            {
                AddNode(node, modulesConfig, loadedModules);
            }

            foreach (KeyValuePair <RuntimeAddin, IList <int> > loadedModuleData in loadedModules)
            {
                m_log.InfoFormat(
                    "[REGIONMODULES]: From plugin {0}, (version {1}), loaded {2} modules, {3} shared, {4} non-shared {5} unknown",
                    loadedModuleData.Key.Id,
                    loadedModuleData.Key.Version,
                    loadedModuleData.Value[0] + loadedModuleData.Value[1] + loadedModuleData.Value[2],
                    loadedModuleData.Value[0], loadedModuleData.Value[1], loadedModuleData.Value[2]);
            }

            // Load and init the module. We try a constructor with a port
            // if a port was given, fall back to one without if there is
            // no port or the more specific constructor fails.
            // This will be removed, so that any module capable of using a port
            // must provide a constructor with a port in the future.
            // For now, we do this so migration is easy.
            //
            foreach (TypeExtensionNode node in m_sharedModules)
            {
                Object[] ctorArgs = new Object[] { (uint)0 };

                // Read the config again
                string moduleString =
                    modulesConfig.GetString("Setup_" + node.Id, String.Empty);

                // Get the port number, if there is one
                if (moduleString != String.Empty)
                {
                    // Get the port number from the string
                    string[] moduleParts = moduleString.Split(new char[] { '/' },
                                                              2);
                    if (moduleParts.Length > 1)
                    {
                        ctorArgs[0] = Convert.ToUInt32(moduleParts[0]);
                    }
                }

                // Try loading and initilaizing the module, using the
                // port if appropriate
                ISharedRegionModule module = null;

                try
                {
                    module = (ISharedRegionModule)Activator.CreateInstance(
                        node.Type, ctorArgs);
                }
                catch
                {
                    module = (ISharedRegionModule)Activator.CreateInstance(
                        node.Type);
                }

                // OK, we're up and running
                m_sharedInstances.Add(module);
                module.Initialise(m_openSim.ConfigSource.Source);
            }
        }
 public void AddNode(ISharedRegionModule module)
 {
     m_sharedInstances.Add(module);
     module.Initialise(m_openSim.ConfigSource.Source);
 }