Major refactoring of appearance handling.

AvatarService -- add two new methods, GetAppearance and SetAppearance
to get around the lossy encoding in AvatarData. Preseve the old
functions to avoid changing the behavior for ROBUST services.

AvatarAppearance -- major refactor, moved the various encoding
methods used by AgentCircuitData, ClientAgentUpdate and
ScenePresence into one location. Changed initialization.

AvatarAttachments -- added a class specifically to handle
attachments in preparation for additional functionality
that will be needed for viewer 2.

AvatarFactory -- removed a number of unused or methods duplicated
in other locations. Moved in all appearance event handling from
ScenePresence. Required a change to IClientAPI that propogated
throughout all the IClientAPI implementations.
This commit is contained in:
Master ScienceSim
2010-10-20 16:17:54 -07:00
parent b2478b41c8
commit b1c8d05888
28 changed files with 1056 additions and 880 deletions

View File

@@ -51,6 +51,20 @@ namespace OpenSim.Services.AvatarService
m_log.Debug("[AVATAR SERVICE]: Starting avatar service");
}
// Get|SetAppearance should preserve existing semantics
// until AvatarData can be removed completely
public AvatarAppearance GetAppearance(UUID principalID)
{
AvatarData avatar = GetAvatar(principalID);
return avatar.ToAvatarAppearance(principalID);
}
public bool SetAppearance(UUID principalID, AvatarAppearance appearance)
{
AvatarData avatar = new AvatarData(appearance);
return SetAvatar(principalID,avatar);
}
public AvatarData GetAvatar(UUID principalID)
{
AvatarBaseData[] av = m_Database.Get("PrincipalID", principalID.ToString());

View File

@@ -87,6 +87,18 @@ namespace OpenSim.Services.Connectors
#region IAvatarService
public AvatarAppearance GetAppearance(UUID userID)
{
AvatarData avatar = GetAvatar(userID);
return avatar.ToAvatarAppearance(userID);
}
public bool SetAppearance(UUID userID, AvatarAppearance appearance)
{
AvatarData avatar = new AvatarData(appearance);
return SetAvatar(userID,avatar);
}
public AvatarData GetAvatar(UUID userID)
{
Dictionary<string, object> sendData = new Dictionary<string, object>();

View File

@@ -28,6 +28,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
// DEBUG ON
using System.Diagnostics;
// DEBUG OFF
using System.Reflection;
using log4net;
using Mono.Addins;
@@ -106,6 +109,80 @@ namespace OpenSim.Services.Connectors.SimianGrid
#region IAvatarService
// <summary>
// Retrieves the LLPackedAppearance field from user data and unpacks
// it into an AvatarAppearance structure
// </summary>
// <param name="userID"></param>
public AvatarAppearance GetAppearance(UUID userID)
{
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "GetUser" },
{ "UserID", userID.ToString() }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
if (response["Success"].AsBoolean())
{
OSDMap map = null;
try { map = OSDParser.DeserializeJson(response["LLPackedAppearance"].AsString()) as OSDMap; }
catch { }
if (map != null)
{
AvatarAppearance appearance = new AvatarAppearance(map);
// DEBUG ON
m_log.WarnFormat("[SIMIAN AVATAR CONNECTOR] retrieved appearance for {0}:\n{1}",userID,appearance.ToString());
// DEBUG OFF
return appearance;
}
m_log.WarnFormat("[SIMIAN AVATAR CONNECTOR]: Failed to decode appearance for {0}",userID);
return null;
}
m_log.WarnFormat("[SIMIAN AVATAR CONNECTOR]: Failed to get appearance for {0}: {1}",
userID,response["Message"].AsString());
return null;
}
// <summary>
// </summary>
// <param name=""></param>
public bool SetAppearance(UUID userID, AvatarAppearance appearance)
{
OSDMap map = appearance.Pack();
if (map == null)
{
m_log.WarnFormat("[SIMIAN AVATAR CONNECTOR]: Failed to encode appearance for {0}",userID);
return false;
}
// DEBUG ON
m_log.WarnFormat("[SIMIAN AVATAR CONNECTOR] save appearance for {0}",userID);
// DEBUG OFF
NameValueCollection requestArgs = new NameValueCollection
{
{ "RequestMethod", "AddUserData" },
{ "UserID", userID.ToString() },
{ "LLPackedAppearance", OSDParser.SerializeJsonString(map) }
};
OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
bool success = response["Success"].AsBoolean();
if (! success)
m_log.WarnFormat("[SIMIAN AVATAR CONNECTOR]: Failed to save appearance for {0}: {1}",
userID,response["Message"].AsString());
return success;
}
// <summary>
// </summary>
// <param name=""></param>
public AvatarData GetAvatar(UUID userID)
{
NameValueCollection requestArgs = new NameValueCollection
@@ -154,7 +231,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
foreach (KeyValuePair<string, OSD> kvp in map)
avatar.Data[kvp.Key] = kvp.Value.AsString();
}
return avatar;
}
else
@@ -173,6 +250,9 @@ namespace OpenSim.Services.Connectors.SimianGrid
return null;
}
// <summary>
// </summary>
// <param name=""></param>
public bool SetAvatar(UUID userID, AvatarData avatar)
{
m_log.Debug("[SIMIAN AVATAR CONNECTOR]: SetAvatar called for " + userID);

View File

@@ -37,6 +37,21 @@ namespace OpenSim.Services.Interfaces
{
public interface IAvatarService
{
/// <summary>
/// Called by the login service
/// </summary>
/// <param name="userID"></param>
/// <returns></returns>
AvatarAppearance GetAppearance(UUID userID);
/// <summary>
/// Called by everyone who can change the avatar data (so, regions)
/// </summary>
/// <param name="userID"></param>
/// <param name="appearance"></param>
/// <returns></returns>
bool SetAppearance(UUID userID, AvatarAppearance appearance);
/// <summary>
/// Called by the login service
/// </summary>
@@ -217,23 +232,26 @@ namespace OpenSim.Services.Interfaces
foreach (KeyValuePair<string, string> _kvp in Data)
if (_kvp.Key.StartsWith("_ap_"))
attchs[_kvp.Key] = _kvp.Value;
Hashtable aaAttachs = new Hashtable();
foreach (KeyValuePair<string, string> _kvp in attchs)
{
string pointStr = _kvp.Key.Substring(4);
int point = 0;
if (!Int32.TryParse(pointStr, out point))
continue;
Hashtable tmp = new Hashtable();
UUID uuid = UUID.Zero;
UUID.TryParse(_kvp.Value, out uuid);
tmp["item"] = uuid;
tmp["asset"] = UUID.Zero.ToString();
aaAttachs[point] = tmp;
appearance.SetAttachment(point,uuid,UUID.Zero);
}
appearance.SetAttachments(aaAttachs);
}
catch { }
catch
{
// We really should report something here, returning null
// will at least break the wrapper
return null;
}
return appearance;
}

View File

@@ -330,10 +330,10 @@ namespace OpenSim.Services.LLLoginService
//
// Get the avatar
//
AvatarData avatar = null;
AvatarAppearance avatar = null;
if (m_AvatarService != null)
{
avatar = m_AvatarService.GetAvatar(account.PrincipalID);
avatar = m_AvatarService.GetAppearance(account.PrincipalID);
}
//
@@ -601,7 +601,7 @@ namespace OpenSim.Services.LLLoginService
}
}
protected AgentCircuitData LaunchAgentAtGrid(GridRegion gatekeeper, GridRegion destination, UserAccount account, AvatarData avatar,
protected AgentCircuitData LaunchAgentAtGrid(GridRegion gatekeeper, GridRegion destination, UserAccount account, AvatarAppearance avatar,
UUID session, UUID secureSession, Vector3 position, string currentWhere, string viewer, string channel, string mac, string id0,
IPEndPoint clientIP, out string where, out string reason, out GridRegion dest)
{
@@ -697,14 +697,14 @@ namespace OpenSim.Services.LLLoginService
}
private AgentCircuitData MakeAgent(GridRegion region, UserAccount account,
AvatarData avatar, UUID session, UUID secureSession, uint circuit, Vector3 position,
AvatarAppearance avatar, UUID session, UUID secureSession, uint circuit, Vector3 position,
string ipaddress, string viewer, string channel, string mac, string id0)
{
AgentCircuitData aCircuit = new AgentCircuitData();
aCircuit.AgentID = account.PrincipalID;
if (avatar != null)
aCircuit.Appearance = avatar.ToAvatarAppearance(account.PrincipalID);
aCircuit.Appearance = new AvatarAppearance(avatar);
else
aCircuit.Appearance = new AvatarAppearance(account.PrincipalID);