From 36bf16d35e928a338c932feeec42c0c8f35d8846 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Wed, 30 Apr 2008 03:36:13 +0000 Subject: Patch from Melanie: 0001077: [PATCH] LSL types cannot be cast implicitly or explicitly in many cases Thanks Melanie! * Also, I moved the event parser and re-writer to a separate static object. More work will be done here shortly. --- .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 64 +++++--- OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | 176 +++++++++++++++------ .../AsyncCommandPlugins/HttpRequest.cs | 2 +- .../AsyncCommandPlugins/Listener.cs | 2 +- .../AsyncCommandPlugins/SensorRepeat.cs | 2 +- .../AsyncCommandPlugins/XmlRequest.cs | 12 +- .../Common/ScriptEngineBase/EventManager.cs | 23 +-- .../ScriptEngine/Common/ScriptServerInterfaces.cs | 2 +- 8 files changed, 185 insertions(+), 98 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Common') diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index e29ee5a..66d2700 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -80,6 +80,15 @@ namespace OpenSim.Region.ScriptEngine.Common // Set it if it changed if (m_state != value) { + try + { + m_ScriptEngine.m_EventManager.state_exit(m_localID); + + } + catch (AppDomainUnloadedException) + { + Console.WriteLine("[SCRIPT]: state change called when script was unloaded. Nothing to worry about, but noting the occurance"); + } m_state = value; try { @@ -2136,7 +2145,7 @@ namespace OpenSim.Region.ScriptEngine.Common m_host.TaskInventory[invItemID].PermsMask=0; m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( - m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {(int)0}); + m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(0)}); return; } @@ -2158,7 +2167,7 @@ namespace OpenSim.Region.ScriptEngine.Common m_host.TaskInventory[invItemID].PermsMask=perm; m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( - m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {(int)perm}); + m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(perm)}); return; } @@ -2175,7 +2184,7 @@ namespace OpenSim.Region.ScriptEngine.Common m_host.TaskInventory[invItemID].PermsMask=perm; m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( - m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {(int)perm}); + m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(perm)}); return; } @@ -2202,7 +2211,7 @@ namespace OpenSim.Region.ScriptEngine.Common // Requested agent is not in range, refuse perms m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( - m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {(int)0}); + m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(0)}); } void handleScriptAnswer(IClientAPI client, LLUUID taskID, LLUUID itemID, int answer) @@ -2220,7 +2229,7 @@ namespace OpenSim.Region.ScriptEngine.Common m_host.TaskInventory[invItemID].PermsMask=answer; m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( - m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {(int)answer}); + m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(answer)}); } public string llGetPermissionsKey() @@ -2600,7 +2609,7 @@ namespace OpenSim.Region.ScriptEngine.Common object[] resobj = new object[] { - m_host.LinkNum + 1, num, msg, id + new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id) }; m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( @@ -2627,7 +2636,7 @@ namespace OpenSim.Region.ScriptEngine.Common partItemID = item.ItemID; Object[] resobj = new object[] { - m_host.LinkNum + 1, num, msg, id + new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id) }; m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( @@ -2655,7 +2664,7 @@ namespace OpenSim.Region.ScriptEngine.Common partItemID = item.ItemID; Object[] resobj = new object[] { - m_host.LinkNum + 1, num, msg, id + new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id) }; m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( @@ -2685,7 +2694,7 @@ namespace OpenSim.Region.ScriptEngine.Common partItemID = item.ItemID; Object[] resobj = new object[] { - m_host.LinkNum + 1, num, msg, id + new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id) }; m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( @@ -2709,7 +2718,7 @@ namespace OpenSim.Region.ScriptEngine.Common object[] resobj = new object[] { - m_host.LinkNum + 1, num, msg, id + new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id) }; m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( @@ -2737,7 +2746,7 @@ namespace OpenSim.Region.ScriptEngine.Common partItemID = item.ItemID; Object[] resObjDef = new object[] { - m_host.LinkNum + 1, num, msg, id + new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id) }; m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( @@ -3058,7 +3067,14 @@ namespace OpenSim.Region.ScriptEngine.Common { return 0; } - return Convert.ToInt32(src.Data[index]); + try + { + return Convert.ToInt32(src.Data[index]); + } + catch (System.FormatException e) + { + return 0; + } } public double osList2Double(LSL_Types.list src, int index) @@ -3086,7 +3102,14 @@ namespace OpenSim.Region.ScriptEngine.Common { return 0.0; } - return Convert.ToDouble(src.Data[index]); + try + { + return Convert.ToDouble(src.Data[index]); + } + catch (System.FormatException e) + { + return 0.0; + } } public string llList2String(LSL_Types.list src, int index) @@ -3112,18 +3135,9 @@ namespace OpenSim.Region.ScriptEngine.Common } if (index >= src.Length) { - return "00000000-0000-0000-0000-000000000000"; - } - //return OpenSim.Framework.ToString(src[index]); - LLUUID tmpkey; - if (LLUUID.TryParse(src.Data[index].ToString(), out tmpkey)) - { - return tmpkey.ToString(); - } - else - { - return "00000000-0000-0000-0000-000000000000"; + return ""; } + return src.Data[index].ToString(); } public LSL_Types.Vector3 llList2Vector(LSL_Types.list src, int index) @@ -4317,7 +4331,7 @@ namespace OpenSim.Region.ScriptEngine.Common if (xmlrpcMod.IsEnabled()) { LLUUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID); - object[] resobj = new object[] { 1, channelID.ToString(), LLUUID.Zero.ToString(), String.Empty, 0, String.Empty }; + object[] resobj = new object[] { new LSL_Types.LSLInteger(1), new LSL_Types.LSLString(channelID.ToString()), new LSL_Types.LSLString(LLUUID.Zero.ToString()), new LSL_Types.LSLString(String.Empty), new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(String.Empty) }; m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(m_localID, m_itemID, "remote_data", EventQueueManager.llDetectNull, resobj); } } diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs index 65047fb..5337d7f 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs @@ -64,6 +64,11 @@ namespace OpenSim.Region.ScriptEngine.Common str = str.Replace('<', ' '); str = str.Replace('>', ' '); string[] tmps = str.Split(new Char[] { ',', '<', '>' }); + if(tmps.Length < 3) + { + x=y=z=0; + return; + } bool res; res = Double.TryParse(tmps[0], out x); res = res & Double.TryParse(tmps[1], out y); @@ -76,14 +81,27 @@ namespace OpenSim.Region.ScriptEngine.Common public override string ToString() { - return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ">"; + string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z); + return s; + } + + public static explicit operator LSLString(Vector3 vec) + { + string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); + return new LSLString(s); } public static explicit operator string(Vector3 vec) { - return "<" + vec.x.ToString() + ", " + vec.y.ToString() + ", " + vec.z.ToString() + ">"; + string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); + return s; } + public static explicit operator Vector3(string s) + { + return new Vector3(s); + } + public static bool operator ==(Vector3 lhs, Vector3 rhs) { return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z); @@ -278,6 +296,11 @@ namespace OpenSim.Region.ScriptEngine.Common str = str.Replace('<', ' '); str = str.Replace('>', ' '); string[] tmps = str.Split(new Char[] { ',', '<', '>' }); + if(tmps.Length < 4) + { + x=y=z=s=0; + return; + } bool res; res = Double.TryParse(tmps[0], out x); res = res & Double.TryParse(tmps[1], out y); @@ -307,14 +330,27 @@ namespace OpenSim.Region.ScriptEngine.Common public override string ToString() { - return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ", " + s.ToString() + ">"; + string st=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s); + return st; } public static explicit operator string(Quaternion r) { - return "<" + r.x.ToString() + ", " + r.y.ToString() + ", " + r.z.ToString() + ", " + r.s.ToString() + ">"; + string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); + return s; + } + + public static explicit operator LSLString(Quaternion r) + { + string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); + return new LSLString(s); } + public static explicit operator Quaternion(string s) + { + return new Quaternion(s); + } + public static bool operator ==(Quaternion lhs, Quaternion rhs) { // Return true if the fields match: @@ -369,12 +405,20 @@ namespace OpenSim.Region.ScriptEngine.Common public int Length { - get { return m_data.Length; } + get { + if(m_data == null) + m_data=new Object[0]; + return m_data.Length; + } } public object[] Data { - get { return m_data; } + get { + if(m_data == null) + m_data=new Object[0]; + return m_data; + } } public static list operator +(list a, list b) @@ -571,13 +615,20 @@ namespace OpenSim.Region.ScriptEngine.Common if(Data.Length == 0) return new list(); // Don't even bother + string[] keys; + if(stride == 1) // The simple case { Object[] ret=new Object[Data.Length]; Array.Copy(Data, 0, ret, 0, Data.Length); - Array.Sort(ret); + keys=new string[Data.Length]; + int k; + for(k=0;k