From 36a02441c55ecb6028bc008c3502d7bf3cb4ed63 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Mon, 27 Apr 2009 14:16:01 +0000 Subject: Thank you, Orion_Shamroy, for a patch to expand notecard reading capabilities in OSSL. Fixes Mantis #3543 --- .../Shared/Api/Implementation/OSSL_Api.cs | 161 +++++++++++++++++---- 1 file changed, 130 insertions(+), 31 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 446a972..1cd25e7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -1369,68 +1369,167 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.Inventory.AddInventoryItem(taskItem, false); } + /*Instead of using the LSL Dataserver event to pull notecard data, - this will simply read the requested line and return its data as a string. + this will simply read the requested line and return its data as a string. + + Warning - due to the synchronous method this function uses to fetch assets, its use + may be dangerous and unreliable while running in grid mode. + */ + public string osGetNotecardLine(string name, int line) + { + CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); + m_host.AddScriptLPS(1); + + UUID assetID = UUID.Zero; + + if (!UUID.TryParse(name, out assetID)) + { + foreach (TaskInventoryItem item in m_host.TaskInventory.Values) + { + if (item.Type == 7 && item.Name == name) + { + assetID = item.AssetID; + } + } + } + + if (assetID == UUID.Zero) + { + OSSLShoutError("Notecard '" + name + "' could not be found."); + return "ERROR!"; + } + + if (!NotecardCache.IsCached(assetID)) + { + AssetBase a = World.CommsManager.AssetCache.GetAsset(assetID, false); + if (a != null) + { + System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); + string data = enc.GetString(a.Data); + NotecardCache.Cache(assetID, data); + } + else + { + OSSLShoutError("Notecard '" + name + "' could not be found."); + return "ERROR!"; + } + }; + + return NotecardCache.GetLine(assetID, line, 255); + + + } + + /*Instead of using the LSL Dataserver event to pull notecard data line by line, + this will simply read the entire notecard and return its data as a string. Warning - due to the synchronous method this function uses to fetch assets, its use may be dangerous and unreliable while running in grid mode. */ - public string osGetNotecardLine(string name, int line) + + public string osGetNotecard(string name) { - CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); + CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard"); m_host.AddScriptLPS(1); - foreach (TaskInventoryItem item in m_host.TaskInventory.Values) + UUID assetID = UUID.Zero; + string NotecardData = ""; + + if (!UUID.TryParse(name, out assetID)) + { + foreach (TaskInventoryItem item in m_host.TaskInventory.Values) + { + if (item.Type == 7 && item.Name == name) + { + assetID = item.AssetID; + } + } + } + + if (assetID == UUID.Zero) + { + OSSLShoutError("Notecard '" + name + "' could not be found."); + return "ERROR!"; + } + + if (!NotecardCache.IsCached(assetID)) { - if (item.Type == 7 && item.Name == name) + AssetBase a = World.CommsManager.AssetCache.GetAsset(assetID, false); + if (a != null) { - if (NotecardCache.IsCached(item.AssetID)== false) - { AssetBase a = World.CommsManager.AssetCache.GetAsset(item.AssetID, false); - System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); - string data = enc.GetString(a.Data); - NotecardCache.Cache(item.AssetID, data); - }; - - return NotecardCache.GetLine(item.AssetID, line, 255); + System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); + string data = enc.GetString(a.Data); + NotecardCache.Cache(assetID, data); } + else + { + OSSLShoutError("Notecard '" + name + "' could not be found."); + return "ERROR!"; + } + }; + + for (int count = 0; count < NotecardCache.GetLines(assetID); count++) + { + NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n"; } - //If all else fails just return error. - OSSLShoutError("Notecard '" + name + "' could not be found."); - return "ERROR!"; + return NotecardData; + + } - /*Instead of using the LSL Dataserver event to pull notecard data, + /*Instead of using the LSL Dataserver event to pull notecard data, this will simply read the number of note card lines and return this data as an integer. Warning - due to the synchronous method this function uses to fetch assets, its use may be dangerous and unreliable while running in grid mode. */ + public int osGetNumberOfNotecardLines(string name) { CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines"); m_host.AddScriptLPS(1); - foreach (TaskInventoryItem item in m_host.TaskInventory.Values) + UUID assetID = UUID.Zero; + + if (!UUID.TryParse(name, out assetID)) { - if (item.Type == 7 && item.Name == name) + foreach (TaskInventoryItem item in m_host.TaskInventory.Values) { - if (NotecardCache.IsCached(item.AssetID) == false) + if (item.Type == 7 && item.Name == name) { - AssetBase a = World.CommsManager.AssetCache.GetAsset(item.AssetID, false); - System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); - string data = enc.GetString(a.Data); - NotecardCache.Cache(item.AssetID, data); - }; - - return NotecardCache.GetLines(item.AssetID); + assetID = item.AssetID; + } } } - //If all else fails just return error. - OSSLShoutError("Notecard '" + name + "' could not be found."); - return -1; - } + if (assetID == UUID.Zero) + { + OSSLShoutError("Notecard '" + name + "' could not be found."); + return -1; + } + + if (!NotecardCache.IsCached(assetID)) + { + AssetBase a = World.CommsManager.AssetCache.GetAsset(assetID, false); + if (a != null) + { + System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); + string data = enc.GetString(a.Data); + NotecardCache.Cache(assetID, data); + } + else + { + OSSLShoutError("Notecard '" + name + "' could not be found."); + return -1; + } + }; + + return NotecardCache.GetLines(assetID); + + + } public string osAvatarName2Key(string firstname, string lastname) { -- cgit v1.1