From f9769a9fcb84a68622abe23160274796937ae0d4 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 28 Jun 2012 00:37:23 +0100 Subject: [PATCH 1/2] minor: reuse colon index calculation in XEngine.OnRezScript. The index if a colon is found on the first line will always be the same as for the whole script. --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 06ed9d6deb..73d384d098 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -768,12 +768,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine int colon = firstline.IndexOf(':'); if (firstline.Length > 2 && firstline.Substring(0, 2) == "//" && colon != -1) { - string engineName = firstline.Substring(2, colon-2); + string engineName = firstline.Substring(2, colon - 2); if (names.Contains(engineName)) { engine = engineName; - script = "//" + script.Substring(script.IndexOf(':')+1); + script = "//" + script.Substring(colon + 1); } else { From 25baa2d894e9bbbb173eb4e6ebe1478d2e3c1265 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 28 Jun 2012 00:58:36 +0100 Subject: [PATCH 2/2] Avoid reporting false positives when a colon is in a comment in the first line of a script where the user was not trying to select a different script engine. This works by only posting the "Selected engine unavailable" message if we're falling back on XEngine and the language is one handled by XEngine. In cases where the language is not handled or not allowed, the user will still be notified by the later compiler error. This avoids the overwhelming majority of false positives where the first line contains a : for other reasons (e.g. source control systems, vim settings, etc.) Ultimately, I think it would be better to detect script language/engine with a mechanism that didn't just rely on : detection (e.g like #! in unix scripts). --- .../Region/ScriptEngine/XEngine/XEngine.cs | 54 +++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 73d384d098..a709be34f6 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -779,24 +779,48 @@ namespace OpenSim.Region.ScriptEngine.XEngine { if (engine == ScriptEngineName) { - SceneObjectPart part = - m_Scene.GetSceneObjectPart( - localID); - - TaskInventoryItem item = - part.Inventory.GetInventoryItem(itemID); + // If we are falling back on XEngine as the default engine, then only complain to the user + // if a script language has been explicitly set and it's one that we recognize. If it's + // explicitly not allowed or the script is not in LSL then the user will be informed by a later compiler message. + // + // This avoids the overwhelming number of false positives where we're in this code because + // there's a colon in a comment in the first line of a script for entirely + // unrelated reasons (e.g. vim settings). + // + // TODO: A better fix would be to deprecate simple : detection and look for some less likely + // string to begin the comment (like #! in unix shell scripts). + bool scriptExplicitlyInXEngineLanguage = false; + string restOfScript = script.Substring(colon + 1); - ScenePresence presence = - m_Scene.GetScenePresence( - item.OwnerID); + // FIXME: These are hardcoded because they are currently hardcoded in Compiler.cs + if (restOfScript.StartsWith("c#") + || restOfScript.StartsWith("vb") + || restOfScript.StartsWith("lsl") + || restOfScript.StartsWith("js") + || restOfScript.StartsWith("yp")) + scriptExplicitlyInXEngineLanguage = true; - if (presence != null) + if (scriptExplicitlyInXEngineLanguage) { - presence.ControllingClient.SendAgentAlertMessage( - "Selected engine unavailable. "+ - "Running script on "+ - ScriptEngineName, - false); + SceneObjectPart part = + m_Scene.GetSceneObjectPart( + localID); + + TaskInventoryItem item = + part.Inventory.GetInventoryItem(itemID); + + ScenePresence presence = + m_Scene.GetScenePresence( + item.OwnerID); + + if (presence != null) + { + presence.ControllingClient.SendAgentAlertMessage( + "Selected engine unavailable. "+ + "Running script on "+ + ScriptEngineName, + false); + } } } }