aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-10-25 01:07:06 +0100
committerJustin Clark-Casey (justincc)2012-10-25 01:07:06 +0100
commitae662b54ea972e4da4f805fe38b5714d595e032a (patch)
treebbb79e30a6b42e25b5edec4abc6c56e5432cb4ea /OpenSim/Region/ScriptEngine
parentAdd TestOsNpcLoadAppearance() (diff)
downloadopensim-SC_OLD-ae662b54ea972e4da4f805fe38b5714d595e032a.zip
opensim-SC_OLD-ae662b54ea972e4da4f805fe38b5714d595e032a.tar.gz
opensim-SC_OLD-ae662b54ea972e4da4f805fe38b5714d595e032a.tar.bz2
opensim-SC_OLD-ae662b54ea972e4da4f805fe38b5714d595e032a.tar.xz
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.
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs26
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs6
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs54
3 files changed, 74 insertions, 12 deletions
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
1780 protected string LoadNotecard(string notecardNameOrUuid) 1780 protected string LoadNotecard(string notecardNameOrUuid)
1781 { 1781 {
1782 UUID assetID = CacheNotecard(notecardNameOrUuid); 1782 UUID assetID = CacheNotecard(notecardNameOrUuid);
1783 StringBuilder notecardData = new StringBuilder();
1784 1783
1785 for (int count = 0; count < NotecardCache.GetLines(assetID); count++) 1784 if (assetID != UUID.Zero)
1786 { 1785 {
1787 string line = NotecardCache.GetLine(assetID, count) + "\n"; 1786 StringBuilder notecardData = new StringBuilder();
1788 1787
1789// m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line); 1788 for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
1790 1789 {
1791 notecardData.Append(line); 1790 string line = NotecardCache.GetLine(assetID, count) + "\n";
1791
1792 // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
1793
1794 notecardData.Append(line);
1795 }
1796
1797 return notecardData.ToString();
1792 } 1798 }
1793 1799
1794 return notecardData.ToString(); 1800 return null;
1795 } 1801 }
1796 1802
1797 /// <summary> 1803 /// <summary>
@@ -2407,6 +2413,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2407 return; 2413 return;
2408 2414
2409 string appearanceSerialized = LoadNotecard(notecard); 2415 string appearanceSerialized = LoadNotecard(notecard);
2416
2417 if (appearanceSerialized == null)
2418 return;
2419
2410 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); 2420 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
2411// OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); 2421// OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
2412// Console.WriteLine("appearanceSerialized {0}", appearanceSerialized); 2422// Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
index eb51c4e..c401794 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
@@ -36,12 +36,11 @@ using OpenMetaverse;
36using OpenMetaverse.Assets; 36using OpenMetaverse.Assets;
37using OpenMetaverse.StructuredData; 37using OpenMetaverse.StructuredData;
38using OpenSim.Framework; 38using OpenSim.Framework;
39using OpenSim.Region.CoreModules.Avatar.Attachments;
40using OpenSim.Region.CoreModules.Avatar.AvatarFactory; 39using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
40using OpenSim.Region.OptionalModules.World.NPC;
41using OpenSim.Region.Framework.Scenes; 41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared; 42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api; 43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Region.OptionalModules.World.NPC;
45using OpenSim.Services.Interfaces; 44using OpenSim.Services.Interfaces;
46using OpenSim.Tests.Common; 45using OpenSim.Tests.Common;
47using OpenSim.Tests.Common.Mock; 46using OpenSim.Tests.Common.Mock;
@@ -69,8 +68,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
69 config.Set("Enabled", "true"); 68 config.Set("Enabled", "true");
70 69
71 m_scene = new SceneHelpers().SetupScene(); 70 m_scene = new SceneHelpers().SetupScene();
72 SceneHelpers.SetupSceneModules( 71 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
73 m_scene, initConfigSource, new AvatarFactoryModule(), new AttachmentsModule(), new NPCModule());
74 72
75 m_engine = new XEngine.XEngine(); 73 m_engine = new XEngine.XEngine();
76 m_engine.Initialise(initConfigSource); 74 m_engine.Initialise(initConfigSource);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
index 0a3a75d..4e58315 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiNpcTests.cs
@@ -114,6 +114,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
114 Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight)); 114 Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight));
115 } 115 }
116 116
117 [Test]
118 public void TestOsNpcCreateNotExistingNotecard()
119 {
120 TestHelpers.InMethod();
121
122 UUID userId = TestHelpers.ParseTail(0x1);
123
124 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
125 m_scene.AddSceneObject(so);
126
127 OSSL_Api osslApi = new OSSL_Api();
128 osslApi.Initialize(m_engine, so.RootPart, null);
129
130 string npcRaw
131 = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), "not existing notecard name");
132
133 UUID npcId = new UUID(npcRaw);
134 Assert.That(npcId, Is.EqualTo(UUID.Zero));
135 }
136
117 /// <summary> 137 /// <summary>
118 /// Test creation of an NPC where the appearance data comes from an avatar already in the region. 138 /// Test creation of an NPC where the appearance data comes from an avatar already in the region.
119 /// </summary> 139 /// </summary>
@@ -187,6 +207,40 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
187 Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(secondHeight)); 207 Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(secondHeight));
188 } 208 }
189 209
210 [Test]
211 public void TestOsNpcLoadAppearanceNotExistingNotecard()
212 {
213 TestHelpers.InMethod();
214
215 // Store an avatar with a different height from default in a notecard.
216 UUID userId = TestHelpers.ParseTail(0x1);
217 float firstHeight = 1.9f;
218 float secondHeight = 2.1f;
219 string firstAppearanceNcName = "appearanceNc1";
220 string secondAppearanceNcName = "appearanceNc2";
221
222 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
223 sp.Appearance.AvatarHeight = firstHeight;
224 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
225 SceneObjectPart part = so.RootPart;
226 m_scene.AddSceneObject(so);
227
228 OSSL_Api osslApi = new OSSL_Api();
229 osslApi.Initialize(m_engine, part, null);
230
231 osslApi.osOwnerSaveAppearance(firstAppearanceNcName);
232
233 string npcRaw
234 = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName);
235
236 osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName);
237
238 UUID npcId = new UUID(npcRaw);
239 ScenePresence npc = m_scene.GetScenePresence(npcId);
240 Assert.That(npc, Is.Not.Null);
241 Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(firstHeight));
242 }
243
190 /// <summary> 244 /// <summary>
191 /// Test removal of an owned NPC. 245 /// Test removal of an owned NPC.
192 /// </summary> 246 /// </summary>