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.
parent
5d4ac5a90f
commit
ae662b54ea
|
@ -1780,6 +1780,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
protected string LoadNotecard(string notecardNameOrUuid)
|
protected string LoadNotecard(string notecardNameOrUuid)
|
||||||
{
|
{
|
||||||
UUID assetID = CacheNotecard(notecardNameOrUuid);
|
UUID assetID = CacheNotecard(notecardNameOrUuid);
|
||||||
|
|
||||||
|
if (assetID != UUID.Zero)
|
||||||
|
{
|
||||||
StringBuilder notecardData = new StringBuilder();
|
StringBuilder notecardData = new StringBuilder();
|
||||||
|
|
||||||
for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
|
for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
|
||||||
|
@ -1794,6 +1797,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
return notecardData.ToString();
|
return notecardData.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cache a notecard's contents.
|
/// Cache a notecard's contents.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -2407,6 +2413,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string appearanceSerialized = LoadNotecard(notecard);
|
string appearanceSerialized = LoadNotecard(notecard);
|
||||||
|
|
||||||
|
if (appearanceSerialized == null)
|
||||||
|
return;
|
||||||
|
|
||||||
OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
|
OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
|
||||||
// OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
|
// OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
|
||||||
// Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
|
// Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
|
||||||
|
|
|
@ -36,12 +36,11 @@ using OpenMetaverse;
|
||||||
using OpenMetaverse.Assets;
|
using OpenMetaverse.Assets;
|
||||||
using OpenMetaverse.StructuredData;
|
using OpenMetaverse.StructuredData;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
using OpenSim.Region.CoreModules.Avatar.Attachments;
|
|
||||||
using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
|
using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
|
||||||
|
using OpenSim.Region.OptionalModules.World.NPC;
|
||||||
using OpenSim.Region.Framework.Scenes;
|
using OpenSim.Region.Framework.Scenes;
|
||||||
using OpenSim.Region.ScriptEngine.Shared;
|
using OpenSim.Region.ScriptEngine.Shared;
|
||||||
using OpenSim.Region.ScriptEngine.Shared.Api;
|
using OpenSim.Region.ScriptEngine.Shared.Api;
|
||||||
using OpenSim.Region.OptionalModules.World.NPC;
|
|
||||||
using OpenSim.Services.Interfaces;
|
using OpenSim.Services.Interfaces;
|
||||||
using OpenSim.Tests.Common;
|
using OpenSim.Tests.Common;
|
||||||
using OpenSim.Tests.Common.Mock;
|
using OpenSim.Tests.Common.Mock;
|
||||||
|
@ -69,8 +68,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
|
||||||
config.Set("Enabled", "true");
|
config.Set("Enabled", "true");
|
||||||
|
|
||||||
m_scene = new SceneHelpers().SetupScene();
|
m_scene = new SceneHelpers().SetupScene();
|
||||||
SceneHelpers.SetupSceneModules(
|
SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
|
||||||
m_scene, initConfigSource, new AvatarFactoryModule(), new AttachmentsModule(), new NPCModule());
|
|
||||||
|
|
||||||
m_engine = new XEngine.XEngine();
|
m_engine = new XEngine.XEngine();
|
||||||
m_engine.Initialise(initConfigSource);
|
m_engine.Initialise(initConfigSource);
|
||||||
|
|
|
@ -114,6 +114,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
|
||||||
Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight));
|
Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestOsNpcCreateNotExistingNotecard()
|
||||||
|
{
|
||||||
|
TestHelpers.InMethod();
|
||||||
|
|
||||||
|
UUID userId = TestHelpers.ParseTail(0x1);
|
||||||
|
|
||||||
|
SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
|
||||||
|
m_scene.AddSceneObject(so);
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
UUID npcId = new UUID(npcRaw);
|
||||||
|
Assert.That(npcId, Is.EqualTo(UUID.Zero));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test creation of an NPC where the appearance data comes from an avatar already in the region.
|
/// Test creation of an NPC where the appearance data comes from an avatar already in the region.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -187,6 +207,40 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
|
||||||
Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(secondHeight));
|
Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(secondHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestOsNpcLoadAppearanceNotExistingNotecard()
|
||||||
|
{
|
||||||
|
TestHelpers.InMethod();
|
||||||
|
|
||||||
|
// Store an avatar with a different height from default in a notecard.
|
||||||
|
UUID userId = TestHelpers.ParseTail(0x1);
|
||||||
|
float firstHeight = 1.9f;
|
||||||
|
float secondHeight = 2.1f;
|
||||||
|
string firstAppearanceNcName = "appearanceNc1";
|
||||||
|
string secondAppearanceNcName = "appearanceNc2";
|
||||||
|
|
||||||
|
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
|
||||||
|
sp.Appearance.AvatarHeight = firstHeight;
|
||||||
|
SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, 0x10);
|
||||||
|
SceneObjectPart part = so.RootPart;
|
||||||
|
m_scene.AddSceneObject(so);
|
||||||
|
|
||||||
|
OSSL_Api osslApi = new OSSL_Api();
|
||||||
|
osslApi.Initialize(m_engine, part, null);
|
||||||
|
|
||||||
|
osslApi.osOwnerSaveAppearance(firstAppearanceNcName);
|
||||||
|
|
||||||
|
string npcRaw
|
||||||
|
= osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), firstAppearanceNcName);
|
||||||
|
|
||||||
|
osslApi.osNpcLoadAppearance(npcRaw, secondAppearanceNcName);
|
||||||
|
|
||||||
|
UUID npcId = new UUID(npcRaw);
|
||||||
|
ScenePresence npc = m_scene.GetScenePresence(npcId);
|
||||||
|
Assert.That(npc, Is.Not.Null);
|
||||||
|
Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(firstHeight));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test removal of an owned NPC.
|
/// Test removal of an owned NPC.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue