From e07548d703798bfd661c1ab89cc3b48c936d0a77 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 4 Mar 2010 20:08:25 +0000 Subject: move linden notecard parsing from LSL_Api.cs to SLUtil so that region modules can use it --- OpenSim/Framework/SLUtil.cs | 99 +++++++++++++++++++++- OpenSim/Region/Application/ConfigurationLoader.cs | 19 ++--- OpenSim/Region/Framework/Scenes/EventManager.cs | 30 +++---- .../Framework/Scenes/SceneObjectPartInventory.cs | 1 - .../Shared/Api/Implementation/LSL_Api.cs | 83 +----------------- 5 files changed, 123 insertions(+), 109 deletions(-) diff --git a/OpenSim/Framework/SLUtil.cs b/OpenSim/Framework/SLUtil.cs index 9d5c30a..ff5f8b9 100644 --- a/OpenSim/Framework/SLUtil.cs +++ b/OpenSim/Framework/SLUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using OpenMetaverse; namespace OpenSim.Framework @@ -181,5 +182,101 @@ namespace OpenSim.Framework } #endregion SL / file extension / content-type conversions + + /// + /// Parse a notecard in Linden format to a string of ordinary text. + /// + /// + /// + public static string ParseNotecardToString(string rawInput) + { + return string.Join("\n", ParseNotecardToList(rawInput).ToArray()); + } + + /// + /// Parse a notecard in Linden format to a list of ordinary lines. + /// + /// + /// + public static List ParseNotecardToList(string rawInput) + { + string[] input = rawInput.Replace("\r", "").Split('\n'); + int idx = 0; + int level = 0; + List output = new List(); + string[] words; + + while (idx < input.Length) + { + if (input[idx] == "{") + { + level++; + idx++; + continue; + } + + if (input[idx]== "}") + { + level--; + idx++; + continue; + } + + switch (level) + { + case 0: + words = input[idx].Split(' '); // Linden text ver + // Notecards are created *really* empty. Treat that as "no text" (just like after saving an empty notecard) + if (words.Length < 3) + return output; + + int version = int.Parse(words[3]); + if (version != 2) + return output; + break; + case 1: + words = input[idx].Split(' '); + if (words[0] == "LLEmbeddedItems") + break; + if (words[0] == "Text") + { + int len = int.Parse(words[2]); + idx++; + + int count = -1; + + while (count < len) + { + // int l = input[idx].Length; + string ln = input[idx]; + + int need = len-count-1; + if (ln.Length > need) + ln = ln.Substring(0, need); + + output.Add(ln); + count += ln.Length + 1; + idx++; + } + + return output; + } + break; + case 2: + words = input[idx].Split(' '); // count + if (words[0] == "count") + { + int c = int.Parse(words[1]); + if (c > 0) + return output; + break; + } + break; + } + idx++; + } + + return output; + } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Application/ConfigurationLoader.cs b/OpenSim/Region/Application/ConfigurationLoader.cs index 655c5ca..8f19417 100644 --- a/OpenSim/Region/Application/ConfigurationLoader.cs +++ b/OpenSim/Region/Application/ConfigurationLoader.cs @@ -164,12 +164,12 @@ namespace OpenSim m_config.Source = new IniConfigSource(); m_config.Source.Merge(DefaultConfig()); - m_log.Info("[CONFIG] Reading configuration settings"); + m_log.Info("[CONFIG]: Reading configuration settings"); if (sources.Count == 0) { - m_log.FatalFormat("[CONFIG] Could not load any configuration"); - m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?"); + m_log.FatalFormat("[CONFIG]: Could not load any configuration"); + m_log.FatalFormat("[CONFIG]: Did you copy the OpenSim.ini.example file to OpenSim.ini?"); Environment.Exit(1); } @@ -182,8 +182,8 @@ namespace OpenSim if (!iniFileExists) { - m_log.FatalFormat("[CONFIG] Could not load any configuration"); - m_log.FatalFormat("[CONFIG] Configuration exists, but there was an error loading it!"); + m_log.FatalFormat("[CONFIG]: Could not load any configuration"); + m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!"); Environment.Exit(1); } @@ -257,20 +257,17 @@ namespace OpenSim if (!IsUri(iniPath)) { - m_log.InfoFormat("[CONFIG] Reading configuration file {0}", - Path.GetFullPath(iniPath)); + m_log.InfoFormat("[CONFIG]: Reading configuration file {0}", Path.GetFullPath(iniPath)); m_config.Source.Merge(new IniConfigSource(iniPath)); success = true; } else { - m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", - iniPath); + m_log.InfoFormat("[CONFIG]: {0} is a http:// URI, fetching ...", iniPath); // The ini file path is a http URI // Try to read it - // try { XmlReader r = XmlReader.Create(iniPath); @@ -281,7 +278,7 @@ namespace OpenSim } catch (Exception e) { - m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniPath); + m_log.FatalFormat("[CONFIG]: Exception reading config from URI {0}\n" + e.ToString(), iniPath); Environment.Exit(1); } } diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index ac04462..f0d346f 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -110,21 +110,24 @@ namespace OpenSim.Region.Framework.Scenes public event OnSetRootAgentSceneDelegate OnSetRootAgentScene; /// - /// Called when an object is touched/grabbed. + /// Fired when an object is touched/grabbed. /// /// The originalID is the local ID of the part that was actually touched. The localID itself is always that of - /// the root part. - public delegate void ObjectGrabDelegate(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs); + /// the root part. public event ObjectGrabDelegate OnObjectGrab; + public delegate void ObjectGrabDelegate(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs); public event ObjectGrabDelegate OnObjectGrabbing; public event ObjectDeGrabDelegate OnObjectDeGrab; public event ScriptResetDelegate OnScriptReset; - public event OnPermissionErrorDelegate OnPermissionError; + public event OnPermissionErrorDelegate OnPermissionError; - public delegate void NewRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource); + /// + /// Fired when a new script is created. + /// public event NewRezScript OnRezScript; + public delegate void NewRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource); public delegate void RemoveScript(uint localID, UUID itemID); public event RemoveScript OnRemoveScript; @@ -166,38 +169,35 @@ namespace OpenSim.Region.Framework.Scenes public delegate void ClientClosed(UUID clientID, Scene scene); - public event ClientClosed OnClientClosed; - - public delegate void ScriptChangedEvent(uint localID, uint change); + public event ClientClosed OnClientClosed; + /// + /// This is fired when a scene object property that a script might be interested in (such as color, scale or + /// inventory) changes. Only enough information is sent for the LSL changed event + /// (see http://lslwiki.net/lslwiki/wakka.php?wakka=changed) + /// public event ScriptChangedEvent OnScriptChangedEvent; + public delegate void ScriptChangedEvent(uint localID, uint change); public delegate void ScriptControlEvent(uint localID, UUID item, UUID avatarID, uint held, uint changed); - public event ScriptControlEvent OnScriptControlEvent; public delegate void ScriptAtTargetEvent(uint localID, uint handle, Vector3 targetpos, Vector3 atpos); - public event ScriptAtTargetEvent OnScriptAtTargetEvent; public delegate void ScriptNotAtTargetEvent(uint localID); - public event ScriptNotAtTargetEvent OnScriptNotAtTargetEvent; public delegate void ScriptAtRotTargetEvent(uint localID, uint handle, Quaternion targetrot, Quaternion atrot); - public event ScriptAtRotTargetEvent OnScriptAtRotTargetEvent; public delegate void ScriptNotAtRotTargetEvent(uint localID); - public event ScriptNotAtRotTargetEvent OnScriptNotAtRotTargetEvent; public delegate void ScriptColliding(uint localID, ColliderArgs colliders); - public event ScriptColliding OnScriptColliderStart; public event ScriptColliding OnScriptColliding; public event ScriptColliding OnScriptCollidingEnd; - public event ScriptColliding OnScriptLandColliderStart; public event ScriptColliding OnScriptLandColliding; public event ScriptColliding OnScriptLandColliderEnd; diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 04e3221..77bf6fe 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -637,7 +637,6 @@ namespace OpenSim.Region.Framework.Scenes m_items[item.ItemID] = item; m_inventorySerial++; m_part.TriggerScriptChangedEvent(Changed.INVENTORY); - HasInventoryChanged = true; m_part.ParentGroup.HasGroupChanged = true; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index dc4249c..974f91b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -9705,90 +9705,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api Notecard nc = new Notecard(); nc.lastRef = DateTime.Now; - nc.text = ParseText(text.Replace("\r", "").Split('\n')); + nc.text = SLUtil.ParseNotecardToList(text).ToArray(); m_Notecards[assetID] = nc; } } - protected static string[] ParseText(string[] input) - { - int idx = 0; - int level = 0; - List output = new List(); - string[] words; - - while (idx < input.Length) - { - if (input[idx] == "{") - { - level++; - idx++; - continue; - } - - if (input[idx]== "}") - { - level--; - idx++; - continue; - } - - switch (level) - { - case 0: - words = input[idx].Split(' '); // Linden text ver - // Notecards are created *really* empty. Treat that as "no text" (just like after saving an empty notecard) - if (words.Length < 3) - return new String[0]; - - int version = int.Parse(words[3]); - if (version != 2) - return new String[0]; - break; - case 1: - words = input[idx].Split(' '); - if (words[0] == "LLEmbeddedItems") - break; - if (words[0] == "Text") - { - int len = int.Parse(words[2]); - idx++; - - int count = -1; - - while (count < len) - { - // int l = input[idx].Length; - string ln = input[idx]; - - int need = len-count-1; - if (ln.Length > need) - ln = ln.Substring(0, need); - - output.Add(ln); - count += ln.Length + 1; - idx++; - } - - return output.ToArray(); - } - break; - case 2: - words = input[idx].Split(' '); // count - if (words[0] == "count") - { - int c = int.Parse(words[1]); - if (c > 0) - return new String[0]; - break; - } - break; - } - idx++; - } - return output.ToArray(); - } - public static bool IsCached(UUID assetID) { lock (m_Notecards) @@ -9844,4 +9765,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } } -} +} \ No newline at end of file -- cgit v1.1