Add "wearables check" console command

This checks that all the wearable assets and any assets for a given logged in avatar exist in the asset service
ghosts
Justin Clark-Casey (justincc) 2014-10-28 23:00:49 +00:00
parent cc23d4bac5
commit 4275342515
2 changed files with 245 additions and 73 deletions

View File

@ -73,6 +73,67 @@ namespace OpenSim.Region.Framework.Scenes
m_assetService = assetService;
}
/// <summary>
/// Gather all the asset uuids associated with the asset referenced by a given uuid
/// </summary>
/// <remarks>
/// This includes both those directly associated with
/// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
/// within this object).
/// This method assumes that the asset type associated with this asset in persistent storage is correct (which
/// should always be the case). So with this method we always need to retrieve asset data even if the asset
/// is of a type which is known not to reference any other assets
/// </remarks>
/// <param name="assetUuid">The uuid of the asset for which to gather referenced assets</param>
/// <param name="assetUuids">The assets gathered</param>
public void GatherAssetUuids(UUID assetUuid, IDictionary<UUID, sbyte> assetUuids)
{
// avoid infinite loops
if (assetUuids.ContainsKey(assetUuid))
return;
try
{
AssetBase assetBase = GetAsset(assetUuid);
if (null != assetBase)
{
sbyte assetType = assetBase.Type;
assetUuids[assetUuid] = assetType;
if ((sbyte)AssetType.Bodypart == assetType || (sbyte)AssetType.Clothing == assetType)
{
GetWearableAssetUuids(assetBase, assetUuids);
}
else if ((sbyte)AssetType.Gesture == assetType)
{
GetGestureAssetUuids(assetBase, assetUuids);
}
else if ((sbyte)AssetType.Notecard == assetType)
{
GetTextEmbeddedAssetUuids(assetBase, assetUuids);
}
else if ((sbyte)AssetType.LSLText == assetType)
{
GetTextEmbeddedAssetUuids(assetBase, assetUuids);
}
else if ((sbyte)OpenSimAssetType.Material == assetType)
{
GetMaterialAssetUuids(assetBase, assetUuids);
}
else if ((sbyte)AssetType.Object == assetType)
{
GetSceneObjectAssetUuids(assetBase, assetUuids);
}
}
}
catch (Exception)
{
m_log.ErrorFormat("[UUID GATHERER]: Failed to gather uuids for asset id {0}", assetUuid);
throw;
}
}
/// <summary>
/// Gather all the asset uuids associated with the asset referenced by a given uuid
/// </summary>
@ -246,19 +307,6 @@ namespace OpenSim.Region.Framework.Scenes
}
}
// /// <summary>
// /// The callback made when we request the asset for an object from the asset service.
// /// </summary>
// private void AssetReceived(string id, Object sender, AssetBase asset)
// {
// lock (this)
// {
// m_requestedObjectAsset = asset;
// m_waitingForObjectAsset = false;
// Monitor.Pulse(this);
// }
// }
/// <summary>
/// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps
/// stored in legacy format in part.DynAttrs
@ -362,19 +410,30 @@ namespace OpenSim.Region.Framework.Scenes
}
/// <summary>
/// Record the asset uuids embedded within the given script.
/// Record the asset uuids embedded within the given text (e.g. a script).
/// </summary>
/// <param name="scriptUuid"></param>
/// <param name="textAssetUuid"></param>
/// <param name="assetUuids">Dictionary in which to record the references</param>
private void GetTextEmbeddedAssetUuids(UUID embeddingAssetId, IDictionary<UUID, sbyte> assetUuids)
private void GetTextEmbeddedAssetUuids(UUID textAssetUuid, IDictionary<UUID, sbyte> assetUuids)
{
// m_log.DebugFormat("[ASSET GATHERER]: Getting assets for uuid references in asset {0}", embeddingAssetId);
AssetBase embeddingAsset = GetAsset(embeddingAssetId);
AssetBase textAsset = GetAsset(textAssetUuid);
if (null != embeddingAsset)
if (null != textAsset)
GetTextEmbeddedAssetUuids(textAsset, assetUuids);
}
/// <summary>
/// Record the asset uuids embedded within the given text (e.g. a script).
/// </summary>
/// <param name="textAsset"></param>
/// <param name="assetUuids">Dictionary in which to record the references</param>
private void GetTextEmbeddedAssetUuids(AssetBase textAsset, IDictionary<UUID, sbyte> assetUuids)
{
string script = Utils.BytesToString(embeddingAsset.Data);
// m_log.DebugFormat("[ASSET GATHERER]: Getting assets for uuid references in asset {0}", embeddingAssetId);
string script = Utils.BytesToString(textAsset.Data);
// m_log.DebugFormat("[ARCHIVER]: Script {0}", script);
MatchCollection uuidMatches = Util.PermissiveUUIDPattern.Matches(script);
// m_log.DebugFormat("[ARCHIVER]: Found {0} matches in text", uuidMatches.Count);
@ -389,7 +448,6 @@ namespace OpenSim.Region.Framework.Scenes
assetUuids[uuid] = (sbyte)AssetType.Unknown;
}
}
}
/// <summary>
/// Record the uuids referenced by the given wearable asset
@ -401,9 +459,18 @@ namespace OpenSim.Region.Framework.Scenes
AssetBase assetBase = GetAsset(wearableAssetUuid);
if (null != assetBase)
GetWearableAssetUuids(assetBase, assetUuids);
}
/// <summary>
/// Record the uuids referenced by the given wearable asset
/// </summary>
/// <param name="assetBase"></param>
/// <param name="assetUuids">Dictionary in which to record the references</param>
private void GetWearableAssetUuids(AssetBase assetBase, IDictionary<UUID, sbyte> assetUuids)
{
//m_log.Debug(new System.Text.ASCIIEncoding().GetString(bodypartAsset.Data));
AssetWearable wearableAsset = new AssetBodypart(wearableAssetUuid, assetBase.Data);
AssetWearable wearableAsset = new AssetBodypart(assetBase.FullID, assetBase.Data);
wearableAsset.Decode();
//m_log.DebugFormat(
@ -414,7 +481,6 @@ namespace OpenSim.Region.Framework.Scenes
assetUuids[uuid] = (sbyte)AssetType.Texture;
}
}
}
/// <summary>
/// Get all the asset uuids associated with a given object. This includes both those directly associated with
@ -425,11 +491,22 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="assetUuids"></param>
private void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary<UUID, sbyte> assetUuids)
{
AssetBase objectAsset = GetAsset(sceneObjectUuid);
AssetBase sceneObjectAsset = GetAsset(sceneObjectUuid);
if (null != objectAsset)
if (null != sceneObjectAsset)
GetSceneObjectAssetUuids(sceneObjectAsset, assetUuids);
}
/// <summary>
/// Get all the asset uuids associated with a given object. This includes both those directly associated with
/// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
/// within this object).
/// </summary>
/// <param name="sceneObjectAsset"></param>
/// <param name="assetUuids"></param>
private void GetSceneObjectAssetUuids(AssetBase sceneObjectAsset, IDictionary<UUID, sbyte> assetUuids)
{
string xml = Utils.BytesToString(objectAsset.Data);
string xml = Utils.BytesToString(sceneObjectAsset.Data);
CoalescedSceneObjects coa;
if (CoalescedSceneObjectsSerializer.TryFromXml(xml, out coa))
@ -445,7 +522,6 @@ namespace OpenSim.Region.Framework.Scenes
GatherAssetUuids(sog, assetUuids);
}
}
}
/// <summary>
/// Get the asset uuid associated with a gesture
@ -454,11 +530,21 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="assetUuids"></param>
private void GetGestureAssetUuids(UUID gestureUuid, IDictionary<UUID, sbyte> assetUuids)
{
AssetBase assetBase = GetAsset(gestureUuid);
if (null == assetBase)
AssetBase gestureAsset = GetAsset(gestureUuid);
if (null == gestureAsset)
return;
using (MemoryStream ms = new MemoryStream(assetBase.Data))
GetGestureAssetUuids(gestureAsset, assetUuids);
}
/// <summary>
/// Get the asset uuid associated with a gesture
/// </summary>
/// <param name="gestureAsset"></param>
/// <param name="assetUuids"></param>
private void GetGestureAssetUuids(AssetBase gestureAsset, IDictionary<UUID, sbyte> assetUuids)
{
using (MemoryStream ms = new MemoryStream(gestureAsset.Data))
using (StreamReader sr = new StreamReader(ms))
{
sr.ReadLine(); // Unknown (Version?)
@ -500,7 +586,15 @@ namespace OpenSim.Region.Framework.Scenes
if (null == assetBase)
return;
OSDMap mat = (OSDMap)OSDParser.DeserializeLLSDXml(assetBase.Data);
GetMaterialAssetUuids(assetBase, assetUuids);
}
/// <summary>
/// Get the asset uuid's referenced in a material.
/// </summary>
private void GetMaterialAssetUuids(AssetBase materialAsset, IDictionary<UUID, sbyte> assetUuids)
{
OSDMap mat = (OSDMap)OSDParser.DeserializeLLSDXml(materialAsset.Data);
UUID normMap = mat["NormMap"].AsUUID();
if (normMap != UUID.Zero)

View File

@ -51,7 +51,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
{
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>();
private List<Scene> m_scenes = new List<Scene>();
// private IAvatarFactoryModule m_avatarFactory;
public string Name { get { return "Appearance Information Module"; } }
@ -83,7 +84,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
// m_log.DebugFormat("[APPEARANCE INFO MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
lock (m_scenes)
m_scenes.Remove(scene.RegionInfo.RegionID);
m_scenes.Remove(scene);
}
public void RegionLoaded(Scene scene)
@ -91,7 +92,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
// m_log.DebugFormat("[APPEARANCE INFO MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
lock (m_scenes)
m_scenes[scene.RegionInfo.RegionID] = scene;
m_scenes.Add(scene);
scene.AddCommand(
"Users", this, "show appearance",
@ -140,6 +141,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
"If no avatar name is given then a general summary for all avatars in the scene is shown.\n"
+ "If an avatar name is given then specific information about current wearables is shown.",
HandleShowWearablesCommand);
scene.AddCommand(
"Users", this, "wearables check",
"wearables check <first-name> <last-name>",
"Check that the wearables of a given avatar in the scene are valid.",
"This currently checks that the wearable assets themselves and any assets referenced by them exist.",
HandleCheckWearablesCommand);
}
private void HandleSendAppearanceCommand(string module, string[] cmd)
@ -163,7 +171,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
lock (m_scenes)
{
foreach (Scene scene in m_scenes.Values)
foreach (Scene scene in m_scenes)
{
if (targetNameSupplied)
{
@ -215,7 +223,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
lock (m_scenes)
{
foreach (Scene scene in m_scenes.Values)
foreach (Scene scene in m_scenes)
{
if (targetNameSupplied)
{
@ -251,7 +259,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
lock (m_scenes)
{
foreach (Scene scene in m_scenes.Values)
foreach (Scene scene in m_scenes)
{
ScenePresence sp = scene.GetScenePresence(firstname, lastname);
if (sp != null && !sp.IsChildAgent)
@ -285,7 +293,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
lock (m_scenes)
{
foreach (Scene scene in m_scenes.Values)
foreach (Scene scene in m_scenes)
{
scene.ForEachRootScenePresence(
sp =>
@ -338,7 +346,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
{
lock (m_scenes)
{
foreach (Scene scene in m_scenes.Values)
foreach (Scene scene in m_scenes)
{
ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
if (sp != null && !sp.IsChildAgent)
@ -354,7 +362,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
lock (m_scenes)
{
foreach (Scene scene in m_scenes.Values)
foreach (Scene scene in m_scenes)
{
scene.ForEachRootScenePresence(
sp =>
@ -376,6 +384,76 @@ namespace OpenSim.Region.OptionalModules.Avatar.Appearance
MainConsole.Instance.Output(sb.ToString());
}
private void HandleCheckWearablesCommand(string module, string[] cmd)
{
if (cmd.Length != 4)
{
MainConsole.Instance.OutputFormat("Usage: wearables check <first-name> <last-name>");
return;
}
string firstname = cmd[2];
string lastname = cmd[3];
StringBuilder sb = new StringBuilder();
UuidGatherer uuidGatherer = new UuidGatherer(m_scenes[0].AssetService);
lock (m_scenes)
{
foreach (Scene scene in m_scenes)
{
ScenePresence sp = scene.GetScenePresence(firstname, lastname);
if (sp != null && !sp.IsChildAgent)
{
sb.AppendFormat("Wearables checks for {0}\n\n", sp.Name);
for (int i = (int)WearableType.Shape; i < (int)WearableType.Physics; i++)
{
AvatarWearable aw = sp.Appearance.Wearables[i];
if (aw.Count > 0)
{
sb.Append(Enum.GetName(typeof(WearableType), i));
sb.Append("\n");
for (int j = 0; j < aw.Count; j++)
{
WearableItem wi = aw[j];
ConsoleDisplayList cdl = new ConsoleDisplayList();
cdl.Indent = 2;
cdl.AddRow("Item UUID", wi.ItemID);
cdl.AddRow("Assets", "");
sb.Append(cdl.ToString());
Dictionary<UUID, sbyte> assetUuids = new Dictionary<UUID, sbyte>();
uuidGatherer.GatherAssetUuids(wi.AssetID, assetUuids);
string[] assetStrings
= Array.ConvertAll<UUID, string>(assetUuids.Keys.ToArray(), u => u.ToString());
bool[] existChecks = scene.AssetService.AssetsExist(assetStrings);
ConsoleDisplayTable cdt = new ConsoleDisplayTable();
cdt.Indent = 4;
cdt.AddColumn("Type", 10);
cdt.AddColumn("UUID", ConsoleDisplayUtil.UuidSize);
cdt.AddColumn("Found", 5);
for (int k = 0; k < existChecks.Length; k++)
cdt.AddRow((AssetType)assetUuids[new UUID(assetStrings[k])], assetStrings[k], existChecks[k] ? "yes" : "no");
sb.Append(cdt.ToString());
sb.Append("\n");
}
}
}
}
}
}
MainConsole.Instance.Output(sb.ToString());
}
private void AppendWearablesDetailReport(ScenePresence sp, StringBuilder sb)
{
sb.AppendFormat("\nWearables for {0}\n", sp.Name);