diff options
author | Justin Clark-Casey (justincc) | 2012-10-25 03:02:00 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-10-25 03:02:00 +0100 |
commit | 8af8319b95c14819d0305527f8f6876a334fa3c0 (patch) | |
tree | 1b74153bfc34b352b15f79efca9672a870697814 | |
parent | When scripts generate expected exceptions (e.g. due to checked bad parameter)... (diff) | |
download | opensim-SC-8af8319b95c14819d0305527f8f6876a334fa3c0.zip opensim-SC-8af8319b95c14819d0305527f8f6876a334fa3c0.tar.gz opensim-SC-8af8319b95c14819d0305527f8f6876a334fa3c0.tar.bz2 opensim-SC-8af8319b95c14819d0305527f8f6876a334fa3c0.tar.xz |
Get osNpcCreate() and osNpcLoadAppearance() to generate a script error if appearance notecard does not exist, rather than returning UUID.Zero or silently failing.
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 11 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs | 30 |
2 files changed, 30 insertions, 11 deletions
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 | |||
2346 | appearance = new AvatarAppearance(); | 2346 | appearance = new AvatarAppearance(); |
2347 | appearance.Unpack(appearanceOsd); | 2347 | appearance.Unpack(appearanceOsd); |
2348 | } | 2348 | } |
2349 | else | ||
2350 | { | ||
2351 | OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard)); | ||
2352 | } | ||
2349 | } | 2353 | } |
2350 | 2354 | ||
2351 | if (appearance == null) | ||
2352 | return new LSL_Key(UUID.Zero.ToString()); | ||
2353 | |||
2354 | UUID ownerID = UUID.Zero; | 2355 | UUID ownerID = UUID.Zero; |
2355 | if (owned) | 2356 | if (owned) |
2356 | ownerID = m_host.OwnerID; | 2357 | ownerID = m_host.OwnerID; |
@@ -2415,8 +2416,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2415 | string appearanceSerialized = LoadNotecard(notecard); | 2416 | string appearanceSerialized = LoadNotecard(notecard); |
2416 | 2417 | ||
2417 | if (appearanceSerialized == null) | 2418 | if (appearanceSerialized == null) |
2418 | return; | 2419 | OSSLError(string.Format("osNpcCreate: Notecard reference '{0}' not found.", notecard)); |
2419 | 2420 | ||
2420 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); | 2421 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); |
2421 | // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); | 2422 | // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); |
2422 | // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized); | 2423 | // 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 4e58315..b49bcc2 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 | |||
127 | OSSL_Api osslApi = new OSSL_Api(); | 127 | OSSL_Api osslApi = new OSSL_Api(); |
128 | osslApi.Initialize(m_engine, so.RootPart, null); | 128 | osslApi.Initialize(m_engine, so.RootPart, null); |
129 | 129 | ||
130 | string npcRaw | 130 | string npcRaw; |
131 | = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name"); | 131 | bool gotExpectedException = false; |
132 | 132 | try | |
133 | UUID npcId = new UUID(npcRaw); | 133 | { |
134 | Assert.That(npcId, Is.EqualTo(UUID.Zero)); | 134 | npcRaw |
135 | = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name"); | ||
136 | } | ||
137 | catch (ScriptException) | ||
138 | { | ||
139 | gotExpectedException = true; | ||
140 | } | ||
141 | |||
142 | Assert.That(gotExpectedException, Is.True); | ||
135 | } | 143 | } |
136 | 144 | ||
137 | /// <summary> | 145 | /// <summary> |
@@ -233,7 +241,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
233 | string npcRaw | 241 | string npcRaw |
234 | = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName); | 242 | = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName); |
235 | 243 | ||
236 | osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName); | 244 | bool gotExpectedException = false; |
245 | try | ||
246 | { | ||
247 | osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName); | ||
248 | } | ||
249 | catch (ScriptException) | ||
250 | { | ||
251 | gotExpectedException = true; | ||
252 | } | ||
253 | |||
254 | Assert.That(gotExpectedException, Is.True); | ||
237 | 255 | ||
238 | UUID npcId = new UUID(npcRaw); | 256 | UUID npcId = new UUID(npcRaw); |
239 | ScenePresence npc = m_scene.GetScenePresence(npcId); | 257 | ScenePresence npc = m_scene.GetScenePresence(npcId); |