Merged master into prioritization

prioritization
John Hurliman 2009-10-21 16:24:17 -07:00
commit 2b39ff0a39
8 changed files with 271 additions and 59 deletions

View File

@ -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<Type> m_nonSharedModules = new List<Type>();
private List<Type> m_sharedModules = new List<Type>();
// Internal lists to collect information about modules present
private List<TypeExtensionNode> m_nonSharedModules =
new List<TypeExtensionNode>();
private List<TypeExtensionNode> m_sharedModules =
new List<TypeExtensionNode>();
private List<ISharedRegionModule> m_sharedInstances = new List<ISharedRegionModule>();
// List of shared module instances, for adding to Scenes
private List<ISharedRegionModule> m_sharedInstances =
new List<ISharedRegionModule>();
#region IApplicationPlugin implementation
@ -57,40 +69,136 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController
m_openSim = openSim;
openSim.ApplicationRegistry.RegisterInterface<IRegionModulesController>(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<Type, ISharedRegionModule> deferredSharedModules =
@ -154,12 +271,26 @@ namespace OpenSim.ApplicationPlugins.RegionModulesController
Dictionary<Type, INonSharedRegionModule> deferredNonSharedModules =
new Dictionary<Type, INonSharedRegionModule>();
// 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<ISharedRegionModule> sharedlist = new List<ISharedRegionModule>();
// This will hold the shared modules we actually load
List<ISharedRegionModule> sharedlist =
new List<ISharedRegionModule>();
// 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<INonSharedRegionModule> list = new List<INonSharedRegionModule>();
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<INonSharedRegionModule> list = new List<INonSharedRegionModule>();
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<INonSharedRegionModule> deferredlist = new List<INonSharedRegionModule>();
// Same thing for nonshared modules, load them unless overridden
List<INonSharedRegionModule> deferredlist =
new List<INonSharedRegionModule>();
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);
}
}

View File

@ -50,8 +50,16 @@ namespace OpenSim.Client.Linden
/// </summary>
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)

View File

@ -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<uint, BaseHttpServer> m_Servers =
new Dictionary<uint, BaseHttpServer>();
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];
}
}
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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();
}
}
}

View File

@ -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);

View File

@ -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/"