Implement osAgentSaveAppearance() to save the appearance of an avatar in the region to a notecard

This is separate from osOwnerSaveAppearance() so that owner saves can be allowed without allowing arbitrary avatar saves
bulletsim
Justin Clark-Casey (justincc) 2011-08-11 22:26:47 +01:00
parent 50945dd560
commit b1ae930c6b
4 changed files with 78 additions and 5 deletions

View File

@ -2165,7 +2165,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (npcModule != null) if (npcModule != null)
{ {
UUID npcId = new UUID(npc.m_string); UUID npcId;
if (!UUID.TryParse(npc.m_string, out npcId))
return new LSL_Key(UUID.Zero.ToString());
if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
return new LSL_Key(UUID.Zero.ToString()); return new LSL_Key(UUID.Zero.ToString());
@ -2273,14 +2275,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return SaveAppearanceToNotecard(m_host.OwnerID, notecardName); return SaveAppearanceToNotecard(m_host.OwnerID, notecardName);
} }
protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecardName) public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecardName)
{
CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance");
return SaveAppearanceToNotecard(avatarId, notecardName);
}
protected LSL_Key SaveAppearanceToNotecard(ScenePresence sp, string notecardName)
{ {
IAvatarFactory appearanceModule = World.RequestModuleInterface<IAvatarFactory>(); IAvatarFactory appearanceModule = World.RequestModuleInterface<IAvatarFactory>();
if (appearanceModule != null) if (appearanceModule != null)
{ {
appearanceModule.SaveBakedTextures(m_host.OwnerID); appearanceModule.SaveBakedTextures(sp.UUID);
ScenePresence sp = m_host.ParentGroup.Scene.GetScenePresence(m_host.OwnerID);
OSDMap appearancePacked = sp.Appearance.Pack(); OSDMap appearancePacked = sp.Appearance.Pack();
TaskInventoryItem item TaskInventoryItem item
@ -2294,6 +2302,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
} }
} }
protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecardName)
{
ScenePresence sp = World.GetScenePresence(avatarId);
if (sp == null || sp.IsChildAgent)
return new LSL_Key(UUID.Zero.ToString());
return SaveAppearanceToNotecard(sp, notecardName);
}
protected LSL_Key SaveAppearanceToNotecard(LSL_Key rawAvatarId, string notecardName)
{
UUID avatarId;
if (!UUID.TryParse(rawAvatarId, out avatarId))
return new LSL_Key(UUID.Zero.ToString());
return SaveAppearanceToNotecard(avatarId, notecardName);
}
/// <summary> /// <summary>
/// Get current region's map texture UUID /// Get current region's map texture UUID
/// </summary> /// </summary>

View File

@ -168,7 +168,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules);
key osNpcCreate(string user, string name, vector position, key cloneFrom); key osNpcCreate(string user, string name, vector position, key cloneFrom);
LSL_Key osNpcSaveAppearance(key npc, string notecardName); LSL_Key osNpcSaveAppearance(key npc, string notecardName);
void osNpcLoadAppearance(key npc, string notecardNameOrUuid); void osNpcLoadAppearance(key npc, string notecardNameOrUuid);
@ -179,6 +178,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
void osNpcRemove(key npc); void osNpcRemove(key npc);
LSL_Key osOwnerSaveAppearance(string notecardName); LSL_Key osOwnerSaveAppearance(string notecardName);
LSL_Key osAgentSaveAppearance(key agentId, string notecardName);
key osGetMapTexture(); key osGetMapTexture();
key osGetRegionMapTexture(string regionName); key osGetRegionMapTexture(string regionName);

View File

@ -523,6 +523,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
return m_OSSL_Functions.osOwnerSaveAppearance(notecardName); return m_OSSL_Functions.osOwnerSaveAppearance(notecardName);
} }
public LSL_Key osAgentSaveAppearance(LSL_Key agentId, string notecardName)
{
return m_OSSL_Functions.osAgentSaveAppearance(agentId, notecardName);
}
public OSSLPrim Prim; public OSSLPrim Prim;
[Serializable] [Serializable]

View File

@ -184,5 +184,46 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight)); Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight));
} }
[Test]
public void TestOsAgentSaveAppearance()
{
TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure();
UUID ownerId = TestHelpers.ParseTail(0x1);
UUID nonOwnerId = TestHelpers.ParseTail(0x2);
float newHeight = 1.9f;
ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, nonOwnerId);
sp.Appearance.AvatarHeight = newHeight;
SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, ownerId);
SceneObjectPart part = so.RootPart;
m_scene.AddSceneObject(so);
OSSL_Api osslApi = new OSSL_Api();
osslApi.Initialize(m_engine, part, part.LocalId, part.UUID);
string notecardName = "appearanceNc";
osslApi.osAgentSaveAppearance(new LSL_Types.LSLString(nonOwnerId.ToString()), notecardName);
IList<TaskInventoryItem> items = part.Inventory.GetInventoryItems(notecardName);
Assert.That(items.Count, Is.EqualTo(1));
TaskInventoryItem ncItem = items[0];
Assert.That(ncItem.Name, Is.EqualTo(notecardName));
AssetBase ncAsset = m_scene.AssetService.Get(ncItem.AssetID.ToString());
Assert.That(ncAsset, Is.Not.Null);
AssetNotecard anc = new AssetNotecard(UUID.Zero, ncAsset.Data);
anc.Decode();
OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(anc.BodyText);
AvatarAppearance savedAppearance = new AvatarAppearance();
savedAppearance.Unpack(appearanceOsd);
Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight));
}
} }
} }