aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs104
1 files changed, 91 insertions, 13 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 154179c..07b36de 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -28,11 +28,16 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
31using System.Runtime.Remoting.Lifetime; 33using System.Runtime.Remoting.Lifetime;
32using System.Text; 34using System.Text;
33using System.Net; 35using System.Net;
34using System.Threading; 36using System.Threading;
37using System.Xml;
38using log4net;
35using OpenMetaverse; 39using OpenMetaverse;
40using OpenMetaverse.StructuredData;
36using Nini.Config; 41using Nini.Config;
37using OpenSim; 42using OpenSim;
38using OpenSim.Framework; 43using OpenSim.Framework;
@@ -119,6 +124,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
119 [Serializable] 124 [Serializable]
120 public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi 125 public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
121 { 126 {
127// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
128
122 internal IScriptEngine m_ScriptEngine; 129 internal IScriptEngine m_ScriptEngine;
123 internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there 130 internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there
124 internal SceneObjectPart m_host; 131 internal SceneObjectPart m_host;
@@ -1730,26 +1737,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1730 for (int i = 0; i < contents.Length; i++) 1737 for (int i = 0; i < contents.Length; i++)
1731 notecardData.Append((string)(contents.GetLSLStringItem(i) + "\n")); 1738 notecardData.Append((string)(contents.GetLSLStringItem(i) + "\n"));
1732 1739
1733 SaveNotecard(notecardName, notecardData.ToString()); 1740 SaveNotecard(notecardName, "Script generated notecard", notecardData.ToString(), false);
1734 } 1741 }
1735 1742
1736 /// <summary> 1743 /// <summary>
1737 /// Save a notecard to prim inventory. 1744 /// Save a notecard to prim inventory.
1738 /// </summary> 1745 /// </summary>
1739 /// <param name="notecardName"></param> 1746 /// <param name="name"></param>
1747 /// <param name="description">Description of notecard</param>
1740 /// <param name="notecardData"></param> 1748 /// <param name="notecardData"></param>
1749 /// <param name="forceSameName">
1750 /// If true, then if an item exists with the same name, it is replaced.
1751 /// If false, then a new item is created witha slightly different name (e.g. name 1)
1752 /// </param>
1741 /// <returns>Prim inventory item created.</returns> 1753 /// <returns>Prim inventory item created.</returns>
1742 protected TaskInventoryItem SaveNotecard(string notecardName, string notecardData) 1754 protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName)
1743 { 1755 {
1744 // Create new asset 1756 // Create new asset
1745 AssetBase asset = new AssetBase(UUID.Random(), notecardName, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString()); 1757 AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
1746 asset.Description = "Script Generated Notecard"; 1758 asset.Description = description;
1747 1759
1748 int textLength = notecardData.Length; 1760 int textLength = data.Length;
1749 notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " 1761 data
1750 + textLength.ToString() + "\n" + notecardData + "}\n"; 1762 = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
1763 + textLength.ToString() + "\n" + data + "}\n";
1751 1764
1752 asset.Data = Util.UTF8.GetBytes(notecardData); 1765 asset.Data = Util.UTF8.GetBytes(data);
1753 World.AssetService.Store(asset); 1766 World.AssetService.Store(asset);
1754 1767
1755 // Create Task Entry 1768 // Create Task Entry
@@ -1775,7 +1788,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1775 taskItem.PermsMask = 0; 1788 taskItem.PermsMask = 0;
1776 taskItem.AssetID = asset.FullID; 1789 taskItem.AssetID = asset.FullID;
1777 1790
1778 m_host.Inventory.AddInventoryItem(taskItem, false); 1791 if (forceSameName)
1792 m_host.Inventory.AddInventoryItemExclusive(taskItem, false);
1793 else
1794 m_host.Inventory.AddInventoryItem(taskItem, false);
1779 1795
1780 return taskItem; 1796 return taskItem;
1781 } 1797 }
@@ -1791,7 +1807,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1791 StringBuilder notecardData = new StringBuilder(); 1807 StringBuilder notecardData = new StringBuilder();
1792 1808
1793 for (int count = 0; count < NotecardCache.GetLines(assetID); count++) 1809 for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
1794 notecardData.Append(NotecardCache.GetLine(assetID, count, 255) + "\n"); 1810 {
1811 string line = NotecardCache.GetLine(assetID, count) + "\n";
1812
1813// m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
1814
1815 notecardData.Append(line);
1816 }
1795 1817
1796 return notecardData.ToString(); 1818 return notecardData.ToString();
1797 } 1819 }
@@ -1807,7 +1829,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1807 protected UUID CacheNotecard(string notecardNameOrUuid) 1829 protected UUID CacheNotecard(string notecardNameOrUuid)
1808 { 1830 {
1809 UUID assetID = UUID.Zero; 1831 UUID assetID = UUID.Zero;
1810 StringBuilder notecardData = new StringBuilder();
1811 1832
1812 if (!UUID.TryParse(notecardNameOrUuid, out assetID)) 1833 if (!UUID.TryParse(notecardNameOrUuid, out assetID))
1813 { 1834 {
@@ -1864,7 +1885,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1864 return "ERROR!"; 1885 return "ERROR!";
1865 } 1886 }
1866 1887
1867 return NotecardCache.GetLine(assetID, line, 255); 1888 return NotecardCache.GetLine(assetID, line);
1868 } 1889 }
1869 1890
1870 /// <summary> 1891 /// <summary>
@@ -2122,9 +2143,66 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2122 2143
2123 return new LSL_Key(x.ToString()); 2144 return new LSL_Key(x.ToString());
2124 } 2145 }
2146
2125 return new LSL_Key(UUID.Zero.ToString()); 2147 return new LSL_Key(UUID.Zero.ToString());
2126 } 2148 }
2127 2149
2150 public LSL_Key osNpcSaveAppearance(string avatar, string notecardName)
2151 {
2152 CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance");
2153
2154 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2155 IAvatarFactory appearanceModule = World.RequestModuleInterface<IAvatarFactory>();
2156
2157 if (npcModule != null && appearanceModule != null)
2158 {
2159 UUID avatarId = UUID.Zero;
2160 if (!UUID.TryParse(avatar, out avatarId))
2161 return new LSL_Key(UUID.Zero.ToString());
2162
2163 if (!npcModule.IsNPC(avatarId, m_host.ParentGroup.Scene))
2164 return new LSL_Key(UUID.Zero.ToString());
2165
2166 appearanceModule.SaveBakedTextures(avatarId);
2167 ScenePresence sp = m_host.ParentGroup.Scene.GetScenePresence(avatarId);
2168 OSDMap appearancePacked = sp.Appearance.Pack();
2169
2170 TaskInventoryItem item
2171 = SaveNotecard(notecardName, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true);
2172
2173 return new LSL_Key(item.AssetID.ToString());
2174 }
2175
2176 return new LSL_Key(UUID.Zero.ToString());
2177 }
2178
2179 public void osNpcLoadAppearance(string avatar, string notecardNameOrUuid)
2180 {
2181 CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance");
2182
2183 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2184
2185 if (npcModule != null)
2186 {
2187 UUID avatarId = UUID.Zero;
2188 if (!UUID.TryParse(avatar, out avatarId))
2189 return;
2190
2191 if (!npcModule.IsNPC(avatarId, m_host.ParentGroup.Scene))
2192 return;
2193
2194 string appearanceSerialized = LoadNotecard(notecardNameOrUuid);
2195 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
2196// OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
2197// Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
2198// Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a);
2199 AvatarAppearance appearance = new AvatarAppearance();
2200 appearance.Unpack(appearanceOsd);
2201
2202 npcModule.SetNPCAppearance(avatarId, appearance, m_host.ParentGroup.Scene);
2203 }
2204 }
2205
2128 public void osNpcMoveTo(LSL_Key npc, LSL_Vector position) 2206 public void osNpcMoveTo(LSL_Key npc, LSL_Vector position)
2129 { 2207 {
2130 CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo"); 2208 CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");