From 01a8a65d75e3e12f5cd4f1472acf12b215ee3ea7 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 25 Oct 2012 03:02:00 +0100 Subject: [PATCH] Get osNpcCreate() and osNpcLoadAppearance() to generate a script error if appearance notecard does not exist, rather than returning UUID.Zero or silently failing. --- .../Shared/Api/Implementation/OSSL_Api.cs | 11 ++++---- .../Shared/Tests/OSSL_ApiNpcTests.cs | 28 +++++++++++++++---- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 09722e7c28..965c1f04f1 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -2325,11 +2325,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; @@ -2394,8 +2395,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); diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs index 4e58315ee5..b49bcc2000 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs @@ -127,11 +127,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests OSSL_Api osslApi = new OSSL_Api(); osslApi.Initialize(m_engine, so.RootPart, null); - string npcRaw - = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name"); + string npcRaw; + bool gotExpectedException = false; + try + { + npcRaw + = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name"); + } + catch (ScriptException) + { + gotExpectedException = true; + } - UUID npcId = new UUID(npcRaw); - Assert.That(npcId, Is.EqualTo(UUID.Zero)); + Assert.That(gotExpectedException, Is.True); } /// @@ -233,7 +241,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName); - osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName); + bool gotExpectedException = false; + try + { + osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName); + } + catch (ScriptException) + { + gotExpectedException = true; + } + + Assert.That(gotExpectedException, Is.True); UUID npcId = new UUID(npcRaw); ScenePresence npc = m_scene.GetScenePresence(npcId);