From c43d4b557267547d07f6c90dc7e335ce4f7e07be Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 12 Mar 2013 22:16:09 +0000 Subject: [PATCH 1/9] Improve teleport cancellation in some circumstances, though cancelling teleports is still not recommended. Previously, hitting the cancel button on a teleport would cancel on the client side but the request was ignored on the server side. Cancel would still work if the teleport failed in the early stages (e.g. because the destination never replied to early CreateAgent and UpdateAgent messages). But if the teleport still completed after a delay here or later on, the viewer would become confused (usual symptom appears to be avatar being unable to move/reteleport). This commit makes OpenSimulator obey cancellations which are received before it sends the TeleportFinish event queue message and does proper cleanup. But cancellations received after this (which can happen even though the cancel button is removed as this messages comes on a different thread) can still result in a frozen avatar. This looks extremely difficult and impossible to fix. I can replicate the same problem on the Linden Lab grid by hitting cancel immediately after a teleport starts (a teleport which would otherwise quickly succeed). --- .../EntityTransfer/EntityTransferModule.cs | 59 ++++++++- .../EntityTransferStateMachine.cs | 124 ++++++++++++++---- 2 files changed, 149 insertions(+), 34 deletions(-) diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index 01b1668c3b..34f09240a8 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -148,6 +148,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer protected virtual void OnNewClient(IClientAPI client) { + client.OnTeleportCancel += OnClientCancelTeleport; client.OnTeleportHomeRequest += TeleportHome; client.OnTeleportLandmarkRequest += RequestTeleportLandmark; } @@ -168,6 +169,14 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer #region Agent Teleports + private void OnClientCancelTeleport(IClientAPI client) + { + m_entityTransferStateMachine.UpdateInTransit(client.AgentId, AgentTransferState.Cancelling); + + m_log.DebugFormat( + "[ENTITY TRANSFER MODULE]: Received teleport cancel request from {0} in {1}", client.Name, Scene.Name); + } + public void Teleport(ScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags) { if (sp.Scene.Permissions.IsGridGod(sp.UUID)) @@ -567,6 +576,15 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer return; } + if (m_entityTransferStateMachine.GetAgentTransferState(sp.UUID) == AgentTransferState.Cancelling) + { + m_log.DebugFormat( + "[ENTITY TRANSFER MODULE]: Cancelled teleport of {0} to {1} from {2} after CreateAgent on client request", + sp.Name, finalDestination.RegionName, sp.Scene.Name); + + return; + } + // Past this point we have to attempt clean up if the teleport fails, so update transfer state. m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.Transferring); @@ -631,7 +649,16 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer return; } - sp.ControllingClient.SendTeleportProgress(teleportFlags | (uint)TeleportFlags.DisableCancel, "sending_dest"); + if (m_entityTransferStateMachine.GetAgentTransferState(sp.UUID) == AgentTransferState.Cancelling) + { + m_log.DebugFormat( + "[ENTITY TRANSFER MODULE]: Cancelled teleport of {0} to {1} from {2} after UpdateAgent on client request", + sp.Name, finalDestination.RegionName, sp.Scene.Name); + + CleanupAbortedInterRegionTeleport(sp, finalDestination); + + return; + } m_log.DebugFormat( "[ENTITY TRANSFER MODULE]: Sending new CAPS seed url {0} from {1} to {2}", @@ -714,14 +741,19 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer // } } - protected virtual void Fail(ScenePresence sp, GridRegion finalDestination, bool logout) + /// + /// Clean up an inter-region teleport that did not complete, either because of simulator failure or cancellation. + /// + /// + /// All operations here must be idempotent so that we can call this method at any point in the teleport process + /// up until we send the TeleportFinish event quene event to the viewer. + /// + /// + /// + protected virtual void CleanupAbortedInterRegionTeleport(ScenePresence sp, GridRegion finalDestination) { m_entityTransferStateMachine.UpdateInTransit(sp.UUID, AgentTransferState.CleaningUp); - // Client never contacted destination. Let's restore everything back - sp.ControllingClient.SendTeleportFailed("Problems connecting to destination."); - - // Fail. Reset it back sp.IsChildAgent = false; ReInstantiateScripts(sp); @@ -729,7 +761,20 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer // Finally, kill the agent we just created at the destination. Scene.SimulationService.CloseAgent(finalDestination, sp.UUID); + } + /// + /// Signal that the inter-region teleport failed and perform cleanup. + /// + /// + /// + /// + protected virtual void Fail(ScenePresence sp, GridRegion finalDestination, bool logout) + { + CleanupAbortedInterRegionTeleport(sp, finalDestination); + + sp.ControllingClient.SendTeleportFailed( + string.Format("Problems connecting to destination {0}", finalDestination.RegionName)); sp.Scene.EventManager.TriggerTeleportFail(sp.ControllingClient, logout); } @@ -2097,7 +2142,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer public bool IsInTransit(UUID id) { - return m_entityTransferStateMachine.IsInTransit(id); + return m_entityTransferStateMachine.GetAgentTransferState(id) != null; } protected void ReInstantiateScripts(ScenePresence sp) diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs index d0cab49563..24d81d9480 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferStateMachine.cs @@ -51,8 +51,9 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer /// This is a state machine. /// /// [Entry] => Preparing - /// Preparing => { Transferring || CleaningUp || [Exit] } - /// Transferring => { ReceivedAtDestination || CleaningUp } + /// Preparing => { Transferring || Cancelling || CleaningUp || [Exit] } + /// Transferring => { ReceivedAtDestination || Cancelling || CleaningUp } + /// Cancelling => CleaningUp /// ReceivedAtDestination => CleaningUp /// CleaningUp => [Exit] /// @@ -64,7 +65,8 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer Preparing, // The agent is being prepared for transfer Transferring, // The agent is in the process of being transferred to a destination ReceivedAtDestination, // The destination has notified us that the agent has been successfully received - CleaningUp // The agent is being changed to child/removed after a transfer + CleaningUp, // The agent is being changed to child/removed after a transfer + Cancelling // The user has cancelled the teleport but we have yet to act upon this. } /// @@ -115,42 +117,110 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer /// /// /// Illegal transitions will throw an Exception - internal void UpdateInTransit(UUID id, AgentTransferState newState) + internal bool UpdateInTransit(UUID id, AgentTransferState newState) { + bool transitionOkay = false; + + // We don't want to throw an exception on cancel since this can come it at any time. + bool failIfNotOkay = true; + + // Should be a failure message if failure is not okay. + string failureMessage = null; + + AgentTransferState? oldState = null; + lock (m_agentsInTransit) { // Illegal to try and update an agent that's not actually in transit. if (!m_agentsInTransit.ContainsKey(id)) - throw new Exception( - string.Format( - "Agent with ID {0} is not registered as in transit in {1}", - id, m_mod.Scene.RegionInfo.RegionName)); + { + if (newState != AgentTransferState.Cancelling) + failureMessage = string.Format( + "Agent with ID {0} is not registered as in transit in {1}", + id, m_mod.Scene.RegionInfo.RegionName); + else + failIfNotOkay = false; + } + else + { + oldState = m_agentsInTransit[id]; - AgentTransferState oldState = m_agentsInTransit[id]; + if (newState == AgentTransferState.CleaningUp && oldState != AgentTransferState.CleaningUp) + { + transitionOkay = true; + } + else if (newState == AgentTransferState.Transferring && oldState == AgentTransferState.Preparing) + { + transitionOkay = true; + } + else if (newState == AgentTransferState.ReceivedAtDestination && oldState == AgentTransferState.Transferring) + { + transitionOkay = true; + } + else + { + if (newState == AgentTransferState.Cancelling + && (oldState == AgentTransferState.Preparing || oldState == AgentTransferState.Transferring)) + { + transitionOkay = true; + } + else + { + failIfNotOkay = false; + } + } - bool transitionOkay = false; - - if (newState == AgentTransferState.CleaningUp && oldState != AgentTransferState.CleaningUp) - transitionOkay = true; - else if (newState == AgentTransferState.Transferring && oldState == AgentTransferState.Preparing) - transitionOkay = true; - else if (newState == AgentTransferState.ReceivedAtDestination && oldState == AgentTransferState.Transferring) - transitionOkay = true; + if (!transitionOkay) + failureMessage + = string.Format( + "Agent with ID {0} is not allowed to move from old transit state {1} to new state {2} in {3}", + id, oldState, newState, m_mod.Scene.RegionInfo.RegionName); + } if (transitionOkay) + { m_agentsInTransit[id] = newState; - else - throw new Exception( - string.Format( - "Agent with ID {0} is not allowed to move from old transit state {1} to new state {2} in {3}", - id, oldState, newState, m_mod.Scene.RegionInfo.RegionName)); + +// m_log.DebugFormat( +// "[ENTITY TRANSFER STATE MACHINE]: Changed agent with id {0} from state {1} to {2} in {3}", +// id, oldState, newState, m_mod.Scene.Name); + } + else if (failIfNotOkay) + { + throw new Exception(failureMessage); + } +// else +// { +// if (oldState != null) +// m_log.DebugFormat( +// "[ENTITY TRANSFER STATE MACHINE]: Ignored change of agent with id {0} from state {1} to {2} in {3}", +// id, oldState, newState, m_mod.Scene.Name); +// else +// m_log.DebugFormat( +// "[ENTITY TRANSFER STATE MACHINE]: Ignored change of agent with id {0} to state {1} in {2} since agent not in transit", +// id, newState, m_mod.Scene.Name); +// } } + + return transitionOkay; } - internal bool IsInTransit(UUID id) + /// + /// Gets the current agent transfer state. + /// + /// Null if the agent is not in transit + /// + /// Identifier. + /// + internal AgentTransferState? GetAgentTransferState(UUID id) { lock (m_agentsInTransit) - return m_agentsInTransit.ContainsKey(id); + { + if (!m_agentsInTransit.ContainsKey(id)) + return null; + else + return m_agentsInTransit[id]; + } } /// @@ -203,14 +273,14 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer lock (m_agentsInTransit) { - if (!IsInTransit(id)) + AgentTransferState? currentState = GetAgentTransferState(id); + + if (currentState == null) throw new Exception( string.Format( "Asked to wait for destination callback for agent with ID {0} in {1} but agent is not in transit", id, m_mod.Scene.RegionInfo.RegionName)); - AgentTransferState currentState = m_agentsInTransit[id]; - if (currentState != AgentTransferState.Transferring && currentState != AgentTransferState.ReceivedAtDestination) throw new Exception( string.Format( From fb1211ad5ef86bf6a1b6170775f1ebb4adcb4cb7 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 12 Mar 2013 23:01:27 +0000 Subject: [PATCH 2/9] Add DisableInterRegionTeleportCancellation option in [EntityTransfer] section of OpenSim.ini. False by default. This option allows the simulator to specify that the cancel button on inter-region teleports should never appear. This exists because sometimes cancellation will result in a stuck avatar requiring relog. It may be hard to prevent this due to the protocol design (the LL grid has the same issue) In small controlled grids where teleport failure is practically impossible it can be better to disable teleport cancellation entirely. --- .../EntityTransfer/EntityTransferModule.cs | 21 ++++++++++++++++++- bin/OpenSim.ini.example | 7 +++++++ bin/OpenSimDefaults.ini | 5 +++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index 34f09240a8..9b1b69aaa4 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -66,6 +66,17 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer /// public bool WaitForAgentArrivedAtDestination { get; set; } + /// + /// If true then we ask the viewer to disable teleport cancellation and ignore teleport requests. + /// + /// + /// This is useful in situations where teleport is very likely to always succeed and we want to avoid a + /// situation where avatars can be come 'stuck' due to a failed teleport cancellation. Unfortunately, the + /// nature of the teleport protocol makes it extremely difficult (maybe impossible) to make teleport + /// cancellation consistently suceed. + /// + public bool DisableInterRegionTeleportCancellation { get; set; } + protected bool m_Enabled = false; public Scene Scene { get; private set; } @@ -116,6 +127,9 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer IConfig transferConfig = source.Configs["EntityTransfer"]; if (transferConfig != null) { + DisableInterRegionTeleportCancellation + = transferConfig.GetBoolean("DisableInterRegionTeleportCancellation", false); + WaitForAgentArrivedAtDestination = transferConfig.GetBoolean("wait_for_callback", WaitForAgentArrivedAtDestinationDefault); @@ -148,9 +162,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer protected virtual void OnNewClient(IClientAPI client) { - client.OnTeleportCancel += OnClientCancelTeleport; client.OnTeleportHomeRequest += TeleportHome; client.OnTeleportLandmarkRequest += RequestTeleportLandmark; + + if (!DisableInterRegionTeleportCancellation) + client.OnTeleportCancel += OnClientCancelTeleport; } public virtual void Close() {} @@ -528,6 +544,9 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer if (sp.ParentID != (uint)0) sp.StandUp(); + if (DisableInterRegionTeleportCancellation) + teleportFlags |= (uint)TeleportFlags.DisableCancel; + // At least on LL 3.3.4, this is not strictly necessary - a teleport will succeed without sending this to // the viewer. However, it might mean that the viewer does not see the black teleport screen (untested). sp.ControllingClient.SendTeleportStart(teleportFlags); diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index e078e86807..ce2e6008cf 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -541,6 +541,13 @@ ; shout_distance = 100 +[EntityTransfer] + ;# {DisableInterRegionTeleportCancellation} {} {Determine whether the cancel button is shown at all during teleports.} {false true} false + ;; This option exists because cancelling at certain points can result in an unuseable session (frozen avatar, etc.) + ;; Disabling cancellation can be okay in small closed grids where all teleports are highly likely to suceed. + ;DisableInterRegionTeleportCancellation = false + + [Messaging] ;# {OfflineMessageModule} {} {Module to use for offline message storage} {OfflineMessageModule "Offline Message Module V2" *} ;; Module to handle offline messaging. The core module requires an external diff --git a/bin/OpenSimDefaults.ini b/bin/OpenSimDefaults.ini index 417150af69..1d2c0cff86 100644 --- a/bin/OpenSimDefaults.ini +++ b/bin/OpenSimDefaults.ini @@ -628,6 +628,11 @@ ; Minimum user level required for HyperGrid teleports LevelHGTeleport = 0 + ; Determine whether the cancel button is shown at all during teleports. + ; This option exists because cancelling at certain points can result in an unuseable session (frozen avatar, etc.) + ; Disabling cancellation can be okay in small closed grids where all teleports are highly likely to suceed. + DisableInterRegionTeleportCancellation = false + [Messaging] ; Control which region module is used for instant messaging. From 0d25be3f8162fc4e99cd5abdaceb425a1f7370fe Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 13 Mar 2013 00:19:37 +0000 Subject: [PATCH 3/9] Make C# scripts return correct error line and column numbers instead of failing because they have no linemap. Adapted fix from http://opensimulator.org/mantis/view.php?id=6571 Thanks Nickel Briand --- .../Region/ScriptEngine/Shared/CodeTools/Compiler.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs index 9d20c9ec80..b71afe338e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs @@ -662,13 +662,18 @@ namespace SecondLife { string severity = CompErr.IsWarning ? "Warning" : "Error"; - KeyValuePair lslPos; + KeyValuePair errorPos; // Show 5 errors max, but check entire list for errors if (severity == "Error") { - lslPos = FindErrorPosition(CompErr.Line, CompErr.Column, m_lineMaps[assembly]); + // C# scripts will not have a linemap since theres no line translation involved. + if (!m_lineMaps.ContainsKey(assembly)) + errorPos = new KeyValuePair(CompErr.Line, CompErr.Column); + else + errorPos = FindErrorPosition(CompErr.Line, CompErr.Column, m_lineMaps[assembly]); + string text = CompErr.ErrorText; // Use LSL type names @@ -678,7 +683,7 @@ namespace SecondLife // The Second Life viewer's script editor begins // countingn lines and columns at 0, so we subtract 1. errtext += String.Format("({0},{1}): {4} {2}: {3}\n", - lslPos.Key - 1, lslPos.Value - 1, + errorPos.Key - 1, errorPos.Value - 1, CompErr.ErrorNumber, text, severity); hadErrors = true; } From f8a4d95bdd2bff70a428d386edad1ca91e15c6c0 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 13 Mar 2013 00:22:07 +0000 Subject: [PATCH 4/9] minor: Remove mono compiler warning in LLClientView --- OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index bae79523ab..7ea538c907 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -7069,7 +7069,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (handlerUpdatePrimFlags != null) { - byte[] data = Pack.ToBytes(); +// byte[] data = Pack.ToBytes(); // 46,47,48 are special positions within the packet // This may change so perhaps we need a better way // of storing this (OMV.FlagUpdatePacket.UsePhysics,etc?) From b7216f4daffca6dad4049c84982beca6dca9b094 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 13 Mar 2013 00:46:17 +0000 Subject: [PATCH 5/9] minor: save some commented out log lines which will be useful again in future debugging of VectorRenderModule --- .../CoreModules/Scripting/VectorRender/VectorRenderModule.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs index f04fabe897..4cecd85941 100644 --- a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs @@ -516,6 +516,9 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender foreach (string line in GetLines(data, dataDelim)) { string nextLine = line.Trim(); + +// m_log.DebugFormat("[VECTOR RENDER MODULE]: Processing line '{0}'", nextLine); + //replace with switch, or even better, do some proper parsing if (nextLine.StartsWith("MoveTo")) { @@ -829,6 +832,8 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender float y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture); PointF point = new PointF(x, y); points[i / 2] = point; + +// m_log.DebugFormat("[VECTOR RENDER MODULE]: Got point {0}", points[i / 2]); } } } From 5c53660a7f055be9ed41f30893de673acac8a0f1 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 13 Mar 2013 22:59:06 +0000 Subject: [PATCH 6/9] Add prototype dynamic objects map for scene object parts This allows region modules to add dynamic objects to SOPs rather than having to continually push and pull OSD dynamic attributes. This is to explore the original MOAP use case for dynamic attributes where it could be very awkward and possibly time-consuming to keep reconstructing MediaEntrys from stored DynamicAttributes. This commit adds a DOExampleModule to demonstrate/evolve this code. Dynamic objects involve no storage or persistence changes - the 'backing store' for any data that does need to be saved will remain the DAMap. DOExampleModule in this commit only attaches a fresh dynamic object. Actually constructing this from stored dynamic attributes and handling persistence is left for later. These changes should affect no existing functionality, though it may or may not reveal necessary changes in DAMap down the road. --- OpenSim/Framework/DAMap.cs | 2 +- OpenSim/Framework/DOMap.cs | 98 +++++++++++++++ .../DynamicAttributes/DOExampleModule.cs | 117 ++++++++++++++++++ .../Framework/Scenes/SceneObjectPart.cs | 22 ++++ 4 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 OpenSim/Framework/DOMap.cs create mode 100644 OpenSim/Region/CoreModules/Framework/DynamicAttributes/DOExampleModule.cs diff --git a/OpenSim/Framework/DAMap.cs b/OpenSim/Framework/DAMap.cs index 64cea77469..df4a6bc4a7 100644 --- a/OpenSim/Framework/DAMap.cs +++ b/OpenSim/Framework/DAMap.cs @@ -180,7 +180,7 @@ namespace OpenSim.Framework /// Validate the key used for storing separate data stores. /// /// - private static void ValidateKey(string key) + public static void ValidateKey(string key) { if (key.Length < MIN_STORE_NAME_LENGTH) throw new Exception("Minimum store name length is " + MIN_STORE_NAME_LENGTH); diff --git a/OpenSim/Framework/DOMap.cs b/OpenSim/Framework/DOMap.cs new file mode 100644 index 0000000000..755e129a13 --- /dev/null +++ b/OpenSim/Framework/DOMap.cs @@ -0,0 +1,98 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * 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 OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Xml; +using System.Xml.Schema; +using System.Xml.Serialization; +using OpenMetaverse; +using OpenMetaverse.StructuredData; + +namespace OpenSim.Framework +{ + /// + /// This class stores and retrieves dynamic objects. + /// + /// + /// Experimental - DO NOT USE. + /// + public class DOMap + { + private IDictionary m_map; + + public void Add(string key, object dynObj) + { + DAMap.ValidateKey(key); + + lock (this) + { + if (m_map == null) + m_map = new Dictionary(); + + m_map.Add(key, dynObj); + } + } + + public bool ContainsKey(string key) + { + return Get(key) != null; + } + + /// + /// Get a dynamic object + /// + /// + /// Not providing an index method so that users can't casually overwrite each other's objects. + /// + /// + public object Get(string key) + { + lock (this) + { + if (m_map == null) + return null; + else + return m_map[key]; + } + } + + public bool Remove(string key) + { + lock (this) + { + if (m_map == null) + return false; + else + return m_map.Remove(key); + } + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DOExampleModule.cs b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DOExampleModule.cs new file mode 100644 index 0000000000..71bb3f0e60 --- /dev/null +++ b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DOExampleModule.cs @@ -0,0 +1,117 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * 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 OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Reflection; +using log4net; +using Mono.Addins; +using Nini.Config; +using OpenMetaverse; +using OpenMetaverse.Packets; +using OpenMetaverse.StructuredData; +using OpenSim.Framework; +using OpenSim.Region.Framework; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.Framework.DynamicAttributes.DOExampleModule +{ + /// + /// Example module for experimenting with and demonstrating dynamic object ideas. + /// + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DOExampleModule")] + public class DOExampleModule : INonSharedRegionModule + { + public class MyObject + { + public int Moves { get; set; } + } + + // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private static readonly bool ENABLED = false; // enable for testing + + private Scene m_scene; + private IDialogModule m_dialogMod; + + public string Name { get { return "DOExample Module"; } } + public Type ReplaceableInterface { get { return null; } } + + public void Initialise(IConfigSource source) {} + + public void AddRegion(Scene scene) + { + if (ENABLED) + { + m_scene = scene; + m_scene.EventManager.OnObjectAddedToScene += OnObjectAddedToScene; + m_scene.EventManager.OnSceneGroupMove += OnSceneGroupMove; + m_dialogMod = m_scene.RequestModuleInterface(); + } + } + + public void RemoveRegion(Scene scene) + { + if (ENABLED) + { + m_scene.EventManager.OnSceneGroupMove -= OnSceneGroupMove; + } + } + + public void RegionLoaded(Scene scene) {} + + public void Close() + { + RemoveRegion(m_scene); + } + + private void OnObjectAddedToScene(SceneObjectGroup so) + { + so.RootPart.DynObjs.Add(Name, new MyObject()); + } + + private bool OnSceneGroupMove(UUID groupId, Vector3 delta) + { + SceneObjectGroup so = m_scene.GetSceneObjectGroup(groupId); + + if (so == null) + return true; + + object rawObj = so.RootPart.DynObjs.Get(Name); + + if (rawObj != null) + { + MyObject myObj = (MyObject)rawObj; + + m_dialogMod.SendGeneralAlert(string.Format("{0} {1} moved {2} times", so.Name, so.UUID, ++myObj.Moves)); + } + + return true; + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 3e9a6fa217..ee7c4f4aec 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -129,6 +129,27 @@ namespace OpenSim.Region.Framework.Scenes /// Dynamic attributes can be created and deleted as required. /// public DAMap DynAttrs { get; set; } + + private DOMap m_dynObjs; + + /// + /// Dynamic objects that can be created and deleted as required. + /// + public DOMap DynObjs + { + get + { + if (m_dynObjs == null) + m_dynObjs = new DOMap(); + + return m_dynObjs; + } + + set + { + m_dynObjs = value; + } + } /// /// Is this a root part? @@ -348,6 +369,7 @@ namespace OpenSim.Region.Framework.Scenes Rezzed = DateTime.UtcNow; Description = String.Empty; DynAttrs = new DAMap(); + DynObjs = new DOMap(); // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol, // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from From 39a0928052bcaf4b81af326e129cbfd6329f9292 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 13 Mar 2013 23:17:27 +0000 Subject: [PATCH 7/9] minor: Remove some mono compiler warnings in OpenSim.Framework.dll --- OpenSim/Framework/PluginManager.cs | 4 ++-- OpenSim/Framework/Util.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenSim/Framework/PluginManager.cs b/OpenSim/Framework/PluginManager.cs index 00263f514f..011709602b 100644 --- a/OpenSim/Framework/PluginManager.cs +++ b/OpenSim/Framework/PluginManager.cs @@ -218,7 +218,7 @@ namespace OpenSim.Framework Console.WriteLine ("Looking for updates..."); Repositories.UpdateAllRepositories (ps); Console.WriteLine ("Available add-in updates:"); - bool found = false; + AddinRepositoryEntry[] entries = Repositories.GetAvailableUpdates(); foreach (AddinRepositoryEntry entry in entries) @@ -541,7 +541,7 @@ namespace OpenSim.Framework { list.AddRange(PluginRegistry.GetAddins()); } - catch(Exception e) + catch (Exception) { Addin[] x = xlist.ToArray(typeof(Addin)) as Addin[]; return x; diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 0fa54b246d..94a172c399 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -303,12 +303,12 @@ namespace OpenSim.Framework // Clamp the maximum magnitude of a vector public static Vector3 ClampV(Vector3 x, float max) { - Vector3 ret = x; float lenSq = x.LengthSquared(); if (lenSq > (max * max)) { x = x / x.Length() * max; } + return x; } From 48d41ef3076eb4c2a8c4a67d811630ab7b498469 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 13 Mar 2013 23:25:56 +0000 Subject: [PATCH 8/9] Remove unnecessary instation of DOMap() in SOP from commit 5c53660 since this is being done lazily --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index ee7c4f4aec..a8b63fedeb 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -369,7 +369,6 @@ namespace OpenSim.Region.Framework.Scenes Rezzed = DateTime.UtcNow; Description = String.Empty; DynAttrs = new DAMap(); - DynObjs = new DOMap(); // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol, // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from From 43220afda2a69e7849c2ab9f98dcbd61a3da218b Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 13 Mar 2013 23:42:14 +0000 Subject: [PATCH 9/9] Improve DAExampleModule to show current necessary locking to avoid race conditions with a serialization thread. --- .../DynamicAttributes/DAExampleModule.cs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs index 37131b9a53..f8744950bf 100644 --- a/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs +++ b/OpenSim/Region/CoreModules/Framework/DynamicAttributes/DAExampleModule.cs @@ -85,19 +85,27 @@ namespace OpenSim.Region.Framework.DynamicAttributes.DAExampleModule { OSDMap attrs = null; SceneObjectPart sop = m_scene.GetSceneObjectPart(groupId); + + if (sop == null) + return true; + if (!sop.DynAttrs.TryGetValue(Name, out attrs)) attrs = new OSDMap(); OSDInteger newValue; - - if (!attrs.ContainsKey("moves")) - newValue = new OSDInteger(1); - else - newValue = new OSDInteger(((OSDInteger)attrs["moves"]).AsInteger() + 1); - - attrs["moves"] = newValue; - sop.DynAttrs[Name] = attrs; + // We have to lock on the entire dynamic attributes map to avoid race conditions with serialization code. + lock (sop.DynAttrs) + { + if (!attrs.ContainsKey("moves")) + newValue = new OSDInteger(1); + else + newValue = new OSDInteger(attrs["moves"].AsInteger() + 1); + + attrs["moves"] = newValue; + + sop.DynAttrs[Name] = attrs; + } m_dialogMod.SendGeneralAlert(string.Format("{0} {1} moved {2} times", sop.Name, sop.UUID, newValue));