From 2b0f924557575777511432e5d72d21297a8002fd Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 26 Aug 2010 22:09:52 +0100 Subject: refactor: Move Scene.Inventory.UpdateKnownItem() into Attachments module since this appears to relate solely to attachments --- .../Avatar/Attachments/AttachmentsModule.cs | 60 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs') diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index b3811bf..d56145a 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -37,6 +37,7 @@ using OpenSim.Framework; using OpenSim.Region.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.Framework.Scenes.Serialization; namespace OpenSim.Region.CoreModules.Avatar.Attachments { @@ -448,7 +449,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments m_scene.EventManager.TriggerOnAttach(group.LocalId, itemID, UUID.Zero); group.DetachToInventoryPrep(); m_log.Debug("[ATTACHMENTS MODULE]: Saving attachpoint: " + ((uint)group.GetAttachmentPoint()).ToString()); - m_scene.UpdateKnownItem(remoteClient, group,group.GetFromItemID(), group.OwnerID); + UpdateKnownItem(remoteClient, group, group.GetFromItemID(), group.OwnerID); m_scene.DeleteSceneObject(group, false); return; } @@ -471,8 +472,63 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments sog.UpdateGroupPosition(pos); sog.RootPart.IsAttachment = false; sog.AbsolutePosition = sog.RootPart.AttachedPos; - m_scene.UpdateKnownItem(client, sog, sog.GetFromItemID(), sog.OwnerID); + UpdateKnownItem(client, sog, sog.GetFromItemID(), sog.OwnerID); sog.SetAttachmentPoint(attachmentPoint); } + + /// + /// 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. + /// + /// + /// + /// + /// + protected void UpdateKnownItem(IClientAPI remoteClient, SceneObjectGroup grp, UUID itemID, UUID agentID) + { + if (grp != null) + { + if (!grp.HasGroupChanged) + { + m_log.WarnFormat("[ATTACHMENTS MODULE]: Save request for {0} which is unchanged", grp.UUID); + return; + } + + m_log.DebugFormat( + "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}", + grp.UUID, grp.GetAttachmentPoint()); + + string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp); + + InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId); + item = m_scene.InventoryService.GetItem(item); + + if (item != null) + { + AssetBase asset = m_scene.CreateAsset( + grp.GetPartName(grp.LocalId), + grp.GetPartDescription(grp.LocalId), + (sbyte)AssetType.Object, + Utils.StringToBytes(sceneObjectXml), + remoteClient.AgentId); + m_scene.AssetService.Store(asset); + + item.AssetID = asset.FullID; + item.Description = asset.Description; + item.Name = asset.Name; + item.AssetType = asset.Type; + item.InvType = (int)InventoryType.Object; + + m_scene.InventoryService.UpdateItem(item); + + // this gets called when the agent logs off! + if (remoteClient != null) + remoteClient.SendInventoryItemCreateUpdate(item, 0); + } + } + } } } \ No newline at end of file -- cgit v1.1