From b0be8075cd318bdd4ff1265f4491e3f7bcce9e2e Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Wed, 28 May 2008 21:43:41 +0000 Subject: From: Kurt Taylor Attached is an initial implementation of llGetNotecardLine and llGetNumberOfNotecardLines. I decided to go ahead an send these out for comment while I continue to work on the second part of the proper implementation. These functions work and return the values requested, as initially defined in the code, but should be properly implemented to return the requested information via a dataserver event. This event will be added and these functions fixed and included in a second patch shortly. --- .../Common/BuiltIn_Commands_BaseClass.cs | 2 +- .../ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 89 ++++++++++++++++++++-- .../Common/LSL_BuiltIn_Commands_Interface.cs | 2 +- 3 files changed, 86 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs b/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs index b7b040d..7b9b496 100644 --- a/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs +++ b/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs @@ -1595,7 +1595,7 @@ namespace OpenSim.Region.ScriptEngine.Common return m_LSL_Functions.llGetNumberOfPrims(); } - public string llGetNumberOfNotecardLines(string name) + public int llGetNumberOfNotecardLines(string name) { return m_LSL_Functions.llGetNumberOfNotecardLines(name); } diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index e91e73c..4e25ff8 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -3821,8 +3821,75 @@ namespace OpenSim.Region.ScriptEngine.Common public string llGetNotecardLine(string name, int line) { m_host.AddScriptLPS(1); - NotImplemented("llGetNotecardLine"); - return String.Empty; + + // TODO: this script function should actually return + // the requested notecard line via the dataserver event + // once it is implemented - krtaylor + + String[] notecardLines = GetNotecardLines(name); + if (!String.IsNullOrEmpty(notecardLines[0])) + { + return notecardLines[line]; + } + else + { + return String.Empty; + } + } + + private String[] GetNotecardLines(string name) + { + bool found = false; + int notecardIndex = 0; + String[] notecardLines = { "0" }; + notecardLines[0] = String.Empty; + + foreach (KeyValuePair inv in m_host.TaskInventory) + { + if ((inv.Value.Name == name) && (inv.Value.InvType == (int)InventoryType.Notecard)) + { + // OK, it has the right name and it is a notecard + // so get the asset that contains the notecard raw data + // and convert it into a string + AssetBase notecardAsset = World.AssetCache.GetAsset(inv.Value.AssetID, false); + String dataString = System.Text.Encoding.ASCII.GetString(notecardAsset.Data); + + if (!String.IsNullOrEmpty(dataString)) + { + // good, we have the notecard data as a string + // now parse the text lines using the Linden Text delimiters + notecardIndex = dataString.IndexOf("}\n"); + if (notecardIndex > 0) + { + notecardIndex = notecardIndex + 2; //get past delimiter + notecardIndex = dataString.IndexOf("\n", notecardIndex); + if (notecardIndex > 0) + { + // Finally got to the first line of the notecard + // now find the end of the notecard text delimited by } + // parse the lines, delimited by + char[] delimChar = { '\n' }; + int notecardEof = dataString.IndexOf("}\n", notecardIndex); + if (notecardEof > 0) + { + int notecardLength = notecardEof - notecardIndex - 1; + notecardIndex = dataString.IndexOf("\n", notecardIndex); + notecardIndex++; // get past delimiter + + // create new string to parse that only consists of the actual lines in the asset + Char[] notecardCharArray = dataString.ToCharArray(notecardIndex, notecardLength); + String notecardString = new String(notecardCharArray); + + // split the lines of the notecard into separate strings + notecardLines = notecardString.Split(delimChar); + return notecardLines; + } + } + } + } + } + } + return notecardLines; } public LSL_Types.Vector3 llGetAgentSize(string id) @@ -4769,11 +4836,23 @@ namespace OpenSim.Region.ScriptEngine.Common return m_host.ParentGroup.PrimCount; } - public string llGetNumberOfNotecardLines(string name) + public int llGetNumberOfNotecardLines(string name) { m_host.AddScriptLPS(1); - NotImplemented("llGetNumberOfNotecardLines"); - return String.Empty; + + // TODO: this script function should actually return + // the number of lines via the dataserver event + // once it is implemented - krtaylor + + String[] notecardLines = GetNotecardLines(name); + if (!String.IsNullOrEmpty(notecardLines[0])) + { + return notecardLines.Length; + } + else + { + return 0; + } } public LSL_Types.list llGetBoundingBox(string obj) diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs index d824f0c..dae7fa0 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs @@ -540,7 +540,7 @@ namespace OpenSim.Region.ScriptEngine.Common //wiki: integer llGetNumberOfPrims() LSL_Types.LSLInteger llGetNumberOfPrims(); //wiki: key llGetNumberOfNotecardLines(string name) - string llGetNumberOfNotecardLines(string name); + int llGetNumberOfNotecardLines(string name); //wiki: list llGetBoundingBox(key object) LSL_Types.list llGetBoundingBox(string obj); //wiki: vector llGetGeometricCenter() -- cgit v1.1