From 36a02441c55ecb6028bc008c3502d7bf3cb4ed63 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Mon, 27 Apr 2009 14:16:01 +0000 Subject: [PATCH] Thank you, Orion_Shamroy, for a patch to expand notecard reading capabilities in OSSL. Fixes Mantis #3543 --- .../Shared/Api/Implementation/OSSL_Api.cs | 169 ++++++++++++++---- .../Shared/Api/Interface/IOSSL_Api.cs | 1 + .../Shared/Api/Runtime/OSSL_Stub.cs | 5 + 3 files changed, 140 insertions(+), 35 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 446a97215a..1cd25e70b0 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. - */ + 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); - foreach (TaskInventoryItem item in m_host.TaskInventory.Values) - { - if (item.Type == 7 && item.Name == name) - { - 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); - }; + UUID assetID = UUID.Zero; - return NotecardCache.GetLine(item.AssetID, line, 255); + 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 all else fails just return error. - OSSLShoutError("Notecard '" + name + "' could not be found."); - return "ERROR!"; + 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, + /*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 osGetNotecard(string name) + { + CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard"); + m_host.AddScriptLPS(1); + + 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)) + { + 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!"; + } + }; + + for (int count = 0; count < NotecardCache.GetLines(assetID); count++) + { + NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n"; + } + + return NotecardData; + + + } + + /*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) - { - if (item.Type == 7 && item.Name == name) - { - 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); - }; + UUID assetID = UUID.Zero; - return NotecardCache.GetLines(item.AssetID); + 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 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) { diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 526c7d0afb..7c0f08683e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs @@ -124,6 +124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces void osMakeNotecard(string notecardName, LSL_Types.list contents); string osGetNotecardLine(string name, int line); + string osGetNotecard(string name); int osGetNumberOfNotecardLines(string name); string osAvatarName2Key(string firstname, string lastname); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 0f259831a3..a66ed30860 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs @@ -312,6 +312,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_OSSL_Functions.osGetNotecardLine(name, line); } + public string osGetNotecard(string name) + { + return m_OSSL_Functions.osGetNotecard(name); + } + public int osGetNumberOfNotecardLines(string name) { return m_OSSL_Functions.osGetNumberOfNotecardLines(name);