2020-07-10 15:06:27 +00:00
|
|
|
|
using log4net;
|
|
|
|
|
using Mono.Addins;
|
|
|
|
|
using Nini.Config;
|
|
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.StructuredData;
|
|
|
|
|
using OpenSim.Framework;
|
2020-07-10 15:49:14 +00:00
|
|
|
|
using OpenSim.Modules.Appearance2Avatar.helper;
|
2020-07-10 15:06:27 +00:00
|
|
|
|
using OpenSim.Region.Framework.Interfaces;
|
|
|
|
|
using OpenSim.Region.Framework.Scenes;
|
2020-07-10 16:06:44 +00:00
|
|
|
|
using OpenSim.Region.ScriptEngine.Interfaces;
|
|
|
|
|
using OpenSim.Region.ScriptEngine.Shared.Api;
|
|
|
|
|
using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
|
2020-07-10 15:06:27 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
[assembly: Addin("Appearance2Avatar", "0.1")]
|
|
|
|
|
[assembly: AddinDependency("OpenSim.Region.Framework", OpenSim.VersionInfo.VersionNumber)]
|
|
|
|
|
namespace OpenSim.Modules.Appearance2Avatar
|
|
|
|
|
{
|
|
|
|
|
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "Appearance2Avatar")]
|
|
|
|
|
|
2020-07-10 15:49:14 +00:00
|
|
|
|
public class Appearance2Avatar : INonSharedRegionModule
|
2020-07-10 15:06:27 +00:00
|
|
|
|
{
|
|
|
|
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
private IScriptModuleComms m_scriptModule = null;
|
2020-07-10 15:49:14 +00:00
|
|
|
|
public static Scene m_scene = null;
|
2020-07-10 17:50:36 +00:00
|
|
|
|
private IAssetCache m_assetCache = null;
|
2020-07-10 15:06:27 +00:00
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Appearance2Avatar"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Type ReplaceableInterface
|
|
|
|
|
{
|
|
|
|
|
get { return null; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddRegion(Scene scene)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Initialise(IConfigSource source)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegionLoaded(Scene scene)
|
|
|
|
|
{
|
|
|
|
|
m_scriptModule = scene.RequestModuleInterface<IScriptModuleComms>();
|
|
|
|
|
if (m_scriptModule != null)
|
|
|
|
|
{
|
2020-07-11 12:34:47 +00:00
|
|
|
|
m_scriptModule.RegisterScriptInvocation(this, "osRemoveAllAttachmentsFromAvatar");
|
2020-07-10 15:06:27 +00:00
|
|
|
|
m_scriptModule.RegisterScriptInvocation(this, "osAppearance2Avatar");
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 17:50:36 +00:00
|
|
|
|
m_assetCache = scene.RequestModuleInterface<IAssetCache>();
|
|
|
|
|
|
2020-07-10 15:06:27 +00:00
|
|
|
|
m_scene = scene;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveRegion(Scene scene)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 12:34:47 +00:00
|
|
|
|
[ScriptInvocation]
|
|
|
|
|
public void osRemoveAllAttachmentsFromAvatar(UUID hostID, UUID scriptID, String targetAvatar)
|
|
|
|
|
{
|
|
|
|
|
ScenePresence sp = m_scene.GetScenePresence(UUID.Parse(targetAvatar));
|
|
|
|
|
|
|
|
|
|
if (sp != null)
|
|
|
|
|
{
|
|
|
|
|
//Remove all attachments
|
|
|
|
|
List<SceneObjectGroup> _allAttachments = sp.GetAttachments();
|
|
|
|
|
foreach (SceneObjectGroup _attachment in _allAttachments)
|
|
|
|
|
m_scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, _attachment);
|
|
|
|
|
|
|
|
|
|
if (m_scene.AttachmentsModule != null)
|
|
|
|
|
m_scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, false);
|
|
|
|
|
|
|
|
|
|
//Remove current outfit from inventory
|
|
|
|
|
InventoryFolderBase _outfitFolder = m_scene.InventoryService.GetFolderForType(sp.UUID, FolderType.CurrentOutfit);
|
|
|
|
|
|
|
|
|
|
if (_outfitFolder != null)
|
|
|
|
|
{
|
|
|
|
|
InventoryCollection _outfitFolderContend = m_scene.InventoryService.GetFolderContent(sp.UUID, _outfitFolder.ID);
|
|
|
|
|
|
|
|
|
|
List<UUID> _itemIDs = new List<UUID>();
|
|
|
|
|
foreach (InventoryItemBase item in _outfitFolderContend.Items)
|
|
|
|
|
if (item.InvType == (int)AssetType.Object)
|
|
|
|
|
_itemIDs.Add(item.ID);
|
|
|
|
|
|
|
|
|
|
m_scene.InventoryService.DeleteItems(sp.UUID, _itemIDs);
|
|
|
|
|
m_scene.InventoryService.UpdateFolder(_outfitFolder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 15:06:27 +00:00
|
|
|
|
[ScriptInvocation]
|
2020-07-10 15:08:27 +00:00
|
|
|
|
public void osAppearance2Avatar(UUID hostID, UUID scriptID, String notecard, String targetAvatar)
|
2020-07-10 15:06:27 +00:00
|
|
|
|
{
|
|
|
|
|
SceneObjectPart _host = m_scene.GetSceneObjectPart(hostID);
|
|
|
|
|
ScenePresence sp = m_scene.GetScenePresence(UUID.Parse(targetAvatar));
|
|
|
|
|
|
2020-07-10 15:28:23 +00:00
|
|
|
|
if(_host != null)
|
2020-07-10 15:06:27 +00:00
|
|
|
|
{
|
2020-07-10 15:28:23 +00:00
|
|
|
|
if (sp != null)
|
2020-07-10 15:06:27 +00:00
|
|
|
|
{
|
2020-07-10 15:28:23 +00:00
|
|
|
|
TaskInventoryItem notecardItem = _host.Inventory.GetInventoryItems().Find(X => X.Name == notecard);
|
2020-07-10 15:14:16 +00:00
|
|
|
|
|
2020-07-10 15:28:23 +00:00
|
|
|
|
if (notecardItem != null)
|
2020-07-10 15:06:27 +00:00
|
|
|
|
{
|
2020-07-10 15:28:23 +00:00
|
|
|
|
if (notecardItem.Type != 7)
|
|
|
|
|
throw new Exception("Given item is not a notecard.");
|
|
|
|
|
|
|
|
|
|
m_log.Info("[" + Name + "] Info: Fetch asset data for notecard.");
|
2020-07-10 16:21:52 +00:00
|
|
|
|
NoteCardReader _ncReader = new NoteCardReader(m_scene, _host);
|
|
|
|
|
String noteCardContend = _ncReader.LoadNotecard(notecard);
|
2020-07-10 15:28:23 +00:00
|
|
|
|
|
2020-07-10 16:21:52 +00:00
|
|
|
|
if(noteCardContend != null)
|
2020-07-10 15:28:23 +00:00
|
|
|
|
{
|
2020-07-10 16:56:38 +00:00
|
|
|
|
//Remove all attachments
|
|
|
|
|
List<SceneObjectGroup> _allAttachments = sp.GetAttachments();
|
|
|
|
|
foreach (SceneObjectGroup _attachment in _allAttachments)
|
2020-07-10 17:22:23 +00:00
|
|
|
|
m_scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, _attachment);
|
2020-07-10 16:41:42 +00:00
|
|
|
|
|
2020-07-11 12:12:45 +00:00
|
|
|
|
if (m_scene.AttachmentsModule != null)
|
|
|
|
|
m_scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, false);
|
|
|
|
|
|
2020-07-10 18:21:16 +00:00
|
|
|
|
//Remove current outfit from inventory
|
|
|
|
|
InventoryFolderBase _outfitFolder = m_scene.InventoryService.GetFolderForType(sp.UUID, FolderType.CurrentOutfit);
|
|
|
|
|
|
|
|
|
|
if(_outfitFolder != null)
|
|
|
|
|
{
|
|
|
|
|
InventoryCollection _outfitFolderContend = m_scene.InventoryService.GetFolderContent(sp.UUID, _outfitFolder.ID);
|
|
|
|
|
|
|
|
|
|
List<UUID> _itemIDs = new List<UUID>();
|
2020-07-11 12:12:45 +00:00
|
|
|
|
foreach (InventoryItemBase item in _outfitFolderContend.Items)
|
2020-07-10 18:23:38 +00:00
|
|
|
|
if (item.InvType == (int)AssetType.Object)
|
|
|
|
|
_itemIDs.Add(item.ID);
|
2020-07-10 18:21:16 +00:00
|
|
|
|
|
|
|
|
|
m_scene.InventoryService.DeleteItems(sp.UUID, _itemIDs);
|
2020-07-10 18:27:08 +00:00
|
|
|
|
m_scene.InventoryService.UpdateFolder(_outfitFolder);
|
2020-07-10 18:21:16 +00:00
|
|
|
|
}
|
2020-07-10 17:38:06 +00:00
|
|
|
|
|
2020-07-10 16:56:38 +00:00
|
|
|
|
//Load Appearance
|
2020-07-10 16:21:52 +00:00
|
|
|
|
OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(noteCardContend);
|
2020-07-10 17:38:06 +00:00
|
|
|
|
AvatarAppearance _appearance = new AvatarAppearance(appearanceOsd);
|
2020-07-11 12:12:45 +00:00
|
|
|
|
AvatarAppearance newAppearance = new AvatarAppearance(_appearance, true);
|
|
|
|
|
sp.Appearance = newAppearance;
|
2020-07-10 18:21:16 +00:00
|
|
|
|
|
2020-07-10 17:22:23 +00:00
|
|
|
|
//Send Update
|
2020-07-10 16:41:42 +00:00
|
|
|
|
m_log.Info("[" + Name + "] Info: Send update to all clients");
|
2020-07-11 12:12:45 +00:00
|
|
|
|
m_scene.AvatarFactory.SendAppearance(sp.UUID);
|
2020-07-10 15:28:23 +00:00
|
|
|
|
}
|
2020-07-10 15:06:27 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-07-10 15:28:23 +00:00
|
|
|
|
m_log.Error("[" + Name + "] ERROR: Notecard not found in objekt inventory");
|
|
|
|
|
throw new Exception("Notecard not found in objekt inventory");
|
2020-07-10 15:06:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-07-10 15:28:23 +00:00
|
|
|
|
m_log.Error("[" + Name + "] ERROR: Target not found in region");
|
|
|
|
|
throw new Exception("Target not found in region");
|
2020-07-10 15:06:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-07-10 15:28:23 +00:00
|
|
|
|
m_log.Error("[" + Name + "] ERROR: Cant find objekt inworld");
|
|
|
|
|
throw new Exception("Cant find objekt inworld");
|
2020-07-10 15:06:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|