From 8e72b53edc435c2c2fbec0b8c91304e7f7a6a4f2 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Mon, 20 Jan 2014 19:16:19 +0000
Subject: Stop exceptions being generated on agent connection if a telehub
object has been deleted or has no spawn points.
---
OpenSim/Framework/RegionSettings.cs | 21 ++--
.../World/Estate/EstateManagementCommands.cs | 2 +-
.../World/Estate/EstateManagementModule.cs | 8 +-
OpenSim/Region/Framework/Scenes/Scene.cs | 50 ++++++---
.../Framework/Scenes/Tests/SceneTelehubTests.cs | 119 +++++++++++++++++++++
OpenSim/Tests/Common/Mock/TestClient.cs | 5 -
OpenSim/Tests/Common/TestHelpers.cs | 21 +++-
7 files changed, 186 insertions(+), 40 deletions(-)
create mode 100644 OpenSim/Region/Framework/Scenes/Tests/SceneTelehubTests.cs
diff --git a/OpenSim/Framework/RegionSettings.cs b/OpenSim/Framework/RegionSettings.cs
index db8c53e..a895c40 100644
--- a/OpenSim/Framework/RegionSettings.cs
+++ b/OpenSim/Framework/RegionSettings.cs
@@ -482,21 +482,14 @@ namespace OpenSim.Framework
set { m_LoadedCreationID = value; }
}
- // Connected Telehub object
- private UUID m_TelehubObject = UUID.Zero;
- public UUID TelehubObject
- {
- get
- {
- return m_TelehubObject;
- }
- set
- {
- m_TelehubObject = value;
- }
- }
+ ///
+ /// Connected Telehub object
+ ///
+ public UUID TelehubObject { get; set; }
- // Our Connected Telehub's SpawnPoints
+ ///
+ /// Our connected Telehub's SpawnPoints
+ ///
public List l_SpawnPoints = new List();
// Add a SpawnPoint
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs
index 173b603..1659493 100644
--- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs
+++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementCommands.cs
@@ -60,7 +60,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
public void Initialise()
{
- m_log.DebugFormat("[ESTATE MODULE]: Setting up estate commands for region {0}", m_module.Scene.RegionInfo.RegionName);
+// m_log.DebugFormat("[ESTATE MODULE]: Setting up estate commands for region {0}", m_module.Scene.RegionInfo.RegionName);
m_module.Scene.AddCommand("Regions", m_module, "set terrain texture",
"set terrain texture [] []",
diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
index 17387da..3bd7b4a 100644
--- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
+++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs
@@ -702,7 +702,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
}
}
- public void handleOnEstateManageTelehub(IClientAPI client, UUID invoice, UUID senderID, string cmd, uint param1)
+ public void HandleOnEstateManageTelehub(IClientAPI client, UUID invoice, UUID senderID, string cmd, uint param1)
{
SceneObjectPart part;
@@ -742,7 +742,9 @@ namespace OpenSim.Region.CoreModules.World.Estate
default:
break;
}
- SendTelehubInfo(client);
+
+ if (client != null)
+ SendTelehubInfo(client);
}
private void SendSimulatorBlueBoxMessage(
@@ -1214,7 +1216,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
client.OnEstateRestartSimRequest += handleEstateRestartSimRequest;
client.OnEstateChangeCovenantRequest += handleChangeEstateCovenantRequest;
client.OnEstateChangeInfo += handleEstateChangeInfo;
- client.OnEstateManageTelehub += handleOnEstateManageTelehub;
+ client.OnEstateManageTelehub += HandleOnEstateManageTelehub;
client.OnUpdateEstateAccessDeltaRequest += handleEstateAccessDeltaRequest;
client.OnSimulatorBlueBoxMessageRequest += SendSimulatorBlueBoxMessage;
client.OnEstateBlueBoxMessageRequest += SendEstateBlueBoxMessage;
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 567ce2a..59c5b09 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -3946,32 +3946,52 @@ namespace OpenSim.Region.Framework.Scenes
}
}
+// m_log.DebugFormat(
+// "[SCENE]: Found telehub object {0} for new user connection {1} to {2}",
+// RegionInfo.RegionSettings.TelehubObject, acd.Name, Name);
+
// Honor Estate teleport routing via Telehubs excluding ViaHome and GodLike TeleportFlags
if (RegionInfo.RegionSettings.TelehubObject != UUID.Zero &&
RegionInfo.EstateSettings.AllowDirectTeleport == false &&
!viahome && !godlike)
{
SceneObjectGroup telehub = GetSceneObjectGroup(RegionInfo.RegionSettings.TelehubObject);
- // Can have multiple SpawnPoints
- List spawnpoints = RegionInfo.RegionSettings.SpawnPoints();
- if (spawnpoints.Count > 1)
+
+ if (telehub != null)
{
- // We have multiple SpawnPoints, Route the agent to a random or sequential one
- if (SpawnPointRouting == "random")
- acd.startpos = spawnpoints[Util.RandomClass.Next(spawnpoints.Count) - 1].GetLocation(
- telehub.AbsolutePosition,
- telehub.GroupRotation
- );
+ // Can have multiple SpawnPoints
+ List spawnpoints = RegionInfo.RegionSettings.SpawnPoints();
+ if (spawnpoints.Count > 1)
+ {
+ // We have multiple SpawnPoints, Route the agent to a random or sequential one
+ if (SpawnPointRouting == "random")
+ acd.startpos = spawnpoints[Util.RandomClass.Next(spawnpoints.Count) - 1].GetLocation(
+ telehub.AbsolutePosition,
+ telehub.GroupRotation
+ );
+ else
+ acd.startpos = spawnpoints[SpawnPoint()].GetLocation(
+ telehub.AbsolutePosition,
+ telehub.GroupRotation
+ );
+ }
+ else if (spawnpoints.Count == 1)
+ {
+ // We have a single SpawnPoint and will route the agent to it
+ acd.startpos = spawnpoints[0].GetLocation(telehub.AbsolutePosition, telehub.GroupRotation);
+ }
else
- acd.startpos = spawnpoints[SpawnPoint()].GetLocation(
- telehub.AbsolutePosition,
- telehub.GroupRotation
- );
+ {
+ m_log.DebugFormat(
+ "[SCENE]: No spawnpoints defined for telehub {0} for {1} in {2}. Continuing.",
+ RegionInfo.RegionSettings.TelehubObject, acd.Name, Name);
+ }
}
else
{
- // We have a single SpawnPoint and will route the agent to it
- acd.startpos = spawnpoints[0].GetLocation(telehub.AbsolutePosition, telehub.GroupRotation);
+ m_log.DebugFormat(
+ "[SCENE]: No telehub {0} found to direct {1} in {2}. Continuing.",
+ RegionInfo.RegionSettings.TelehubObject, acd.Name, Name);
}
return true;
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneTelehubTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneTelehubTests.cs
new file mode 100644
index 0000000..9a97acc
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneTelehubTests.cs
@@ -0,0 +1,119 @@
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSimulator Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using Nini.Config;
+using NUnit.Framework;
+using OpenMetaverse;
+using OpenSim.Framework;
+using OpenSim.Region.CoreModules.World.Estate;
+using OpenSim.Region.Framework.Scenes;
+using OpenSim.Region.Framework.Interfaces;
+using OpenSim.Services.Interfaces;
+using OpenSim.Tests.Common;
+using OpenSim.Tests.Common.Mock;
+
+namespace OpenSim.Region.Framework.Scenes.Tests
+{
+ ///
+ /// Scene telehub tests
+ ///
+ ///
+ /// TODO: Tests which run through normal functionality. Currently, the only test is one that checks behaviour
+ /// in the case of an error condition
+ ///
+ [TestFixture]
+ public class SceneTelehubTests : OpenSimTestCase
+ {
+ ///
+ /// Test for desired behaviour when a telehub has no spawn points
+ ///
+ [Test]
+ public void TestNoTelehubSpawnPoints()
+ {
+ TestHelpers.InMethod();
+// TestHelpers.EnableLogging();
+
+ EstateManagementModule emm = new EstateManagementModule();
+
+ SceneHelpers sh = new SceneHelpers();
+ Scene scene = sh.SetupScene();
+ SceneHelpers.SetupSceneModules(scene, emm);
+
+ UUID telehubSceneObjectOwner = TestHelpers.ParseTail(0x1);
+
+ SceneObjectGroup telehubSo = SceneHelpers.AddSceneObject(scene, "telehubObject", telehubSceneObjectOwner);
+
+ emm.HandleOnEstateManageTelehub(null, UUID.Zero, UUID.Zero, "connect", telehubSo.LocalId);
+ scene.RegionInfo.EstateSettings.AllowDirectTeleport = false;
+
+ // Must still be possible to successfully log in
+ UUID loggingInUserId = TestHelpers.ParseTail(0x2);
+
+ UserAccount ua
+ = UserAccountHelpers.CreateUserWithInventory(scene, "Test", "User", loggingInUserId, "password");
+
+ SceneHelpers.AddScenePresence(scene, ua);
+
+ Assert.That(scene.GetScenePresence(loggingInUserId), Is.Not.Null);
+ }
+
+ ///
+ /// Test for desired behaviour when the scene object nominated as a telehub object does not exist.
+ ///
+ [Test]
+ public void TestNoTelehubSceneObject()
+ {
+ TestHelpers.InMethod();
+// TestHelpers.EnableLogging();
+
+ EstateManagementModule emm = new EstateManagementModule();
+
+ SceneHelpers sh = new SceneHelpers();
+ Scene scene = sh.SetupScene();
+ SceneHelpers.SetupSceneModules(scene, emm);
+
+ UUID telehubSceneObjectOwner = TestHelpers.ParseTail(0x1);
+
+ SceneObjectGroup telehubSo = SceneHelpers.AddSceneObject(scene, "telehubObject", telehubSceneObjectOwner);
+ SceneObjectGroup spawnPointSo = SceneHelpers.AddSceneObject(scene, "spawnpointObject", telehubSceneObjectOwner);
+
+ emm.HandleOnEstateManageTelehub(null, UUID.Zero, UUID.Zero, "connect", telehubSo.LocalId);
+ emm.HandleOnEstateManageTelehub(null, UUID.Zero, UUID.Zero, "spawnpoint add", spawnPointSo.LocalId);
+ scene.RegionInfo.EstateSettings.AllowDirectTeleport = false;
+
+ scene.DeleteSceneObject(telehubSo, false);
+
+ // Must still be possible to successfully log in
+ UUID loggingInUserId = TestHelpers.ParseTail(0x2);
+
+ UserAccount ua
+ = UserAccountHelpers.CreateUserWithInventory(scene, "Test", "User", loggingInUserId, "password");
+
+ SceneHelpers.AddScenePresence(scene, ua);
+
+ Assert.That(scene.GetScenePresence(loggingInUserId), Is.Not.Null);
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenSim/Tests/Common/Mock/TestClient.cs b/OpenSim/Tests/Common/Mock/TestClient.cs
index 9370102..a4247e3 100644
--- a/OpenSim/Tests/Common/Mock/TestClient.cs
+++ b/OpenSim/Tests/Common/Mock/TestClient.cs
@@ -788,11 +788,6 @@ namespace OpenSim.Tests.Common.Mock
{
OnRegionHandShakeReply(this);
}
-
- if (OnCompleteMovementToRegion != null)
- {
- OnCompleteMovementToRegion(this, true);
- }
}
public void SendAssetUploadCompleteMessage(sbyte AssetType, bool Success, UUID AssetFullID)
diff --git a/OpenSim/Tests/Common/TestHelpers.cs b/OpenSim/Tests/Common/TestHelpers.cs
index a684d72..6bf23f8 100644
--- a/OpenSim/Tests/Common/TestHelpers.cs
+++ b/OpenSim/Tests/Common/TestHelpers.cs
@@ -117,8 +117,6 @@ namespace OpenSim.Tests.Common
/// Parse a UUID stem into a full UUID.
///
///
- /// Yes, this is completely inconsistent with ParseTail but this is probably a better way to do it,
- /// UUIDs are conceptually not hexadecmial numbers.
/// The fragment will come at the start of the UUID. The rest will be 0s
///
///
@@ -143,5 +141,24 @@ namespace OpenSim.Tests.Common
{
return new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", tail));
}
+
+ ///
+ /// Parse a UUID tail section into a full UUID.
+ ///
+ ///
+ /// The fragment will come at the end of the UUID. The rest will be 0s
+ ///
+ ///
+ ///
+ /// A UUID fragment that will be parsed into a full UUID. Therefore, it can only contain
+ /// cahracters which are valid in a UUID, except for "-" which is currently only allowed if a full UUID is
+ /// given as the 'fragment'.
+ ///
+ public static UUID ParseTail(string stem)
+ {
+ string rawUuid = stem.PadLeft(32, '0');
+
+ return UUID.Parse(rawUuid);
+ }
}
}
--
cgit v1.1
From 2e78e89c36e661f72773e54f97bec3f04af67b79 Mon Sep 17 00:00:00 2001
From: Mic Bowman
Date: Mon, 20 Jan 2014 11:33:49 -0800
Subject: Clean up orphaned json stores. This can happen when an object is
removed, when a script is removed, or when a script is reset. Also added a
stats command to track the number of json stores used by a region. Will
probably add some more commands later.
---
.../Framework/Interfaces/IJsonStoreModule.cs | 7 +
.../Scripting/JsonStore/JsonStoreCommands.cs | 195 +++++++++++++++++++++
.../Scripting/JsonStore/JsonStoreModule.cs | 41 ++++-
.../Scripting/JsonStore/JsonStoreScriptModule.cs | 41 ++++-
4 files changed, 281 insertions(+), 3 deletions(-)
create mode 100644 OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreCommands.cs
diff --git a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs
index b67312e..1a89721 100644
--- a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs
@@ -51,10 +51,17 @@ namespace OpenSim.Region.Framework.Interfaces
UUID = 5
}
+ public struct JsonStoreStats
+ {
+ public int StoreCount;
+ }
+
public delegate void TakeValueCallback(string s);
public interface IJsonStoreModule
{
+ JsonStoreStats GetStoreStats();
+
bool AttachObjectStore(UUID objectID);
bool CreateStore(string value, ref UUID result);
bool DestroyStore(UUID storeID);
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreCommands.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreCommands.cs
new file mode 100644
index 0000000..d4b19dd
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreCommands.cs
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) Contributors
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSim Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using Mono.Addins;
+
+using System;
+using System.Reflection;
+using System.Threading;
+using System.Text;
+using System.Net;
+using System.Net.Sockets;
+using log4net;
+using Nini.Config;
+using OpenMetaverse;
+using OpenMetaverse.StructuredData;
+using OpenSim.Framework;
+using OpenSim.Region.Framework.Interfaces;
+using OpenSim.Region.Framework.Scenes;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+
+namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
+{
+ [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreCommandsModule")]
+
+ public class JsonStoreCommandsModule : INonSharedRegionModule
+ {
+ private static readonly ILog m_log =
+ LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
+ private IConfig m_config = null;
+ private bool m_enabled = false;
+
+ private Scene m_scene = null;
+ //private IJsonStoreModule m_store;
+ private JsonStoreModule m_store;
+
+#region Region Module interface
+
+ // -----------------------------------------------------------------
+ ///
+ /// Name of this shared module is it's class name
+ ///
+ // -----------------------------------------------------------------
+ public string Name
+ {
+ get { return this.GetType().Name; }
+ }
+
+ // -----------------------------------------------------------------
+ ///
+ /// Initialise this shared module
+ ///
+ /// this region is getting initialised
+ /// nini config, we are not using this
+ // -----------------------------------------------------------------
+ public void Initialise(IConfigSource config)
+ {
+ try
+ {
+ if ((m_config = config.Configs["JsonStore"]) == null)
+ {
+ // There is no configuration, the module is disabled
+ // m_log.InfoFormat("[JsonStore] no configuration info");
+ return;
+ }
+
+ m_enabled = m_config.GetBoolean("Enabled", m_enabled);
+ }
+ catch (Exception e)
+ {
+ m_log.Error("[JsonStore]: initialization error: {0}", e);
+ return;
+ }
+
+ if (m_enabled)
+ m_log.DebugFormat("[JsonStore]: module is enabled");
+ }
+
+ // -----------------------------------------------------------------
+ ///
+ /// everything is loaded, perform post load configuration
+ ///
+ // -----------------------------------------------------------------
+ public void PostInitialise()
+ {
+ }
+
+ // -----------------------------------------------------------------
+ ///
+ /// Nothing to do on close
+ ///
+ // -----------------------------------------------------------------
+ public void Close()
+ {
+ }
+
+ // -----------------------------------------------------------------
+ ///
+ ///
+ // -----------------------------------------------------------------
+ public void AddRegion(Scene scene)
+ {
+ if (m_enabled)
+ {
+ m_scene = scene;
+
+ }
+ }
+
+ // -----------------------------------------------------------------
+ ///
+ ///
+ // -----------------------------------------------------------------
+ public void RemoveRegion(Scene scene)
+ {
+ // need to remove all references to the scene in the subscription
+ // list to enable full garbage collection of the scene object
+ }
+
+ // -----------------------------------------------------------------
+ ///
+ /// Called when all modules have been added for a region. This is
+ /// where we hook up events
+ ///
+ // -----------------------------------------------------------------
+ public void RegionLoaded(Scene scene)
+ {
+ if (m_enabled)
+ {
+ m_scene = scene;
+
+ m_store = (JsonStoreModule) m_scene.RequestModuleInterface();
+ if (m_store == null)
+ {
+ m_log.ErrorFormat("[JsonStoreCommands]: JsonModule interface not defined");
+ m_enabled = false;
+ return;
+ }
+
+ scene.AddCommand("JsonStore", this, "jsonstore stats", "jsonstore stats",
+ "Display statistics about the state of the JsonStore module", "",
+ CmdStats);
+ }
+ }
+
+ /// -----------------------------------------------------------------
+ ///
+ ///
+ // -----------------------------------------------------------------
+ public Type ReplaceableInterface
+ {
+ get { return null; }
+ }
+
+#endregion
+
+#region Commands
+
+ private void CmdStats(string module, string[] cmd)
+ {
+ if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
+ return;
+
+ JsonStoreStats stats = m_store.GetStoreStats();
+ MainConsole.Instance.OutputFormat("{0}\t{1}",m_scene.RegionInfo.RegionName,stats.StoreCount);
+ }
+
+#endregion
+
+ }
+}
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
index 5fbfcc5..b502a55 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
@@ -42,7 +42,6 @@ using OpenSim.Region.Framework.Scenes;
using System.Collections.Generic;
using System.Text.RegularExpressions;
-
namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreModule")]
@@ -60,6 +59,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
private Scene m_scene = null;
private Dictionary m_JsonValueStore;
+
private UUID m_sharedStore;
#region Region Module interface
@@ -140,6 +140,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
m_sharedStore = UUID.Zero;
m_JsonValueStore = new Dictionary();
m_JsonValueStore.Add(m_sharedStore,new JsonStore(""));
+
+ scene.EventManager.OnObjectBeingRemovedFromScene += EventManagerOnObjectBeingRemovedFromScene;
}
}
@@ -149,6 +151,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
// -----------------------------------------------------------------
public void RemoveRegion(Scene scene)
{
+ scene.EventManager.OnObjectBeingRemovedFromScene -= EventManagerOnObjectBeingRemovedFromScene;
+
// need to remove all references to the scene in the subscription
// list to enable full garbage collection of the scene object
}
@@ -161,7 +165,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
// -----------------------------------------------------------------
public void RegionLoaded(Scene scene)
{
- if (m_enabled) {}
+ if (m_enabled)
+ {
+ }
}
/// -----------------------------------------------------------------
@@ -175,8 +181,39 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
#endregion
+#region SceneEvents
+ // -----------------------------------------------------------------
+ ///
+ ///
+ ///
+ // -----------------------------------------------------------------
+ public void EventManagerOnObjectBeingRemovedFromScene(SceneObjectGroup obj)
+ {
+ obj.ForEachPart(delegate(SceneObjectPart sop) { DestroyStore(sop.UUID); } );
+ }
+
+#endregion
+
#region ScriptInvocationInteface
+
+ // -----------------------------------------------------------------
+ ///
+ ///
+ ///
+ // -----------------------------------------------------------------
+ public JsonStoreStats GetStoreStats()
+ {
+ JsonStoreStats stats;
+
+ lock (m_JsonValueStore)
+ {
+ stats.StoreCount = m_JsonValueStore.Count;
+ }
+
+ return stats;
+ }
+
// -----------------------------------------------------------------
///
///
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
index 1bb5aee..9fbfb66 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
@@ -59,7 +59,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
private IScriptModuleComms m_comms;
private IJsonStoreModule m_store;
-
+
+ private Dictionary> m_scriptStores = new Dictionary>();
+
#region Region Module interface
// -----------------------------------------------------------------
@@ -126,6 +128,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
// -----------------------------------------------------------------
public void AddRegion(Scene scene)
{
+ scene.EventManager.OnScriptReset += HandleScriptReset;
+ scene.EventManager.OnRemoveScript += HandleScriptReset;
}
// -----------------------------------------------------------------
@@ -134,12 +138,34 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
// -----------------------------------------------------------------
public void RemoveRegion(Scene scene)
{
+ scene.EventManager.OnScriptReset -= HandleScriptReset;
+ scene.EventManager.OnRemoveScript -= HandleScriptReset;
+
// need to remove all references to the scene in the subscription
// list to enable full garbage collection of the scene object
}
// -----------------------------------------------------------------
///
+ ///
+ // -----------------------------------------------------------------
+ private void HandleScriptReset(uint localID, UUID itemID)
+ {
+ HashSet stores;
+
+ lock (m_scriptStores)
+ {
+ if (! m_scriptStores.TryGetValue(itemID, out stores))
+ return;
+ m_scriptStores.Remove(itemID);
+ }
+
+ foreach (UUID id in stores)
+ m_store.DestroyStore(id);
+ }
+
+ // -----------------------------------------------------------------
+ ///
/// Called when all modules have been added for a region. This is
/// where we hook up events
///
@@ -250,6 +276,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
if (! m_store.CreateStore(value, ref uuid))
GenerateRuntimeError("Failed to create Json store");
+ lock (m_scriptStores)
+ {
+ if (! m_scriptStores.ContainsKey(scriptID))
+ m_scriptStores[scriptID] = new HashSet();
+
+ m_scriptStores[scriptID].Add(uuid);
+ }
return uuid;
}
@@ -261,6 +294,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
[ScriptInvocation]
public int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID)
{
+ lock(m_scriptStores)
+ {
+ if (m_scriptStores.ContainsKey(scriptID))
+ m_scriptStores[scriptID].Remove(storeID);
+ }
+
return m_store.DestroyStore(storeID) ? 1 : 0;
}
--
cgit v1.1