From 109aa00150aea01ba32620b4d965edd459827ff7 Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Tue, 2 Sep 2008 12:07:23 +0000 Subject: [PATCH] fix: PostInitialise() not being called on script engines (nasty one that) cleanup: warnings, readability --- .../LoadRegions/LoadRegionsPlugin.cs | 2 +- .../RemoteController/RemoteAdminPlugin.cs | 4 - .../Filesystem/RegionLoaderFileSystem.cs | 2 +- OpenSim/Region/Application/OpenSimBase.cs | 10 +- .../InterGrid/OpenGridProtocolModule.cs | 4 +- .../Scenes/SceneObjectPart.Inventory.cs | 46 ++++----- OpenSim/Region/Physics/Meshing/PrimMesher.cs | 2 +- .../Shared/Api/Runtime/Executor.cs | 2 +- .../Region/ScriptEngine/XEngine/XEngine.cs | 93 +++++++++---------- 9 files changed, 81 insertions(+), 84 deletions(-) diff --git a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs index 535a5ea4c3..c04336331a 100644 --- a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs +++ b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs @@ -52,7 +52,7 @@ namespace OpenSim.ApplicationPlugins.LoadRegions public void Initialise() { m_log.Info("[LOADREGIONS]: " + Name + " cannot be default-initialized!"); - throw new PluginNotInitialisedException (Name); + throw new PluginNotInitialisedException(Name); } public void Initialise(OpenSimBase openSim) diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs index 3bd80f56d2..6691f14551 100644 --- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs +++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs @@ -416,10 +416,6 @@ namespace OpenSim.ApplicationPlugins.RemoteController scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); - // Security risk [and apparently not used] - // if (requestData.ContainsKey("datastore")) - // region.DataStore = (string) requestData["datastore"]; - region.InternalEndPoint = new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0); diff --git a/OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs b/OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs index 46670705da..a371851e3d 100644 --- a/OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs +++ b/OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs @@ -70,7 +70,7 @@ namespace OpenSim.Framework.RegionLoader.Filesystem RegionInfo[] regionInfos = new RegionInfo[configFiles.Length]; for (int i = 0; i < configFiles.Length; i++) { - RegionInfo regionInfo = new RegionInfo("REGION CONFIG #" + (i + 1), configFiles[i],false); + RegionInfo regionInfo = new RegionInfo("REGION CONFIG #" + (i + 1), configFiles[i], false); regionInfos[i] = regionInfo; } diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index ce4fdfe526..4003001998 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -475,7 +475,7 @@ namespace OpenSim { int port = regionInfo.InternalEndPoint.Port; - // set initial RegionID to originRegionID in RegionInfo. (it needs for loding prims) + // set initial originRegionID to RegionID in RegionInfo. (it needs for loding prims) regionInfo.originRegionID = regionInfo.RegionID; // set initial ServerURI @@ -517,7 +517,7 @@ namespace OpenSim m_log.Info("[MODULES]: Loading scripting engine: " + mod); try { - m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", mod), scene); + modules.AddRange(m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", mod), scene)); } catch (Exception ex) { @@ -540,11 +540,13 @@ namespace OpenSim { m_log.ErrorFormat("[STARTUP]: Registration of region with grid failed, aborting startup - {0}", e); - // Carrying on now causes a lot of confusion down the line - we need to get the user's attention + // Carrying on now causes a lot of confusion down the + // line - we need to get the user's attention System.Environment.Exit(1); } - // We need to do this after we've initialized the scripting engines. + // We need to do this after we've initialized the + // scripting engines. scene.CreateScriptInstances(); scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID); diff --git a/OpenSim/Region/Environment/Modules/InterGrid/OpenGridProtocolModule.cs b/OpenSim/Region/Environment/Modules/InterGrid/OpenGridProtocolModule.cs index 90b7bcf97c..dbe045abdd 100644 --- a/OpenSim/Region/Environment/Modules/InterGrid/OpenGridProtocolModule.cs +++ b/OpenSim/Region/Environment/Modules/InterGrid/OpenGridProtocolModule.cs @@ -123,10 +123,10 @@ namespace OpenSim.Region.Environment.Modules.InterGrid { try { -#pragma warning disable 0612 +#pragma warning disable 0612, 0618 // Mono does not implement the ServicePointManager.ServerCertificateValidationCallback yet! Don't remove this! ServicePointManager.CertificatePolicy = new MonoCert(); -#pragma warning restore 0612 +#pragma warning restore 0612, 0618 } catch (Exception) { diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs index eb6b9ccf58..3bfe7e9d04 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs @@ -164,10 +164,11 @@ namespace OpenSim.Region.Environment.Scenes /// public void CreateScriptInstance(TaskInventoryItem item, int startParam, bool postOnRez) { - // m_log.InfoFormat( - // "[PRIM INVENTORY]: " + - // "Starting script {0}, {1} in prim {2}, {3}", - // item.Name, item.ItemID, Name, UUID); + // m_log.InfoFormat( + // "[PRIM INVENTORY]: " + + // "Starting script {0}, {1} in prim {2}, {3}", + // item.Name, item.ItemID, Name, UUID); + if (!m_parentGroup.Scene.ExternalChecks.ExternalChecksCanRunScript(item.ItemID, UUID, item.OwnerID)) return; @@ -178,24 +179,25 @@ namespace OpenSim.Region.Environment.Scenes AssetCache cache = m_parentGroup.Scene.AssetCache; cache.GetAsset(item.AssetID, delegate(LLUUID assetID, AssetBase asset) - { - if (null == asset) - { - m_log.ErrorFormat( - "[PRIM INVENTORY]: " + - "Couldn't start script {0}, {1} since asset ID {2} could not be found", - item.Name, item.ItemID, item.AssetID); - } - else - { - m_taskInventory[item.ItemID].PermsMask = 0; - m_taskInventory[item.ItemID].PermsGranter = LLUUID.Zero; - string script = Helpers.FieldToUTF8String(asset.Data); - m_parentGroup.Scene.EventManager.TriggerRezScript(LocalId, item.ItemID,script, startParam, postOnRez); - m_parentGroup.AddActiveScriptCount(1); - ScheduleFullUpdate(); - } - }, false); + { + if (null == asset) + { + m_log.ErrorFormat( + "[PRIM INVENTORY]: " + + "Couldn't start script {0}, {1} since asset ID {2} could not be found", + item.Name, item.ItemID, item.AssetID); + } + else + { + m_taskInventory[item.ItemID].PermsMask = 0; + m_taskInventory[item.ItemID].PermsGranter = LLUUID.Zero; + string script = Helpers.FieldToUTF8String(asset.Data); + m_parentGroup.Scene.EventManager.TriggerRezScript(LocalId, item.ItemID, script, + startParam, postOnRez); + m_parentGroup.AddActiveScriptCount(1); + ScheduleFullUpdate(); + } + }, false); } } diff --git a/OpenSim/Region/Physics/Meshing/PrimMesher.cs b/OpenSim/Region/Physics/Meshing/PrimMesher.cs index f03aa7cdb5..e15804ed44 100644 --- a/OpenSim/Region/Physics/Meshing/PrimMesher.cs +++ b/OpenSim/Region/Physics/Meshing/PrimMesher.cs @@ -196,7 +196,7 @@ namespace OpenSim.Region.Physics.Meshing float startAngle = profileStart * twoPi; float stopAngle = profileEnd * twoPi; - float stepSize = twoPi / sides; + // float stepSize = twoPi / sides; try { angles.makeAngles(sides, startAngle, stopAngle); } catch (Exception ex) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs index 0241da5be3..aee03ef55d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs @@ -90,7 +90,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase /// Make sure our object does not timeout when in AppDomain. (Called by ILease base class) /// /// - public Object InitializeLifetimeService() + public override Object InitializeLifetimeService() { //Console.WriteLine("Executor: InitializeLifetimeService()"); // return null; diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index f9f88832ea..8ad81105cf 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -145,11 +145,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine public void Initialise(Scene scene, IConfigSource configSource) { AppDomain.CurrentDomain.AssemblyResolve += - OnAssemblyResolve; + OnAssemblyResolve; m_log.InfoFormat("[XEngine] Initializing scripts in region {0}", - scene.RegionInfo.RegionName); - m_Scene=scene; + scene.RegionInfo.RegionName); + m_Scene = scene; m_ScriptConfig = configSource.Configs["XEngine"]; @@ -165,34 +165,31 @@ namespace OpenSim.Region.ScriptEngine.XEngine string priority = m_ScriptConfig.GetString("Priority", "BelowNormal"); int maxScriptQueue = m_ScriptConfig.GetInt("MaxScriptEventQueue",300); int stackSize = m_ScriptConfig.GetInt("ThreadStackSize", 262144); - int sleepTime = m_ScriptConfig.GetInt("MaintenanceInterval", - 10)*1000; + int sleepTime = m_ScriptConfig.GetInt("MaintenanceInterval", 10)*1000; m_EventLimit = m_ScriptConfig.GetInt("EventLimit", 30); - m_KillTimedOutScripts = m_ScriptConfig.GetBoolean( - "KillTimedOutScripts", false); + m_KillTimedOutScripts = m_ScriptConfig.GetBoolean("KillTimedOutScripts", false); int saveTime = m_ScriptConfig.GetInt("SaveInterval", 300)*1000; ThreadPriority prio = ThreadPriority.BelowNormal; switch (priority) { case "Lowest": - prio=ThreadPriority.Lowest; + prio = ThreadPriority.Lowest; break; case "BelowNormal": - prio=ThreadPriority.BelowNormal; + prio = ThreadPriority.BelowNormal; break; case "Normal": - prio=ThreadPriority.Normal; + prio = ThreadPriority.Normal; break; case "AboveNormal": - prio=ThreadPriority.AboveNormal; + prio = ThreadPriority.AboveNormal; break; case "Highest": - prio=ThreadPriority.Highest; + prio = ThreadPriority.Highest; break; default: - m_log.ErrorFormat("[XEngine] Invalid thread priority: '"+ - priority+"'. Assuming BelowNormal"); + m_log.ErrorFormat("[XEngine] Invalid thread priority: '{0}'. Assuming BelowNormal", priority); break; } @@ -204,7 +201,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine m_EventManager = new EventManager(this); StartEngine(minThreads, maxThreads, idleTimeout, prio, - maxScriptQueue, stackSize); + maxScriptQueue, stackSize); m_Compiler = new Compiler(this); @@ -218,15 +215,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (sleepTime > 0) { - m_ThreadPool.QueueWorkItem(new WorkItemCallback( - this.DoMaintenance), new Object[] - { sleepTime }); + m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoMaintenance), + new Object[]{ sleepTime }); } if (saveTime > 0) { - m_ThreadPool.QueueWorkItem(new WorkItemCallback( - this.DoBackup), new Object[] { saveTime }); + m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoBackup), + new Object[] { saveTime }); } scene.RegisterModuleInterface(this); @@ -279,8 +275,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine instances.Clear(); - m_ThreadPool.QueueWorkItem(new WorkItemCallback( - this.DoBackup), new Object[] { saveTime }); + m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoBackup), + new Object[] { saveTime }); return 0; } @@ -302,9 +298,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine System.Threading.Thread.Sleep(sleepTime); - m_ThreadPool.QueueWorkItem(new WorkItemCallback( - this.DoMaintenance), new Object[] - { sleepTime }); + m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoMaintenance), + new Object[]{ sleepTime }); return 0; } @@ -321,25 +316,26 @@ namespace OpenSim.Region.ScriptEngine.XEngine public void OnRezScript(uint localID, LLUUID itemID, string script, int startParam, bool postOnRez) { - Object[] parms = new Object[] - { localID, itemID, script, startParam, postOnRez}; + Object[] parms = new Object[]{localID, itemID, script, startParam, postOnRez}; lock (m_CompileQueue) { m_CompileQueue.Enqueue(parms); + if (m_CurrentCompile == null) { if (m_firstStart) { m_firstStart = false; m_CurrentCompile = m_ThreadPool.QueueWorkItem( - new WorkItemCallback( - this.DoScriptWait), new Object[0]); + new WorkItemCallback(this.DoScriptWait), + new Object[0]); return; } + m_CurrentCompile = m_ThreadPool.QueueWorkItem( - new WorkItemCallback( - this.DoOnRezScriptQueue), new Object[0]); + new WorkItemCallback(this.DoOnRezScriptQueue), + new Object[0]); } } } @@ -353,8 +349,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (m_CompileQueue.Count > 0) { m_CurrentCompile = m_ThreadPool.QueueWorkItem( - new WorkItemCallback( - this.DoOnRezScriptQueue), new Object[0]); + new WorkItemCallback(this.DoOnRezScriptQueue), + new Object[0]); } else { @@ -384,8 +380,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (m_CompileQueue.Count > 0) { m_CurrentCompile = m_ThreadPool.QueueWorkItem( - new WorkItemCallback( - this.DoOnRezScriptQueue), new Object[0]); + new WorkItemCallback(this.DoOnRezScriptQueue), + new Object[0]); } else { @@ -459,7 +455,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine if ((!m_Scripts.ContainsKey(itemID)) || (m_Scripts[itemID].AssetID != assetID)) { - LLUUID appDomain=assetID; + LLUUID appDomain = assetID; if (part.ParentGroup.RootPart.IsAttachment) appDomain = part.ParentGroup.RootPart.UUID; @@ -473,8 +469,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine // "ScriptEngines", // m_Scene.RegionInfo.RegionID.ToString()); - Evidence baseEvidence = - AppDomain.CurrentDomain.Evidence; + Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; Evidence evidence = new Evidence(baseEvidence); m_AppDomains[appDomain] = @@ -489,18 +484,19 @@ namespace OpenSim.Region.ScriptEngine.XEngine } catch (Exception e) { - m_log.Error("[XEngine] Exception creating app domain:\n"+e.ToString()); + m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString()); return false; } } m_DomainScripts[appDomain].Add(itemID); - ScriptInstance instance = new ScriptInstance(this,localID, - part.UUID, itemID, assetID, assembly, - m_AppDomains[appDomain], - part.ParentGroup.RootPart.Name, - item.Name, startParam, postOnRez, - StateSource.NewRez, m_MaxScriptQueue); + ScriptInstance instance = + new ScriptInstance(this,localID, + part.UUID, itemID, assetID, assembly, + m_AppDomains[appDomain], + part.ParentGroup.RootPart.Name, + item.Name, startParam, postOnRez, + StateSource.NewRez, m_MaxScriptQueue); m_log.DebugFormat("[XEngine] Loaded script {0}.{1}", part.ParentGroup.RootPart.Name, item.Name); @@ -657,8 +653,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine // public IScriptWorkItem QueueEventHandler(object parms) { - return new XWorkItem(m_ThreadPool.QueueWorkItem(new WorkItemCallback( - this.ProcessEventHandler), parms)); + return new XWorkItem(m_ThreadPool.QueueWorkItem( + new WorkItemCallback(this.ProcessEventHandler), + parms)); } // @@ -723,7 +720,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine string[] pathList = new string[] {"bin", "ScriptEngines", Path.Combine("ScriptEngines", m_Scene.RegionInfo.RegionID.ToString())}; - + string assemblyName = args.Name; if (assemblyName.IndexOf(",") != -1) assemblyName = args.Name.Substring(0, args.Name.IndexOf(","));