aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting
diff options
context:
space:
mode:
authorMelanie2013-02-10 00:17:14 +0000
committerMelanie2013-02-10 00:17:14 +0000
commit069e587841465d8d041164929e27fc891b66a64a (patch)
treec37a59b837bfbac696850a7af2b8f20c520141ba /OpenSim/Region/OptionalModules/Scripting
parentMerge branch 'master' into careminster (diff)
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-069e587841465d8d041164929e27fc891b66a64a.zip
opensim-SC_OLD-069e587841465d8d041164929e27fc891b66a64a.tar.gz
opensim-SC_OLD-069e587841465d8d041164929e27fc891b66a64a.tar.bz2
opensim-SC_OLD-069e587841465d8d041164929e27fc891b66a64a.tar.xz
Merge branch 'master' into careminster
Conflicts: OpenSim/Data/MySQL/MySQLSimulationData.cs OpenSim/Data/MySQL/Resources/RegionStore.migrations
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting')
-rwxr-xr-xOpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs171
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs99
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs12
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs7
4 files changed, 261 insertions, 28 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs b/OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs
new file mode 100755
index 0000000..6009dc5
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs
@@ -0,0 +1,171 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyrightD
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.Linq;
30using System.Reflection;
31using System.Text;
32
33using OpenSim.Framework;
34using OpenSim.Region.Framework;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Region.CoreModules;
38
39using Mono.Addins;
40using Nini.Config;
41using log4net;
42using OpenMetaverse;
43
44namespace OpenSim.Region.OptionalModules.Scripting
45{
46[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
47public class ExtendedPhysics : INonSharedRegionModule
48{
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 private static string LogHeader = "[EXTENDED PHYSICS]";
51
52 private IConfig Configuration { get; set; }
53 private bool Enabled { get; set; }
54 private Scene BaseScene { get; set; }
55 private IScriptModuleComms Comms { get; set; }
56
57 #region INonSharedRegionModule
58
59 public string Name { get { return this.GetType().Name; } }
60
61 public void Initialise(IConfigSource config)
62 {
63 BaseScene = null;
64 Enabled = false;
65 Configuration = null;
66 Comms = null;
67
68 try
69 {
70 if ((Configuration = config.Configs["ExtendedPhysics"]) != null)
71 {
72 Enabled = Configuration.GetBoolean("Enabled", Enabled);
73 }
74 }
75 catch (Exception e)
76 {
77 m_log.ErrorFormat("{0} Initialization error: {0}", LogHeader, e);
78 }
79
80 m_log.InfoFormat("{0} module {1} enabled", LogHeader, (Enabled ? "is" : "is not"));
81 }
82
83 public void Close()
84 {
85 if (BaseScene != null)
86 {
87 BaseScene.EventManager.OnObjectAddedToScene -= EventManager_OnObjectAddedToScene;
88 BaseScene.EventManager.OnSceneObjectPartUpdated -= EventManager_OnSceneObjectPartUpdated;
89 BaseScene = null;
90 }
91 }
92
93 public void AddRegion(Scene scene)
94 {
95 }
96
97 public void RemoveRegion(Scene scene)
98 {
99 if (BaseScene != null && BaseScene == scene)
100 {
101 Close();
102 }
103 }
104
105 public void RegionLoaded(Scene scene)
106 {
107 if (!Enabled) return;
108
109 BaseScene = scene;
110
111 Comms = BaseScene.RequestModuleInterface<IScriptModuleComms>();
112 if (Comms == null)
113 {
114 m_log.WarnFormat("{0} ScriptModuleComms interface not defined", LogHeader);
115 Enabled = false;
116
117 return;
118 }
119
120 // Register as LSL functions all the [ScriptInvocation] marked methods.
121 Comms.RegisterScriptInvocations(this);
122
123 // When an object is modified, we might need to update its extended physics parameters
124 BaseScene.EventManager.OnObjectAddedToScene += EventManager_OnObjectAddedToScene;
125 BaseScene.EventManager.OnSceneObjectPartUpdated += EventManager_OnSceneObjectPartUpdated;
126
127 }
128
129 public Type ReplaceableInterface { get { return null; } }
130
131 #endregion // INonSharedRegionModule
132
133 private void EventManager_OnObjectAddedToScene(SceneObjectGroup obj)
134 {
135 throw new NotImplementedException();
136 }
137
138 // Event generated when some property of a prim changes.
139 private void EventManager_OnSceneObjectPartUpdated(SceneObjectPart sop, bool isFullUpdate)
140 {
141 }
142
143 [ScriptConstant]
144 public static int PHYS_CENTER_OF_MASS = 1 << 0;
145
146 [ScriptConstant]
147 public static int PHYS_LINKSET_TYPE_CONSTRAINT = 1;
148 [ScriptConstant]
149 public static int PHYS_LINKSET_TYPE_COMPOUND = 2;
150 [ScriptConstant]
151 public static int PHYS_LINKSET_TYPE_MANUAL = 3;
152
153 [ScriptInvocation]
154 public string physGetEngineType(UUID hostID, UUID scriptID)
155 {
156 string ret = string.Empty;
157
158 if (BaseScene.PhysicsScene != null)
159 {
160 ret = BaseScene.PhysicsScene.EngineType;
161 }
162
163 return ret;
164 }
165
166 [ScriptInvocation]
167 public void physSetLinksetType(UUID hostID, UUID scriptID, int linksetType)
168 {
169 }
170}
171}
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
index 088d0cd..3d715cc 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
@@ -81,7 +81,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
81 protected static Regex m_ParsePassFour = new Regex("\\.+"); 81 protected static Regex m_ParsePassFour = new Regex("\\.+");
82 82
83 // expression used to validate the full path, this is canonical representation 83 // expression used to validate the full path, this is canonical representation
84 protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)+$"); 84 protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)*$");
85 85
86 // expression used to match path components 86 // expression used to match path components
87 protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)"); 87 protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)");
@@ -107,9 +107,17 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
107 /// 107 ///
108 /// </summary> 108 /// </summary>
109 // ----------------------------------------------------------------- 109 // -----------------------------------------------------------------
110 public static string CanonicalPathExpression(string path) 110 public static bool CanonicalPathExpression(string ipath, out string opath)
111 { 111 {
112 return PathExpressionToKey(ParsePathExpression(path)); 112 Stack<string> path;
113 if (! ParsePathExpression(ipath,out path))
114 {
115 opath = "";
116 return false;
117 }
118
119 opath = PathExpressionToKey(path);
120 return true;
113 } 121 }
114 122
115 // ----------------------------------------------------------------- 123 // -----------------------------------------------------------------
@@ -139,13 +147,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
139 // ----------------------------------------------------------------- 147 // -----------------------------------------------------------------
140 public bool TestPath(string expr, bool useJson) 148 public bool TestPath(string expr, bool useJson)
141 { 149 {
142 Stack<string> path = ParsePathExpression(expr); 150 Stack<string> path;
151 if (! ParsePathExpression(expr,out path))
152 return false;
153
143 OSD result = ProcessPathExpression(ValueStore,path); 154 OSD result = ProcessPathExpression(ValueStore,path);
144 155
145 if (result == null) 156 if (result == null)
146 return false; 157 return false;
147 158
148 if (useJson || result.Type == OSDType.String) 159 if (useJson || OSDBaseType(result.Type))
149 return true; 160 return true;
150 161
151 return false; 162 return false;
@@ -158,7 +169,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
158 // ----------------------------------------------------------------- 169 // -----------------------------------------------------------------
159 public bool GetValue(string expr, out string value, bool useJson) 170 public bool GetValue(string expr, out string value, bool useJson)
160 { 171 {
161 Stack<string> path = ParsePathExpression(expr); 172 Stack<string> path;
173 if (! ParsePathExpression(expr,out path))
174 {
175 value = "";
176 return false;
177 }
178
162 OSD result = ProcessPathExpression(ValueStore,path); 179 OSD result = ProcessPathExpression(ValueStore,path);
163 return ConvertOutputValue(result,out value,useJson); 180 return ConvertOutputValue(result,out value,useJson);
164 } 181 }
@@ -192,7 +209,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
192 // ----------------------------------------------------------------- 209 // -----------------------------------------------------------------
193 public bool TakeValue(string expr, bool useJson, TakeValueCallback cback) 210 public bool TakeValue(string expr, bool useJson, TakeValueCallback cback)
194 { 211 {
195 Stack<string> path = ParsePathExpression(expr); 212 Stack<string> path;
213 if (! ParsePathExpression(expr,out path))
214 return false;
215
196 string pexpr = PathExpressionToKey(path); 216 string pexpr = PathExpressionToKey(path);
197 217
198 OSD result = ProcessPathExpression(ValueStore,path); 218 OSD result = ProcessPathExpression(ValueStore,path);
@@ -223,7 +243,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
223 // ----------------------------------------------------------------- 243 // -----------------------------------------------------------------
224 public bool ReadValue(string expr, bool useJson, TakeValueCallback cback) 244 public bool ReadValue(string expr, bool useJson, TakeValueCallback cback)
225 { 245 {
226 Stack<string> path = ParsePathExpression(expr); 246 Stack<string> path;
247 if (! ParsePathExpression(expr,out path))
248 return false;
249
227 string pexpr = PathExpressionToKey(path); 250 string pexpr = PathExpressionToKey(path);
228 251
229 OSD result = ProcessPathExpression(ValueStore,path); 252 OSD result = ProcessPathExpression(ValueStore,path);
@@ -253,7 +276,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
253 // ----------------------------------------------------------------- 276 // -----------------------------------------------------------------
254 protected bool SetValueFromExpression(string expr, OSD ovalue) 277 protected bool SetValueFromExpression(string expr, OSD ovalue)
255 { 278 {
256 Stack<string> path = ParsePathExpression(expr); 279 Stack<string> path;
280 if (! ParsePathExpression(expr,out path))
281 return false;
282
257 if (path.Count == 0) 283 if (path.Count == 0)
258 { 284 {
259 ValueStore = ovalue; 285 ValueStore = ovalue;
@@ -399,34 +425,36 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
399 /// use a stack because we process the path in inverse order later 425 /// use a stack because we process the path in inverse order later
400 /// </summary> 426 /// </summary>
401 // ----------------------------------------------------------------- 427 // -----------------------------------------------------------------
402 protected static Stack<string> ParsePathExpression(string path) 428 protected static bool ParsePathExpression(string expr, out Stack<string> path)
403 { 429 {
404 Stack<string> m_path = new Stack<string>(); 430 path = new Stack<string>();
405 431
406 // add front and rear separators 432 // add front and rear separators
407 path = "." + path + "."; 433 expr = "." + expr + ".";
408 434
409 // add separators for quoted paths 435 // add separators for quoted exprs
410 path = m_ParsePassOne.Replace(path,".$0.",-1,0); 436 expr = m_ParsePassOne.Replace(expr,".$0.",-1,0);
411 437
412 // add separators for array references 438 // add separators for array references
413 path = m_ParsePassTwo.Replace(path,".$0.",-1,0); 439 expr = m_ParsePassTwo.Replace(expr,".$0.",-1,0);
414 440
415 // add quotes to bare identifier 441 // add quotes to bare identifier
416 path = m_ParsePassThree.Replace(path,".{$1}",-1,0); 442 expr = m_ParsePassThree.Replace(expr,".{$1}",-1,0);
417 443
418 // remove extra separators 444 // remove extra separators
419 path = m_ParsePassFour.Replace(path,".",-1,0); 445 expr = m_ParsePassFour.Replace(expr,".",-1,0);
420 446
421 // validate the results (catches extra quote characters for example) 447 // validate the results (catches extra quote characters for example)
422 if (m_ValidatePath.IsMatch(path)) 448 if (m_ValidatePath.IsMatch(expr))
423 { 449 {
424 MatchCollection matches = m_PathComponent.Matches(path,0); 450 MatchCollection matches = m_PathComponent.Matches(expr,0);
425 foreach (Match match in matches) 451 foreach (Match match in matches)
426 m_path.Push(match.Groups[1].Value); 452 path.Push(match.Groups[1].Value);
453
454 return true;
427 } 455 }
428 456
429 return m_path; 457 return false;
430 } 458 }
431 459
432 // ----------------------------------------------------------------- 460 // -----------------------------------------------------------------
@@ -531,7 +559,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
531 return true; 559 return true;
532 } 560 }
533 561
534 if (result.Type == OSDType.String) 562 if (OSDBaseType(result.Type))
535 { 563 {
536 value = result.AsString(); 564 value = result.AsString();
537 return true; 565 return true;
@@ -562,6 +590,33 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
562 /// 590 ///
563 /// </summary> 591 /// </summary>
564 // ----------------------------------------------------------------- 592 // -----------------------------------------------------------------
593 protected static bool OSDBaseType(OSDType type)
594 {
595 // Should be the list of base types for which AsString() returns
596 // something useful
597 if (type == OSDType.Boolean)
598 return true;
599 if (type == OSDType.Integer)
600 return true;
601 if (type == OSDType.Real)
602 return true;
603 if (type == OSDType.String)
604 return true;
605 if (type == OSDType.UUID)
606 return true;
607 if (type == OSDType.Date)
608 return true;
609 if (type == OSDType.URI)
610 return true;
611
612 return false;
613 }
614
615 // -----------------------------------------------------------------
616 /// <summary>
617 ///
618 /// </summary>
619 // -----------------------------------------------------------------
565 protected static int ComputeSizeOf(OSD value) 620 protected static int ComputeSizeOf(OSD value)
566 { 621 {
567 string sval; 622 string sval;
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
index d75cd32..e436304 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
@@ -301,7 +301,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
301 [ScriptInvocation] 301 [ScriptInvocation]
302 public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist) 302 public string JsonList2Path(UUID hostID, UUID scriptID, object[] pathlist)
303 { 303 {
304 return JsonStore.CanonicalPathExpression(ConvertList2Path(pathlist)); 304 string ipath = ConvertList2Path(pathlist);
305 string opath;
306
307 if (JsonStore.CanonicalPathExpression(ipath,out opath))
308 return opath;
309
310 // This won't parse if passed to the other routines as opposed to
311 // returning an empty string which is a valid path and would overwrite
312 // the entire store
313 return "**INVALID**";
305 } 314 }
306 315
307 // ----------------------------------------------------------------- 316 // -----------------------------------------------------------------
@@ -421,6 +430,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
421 // ----------------------------------------------------------------- 430 // -----------------------------------------------------------------
422 protected void GenerateRuntimeError(string msg) 431 protected void GenerateRuntimeError(string msg)
423 { 432 {
433 m_log.InfoFormat("[JsonStore] runtime error: {0}",msg);
424 throw new Exception("JsonStore Runtime Error: " + msg); 434 throw new Exception("JsonStore Runtime Error: " + msg);
425 } 435 }
426 436
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
index ca88d1a..af97ac7 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
@@ -144,8 +144,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
144 144
145 int dsrv = (int)InvokeOp("JsonDestroyStore", fakeStoreId); 145 int dsrv = (int)InvokeOp("JsonDestroyStore", fakeStoreId);
146 146
147 // XXX: Current returns 'true' even though no such store existed. Need to ask if this is best behaviour. 147 Assert.That(dsrv, Is.EqualTo(0));
148 Assert.That(dsrv, Is.EqualTo(1));
149 } 148 }
150 149
151 [Test] 150 [Test]
@@ -211,9 +210,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
211 210
212 // Test remove of non-existing value 211 // Test remove of non-existing value
213 int fakeValueRemove = (int)InvokeOp("JsonRemoveValue", storeId, "Hello"); 212 int fakeValueRemove = (int)InvokeOp("JsonRemoveValue", storeId, "Hello");
214 213 Assert.That(fakeValueRemove, Is.EqualTo(0));
215 // XXX: Is this the best response to removing a value that isn't there?
216 Assert.That(fakeValueRemove, Is.EqualTo(1));
217 214
218 // Test get from non-existing store 215 // Test get from non-existing store
219 UUID fakeStoreId = TestHelpers.ParseTail(0x500); 216 UUID fakeStoreId = TestHelpers.ParseTail(0x500);