From 990225a4ba79ca05bacc293c416bd4efb6954f48 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 7 Jun 2008 17:43:07 +0000 Subject: Patch for mantis#1493: Several patches to xengine. Thanks Melanie! --- OpenSim/Region/ScriptEngine/XEngine/Compiler.cs | 11 +- .../ScriptEngine/XEngine/LSL_ScriptCommands.cs | 156 +++++++++++++++++---- .../ScriptEngine/XEngine/Script/LSL_Types.cs | 60 +++++++- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 104 +++++++++++--- 4 files changed, 278 insertions(+), 53 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/XEngine') diff --git a/OpenSim/Region/ScriptEngine/XEngine/Compiler.cs b/OpenSim/Region/ScriptEngine/XEngine/Compiler.cs index 3ff7ce0..68fb1dd 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/Compiler.cs @@ -257,7 +257,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine // FilePrefix + "_compiled_" + asset + ".dll"); if (File.Exists(OutFile)) + { + m_scriptEngine.Log.DebugFormat("[XEngine] Returning existing assembly for {0}", asset); return OutFile; + } if (!Directory.Exists(ScriptEnginesPath)) { @@ -422,9 +425,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine string srcFileName = FilePrefix + "_source_" + Path.GetFileNameWithoutExtension(OutFile) + ext; try { - File.WriteAllText( - Path.Combine("ScriptEngines", srcFileName), - Script); + File.WriteAllText(Path.Combine(Path.Combine( + ScriptEnginesPath, + m_scriptEngine.World.RegionInfo.RegionID.ToString()), + srcFileName), Script); } catch (Exception ex) // NOTLEGIT - Should be just catching FileIOException { @@ -504,6 +508,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine errtext += "No compile error. But not able to locate compiled file."; throw new Exception(errtext); } + m_scriptEngine.Log.DebugFormat("[XEngine] Compiled new assembly for {0}", asset); return OutFile; } } diff --git a/OpenSim/Region/ScriptEngine/XEngine/LSL_ScriptCommands.cs b/OpenSim/Region/ScriptEngine/XEngine/LSL_ScriptCommands.cs index 3fb0ff9..bf0e14e 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/LSL_ScriptCommands.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/LSL_ScriptCommands.cs @@ -31,8 +31,10 @@ using System.Collections.Generic; using System.Runtime.Remoting.Lifetime; using System.Text; using System.Threading; +using Nini.Config; using Axiom.Math; using libsecondlife; +using OpenSim; using OpenSim.Framework; using OpenSim.Region.Environment; using OpenSim.Region.Environment.Interfaces; @@ -973,6 +975,78 @@ namespace OpenSim.Region.ScriptEngine.XEngine } } + private void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction, + float wind, float tension, LSL_Types.Vector3 Force) + { + if (part == null) + return; + + bool needs_fakedelete = false; + if (flexi) + { + if (!part.Shape.FlexiEntry) + { + needs_fakedelete = true; + } + part.Shape.FlexiEntry = true; // this setting flexi true isn't working, but the below parameters do + // work once the prim is already flexi + part.Shape.FlexiSoftness = softness; + part.Shape.FlexiGravity = gravity; + part.Shape.FlexiDrag = friction; + part.Shape.FlexiWind = wind; + part.Shape.FlexiTension = tension; + part.Shape.FlexiForceX = (float)Force.x; + part.Shape.FlexiForceY = (float)Force.y; + part.Shape.FlexiForceZ = (float)Force.z; + part.Shape.PathCurve = 0x80; + + } + else + { + if (part.Shape.FlexiEntry) + { + needs_fakedelete = true; + } + part.Shape.FlexiEntry = false; + } + + needs_fakedelete = false; + if (needs_fakedelete) + { + if (part.ParentGroup != null) + { + part.ParentGroup.FakeDeleteGroup(); + } + } + + part.ScheduleFullUpdate(); + } + + private void SetPointLight(SceneObjectPart part, bool light, LSL_Types.Vector3 color, float intensity, float radius, float falloff) + { + if (part == null) + return; + + if (light) + { + part.Shape.LightEntry = true; + part.Shape.LightColorR = (float)color.x; + part.Shape.LightColorG = (float)color.y; + part.Shape.LightColorB = (float)color.z; + part.Shape.LightIntensity = intensity; + part.Shape.LightRadius = radius; + part.Shape.LightFalloff = falloff; + } + else + { + part.Shape.LightEntry = false; + } + + part.ScheduleFullUpdate(); + } + + + public LSL_Types.Vector3 llGetColor(int face) { m_host.AddScriptLPS(1); @@ -4516,7 +4590,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine SetPos(part, v); break; + case 7: // PRIM_SIZE + if (remain < 1) + return; + v=new LSL_Types.Vector3(rules.Data[idx++].ToString()); + SetScale(part, v); + + break; case 8: // PRIM_ROTATION if (remain < 1) return; @@ -4555,13 +4636,31 @@ namespace OpenSim.Region.ScriptEngine.XEngine SetAlpha(part, alpha, face); break; - - case 7: // PRIM_SIZE - if (remain < 1) + case 21: // PRIM_FLEXI + if (remain < 7) return; - v=new LSL_Types.Vector3(rules.Data[idx++].ToString()); - SetScale(part, v); + int flexi = Convert.ToInt32(rules.Data[idx++]); + int softness = Convert.ToInt32(rules.Data[idx++]); + float gravity = (float)Convert.ToDouble(rules.Data[idx++]); + float friction = (float)Convert.ToDouble(rules.Data[idx++]); + float wind = (float)Convert.ToDouble(rules.Data[idx++]); + float tension = (float)Convert.ToDouble(rules.Data[idx++]); + LSL_Types.Vector3 force =new LSL_Types.Vector3(rules.Data[idx++].ToString()); + + SetFlexi(part, (flexi == 1), softness, gravity, friction, wind, tension, force); + + break; + case 23: // PRIM_POINT_LIGHT + if (remain < 5) + return; + int light = Convert.ToInt32(rules.Data[idx++]); + LSL_Types.Vector3 lightcolor =new LSL_Types.Vector3(rules.Data[idx++].ToString()); + float intensity = (float)Convert.ToDouble(rules.Data[idx++]); + float radius = (float)Convert.ToDouble(rules.Data[idx++]); + float falloff = (float)Convert.ToDouble(rules.Data[idx++]); + + SetPointLight(part, (light == 1), lightcolor, intensity, radius, falloff); break; } @@ -5466,30 +5565,39 @@ namespace OpenSim.Region.ScriptEngine.XEngine public void llSetObjectPermMask(int mask, int value) { m_host.AddScriptLPS(1); - - if (mask == BuiltIn_Commands_BaseClass.MASK_BASE)//0 + IConfigSource config = new IniConfigSource(Application.iniFilePath); + if (config.Configs["XEngine"] == null) + config.AddConfig("XEngine"); + + if (config.Configs["XEngine"].GetBoolean("AllowGodFunctions", false)) { - m_host.BaseMask = (uint)value; - } + if (World.ExternalChecks.ExternalChecksCanRunConsoleCommand(m_host.OwnerID)) + { + if (mask == BuiltIn_Commands_BaseClass.MASK_BASE)//0 + { + m_host.BaseMask = (uint)value; + } - else if (mask == BuiltIn_Commands_BaseClass.MASK_OWNER)//1 - { - m_host.OwnerMask = (uint)value; - } + else if (mask == BuiltIn_Commands_BaseClass.MASK_OWNER)//1 + { + m_host.OwnerMask = (uint)value; + } - else if (mask == BuiltIn_Commands_BaseClass.MASK_GROUP)//2 - { - m_host.GroupMask = (uint)value; - } + else if (mask == BuiltIn_Commands_BaseClass.MASK_GROUP)//2 + { + m_host.GroupMask = (uint)value; + } - else if (mask == BuiltIn_Commands_BaseClass.MASK_EVERYONE)//3 - { - m_host.EveryoneMask = (uint)value; - } + else if (mask == BuiltIn_Commands_BaseClass.MASK_EVERYONE)//3 + { + m_host.EveryoneMask = (uint)value; + } - else if (mask == BuiltIn_Commands_BaseClass.MASK_NEXT)//4 - { - m_host.NextOwnerMask = (uint)value; + else if (mask == BuiltIn_Commands_BaseClass.MASK_NEXT)//4 + { + m_host.NextOwnerMask = (uint)value; + } + } } } diff --git a/OpenSim/Region/ScriptEngine/XEngine/Script/LSL_Types.cs b/OpenSim/Region/ScriptEngine/XEngine/Script/LSL_Types.cs index 107d493..a325629 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/Script/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/Script/LSL_Types.cs @@ -425,6 +425,30 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Script return new list(tmp); } + private void ExtendAndAdd(object o) + { + Array.Resize(ref m_data, Length + 1); + m_data.SetValue(o, Length - 1); + } + + public static list operator +(list a, string s) + { + a.ExtendAndAdd(s); + return a; + } + + public static list operator +(list a, int i) + { + a.ExtendAndAdd(i); + return a; + } + + public static list operator +(list a, double d) + { + a.ExtendAndAdd(d); + return a; + } + public void Add(object o) { object[] tmp; @@ -1321,6 +1345,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Script return (double)i.value; } + static public implicit operator LSLFloat(LSLInteger i) + { + return new LSLFloat((double)i.value); + } + public static bool operator true(LSLInteger i) { return i.value != 0; @@ -1370,12 +1399,28 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Script public LSLFloat(int i) { - this.value = (double)i; + value = (double)i; } public LSLFloat(double d) { - this.value = d; + value = d; + } + + public LSLFloat(string s) + { + value = double.Parse(s); + } + + public LSLFloat(Object o) + { + if(!((o is double) || (o is float))) + { + value = 0.0; + return; + } + + value = (double)o; } #endregion @@ -1445,11 +1490,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Script { return f.value; } - - //static public implicit operator System.Int32(LSLFloat f) - //{ - // return (int)f.value; - //} + + static public explicit operator LSLString(LSLFloat f) + { + string v = String.Format("{0:0.000000}", f.value); + return new LSLString(v); + } #endregion diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 0a6de60..1b49baa 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -314,8 +314,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine { assembly = m_Compiler.PerformScriptCompile(script, assetID.ToString()); - m_log.DebugFormat("[XEngine] Loaded script {0}.{1}", - part.ParentGroup.RootPart.Name, item.Name); } catch (Exception e) { @@ -387,8 +385,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine m_DomainScripts[appDomain].Add(itemID); XScriptInstance instance = new XScriptInstance(this,localID, - part.UUID, itemID, assetID, assembly, - m_AppDomains[appDomain]); + part.UUID, itemID, assetID, assembly, + m_AppDomains[appDomain], + part.ParentGroup.RootPart.Name, + item.Name); + + m_log.DebugFormat("[XEngine] Loaded script {0}.{1}", + part.ParentGroup.RootPart.Name, item.Name); instance.AppDomain = appDomain; @@ -450,6 +453,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine UnloadAppDomain(instance.AppDomain); } + instance.RemoveState(); + instance = null; CleanAssemblies(); @@ -706,6 +711,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine private bool m_TimerQueued; private DateTime m_EventStart; private bool m_InEvent; + private string m_PrimName; + private string m_ScriptName; + private string m_Assembly; // Script state private string m_State="default"; @@ -715,6 +723,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine public bool Running { get { return m_RunEvents; } + set { m_RunEvents = value; } } public string State @@ -734,6 +743,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine set { m_AppDomain = value; } } + public string PrimName + { + get { return m_PrimName; } + } + + public string ScriptName + { + get { return m_ScriptName; } + } + public LLUUID ItemID { get { return m_ItemID; } @@ -766,7 +785,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine } public XScriptInstance(XEngine engine, uint localID, LLUUID objectID, - LLUUID itemID, LLUUID assetID, string assembly, AppDomain dom) + LLUUID itemID, LLUUID assetID, string assembly, AppDomain dom, + string primName, string scriptName) { m_Engine = engine; @@ -774,6 +794,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine m_ObjectID = objectID; m_ItemID = itemID; m_AssetID = assetID; + m_PrimName = primName; + m_ScriptName = scriptName; + m_Assembly = assembly; SceneObjectPart part=engine.World.GetSceneObjectPart(localID); if (part == null) @@ -811,10 +834,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine } catch (Exception e) { - m_Engine.Log.Error("Error loading script instance\n"+e.ToString()); + m_Engine.Log.Error("[XEngine] Error loading script instance\n"+e.ToString()); + return; } - string savedState = assembly + ".state"; + string savedState = Path.Combine(Path.GetDirectoryName(assembly), + m_ItemID.ToString() + ".state"); if (File.Exists(savedState)) { string xml = String.Empty; @@ -841,28 +866,53 @@ namespace OpenSim.Region.ScriptEngine.XEngine m_Engine.m_ASYNCLSLCommandManager.CreateFromData( m_LocalID, m_ItemID, m_ObjectID, PluginData); + + m_Engine.Log.DebugFormat("[XEngine] Successfully retrieved state for script {0}.{1}", m_PrimName, m_ScriptName); + + if(m_RunEvents) + { + m_RunEvents = false; + Start(); + } } } else { - m_Engine.Log.Error("Unable to load script state: Memory limit exceeded"); + m_Engine.Log.Error("[XEngine] Unable to load script state: Memory limit exceeded"); PostEvent(new XEventParams("state_entry", new Object[0], new XDetectParams[0])); + Start(); } } catch (Exception e) { - m_Engine.Log.ErrorFormat("Unable to load script state from xml: {0}\n"+e.ToString(), xml); + m_Engine.Log.ErrorFormat("[XEngine] Unable to load script state from xml: {0}\n"+e.ToString(), xml); PostEvent(new XEventParams("state_entry", new Object[0], new XDetectParams[0])); + Start(); } } else { + m_Engine.Log.ErrorFormat("[XEngine] Unable to load script state, file not found"); PostEvent(new XEventParams("state_entry", new Object[0], new XDetectParams[0])); + Start(); + } + } + + public void RemoveState() + { + string savedState = Path.Combine(Path.GetDirectoryName(m_Assembly), + m_ItemID.ToString() + ".state"); + + try + { + File.Delete(savedState); + } + catch(Exception) + { } - Start(); } public void VarDump(Dictionary vars) @@ -935,16 +985,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine result.Abort(); - if (SmartThreadPool.WaitAll(new IWorkItemResult[] {result}, new TimeSpan((long)10000000), false)) + lock (m_EventQueue) { - lock (m_EventQueue) - { - m_CurrentResult = null; - } - return true; + m_CurrentResult = null; } - m_Engine.Log.Error("[XEngine] Failed to reliably stop script"); return true; } @@ -960,6 +1005,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine public void PostEvent(XEventParams data) { +// m_Engine.Log.DebugFormat("[XEngine] Posted event {2} in state {3} to {0}.{1}", +// m_PrimName, m_ScriptName, data.EventName, m_State); lock (m_EventQueue) { if (m_EventQueue.Count >= m_Engine.MaxScriptQueue) @@ -1003,6 +1050,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (data.EventName == "state") // Hardcoded state change { +// m_Engine.Log.DebugFormat("[XEngine] Script {0}.{1} state set to {2}", +// m_PrimName, m_ScriptName, data.Params[0].ToString()); m_State=data.Params[0].ToString(); m_Engine.m_ASYNCLSLCommandManager.RemoveScript( m_LocalID, m_ItemID); @@ -1020,6 +1069,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine // m_Engine.Log.DebugFormat("[XEngine] Processed event {0}", data.EventName); SceneObjectPart part = m_Engine.World.GetSceneObjectPart( m_LocalID); +// m_Engine.Log.DebugFormat("[XEngine] Delivered event {2} in state {3} to {0}.{1}", +// m_PrimName, m_ScriptName, data.EventName, m_State); + try { m_EventStart = DateTime.Now; @@ -1148,14 +1200,19 @@ namespace OpenSim.Region.ScriptEngine.XEngine try { - FileStream fs = File.Create(assembly + ".state"); + FileStream fs = File.Create(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state")); System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); Byte[] buf = enc.GetBytes(xml); fs.Write(buf, 0, buf.Length); fs.Close(); } - catch(Exception) + catch(Exception e) + { + Console.WriteLine("Unable to save xml\n"+e.ToString()); + } + if(!File.Exists(Path.Combine(Path.GetDirectoryName(assembly), m_ItemID.ToString() + ".state"))) { + throw new Exception("Completed persistence save, but no file was created"); } } } @@ -1181,6 +1238,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine rootElement.AppendChild(state); + XmlElement running = xmldoc.CreateElement("", "Running", ""); + running.AppendChild(xmldoc.CreateTextNode( + instance.Running.ToString())); + + rootElement.AppendChild(running); + Dictionary vars = instance.GetVars(); XmlElement variables = xmldoc.CreateElement("", "Variables", ""); @@ -1277,6 +1340,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine case "State": instance.State=part.InnerText; break; + case "Running": + instance.Running=bool.Parse(part.InnerText); + break; case "Variables": XmlNodeList varL = part.ChildNodes; foreach (XmlNode var in varL) -- cgit v1.1