From ae662b54ea972e4da4f805fe38b5714d595e032a Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 25 Oct 2012 01:07:06 +0100 Subject: Make osNpcCreate() return UUID.Zero instead of throwing an exception if notecard name is invalid. Make osNpcLoadAppearance() fail silently in same circumstance rather than throwing exception. --- .../Shared/Api/Implementation/OSSL_Api.cs | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 29bc163..804b0af 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -1780,18 +1780,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api protected string LoadNotecard(string notecardNameOrUuid) { UUID assetID = CacheNotecard(notecardNameOrUuid); - StringBuilder notecardData = new StringBuilder(); - for (int count = 0; count < NotecardCache.GetLines(assetID); count++) + if (assetID != UUID.Zero) { - string line = NotecardCache.GetLine(assetID, count) + "\n"; - -// m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line); - - notecardData.Append(line); + StringBuilder notecardData = new StringBuilder(); + + for (int count = 0; count < NotecardCache.GetLines(assetID); count++) + { + string line = NotecardCache.GetLine(assetID, count) + "\n"; + + // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line); + + notecardData.Append(line); + } + + return notecardData.ToString(); } - return notecardData.ToString(); + return null; } /// @@ -2407,6 +2413,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return; string appearanceSerialized = LoadNotecard(notecard); + + if (appearanceSerialized == null) + return; + OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized); -- cgit v1.1 From d9aaf51561ea7bb2ee030c648611a5281f21ec49 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 25 Oct 2012 02:52:20 +0100 Subject: When scripts generate expected exceptions (e.g. due to checked bad parameter) throw ScriptException instead of just a plain old exception. This is to make it easier to distinguish these exceptions from unexpected OpenSimulator problems internally and in regression tests. No functional changes. --- .../Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 4 ++-- .../Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | 10 +++++----- .../Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index cf801ba..dc791d3 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -10685,12 +10685,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api internal void Deprecated(string command) { - throw new Exception("Command deprecated: " + command); + throw new ScriptException("Command deprecated: " + command); } internal void LSLError(string msg) { - throw new Exception("LSL Runtime Error: " + msg); + throw new ScriptException("LSL Runtime Error: " + msg); } public delegate void AssetRequestCallback(UUID assetID, AssetBase asset); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index 6809c09..a830a15 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs @@ -95,13 +95,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api internal void MODError(string msg) { - throw new Exception("MOD Runtime Error: " + msg); + throw new ScriptException("MOD Runtime Error: " + msg); } - // - //Dumps an error message on the debug console. - // - + /// + /// Dumps an error message on the debug console. + /// + /// internal void MODShoutError(string message) { if (message.Length > 1023) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 804b0af..5301ccd 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -210,7 +210,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api internal void OSSLError(string msg) { - throw new Exception("OSSL Runtime Error: " + msg); + throw new ScriptException("OSSL Runtime Error: " + msg); } /// -- cgit v1.1 From 8af8319b95c14819d0305527f8f6876a334fa3c0 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 25 Oct 2012 03:02:00 +0100 Subject: Get osNpcCreate() and osNpcLoadAppearance() to generate a script error if appearance notecard does not exist, rather than returning UUID.Zero or silently failing. --- .../Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 5301ccd..0811519 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2346,11 +2346,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api appearance = new AvatarAppearance(); appearance.Unpack(appearanceOsd); } + else + { + OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard)); + } } - if (appearance == null) - return new LSL_Key(UUID.Zero.ToString()); - UUID ownerID = UUID.Zero; if (owned) ownerID = m_host.OwnerID; @@ -2415,8 +2416,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api string appearanceSerialized = LoadNotecard(notecard); if (appearanceSerialized == null) - return; - + OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard)); + OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized); -- cgit v1.1 From 01972cc9e8f3288330cdc7ba343b99be7f1491ec Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Tue, 23 Oct 2012 11:34:43 +0100 Subject: system ints can end up in LSL lists, which can cause counter-intuitive unknown list element type errors in ConvertFromLSL (via modInvoke) --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index a830a15..60bb107 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs @@ -359,6 +359,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api result[i] = (string)(LSL_String)plist[i]; else if (plist[i] is LSL_Integer) result[i] = (int)(LSL_Integer)plist[i]; + else if (plist[i] is int) + result[i] = plist[i]; else if (plist[i] is LSL_Float) result[i] = (float)(LSL_Float)plist[i]; else if (plist[i] is LSL_Key) -- cgit v1.1 From ecdb88679e6bb59da13da0f3994cc42d8e84a30d Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Tue, 23 Oct 2012 11:39:55 +0100 Subject: Removing the apparently superfluous explicit namespace reference so that the if-else-if-else block in ConvertFromLSL can have a consistent appearance --- .../Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index 60bb107..a181dbe 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs @@ -366,15 +366,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api else if (plist[i] is LSL_Key) result[i] = new UUID((LSL_Key)plist[i]); else if (plist[i] is LSL_Rotation) - { - result[i] = (OpenMetaverse.Quaternion)( - (LSL_Rotation)plist[i]); - } + result[i] = (Quaternion)((LSL_Rotation)plist[i]); else if (plist[i] is LSL_Vector) - { - result[i] = (OpenMetaverse.Vector3)( - (LSL_Vector)plist[i]); - } + result[i] = (Vector3)((LSL_Vector)plist[i]); else MODError(String.Format("{0}: unknown LSL list element type", fname)); } -- cgit v1.1 From 1b3b7a61acf8784af3167a35c0f06eaeb413af9c Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 26 Oct 2012 01:50:46 +0100 Subject: minor: Add comment as to why we are pulcking plain old ints out of the LSL_List when converting values from LSL for modInvoke() --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index a181dbe..8f34833 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs @@ -359,6 +359,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api result[i] = (string)(LSL_String)plist[i]; else if (plist[i] is LSL_Integer) result[i] = (int)(LSL_Integer)plist[i]; + // The int check exists because of the many plain old int script constants in ScriptBase which + // are not LSL_Integers. else if (plist[i] is int) result[i] = plist[i]; else if (plist[i] is LSL_Float) -- cgit v1.1 From 18b1ee6f379f4d34f72a9056bf6cdf185311fd05 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Tue, 23 Oct 2012 15:29:40 +0100 Subject: Formatting and casing correction in WorldCommModule, trailing new line in OSSL to get git diff to not complain --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 0811519..0650b90 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -3648,4 +3648,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api DropAttachmentAt(false, pos, rot); } } -} \ No newline at end of file +} -- cgit v1.1 From e977761071a2d614a9a621437fbf86479b414759 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Tue, 23 Oct 2012 15:42:16 +0100 Subject: adding ability for listeners to be filtered by regular expressions and a general-purpose function to see if a given string matches a given regex --- .../Shared/Api/Implementation/OSSL_Api.cs | 63 ++++++++++++++++++++++ .../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 24 +++++++++ .../Shared/Api/Runtime/LSL_Constants.cs | 10 ++++ .../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 10 ++++ 4 files changed, 107 insertions(+) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 0650b90..828288d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -3647,5 +3647,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api DropAttachmentAt(false, pos, rot); } + + public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield) + { + CheckThreatLevel(ThreatLevel.Low, "osListenRegex"); + m_host.AddScriptLPS(1); + UUID keyID; + UUID.TryParse(ID, out keyID); + + // if we want the name to be used as a regular expression, ensure it is valid first. + if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME) + { + try + { + Regex.IsMatch("", name); + } + catch (Exception) + { + OSSLShoutError("Name regex is invalid."); + return -1; + } + } + + // if we want the msg to be used as a regular expression, ensure it is valid first. + if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) + { + try + { + Regex.IsMatch("", msg); + } + catch (Exception) + { + OSSLShoutError("Message regex is invalid."); + return -1; + } + } + + IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface(); + return (wComm == null) ? -1 : wComm.Listen( + m_host.LocalId, + m_item.ItemID, + m_host.UUID, + channelID, + name, + keyID, + msg, + regexBitfield + ); + } + + public LSL_Integer osRegexIsMatch(string input, string pattern) + { + CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch"); + m_host.AddScriptLPS(1); + try + { + return Regex.IsMatch(input, pattern) ? 1 : 0; + } + catch (Exception) + { + OSSLShoutError("Possible invalid regular expression detected."); + return 0; + } + } } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 93188c9..cdd9ea8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -418,5 +418,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces /// /// void osForceDropAttachmentAt(vector pos, rotation rot); + + /// + /// Identical to llListen except for a bitfield which indicates which + /// string parameters should be parsed as regex patterns. + /// + /// + /// + /// + /// + /// + /// OS_LISTEN_REGEX_NAME + /// OS_LISTEN_REGEX_MESSAGE + /// + /// + LSL_Integer osListenRegex(int channelID, string name, string ID, + string msg, int regexBitfield); + + /// + /// Wraps to bool Regex.IsMatch(string input, string pattern) + /// + /// string to test for match + /// string to use as pattern + /// boolean + LSL_Integer osRegexIsMatch(string input, string pattern); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index 62bd6b8..880841b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs @@ -716,5 +716,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public static readonly LSLInteger RCERR_UNKNOWN = -1; public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2; public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3; + + /// + /// process name parameter as regex + /// + public const int OS_LISTEN_REGEX_NAME = 0x1; + + /// + /// process message parameter as regex + /// + public const int OS_LISTEN_REGEX_MESSAGE = 0x2; } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index dee1b28..afa9ae0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -992,5 +992,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase { m_OSSL_Functions.osForceDropAttachmentAt(pos, rot); } + + public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield) + { + return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield); + } + + public LSL_Integer osRegexIsMatch(string input, string pattern) + { + return m_OSSL_Functions.osRegexIsMatch(input, pattern); + } } } -- cgit v1.1