Browse Source

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
Justin Clark-Casey (justincc) 12 years ago
parent
commit
c1a34cd8da

+ 4 - 3
OpenSim/Framework/IScene.cs

@@ -72,10 +72,11 @@ namespace OpenSim.Framework
 
         /// <summary>
         /// 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.
         /// </summary>
-        /// <param name="client"></param        
-        void AddNewClient(IClientAPI client);
+        /// <param name="client"></param>
+        /// <param name="type">The type of agent to add.</param>
+        void AddNewClient(IClientAPI client, PresenceType type);
 
         /// <summary>
         /// Remove the given client from the scene.

+ 39 - 0
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
+{
+    /// <summary>
+    /// Indicate the type of ScenePresence.
+    /// </summary>
+    public enum PresenceType
+    {
+        User,
+        Npc
+    }
+}

+ 1 - 1
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();
         }

+ 2 - 2
OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs

@@ -501,10 +501,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
         /// <summary>
         /// Update the attachment asset for the new sog details if they have changed.
         /// </summary>
-        /// 
+        /// <remarks>
         /// This is essential for preserving attachment attributes such as permission.  Unlike normal scene objects,
         /// these details are not stored on the region.
-        /// 
+        /// </remarks>
         /// <param name="remoteClient"></param>
         /// <param name="grp"></param>
         /// <param name="itemID"></param>

+ 1 - 1
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);
             }
 

+ 5 - 4
OpenSim/Region/Framework/Scenes/Scene.cs

@@ -2543,10 +2543,11 @@ namespace OpenSim.Region.Framework.Scenes
         #region Add/Remove Avatar Methods
 
         /// <summary>
-        /// Adding a New Client and Create a Presence for it.
+        /// Add a new client and create a child agent for it.
         /// </summary>
         /// <param name="client"></param>
-        public override void AddNewClient(IClientAPI client)
+        /// <param name="type">The type of agent to add.</param>
+        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(

+ 1 - 1
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)

+ 3 - 2
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);
 

+ 9 - 3
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);
 
+        /// <summary>
+        /// What type of presence is this?  User, NPC, etc.
+        /// </summary>
+        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;
         }

+ 2 - 2
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);

+ 1 - 1
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;

+ 1 - 1
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))

+ 1 - 1
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);

+ 1 - 1
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,