diff --git a/OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs b/OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs index a868bd0f42..ddc37edd85 100644 --- a/OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs +++ b/OpenSim/ApplicationPlugins/RegionModulesController/RegionModulesControllerPlugin.cs @@ -30,24 +30,36 @@ using System.Collections.Generic; using System.Reflection; using log4net; using Mono.Addins; +using Nini.Config; using OpenSim; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; namespace OpenSim.ApplicationPlugins.RegionModulesController { - public class RegionModulesControllerPlugin : IRegionModulesController, IApplicationPlugin + public class RegionModulesControllerPlugin : IRegionModulesController, + IApplicationPlugin { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + // Logger + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); - private OpenSimBase m_openSim; // for getting the config + // Config access + private OpenSimBase m_openSim; + // Our name private string m_name; - private List m_nonSharedModules = new List(); - private List m_sharedModules = new List(); + // Internal lists to collect information about modules present + private List m_nonSharedModules = + new List(); + private List m_sharedModules = + new List(); - private List m_sharedInstances = new List(); + // List of shared module instances, for adding to Scenes + private List m_sharedInstances = + new List(); #region IApplicationPlugin implementation @@ -57,40 +69,136 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController m_openSim = openSim; openSim.ApplicationRegistry.RegisterInterface(this); + // Who we are 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")) + // 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 = + openSim.ConfigSource.Source.Configs["Modules"]; + if (modulesConfig == null) + modulesConfig = openSim.ConfigSource.Source.AddConfig("Modules"); + + // Scan modules and load all that aren't disabled + 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) { + // 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("[REGIONMODULES]: Found shared region module {0}, class {1}", node.Id, node.Type); - m_sharedModules.Add(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("[REGIONMODULES]: Found non-shared region module {0}, class {1}", node.Id, node.Type); - m_nonSharedModules.Add(node.Type); + m_nonSharedModules.Add(node); } 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) + // 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) { - ISharedRegionModule module = (ISharedRegionModule)Activator.CreateInstance(type); + 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(openSim.ConfigSource.Source); } + // Immediately run PostInitialise on shared modules foreach (ISharedRegionModule module in m_sharedInstances) { module.PostInitialise(); @@ -105,6 +213,8 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController #region IPlugin implementation + // We don't do that here + // public void Initialise () { throw new System.NotImplementedException(); @@ -114,9 +224,11 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController #region IDisposable implementation + // Cleanup + // public void Dispose () { - // we expect that all regions have been removed already + // We expect that all regions have been removed already while (m_sharedInstances.Count > 0) { m_sharedInstances[0].Close(); @@ -147,6 +259,11 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController #region IRegionModulesController implementation + // The root of all evil. + // This is where we handle adding the modules to scenes when they + // load. This means that here we deal with replaceable interfaces, + // nonshared modules, etc. + // public void AddRegionToModules (Scene scene) { Dictionary deferredSharedModules = @@ -154,12 +271,26 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController Dictionary deferredNonSharedModules = new Dictionary(); + // We need this to see if a module has already been loaded and + // has defined a replaceable interface. It's a generic call, + // so this can't be used directly. It will be used later Type s = scene.GetType(); MethodInfo mi = s.GetMethod("RequestModuleInterface"); - List sharedlist = new List(); + // This will hold the shared modules we actually load + List sharedlist = + new List(); + + // Iterate over the shared modules that have been loaded + // Add them to the new Scene foreach (ISharedRegionModule module in m_sharedInstances) { + // Here is where we check if a replaceable interface + // is defined. If it is, the module is checked against + // the interfaces already defined. If the interface is + // defined, we simply skip the module. Else, if the module + // defines a replaceable interface, we add it to the deferred + // list. Type replaceableInterface = module.ReplaceableInterface; if (replaceableInterface != null) { @@ -185,11 +316,41 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController sharedlist.Add(module); } - List list = new List(); - foreach (Type type in m_nonSharedModules) - { - INonSharedRegionModule module = (INonSharedRegionModule)Activator.CreateInstance(type); + IConfig modulesConfig = + m_openSim.ConfigSource.Source.Configs["Modules"]; + // Scan for, and load, nonshared modules + List list = new List(); + foreach (TypeExtensionNode node in m_nonSharedModules) + { + Object[] ctorArgs = new Object[] {0}; + + // Read the config + 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]); + } + + // Actually load it + INonSharedRegionModule module = null; + try + { + module = (INonSharedRegionModule)Activator.CreateInstance(node.Type, ctorArgs); + } + catch + { + module = (INonSharedRegionModule)Activator.CreateInstance(node.Type); + } + + // Check for replaceable interfaces Type replaceableInterface = module.ReplaceableInterface; if (replaceableInterface != null) { @@ -209,11 +370,16 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController m_log.DebugFormat("[REGIONMODULE]: Adding scene {0} to non-shared module {1}", scene.RegionInfo.RegionName, module.Name); + // Initialise the module module.Initialise(m_openSim.ConfigSource.Source); list.Add(module); } + // Now add the modules that we found to the scene. If a module + // wishes to override a replaceable interface, it needs to + // register it in Initialise, so that the deferred module + // won't load. foreach (INonSharedRegionModule module in list) { module.AddRegion(scene); @@ -223,9 +389,9 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController // Now all modules without a replaceable base interface are loaded // Replaceable modules have either been skipped, or omitted. // Now scan the deferred modules here - foreach (ISharedRegionModule module in deferredSharedModules.Values) { + // Determine if the interface has been replaced Type replaceableInterface = module.ReplaceableInterface; MethodInfo mii = mi.MakeGenericMethod(replaceableInterface); @@ -238,15 +404,20 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController m_log.DebugFormat("[REGIONMODULE]: Adding scene {0} to shared module {1} (deferred)", scene.RegionInfo.RegionName, module.Name); + // Not replaced, load the module module.AddRegion(scene); scene.AddRegionModule(module.Name, module); sharedlist.Add(module); } - List deferredlist = new List(); + // Same thing for nonshared modules, load them unless overridden + List deferredlist = + new List(); + foreach (INonSharedRegionModule module in deferredNonSharedModules.Values) { + // Check interface override Type replaceableInterface = module.ReplaceableInterface; if (replaceableInterface != null) { @@ -268,7 +439,8 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController deferredlist.Add(module); } - foreach (IRegionModuleBase module in deferredlist) + // Finally, load valid deferred modules + foreach (INonSharedRegionModule module in deferredlist) { module.AddRegion(scene); scene.AddRegionModule(module.Name, module); @@ -284,16 +456,14 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController // and unneccessary caching logic repeated in all modules. // The extra function stub is just that much cleaner // - foreach (IRegionModuleBase module in sharedlist) + foreach (ISharedRegionModule module in sharedlist) { - try { module.RegionLoaded(scene); } - catch (Exception ex) { m_log.Error("[REGIONMODULE]: Exception while loading shared region module " + module + ": " + ex.Message, ex); } + module.RegionLoaded(scene); } - foreach (IRegionModuleBase module in list) + foreach (INonSharedRegionModule module in list) { - try { module.RegionLoaded(scene); } - catch (Exception ex) { m_log.Error("[REGIONMODULE]: Exception while loading non-shared region module " + module + ": " + ex.Message, ex); } + module.RegionLoaded(scene); } } diff --git a/OpenSim/Client/Linden/LLProxyLoginModule.cs b/OpenSim/Client/Linden/LLProxyLoginModule.cs index 2da774f755..ad67c440bb 100644 --- a/OpenSim/Client/Linden/LLProxyLoginModule.cs +++ b/OpenSim/Client/Linden/LLProxyLoginModule.cs @@ -50,8 +50,16 @@ namespace OpenSim.Client.Linden /// public class LLProxyLoginModule : ISharedRegionModule { + private uint m_port = 0; + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + public LLProxyLoginModule(uint port) + { + m_log.DebugFormat("[CLIENT]: LLProxyLoginModule port {0}", port); + m_port = port; + } + protected bool RegionLoginsEnabled { get @@ -148,8 +156,8 @@ namespace OpenSim.Client.Linden protected void AddHttpHandlers() { //we will add our handlers to the first scene we received, as all scenes share a http server. But will this ever change? - MainServer.Instance.AddXmlRPCHandler("expect_user", ExpectUser, false); - MainServer.Instance.AddXmlRPCHandler("logoff_user", LogOffUser, false); + MainServer.GetHttpServer(m_port).AddXmlRPCHandler("expect_user", ExpectUser, false); + MainServer.GetHttpServer(m_port).AddXmlRPCHandler("logoff_user", LogOffUser, false); } protected void AddScene(Scene scene) diff --git a/OpenSim/Framework/MainServer.cs b/OpenSim/Framework/MainServer.cs index b5f947e4a6..7da4893b62 100644 --- a/OpenSim/Framework/MainServer.cs +++ b/OpenSim/Framework/MainServer.cs @@ -26,17 +26,36 @@ */ using OpenSim.Framework.Servers.HttpServer; +using System.Collections.Generic; namespace OpenSim.Framework { public class MainServer { private static BaseHttpServer instance; + private static Dictionary m_Servers = + new Dictionary(); public static BaseHttpServer Instance { get { return instance; } set { instance = value; } } + + public static IHttpServer GetHttpServer(uint port) + { + if (port == 0) + return Instance; + if (port == Instance.Port) + return Instance; + + if (m_Servers.ContainsKey(port)) + return m_Servers[port]; + + m_Servers[port] = new BaseHttpServer(port); + m_Servers[port].Start(); + + return m_Servers[port]; + } } } diff --git a/OpenSim/Framework/RegionInfo.cs b/OpenSim/Framework/RegionInfo.cs index fa747c4c7a..721233df21 100644 --- a/OpenSim/Framework/RegionInfo.cs +++ b/OpenSim/Framework/RegionInfo.cs @@ -978,11 +978,12 @@ namespace OpenSim.Framework public void SaveLastMapUUID(UUID mapUUID) { - if (null == configMember) return; - lastMapUUID = mapUUID; lastMapRefresh = Util.UnixTimeSinceEpoch().ToString(); + if (configMember == null) + return; + configMember.forceSetConfigurationOption("lastmap_uuid", mapUUID.ToString()); configMember.forceSetConfigurationOption("lastmap_refresh", lastMapRefresh); } diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index ca6a2a3451..143dd2a2a0 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -628,8 +628,20 @@ namespace OpenSim break; case "save": - m_log.Info("Saving configuration file: " + Application.iniFilePath); - m_config.Save(Application.iniFilePath); + if (cmdparams.Length < 2) + { + m_log.Error("SYNTAX: " + n + " SAVE FILE"); + return; + } + + if (Application.iniFilePath == cmdparams[1]) + { + m_log.Error("FILE can not be "+Application.iniFilePath); + return; + } + + m_log.Info("Saving configuration file: " + cmdparams[1]); + m_config.Save(cmdparams[1]); break; } } diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs index b2091995e9..b2544fac73 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs @@ -1244,18 +1244,16 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: Updating scene title for {0} with title: {1}", AgentID, Title); ScenePresence presence = null; - lock (m_sceneList) - { - foreach (Scene scene in m_sceneList) - { - presence = scene.GetScenePresence(AgentID); - if (presence != null) - { - presence.Grouptitle = Title; - // FixMe: Ter suggests a "Schedule" method that I can't find. - presence.SendFullUpdateToAllClients(); - } + foreach (Scene scene in m_sceneList) + { + presence = scene.GetScenePresence(AgentID); + if (presence != null) + { + presence.Grouptitle = Title; + + // FixMe: Ter suggests a "Schedule" method that I can't find. + presence.SendFullUpdateToAllClients(); } } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 57b14f772c..a94b4e4795 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -4660,7 +4660,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { index = src.Length + index; } - if (index >= src.Length) + if (index >= src.Length || index < 0) { return 0; } @@ -4685,7 +4685,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { index = src.Length + index; } - if (index >= src.Length) + if (index >= src.Length || index < 0) { return 0.0; } @@ -4712,7 +4712,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { index = src.Length + index; } - if (index >= src.Length) + if (index >= src.Length || index < 0) { return String.Empty; } @@ -4726,7 +4726,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { index = src.Length + index; } - if (index >= src.Length) + if (index >= src.Length || index < 0) { return ""; } @@ -4740,7 +4740,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { index = src.Length + index; } - if (index >= src.Length) + if (index >= src.Length || index < 0) { return new LSL_Vector(0, 0, 0); } @@ -4761,7 +4761,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { index = src.Length + index; } - if (index >= src.Length) + if (index >= src.Length || index < 0) { return new LSL_Rotation(0, 0, 0, 1); } @@ -5844,7 +5844,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api for (int i = 0; i < rules.Length; i += 2) { - switch ((int)rules.Data[i]) + switch (Convert.ToInt32(rules.Data[i])) { case (int)ScriptBaseClass.PSYS_PART_FLAGS: prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1); diff --git a/bin/config-include/GridCommon.ini.example b/bin/config-include/GridCommon.ini.example index 3bc9b6ccdb..6da0f1e8a1 100644 --- a/bin/config-include/GridCommon.ini.example +++ b/bin/config-include/GridCommon.ini.example @@ -32,3 +32,7 @@ ;Include-CenomeCache = "config-include/CenomeCache.ini" ;AssetCaching = "GlynnTuckerAssetCache" + + ;; Optionally, the port for the LLProxyLoginModule module can be changed + + ;Setup_LLProxyLoginModule = "9090/"