From d285ccb5cfdfca3128e2eef4f5185714a54a7a66 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sat, 18 Apr 2009 19:08:35 +0000 Subject: [PATCH] Allow reading of notecards by asset ID. Fixes Manthis #3420 --- .../Shared/Api/Implementation/LSL_Api.cs | 166 ++++++++++++------ 1 file changed, 111 insertions(+), 55 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 6a5777cf16..56d7d50778 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -9167,41 +9167,71 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } public LSL_String llGetNumberOfNotecardLines(string name) - { + { m_host.AddScriptLPS(1); TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); - foreach (TaskInventoryItem item in itemsDictionary.Values) + UUID assetID = UUID.Zero; + + if (!UUID.TryParse(name, out assetID)) { - if (item.Type == 7 && item.Name == name) + foreach (TaskInventoryItem item in itemsDictionary.Values) { - UUID tid = AsyncCommands. - DataserverPlugin.RegisterRequest(m_localID, - m_itemID, item.AssetID.ToString()); - if (NotecardCache.IsCached(item.AssetID)) + if (item.Type == 7 && item.Name == name) { - AsyncCommands. - DataserverPlugin.DataserverReply(item.AssetID.ToString(), - NotecardCache.GetLines(item.AssetID).ToString()); - // ScriptSleep(100); - return tid.ToString(); + assetID = item.AssetID; + break; } - WithNotecard(item.AssetID, delegate (UUID id, AssetBase a) - { - System.Text.ASCIIEncoding enc = - new System.Text.ASCIIEncoding(); - string data = enc.GetString(a.Data); - //m_log.Debug(data); - NotecardCache.Cache(id, data); - AsyncCommands. - DataserverPlugin.DataserverReply(id.ToString(), - NotecardCache.GetLines(id).ToString()); - }); - // ScriptSleep(100); - return tid.ToString(); } } + + if (assetID == UUID.Zero) + { + // => complain loudly, as specified by the LSL docs + ShoutError("Notecard '" + name + "' could not be found."); + } + + UUID tid = UUID.Zero; + + if (NotecardCache.IsCached(assetID)) + { + tid = AsyncCommands. + DataserverPlugin.RegisterRequest(m_localID, + m_itemID, assetID.ToString()); + + AsyncCommands. + DataserverPlugin.DataserverReply(assetID.ToString(), + NotecardCache.GetLines(assetID).ToString()); + // ScriptSleep(100); + return tid.ToString(); + } + + WithNotecard(assetID, delegate (UUID id, AssetBase a) + { + if (a.Type != 7) + return; + + tid = AsyncCommands. + DataserverPlugin.RegisterRequest(m_localID, + m_itemID, assetID.ToString()); + + System.Text.ASCIIEncoding enc = + new System.Text.ASCIIEncoding(); + string data = enc.GetString(a.Data); + //m_log.Debug(data); + NotecardCache.Cache(id, data); + AsyncCommands. + DataserverPlugin.DataserverReply(id.ToString(), + NotecardCache.GetLines(id).ToString()); + }); + + if (tid != UUID.Zero) + { + // ScriptSleep(100); + return tid.ToString(); + } + // if we got to here, we didn't find the notecard the script was asking for // => complain loudly, as specified by the LSL docs ShoutError("Notecard '" + name + "' could not be found."); @@ -9216,40 +9246,66 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); - foreach (TaskInventoryItem item in itemsDictionary.Values) - { - if (item.Type == 7 && item.Name == name) - { - UUID tid = AsyncCommands. - DataserverPlugin.RegisterRequest(m_localID, - m_itemID, item.AssetID.ToString()); - - if (NotecardCache.IsCached(item.AssetID)) - { - AsyncCommands. - DataserverPlugin.DataserverReply(item.AssetID.ToString(), - NotecardCache.GetLine(item.AssetID, line, m_notecardLineReadCharsMax)); - // ScriptSleep(100); - return tid.ToString(); - } - - WithNotecard(item.AssetID, delegate (UUID id, AssetBase a) - { - System.Text.ASCIIEncoding enc = - new System.Text.ASCIIEncoding(); - string data = enc.GetString(a.Data); - //m_log.Debug(data); - NotecardCache.Cache(id, data); - AsyncCommands. - DataserverPlugin.DataserverReply(id.ToString(), - NotecardCache.GetLine(id, line, m_notecardLineReadCharsMax)); - }); + UUID assetID = UUID.Zero; - // ScriptSleep(100); - return tid.ToString(); + if (!UUID.TryParse(name, out assetID)) + { + foreach (TaskInventoryItem item in itemsDictionary.Values) + { + if (item.Type == 7 && item.Name == name) + { + assetID = item.AssetID; + break; + } } } + if (assetID == UUID.Zero) + { + // => complain loudly, as specified by the LSL docs + ShoutError("Notecard '" + name + "' could not be found."); + } + + UUID tid = UUID.Zero; + + if (NotecardCache.IsCached(assetID)) + { + tid = AsyncCommands. + DataserverPlugin.RegisterRequest(m_localID, + m_itemID, assetID.ToString()); + + AsyncCommands. + DataserverPlugin.DataserverReply(assetID.ToString(), + NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax)); + // ScriptSleep(100); + return tid.ToString(); + } + + WithNotecard(assetID, delegate (UUID id, AssetBase a) + { + if (a.Type != 7) + return; + + tid = AsyncCommands. + DataserverPlugin.RegisterRequest(m_localID, + m_itemID, assetID.ToString()); + + System.Text.ASCIIEncoding enc = + new System.Text.ASCIIEncoding(); + string data = enc.GetString(a.Data); + //m_log.Debug(data); + NotecardCache.Cache(id, data); + AsyncCommands. + DataserverPlugin.DataserverReply(id.ToString(), + NotecardCache.GetLine(id, line, m_notecardLineReadCharsMax)); + }); + + if (tid != UUID.Zero) + { + // ScriptSleep(100); + return tid.ToString(); + } + // if we got to here, we didn't find the notecard the script was asking for // => complain loudly, as specified by the LSL docs ShoutError("Notecard '" + name + "' could not be found.");