aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting
diff options
context:
space:
mode:
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.cs82
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs17
3 files changed, 266 insertions, 4 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 c7f0001..5c89717 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
@@ -95,6 +95,15 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
95 95
96 // ----------------------------------------------------------------- 96 // -----------------------------------------------------------------
97 /// <summary> 97 /// <summary>
98 /// This is a simple estimator for the size of the stored data, it
99 /// is not precise, but should be close enough to implement reasonable
100 /// limits on the storage space used
101 /// </summary>
102 // -----------------------------------------------------------------
103 public int StringSpace { get; set; }
104
105 // -----------------------------------------------------------------
106 /// <summary>
98 /// 107 ///
99 /// </summary> 108 /// </summary>
100 // ----------------------------------------------------------------- 109 // -----------------------------------------------------------------
@@ -110,6 +119,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
110 // ----------------------------------------------------------------- 119 // -----------------------------------------------------------------
111 public JsonStore() 120 public JsonStore()
112 { 121 {
122 StringSpace = 0;
113 m_TakeStore = new List<TakeValueCallbackClass>(); 123 m_TakeStore = new List<TakeValueCallbackClass>();
114 m_ReadStore = new List<TakeValueCallbackClass>(); 124 m_ReadStore = new List<TakeValueCallbackClass>();
115 } 125 }
@@ -135,7 +145,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
135 if (result == null) 145 if (result == null)
136 return false; 146 return false;
137 147
138 if (useJson || result.Type == OSDType.String) 148 if (useJson || OSDBaseType(result.Type))
139 return true; 149 return true;
140 150
141 return false; 151 return false;
@@ -247,6 +257,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
247 if (path.Count == 0) 257 if (path.Count == 0)
248 { 258 {
249 ValueStore = ovalue; 259 ValueStore = ovalue;
260 StringSpace = 0;
250 return true; 261 return true;
251 } 262 }
252 263
@@ -278,8 +289,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
278 { 289 {
279 string npkey = String.Format("[{0}]",amap.Count); 290 string npkey = String.Format("[{0}]",amap.Count);
280 291
281 amap.Add(ovalue); 292 if (ovalue != null)
282 InvokeNextCallback(pexpr + npkey); 293 {
294 StringSpace += ComputeSizeOf(ovalue);
295
296 amap.Add(ovalue);
297 InvokeNextCallback(pexpr + npkey);
298 }
283 return true; 299 return true;
284 } 300 }
285 301
@@ -287,9 +303,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
287 if (0 <= aval && aval < amap.Count) 303 if (0 <= aval && aval < amap.Count)
288 { 304 {
289 if (ovalue == null) 305 if (ovalue == null)
306 {
307 StringSpace -= ComputeSizeOf(amap[aval]);
290 amap.RemoveAt(aval); 308 amap.RemoveAt(aval);
309 }
291 else 310 else
292 { 311 {
312 StringSpace -= ComputeSizeOf(amap[aval]);
313 StringSpace += ComputeSizeOf(ovalue);
293 amap[aval] = ovalue; 314 amap[aval] = ovalue;
294 InvokeNextCallback(pexpr + pkey); 315 InvokeNextCallback(pexpr + pkey);
295 } 316 }
@@ -313,6 +334,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
313 OSDMap hmap = result as OSDMap; 334 OSDMap hmap = result as OSDMap;
314 if (ovalue != null) 335 if (ovalue != null)
315 { 336 {
337 StringSpace -= ComputeSizeOf(hmap[hkey]);
338 StringSpace += ComputeSizeOf(ovalue);
339
316 hmap[hkey] = ovalue; 340 hmap[hkey] = ovalue;
317 InvokeNextCallback(pexpr + pkey); 341 InvokeNextCallback(pexpr + pkey);
318 return true; 342 return true;
@@ -321,6 +345,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
321 // this is the remove case 345 // this is the remove case
322 if (hmap.ContainsKey(hkey)) 346 if (hmap.ContainsKey(hkey))
323 { 347 {
348 StringSpace -= ComputeSizeOf(hmap[hkey]);
324 hmap.Remove(hkey); 349 hmap.Remove(hkey);
325 return true; 350 return true;
326 } 351 }
@@ -506,7 +531,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
506 return true; 531 return true;
507 } 532 }
508 533
509 if (result.Type == OSDType.String) 534 if (OSDBaseType(result.Type))
510 { 535 {
511 value = result.AsString(); 536 value = result.AsString();
512 return true; 537 return true;
@@ -531,8 +556,54 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
531 556
532 return pkey; 557 return pkey;
533 } 558 }
559
560 // -----------------------------------------------------------------
561 /// <summary>
562 ///
563 /// </summary>
564 // -----------------------------------------------------------------
565 protected static bool OSDBaseType(OSDType type)
566 {
567 // Should be the list of base types for which AsString() returns
568 // something useful
569 if (type == OSDType.Boolean)
570 return true;
571 if (type == OSDType.Integer)
572 return true;
573 if (type == OSDType.Real)
574 return true;
575 if (type == OSDType.String)
576 return true;
577 if (type == OSDType.UUID)
578 return true;
579 if (type == OSDType.Date)
580 return true;
581 if (type == OSDType.URI)
582 return true;
583
584 return false;
585 }
586
587 // -----------------------------------------------------------------
588 /// <summary>
589 ///
590 /// </summary>
591 // -----------------------------------------------------------------
592 protected static int ComputeSizeOf(OSD value)
593 {
594 string sval;
595
596 if (ConvertOutputValue(value,out sval,true))
597 return sval.Length;
598
599 return 0;
600 }
534 } 601 }
535 602
603 // -----------------------------------------------------------------
604 /// <summary>
605 /// </summary>
606 // -----------------------------------------------------------------
536 public class JsonObjectStore : JsonStore 607 public class JsonObjectStore : JsonStore
537 { 608 {
538 private static readonly ILog m_log = 609 private static readonly ILog m_log =
@@ -566,6 +637,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
566 { 637 {
567 m_scene = scene; 638 m_scene = scene;
568 m_objectID = oid; 639 m_objectID = oid;
640
641 // the size limit is imposed on whatever is already in the store
642 StringSpace = ComputeSizeOf(ValueStore);
569 } 643 }
570 } 644 }
571 645
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
index 3249aa3..f1ce856 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
@@ -54,6 +54,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
54 54
55 private IConfig m_config = null; 55 private IConfig m_config = null;
56 private bool m_enabled = false; 56 private bool m_enabled = false;
57 private bool m_enableObjectStore = false;
58 private int m_maxStringSpace = Int32.MaxValue;
59
57 private Scene m_scene = null; 60 private Scene m_scene = null;
58 61
59 private Dictionary<UUID,JsonStore> m_JsonValueStore; 62 private Dictionary<UUID,JsonStore> m_JsonValueStore;
@@ -90,6 +93,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
90 } 93 }
91 94
92 m_enabled = m_config.GetBoolean("Enabled", m_enabled); 95 m_enabled = m_config.GetBoolean("Enabled", m_enabled);
96 m_enableObjectStore = m_config.GetBoolean("EnableObjectStore", m_enableObjectStore);
97 m_maxStringSpace = m_config.GetInt("MaxStringSpace", m_maxStringSpace);
98 if (m_maxStringSpace == 0)
99 m_maxStringSpace = Int32.MaxValue;
93 } 100 }
94 catch (Exception e) 101 catch (Exception e)
95 { 102 {
@@ -178,6 +185,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
178 public bool AttachObjectStore(UUID objectID) 185 public bool AttachObjectStore(UUID objectID)
179 { 186 {
180 if (! m_enabled) return false; 187 if (! m_enabled) return false;
188 if (! m_enableObjectStore) return false;
181 189
182 SceneObjectPart sop = m_scene.GetSceneObjectPart(objectID); 190 SceneObjectPart sop = m_scene.GetSceneObjectPart(objectID);
183 if (sop == null) 191 if (sop == null)
@@ -311,7 +319,16 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
311 try 319 try
312 { 320 {
313 lock (map) 321 lock (map)
322 {
323 if (map.StringSpace > m_maxStringSpace)
324 {
325 m_log.WarnFormat("[JsonStore] {0} exceeded string size; {1} bytes used of {2} limit",
326 storeID,map.StringSpace,m_maxStringSpace);
327 return false;
328 }
329
314 return map.SetValue(path,value,useJson); 330 return map.SetValue(path,value,useJson);
331 }
315 } 332 }
316 catch (Exception e) 333 catch (Exception e)
317 { 334 {