From e02062051d38e56ec22952e25a558039b5e54ab3 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 16 Aug 2009 16:17:19 -0700 Subject: Making attachments work again. Tons of debug more. This needs more testing and a lot of cleaning. --- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 4 +- OpenSim/Region/Framework/Scenes/Scene.cs | 15 +- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 13 +- .../Region/Framework/Scenes/SceneObjectGroup.cs | 1 + OpenSim/Region/Framework/Scenes/ScenePresence.cs | 151 +++++++++++++-------- 5 files changed, 119 insertions(+), 65 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index cea9044..f5e9be1 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -2357,7 +2357,9 @@ namespace OpenSim.Region.Framework.Scenes ScenePresence presence; if (TryGetAvatar(remoteClient.AgentId, out presence)) { - presence.Appearance.SetAttachment((int)AttachmentPt, itemID, att.UUID); + // XXYY!! + InventoryItemBase item = InventoryService.GetItem(new InventoryItemBase(itemID)); + presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/); IAvatarFactory ava = RequestModuleInterface(); if (ava != null) { diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 33166df..f475c64 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2042,13 +2042,22 @@ namespace OpenSim.Region.Framework.Scenes } else { + AgentCircuitData aCircuit = m_authenticateHandler.GetAgentCircuitData(client.CircuitCode); + m_log.DebugFormat( - "[SCENE]: Adding new child agent for {0} in {1}", - client.Name, RegionInfo.RegionName); + "[SCENE]: Adding new {0} agent for {1} in {2}", + ((aCircuit.child == true) ? "child" : "root"), client.Name, RegionInfo.RegionName); CommsManager.UserProfileCacheService.AddNewUser(client.AgentId); - CreateAndAddScenePresence(client); + ScenePresence sp = CreateAndAddScenePresence(client); + + // HERE!!! Do the initial attachments here + if (aCircuit.child == false) // first agent upon login is root agent + { + sp.IsChildAgent = false; + sp.RezAttachments(); + } } m_LastLogin = Environment.TickCount; diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index 3bd079a..fd13633 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -557,6 +557,7 @@ namespace OpenSim.Region.Framework.Scenes SceneObjectGroup group = GetGroupByPrim(objectLocalID); if (group != null) { + m_log.DebugFormat("[SCENE GRAPH]: AttachObject got {0}", group.UUID); if (m_parentScene.Permissions.CanTakeObject(group.UUID, remoteClient.AgentId)) { // If the attachment point isn't the same as the one previously used @@ -564,6 +565,7 @@ namespace OpenSim.Region.Framework.Scenes // and not in a weird location somewhere unknown. if (AttachmentPt != 0 && AttachmentPt != (uint)group.GetAttachmentPoint()) { + m_log.DebugFormat("[SCENE GRAPH]: AttachObject 1 got {0}", group.UUID); attachPos = Vector3.Zero; } @@ -572,7 +574,8 @@ namespace OpenSim.Region.Framework.Scenes { // Check object for stored attachment point AttachmentPt = (uint)group.GetAttachmentPoint(); - } + m_log.DebugFormat("[SCENE GRAPH]: AttachObject 2 got {0}", group.UUID); + } // if we still didn't find a suitable attachment point....... if (AttachmentPt == 0) @@ -580,8 +583,12 @@ namespace OpenSim.Region.Framework.Scenes // Stick it on left hand with Zero Offset from the attachment point. AttachmentPt = (uint)AttachmentPoint.LeftHand; attachPos = Vector3.Zero; + m_log.DebugFormat("[SCENE GRAPH]: AttachObject 3 got {0}", group.UUID); + } + m_log.DebugFormat("[SCENE GRAPH]: AttachObject 4 got {0}", group.UUID); + group.SetAttachmentPoint(Convert.ToByte(AttachmentPt)); group.AbsolutePosition = attachPos; @@ -590,10 +597,12 @@ namespace OpenSim.Region.Framework.Scenes if (group.GetFromItemID() == UUID.Zero) { + m_log.DebugFormat("[SCENE GRAPH]: AttachObject 5 got {0}", group.UUID); m_parentScene.attachObjectAssetStore(remoteClient, group, remoteClient.AgentId, out itemId); } else { + m_log.DebugFormat("[SCENE GRAPH]: AttachObject 6 got {0}", group.GetFromItemID()); itemId = group.GetFromItemID(); } @@ -611,6 +620,8 @@ namespace OpenSim.Region.Framework.Scenes remoteClient.SendAgentAlertMessage("You don't have sufficient permissions to attach this object", false); } } + else + m_log.DebugFormat("[SCENE GRAPH]: AttachObject found no such scene object {0}", objectLocalID); } protected internal ScenePresence CreateAndAddChildScenePresence(IClientAPI client, AvatarAppearance appearance) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 708c455..1b541c4 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -935,6 +935,7 @@ namespace OpenSim.Region.Framework.Scenes SetAttachmentPoint(Convert.ToByte(attachmentpoint)); avatar.AddAttachment(this); + m_log.DebugFormat("[SOG]: Added att {0} to avie {1}", UUID, avatar.UUID); if (!silent) { diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index fc8b62e..b0bb005 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -652,9 +652,6 @@ namespace OpenSim.Region.Framework.Scenes RegisterToEvents(); SetDirectionVectors(); - CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(m_uuid); - if (userInfo != null) - userInfo.OnItemReceived += ItemReceived; } public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, byte[] visualParams, @@ -1021,7 +1018,9 @@ namespace OpenSim.Region.Framework.Scenes } /// - /// Complete Avatar's movement into the region + /// Complete Avatar's movement into the region. + /// This is called upon a very important packet sent from the client, + /// so it's client-controlled. Never call this method directly. /// public void CompleteMovement() { @@ -1042,22 +1041,19 @@ namespace OpenSim.Region.Framework.Scenes AbsolutePosition = pos; } - if (m_isChildAgent) - { - m_isChildAgent = false; - bool m_flying = ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); - MakeRootAgent(AbsolutePosition, m_flying); - - if ((m_callbackURI != null) && !m_callbackURI.Equals("")) - { - m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI); - Scene.SendReleaseAgent(m_rootRegionHandle, UUID, m_callbackURI); - m_callbackURI = null; - } + m_isChildAgent = false; + bool m_flying = ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); + MakeRootAgent(AbsolutePosition, m_flying); - //m_log.DebugFormat("Completed movement"); + if ((m_callbackURI != null) && !m_callbackURI.Equals("")) + { + m_log.DebugFormat("[SCENE PRESENCE]: Releasing agent in URI {0}", m_callbackURI); + Scene.SendReleaseAgent(m_rootRegionHandle, UUID, m_callbackURI); + m_callbackURI = null; } + //m_log.DebugFormat("Completed movement"); + m_controllingClient.MoveAgentIntoRegion(m_regionInfo, AbsolutePosition, look); SendInitialData(); @@ -3154,6 +3150,20 @@ namespace OpenSim.Region.Framework.Scenes m_log.Warn("[SCENE PRESENCE]: exception in CopyTo " + e.Message); } + //Attachments + List attPoints = m_appearance.GetAttachedPoints(); + if (attPoints != null) + { + m_log.DebugFormat("[SCENE PRESENCE]: attachments {0}", attPoints.Count); + int i = 0; + AttachmentData[] attachs = new AttachmentData[attPoints.Count]; + foreach (int point in attPoints) + { + attachs[i++] = new AttachmentData(point, m_appearance.GetAttachedItem(point), m_appearance.GetAttachedAsset(point)); + } + cAgent.Attachments = attachs; + } + // Animations try { @@ -3219,6 +3229,19 @@ namespace OpenSim.Region.Framework.Scenes m_log.Warn("[SCENE PRESENCE]: exception in CopyFrom " + e.Message); } + // Attachments + try + { + if (cAgent.Attachments != null) + { + foreach (AttachmentData att in cAgent.Attachments) + { + m_appearance.SetAttachment(att.AttachPoint, att.ItemID, att.AssetID); + } + } + } + catch { } + // Animations try { @@ -3729,37 +3752,46 @@ namespace OpenSim.Region.Framework.Scenes return flags; } - private void ItemReceived(UUID itemID) + /// + /// RezAttachments. This should only be called upon login on the first region + /// + public void RezAttachments() { - if (IsChildAgent) - return; - if (null == m_appearance) { - m_log.Warn("[ATTACHMENT] Appearance has not been initialized"); + m_log.WarnFormat("[ATTACHMENT] Appearance has not been initialized for agent {0}", UUID); return; } - int attachpoint = m_appearance.GetAttachpoint(itemID); - if (attachpoint == 0) - return; - - UUID asset = m_appearance.GetAttachedAsset(attachpoint); - if (UUID.Zero == asset) // We have just logged in + List attPoints = m_appearance.GetAttachedPoints(); + foreach (int p in attPoints) { + UUID itemID = m_appearance.GetAttachedItem(p); + UUID assetID = m_appearance.GetAttachedAsset(p); + + if (UUID.Zero == assetID) + { + m_log.DebugFormat("[ATTACHMENT]: Cannot rez attachment in point {0} with itemID {1}", p, itemID); + continue; + } + try { // Rez from inventory - asset = m_scene.RezSingleAttachment(ControllingClient, - itemID, (uint)attachpoint); - // Corner case: We are not yet a Scene Entity - // Setting attachment info in RezSingleAttachment will fail - // Set it here - // - m_appearance.SetAttachment((int)attachpoint, itemID, - asset); - m_log.InfoFormat("[ATTACHMENT] Rezzed attachment {0}, inworld asset {1}", - itemID.ToString(), asset); + UUID asset = m_scene.RezSingleAttachment(ControllingClient, + itemID, (uint)p); + + m_log.InfoFormat("[ATTACHMENT]: Rezzed attachment in point {0} from item {1} and asset {2} ({3})", + p, itemID, assetID, asset); + + //SceneObjectPart att = m_scene.GetSceneObjectPart(asset); + //m_log.DebugFormat("[ATTCHMENT]: Got scene object parent {0} IsAtt {1}", + // ((att.ParentGroup != null) ? "not null" : "null"), att.IsAttachment); + //if (att.ParentGroup != null && !att.IsAttachment) + //{ + // att.FromItemID = itemID; + // m_scene.AttachObject(ControllingClient, att.ParentGroup.LocalId, 0, Quaternion.Identity, att.ParentGroup.AbsolutePosition, false); + //} } catch (Exception e) @@ -3767,31 +3799,30 @@ namespace OpenSim.Region.Framework.Scenes m_log.ErrorFormat("[ATTACHMENT] Unable to rez attachment: {0}", e.ToString()); } - return; } - SceneObjectPart att = m_scene.GetSceneObjectPart(asset); + //SceneObjectPart att = m_scene.GetSceneObjectPart(asset); - // If this is null, then the asset has not yet appeared in world - // so we revisit this when it does - // - if (att != null && att.UUID != asset) // Yes. It's really needed - { - m_log.DebugFormat("[ATTACHMENT]: Attach from in world: ItemID {0}, Asset ID {1}, Attachment inworld: {2}", itemID.ToString(), asset.ToString(), att.UUID.ToString()); - - // This will throw if crossing katty-korner - // So catch it here to avoid the noid - // - try - { - // Attach from world, if not already attached - if (att.ParentGroup != null && !att.IsAttachment) - m_scene.AttachObject(ControllingClient, att.ParentGroup.LocalId, 0, Quaternion.Identity, att.ParentGroup.AbsolutePosition, false); - } - catch (NullReferenceException) - { - } - } + //// If this is null, then the asset has not yet appeared in world + //// so we revisit this when it does + //// + //if (att != null && att.UUID != asset) // Yes. It's really needed + //{ + // m_log.DebugFormat("[ATTACHMENT]: Attach from in world: ItemID {0}, Asset ID {1}, Attachment inworld: {2}", itemID.ToString(), asset.ToString(), att.UUID.ToString()); + + // // This will throw if crossing katty-korner + // // So catch it here to avoid the noid + // // + // try + // { + // // Attach from world, if not already attached + // if (att.ParentGroup != null && !att.IsAttachment) + // m_scene.AttachObject(ControllingClient, att.ParentGroup.LocalId, 0, Quaternion.Identity, att.ParentGroup.AbsolutePosition, false); + // } + // catch (NullReferenceException) + // { + // } + //} } } } -- cgit v1.1