From 317aebcce6618cacbe3afd831c3e100b96665be2 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 14 Apr 2012 01:47:56 +0100 Subject: [PATCH 01/21] refactor: put SOG position test in a separate TestSceneObjectGroupPosition() --- .../Scenes/Tests/SceneObjectSpatialTests.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs index 19526c02fb..3509de1309 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs @@ -44,6 +44,23 @@ namespace OpenSim.Region.Framework.Scenes.Tests [TestFixture] public class SceneObjectSpatialTests { + [Test] + public void TestSceneObjectGroupPosition() + { + TestHelpers.InMethod(); + + Scene scene = SceneHelpers.SetupScene(); + UUID ownerId = TestHelpers.ParseTail(0x1); + Vector3 position = new Vector3(10, 20, 30); + + SceneObjectGroup so + = SceneHelpers.CreateSceneObject(1, ownerId, "obj1", 0x10); + so.AbsolutePosition = position; + scene.AddNewSceneObject(so, false); + + Assert.That(so.AbsolutePosition, Is.EqualTo(position)); + } + [Test] public void TestGetRootPartPosition() { @@ -58,7 +75,6 @@ namespace OpenSim.Region.Framework.Scenes.Tests so.AbsolutePosition = partPosition; scene.AddNewSceneObject(so, false); - Assert.That(so.AbsolutePosition, Is.EqualTo(partPosition)); Assert.That(so.RootPart.AbsolutePosition, Is.EqualTo(partPosition)); Assert.That(so.RootPart.OffsetPosition, Is.EqualTo(Vector3.Zero)); Assert.That(so.RootPart.RelativePosition, Is.EqualTo(partPosition)); From f61b2342524023b89725e3473b8332fe6a8e71ca Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 14 Apr 2012 01:52:16 +0100 Subject: [PATCH 02/21] refactor: move common init code into SetUp() in SceneObjectSpatialTests --- .../Scenes/Tests/SceneObjectSpatialTests.cs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs index 3509de1309..69b5b1f3be 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs @@ -44,19 +44,26 @@ namespace OpenSim.Region.Framework.Scenes.Tests [TestFixture] public class SceneObjectSpatialTests { + TestScene m_scene; + UUID m_ownerId = TestHelpers.ParseTail(0x1); + + [SetUp] + public void SetUp() + { + m_scene = SceneHelpers.SetupScene(); + } + [Test] public void TestSceneObjectGroupPosition() { TestHelpers.InMethod(); - Scene scene = SceneHelpers.SetupScene(); - UUID ownerId = TestHelpers.ParseTail(0x1); Vector3 position = new Vector3(10, 20, 30); SceneObjectGroup so - = SceneHelpers.CreateSceneObject(1, ownerId, "obj1", 0x10); + = SceneHelpers.CreateSceneObject(1, m_ownerId, "obj1", 0x10); so.AbsolutePosition = position; - scene.AddNewSceneObject(so, false); + m_scene.AddNewSceneObject(so, false); Assert.That(so.AbsolutePosition, Is.EqualTo(position)); } @@ -66,14 +73,12 @@ namespace OpenSim.Region.Framework.Scenes.Tests { TestHelpers.InMethod(); - Scene scene = SceneHelpers.SetupScene(); - UUID ownerId = TestHelpers.ParseTail(0x1); Vector3 partPosition = new Vector3(10, 20, 30); SceneObjectGroup so - = SceneHelpers.CreateSceneObject(1, ownerId, "obj1", 0x10); + = SceneHelpers.CreateSceneObject(1, m_ownerId, "obj1", 0x10); so.AbsolutePosition = partPosition; - scene.AddNewSceneObject(so, false); + m_scene.AddNewSceneObject(so, false); Assert.That(so.RootPart.AbsolutePosition, Is.EqualTo(partPosition)); Assert.That(so.RootPart.OffsetPosition, Is.EqualTo(Vector3.Zero)); From da342d0b21b867061a3f3a502256331c609e1564 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 14 Apr 2012 01:53:40 +0100 Subject: [PATCH 03/21] minor: make test names consistent --- .../Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs index 69b5b1f3be..c38a22dd24 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs @@ -54,7 +54,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests } [Test] - public void TestSceneObjectGroupPosition() + public void TestGetSceneObjectGroupPosition() { TestHelpers.InMethod(); From 2c74e1bba8d93a1c3b95da913bc3de0aae6dca4a Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Sat, 14 Apr 2012 01:57:09 +0100 Subject: [PATCH 04/21] Add GroupPosition and GetWorldPosition() checks to TestGetRootPartPosition() --- .../Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs index c38a22dd24..7a3b3627e0 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs @@ -81,8 +81,10 @@ namespace OpenSim.Region.Framework.Scenes.Tests m_scene.AddNewSceneObject(so, false); Assert.That(so.RootPart.AbsolutePosition, Is.EqualTo(partPosition)); - Assert.That(so.RootPart.OffsetPosition, Is.EqualTo(Vector3.Zero)); + Assert.That(so.RootPart.GroupPosition, Is.EqualTo(partPosition)); + Assert.That(so.RootPart.GetWorldPosition(), Is.EqualTo(partPosition)); Assert.That(so.RootPart.RelativePosition, Is.EqualTo(partPosition)); + Assert.That(so.RootPart.OffsetPosition, Is.EqualTo(Vector3.Zero)); } } } \ No newline at end of file From f213f55586b9af66955fdfccdd50237febaf98ca Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 17 Apr 2012 00:02:58 +0100 Subject: [PATCH 05/21] Fix bug in WebStatsModule where an exception would always be output on update if the user teleported to another region on that simulator. This was because update was looking for an existing stats record unique in session id, agent id and region id. But if the user teleports to another region then region id changes. WebStatsModule promptly doesn't find the existing record and tries to insert a new one, but only session id is the primary key and that's still the same, which makes things go bang. This makes the update search only on the unique session id. This is only an issue with simulators that have multiple regions where the webstats module is enabled. --- OpenSim/Region/UserStatistics/WebStatsModule.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs index b9ba4bc797..dbe9b3fd4f 100644 --- a/OpenSim/Region/UserStatistics/WebStatsModule.cs +++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs @@ -446,7 +446,7 @@ namespace OpenSim.Region.UserStatistics { // m_log.DebugFormat("[WEB STATS MODULE]: Received viewer starts report from {0}", agentID); - UpdateUserStats(ParseViewerStats(request,agentID), dbConn); + UpdateUserStats(ParseViewerStats(request, agentID), dbConn); return String.Empty; } @@ -654,8 +654,6 @@ namespace OpenSim.Region.UserStatistics updatecmd.Parameters.Add(new SqliteParameter(":f_send_packet", uid.session_data.f_send_packet)); updatecmd.Parameters.Add(new SqliteParameter(":session_key", uid.session_data.session_id.ToString())); - updatecmd.Parameters.Add(new SqliteParameter(":agent_key", uid.session_data.agent_id.ToString())); - updatecmd.Parameters.Add(new SqliteParameter(":region_key", uid.session_data.region_id.ToString())); // m_log.DebugFormat("[WEB STATS MODULE]: Database stats update for {0}", uid.session_data.agent_id); @@ -667,11 +665,18 @@ namespace OpenSim.Region.UserStatistics updatecmd.CommandText = SQL_STATS_TABLE_INSERT; +// StringBuilder parameters = new StringBuilder(); +// SqliteParameterCollection spc = updatecmd.Parameters; +// foreach (SqliteParameter sp in spc) +// parameters.AppendFormat("{0}={1},", sp.ParameterName, sp.Value); +// +// m_log.DebugFormat("[WEB STATS MODULE]: Parameters {0}", parameters); + try { updatecmd.ExecuteNonQuery(); } - catch (Exception e) + catch (SqliteExecutionException e) { m_log.WarnFormat( "[WEB STATS MODULE]: failed to write stats for {0}, storage Execution Exception {1}{2}", @@ -801,7 +806,7 @@ set session_id=:session_id, f_off_circuit=:f_off_circuit, f_resent=:f_resent, f_send_packet=:f_send_packet -WHERE session_id=:session_key AND agent_id=:agent_key AND region_id=:region_key"; +WHERE session_id=:session_key"; #endregion } From 1bb387333868e223c90519d18fa18b84bd1a4324 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 17 Apr 2012 00:19:36 +0100 Subject: [PATCH 06/21] Simplify WebStatsModule by removing the uncompleted migrations section. Use "create table if not exists" instead. Client stats data is transitory data that it is not worth migrating. --- .../Region/UserStatistics/WebStatsModule.cs | 32 ++----------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs index dbe9b3fd4f..e593ecd15f 100644 --- a/OpenSim/Region/UserStatistics/WebStatsModule.cs +++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs @@ -90,7 +90,7 @@ namespace OpenSim.Region.UserStatistics dbConn = new SqliteConnection("URI=file:LocalUserStatistics.db,version=3"); dbConn.Open(); - CheckAndUpdateDatabase(dbConn); + CreateTables(dbConn); Prototype_distributor protodep = new Prototype_distributor(); Updater_distributor updatedep = new Updater_distributor(); @@ -237,36 +237,12 @@ namespace OpenSim.Region.UserStatistics return responsedata; } - - public void CheckAndUpdateDatabase(SqliteConnection db) - { - lock (db) - { - // TODO: FIXME: implement stats migrations - const string SQL = @"SELECT * FROM migrations LIMIT 1"; - - using (SqliteCommand cmd = new SqliteCommand(SQL, db)) - { - try - { - cmd.ExecuteNonQuery(); - } - catch (SqliteSyntaxException) - { - CreateTables(db); - } - } - } - } public void CreateTables(SqliteConnection db) { using (SqliteCommand createcmd = new SqliteCommand(SQL_STATS_TABLE_CREATE, db)) { createcmd.ExecuteNonQuery(); - - createcmd.CommandText = SQL_MIGRA_TABLE_CREATE; - createcmd.ExecuteNonQuery(); } } @@ -688,9 +664,7 @@ namespace OpenSim.Region.UserStatistics } #region SQL - private const string SQL_MIGRA_TABLE_CREATE = @"create table migrations(name varchar(100), version int)"; - - private const string SQL_STATS_TABLE_CREATE = @"CREATE TABLE stats_session_data ( + private const string SQL_STATS_TABLE_CREATE = @"CREATE TABLE IF NOT EXISTS stats_session_data ( session_id VARCHAR(36) NOT NULL PRIMARY KEY, agent_id VARCHAR(36) NOT NULL DEFAULT '', region_id VARCHAR(36) NOT NULL DEFAULT '', @@ -807,8 +781,8 @@ set session_id=:session_id, f_resent=:f_resent, f_send_packet=:f_send_packet WHERE session_id=:session_key"; - #endregion } + #endregion public static class UserSessionUtil { From 572440cd23cdd5737979a2140b9d782b836fb952 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 17 Apr 2012 00:33:23 +0100 Subject: [PATCH 07/21] correct bug where f_invalid was being inserted on a webstats update for an existing session rather than d_world_kb --- OpenSim/Region/UserStatistics/WebStatsModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs index e593ecd15f..cc041d1f51 100644 --- a/OpenSim/Region/UserStatistics/WebStatsModule.cs +++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs @@ -718,7 +718,7 @@ namespace OpenSim.Region.UserStatistics session_id, agent_id, region_id, last_updated, remote_ip, name_f, name_l, avg_agents_in_view, min_agents_in_view, max_agents_in_view, mode_agents_in_view, avg_fps, min_fps, max_fps, mode_fps, a_language, mem_use, meters_traveled, avg_ping, min_ping, max_ping, mode_ping, regions_visited, run_time, avg_sim_fps, min_sim_fps, max_sim_fps, mode_sim_fps, start_time, client_version, s_cpu, s_gpu, s_os, s_ram, -d_object_kb, d_texture_kb, n_in_kb, n_in_pk, n_out_kb, n_out_pk, f_dropped, f_failed_resends, f_invalid, f_invalid, f_off_circuit, +d_object_kb, d_texture_kb, d_world_kb, n_in_kb, n_in_pk, n_out_kb, n_out_pk, f_dropped, f_failed_resends, f_invalid, f_off_circuit, f_resent, f_send_packet ) VALUES @@ -726,7 +726,7 @@ VALUES :session_id, :agent_id, :region_id, :last_updated, :remote_ip, :name_f, :name_l, :avg_agents_in_view, :min_agents_in_view, :max_agents_in_view, :mode_agents_in_view, :avg_fps, :min_fps, :max_fps, :mode_fps, :a_language, :mem_use, :meters_traveled, :avg_ping, :min_ping, :max_ping, :mode_ping, :regions_visited, :run_time, :avg_sim_fps, :min_sim_fps, :max_sim_fps, :mode_sim_fps, :start_time, :client_version, :s_cpu, :s_gpu, :s_os, :s_ram, -:d_object_kb, :d_texture_kb, :n_in_kb, :n_in_pk, :n_out_kb, :n_out_pk, :f_dropped, :f_failed_resends, :f_invalid, :f_invalid, :f_off_circuit, +:d_object_kb, :d_texture_kb, :d_world_kb, :n_in_kb, :n_in_pk, :n_out_kb, :n_out_pk, :f_dropped, :f_failed_resends, :f_invalid, :f_off_circuit, :f_resent, :f_send_packet ) "; From e6ec83125b9d77db833e18bbbdb396a31fb7b871 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 17 Apr 2012 00:46:43 +0100 Subject: [PATCH 08/21] Use INSERT OR REPLACE INTO sql in WebStatsModule for session update rather than separate insert and update statements --- .../Region/UserStatistics/WebStatsModule.cs | 84 ++----------------- 1 file changed, 7 insertions(+), 77 deletions(-) diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs index cc041d1f51..a00955a05f 100644 --- a/OpenSim/Region/UserStatistics/WebStatsModule.cs +++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs @@ -575,7 +575,7 @@ namespace OpenSim.Region.UserStatistics lock (db) { - using (SqliteCommand updatecmd = new SqliteCommand(SQL_STATS_TABLE_UPDATE, db)) + using (SqliteCommand updatecmd = new SqliteCommand(SQL_STATS_TABLE_INSERT, db)) { updatecmd.Parameters.Add(new SqliteParameter(":session_id", uid.session_data.session_id.ToString())); updatecmd.Parameters.Add(new SqliteParameter(":agent_id", uid.session_data.agent_id.ToString())); @@ -624,22 +624,9 @@ namespace OpenSim.Region.UserStatistics updatecmd.Parameters.Add(new SqliteParameter(":f_dropped", uid.session_data.f_dropped)); updatecmd.Parameters.Add(new SqliteParameter(":f_failed_resends", uid.session_data.f_failed_resends)); updatecmd.Parameters.Add(new SqliteParameter(":f_invalid", uid.session_data.f_invalid)); - updatecmd.Parameters.Add(new SqliteParameter(":f_off_circuit", uid.session_data.f_off_circuit)); updatecmd.Parameters.Add(new SqliteParameter(":f_resent", uid.session_data.f_resent)); updatecmd.Parameters.Add(new SqliteParameter(":f_send_packet", uid.session_data.f_send_packet)); - - updatecmd.Parameters.Add(new SqliteParameter(":session_key", uid.session_data.session_id.ToString())); - -// m_log.DebugFormat("[WEB STATS MODULE]: Database stats update for {0}", uid.session_data.agent_id); - - int result = updatecmd.ExecuteNonQuery(); - - if (result == 0) - { -// m_log.DebugFormat("[WEB STATS MODULE]: Database stats insert for {0}", uid.session_data.agent_id); - - updatecmd.CommandText = SQL_STATS_TABLE_INSERT; // StringBuilder parameters = new StringBuilder(); // SqliteParameterCollection spc = updatecmd.Parameters; @@ -648,17 +635,9 @@ namespace OpenSim.Region.UserStatistics // // m_log.DebugFormat("[WEB STATS MODULE]: Parameters {0}", parameters); - try - { - updatecmd.ExecuteNonQuery(); - } - catch (SqliteExecutionException e) - { - m_log.WarnFormat( - "[WEB STATS MODULE]: failed to write stats for {0}, storage Execution Exception {1}{2}", - uid.session_data.agent_id, e.Message, e.StackTrace); - } - } +// m_log.DebugFormat("[WEB STATS MODULE]: Database stats update for {0}", uid.session_data.agent_id); + + updatecmd.ExecuteNonQuery(); } } } @@ -714,7 +693,7 @@ namespace OpenSim.Region.UserStatistics f_send_packet INT NOT NULL DEFAULT '0' );"; - private const string SQL_STATS_TABLE_INSERT = @"INSERT INTO stats_session_data ( + private const string SQL_STATS_TABLE_INSERT = @"INSERT OR REPLACE INTO stats_session_data ( session_id, agent_id, region_id, last_updated, remote_ip, name_f, name_l, avg_agents_in_view, min_agents_in_view, max_agents_in_view, mode_agents_in_view, avg_fps, min_fps, max_fps, mode_fps, a_language, mem_use, meters_traveled, avg_ping, min_ping, max_ping, mode_ping, regions_visited, run_time, avg_sim_fps, min_sim_fps, max_sim_fps, mode_sim_fps, start_time, client_version, s_cpu, s_gpu, s_os, s_ram, @@ -731,59 +710,10 @@ VALUES ) "; - private const string SQL_STATS_TABLE_UPDATE = @" -UPDATE stats_session_data -set session_id=:session_id, - agent_id=:agent_id, - region_id=:region_id, - last_updated=:last_updated, - remote_ip=:remote_ip, - name_f=:name_f, - name_l=:name_l, - avg_agents_in_view=:avg_agents_in_view, - min_agents_in_view=:min_agents_in_view, - max_agents_in_view=:max_agents_in_view, - mode_agents_in_view=:mode_agents_in_view, - avg_fps=:avg_fps, - min_fps=:min_fps, - max_fps=:max_fps, - mode_fps=:mode_fps, - a_language=:a_language, - mem_use=:mem_use, - meters_traveled=:meters_traveled, - avg_ping=:avg_ping, - min_ping=:min_ping, - max_ping=:max_ping, - mode_ping=:mode_ping, - regions_visited=:regions_visited, - run_time=:run_time, - avg_sim_fps=:avg_sim_fps, - min_sim_fps=:min_sim_fps, - max_sim_fps=:max_sim_fps, - mode_sim_fps=:mode_sim_fps, - start_time=:start_time, - client_version=:client_version, - s_cpu=:s_cpu, - s_gpu=:s_gpu, - s_os=:s_os, - s_ram=:s_ram, - d_object_kb=:d_object_kb, - d_texture_kb=:d_texture_kb, - d_world_kb=:d_world_kb, - n_in_kb=:n_in_kb, - n_in_pk=:n_in_pk, - n_out_kb=:n_out_kb, - n_out_pk=:n_out_pk, - f_dropped=:f_dropped, - f_failed_resends=:f_failed_resends, - f_invalid=:f_invalid, - f_off_circuit=:f_off_circuit, - f_resent=:f_resent, - f_send_packet=:f_send_packet -WHERE session_id=:session_key"; - } #endregion + } + public static class UserSessionUtil { public static UserSessionData newUserSessionData() From 5655239f440dce36cdf9288db70be567aef2d565 Mon Sep 17 00:00:00 2001 From: Talun Date: Mon, 16 Apr 2012 20:24:56 +0100 Subject: [PATCH 09/21] Null reference in llGetObjectMass on a seated avatar. --- .../Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index a19427da73..55817273b5 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -9255,7 +9255,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // child agents have a mass of 1.0 return 1; else - return (double)avatar.PhysicsActor.Mass; + return (double)avatar.GetMass(); } catch (KeyNotFoundException) { From 24a0cc5261f1fd1a1d8779c8fb5e7d7fba98ed68 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 17 Apr 2012 01:25:41 +0100 Subject: [PATCH 10/21] refactor: Rename EstateSettings.IsEstateManager() to EstateSettings.IsEstateManagerOrOwner() to reflect what it actually does. This makes it consistent with other parts of OpenSimulator that are treating ESTATE_MANAGER and ESTATE_OWNER as different entities. As per opensim-dev mailing list. --- OpenSim/Framework/EstateSettings.cs | 4 ++-- OpenSim/Framework/Tests/MundaneFrameworkTests.cs | 4 ++-- .../CoreModules/World/Estate/EstateManagementModule.cs | 2 +- OpenSim/Region/CoreModules/World/Land/LandObject.cs | 4 ++-- .../CoreModules/World/Permissions/PermissionsModule.cs | 2 +- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 6 +++--- .../ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 2 +- .../Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs | 6 +++--- .../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/OpenSim/Framework/EstateSettings.cs b/OpenSim/Framework/EstateSettings.cs index 98604f27ba..a92abbf026 100644 --- a/OpenSim/Framework/EstateSettings.cs +++ b/OpenSim/Framework/EstateSettings.cs @@ -322,7 +322,7 @@ namespace OpenSim.Framework l_EstateManagers.Remove(avatarID); } - public bool IsEstateManager(UUID avatarID) + public bool IsEstateManagerOrOwner(UUID avatarID) { if (IsEstateOwner(avatarID)) return true; @@ -368,7 +368,7 @@ namespace OpenSim.Framework public bool HasAccess(UUID user) { - if (IsEstateManager(user)) + if (IsEstateManagerOrOwner(user)) return true; return l_EstateAccess.Contains(user); diff --git a/OpenSim/Framework/Tests/MundaneFrameworkTests.cs b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs index 76de6be267..672847dfed 100644 --- a/OpenSim/Framework/Tests/MundaneFrameworkTests.cs +++ b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs @@ -227,10 +227,10 @@ namespace OpenSim.Framework.Tests es.AddEstateManager(UUID.Zero); es.AddEstateManager(bannedUserId); - Assert.IsTrue(es.IsEstateManager(bannedUserId), "bannedUserId should be EstateManager but isn't."); + Assert.IsTrue(es.IsEstateManagerOrOwner(bannedUserId), "bannedUserId should be EstateManager but isn't."); es.RemoveEstateManager(bannedUserId); - Assert.IsFalse(es.IsEstateManager(bannedUserId), "bannedUserID is estateManager but shouldn't be"); + Assert.IsFalse(es.IsEstateManagerOrOwner(bannedUserId), "bannedUserID is estateManager but shouldn't be"); Assert.IsFalse(es.HasAccess(bannedUserId), "bannedUserID has access but shouldn't"); diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs index 124f01c9e5..58bbd2405a 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs @@ -967,7 +967,7 @@ namespace OpenSim.Region.CoreModules.World.Estate { RegionHandshakeArgs args = new RegionHandshakeArgs(); - args.isEstateManager = Scene.RegionInfo.EstateSettings.IsEstateManager(remoteClient.AgentId); + args.isEstateManager = Scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(remoteClient.AgentId); if (Scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero && Scene.RegionInfo.EstateSettings.EstateOwner == remoteClient.AgentId) args.isEstateManager = true; diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs index 7f44613d5e..0536f6ec6e 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs @@ -469,7 +469,7 @@ namespace OpenSim.Region.CoreModules.World.Land if (m_scene.Permissions.IsAdministrator(avatar)) return false; - if (m_scene.RegionInfo.EstateSettings.IsEstateManager(avatar)) + if (m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(avatar)) return false; if (avatar == LandData.OwnerID) @@ -499,7 +499,7 @@ namespace OpenSim.Region.CoreModules.World.Land if (m_scene.Permissions.IsAdministrator(avatar)) return false; - if (m_scene.RegionInfo.EstateSettings.IsEstateManager(avatar)) + if (m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(avatar)) return false; if (avatar == LandData.OwnerID) diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs index 64759a7e12..2032905c5f 100644 --- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs +++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs @@ -503,7 +503,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions { if (user == UUID.Zero) return false; - return m_scene.RegionInfo.EstateSettings.IsEstateManager(user); + return m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(user); } #endregion diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 641d742f95..b5f789b52a 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -3832,7 +3832,7 @@ namespace OpenSim.Region.Framework.Scenes land.LandData.UserLocation != Vector3.Zero && land.LandData.OwnerID != m_uuid && (!m_scene.Permissions.IsGod(m_uuid)) && - (!m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid))) + (!m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_uuid))) { float curr = Vector3.Distance(AbsolutePosition, pos); if (Vector3.Distance(land.LandData.UserLocation, pos) < curr) @@ -3852,7 +3852,7 @@ namespace OpenSim.Region.Framework.Scenes { if (GodLevel < 200 && ((!m_scene.Permissions.IsGod(m_uuid) && - !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid)) || + !m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_uuid)) || (m_teleportFlags & TeleportFlags.ViaLocation) != 0 || (m_teleportFlags & Constants.TeleportFlags.ViaHGLogin) != 0)) { @@ -3920,7 +3920,7 @@ namespace OpenSim.Region.Framework.Scenes GodLevel < 200 && ((land.LandData.OwnerID != m_uuid && !m_scene.Permissions.IsGod(m_uuid) && - !m_scene.RegionInfo.EstateSettings.IsEstateManager(m_uuid)) || + !m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_uuid)) || (m_teleportFlags & TeleportFlags.ViaLocation) != 0 || (m_teleportFlags & Constants.TeleportFlags.ViaHGLogin) != 0)) { diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 55817273b5..36c9d5e74e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -10887,7 +10887,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api bool isAccount = false; bool isGroup = false; - if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManager(m_host.OwnerID)) + if (!estate.IsEstateOwner(m_host.OwnerID) || !estate.IsEstateManagerOrOwner(m_host.OwnerID)) return 0; UUID id = new UUID(); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs index 77a784d077..df20126ff2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs @@ -449,7 +449,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api LSShoutError("LightShare functions are not enabled."); return 0; } - if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) + if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) { LSShoutError("lsSetWindlightScene can only be used by estate managers or owners."); return 0; @@ -477,7 +477,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api LSShoutError("LightShare functions are not enabled."); return; } - if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) + if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) { LSShoutError("lsSetWindlightScene can only be used by estate managers or owners."); return; @@ -500,7 +500,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api LSShoutError("LightShare functions are not enabled."); return 0; } - if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) + if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) { LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners."); return 0; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 2680ad0667..fe94b79b74 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -369,7 +369,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_FunctionPerms[function].AllowedOwnerClasses.Contains("ESTATE_MANAGER")) { //Only Estate Managers may use the function - if (World.RegionInfo.EstateSettings.IsEstateManager(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID) + if (World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(ownerID) && World.RegionInfo.EstateSettings.EstateOwner != ownerID) { return; } From 7e1ab216e3c8b7ade3f007d352451c9d9d742b5c Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 17 Apr 2012 01:33:55 +0100 Subject: [PATCH 11/21] Move some public methods on WebStatsModule to private to reduce some static analysis complexity. There's no obvious reason for these methods to be public. --- .../Region/UserStatistics/WebStatsModule.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs index a00955a05f..4248035904 100644 --- a/OpenSim/Region/UserStatistics/WebStatsModule.cs +++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs @@ -131,7 +131,7 @@ namespace OpenSim.Region.UserStatistics } } - public void ReceiveClassicSimStatsPacket(SimStats stats) + private void ReceiveClassicSimStatsPacket(SimStats stats) { if (!enabled) { @@ -163,7 +163,7 @@ namespace OpenSim.Region.UserStatistics } } - public Hashtable HandleUnknownCAPSRequest(Hashtable request) + private Hashtable HandleUnknownCAPSRequest(Hashtable request) { //string regpath = request["uri"].ToString(); int response_code = 200; @@ -178,7 +178,7 @@ namespace OpenSim.Region.UserStatistics return responsedata; } - public Hashtable HandleStatsRequest(Hashtable request) + private Hashtable HandleStatsRequest(Hashtable request) { lastHit = System.Environment.TickCount; Hashtable responsedata = new Hashtable(); @@ -238,7 +238,7 @@ namespace OpenSim.Region.UserStatistics return responsedata; } - public void CreateTables(SqliteConnection db) + private void CreateTables(SqliteConnection db) { using (SqliteCommand createcmd = new SqliteCommand(SQL_STATS_TABLE_CREATE, db)) { @@ -277,7 +277,7 @@ namespace OpenSim.Region.UserStatistics get { return true; } } - public void OnRegisterCaps(UUID agentID, Caps caps) + private void OnRegisterCaps(UUID agentID, Caps caps) { // m_log.DebugFormat("[WEB STATS MODULE]: OnRegisterCaps: agentID {0} caps {1}", agentID, caps); @@ -292,7 +292,7 @@ namespace OpenSim.Region.UserStatistics })); } - public void OnDeRegisterCaps(UUID agentID, Caps caps) + private void OnDeRegisterCaps(UUID agentID, Caps caps) { } @@ -312,7 +312,7 @@ namespace OpenSim.Region.UserStatistics } } - public void OnMakeRootAgent(ScenePresence agent) + private void OnMakeRootAgent(ScenePresence agent) { UUID regionUUID = GetRegionUUIDFromHandle(agent.RegionHandle); @@ -341,11 +341,11 @@ namespace OpenSim.Region.UserStatistics } } - public void OnMakeChildAgent(ScenePresence agent) + private void OnMakeChildAgent(ScenePresence agent) { } - public void OnClientClosed(UUID agentID, Scene scene) + private void OnClientClosed(UUID agentID, Scene scene) { lock (m_sessions) { @@ -356,7 +356,7 @@ namespace OpenSim.Region.UserStatistics } } - public string readLogLines(int amount) + private string readLogLines(int amount) { Encoding encoding = Encoding.ASCII; int sizeOfChar = encoding.GetByteCount("\n"); @@ -394,7 +394,7 @@ namespace OpenSim.Region.UserStatistics return encoding.GetString(buffer); } - public UUID GetRegionUUIDFromHandle(ulong regionhandle) + private UUID GetRegionUUIDFromHandle(ulong regionhandle) { lock (m_scenes) { @@ -417,7 +417,7 @@ namespace OpenSim.Region.UserStatistics /// /// /// - public string ViewerStatsReport(string request, string path, string param, + private string ViewerStatsReport(string request, string path, string param, UUID agentID, Caps caps) { // m_log.DebugFormat("[WEB STATS MODULE]: Received viewer starts report from {0}", agentID); @@ -427,7 +427,7 @@ namespace OpenSim.Region.UserStatistics return String.Empty; } - public UserSessionID ParseViewerStats(string request, UUID agentID) + private UserSessionID ParseViewerStats(string request, UUID agentID) { UserSessionID uid = new UserSessionID(); UserSessionData usd; @@ -568,7 +568,7 @@ namespace OpenSim.Region.UserStatistics return uid; } - public void UpdateUserStats(UserSessionID uid, SqliteConnection db) + private void UpdateUserStats(UserSessionID uid, SqliteConnection db) { if (uid.session_id == UUID.Zero) return; From 2f2181683c9b3963da5e1cfd7fa1c6491d8a2ac0 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 17 Apr 2012 01:51:13 +0100 Subject: [PATCH 12/21] Add test TestGetChildPartPosition() --- .../Scenes/Tests/SceneObjectSpatialTests.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs index 7a3b3627e0..fffa3bd152 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs @@ -86,5 +86,33 @@ namespace OpenSim.Region.Framework.Scenes.Tests Assert.That(so.RootPart.RelativePosition, Is.EqualTo(partPosition)); Assert.That(so.RootPart.OffsetPosition, Is.EqualTo(Vector3.Zero)); } + + [Test] + public void TestGetChildPartPosition() + { + TestHelpers.InMethod(); + + Vector3 rootPartPosition = new Vector3(10, 20, 30); + Vector3 childOffsetPosition = new Vector3(2, 3, 4); + + SceneObjectGroup so + = SceneHelpers.CreateSceneObject(2, m_ownerId, "obj1", 0x10); + so.AbsolutePosition = rootPartPosition; + so.Parts[1].OffsetPosition = childOffsetPosition; + + m_scene.AddNewSceneObject(so, false); + + // Calculate child absolute position. + Vector3 childPosition = new Vector3(rootPartPosition + childOffsetPosition); + + SceneObjectPart childPart = so.Parts[1]; + Assert.That(childPart.AbsolutePosition, Is.EqualTo(childPosition)); + Assert.That(childPart.GroupPosition, Is.EqualTo(rootPartPosition)); + Assert.That(childPart.GetWorldPosition(), Is.EqualTo(childPosition)); + Assert.That(childPart.RelativePosition, Is.EqualTo(childOffsetPosition)); + Assert.That(childPart.OffsetPosition, Is.EqualTo(childOffsetPosition)); + + // TODO: Write test for child part position after rotation. + } } } \ No newline at end of file From cca6b6bd0d679e817cbcb8b51de82577a15e2ff0 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 17 Apr 2012 02:14:10 +0100 Subject: [PATCH 13/21] Add TestGetChildPartPositionAfterObjectRotation() --- .../Scenes/Tests/SceneObjectSpatialTests.cs | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs index fffa3bd152..9fea3c63a7 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSpatialTests.cs @@ -111,8 +111,44 @@ namespace OpenSim.Region.Framework.Scenes.Tests Assert.That(childPart.GetWorldPosition(), Is.EqualTo(childPosition)); Assert.That(childPart.RelativePosition, Is.EqualTo(childOffsetPosition)); Assert.That(childPart.OffsetPosition, Is.EqualTo(childOffsetPosition)); + } - // TODO: Write test for child part position after rotation. + [Test] + public void TestGetChildPartPositionAfterObjectRotation() + { + TestHelpers.InMethod(); + + Vector3 rootPartPosition = new Vector3(10, 20, 30); + Vector3 childOffsetPosition = new Vector3(2, 3, 4); + + SceneObjectGroup so + = SceneHelpers.CreateSceneObject(2, m_ownerId, "obj1", 0x10); + so.AbsolutePosition = rootPartPosition; + so.Parts[1].OffsetPosition = childOffsetPosition; + + m_scene.AddNewSceneObject(so, false); + + so.UpdateGroupRotationR(Quaternion.CreateFromEulers(0, 0, -90 * Utils.DEG_TO_RAD)); + + // Calculate child absolute position. + Vector3 rotatedChildOffsetPosition + = new Vector3(childOffsetPosition.Y, -childOffsetPosition.X, childOffsetPosition.Z); + + Vector3 childPosition = new Vector3(rootPartPosition + rotatedChildOffsetPosition); + + SceneObjectPart childPart = so.Parts[1]; + + // FIXME: Should be childPosition after rotation? + Assert.That(childPart.AbsolutePosition, Is.EqualTo(rootPartPosition + childOffsetPosition)); + + Assert.That(childPart.GroupPosition, Is.EqualTo(rootPartPosition)); + Assert.That(childPart.GetWorldPosition(), Is.EqualTo(childPosition)); + + // Relative to root part as (0, 0, 0) + Assert.That(childPart.RelativePosition, Is.EqualTo(childOffsetPosition)); + + // Relative to root part as (0, 0, 0) + Assert.That(childPart.OffsetPosition, Is.EqualTo(childOffsetPosition)); } } } \ No newline at end of file From 4bb72c9ffef9a54a46b7059ba4785c939c791ac4 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Tue, 17 Apr 2012 13:45:03 -0700 Subject: [PATCH 14/21] make the namespace for the ScriptModuleComms consistent with its file system location --- .../Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index cab30dec25..74a85e2cd5 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs @@ -38,7 +38,7 @@ using OpenMetaverse; using System.Linq; using System.Linq.Expressions; -namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms +namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms { [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")] class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms From 5ff2bda587a50b73f470ba778348645953b6b4b0 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Tue, 17 Apr 2012 13:45:27 -0700 Subject: [PATCH 15/21] This commit adds a new optional region module, JsonStore, that provides structured storage (dictionaries and arrays of string values) for scripts and region modules. In addition, there are operations on the storage that enable "real" distributed computation between scripts through operations similar to those of a tuple space. Scripts can share task queues, implement shared locks or semaphores, etc. The structured store is limited to the current region and is not currently persisted. However, script operations are defined to initialize a store from a notecard and to serialize the store to a notecard. Documentation will be posted to the opensim wiki soon. --- .../Framework/Interfaces/IJsonStoreModule.cs | 48 ++ .../Scripting/JsonStore/JsonStore.cs | 498 ++++++++++++++++++ .../Scripting/JsonStore/JsonStoreModule.cs | 429 +++++++++++++++ .../JsonStore/JsonStoreScriptModule.cs | 489 +++++++++++++++++ 4 files changed, 1464 insertions(+) create mode 100644 OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs create mode 100644 OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs create mode 100644 OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs create mode 100644 OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs diff --git a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs new file mode 100644 index 0000000000..baac6e827f --- /dev/null +++ b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs @@ -0,0 +1,48 @@ +/* + * 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 System; +using System.Reflection; +using OpenMetaverse; + +namespace OpenSim.Region.Framework.Interfaces +{ + public delegate void TakeValueCallback(string s); + + public interface IJsonStoreModule + { + bool CreateStore(string value, out UUID result); + bool DestroyStore(UUID storeID); + bool TestPath(UUID storeID, string path, bool useJson); + bool SetValue(UUID storeID, string path, string value, bool useJson); + bool RemoveValue(UUID storeID, string path); + bool GetValue(UUID storeID, string path, bool useJson, out string value); + + void TakeValue(UUID storeID, string path, bool useJson, TakeValueCallback cback); + void ReadValue(UUID storeID, string path, bool useJson, TakeValueCallback cback); + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs new file mode 100644 index 0000000000..49556b601d --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs @@ -0,0 +1,498 @@ +/* + * 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 +{ + public class JsonStore + { + private static readonly ILog m_log = + LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private OSD m_ValueStore; + + protected class TakeValueCallbackClass + { + public string Path { get; set; } + public bool UseJson { get; set; } + public TakeValueCallback Callback { get; set; } + + public TakeValueCallbackClass(string spath, bool usejson, TakeValueCallback cback) + { + Path = spath; + UseJson = usejson; + Callback = cback; + } + } + + protected List m_TakeStore; + protected List m_ReadStore; + + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public JsonStore(string value = "") + { + m_TakeStore = new List(); + m_ReadStore = new List(); + + if (String.IsNullOrEmpty(value)) + m_ValueStore = new OSDMap(); + else + m_ValueStore = OSDParser.DeserializeJson(value); + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool TestPath(string expr, bool useJson) + { + Stack path = ParsePathExpression(expr); + OSD result = ProcessPathExpression(m_ValueStore,path); + + if (result == null) + return false; + + if (useJson || result.Type == OSDType.String) + return true; + + return false; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool GetValue(string expr, out string value, bool useJson) + { + Stack path = ParsePathExpression(expr); + OSD result = ProcessPathExpression(m_ValueStore,path); + return ConvertOutputValue(result,out value,useJson); + } + + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool RemoveValue(string expr) + { + return SetValueFromExpression(expr,null); + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool SetValue(string expr, string value, bool useJson) + { + OSD ovalue = useJson ? OSDParser.DeserializeJson(value) : new OSDString(value); + return SetValueFromExpression(expr,ovalue); + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool TakeValue(string expr, bool useJson, TakeValueCallback cback) + { + Stack path = ParsePathExpression(expr); + string pexpr = PathExpressionToKey(path); + + OSD result = ProcessPathExpression(m_ValueStore,path); + if (result == null) + { + m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); + return false; + } + + string value = String.Empty; + if (! ConvertOutputValue(result,out value,useJson)) + { + // the structure does not match the request so i guess we'll wait + m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); + return false; + } + + SetValueFromExpression(expr,null); + cback(value); + + return true; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool ReadValue(string expr, bool useJson, TakeValueCallback cback) + { + Stack path = ParsePathExpression(expr); + string pexpr = PathExpressionToKey(path); + + OSD result = ProcessPathExpression(m_ValueStore,path); + if (result == null) + { + m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); + return false; + } + + string value = String.Empty; + if (! ConvertOutputValue(result,out value,useJson)) + { + // the structure does not match the request so i guess we'll wait + m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); + return false; + } + + cback(value); + + return true; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected bool SetValueFromExpression(string expr, OSD ovalue) + { + Stack path = ParsePathExpression(expr); + if (path.Count == 0) + { + m_ValueStore = ovalue; + return true; + } + + string pkey = path.Pop(); + string pexpr = PathExpressionToKey(path); + if (pexpr != "") + pexpr += "."; + + OSD result = ProcessPathExpression(m_ValueStore,path); + if (result == null) + return false; + + Regex aPattern = new Regex("\\[([0-9]+|\\+)\\]"); + MatchCollection amatches = aPattern.Matches(pkey,0); + + if (amatches.Count > 0) + { + if (result.Type != OSDType.Array) + return false; + + OSDArray amap = result as OSDArray; + + Match match = amatches[0]; + GroupCollection groups = match.Groups; + string akey = groups[1].Value; + + if (akey == "+") + { + string npkey = String.Format("[{0}]",amap.Count); + + amap.Add(ovalue); + InvokeNextCallback(pexpr + npkey); + return true; + } + + int aval = Convert.ToInt32(akey); + if (0 <= aval && aval < amap.Count) + { + if (ovalue == null) + amap.RemoveAt(aval); + else + { + amap[aval] = ovalue; + InvokeNextCallback(pexpr + pkey); + } + return true; + } + + return false; + } + + Regex hPattern = new Regex("{([^}]+)}"); + MatchCollection hmatches = hPattern.Matches(pkey,0); + + if (hmatches.Count > 0) + { + Match match = hmatches[0]; + GroupCollection groups = match.Groups; + string hkey = groups[1].Value; + + if (result is OSDMap) + { + OSDMap hmap = result as OSDMap; + if (ovalue != null) + { + hmap[hkey] = ovalue; + InvokeNextCallback(pexpr + pkey); + } + else if (hmap.ContainsKey(hkey)) + hmap.Remove(hkey); + + return true; + } + + return false; + } + + // Shouldn't get here if the path was checked correctly + m_log.WarnFormat("[JsonStore] invalid path expression"); + return false; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected bool InvokeNextCallback(string pexpr) + { + // Process all of the reads that match the expression first + List reads = + m_ReadStore.FindAll(delegate(TakeValueCallbackClass tb) { return pexpr.StartsWith(tb.Path); }); + + foreach (TakeValueCallbackClass readcb in reads) + { + m_ReadStore.Remove(readcb); + ReadValue(readcb.Path,readcb.UseJson,readcb.Callback); + } + + // Process one take next + TakeValueCallbackClass takecb = + m_TakeStore.Find(delegate(TakeValueCallbackClass tb) { return pexpr.StartsWith(tb.Path); }); + + if (takecb != null) + { + m_TakeStore.Remove(takecb); + TakeValue(takecb.Path,takecb.UseJson,takecb.Callback); + + return true; + } + + return false; + } + + // ----------------------------------------------------------------- + /// + /// Parse the path expression and put the components into a stack. We + /// use a stack because we process the path in inverse order later + /// + // ----------------------------------------------------------------- + protected static Stack ParsePathExpression(string path) + { + Stack m_path = new Stack(); + + // add front and rear separators + path = "." + path + "."; + + // add separators for quoted paths + Regex pass1 = new Regex("{[^}]+}"); + path = pass1.Replace(path,".$0.",-1,0); + + // add separators for array references + Regex pass2 = new Regex("(\\[[0-9]+\\]|\\[\\+\\])"); + path = pass2.Replace(path,".$0.",-1,0); + + // add quotes to bare identifier + Regex pass3 = new Regex("\\.([a-zA-Z]+)"); + path = pass3.Replace(path,".{$1}",-1,0); + + // remove extra separators + Regex pass4 = new Regex("\\.+"); + path = pass4.Replace(path,".",-1,0); + + Regex validate = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)+$"); + if (validate.IsMatch(path)) + { + Regex parser = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)"); + MatchCollection matches = parser.Matches(path,0); + foreach (Match match in matches) + m_path.Push(match.Groups[1].Value); + } + + return m_path; + } + + // ----------------------------------------------------------------- + /// + /// + /// + /// path is a stack where the top level of the path is at the bottom of the stack + // ----------------------------------------------------------------- + protected static OSD ProcessPathExpression(OSD map, Stack path) + { + if (path.Count == 0) + return map; + + string pkey = path.Pop(); + + OSD rmap = ProcessPathExpression(map,path); + if (rmap == null) + return null; + + // ---------- Check for an array index ---------- + Regex aPattern = new Regex("\\[([0-9]+)\\]"); + MatchCollection amatches = aPattern.Matches(pkey,0); + + if (amatches.Count > 0) + { + if (rmap.Type != OSDType.Array) + { + m_log.WarnFormat("[JsonStore] wrong type for key {2}, expecting {0}, got {1}",OSDType.Array,rmap.Type,pkey); + return null; + } + + OSDArray amap = rmap as OSDArray; + + Match match = amatches[0]; + GroupCollection groups = match.Groups; + string akey = groups[1].Value; + int aval = Convert.ToInt32(akey); + + if (aval < amap.Count) + return (OSD) amap[aval]; + + return null; + } + + // ---------- Check for a hash index ---------- + Regex hPattern = new Regex("{([^}]+)}"); + MatchCollection hmatches = hPattern.Matches(pkey,0); + + if (hmatches.Count > 0) + { + if (rmap.Type != OSDType.Map) + { + m_log.WarnFormat("[JsonStore] wrong type for key {2}, expecting {0}, got {1}",OSDType.Map,rmap.Type,pkey); + return null; + } + + OSDMap hmap = rmap as OSDMap; + + Match match = hmatches[0]; + GroupCollection groups = match.Groups; + string hkey = groups[1].Value; + + if (hmap.ContainsKey(hkey)) + return (OSD) hmap[hkey]; + + return null; + } + + // Shouldn't get here if the path was checked correctly + m_log.WarnFormat("[JsonStore] Path type (unknown) does not match the structure"); + return null; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected static bool ConvertOutputValue(OSD result, out string value, bool useJson) + { + value = String.Empty; + + // If we couldn't process the path + if (result == null) + return false; + + if (useJson) + { + // The path pointed to an intermediate hash structure + if (result.Type == OSDType.Map) + { + value = OSDParser.SerializeJsonString(result as OSDMap); + return true; + } + + // The path pointed to an intermediate hash structure + if (result.Type == OSDType.Array) + { + value = OSDParser.SerializeJsonString(result as OSDArray); + return true; + } + + value = "'" + result.AsString() + "'"; + return true; + } + + if (result.Type == OSDType.String) + { + value = result.AsString(); + return true; + } + + return false; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected static string PathExpressionToKey(Stack path) + { + if (path.Count == 0) + return ""; + + string pkey = ""; + foreach (string k in path) + pkey = (pkey == "") ? k : (k + "." + pkey); + + return pkey; + } + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs new file mode 100644 index 0000000000..6dae9566d0 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs @@ -0,0 +1,429 @@ +/* + * 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 = "JsonStoreModule")] + + public class JsonStoreModule : INonSharedRegionModule, IJsonStoreModule + { + 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 Dictionary m_JsonValueStore; + private UUID m_sharedStore; + +#region IRegionModule Members + + // ----------------------------------------------------------------- + /// + /// 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.ErrorFormat("[JsonStore] initialization error: {0}",e.Message); + return; + } + + m_log.InfoFormat("[JsonStore] module {0} enabled",(m_enabled ? "is" : "is not")); + } + + // ----------------------------------------------------------------- + /// + /// 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; + m_scene.RegisterModuleInterface(this); + + m_sharedStore = UUID.Zero; + m_JsonValueStore = new Dictionary(); + m_JsonValueStore.Add(m_sharedStore,new JsonStore("")); + } + } + + // ----------------------------------------------------------------- + /// + /// + // ----------------------------------------------------------------- + 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) {} + } + + /// ----------------------------------------------------------------- + /// + /// + // ----------------------------------------------------------------- + public Type ReplaceableInterface + { + get { return null; } + } + +#endregion + +#region ScriptInvocationInteface + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool CreateStore(string value, out UUID result) + { + result = UUID.Zero; + + if (! m_enabled) return false; + + UUID uuid = UUID.Random(); + JsonStore map = null; + + try + { + map = new JsonStore(value); + } + catch (Exception e) + { + m_log.InfoFormat("[JsonStore] Unable to initialize store from {0}; {1}",value,e.Message); + return false; + } + + lock (m_JsonValueStore) + m_JsonValueStore.Add(uuid,map); + + result = uuid; + return true; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool DestroyStore(UUID storeID) + { + if (! m_enabled) return false; + + lock (m_JsonValueStore) + m_JsonValueStore.Remove(storeID); + + return true; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool TestPath(UUID storeID, string path, bool useJson) + { + if (! m_enabled) return false; + + JsonStore map = null; + lock (m_JsonValueStore) + { + if (! m_JsonValueStore.TryGetValue(storeID,out map)) + { + m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); + return true; + } + } + + try + { + lock (map) + return map.TestPath(path,useJson); + } + catch (Exception e) + { + m_log.InfoFormat("[JsonStore] Path test failed for {0} in {1}; {2}",path,storeID,e.Message); + } + + return false; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool SetValue(UUID storeID, string path, string value, bool useJson) + { + if (! m_enabled) return false; + + JsonStore map = null; + lock (m_JsonValueStore) + { + if (! m_JsonValueStore.TryGetValue(storeID,out map)) + { + m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); + return false; + } + } + + try + { + lock (map) + if (map.SetValue(path,value,useJson)) + return true; + } + catch (Exception e) + { + m_log.InfoFormat("[JsonStore] Unable to assign {0} to {1} in {2}; {3}",value,path,storeID,e.Message); + } + + return false; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool RemoveValue(UUID storeID, string path) + { + if (! m_enabled) return false; + + JsonStore map = null; + lock (m_JsonValueStore) + { + if (! m_JsonValueStore.TryGetValue(storeID,out map)) + { + m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); + return false; + } + } + + try + { + lock (map) + if (map.RemoveValue(path)) + return true; + } + catch (Exception e) + { + m_log.InfoFormat("[JsonStore] Unable to remove {0} in {1}; {2}",path,storeID,e.Message); + } + + return false; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool GetValue(UUID storeID, string path, bool useJson, out string value) + { + value = String.Empty; + + if (! m_enabled) return false; + + JsonStore map = null; + lock (m_JsonValueStore) + { + if (! m_JsonValueStore.TryGetValue(storeID,out map)) + return false; + } + + try + { + lock (map) + { + return map.GetValue(path, out value, useJson); + } + } + catch (Exception e) + { + m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.Message); + } + + return false; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public void TakeValue(UUID storeID, string path, bool useJson, TakeValueCallback cback) + { + if (! m_enabled) + { + cback(String.Empty); + return; + } + + JsonStore map = null; + lock (m_JsonValueStore) + { + if (! m_JsonValueStore.TryGetValue(storeID,out map)) + { + cback(String.Empty); + return; + } + } + + try + { + lock (map) + { + map.TakeValue(path, useJson, cback); + return; + } + } + catch (Exception e) + { + m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString()); + } + + cback(String.Empty); + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public void ReadValue(UUID storeID, string path, bool useJson, TakeValueCallback cback) + { + if (! m_enabled) + { + cback(String.Empty); + return; + } + + JsonStore map = null; + lock (m_JsonValueStore) + { + if (! m_JsonValueStore.TryGetValue(storeID,out map)) + { + cback(String.Empty); + return; + } + } + + try + { + lock (map) + { + map.ReadValue(path, useJson, cback); + return; + } + } + catch (Exception e) + { + m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString()); + } + + cback(String.Empty); + } + +#endregion + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs new file mode 100644 index 0000000000..7aba860a89 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs @@ -0,0 +1,489 @@ +/* + * 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 = "JsonStoreScriptModule")] + + public class JsonStoreScriptModule : 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 IScriptModuleComms m_comms; + private IJsonStoreModule m_store; + +#region IRegionModule Members + + // ----------------------------------------------------------------- + /// + /// 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("[JsonStoreScripts] no configuration info"); + return; + } + + m_enabled = m_config.GetBoolean("Enabled", m_enabled); + } + catch (Exception e) + { + m_log.ErrorFormat("[JsonStoreScripts] initialization error: {0}",e.Message); + return; + } + + m_log.InfoFormat("[JsonStoreScripts] module {0} enabled",(m_enabled ? "is" : "is not")); + } + + // ----------------------------------------------------------------- + /// + /// everything is loaded, perform post load configuration + /// + // ----------------------------------------------------------------- + public void PostInitialise() + { + } + + // ----------------------------------------------------------------- + /// + /// Nothing to do on close + /// + // ----------------------------------------------------------------- + public void Close() + { + } + + // ----------------------------------------------------------------- + /// + /// + // ----------------------------------------------------------------- + public void AddRegion(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_comms = m_scene.RequestModuleInterface(); + if (m_comms == null) + { + m_log.ErrorFormat("[JsonStoreScripts] ScriptModuleComms interface not defined"); + m_enabled = false; + return; + } + + m_store = m_scene.RequestModuleInterface(); + if (m_store == null) + { + m_log.ErrorFormat("[JsonStoreScripts] JsonModule interface not defined"); + m_enabled = false; + return; + } + + m_comms.RegisterScriptInvocation(this,"JsonCreateStore"); + m_comms.RegisterScriptInvocation(this,"JsonDestroyStore"); + + m_comms.RegisterScriptInvocation(this,"JsonReadNotecard"); + m_comms.RegisterScriptInvocation(this,"JsonWriteNotecard"); + + m_comms.RegisterScriptInvocation(this,"JsonTestPath"); + m_comms.RegisterScriptInvocation(this,"JsonTestPathJson"); + + m_comms.RegisterScriptInvocation(this,"JsonGetValue"); + m_comms.RegisterScriptInvocation(this,"JsonGetValueJson"); + + m_comms.RegisterScriptInvocation(this,"JsonTakeValue"); + m_comms.RegisterScriptInvocation(this,"JsonTakeValueJson"); + + m_comms.RegisterScriptInvocation(this,"JsonReadValue"); + m_comms.RegisterScriptInvocation(this,"JsonReadValueJson"); + + m_comms.RegisterScriptInvocation(this,"JsonSetValue"); + m_comms.RegisterScriptInvocation(this,"JsonSetValueJson"); + + m_comms.RegisterScriptInvocation(this,"JsonRemoveValue"); + } + } + + /// ----------------------------------------------------------------- + /// + /// + // ----------------------------------------------------------------- + public Type ReplaceableInterface + { + get { return null; } + } + +#endregion + +#region ScriptInvocationInteface + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected void GenerateRuntimeError(string msg) + { + throw new Exception("JsonStore Runtime Error: " + msg); + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected UUID JsonCreateStore(UUID hostID, UUID scriptID, string value) + { + UUID uuid = UUID.Zero; + if (! m_store.CreateStore(value, out uuid)) + GenerateRuntimeError("Failed to create Json store"); + + return uuid; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID) + { + return m_store.DestroyStore(storeID) ? 1 : 0; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) + { + UUID reqID = UUID.Random(); + Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); }); + return reqID; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name) + { + UUID reqID = UUID.Random(); + Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); }); + return reqID; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path) + { + return m_store.TestPath(storeID,path,false) ? 1 : 0; + } + + protected int JsonTestPathJson(UUID hostID, UUID scriptID, UUID storeID, string path) + { + return m_store.TestPath(storeID,path,true) ? 1 : 0; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value) + { + return m_store.SetValue(storeID,path,value,false) ? 1 : 0; + } + + protected int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value) + { + return m_store.SetValue(storeID,path,value,true) ? 1 : 0; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path) + { + return m_store.RemoveValue(storeID,path) ? 1 : 0; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path) + { + string value = String.Empty; + m_store.GetValue(storeID,path,false,out value); + return value; + } + + protected string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) + { + string value = String.Empty; + m_store.GetValue(storeID,path,true, out value); + return value; + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path) + { + UUID reqID = UUID.Random(); + Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); }); + return reqID; + } + + protected UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) + { + UUID reqID = UUID.Random(); + Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); }); + return reqID; + } + + private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson) + { + try + { + m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); }); + return; + } + catch (Exception e) + { + m_log.InfoFormat("[JsonStoreScripts] unable to retrieve value; {0}",e.ToString()); + } + + DispatchValue(scriptID,reqID,String.Empty); + } + + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path) + { + UUID reqID = UUID.Random(); + Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); }); + return reqID; + } + + protected UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) + { + UUID reqID = UUID.Random(); + Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); }); + return reqID; + } + + private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson) + { + try + { + m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); }); + return; + } + catch (Exception e) + { + m_log.InfoFormat("[JsonStoreScripts] unable to retrieve value; {0}",e.ToString()); + } + + DispatchValue(scriptID,reqID,String.Empty); + } + +#endregion + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + protected void DispatchValue(UUID scriptID, UUID reqID, string value) + { + m_comms.DispatchReply(scriptID,1,value,reqID.ToString()); + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + private void DoJsonReadNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) + { + AssetBase a = m_scene.AssetService.Get(assetID.ToString()); + if (a == null) + GenerateRuntimeError(String.Format("Unable to find notecard asset {0}",assetID)); + + if (a.Type != (sbyte)AssetType.Notecard) + GenerateRuntimeError(String.Format("Invalid notecard asset {0}",assetID)); + + m_log.DebugFormat("[JsonStoreScripts] read notecard in context {0}",storeID); + + try + { + System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); + string jsondata = SLUtil.ParseNotecardToString(enc.GetString(a.Data)); + int result = m_store.SetValue(storeID,path,jsondata,true) ? 1 : 0; + m_comms.DispatchReply(scriptID,result,"",reqID.ToString()); + return; + } + catch (Exception e) + { + m_log.WarnFormat("[JsonStoreScripts] Json parsing failed; {0}",e.Message); + } + + GenerateRuntimeError(String.Format("Json parsing failed for {0}",assetID.ToString())); + m_comms.DispatchReply(scriptID,0,"",reqID.ToString()); + } + + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + private void DoJsonWriteNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string name) + { + string data; + if (! m_store.GetValue(storeID,path,true, out data)) + { + m_comms.DispatchReply(scriptID,0,UUID.Zero.ToString(),reqID.ToString()); + return; + } + + SceneObjectPart host = m_scene.GetSceneObjectPart(hostID); + + // Create new asset + UUID assetID = UUID.Random(); + AssetBase asset = new AssetBase(assetID, name, (sbyte)AssetType.Notecard, host.OwnerID.ToString()); + asset.Description = "Json store"; + + int textLength = data.Length; + data = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " + + textLength.ToString() + "\n" + data + "}\n"; + + asset.Data = Util.UTF8.GetBytes(data); + m_scene.AssetService.Store(asset); + + // Create Task Entry + TaskInventoryItem taskItem = new TaskInventoryItem(); + + taskItem.ResetIDs(host.UUID); + taskItem.ParentID = host.UUID; + taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch(); + taskItem.Name = asset.Name; + taskItem.Description = asset.Description; + taskItem.Type = (int)AssetType.Notecard; + taskItem.InvType = (int)InventoryType.Notecard; + taskItem.OwnerID = host.OwnerID; + taskItem.CreatorID = host.OwnerID; + taskItem.BasePermissions = (uint)PermissionMask.All; + taskItem.CurrentPermissions = (uint)PermissionMask.All; + taskItem.EveryonePermissions = 0; + taskItem.NextPermissions = (uint)PermissionMask.All; + taskItem.GroupID = host.GroupID; + taskItem.GroupPermissions = 0; + taskItem.Flags = 0; + taskItem.PermsGranter = UUID.Zero; + taskItem.PermsMask = 0; + taskItem.AssetID = asset.FullID; + + host.Inventory.AddInventoryItem(taskItem, false); + + m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString()); + } + } +} From 2d45ba47ac91646901701df8eec4eb86a0fddabf Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Tue, 17 Apr 2012 13:55:00 -0700 Subject: [PATCH 16/21] add configuration for jsonstore module, disabled by default --- bin/OpenSimDefaults.ini | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/OpenSimDefaults.ini b/bin/OpenSimDefaults.ini index 68a2ea307f..3f2f1318ac 100644 --- a/bin/OpenSimDefaults.ini +++ b/bin/OpenSimDefaults.ini @@ -1560,6 +1560,12 @@ MaptileURL = "http://www.mygrid.com/Grid/" RefreshTime = 3600 +;; +;; JsonStore module provides structured store for scripts +;; +[JsonStore] +Enabled = False + ;; ;; These are defaults that are overwritten below in [Architecture]. ;; These defaults allow OpenSim to work out of the box with From 4db518b9a30122f662a40252d3674ea272d6dcc1 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Tue, 17 Apr 2012 14:15:17 -0700 Subject: [PATCH 17/21] Fix the Csharp 3.0 vs 4.0 problem in JsonStore initialization. Cut down on the logging spam. --- .../Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | 4 +++- .../OptionalModules/Scripting/JsonStore/JsonStoreModule.cs | 4 ++-- .../Scripting/JsonStore/JsonStoreScriptModule.cs | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs index 49556b601d..34894badf7 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs @@ -74,7 +74,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore /// /// // ----------------------------------------------------------------- - public JsonStore(string value = "") + public JsonStore() : this("") {} + + public JsonStore(string value) { m_TakeStore = new List(); m_ReadStore = new List(); diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs index 6dae9566d0..26bc615110 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs @@ -85,7 +85,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore if ((m_config = config.Configs["JsonStore"]) == null) { // There is no configuration, the module is disabled - m_log.InfoFormat("[JsonStore] no configuration info"); + // m_log.InfoFormat("[JsonStore] no configuration info"); return; } @@ -97,7 +97,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return; } - m_log.InfoFormat("[JsonStore] module {0} enabled",(m_enabled ? "is" : "is not")); + m_log.DebugFormat("[JsonStore] module {0} enabled",(m_enabled ? "is" : "is not")); } // ----------------------------------------------------------------- diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs index 7aba860a89..c619d0d252 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs @@ -84,7 +84,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore if ((m_config = config.Configs["JsonStore"]) == null) { // There is no configuration, the module is disabled - m_log.InfoFormat("[JsonStoreScripts] no configuration info"); + // m_log.InfoFormat("[JsonStoreScripts] no configuration info"); return; } @@ -96,7 +96,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return; } - m_log.InfoFormat("[JsonStoreScripts] module {0} enabled",(m_enabled ? "is" : "is not")); + m_log.DebugFormat("[JsonStoreScripts] module {0} enabled",(m_enabled ? "is" : "is not")); } // ----------------------------------------------------------------- From 84891930aa73a013493ec511b13f7c8954d20770 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Tue, 17 Apr 2012 14:23:43 -0700 Subject: [PATCH 18/21] clean up some more logging spam in the jsonstore modules --- .../OptionalModules/Scripting/JsonStore/JsonStoreModule.cs | 3 ++- .../Scripting/JsonStore/JsonStoreScriptModule.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs index 26bc615110..311531c8d4 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs @@ -97,7 +97,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return; } - m_log.DebugFormat("[JsonStore] module {0} enabled",(m_enabled ? "is" : "is not")); + if (m_enabled) + m_log.DebugFormat("[JsonStore] module is enabled"); } // ----------------------------------------------------------------- diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs index c619d0d252..eda2aef9ed 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs @@ -96,7 +96,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return; } - m_log.DebugFormat("[JsonStoreScripts] module {0} enabled",(m_enabled ? "is" : "is not")); + if (m_enabled) + m_log.DebugFormat("[JsonStoreScripts] module is enabled"); } // ----------------------------------------------------------------- From 859646ef5cf016eecfefb53b2b388fe880c39a3a Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 17 Apr 2012 23:54:51 +0100 Subject: [PATCH 19/21] minor: Add some method doc. Add warnings since calling SOG link/delink methods directly rather than through Scene may allow race conditions. --- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 3 +++ .../Framework/Scenes/SceneObjectGroup.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index 0098addb42..67eb0fe128 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -91,6 +91,9 @@ namespace OpenSim.Region.Framework.Scenes /// protected internal Dictionary SceneObjectGroupsByLocalPartID = new Dictionary(); + /// + /// Lock to prevent object group update, linking and delinking operations from running concurrently. + /// private Object m_updateLock = new Object(); #endregion diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index a49ed13ed2..8e786c150e 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -1962,6 +1962,10 @@ namespace OpenSim.Region.Framework.Scenes /// /// Link the prims in a given group to this group /// + /// + /// Do not call this method directly - use Scene.LinkObjects() instead to avoid races between threads. + /// FIXME: There are places where scripts call these methods directly without locking. This is a potential race condition. + /// /// The group of prims which should be linked to this group public void LinkToGroup(SceneObjectGroup objectGroup) { @@ -2045,6 +2049,11 @@ namespace OpenSim.Region.Framework.Scenes /// Delink the given prim from this group. The delinked prim is established as /// an independent SceneObjectGroup. /// + /// + /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race + /// condition. But currently there is no + /// alternative method that does take a lonk to delink a single prim. + /// /// /// The object group of the newly delinked prim. Null if part could not be found public SceneObjectGroup DelinkFromGroup(uint partID) @@ -2056,6 +2065,11 @@ namespace OpenSim.Region.Framework.Scenes /// Delink the given prim from this group. The delinked prim is established as /// an independent SceneObjectGroup. /// + /// + /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race + /// condition. But currently there is no + /// alternative method that does take a lonk to delink a single prim. + /// /// /// /// The object group of the newly delinked prim. Null if part could not be found @@ -2081,6 +2095,11 @@ namespace OpenSim.Region.Framework.Scenes /// Delink the given prim from this group. The delinked prim is established as /// an independent SceneObjectGroup. /// + /// + /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race + /// condition. But currently there is no + /// alternative method that does take a lonk to delink a single prim. + /// /// /// /// The object group of the newly delinked prim. From c85f9d681a7e9cb09e8cf4de97643eadc7a9d4d8 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 18 Apr 2012 00:39:39 +0100 Subject: [PATCH 20/21] On "show part" command, show link number. This replaces the Parts count which was rather pointless for a prim (it was either 1 if a child or the number of parts if the root). This information is still avaliable on the "show object" command. --- .../CoreModules/World/Objects/Commands/ObjectCommandsModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs index f5a5c92c4a..06fea58ea3 100644 --- a/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs +++ b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs @@ -282,7 +282,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands sb.AppendFormat("Location: {0} @ {1}\n", sop.AbsolutePosition, sop.ParentGroup.Scene.RegionInfo.RegionName); sb.AppendFormat("Parent: {0}", sop.IsRoot ? "Is Root\n" : string.Format("{0} {1}\n", sop.ParentGroup.Name, sop.ParentGroup.UUID)); - sb.AppendFormat("Parts: {0}\n", !sop.IsRoot ? "1" : sop.ParentGroup.PrimCount.ToString());; + sb.AppendFormat("Link number: {0}\n", sop.LinkNum); return sb; } From ea73a035531a0e957f54fe897f3a3ff7ca3dc22d Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 18 Apr 2012 20:01:41 +0100 Subject: [PATCH 21/21] Don't re-add the assembly resolver for each script if not creating the appdomain --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index b7903d5a20..ad2f12e2ed 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1021,11 +1021,18 @@ namespace OpenSim.Region.ScriptEngine.XEngine AppDomain sandbox; if (m_AppDomainLoading) + { sandbox = AppDomain.CreateDomain( m_Scene.RegionInfo.RegionID.ToString(), evidence, appSetup); + m_AppDomains[appDomain].AssemblyResolve += + new ResolveEventHandler( + AssemblyResolver.OnAssemblyResolve); + } else + { sandbox = AppDomain.CurrentDomain; + } //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); @@ -1037,9 +1044,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine m_AppDomains[appDomain] = sandbox; - m_AppDomains[appDomain].AssemblyResolve += - new ResolveEventHandler( - AssemblyResolver.OnAssemblyResolve); m_DomainScripts[appDomain] = new List(); } catch (Exception e) @@ -1984,4 +1988,4 @@ namespace OpenSim.Region.ScriptEngine.XEngine // m_log.DebugFormat("[XEngine]: Could not find script with ID {0} to resume", itemID); } } -} \ No newline at end of file +}