aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs167
1 files changed, 74 insertions, 93 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 32ad21f..154179c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -1733,7 +1733,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1733 SaveNotecard(notecardName, notecardData.ToString()); 1733 SaveNotecard(notecardName, notecardData.ToString());
1734 } 1734 }
1735 1735
1736 protected void SaveNotecard(string notecardName, string notecardData) 1736 /// <summary>
1737 /// Save a notecard to prim inventory.
1738 /// </summary>
1739 /// <param name="notecardName"></param>
1740 /// <param name="notecardData"></param>
1741 /// <returns>Prim inventory item created.</returns>
1742 protected TaskInventoryItem SaveNotecard(string notecardName, string notecardData)
1737 { 1743 {
1738 // Create new asset 1744 // Create new asset
1739 AssetBase asset = new AssetBase(UUID.Random(), notecardName, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString()); 1745 AssetBase asset = new AssetBase(UUID.Random(), notecardName, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
@@ -1770,6 +1776,66 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1770 taskItem.AssetID = asset.FullID; 1776 taskItem.AssetID = asset.FullID;
1771 1777
1772 m_host.Inventory.AddInventoryItem(taskItem, false); 1778 m_host.Inventory.AddInventoryItem(taskItem, false);
1779
1780 return taskItem;
1781 }
1782
1783 /// <summary>
1784 /// Load the notecard data found at the given prim inventory item name or asset uuid.
1785 /// </summary>
1786 /// <param name="notecardNameOrUuid"></param>
1787 /// <returns>The text loaded. Null if no notecard was found.</returns>
1788 protected string LoadNotecard(string notecardNameOrUuid)
1789 {
1790 UUID assetID = CacheNotecard(notecardNameOrUuid);
1791 StringBuilder notecardData = new StringBuilder();
1792
1793 for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
1794 notecardData.Append(NotecardCache.GetLine(assetID, count, 255) + "\n");
1795
1796 return notecardData.ToString();
1797 }
1798
1799 /// <summary>
1800 /// Cache a notecard's contents.
1801 /// </summary>
1802 /// <param name="notecardNameOrUuid"></param>
1803 /// <returns>
1804 /// The asset id of the notecard, which is used for retrieving the cached data.
1805 /// UUID.Zero if no asset could be found.
1806 /// </returns>
1807 protected UUID CacheNotecard(string notecardNameOrUuid)
1808 {
1809 UUID assetID = UUID.Zero;
1810 StringBuilder notecardData = new StringBuilder();
1811
1812 if (!UUID.TryParse(notecardNameOrUuid, out assetID))
1813 {
1814 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1815 {
1816 if (item.Type == 7 && item.Name == notecardNameOrUuid)
1817 {
1818 assetID = item.AssetID;
1819 }
1820 }
1821 }
1822
1823 if (assetID == UUID.Zero)
1824 return UUID.Zero;
1825
1826 if (!NotecardCache.IsCached(assetID))
1827 {
1828 AssetBase a = World.AssetService.Get(assetID.ToString());
1829
1830 if (a == null)
1831 return UUID.Zero;
1832
1833 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
1834 string data = enc.GetString(a.Data);
1835 NotecardCache.Cache(assetID, data);
1836 };
1837
1838 return assetID;
1773 } 1839 }
1774 1840
1775 /// <summary> 1841 /// <summary>
@@ -1790,18 +1856,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1790 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); 1856 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
1791 m_host.AddScriptLPS(1); 1857 m_host.AddScriptLPS(1);
1792 1858
1793 UUID assetID = UUID.Zero; 1859 UUID assetID = CacheNotecard(name);
1794
1795 if (!UUID.TryParse(name, out assetID))
1796 {
1797 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1798 {
1799 if (item.Type == 7 && item.Name == name)
1800 {
1801 assetID = item.AssetID;
1802 }
1803 }
1804 }
1805 1860
1806 if (assetID == UUID.Zero) 1861 if (assetID == UUID.Zero)
1807 { 1862 {
@@ -1809,22 +1864,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1809 return "ERROR!"; 1864 return "ERROR!";
1810 } 1865 }
1811 1866
1812 if (!NotecardCache.IsCached(assetID))
1813 {
1814 AssetBase a = World.AssetService.Get(assetID.ToString());
1815 if (a != null)
1816 {
1817 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
1818 string data = enc.GetString(a.Data);
1819 NotecardCache.Cache(assetID, data);
1820 }
1821 else
1822 {
1823 OSSLShoutError("Notecard '" + name + "' could not be found.");
1824 return "ERROR!";
1825 }
1826 };
1827
1828 return NotecardCache.GetLine(assetID, line, 255); 1867 return NotecardCache.GetLine(assetID, line, 255);
1829 } 1868 }
1830 1869
@@ -1845,48 +1884,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1845 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard"); 1884 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
1846 m_host.AddScriptLPS(1); 1885 m_host.AddScriptLPS(1);
1847 1886
1848 UUID assetID = UUID.Zero; 1887 string text = LoadNotecard(name);
1849 string NotecardData = "";
1850
1851 if (!UUID.TryParse(name, out assetID))
1852 {
1853 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1854 {
1855 if (item.Type == 7 && item.Name == name)
1856 {
1857 assetID = item.AssetID;
1858 }
1859 }
1860 }
1861 1888
1862 if (assetID == UUID.Zero) 1889 if (text == null)
1863 { 1890 {
1864 OSSLShoutError("Notecard '" + name + "' could not be found."); 1891 OSSLShoutError("Notecard '" + name + "' could not be found.");
1865 return "ERROR!"; 1892 return "ERROR!";
1866 } 1893 }
1867 1894 else
1868 if (!NotecardCache.IsCached(assetID))
1869 {
1870 AssetBase a = World.AssetService.Get(assetID.ToString());
1871 if (a != null)
1872 {
1873 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
1874 string data = enc.GetString(a.Data);
1875 NotecardCache.Cache(assetID, data);
1876 }
1877 else
1878 {
1879 OSSLShoutError("Notecard '" + name + "' could not be found.");
1880 return "ERROR!";
1881 }
1882 };
1883
1884 for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
1885 { 1895 {
1886 NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n"; 1896 return text;
1887 } 1897 }
1888
1889 return NotecardData;
1890 } 1898 }
1891 1899
1892 /// <summary> 1900 /// <summary>
@@ -1906,18 +1914,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1906 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines"); 1914 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
1907 m_host.AddScriptLPS(1); 1915 m_host.AddScriptLPS(1);
1908 1916
1909 UUID assetID = UUID.Zero; 1917 UUID assetID = CacheNotecard(name);
1910
1911 if (!UUID.TryParse(name, out assetID))
1912 {
1913 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1914 {
1915 if (item.Type == 7 && item.Name == name)
1916 {
1917 assetID = item.AssetID;
1918 }
1919 }
1920 }
1921 1918
1922 if (assetID == UUID.Zero) 1919 if (assetID == UUID.Zero)
1923 { 1920 {
@@ -1925,22 +1922,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1925 return -1; 1922 return -1;
1926 } 1923 }
1927 1924
1928 if (!NotecardCache.IsCached(assetID))
1929 {
1930 AssetBase a = World.AssetService.Get(assetID.ToString());
1931 if (a != null)
1932 {
1933 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
1934 string data = enc.GetString(a.Data);
1935 NotecardCache.Cache(assetID, data);
1936 }
1937 else
1938 {
1939 OSSLShoutError("Notecard '" + name + "' could not be found.");
1940 return -1;
1941 }
1942 };
1943
1944 return NotecardCache.GetLines(assetID); 1925 return NotecardCache.GetLines(assetID);
1945 } 1926 }
1946 1927
@@ -2412,7 +2393,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2412 } 2393 }
2413 } 2394 }
2414 }); 2395 });
2415 2396
2416 return result; 2397 return result;
2417 } 2398 }
2418 2399