add more error handling

master
Christopher 2020-07-10 17:28:23 +02:00
parent 49cb60bd8a
commit 90bf8b7487
1 changed files with 43 additions and 25 deletions

View File

@ -74,49 +74,67 @@ namespace OpenSim.Modules.Appearance2Avatar
SceneObjectPart _host = m_scene.GetSceneObjectPart(hostID); SceneObjectPart _host = m_scene.GetSceneObjectPart(hostID);
ScenePresence sp = m_scene.GetScenePresence(UUID.Parse(targetAvatar)); ScenePresence sp = m_scene.GetScenePresence(UUID.Parse(targetAvatar));
if(sp != null) if(_host != null)
{ {
TaskInventoryItem notecardItem = _host.Inventory.GetInventoryItems().Find(X => X.Name == notecard); if (sp != null)
if(notecardItem != null)
{ {
if(notecardItem.Type != 7) TaskInventoryItem notecardItem = _host.Inventory.GetInventoryItems().Find(X => X.Name == notecard);
if (notecardItem != null)
{ {
m_log.Error("[" + Name + "] ERROR: Given item is not a notecard"); if (notecardItem.Type != 7)
throw new Exception("Given item is not a notecard."); {
return; m_log.Error("[" + Name + "] ERROR: Given item is not a notecard");
} throw new Exception("Given item is not a notecard.");
return;
}
AssetBase asset = m_scene.AssetService.Get(notecardItem.AssetID.ToString()); m_log.Info("[" + Name + "] Info: Fetch asset data for notecard.");
AssetBase asset = m_scene.AssetService.Get(notecardItem.AssetID.ToString());
if(asset != null) if (asset != null)
{ {
String _appearanceNotecard = new ASCIIEncoding().GetString(asset.Data); m_log.Info("[" + Name + "] Info: Convert notecard to string.");
String _appearanceNotecard = new ASCIIEncoding().GetString(asset.Data);
OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(_appearanceNotecard); m_log.Info("[" + Name + "] Info: Deserialize notecard.");
AvatarAppearance appearance = new AvatarAppearance(); OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(_appearanceNotecard);
appearance.Unpack(appearanceOsd); AvatarAppearance appearance = new AvatarAppearance();
appearance.Unpack(appearanceOsd);
m_log.Info("[" + Name + "] Info: Overwrite appearance");
sp.Appearance = appearance;
sp.TriggerScenePresenceUpdated();
m_scene.ForEachClient(
client =>
{
sp.SendFullUpdateToClient(client);
});
}
else
{
m_log.Error("[" + Name + "] ERROR: Cant get asset data for appearance notecard");
throw new Exception("Cant get asset data for appearance notecard");
}
sp.Appearance = appearance;
sp.TriggerScenePresenceUpdated();
} }
else else
{ {
m_log.Error("[" + Name + "] ERROR: Cant get asset data for appearance notecard"); m_log.Error("[" + Name + "] ERROR: Notecard not found in objekt inventory");
throw new Exception("Cant get asset data for appearance notecard"); throw new Exception("Notecard not found in objekt inventory");
} }
} }
else else
{ {
m_log.Error("[" + Name + "] ERROR: Notecard not found in objekt inventory"); m_log.Error("[" + Name + "] ERROR: Target not found in region");
throw new Exception("Notecard not found in objekt inventory"); throw new Exception("Target not found in region");
} }
} }
else else
{ {
m_log.Error("[" + Name + "] ERROR: Target not found in region"); m_log.Error("[" + Name + "] ERROR: Cant find objekt inworld");
throw new Exception("Target not found in region"); throw new Exception("Cant find objekt inworld");
} }
} }
} }