From dc200d7bb5a7246d56288d6437ee653ee9839800 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 19:38:36 +0000 Subject: [PATCH 01/13] Add new ScenePresenceSitTests with a single sit/stand test --- .../Scenes/Tests/ScenePresenceSitTests.cs | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs new file mode 100644 index 0000000000..627bce7f83 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs @@ -0,0 +1,103 @@ +/* + * 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.Reflection; +using Nini.Config; +using NUnit.Framework; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Framework.Servers; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; +using OpenSim.Tests.Common; +using OpenSim.Tests.Common.Mock; +using System.Threading; + +namespace OpenSim.Region.Framework.Scenes.Tests +{ + [TestFixture] + public class ScenePresenceSitTests + { + private TestScene m_scene; +// private AvatarFactoryModule afm; +// private UserManagementModule umm; +// private AttachmentsModule am; + + [SetUp] + public void Init() + { +// IConfigSource config = new IniConfigSource(); +// config.AddConfig("NPC"); +// config.Configs["NPC"].Set("Enabled", "true"); +// config.AddConfig("Modules"); +// config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); +// +// afm = new AvatarFactoryModule(); +// umm = new UserManagementModule(); +// am = new AttachmentsModule(); + + m_scene = SceneHelpers.SetupScene(); +// SceneHelpers.SetupSceneModules(scene, config, afm, umm, am, new BasicInventoryAccessModule(), new NPCModule()); + } + + [Test] + public void TestSitAndStandWithNoSitTarget() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); + + // FIXME: To get this to work for now, we are going to place the npc right next to the target so that + // the autopilot doesn't trigger + Vector3 startPos = new Vector3(1, 1, 1); + sp.AbsolutePosition = startPos; + + SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene); + + sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero); + + Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); + Assert.That(sp.ParentID, Is.EqualTo(part.LocalId)); + + // FIXME: This is different for live avatars - z position is adjusted. This is half the height of the + // default avatar. + // Curiously, Vector3.ToString() will not display the last two places of the float. For example, + // printing out npc.AbsolutePosition will give <0, 0, 0.8454993> not <0, 0, 0.845499337> + Assert.That( + sp.AbsolutePosition, + Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, 0.845499337f))); + + sp.StandUp(); + + Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); + Assert.That(sp.ParentID, Is.EqualTo(0)); + } + } +} \ No newline at end of file From 01518de0bf7da141186225da2602138cfc0ea51f Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 19:43:42 +0000 Subject: [PATCH 02/13] update minimum mono version --- BUILDING.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/BUILDING.txt b/BUILDING.txt index e929cbf602..0fb68cb5ba 100644 --- a/BUILDING.txt +++ b/BUILDING.txt @@ -12,7 +12,7 @@ Steps: === Building on Linux === Prereqs: - * Mono >= 2.4.2 + * Mono >= 2.4.3 * Nant >= 0.85 * On some Linux distributions you may need to install additional packages. See http://opensimulator.org/wiki/Dependencies for more information. @@ -28,5 +28,3 @@ From the distribution type: Helpful resources: * http://opensimulator.org/wiki/Build_Instructions - - From a658bddbcd03a12d55f51368248ec86d0d9d61e1 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 19:59:12 +0000 Subject: [PATCH 03/13] Bump warp sit distance up to 10 meters, as discussed on opensim-dev mailing list last week. This means that if the avatar is within 10 meters of the selected target, it sits on it immediately without walking. Existing autopilot outside this range will be disabled in a later commit --- .../Region/Framework/Scenes/ScenePresence.cs | 2 +- .../Scenes/Tests/ScenePresenceSitTests.cs | 57 +++++++++++++------ 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index fdf944b5a0..e098c6279d 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -2034,7 +2034,7 @@ namespace OpenSim.Region.Framework.Scenes if (autopilot) { - if (Util.GetDistanceTo(AbsolutePosition, pos) < 4.5) + if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10) { autopilot = false; diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs index 627bce7f83..2636473af8 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs @@ -45,25 +45,51 @@ namespace OpenSim.Region.Framework.Scenes.Tests public class ScenePresenceSitTests { private TestScene m_scene; -// private AvatarFactoryModule afm; -// private UserManagementModule umm; -// private AttachmentsModule am; [SetUp] public void Init() { -// IConfigSource config = new IniConfigSource(); -// config.AddConfig("NPC"); -// config.Configs["NPC"].Set("Enabled", "true"); -// config.AddConfig("Modules"); -// config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); -// -// afm = new AvatarFactoryModule(); -// umm = new UserManagementModule(); -// am = new AttachmentsModule(); - m_scene = SceneHelpers.SetupScene(); -// SceneHelpers.SetupSceneModules(scene, config, afm, umm, am, new BasicInventoryAccessModule(), new NPCModule()); + } + + [Test] + public void TestSitOutsideRange() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); + + // More than 10 meters away from 0, 0, 0 (default part position) + Vector3 startPos = new Vector3(10.1f, 0, 0); + sp.AbsolutePosition = startPos; + + SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene); + + sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero); + + Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); + Assert.That(sp.ParentID, Is.EqualTo(0)); + } + + [Test] + public void TestSitWithinRange() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); + + // Less than 10 meters away from 0, 0, 0 (default part position) + Vector3 startPos = new Vector3(9.9f, 0, 0); + sp.AbsolutePosition = startPos; + + SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene); + + sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero); + + Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); + Assert.That(sp.ParentID, Is.EqualTo(part.LocalId)); } [Test] @@ -74,8 +100,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); - // FIXME: To get this to work for now, we are going to place the npc right next to the target so that - // the autopilot doesn't trigger + // Make sure we're within range to sit Vector3 startPos = new Vector3(1, 1, 1); sp.AbsolutePosition = startPos; From b1cb4f5b04f076c067842de6971ec1016b9a3912 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 21:42:58 +0000 Subject: [PATCH 04/13] As per mailing list last week, remove facility that would automatically move the avatar if prim with no sit target was out of sitting range. Now, no movement occurs. Note that you can still sit on a prim with an explicit sit target from any distance, as was the case before. --- .../Region/Framework/Scenes/ScenePresence.cs | 391 ++++++++---------- .../Scenes/Tests/ScenePresenceSitTests.cs | 33 +- 2 files changed, 197 insertions(+), 227 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index e098c6279d..6979d2ef2f 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -188,20 +188,12 @@ namespace OpenSim.Region.Framework.Scenes private readonly Vector3[] Dir_Vectors = new Vector3[11]; - protected Timer m_reprioritization_timer; protected bool m_reprioritizing; protected bool m_reprioritization_called; private Quaternion m_headrotation = Quaternion.Identity; - //Reuse the Vector3 instead of creating a new one on the UpdateMovement method -// private Vector3 movementvector; - - private bool m_autopilotMoving; - private Vector3 m_autoPilotTarget; - private bool m_sitAtAutoTarget; - private string m_nextSitAnimation = String.Empty; //PauPaw:Proper PID Controler for autopilot************ @@ -1417,9 +1409,6 @@ namespace OpenSim.Region.Framework.Scenes } } - if (m_autopilotMoving) - CheckAtSitTarget(); - if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) { m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick. @@ -1636,111 +1625,109 @@ namespace OpenSim.Region.Framework.Scenes // "[SCENE PRESENCE]: bAllowUpdateMoveToPosition {0}, m_moveToPositionInProgress {1}, m_autopilotMoving {2}", // allowUpdate, m_moveToPositionInProgress, m_autopilotMoving); - if (!m_autopilotMoving) - { - double distanceToTarget = Util.GetDistanceTo(AbsolutePosition, MoveToPositionTarget); + double distanceToTarget = Util.GetDistanceTo(AbsolutePosition, MoveToPositionTarget); + // m_log.DebugFormat( // "[SCENE PRESENCE]: Abs pos of {0} is {1}, target {2}, distance {3}", // Name, AbsolutePosition, MoveToPositionTarget, distanceToTarget); - // Check the error term of the current position in relation to the target position - if (distanceToTarget <= 1) + // Check the error term of the current position in relation to the target position + if (distanceToTarget <= 1) + { + // We are close enough to the target + AbsolutePosition = MoveToPositionTarget; + ResetMoveToTarget(); + updated = true; + } + else + { + try { - // We are close enough to the target - AbsolutePosition = MoveToPositionTarget; - ResetMoveToTarget(); - updated = true; - } - else - { - try - { - // move avatar in 3D at one meter/second towards target, in avatar coordinate frame. - // This movement vector gets added to the velocity through AddNewMovement(). - // Theoretically we might need a more complex PID approach here if other - // unknown forces are acting on the avatar and we need to adaptively respond - // to such forces, but the following simple approach seems to works fine. - Vector3 LocalVectorToTarget3D = - (MoveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords - * Matrix4.CreateFromQuaternion(Quaternion.Inverse(Rotation)); // change to avatar coords - // Ignore z component of vector + // move avatar in 3D at one meter/second towards target, in avatar coordinate frame. + // This movement vector gets added to the velocity through AddNewMovement(). + // Theoretically we might need a more complex PID approach here if other + // unknown forces are acting on the avatar and we need to adaptively respond + // to such forces, but the following simple approach seems to works fine. + Vector3 LocalVectorToTarget3D = + (MoveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords + * Matrix4.CreateFromQuaternion(Quaternion.Inverse(Rotation)); // change to avatar coords + // Ignore z component of vector // Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); - LocalVectorToTarget3D.Normalize(); + LocalVectorToTarget3D.Normalize(); - // update avatar movement flags. the avatar coordinate system is as follows: - // - // +X (forward) - // - // ^ - // | - // | - // | - // | - // (left) +Y <--------o--------> -Y - // avatar - // | - // | - // | - // | - // v - // -X - // + // update avatar movement flags. the avatar coordinate system is as follows: + // + // +X (forward) + // + // ^ + // | + // | + // | + // | + // (left) +Y <--------o--------> -Y + // avatar + // | + // | + // | + // | + // v + // -X + // - // based on the above avatar coordinate system, classify the movement into - // one of left/right/back/forward. - if (LocalVectorToTarget3D.X < 0) //MoveBack - { - MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; - AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; - updated = true; - } - else if (LocalVectorToTarget3D.X > 0) //Move Forward - { - MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; - AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; - updated = true; - } + // based on the above avatar coordinate system, classify the movement into + // one of left/right/back/forward. + if (LocalVectorToTarget3D.X < 0) //MoveBack + { + MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; + AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; + updated = true; + } + else if (LocalVectorToTarget3D.X > 0) //Move Forward + { + MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; + AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; + updated = true; + } - if (LocalVectorToTarget3D.Y > 0) //MoveLeft - { - MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; - AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; - updated = true; - } - else if (LocalVectorToTarget3D.Y < 0) //MoveRight - { - MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; - AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; - updated = true; - } + if (LocalVectorToTarget3D.Y > 0) //MoveLeft + { + MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; + AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; + updated = true; + } + else if (LocalVectorToTarget3D.Y < 0) //MoveRight + { + MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; + AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; + updated = true; + } - if (LocalVectorToTarget3D.Z > 0) //Up - { - // Don't set these flags for up or down - doing so will make the avatar crouch or - // keep trying to jump even if walking along level ground - //MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_UP; - //AgentControlFlags - //AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_UP; - updated = true; - } - else if (LocalVectorToTarget3D.Z < 0) //Down - { - //MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN; - //AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN; - updated = true; - } + if (LocalVectorToTarget3D.Z > 0) //Up + { + // Don't set these flags for up or down - doing so will make the avatar crouch or + // keep trying to jump even if walking along level ground + //MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_UP; + //AgentControlFlags + //AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_UP; + updated = true; + } + else if (LocalVectorToTarget3D.Z < 0) //Down + { + //MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN; + //AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN; + updated = true; + } // m_log.DebugFormat( // "[SCENE PRESENCE]: HandleMoveToTargetUpdate adding {0} to move vector {1} for {2}", // LocalVectorToTarget3D, agent_control_v3, Name); - agent_control_v3 += LocalVectorToTarget3D; - } - catch (Exception e) - { - //Avoid system crash, can be slower but... - m_log.DebugFormat("Crash! {0}", e.ToString()); - } + agent_control_v3 += LocalVectorToTarget3D; + } + catch (Exception e) + { + //Avoid system crash, can be slower but... + m_log.DebugFormat("Crash! {0}", e.ToString()); } } @@ -1842,47 +1829,6 @@ namespace OpenSim.Region.Framework.Scenes AgentControlFlags = (uint)AgentManager.ControlFlags.NONE; } - private void CheckAtSitTarget() - { - //m_log.Debug("[AUTOPILOT]: " + Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget).ToString()); - if (Util.GetDistanceTo(AbsolutePosition, m_autoPilotTarget) <= 1.5) - { - if (m_sitAtAutoTarget) - { - SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetUUID); - if (part != null) - { - AbsolutePosition = part.AbsolutePosition; - Velocity = Vector3.Zero; - SendAvatarDataToAllAgents(); - - //HandleAgentSit(ControllingClient, m_requestedSitTargetUUID); - } - //ControllingClient.SendSitResponse(m_requestedSitTargetID, m_requestedSitOffset, Quaternion.Identity, false, Vector3.Zero, Vector3.Zero, false); - m_requestedSitTargetUUID = UUID.Zero; - } - /* - else - { - //ControllingClient.SendAlertMessage("Autopilot cancelled"); - //SendTerseUpdateToAllClients(); - //PrimitiveBaseShape proxy = PrimitiveBaseShape.Default; - //proxy.PCode = (byte)PCode.ParticleSystem; - ////uint nextUUID = m_scene.NextLocalId; - - //proxyObjectGroup = new SceneObjectGroup(m_scene, m_scene.RegionInfo.RegionHandle, UUID, nextUUID, m_autoPilotTarget, Quaternion.Identity, proxy); - //if (proxyObjectGroup != null) - //{ - //proxyObjectGroup.SendGroupFullUpdate(); - //ControllingClient.SendSitResponse(UUID.Zero, m_autoPilotTarget, Quaternion.Identity, true, Vector3.Zero, Vector3.Zero, false); - //m_scene.DeleteSceneObject(proxyObjectGroup); - //} - } - */ - m_autoPilotTarget = Vector3.Zero; - m_autopilotMoving = false; - } - } /// /// Perform the logic necessary to stand the avatar up. This method also executes /// the stand animation. @@ -1893,7 +1839,7 @@ namespace OpenSim.Region.Framework.Scenes if (ParentID != 0) { - m_log.Debug("StandupCode Executed"); +// m_log.Debug("StandupCode Executed"); SceneObjectPart part = m_scene.GetSceneObjectPart(ParentID); if (part != null) { @@ -1983,7 +1929,6 @@ namespace OpenSim.Region.Framework.Scenes private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) { - bool autopilot = true; Vector3 pos = new Vector3(); Quaternion sitOrientation = pSitOrientation; Vector3 cameraEyeOffset = Vector3.Zero; @@ -1991,86 +1936,85 @@ namespace OpenSim.Region.Framework.Scenes bool forceMouselook = false; SceneObjectPart part = FindNextAvailableSitTarget(targetID); - if (part != null) - { - // TODO: determine position to sit at based on scene geometry; don't trust offset from client - // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it + if (part == null) + return; - // Is a sit target available? - Vector3 avSitOffSet = part.SitTargetPosition; - Quaternion avSitOrientation = part.SitTargetOrientation; - UUID avOnTargetAlready = part.SitTargetAvatar; + // TODO: determine position to sit at based on scene geometry; don't trust offset from client + // see http://wiki.secondlife.com/wiki/User:Andrew_Linden/Office_Hours/2007_11_06 for details on how LL does it - bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); - bool SitTargetisSet = - (!(avSitOffSet == Vector3.Zero && - ( - avSitOrientation == Quaternion.Identity // Valid Zero Rotation quaternion - || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point - || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion - ) - )); + // Is a sit target available? + Vector3 avSitOffSet = part.SitTargetPosition; + Quaternion avSitOrientation = part.SitTargetOrientation; + UUID avOnTargetAlready = part.SitTargetAvatar; + + bool SitTargetUnOccupied = (!(avOnTargetAlready != UUID.Zero)); + bool SitTargetisSet = + (!(avSitOffSet == Vector3.Zero && + ( + avSitOrientation == Quaternion.Identity // Valid Zero Rotation quaternion + || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 1f && avSitOrientation.W == 0f // W-Z Mapping was invalid at one point + || avSitOrientation.X == 0f && avSitOrientation.Y == 0f && avSitOrientation.Z == 0f && avSitOrientation.W == 0f // Invalid Quaternion + ) + )); // m_log.DebugFormat("[SCENE PRESENCE]: {0} {1}", SitTargetisSet, SitTargetUnOccupied); - if (SitTargetisSet && SitTargetUnOccupied) + if (PhysicsActor != null) + m_sitAvatarHeight = m_physicsActor.Size.Z; + + bool canSit = false; + pos = part.AbsolutePosition + offset; + + if (SitTargetisSet) + { + if (SitTargetUnOccupied) { + m_log.DebugFormat( + "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is set and unoccupied", + Name, part.Name, part.LocalId); + part.SitTargetAvatar = UUID; offset = new Vector3(avSitOffSet.X, avSitOffSet.Y, avSitOffSet.Z); sitOrientation = avSitOrientation; - autopilot = false; + canSit = true; } - pos = part.AbsolutePosition + offset; - //if (Math.Abs(part.AbsolutePosition.Z - AbsolutePosition.Z) > 1) - //{ - // offset = pos; - //autopilot = false; - //} + } + else + { + if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10) + { + m_log.DebugFormat( + "[SCENE PRESENCE]: Sitting {0} on {1} {2} because sit target is unset and within 10m", + Name, part.Name, part.LocalId); + + AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); + canSit = true; + } + } + + if (canSit) + { if (PhysicsActor != null) { - // If we're not using the client autopilot, we're immediately warping the avatar to the location // We can remove the physicsActor until they stand up. - m_sitAvatarHeight = PhysicsActor.Size.Z; - - if (autopilot) - { - if (Util.GetDistanceTo(AbsolutePosition, pos) <= 10) - { - autopilot = false; - - RemoveFromPhysicalScene(); - AbsolutePosition = pos + new Vector3(0.0f, 0.0f, m_sitAvatarHeight); - } - } - else - { - RemoveFromPhysicalScene(); - } + RemoveFromPhysicalScene(); } cameraAtOffset = part.GetCameraAtOffset(); cameraEyeOffset = part.GetCameraEyeOffset(); forceMouselook = part.GetForceMouselook(); - } - ControllingClient.SendSitResponse(targetID, offset, sitOrientation, autopilot, cameraAtOffset, cameraEyeOffset, forceMouselook); - m_requestedSitTargetUUID = targetID; + ControllingClient.SendSitResponse( + targetID, offset, sitOrientation, false, cameraAtOffset, cameraEyeOffset, forceMouselook); + + m_requestedSitTargetUUID = targetID; - // This calls HandleAgentSit twice, once from here, and the client calls - // HandleAgentSit itself after it gets to the location - // It doesn't get to the location until we've moved them there though - // which happens in HandleAgentSit :P - m_autopilotMoving = autopilot; - m_autoPilotTarget = pos; - m_sitAtAutoTarget = autopilot; - if (!autopilot) HandleAgentSit(remoteClient, UUID); - // Moved here to avoid a race with default sit anim - // The script event needs to be raised after the default sit anim is set. - if (part != null) + // Moved here to avoid a race with default sit anim + // The script event needs to be raised after the default sit anim is set. part.ParentGroup.TriggerScriptChangedEvent(Changed.LINK); - + } } // public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset, string sitAnimation) @@ -2099,11 +2043,11 @@ namespace OpenSim.Region.Framework.Scenes { m_nextSitAnimation = part.SitAnimation; } + m_requestedSitTargetID = part.LocalId; - //m_requestedSitOffset = offset; m_requestedSitTargetUUID = targetID; - m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); +// m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); if (m_scene.PhysicsScene.SupportsRayCast()) { @@ -2328,43 +2272,40 @@ namespace OpenSim.Region.Framework.Scenes { SceneObjectPart part = m_scene.GetSceneObjectPart(m_requestedSitTargetID); - if (m_sitAtAutoTarget || !m_autopilotMoving) + if (part != null) { - if (part != null) + if (part.SitTargetAvatar == UUID) { - if (part.SitTargetAvatar == UUID) - { - Vector3 sitTargetPos = part.SitTargetPosition; - Quaternion sitTargetOrient = part.SitTargetOrientation; + Vector3 sitTargetPos = part.SitTargetPosition; + Quaternion sitTargetOrient = part.SitTargetOrientation; // m_log.DebugFormat( // "[SCENE PRESENCE]: Sitting {0} at sit target {1}, {2} on {3} {4}", // Name, sitTargetPos, sitTargetOrient, part.Name, part.LocalId); - //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0); - //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w); + //Quaternion vq = new Quaternion(sitTargetPos.X, sitTargetPos.Y+0.2f, sitTargetPos.Z+0.2f, 0); + //Quaternion nq = new Quaternion(-sitTargetOrient.X, -sitTargetOrient.Y, -sitTargetOrient.Z, sitTargetOrient.w); - //Quaternion result = (sitTargetOrient * vq) * nq; + //Quaternion result = (sitTargetOrient * vq) * nq; - m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; - Rotation = sitTargetOrient; - ParentPosition = part.AbsolutePosition; - } - else - { - m_pos -= part.AbsolutePosition; - ParentPosition = part.AbsolutePosition; + m_pos = sitTargetPos + SIT_TARGET_ADJUSTMENT; + Rotation = sitTargetOrient; + ParentPosition = part.AbsolutePosition; + } + else + { + m_pos -= part.AbsolutePosition; + ParentPosition = part.AbsolutePosition; // m_log.DebugFormat( // "[SCENE PRESENCE]: Sitting {0} at position {1} ({2} + {3}) on part {4} {5} without sit target", // Name, part.AbsolutePosition, m_pos, ParentPosition, part.Name, part.LocalId); - } - } - else - { - return; } } + else + { + return; + } ParentID = m_requestedSitTargetID; diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs index 2636473af8..a1d30f3848 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs @@ -53,7 +53,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests } [Test] - public void TestSitOutsideRange() + public void TestSitOutsideRangeNoTarget() { TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); @@ -73,7 +73,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests } [Test] - public void TestSitWithinRange() + public void TestSitWithinRangeNoTarget() { TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); @@ -124,5 +124,34 @@ namespace OpenSim.Region.Framework.Scenes.Tests Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); Assert.That(sp.ParentID, Is.EqualTo(0)); } + + [Test] + public void TestSitAndStandWithSitTarget() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); + + // If a prim has a sit target then we can sit from any distance away + Vector3 startPos = new Vector3(128, 128, 30); + sp.AbsolutePosition = startPos; + + SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene); + part.SitTargetPosition = new Vector3(0, 0, 1); + + sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero); + + Assert.That(part.SitTargetAvatar, Is.EqualTo(sp.UUID)); + Assert.That(sp.ParentID, Is.EqualTo(part.LocalId)); + Assert.That( + sp.AbsolutePosition, + Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT)); + + sp.StandUp(); + + Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); + Assert.That(sp.ParentID, Is.EqualTo(0)); + } } } \ No newline at end of file From 2a7f4e0602c1b34a5a3439d767e5c7da388118fa Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 21:53:00 +0000 Subject: [PATCH 05/13] remove unncessary IClientAPI parameter from SP.SendSitResponse() --- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 6979d2ef2f..0c200452ed 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1927,7 +1927,7 @@ namespace OpenSim.Region.Framework.Scenes return targetPart; } - private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) + private void SendSitResponse(UUID targetID, Vector3 offset, Quaternion pSitOrientation) { Vector3 pos = new Vector3(); Quaternion sitOrientation = pSitOrientation; @@ -2009,7 +2009,7 @@ namespace OpenSim.Region.Framework.Scenes m_requestedSitTargetUUID = targetID; - HandleAgentSit(remoteClient, UUID); + HandleAgentSit(ControllingClient, UUID); // Moved here to avoid a race with default sit anim // The script event needs to be raised after the default sit anim is set. @@ -2017,7 +2017,6 @@ namespace OpenSim.Region.Framework.Scenes } } - // public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset, string sitAnimation) public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset) { if (ParentID != 0) @@ -2061,7 +2060,7 @@ namespace OpenSim.Region.Framework.Scenes m_log.Warn("Sit requested on unknown object: " + targetID.ToString()); } - SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); + SendSitResponse(targetID, offset, Quaternion.Identity); } /* From ce8441132e43dc8e3579f413daf914d48b8f115e Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 22:37:57 +0000 Subject: [PATCH 06/13] Restore sending of OutPacket() for object kills removed in commit c7dd7b1. OutPacket() must be called within the m_killRecord lock. Otherwise the following event sequence is possible 1) LLClientView.ProcessEntityUpdates() passes the kill record check for a particular part suspends before OutPacket() 2) Another thread calls LLClientView.SendKillObject() to delete the same part and modifies the kill record 3) The same thread places the kill packet on the Task queue. 4) The earlier thread resumes and places the update packet on the Task queue after the kill packet. This results in a ghost part in the sim that only goes away after client relog. This commit also removes the unnecessary m_entityUpdates.SyncRoot locking in SendKillObject. --- .../ClientStack/Linden/UDP/LLClientView.cs | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 4a0b0c6dd1..626ebb5939 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -1546,41 +1546,35 @@ namespace OpenSim.Region.ClientStack.LindenUDP kill.Header.Reliable = true; kill.Header.Zerocoded = true; - lock (m_killRecord) + if (localIDs.Count == 1 && m_scene.GetScenePresence(localIDs[0]) != null) { - if (localIDs.Count == 1) + OutPacket(kill, ThrottleOutPacketType.State); + } + else + { + // We MUST lock for both manipulating the kill record and sending the packet, in order to avoid a race + // condition where a kill can be processed before an out-of-date update for the same object. + // ProcessEntityUpdates() also takes the m_killRecord lock. + lock (m_killRecord) { - if (m_scene.GetScenePresence(localIDs[0]) != null) - { - OutPacket(kill, ThrottleOutPacketType.State); - return; - } - m_killRecord.Add(localIDs[0]); - } - else - { - lock (m_entityUpdates.SyncRoot) - { - foreach (uint localID in localIDs) - m_killRecord.Add(localID); - } + foreach (uint localID in localIDs) + m_killRecord.Add(localID); + + // The throttle queue used here must match that being used for updates. Otherwise, there is a + // chance that a kill packet put on a separate queue will be sent to the client before an existing + // update packet on another queue. Receiving updates after kills results in unowned and undeletable + // scene objects in a viewer until that viewer is relogged in. + OutPacket(kill, ThrottleOutPacketType.Task); } } - - // The throttle queue used here must match that being used for - // updates. Otherwise, there is a chance that a kill packet put - // on a separate queue will be sent to the client before an - // existing update packet on another queue. Receiving updates - // after kills results in unowned and undeletable - // scene objects in a viewer until that viewer is relogged in. - OutPacket(kill, ThrottleOutPacketType.Task); } /// /// Send information about the items contained in a folder to the client. - /// - /// XXX This method needs some refactoring loving /// + /// + /// XXX This method needs some refactoring loving + /// /// The owner of the folder /// The id of the folder /// The items contained in the folder identified by folderID From 2a2cdaa211086b48c1a19f371b544e1550500e33 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 23:10:43 +0000 Subject: [PATCH 07/13] As with prim sitting avatars, make an avatar phantom when it sits on the ground and solid again when it stands. This is to avoid http://opensimulator.org/mantis/view.php?id=5783 when a collision with a ground sitting avatar causes that avatar to automatically stand and sometimes not be able to move A better solution may be to keep gound sitting avatars solid but remove their collision status. However, this requires some physics code work. --- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 0c200452ed..f5a7f02ca2 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1419,6 +1419,7 @@ namespace OpenSim.Region.Framework.Scenes // to use. Or we could add a m_isSitting variable. //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); SitGround = true; + RemoveFromPhysicalScene(); } // In the future, these values might need to go global. @@ -1835,11 +1836,14 @@ namespace OpenSim.Region.Framework.Scenes /// public void StandUp() { +// m_log.DebugFormat("[SCENE PRESENCE]: StandUp() for {0}", Name); + SitGround = false; + if (PhysicsActor == null) + AddToPhysicalScene(false); if (ParentID != 0) { -// m_log.Debug("StandupCode Executed"); SceneObjectPart part = m_scene.GetSceneObjectPart(ParentID); if (part != null) { @@ -1866,11 +1870,6 @@ namespace OpenSim.Region.Framework.Scenes ControllingClient.SendClearFollowCamProperties(part.ParentUUID); } - if (PhysicsActor == null) - { - AddToPhysicalScene(false); - } - m_pos += ParentPosition + new Vector3(0.0f, 0.0f, 2.0f * m_sitAvatarHeight); ParentPosition = Vector3.Zero; From 6ce3daff94a2d5348d15c66be5091a608ed28217 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 23:15:53 +0000 Subject: [PATCH 08/13] Pick up the intended ConsolePrompt from [Startup] instead of console_prompt. Addresses http://opensimulator.org/mantis/view.php?id=5786 --- OpenSim/Region/Application/OpenSim.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index beb75a8904..0cad8a917c 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -121,7 +121,7 @@ namespace OpenSim Util.FireAndForgetMethod = asyncCallMethod; stpMaxThreads = startupConfig.GetInt("MaxPoolThreads", 15); - m_consolePrompt = startupConfig.GetString("console_prompt", @"Region (\R) "); + m_consolePrompt = startupConfig.GetString("ConsolePrompt", @"Region (\R) "); } if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool) From a3052e40ad9ae56d5e968af9792e0ff8b905e9b9 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 23:28:32 +0000 Subject: [PATCH 09/13] extract ground sit code into SP.HandleAgentSitOnGround() for consistency with other sitting code. --- .../Region/Framework/Scenes/ScenePresence.cs | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index f5a7f02ca2..3fee642afe 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -163,7 +163,11 @@ namespace OpenSim.Region.Framework.Scenes private uint m_requestedSitTargetID; private UUID m_requestedSitTargetUUID; - public bool SitGround = false; + + /// + /// Are we sitting on the ground? + /// + public bool SitGround { get; private set; } private SendCourseLocationsMethod m_sendCourseLocationsMethod; @@ -1410,17 +1414,7 @@ namespace OpenSim.Region.Framework.Scenes } if ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) - { - m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick. - Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); - - // TODO: This doesn't prevent the user from walking yet. - // Setting parent ID would fix this, if we knew what value - // to use. Or we could add a m_isSitting variable. - //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); - SitGround = true; - RemoveFromPhysicalScene(); - } + HandleAgentSitOnGround(); // In the future, these values might need to go global. // Here's where you get them. @@ -2314,6 +2308,19 @@ namespace OpenSim.Region.Framework.Scenes SendAvatarDataToAllAgents(); } + public void HandleAgentSitOnGround() + { + m_updateCount = 0; // Kill animation update burst so that the SIT_G.. will stick. + Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); + + // TODO: This doesn't prevent the user from walking yet. + // Setting parent ID would fix this, if we knew what value + // to use. Or we could add a m_isSitting variable. + //Animator.TrySetMovementAnimation("SIT_GROUND_CONSTRAINED"); + SitGround = true; + RemoveFromPhysicalScene(); + } + /// /// Event handler for the 'Always run' setting on the client /// Tells the physics plugin to increase speed of movement. From acaf6937c54071f93a09de7332b4a95bf2a2c88e Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 23:32:43 +0000 Subject: [PATCH 10/13] add sit and stand on ground test --- .../Scenes/Tests/ScenePresenceSitTests.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs index a1d30f3848..e3ffb53b9a 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs @@ -153,5 +153,28 @@ namespace OpenSim.Region.Framework.Scenes.Tests Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); Assert.That(sp.ParentID, Is.EqualTo(0)); } + + [Test] + public void TestSitAndStandOnGround() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); + + // If a prim has a sit target then we can sit from any distance away +// Vector3 startPos = new Vector3(128, 128, 30); +// sp.AbsolutePosition = startPos; + + sp.HandleAgentSitOnGround(); + + Assert.That(sp.SitGround, Is.True); + Assert.That(sp.PhysicsActor, Is.Null); + + sp.StandUp(); + + Assert.That(sp.SitGround, Is.False); + Assert.That(sp.PhysicsActor, Is.Not.Null); + } } } \ No newline at end of file From 84ad23234b369cc56db3004a1b6a0346c574724f Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 23:33:55 +0000 Subject: [PATCH 11/13] add SP.PhysicsActor checks to other sit/stand tests --- .../Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs index e3ffb53b9a..fa308b4d11 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs @@ -110,6 +110,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); Assert.That(sp.ParentID, Is.EqualTo(part.LocalId)); + Assert.That(sp.PhysicsActor, Is.Null); // FIXME: This is different for live avatars - z position is adjusted. This is half the height of the // default avatar. @@ -123,6 +124,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); Assert.That(sp.ParentID, Is.EqualTo(0)); + Assert.That(sp.PhysicsActor, Is.Not.Null); } [Test] @@ -147,11 +149,13 @@ namespace OpenSim.Region.Framework.Scenes.Tests Assert.That( sp.AbsolutePosition, Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT)); + Assert.That(sp.PhysicsActor, Is.Null); sp.StandUp(); Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); Assert.That(sp.ParentID, Is.EqualTo(0)); + Assert.That(sp.PhysicsActor, Is.Not.Null); } [Test] From 6adaf1be74436395b03519f6105454a5afcd8004 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 23:36:35 +0000 Subject: [PATCH 12/13] extract common ScenePresence setup code into Init() method for ScenePresenceSitTests --- .../Scenes/Tests/ScenePresenceSitTests.cs | 70 ++++++++----------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs index fa308b4d11..b7b8db445e 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs @@ -45,11 +45,13 @@ namespace OpenSim.Region.Framework.Scenes.Tests public class ScenePresenceSitTests { private TestScene m_scene; + private ScenePresence m_sp; [SetUp] public void Init() { m_scene = SceneHelpers.SetupScene(); + m_sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); } [Test] @@ -58,18 +60,16 @@ namespace OpenSim.Region.Framework.Scenes.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); - // More than 10 meters away from 0, 0, 0 (default part position) Vector3 startPos = new Vector3(10.1f, 0, 0); - sp.AbsolutePosition = startPos; + m_sp.AbsolutePosition = startPos; SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene); - sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero); + m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); - Assert.That(sp.ParentID, Is.EqualTo(0)); + Assert.That(m_sp.ParentID, Is.EqualTo(0)); } [Test] @@ -78,18 +78,16 @@ namespace OpenSim.Region.Framework.Scenes.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); - // Less than 10 meters away from 0, 0, 0 (default part position) Vector3 startPos = new Vector3(9.9f, 0, 0); - sp.AbsolutePosition = startPos; + m_sp.AbsolutePosition = startPos; SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene); - sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero); + m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); - Assert.That(sp.ParentID, Is.EqualTo(part.LocalId)); + Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId)); } [Test] @@ -98,33 +96,31 @@ namespace OpenSim.Region.Framework.Scenes.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); - // Make sure we're within range to sit Vector3 startPos = new Vector3(1, 1, 1); - sp.AbsolutePosition = startPos; + m_sp.AbsolutePosition = startPos; SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene); - sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero); + m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); - Assert.That(sp.ParentID, Is.EqualTo(part.LocalId)); - Assert.That(sp.PhysicsActor, Is.Null); + Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId)); + Assert.That(m_sp.PhysicsActor, Is.Null); // FIXME: This is different for live avatars - z position is adjusted. This is half the height of the // default avatar. // Curiously, Vector3.ToString() will not display the last two places of the float. For example, // printing out npc.AbsolutePosition will give <0, 0, 0.8454993> not <0, 0, 0.845499337> Assert.That( - sp.AbsolutePosition, + m_sp.AbsolutePosition, Is.EqualTo(part.AbsolutePosition + new Vector3(0, 0, 0.845499337f))); - sp.StandUp(); + m_sp.StandUp(); Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); - Assert.That(sp.ParentID, Is.EqualTo(0)); - Assert.That(sp.PhysicsActor, Is.Not.Null); + Assert.That(m_sp.ParentID, Is.EqualTo(0)); + Assert.That(m_sp.PhysicsActor, Is.Not.Null); } [Test] @@ -133,29 +129,27 @@ namespace OpenSim.Region.Framework.Scenes.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); - // If a prim has a sit target then we can sit from any distance away Vector3 startPos = new Vector3(128, 128, 30); - sp.AbsolutePosition = startPos; + m_sp.AbsolutePosition = startPos; SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene); part.SitTargetPosition = new Vector3(0, 0, 1); - sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero); + m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero); - Assert.That(part.SitTargetAvatar, Is.EqualTo(sp.UUID)); - Assert.That(sp.ParentID, Is.EqualTo(part.LocalId)); + Assert.That(part.SitTargetAvatar, Is.EqualTo(m_sp.UUID)); + Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId)); Assert.That( - sp.AbsolutePosition, + m_sp.AbsolutePosition, Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT)); - Assert.That(sp.PhysicsActor, Is.Null); + Assert.That(m_sp.PhysicsActor, Is.Null); - sp.StandUp(); + m_sp.StandUp(); Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero)); - Assert.That(sp.ParentID, Is.EqualTo(0)); - Assert.That(sp.PhysicsActor, Is.Not.Null); + Assert.That(m_sp.ParentID, Is.EqualTo(0)); + Assert.That(m_sp.PhysicsActor, Is.Not.Null); } [Test] @@ -164,21 +158,19 @@ namespace OpenSim.Region.Framework.Scenes.Tests TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1)); - // If a prim has a sit target then we can sit from any distance away // Vector3 startPos = new Vector3(128, 128, 30); // sp.AbsolutePosition = startPos; - sp.HandleAgentSitOnGround(); + m_sp.HandleAgentSitOnGround(); - Assert.That(sp.SitGround, Is.True); - Assert.That(sp.PhysicsActor, Is.Null); + Assert.That(m_sp.SitGround, Is.True); + Assert.That(m_sp.PhysicsActor, Is.Null); - sp.StandUp(); + m_sp.StandUp(); - Assert.That(sp.SitGround, Is.False); - Assert.That(sp.PhysicsActor, Is.Not.Null); + Assert.That(m_sp.SitGround, Is.False); + Assert.That(m_sp.PhysicsActor, Is.Not.Null); } } } \ No newline at end of file From 25c32061e4407e9aa2f5f719ed7961d30545208e Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 11 Nov 2011 23:45:08 +0000 Subject: [PATCH 13/13] Make log messages on authentication failure more explicit --- .../PasswordAuthenticationService.cs | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs index 2fc92487d6..14d96cb3f4 100644 --- a/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs +++ b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs @@ -60,16 +60,25 @@ namespace OpenSim.Services.AuthenticationService { AuthenticationData data = m_Database.Get(principalID); - if (data != null && data.Data != null) + if (data == null) { - if (!data.Data.ContainsKey("passwordHash") || - !data.Data.ContainsKey("passwordSalt")) - { - return String.Empty; - } - - string hashed = Util.Md5Hash(password + ":" + - data.Data["passwordSalt"].ToString()); + m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} not found", principalID); + return String.Empty; + } + else if (data.Data == null) + { + m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} data not found", principalID); + return String.Empty; + } + else if (!data.Data.ContainsKey("passwordHash") || !data.Data.ContainsKey("passwordSalt")) + { + m_log.DebugFormat( + "[AUTH SERVICE]: PrincipalID {0} data didn't contain either passwordHash or passwordSalt", principalID); + return String.Empty; + } + else + { + string hashed = Util.Md5Hash(password + ":" + data.Data["passwordSalt"].ToString()); //m_log.DebugFormat("[PASS AUTH]: got {0}; hashed = {1}; stored = {2}", password, hashed, data.Data["passwordHash"].ToString()); @@ -77,10 +86,14 @@ namespace OpenSim.Services.AuthenticationService { return GetToken(principalID, lifetime); } + else + { + m_log.DebugFormat( + "[AUTH SERVICE]: Salted hash {0} of given password did not match salted hash of {1} for PrincipalID {2}. Authentication failure.", + principalID); + return String.Empty; + } } - - m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} or its data not found", principalID); - return String.Empty; } } -} +} \ No newline at end of file