151 lines
5.0 KiB
C#
151 lines
5.0 KiB
C#
using log4net;
|
|
using Mono.Addins;
|
|
using Nini.Config;
|
|
using OpenMetaverse;
|
|
using OpenMetaverse.StructuredData;
|
|
using OpenSim.Framework;
|
|
using OpenSim.Modules.Appearance2Avatar.helper;
|
|
using OpenSim.Region.Framework.Interfaces;
|
|
using OpenSim.Region.Framework.Scenes;
|
|
using OpenSim.Region.ScriptEngine.Interfaces;
|
|
using OpenSim.Region.ScriptEngine.Shared.Api;
|
|
using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
|
|
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")]
|
|
|
|
public class Appearance2Avatar : INonSharedRegionModule
|
|
{
|
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
private IScriptModuleComms m_scriptModule = null;
|
|
public static Scene m_scene = null;
|
|
|
|
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)
|
|
{
|
|
m_scriptModule.RegisterScriptInvocation(this, "osAppearance2Avatar");
|
|
}
|
|
|
|
m_scene = scene;
|
|
}
|
|
|
|
public void RemoveRegion(Scene scene)
|
|
{
|
|
|
|
}
|
|
|
|
protected string LoadNotecard(SceneObjectPart host, String notecardname)
|
|
{
|
|
IScriptEngine wComm = m_scene.RequestModuleInterface<IScriptEngine>();
|
|
|
|
IOSSL_Api _api = (IOSSL_Api)wComm.GetApi(host.UUID, "LSL");
|
|
return _api.osGetNotecard(notecardname);
|
|
}
|
|
|
|
[ScriptInvocation]
|
|
public void osAppearance2Avatar(UUID hostID, UUID scriptID, String notecard, String targetAvatar)
|
|
{
|
|
SceneObjectPart _host = m_scene.GetSceneObjectPart(hostID);
|
|
ScenePresence sp = m_scene.GetScenePresence(UUID.Parse(targetAvatar));
|
|
|
|
if(_host != null)
|
|
{
|
|
if (sp != null)
|
|
{
|
|
TaskInventoryItem notecardItem = _host.Inventory.GetInventoryItems().Find(X => X.Name == notecard);
|
|
|
|
if (notecardItem != null)
|
|
{
|
|
if (notecardItem.Type != 7)
|
|
{
|
|
throw new Exception("Given item is not a notecard.");
|
|
return;
|
|
}
|
|
|
|
m_log.Info("[" + Name + "] Info: Fetch asset data for notecard.");
|
|
String asset = LoadNotecard(_host, notecard);
|
|
|
|
if (asset != null)
|
|
{
|
|
m_log.Info(asset);
|
|
|
|
m_log.Info("[" + Name + "] Info: Deserialize notecard.");
|
|
OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(asset);
|
|
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");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
m_log.Error("[" + Name + "] ERROR: Notecard not found in objekt inventory");
|
|
throw new Exception("Notecard not found in objekt inventory");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_log.Error("[" + Name + "] ERROR: Target not found in region");
|
|
throw new Exception("Target not found in region");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_log.Error("[" + Name + "] ERROR: Cant find objekt inworld");
|
|
throw new Exception("Cant find objekt inworld");
|
|
}
|
|
}
|
|
}
|
|
}
|