diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 593 |
1 files changed, 429 insertions, 164 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 6d2efce..9ec8a42 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 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.IO; | ||
32 | using System.Reflection; | ||
31 | using System.Runtime.Remoting.Lifetime; | 33 | using System.Runtime.Remoting.Lifetime; |
32 | using System.Text; | 34 | using System.Text; |
33 | using System.Net; | 35 | using System.Net; |
34 | using System.Threading; | 36 | using System.Threading; |
37 | using System.Xml; | ||
38 | using log4net; | ||
35 | using OpenMetaverse; | 39 | using OpenMetaverse; |
40 | using OpenMetaverse.StructuredData; | ||
36 | using Nini.Config; | 41 | using Nini.Config; |
37 | using OpenSim; | 42 | using OpenSim; |
38 | using OpenSim.Framework; | 43 | using 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; |
@@ -357,20 +364,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
357 | System.Threading.Thread.Sleep(delay); | 364 | System.Threading.Thread.Sleep(delay); |
358 | } | 365 | } |
359 | 366 | ||
360 | // | ||
361 | // OpenSim functions | ||
362 | // | ||
363 | public LSL_Integer osSetTerrainHeight(int x, int y, double val) | 367 | public LSL_Integer osSetTerrainHeight(int x, int y, double val) |
364 | { | 368 | { |
365 | CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight"); | 369 | CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight"); |
366 | return SetTerrainHeight(x, y, val); | 370 | return SetTerrainHeight(x, y, val); |
367 | } | 371 | } |
372 | |||
368 | public LSL_Integer osTerrainSetHeight(int x, int y, double val) | 373 | public LSL_Integer osTerrainSetHeight(int x, int y, double val) |
369 | { | 374 | { |
370 | CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight"); | 375 | CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight"); |
371 | OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight"); | 376 | OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight"); |
372 | return SetTerrainHeight(x, y, val); | 377 | return SetTerrainHeight(x, y, val); |
373 | } | 378 | } |
379 | |||
374 | private LSL_Integer SetTerrainHeight(int x, int y, double val) | 380 | private LSL_Integer SetTerrainHeight(int x, int y, double val) |
375 | { | 381 | { |
376 | m_host.AddScriptLPS(1); | 382 | m_host.AddScriptLPS(1); |
@@ -393,12 +399,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
393 | CheckThreatLevel(ThreatLevel.None, "osGetTerrainHeight"); | 399 | CheckThreatLevel(ThreatLevel.None, "osGetTerrainHeight"); |
394 | return GetTerrainHeight(x, y); | 400 | return GetTerrainHeight(x, y); |
395 | } | 401 | } |
402 | |||
396 | public LSL_Float osTerrainGetHeight(int x, int y) | 403 | public LSL_Float osTerrainGetHeight(int x, int y) |
397 | { | 404 | { |
398 | CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight"); | 405 | CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight"); |
399 | OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight"); | 406 | OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight"); |
400 | return GetTerrainHeight(x, y); | 407 | return GetTerrainHeight(x, y); |
401 | } | 408 | } |
409 | |||
402 | private LSL_Float GetTerrainHeight(int x, int y) | 410 | private LSL_Float GetTerrainHeight(int x, int y) |
403 | { | 411 | { |
404 | m_host.AddScriptLPS(1); | 412 | m_host.AddScriptLPS(1); |
@@ -673,13 +681,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
673 | CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater"); | 681 | CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater"); |
674 | 682 | ||
675 | m_host.AddScriptLPS(1); | 683 | m_host.AddScriptLPS(1); |
676 | if (m_host.ParentGroup != null) | 684 | |
677 | { | 685 | m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN); |
678 | if (m_host.ParentGroup.RootPart != null) | ||
679 | { | ||
680 | m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN); | ||
681 | } | ||
682 | } | ||
683 | } | 686 | } |
684 | 687 | ||
685 | // Teleport functions | 688 | // Teleport functions |
@@ -870,7 +873,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
870 | ScenePresence target = (ScenePresence)World.Entities[avatarID]; | 873 | ScenePresence target = (ScenePresence)World.Entities[avatarID]; |
871 | if (target != null) | 874 | if (target != null) |
872 | { | 875 | { |
873 | UUID animID=UUID.Zero; | 876 | UUID animID = UUID.Zero; |
874 | m_host.TaskInventory.LockItemsForRead(true); | 877 | m_host.TaskInventory.LockItemsForRead(true); |
875 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 878 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) |
876 | { | 879 | { |
@@ -1028,6 +1031,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1028 | drawList += "PenColor " + color + "; "; | 1031 | drawList += "PenColor " + color + "; "; |
1029 | return drawList; | 1032 | return drawList; |
1030 | } | 1033 | } |
1034 | |||
1031 | // Deprecated | 1035 | // Deprecated |
1032 | public string osSetPenColour(string drawList, string colour) | 1036 | public string osSetPenColour(string drawList, string colour) |
1033 | { | 1037 | { |
@@ -1189,11 +1193,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1189 | OSSLDeprecated("osSunGetParam", "osGetSunParam"); | 1193 | OSSLDeprecated("osSunGetParam", "osGetSunParam"); |
1190 | return GetSunParam(param); | 1194 | return GetSunParam(param); |
1191 | } | 1195 | } |
1196 | |||
1192 | public double osGetSunParam(string param) | 1197 | public double osGetSunParam(string param) |
1193 | { | 1198 | { |
1194 | CheckThreatLevel(ThreatLevel.None, "osGetSunParam"); | 1199 | CheckThreatLevel(ThreatLevel.None, "osGetSunParam"); |
1195 | return GetSunParam(param); | 1200 | return GetSunParam(param); |
1196 | } | 1201 | } |
1202 | |||
1197 | private double GetSunParam(string param) | 1203 | private double GetSunParam(string param) |
1198 | { | 1204 | { |
1199 | m_host.AddScriptLPS(1); | 1205 | m_host.AddScriptLPS(1); |
@@ -1215,11 +1221,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1215 | OSSLDeprecated("osSunSetParam", "osSetSunParam"); | 1221 | OSSLDeprecated("osSunSetParam", "osSetSunParam"); |
1216 | SetSunParam(param, value); | 1222 | SetSunParam(param, value); |
1217 | } | 1223 | } |
1224 | |||
1218 | public void osSetSunParam(string param, double value) | 1225 | public void osSetSunParam(string param, double value) |
1219 | { | 1226 | { |
1220 | CheckThreatLevel(ThreatLevel.None, "osSetSunParam"); | 1227 | CheckThreatLevel(ThreatLevel.None, "osSetSunParam"); |
1221 | SetSunParam(param, value); | 1228 | SetSunParam(param, value); |
1222 | } | 1229 | } |
1230 | |||
1223 | private void SetSunParam(string param, double value) | 1231 | private void SetSunParam(string param, double value) |
1224 | { | 1232 | { |
1225 | m_host.AddScriptLPS(1); | 1233 | m_host.AddScriptLPS(1); |
@@ -1229,10 +1237,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1229 | { | 1237 | { |
1230 | module.SetSunParameter(param, value); | 1238 | module.SetSunParameter(param, value); |
1231 | } | 1239 | } |
1232 | |||
1233 | } | 1240 | } |
1234 | 1241 | ||
1235 | |||
1236 | public string osWindActiveModelPluginName() | 1242 | public string osWindActiveModelPluginName() |
1237 | { | 1243 | { |
1238 | CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName"); | 1244 | CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName"); |
@@ -1311,12 +1317,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1311 | OSSLDeprecated(functionName, "osSetParcelDetails"); | 1317 | OSSLDeprecated(functionName, "osSetParcelDetails"); |
1312 | SetParcelDetails(pos, rules, functionName); | 1318 | SetParcelDetails(pos, rules, functionName); |
1313 | } | 1319 | } |
1320 | |||
1314 | public void osSetParcelDetails(LSL_Vector pos, LSL_List rules) | 1321 | public void osSetParcelDetails(LSL_Vector pos, LSL_List rules) |
1315 | { | 1322 | { |
1316 | const string functionName = "osSetParcelDetails"; | 1323 | const string functionName = "osSetParcelDetails"; |
1317 | CheckThreatLevel(ThreatLevel.High, functionName); | 1324 | CheckThreatLevel(ThreatLevel.High, functionName); |
1318 | SetParcelDetails(pos, rules, functionName); | 1325 | SetParcelDetails(pos, rules, functionName); |
1319 | } | 1326 | } |
1327 | |||
1320 | private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName) | 1328 | private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName) |
1321 | { | 1329 | { |
1322 | m_host.AddScriptLPS(1); | 1330 | m_host.AddScriptLPS(1); |
@@ -1436,8 +1444,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1436 | voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID); | 1444 | voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID); |
1437 | else | 1445 | else |
1438 | OSSLError("osSetParcelSIPAddress: No voice module enabled for this land"); | 1446 | OSSLError("osSetParcelSIPAddress: No voice module enabled for this land"); |
1439 | |||
1440 | |||
1441 | } | 1447 | } |
1442 | 1448 | ||
1443 | public string osGetScriptEngineName() | 1449 | public string osGetScriptEngineName() |
@@ -1690,8 +1696,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1690 | return jsondata; | 1696 | return jsondata; |
1691 | } | 1697 | } |
1692 | 1698 | ||
1693 | // send a message to to object identified by the given UUID, a script in the object must implement the dataserver function | 1699 | /// <summary> |
1694 | // the dataserver function is passed the ID of the calling function and a string message | 1700 | /// Send a message to to object identified by the given UUID |
1701 | /// </summary> | ||
1702 | /// <remarks> | ||
1703 | /// A script in the object must implement the dataserver function | ||
1704 | /// the dataserver function is passed the ID of the calling function and a string message | ||
1705 | /// </remarks> | ||
1706 | /// <param name="objectUUID"></param> | ||
1707 | /// <param name="message"></param> | ||
1695 | public void osMessageObject(LSL_Key objectUUID, string message) | 1708 | public void osMessageObject(LSL_Key objectUUID, string message) |
1696 | { | 1709 | { |
1697 | CheckThreatLevel(ThreatLevel.Low, "osMessageObject"); | 1710 | CheckThreatLevel(ThreatLevel.Low, "osMessageObject"); |
@@ -1706,34 +1719,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1706 | "dataserver", resobj, new DetectParams[0])); | 1719 | "dataserver", resobj, new DetectParams[0])); |
1707 | } | 1720 | } |
1708 | 1721 | ||
1709 | 1722 | /// <summary> | |
1710 | // This needs ThreatLevel high. It is an excellent griefer tool, | 1723 | /// Write a notecard directly to the prim's inventory. |
1711 | // In a loop, it can cause asset bloat and DOS levels of asset | 1724 | /// </summary> |
1712 | // writes. | 1725 | /// <remarks> |
1713 | // | 1726 | /// This needs ThreatLevel high. It is an excellent griefer tool, |
1727 | /// In a loop, it can cause asset bloat and DOS levels of asset | ||
1728 | /// writes. | ||
1729 | /// </remarks> | ||
1730 | /// <param name="notecardName">The name of the notecard to write.</param> | ||
1731 | /// <param name="contents">The contents of the notecard.</param> | ||
1714 | public void osMakeNotecard(string notecardName, LSL_Types.list contents) | 1732 | public void osMakeNotecard(string notecardName, LSL_Types.list contents) |
1715 | { | 1733 | { |
1716 | CheckThreatLevel(ThreatLevel.High, "osMakeNotecard"); | 1734 | CheckThreatLevel(ThreatLevel.High, "osMakeNotecard"); |
1717 | m_host.AddScriptLPS(1); | 1735 | m_host.AddScriptLPS(1); |
1718 | 1736 | ||
1719 | // Create new asset | 1737 | StringBuilder notecardData = new StringBuilder(); |
1720 | AssetBase asset = new AssetBase(UUID.Random(), notecardName, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString()); | ||
1721 | asset.Description = "Script Generated Notecard"; | ||
1722 | string notecardData = String.Empty; | ||
1723 | 1738 | ||
1724 | for (int i = 0; i < contents.Length; i++) { | 1739 | for (int i = 0; i < contents.Length; i++) |
1725 | notecardData += contents.GetLSLStringItem(i) + "\n"; | 1740 | notecardData.Append((string)(contents.GetLSLStringItem(i) + "\n")); |
1726 | } | 1741 | |
1742 | SaveNotecard(notecardName, "Script generated notecard", notecardData.ToString(), false); | ||
1743 | } | ||
1727 | 1744 | ||
1728 | int textLength = notecardData.Length; | 1745 | /// <summary> |
1729 | notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " | 1746 | /// Save a notecard to prim inventory. |
1730 | + textLength.ToString() + "\n" + notecardData + "}\n"; | 1747 | /// </summary> |
1748 | /// <param name="name"></param> | ||
1749 | /// <param name="description">Description of notecard</param> | ||
1750 | /// <param name="notecardData"></param> | ||
1751 | /// <param name="forceSameName"> | ||
1752 | /// If true, then if an item exists with the same name, it is replaced. | ||
1753 | /// If false, then a new item is created witha slightly different name (e.g. name 1) | ||
1754 | /// </param> | ||
1755 | /// <returns>Prim inventory item created.</returns> | ||
1756 | protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName) | ||
1757 | { | ||
1758 | // Create new asset | ||
1759 | AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString()); | ||
1760 | asset.Description = description; | ||
1761 | |||
1762 | int textLength = data.Length; | ||
1763 | data | ||
1764 | = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " | ||
1765 | + textLength.ToString() + "\n" + data + "}\n"; | ||
1731 | 1766 | ||
1732 | asset.Data = Util.UTF8.GetBytes(notecardData); | 1767 | asset.Data = Util.UTF8.GetBytes(data); |
1733 | World.AssetService.Store(asset); | 1768 | World.AssetService.Store(asset); |
1734 | 1769 | ||
1735 | // Create Task Entry | 1770 | // Create Task Entry |
1736 | TaskInventoryItem taskItem=new TaskInventoryItem(); | 1771 | TaskInventoryItem taskItem = new TaskInventoryItem(); |
1737 | 1772 | ||
1738 | taskItem.ResetIDs(m_host.UUID); | 1773 | taskItem.ResetIDs(m_host.UUID); |
1739 | taskItem.ParentID = m_host.UUID; | 1774 | taskItem.ParentID = m_host.UUID; |
@@ -1755,29 +1790,54 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1755 | taskItem.PermsMask = 0; | 1790 | taskItem.PermsMask = 0; |
1756 | taskItem.AssetID = asset.FullID; | 1791 | taskItem.AssetID = asset.FullID; |
1757 | 1792 | ||
1758 | m_host.Inventory.AddInventoryItem(taskItem, false); | 1793 | if (forceSameName) |
1794 | m_host.Inventory.AddInventoryItemExclusive(taskItem, false); | ||
1795 | else | ||
1796 | m_host.Inventory.AddInventoryItem(taskItem, false); | ||
1797 | |||
1798 | return taskItem; | ||
1759 | } | 1799 | } |
1760 | 1800 | ||
1801 | /// <summary> | ||
1802 | /// Load the notecard data found at the given prim inventory item name or asset uuid. | ||
1803 | /// </summary> | ||
1804 | /// <param name="notecardNameOrUuid"></param> | ||
1805 | /// <returns>The text loaded. Null if no notecard was found.</returns> | ||
1806 | protected string LoadNotecard(string notecardNameOrUuid) | ||
1807 | { | ||
1808 | UUID assetID = CacheNotecard(notecardNameOrUuid); | ||
1809 | StringBuilder notecardData = new StringBuilder(); | ||
1761 | 1810 | ||
1762 | /*Instead of using the LSL Dataserver event to pull notecard data, | 1811 | for (int count = 0; count < NotecardCache.GetLines(assetID); count++) |
1763 | this will simply read the requested line and return its data as a string. | 1812 | { |
1813 | string line = NotecardCache.GetLine(assetID, count) + "\n"; | ||
1764 | 1814 | ||
1765 | Warning - due to the synchronous method this function uses to fetch assets, its use | 1815 | // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line); |
1766 | may be dangerous and unreliable while running in grid mode. | 1816 | |
1767 | */ | 1817 | notecardData.Append(line); |
1768 | public string osGetNotecardLine(string name, int line) | 1818 | } |
1769 | { | 1819 | |
1770 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); | 1820 | return notecardData.ToString(); |
1771 | m_host.AddScriptLPS(1); | 1821 | } |
1772 | 1822 | ||
1823 | /// <summary> | ||
1824 | /// Cache a notecard's contents. | ||
1825 | /// </summary> | ||
1826 | /// <param name="notecardNameOrUuid"></param> | ||
1827 | /// <returns> | ||
1828 | /// The asset id of the notecard, which is used for retrieving the cached data. | ||
1829 | /// UUID.Zero if no asset could be found. | ||
1830 | /// </returns> | ||
1831 | protected UUID CacheNotecard(string notecardNameOrUuid) | ||
1832 | { | ||
1773 | UUID assetID = UUID.Zero; | 1833 | UUID assetID = UUID.Zero; |
1774 | 1834 | ||
1775 | if (!UUID.TryParse(name, out assetID)) | 1835 | if (!UUID.TryParse(notecardNameOrUuid, out assetID)) |
1776 | { | 1836 | { |
1777 | m_host.TaskInventory.LockItemsForRead(true); | 1837 | m_host.TaskInventory.LockItemsForRead(true); |
1778 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 1838 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) |
1779 | { | 1839 | { |
1780 | if (item.Type == 7 && item.Name == name) | 1840 | if (item.Type == 7 && item.Name == notecardNameOrUuid) |
1781 | { | 1841 | { |
1782 | assetID = item.AssetID; | 1842 | assetID = item.AssetID; |
1783 | } | 1843 | } |
@@ -1786,118 +1846,100 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1786 | } | 1846 | } |
1787 | 1847 | ||
1788 | if (assetID == UUID.Zero) | 1848 | if (assetID == UUID.Zero) |
1789 | { | 1849 | return UUID.Zero; |
1790 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1791 | return "ERROR!"; | ||
1792 | } | ||
1793 | 1850 | ||
1794 | if (!NotecardCache.IsCached(assetID)) | 1851 | if (!NotecardCache.IsCached(assetID)) |
1795 | { | 1852 | { |
1796 | AssetBase a = World.AssetService.Get(assetID.ToString()); | 1853 | AssetBase a = World.AssetService.Get(assetID.ToString()); |
1797 | if (a != null) | ||
1798 | { | ||
1799 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | ||
1800 | string data = enc.GetString(a.Data); | ||
1801 | NotecardCache.Cache(assetID, data); | ||
1802 | } | ||
1803 | else | ||
1804 | { | ||
1805 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1806 | return "ERROR!"; | ||
1807 | } | ||
1808 | }; | ||
1809 | 1854 | ||
1810 | return NotecardCache.GetLine(assetID, line, 255); | 1855 | if (a == null) |
1856 | return UUID.Zero; | ||
1811 | 1857 | ||
1858 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | ||
1859 | string data = enc.GetString(a.Data); | ||
1860 | NotecardCache.Cache(assetID, data); | ||
1861 | }; | ||
1812 | 1862 | ||
1863 | return assetID; | ||
1813 | } | 1864 | } |
1814 | 1865 | ||
1815 | /*Instead of using the LSL Dataserver event to pull notecard data line by line, | 1866 | /// <summary> |
1816 | this will simply read the entire notecard and return its data as a string. | 1867 | /// Directly get an entire notecard at once. |
1868 | /// </summary> | ||
1869 | /// <remarks> | ||
1870 | /// Instead of using the LSL Dataserver event to pull notecard data | ||
1871 | /// this will simply read the entire notecard and return its data as a string. | ||
1872 | /// | ||
1873 | /// Warning - due to the synchronous method this function uses to fetch assets, its use | ||
1874 | /// may be dangerous and unreliable while running in grid mode. | ||
1875 | /// </remarks> | ||
1876 | /// <param name="name">Name of the notecard or its asset id</param> | ||
1877 | /// <param name="line">The line number to read. The first line is line 0</param> | ||
1878 | /// <returns>Notecard line</returns> | ||
1879 | public string osGetNotecardLine(string name, int line) | ||
1880 | { | ||
1881 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); | ||
1882 | m_host.AddScriptLPS(1); | ||
1817 | 1883 | ||
1818 | Warning - due to the synchronous method this function uses to fetch assets, its use | 1884 | UUID assetID = CacheNotecard(name); |
1819 | may be dangerous and unreliable while running in grid mode. | ||
1820 | */ | ||
1821 | 1885 | ||
1886 | if (assetID == UUID.Zero) | ||
1887 | { | ||
1888 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1889 | return "ERROR!"; | ||
1890 | } | ||
1891 | |||
1892 | return NotecardCache.GetLine(assetID, line); | ||
1893 | } | ||
1894 | |||
1895 | /// <summary> | ||
1896 | /// Get an entire notecard at once. | ||
1897 | /// </summary> | ||
1898 | /// <remarks> | ||
1899 | /// Instead of using the LSL Dataserver event to pull notecard data line by line, | ||
1900 | /// this will simply read the entire notecard and return its data as a string. | ||
1901 | /// | ||
1902 | /// Warning - due to the synchronous method this function uses to fetch assets, its use | ||
1903 | /// may be dangerous and unreliable while running in grid mode. | ||
1904 | /// </remarks> | ||
1905 | /// <param name="name">Name of the notecard or its asset id</param> | ||
1906 | /// <returns>Notecard text</returns> | ||
1822 | public string osGetNotecard(string name) | 1907 | public string osGetNotecard(string name) |
1823 | { | 1908 | { |
1824 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard"); | 1909 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard"); |
1825 | m_host.AddScriptLPS(1); | 1910 | m_host.AddScriptLPS(1); |
1826 | 1911 | ||
1827 | UUID assetID = UUID.Zero; | 1912 | string text = LoadNotecard(name); |
1828 | string NotecardData = ""; | ||
1829 | 1913 | ||
1830 | if (!UUID.TryParse(name, out assetID)) | 1914 | if (text == null) |
1831 | { | ||
1832 | m_host.TaskInventory.LockItemsForRead(true); | ||
1833 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
1834 | { | ||
1835 | if (item.Type == 7 && item.Name == name) | ||
1836 | { | ||
1837 | assetID = item.AssetID; | ||
1838 | } | ||
1839 | } | ||
1840 | m_host.TaskInventory.LockItemsForRead(false); | ||
1841 | } | ||
1842 | |||
1843 | if (assetID == UUID.Zero) | ||
1844 | { | 1915 | { |
1845 | OSSLShoutError("Notecard '" + name + "' could not be found."); | 1916 | OSSLShoutError("Notecard '" + name + "' could not be found."); |
1846 | return "ERROR!"; | 1917 | return "ERROR!"; |
1847 | } | 1918 | } |
1848 | 1919 | else | |
1849 | if (!NotecardCache.IsCached(assetID)) | ||
1850 | { | ||
1851 | AssetBase a = World.AssetService.Get(assetID.ToString()); | ||
1852 | if (a != null) | ||
1853 | { | ||
1854 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | ||
1855 | string data = enc.GetString(a.Data); | ||
1856 | NotecardCache.Cache(assetID, data); | ||
1857 | } | ||
1858 | else | ||
1859 | { | ||
1860 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1861 | return "ERROR!"; | ||
1862 | } | ||
1863 | }; | ||
1864 | |||
1865 | for (int count = 0; count < NotecardCache.GetLines(assetID); count++) | ||
1866 | { | 1920 | { |
1867 | NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n"; | 1921 | return text; |
1868 | } | 1922 | } |
1869 | |||
1870 | return NotecardData; | ||
1871 | |||
1872 | |||
1873 | } | 1923 | } |
1874 | 1924 | ||
1875 | /*Instead of using the LSL Dataserver event to pull notecard data, | 1925 | /// <summary> |
1876 | this will simply read the number of note card lines and return this data as an integer. | 1926 | /// Get the number of lines in the given notecard. |
1877 | 1927 | /// </summary> | |
1878 | Warning - due to the synchronous method this function uses to fetch assets, its use | 1928 | /// <remarks> |
1879 | may be dangerous and unreliable while running in grid mode. | 1929 | /// Instead of using the LSL Dataserver event to pull notecard data, |
1880 | */ | 1930 | /// this will simply read the number of note card lines and return this data as an integer. |
1881 | 1931 | /// | |
1932 | /// Warning - due to the synchronous method this function uses to fetch assets, its use | ||
1933 | /// may be dangerous and unreliable while running in grid mode. | ||
1934 | /// </remarks> | ||
1935 | /// <param name="name">Name of the notecard or its asset id</param> | ||
1936 | /// <returns></returns> | ||
1882 | public int osGetNumberOfNotecardLines(string name) | 1937 | public int osGetNumberOfNotecardLines(string name) |
1883 | { | 1938 | { |
1884 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines"); | 1939 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines"); |
1885 | m_host.AddScriptLPS(1); | 1940 | m_host.AddScriptLPS(1); |
1886 | 1941 | ||
1887 | UUID assetID = UUID.Zero; | 1942 | UUID assetID = CacheNotecard(name); |
1888 | |||
1889 | if (!UUID.TryParse(name, out assetID)) | ||
1890 | { | ||
1891 | m_host.TaskInventory.LockItemsForRead(true); | ||
1892 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
1893 | { | ||
1894 | if (item.Type == 7 && item.Name == name) | ||
1895 | { | ||
1896 | assetID = item.AssetID; | ||
1897 | } | ||
1898 | } | ||
1899 | m_host.TaskInventory.LockItemsForRead(false); | ||
1900 | } | ||
1901 | 1943 | ||
1902 | if (assetID == UUID.Zero) | 1944 | if (assetID == UUID.Zero) |
1903 | { | 1945 | { |
@@ -1905,25 +1947,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1905 | return -1; | 1947 | return -1; |
1906 | } | 1948 | } |
1907 | 1949 | ||
1908 | if (!NotecardCache.IsCached(assetID)) | ||
1909 | { | ||
1910 | AssetBase a = World.AssetService.Get(assetID.ToString()); | ||
1911 | if (a != null) | ||
1912 | { | ||
1913 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | ||
1914 | string data = enc.GetString(a.Data); | ||
1915 | NotecardCache.Cache(assetID, data); | ||
1916 | } | ||
1917 | else | ||
1918 | { | ||
1919 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1920 | return -1; | ||
1921 | } | ||
1922 | }; | ||
1923 | |||
1924 | return NotecardCache.GetLines(assetID); | 1950 | return NotecardCache.GetLines(assetID); |
1925 | |||
1926 | |||
1927 | } | 1951 | } |
1928 | 1952 | ||
1929 | public string osAvatarName2Key(string firstname, string lastname) | 1953 | public string osAvatarName2Key(string firstname, string lastname) |
@@ -1962,15 +1986,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1962 | { | 1986 | { |
1963 | return ""; | 1987 | return ""; |
1964 | } | 1988 | } |
1965 | |||
1966 | } | 1989 | } |
1967 | 1990 | ||
1991 | /// <summary> | ||
1992 | /// Get the nickname of this grid, as set in the [GridInfo] config section. | ||
1993 | /// </summary> | ||
1994 | /// <remarks> | ||
1968 | /// Threat level is Moderate because intentional abuse, for instance | 1995 | /// Threat level is Moderate because intentional abuse, for instance |
1969 | /// scripts that are written to be malicious only on one grid, | 1996 | /// scripts that are written to be malicious only on one grid, |
1970 | /// for instance in a HG scenario, are a distinct possibility. | 1997 | /// for instance in a HG scenario, are a distinct possibility. |
1971 | /// | 1998 | /// </remarks> |
1972 | /// Use value from the config file and return it. | 1999 | /// <returns></returns> |
1973 | /// | ||
1974 | public string osGetGridNick() | 2000 | public string osGetGridNick() |
1975 | { | 2001 | { |
1976 | CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick"); | 2002 | CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick"); |
@@ -2037,7 +2063,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2037 | // Find matches beginning at start position | 2063 | // Find matches beginning at start position |
2038 | Regex matcher = new Regex(pattern); | 2064 | Regex matcher = new Regex(pattern); |
2039 | Match match = matcher.Match(src, start); | 2065 | Match match = matcher.Match(src, start); |
2040 | if (match.Success) | 2066 | while (match.Success) |
2041 | { | 2067 | { |
2042 | foreach (System.Text.RegularExpressions.Group g in match.Groups) | 2068 | foreach (System.Text.RegularExpressions.Group g in match.Groups) |
2043 | { | 2069 | { |
@@ -2047,6 +2073,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2047 | result.Add(new LSL_Integer(g.Index)); | 2073 | result.Add(new LSL_Integer(g.Index)); |
2048 | } | 2074 | } |
2049 | } | 2075 | } |
2076 | |||
2077 | match = match.NextMatch(); | ||
2050 | } | 2078 | } |
2051 | 2079 | ||
2052 | return result; | 2080 | return result; |
@@ -2076,12 +2104,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2076 | return World.RegionInfo.RegionSettings.LoadedCreationID; | 2104 | return World.RegionInfo.RegionSettings.LoadedCreationID; |
2077 | } | 2105 | } |
2078 | 2106 | ||
2079 | // Threat level is 'Low' because certain users could possibly be tricked into | 2107 | /// <summary> |
2080 | // dropping an unverified script into one of their own objects, which could | 2108 | /// Get the primitive parameters of a linked prim. |
2081 | // then gather the physical construction details of the object and transmit it | 2109 | /// </summary> |
2082 | // to an unscrupulous third party, thus permitting unauthorized duplication of | 2110 | /// <remarks> |
2083 | // the object's form. | 2111 | /// Threat level is 'Low' because certain users could possibly be tricked into |
2084 | // | 2112 | /// dropping an unverified script into one of their own objects, which could |
2113 | /// then gather the physical construction details of the object and transmit it | ||
2114 | /// to an unscrupulous third party, thus permitting unauthorized duplication of | ||
2115 | /// the object's form. | ||
2116 | /// </remarks> | ||
2117 | /// <param name="linknumber"></param> | ||
2118 | /// <param name="rules"></param> | ||
2119 | /// <returns></returns> | ||
2085 | public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules) | 2120 | public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules) |
2086 | { | 2121 | { |
2087 | CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams"); | 2122 | CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams"); |
@@ -2096,25 +2131,122 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2096 | return retVal; | 2131 | return retVal; |
2097 | } | 2132 | } |
2098 | 2133 | ||
2099 | public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom) | 2134 | public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard) |
2100 | { | 2135 | { |
2101 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); | 2136 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); |
2102 | //QueueUserWorkItem | ||
2103 | 2137 | ||
2104 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | 2138 | INPCModule module = World.RequestModuleInterface<INPCModule>(); |
2105 | if (module != null) | 2139 | if (module != null) |
2106 | { | 2140 | { |
2141 | AvatarAppearance appearance = null; | ||
2142 | |||
2143 | UUID id; | ||
2144 | if (UUID.TryParse(notecard, out id)) | ||
2145 | { | ||
2146 | ScenePresence clonePresence = World.GetScenePresence(id); | ||
2147 | if (clonePresence != null) | ||
2148 | appearance = clonePresence.Appearance; | ||
2149 | } | ||
2150 | |||
2151 | if (appearance == null) | ||
2152 | { | ||
2153 | string appearanceSerialized = LoadNotecard(notecard); | ||
2154 | |||
2155 | if (appearanceSerialized != null) | ||
2156 | { | ||
2157 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); | ||
2158 | appearance = new AvatarAppearance(); | ||
2159 | appearance.Unpack(appearanceOsd); | ||
2160 | } | ||
2161 | } | ||
2162 | |||
2163 | if (appearance == null) | ||
2164 | return new LSL_Key(UUID.Zero.ToString()); | ||
2165 | |||
2107 | UUID x = module.CreateNPC(firstname, | 2166 | UUID x = module.CreateNPC(firstname, |
2108 | lastname, | 2167 | lastname, |
2109 | new Vector3((float) position.x, (float) position.y, (float) position.z), | 2168 | new Vector3((float) position.x, (float) position.y, (float) position.z), |
2110 | World, | 2169 | World, |
2111 | new UUID(cloneFrom)); | 2170 | appearance); |
2112 | 2171 | ||
2113 | return new LSL_Key(x.ToString()); | 2172 | return new LSL_Key(x.ToString()); |
2114 | } | 2173 | } |
2174 | |||
2175 | return new LSL_Key(UUID.Zero.ToString()); | ||
2176 | } | ||
2177 | |||
2178 | /// <summary> | ||
2179 | /// Save the current appearance of the NPC permanently to the named notecard. | ||
2180 | /// </summary> | ||
2181 | /// <param name="avatar"></param> | ||
2182 | /// <param name="notecard">The name of the notecard to which to save the appearance.</param> | ||
2183 | /// <returns>The asset ID of the notecard saved.</returns> | ||
2184 | public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard) | ||
2185 | { | ||
2186 | CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance"); | ||
2187 | |||
2188 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | ||
2189 | |||
2190 | if (npcModule != null) | ||
2191 | { | ||
2192 | UUID npcId; | ||
2193 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2194 | return new LSL_Key(UUID.Zero.ToString()); | ||
2195 | |||
2196 | if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) | ||
2197 | return new LSL_Key(UUID.Zero.ToString()); | ||
2198 | |||
2199 | return SaveAppearanceToNotecard(npcId, notecard); | ||
2200 | } | ||
2201 | |||
2115 | return new LSL_Key(UUID.Zero.ToString()); | 2202 | return new LSL_Key(UUID.Zero.ToString()); |
2116 | } | 2203 | } |
2117 | 2204 | ||
2205 | public void osNpcLoadAppearance(LSL_Key npc, string notecard) | ||
2206 | { | ||
2207 | CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance"); | ||
2208 | |||
2209 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | ||
2210 | |||
2211 | if (npcModule != null) | ||
2212 | { | ||
2213 | UUID npcId; | ||
2214 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2215 | return; | ||
2216 | |||
2217 | string appearanceSerialized = LoadNotecard(notecard); | ||
2218 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); | ||
2219 | // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); | ||
2220 | // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized); | ||
2221 | // Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a); | ||
2222 | AvatarAppearance appearance = new AvatarAppearance(); | ||
2223 | appearance.Unpack(appearanceOsd); | ||
2224 | |||
2225 | npcModule.SetNPCAppearance(npcId, appearance, m_host.ParentGroup.Scene); | ||
2226 | } | ||
2227 | } | ||
2228 | |||
2229 | public LSL_Vector osNpcGetPos(LSL_Key npc) | ||
2230 | { | ||
2231 | CheckThreatLevel(ThreatLevel.High, "osNpcGetPos"); | ||
2232 | |||
2233 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | ||
2234 | if (npcModule != null) | ||
2235 | { | ||
2236 | UUID npcId; | ||
2237 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2238 | return new LSL_Vector(0, 0, 0); | ||
2239 | |||
2240 | if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) | ||
2241 | return new LSL_Vector(0, 0, 0); | ||
2242 | |||
2243 | Vector3 pos = World.GetScenePresence(npcId).AbsolutePosition; | ||
2244 | return new LSL_Vector(pos.X, pos.Y, pos.Z); | ||
2245 | } | ||
2246 | |||
2247 | return new LSL_Vector(0, 0, 0); | ||
2248 | } | ||
2249 | |||
2118 | public void osNpcMoveTo(LSL_Key npc, LSL_Vector position) | 2250 | public void osNpcMoveTo(LSL_Key npc, LSL_Vector position) |
2119 | { | 2251 | { |
2120 | CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo"); | 2252 | CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo"); |
@@ -2122,11 +2254,87 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2122 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | 2254 | INPCModule module = World.RequestModuleInterface<INPCModule>(); |
2123 | if (module != null) | 2255 | if (module != null) |
2124 | { | 2256 | { |
2257 | UUID npcId; | ||
2258 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2259 | return; | ||
2260 | |||
2125 | Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); | 2261 | Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); |
2126 | module.Autopilot(new UUID(npc.m_string), World, pos); | 2262 | module.MoveToTarget(npcId, World, pos, false, true); |
2127 | } | 2263 | } |
2128 | } | 2264 | } |
2129 | 2265 | ||
2266 | public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options) | ||
2267 | { | ||
2268 | CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget"); | ||
2269 | |||
2270 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | ||
2271 | if (module != null) | ||
2272 | { | ||
2273 | UUID npcId; | ||
2274 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2275 | return; | ||
2276 | |||
2277 | Vector3 pos = new Vector3((float)target.x, (float)target.y, (float)target.z); | ||
2278 | module.MoveToTarget( | ||
2279 | new UUID(npc.m_string), | ||
2280 | World, | ||
2281 | pos, | ||
2282 | (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0, | ||
2283 | (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0); | ||
2284 | } | ||
2285 | } | ||
2286 | |||
2287 | public LSL_Rotation osNpcGetRot(LSL_Key npc) | ||
2288 | { | ||
2289 | CheckThreatLevel(ThreatLevel.High, "osNpcGetRot"); | ||
2290 | |||
2291 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | ||
2292 | if (npcModule != null) | ||
2293 | { | ||
2294 | UUID npcId; | ||
2295 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2296 | return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); | ||
2297 | |||
2298 | if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) | ||
2299 | return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); | ||
2300 | |||
2301 | ScenePresence sp = World.GetScenePresence(npcId); | ||
2302 | Quaternion rot = sp.Rotation; | ||
2303 | |||
2304 | return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W); | ||
2305 | } | ||
2306 | |||
2307 | return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); | ||
2308 | } | ||
2309 | |||
2310 | public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation) | ||
2311 | { | ||
2312 | CheckThreatLevel(ThreatLevel.High, "osNpcSetRot"); | ||
2313 | |||
2314 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | ||
2315 | if (npcModule != null) | ||
2316 | { | ||
2317 | UUID npcId; | ||
2318 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2319 | return; | ||
2320 | |||
2321 | if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) | ||
2322 | return; | ||
2323 | |||
2324 | ScenePresence sp = World.GetScenePresence(npcId); | ||
2325 | sp.Rotation = LSL_Api.Rot2Quaternion(rotation); | ||
2326 | } | ||
2327 | } | ||
2328 | |||
2329 | public void osNpcStopMoveToTarget(LSL_Key npc) | ||
2330 | { | ||
2331 | CheckThreatLevel(ThreatLevel.VeryLow, "osNpcStopMoveTo"); | ||
2332 | |||
2333 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | ||
2334 | if (module != null) | ||
2335 | module.StopMoveToTarget(new UUID(npc.m_string), World); | ||
2336 | } | ||
2337 | |||
2130 | public void osNpcSay(LSL_Key npc, string message) | 2338 | public void osNpcSay(LSL_Key npc, string message) |
2131 | { | 2339 | { |
2132 | CheckThreatLevel(ThreatLevel.High, "osNpcSay"); | 2340 | CheckThreatLevel(ThreatLevel.High, "osNpcSay"); |
@@ -2148,6 +2356,64 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2148 | module.DeleteNPC(new UUID(npc.m_string), World); | 2356 | module.DeleteNPC(new UUID(npc.m_string), World); |
2149 | } | 2357 | } |
2150 | } | 2358 | } |
2359 | |||
2360 | /// <summary> | ||
2361 | /// Save the current appearance of the script owner permanently to the named notecard. | ||
2362 | /// </summary> | ||
2363 | /// <param name="notecard">The name of the notecard to which to save the appearance.</param> | ||
2364 | /// <returns>The asset ID of the notecard saved.</returns> | ||
2365 | public LSL_Key osOwnerSaveAppearance(string notecard) | ||
2366 | { | ||
2367 | CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance"); | ||
2368 | |||
2369 | return SaveAppearanceToNotecard(m_host.OwnerID, notecard); | ||
2370 | } | ||
2371 | |||
2372 | public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard) | ||
2373 | { | ||
2374 | CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance"); | ||
2375 | |||
2376 | return SaveAppearanceToNotecard(avatarId, notecard); | ||
2377 | } | ||
2378 | |||
2379 | protected LSL_Key SaveAppearanceToNotecard(ScenePresence sp, string notecard) | ||
2380 | { | ||
2381 | IAvatarFactory appearanceModule = World.RequestModuleInterface<IAvatarFactory>(); | ||
2382 | |||
2383 | if (appearanceModule != null) | ||
2384 | { | ||
2385 | appearanceModule.SaveBakedTextures(sp.UUID); | ||
2386 | OSDMap appearancePacked = sp.Appearance.Pack(); | ||
2387 | |||
2388 | TaskInventoryItem item | ||
2389 | = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true); | ||
2390 | |||
2391 | return new LSL_Key(item.AssetID.ToString()); | ||
2392 | } | ||
2393 | else | ||
2394 | { | ||
2395 | return new LSL_Key(UUID.Zero.ToString()); | ||
2396 | } | ||
2397 | } | ||
2398 | |||
2399 | protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecard) | ||
2400 | { | ||
2401 | ScenePresence sp = World.GetScenePresence(avatarId); | ||
2402 | |||
2403 | if (sp == null || sp.IsChildAgent) | ||
2404 | return new LSL_Key(UUID.Zero.ToString()); | ||
2405 | |||
2406 | return SaveAppearanceToNotecard(sp, notecard); | ||
2407 | } | ||
2408 | |||
2409 | protected LSL_Key SaveAppearanceToNotecard(LSL_Key rawAvatarId, string notecard) | ||
2410 | { | ||
2411 | UUID avatarId; | ||
2412 | if (!UUID.TryParse(rawAvatarId, out avatarId)) | ||
2413 | return new LSL_Key(UUID.Zero.ToString()); | ||
2414 | |||
2415 | return SaveAppearanceToNotecard(avatarId, notecard); | ||
2416 | } | ||
2151 | 2417 | ||
2152 | /// <summary> | 2418 | /// <summary> |
2153 | /// Get current region's map texture UUID | 2419 | /// Get current region's map texture UUID |
@@ -2357,10 +2623,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2357 | obj.Shape.ProjectionFocus = (float)focus; | 2623 | obj.Shape.ProjectionFocus = (float)focus; |
2358 | obj.Shape.ProjectionAmbiance = (float)amb; | 2624 | obj.Shape.ProjectionAmbiance = (float)amb; |
2359 | 2625 | ||
2360 | |||
2361 | obj.ParentGroup.HasGroupChanged = true; | 2626 | obj.ParentGroup.HasGroupChanged = true; |
2362 | obj.ScheduleFullUpdate(); | 2627 | obj.ScheduleFullUpdate(); |
2363 | |||
2364 | } | 2628 | } |
2365 | 2629 | ||
2366 | /// <summary> | 2630 | /// <summary> |
@@ -2385,6 +2649,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2385 | } | 2649 | } |
2386 | } | 2650 | } |
2387 | }); | 2651 | }); |
2652 | |||
2388 | return result; | 2653 | return result; |
2389 | } | 2654 | } |
2390 | 2655 | ||
@@ -2404,4 +2669,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2404 | return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); | 2669 | return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); |
2405 | } | 2670 | } |
2406 | } | 2671 | } |
2407 | } | 2672 | } \ No newline at end of file |