From c1a34cd8da293e63d3cba70b5271c9a297789db2 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 18 Aug 2011 00:53:05 +0100 Subject: [PATCH] Don't try to save changed attachment states when an NPC with attachments is removed from the scene. This is done by introducing a PresenceType enum into ScenePresence which currently has two values, User and Npc. This seems better than a SaveAttachments flag in terms of code comprehension, though I'm still slightly uneasy about introducing these semantics to core objects --- OpenSim/Framework/IScene.cs | 7 ++-- OpenSim/Framework/PresenceType.cs | 39 +++++++++++++++++++ .../ClientStack/Linden/UDP/LLClientView.cs | 2 +- .../Avatar/Attachments/AttachmentsModule.cs | 4 +- .../Examples/SimpleModule/RegionModule.cs | 2 +- OpenSim/Region/Framework/Scenes/Scene.cs | 9 +++-- OpenSim/Region/Framework/Scenes/SceneBase.cs | 2 +- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 5 ++- .../Region/Framework/Scenes/ScenePresence.cs | 12 ++++-- .../Scenes/Tests/ScenePresenceAgentTests.cs | 4 +- .../Server/IRCClientView.cs | 2 +- .../OptionalModules/World/NPC/NPCModule.cs | 2 +- OpenSim/Tests/Common/Helpers/SceneHelpers.cs | 2 +- OpenSim/Tests/Common/Mock/TestClient.cs | 2 +- 14 files changed, 71 insertions(+), 23 deletions(-) create mode 100644 OpenSim/Framework/PresenceType.cs diff --git a/OpenSim/Framework/IScene.cs b/OpenSim/Framework/IScene.cs index b5f975b7be..8f7a2e5b4e 100644 --- a/OpenSim/Framework/IScene.cs +++ b/OpenSim/Framework/IScene.cs @@ -72,10 +72,11 @@ namespace OpenSim.Framework /// /// Register the new client with the scene. The client starts off as a child agent - the later agent crossing - /// will promote it to a root agent during login. + /// will promote it to a root agent. /// - /// + /// The type of agent to add. + void AddNewClient(IClientAPI client, PresenceType type); /// /// Remove the given client from the scene. diff --git a/OpenSim/Framework/PresenceType.cs b/OpenSim/Framework/PresenceType.cs new file mode 100644 index 0000000000..8c4c6e686b --- /dev/null +++ b/OpenSim/Framework/PresenceType.cs @@ -0,0 +1,39 @@ +/* + * 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; + +namespace OpenSim.Framework +{ + /// + /// Indicate the type of ScenePresence. + /// + public enum PresenceType + { + User, + Npc + } +} \ No newline at end of file diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 1d35973646..f71871e1c7 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -692,7 +692,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP public virtual void Start() { - m_scene.AddNewClient(this); + m_scene.AddNewClient(this, PresenceType.User); RefreshGroupMembership(); } diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index a3639e8fd0..97a1be607d 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -501,10 +501,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments /// /// Update the attachment asset for the new sog details if they have changed. /// - /// + /// /// This is essential for preserving attachment attributes such as permission. Unlike normal scene objects, /// these details are not stored on the region. - /// + /// /// /// /// diff --git a/OpenSim/Region/Examples/SimpleModule/RegionModule.cs b/OpenSim/Region/Examples/SimpleModule/RegionModule.cs index 088b81876a..3b8ce379f0 100644 --- a/OpenSim/Region/Examples/SimpleModule/RegionModule.cs +++ b/OpenSim/Region/Examples/SimpleModule/RegionModule.cs @@ -95,7 +95,7 @@ namespace OpenSim.Region.Examples.SimpleModule for (int i = 0; i < 1; i++) { MyNpcCharacter m_character = new MyNpcCharacter(m_scene); - m_scene.AddNewClient(m_character); + m_scene.AddNewClient(m_character, PresenceType.Npc); m_scene.AgentCrossing(m_character.AgentId, Vector3.Zero, false); } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 13b4cbcb71..ae88a87712 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2543,10 +2543,11 @@ namespace OpenSim.Region.Framework.Scenes #region Add/Remove Avatar Methods /// - /// Adding a New Client and Create a Presence for it. + /// Add a new client and create a child agent for it. /// /// - public override void AddNewClient(IClientAPI client) + /// The type of agent to add. + public override void AddNewClient(IClientAPI client, PresenceType type) { AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode); bool vialogin = false; @@ -2566,7 +2567,7 @@ namespace OpenSim.Region.Framework.Scenes m_clientManager.Add(client); SubscribeToClientEvents(client); - ScenePresence sp = m_sceneGraph.CreateAndAddChildScenePresence(client, aCircuit.Appearance); + ScenePresence sp = m_sceneGraph.CreateAndAddChildScenePresence(client, aCircuit.Appearance, type); m_eventManager.TriggerOnNewPresence(sp); sp.TeleportFlags = (TeleportFlags)aCircuit.teleportFlags; @@ -3149,7 +3150,7 @@ namespace OpenSim.Region.Framework.Scenes m_eventManager.TriggerOnRemovePresence(agentID); - if (avatar != null && (!avatar.IsChildAgent)) + if (avatar != null && (!avatar.IsChildAgent) && avatar.PresenceType != PresenceType.Npc) avatar.SaveChangedAttachments(); ForEachClient( diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs index 2f1cdc1212..ec94f105cf 100644 --- a/OpenSim/Region/Framework/Scenes/SceneBase.cs +++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs @@ -175,7 +175,7 @@ namespace OpenSim.Region.Framework.Scenes #region Add/Remove Agent/Avatar - public abstract void AddNewClient(IClientAPI client); + public abstract void AddNewClient(IClientAPI client, PresenceType type); public abstract void RemoveClient(UUID agentID, bool closeChildAgents); public bool TryGetScenePresence(UUID agentID, out object scenePresence) diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index 65dc2c9cf6..f40b373e15 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -590,12 +590,13 @@ namespace OpenSim.Region.Framework.Scenes } } - protected internal ScenePresence CreateAndAddChildScenePresence(IClientAPI client, AvatarAppearance appearance) + protected internal ScenePresence CreateAndAddChildScenePresence( + IClientAPI client, AvatarAppearance appearance, PresenceType type) { ScenePresence newAvatar = null; // ScenePresence always defaults to child agent - newAvatar = new ScenePresence(client, m_parentScene, m_regInfo, appearance); + newAvatar = new ScenePresence(client, m_parentScene, m_regInfo, appearance, type); AddScenePresence(newAvatar); diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 90c4706c4b..e3bd393b80 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -75,6 +75,11 @@ namespace OpenSim.Region.Framework.Scenes private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + /// + /// What type of presence is this? User, NPC, etc. + /// + public PresenceType PresenceType { get; private set; } + // private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes(); private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags)); private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f); @@ -715,8 +720,9 @@ namespace OpenSim.Region.Framework.Scenes m_animator = new ScenePresenceAnimator(this); } - private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this() + private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, PresenceType type) : this() { + PresenceType = type; m_DrawDistance = world.DefaultDrawDistance; m_rootRegionHandle = reginfo.RegionHandle; m_controllingClient = client; @@ -764,8 +770,8 @@ namespace OpenSim.Region.Framework.Scenes SetDirectionVectors(); } - public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance) - : this(client, world, reginfo) + public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance, PresenceType type) + : this(client, world, reginfo, type) { m_appearance = appearance; } diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs index dd2c7170fa..35b41fb6c1 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs @@ -207,7 +207,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests scene.NewUserConnection(acd1, 0, out reason); if (testclient == null) testclient = new TestClient(acd1, scene); - scene.AddNewClient(testclient); + scene.AddNewClient(testclient, PresenceType.User); ScenePresence presence = scene.GetScenePresence(agent1); presence.MakeRootAgent(new Vector3(90,90,90),false); @@ -257,7 +257,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests // Adding child agent to region 1001 string reason; scene2.NewUserConnection(acd1,0, out reason); - scene2.AddNewClient(testclient); + scene2.AddNewClient(testclient, PresenceType.User); ScenePresence presence = scene.GetScenePresence(agent1); presence.MakeRootAgent(new Vector3(0,unchecked(Constants.RegionSize-1),0), true); diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs index 15201da44d..c413634c61 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs @@ -893,7 +893,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server public void Start() { - Scene.AddNewClient(this); + Scene.AddNewClient(this, PresenceType.User); // Mimicking LLClientView which gets always set appearance from client. Scene scene = (Scene)Scene; diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 3b7ae9d246..c1da803a40 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -190,7 +190,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC // } scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); - scene.AddNewClient(npcAvatar); + scene.AddNewClient(npcAvatar, PresenceType.Npc); ScenePresence sp; if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs index 8d2108c116..03df7abddc 100644 --- a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs +++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs @@ -379,7 +379,7 @@ namespace OpenSim.Tests.Common // Stage 2: add the new client as a child agent to the scene TestClient client = new TestClient(agentData, scene); - scene.AddNewClient(client); + scene.AddNewClient(client, PresenceType.User); // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent. ScenePresence scp = scene.GetScenePresence(agentData.AgentID); diff --git a/OpenSim/Tests/Common/Mock/TestClient.cs b/OpenSim/Tests/Common/Mock/TestClient.cs index 7b64947221..b7cefeb9b5 100644 --- a/OpenSim/Tests/Common/Mock/TestClient.cs +++ b/OpenSim/Tests/Common/Mock/TestClient.cs @@ -579,7 +579,7 @@ namespace OpenSim.Tests.Common.Mock // Stage 2: add the new client as a child agent to the scene TeleportSceneClient = new TestClient(newAgent, TeleportTargetScene); - TeleportTargetScene.AddNewClient(TeleportSceneClient); + TeleportTargetScene.AddNewClient(TeleportSceneClient, PresenceType.User); } public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint,