diff options
author | Justin Clark-Casey (justincc) | 2011-08-24 21:35:44 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-08-24 21:35:44 +0100 |
commit | 5eeee480d47b855774829c94aadcb69af8c0e8da (patch) | |
tree | 56af07c0b2f891265c641226be05109fabbc397a /OpenSim/Region/CoreModules/Avatar/Attachments | |
parent | get rid of pointless grp null check in attachObjectAssetStore() (diff) | |
download | opensim-SC-5eeee480d47b855774829c94aadcb69af8c0e8da.zip opensim-SC-5eeee480d47b855774829c94aadcb69af8c0e8da.tar.gz opensim-SC-5eeee480d47b855774829c94aadcb69af8c0e8da.tar.bz2 opensim-SC-5eeee480d47b855774829c94aadcb69af8c0e8da.tar.xz |
refactor: move Scene.Inventory.attachObjectAssetStore() into AttachmentsModule.AddSceneObjectAsAttachment()
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Attachments')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | 102 |
1 files changed, 100 insertions, 2 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index 88fc9e4..5661254 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | |||
@@ -46,7 +46,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
46 | { | 46 | { |
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 48 | ||
49 | protected Scene m_scene = null; | 49 | private Scene m_scene = null; |
50 | private IDialogModule m_dialogModule; | ||
50 | 51 | ||
51 | public string Name { get { return "Attachments Module"; } } | 52 | public string Name { get { return "Attachments Module"; } } |
52 | public Type ReplaceableInterface { get { return null; } } | 53 | public Type ReplaceableInterface { get { return null; } } |
@@ -56,6 +57,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
56 | public void AddRegion(Scene scene) | 57 | public void AddRegion(Scene scene) |
57 | { | 58 | { |
58 | m_scene = scene; | 59 | m_scene = scene; |
60 | m_dialogModule = m_scene.RequestModuleInterface<IDialogModule>(); | ||
59 | m_scene.RegisterModuleInterface<IAttachmentsModule>(this); | 61 | m_scene.RegisterModuleInterface<IAttachmentsModule>(this); |
60 | m_scene.EventManager.OnNewClient += SubscribeToClientEvents; | 62 | m_scene.EventManager.OnNewClient += SubscribeToClientEvents; |
61 | // TODO: Should probably be subscribing to CloseClient too, but this doesn't yet give us IClientAPI | 63 | // TODO: Should probably be subscribing to CloseClient too, but this doesn't yet give us IClientAPI |
@@ -228,7 +230,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
228 | 230 | ||
229 | itemID = group.GetFromItemID(); | 231 | itemID = group.GetFromItemID(); |
230 | if (itemID == UUID.Zero) | 232 | if (itemID == UUID.Zero) |
231 | m_scene.attachObjectAssetStore(sp.ControllingClient, group, out itemID); | 233 | AddSceneObjectAsAttachment(sp.ControllingClient, group, out itemID); |
232 | 234 | ||
233 | ShowAttachInUserInventory(sp, AttachmentPt, itemID, group); | 235 | ShowAttachInUserInventory(sp, AttachmentPt, itemID, group); |
234 | 236 | ||
@@ -656,5 +658,101 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
656 | // it get cleaned up | 658 | // it get cleaned up |
657 | so.RootPart.RemFlag(PrimFlags.TemporaryOnRez); | 659 | so.RootPart.RemFlag(PrimFlags.TemporaryOnRez); |
658 | } | 660 | } |
661 | |||
662 | /// <summary> | ||
663 | /// Add a scene object that was previously free in the scene as an attachment to an avatar. | ||
664 | /// </summary> | ||
665 | /// <param name="remoteClient"></param> | ||
666 | /// <param name="grp"></param> | ||
667 | /// <param name="itemID"></param> | ||
668 | /// <returns></returns> | ||
669 | private UUID AddSceneObjectAsAttachment(IClientAPI remoteClient, SceneObjectGroup grp, out UUID itemID) | ||
670 | { | ||
671 | // m_log.DebugFormat("[SCENE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2} {3} {4}", grp.Name, grp.LocalId, remoteClient.Name, remoteClient.AgentId, AgentId); | ||
672 | |||
673 | itemID = UUID.Zero; | ||
674 | |||
675 | Vector3 inventoryStoredPosition = new Vector3 | ||
676 | (((grp.AbsolutePosition.X > (int)Constants.RegionSize) | ||
677 | ? Constants.RegionSize - 6 | ||
678 | : grp.AbsolutePosition.X) | ||
679 | , | ||
680 | (grp.AbsolutePosition.Y > (int)Constants.RegionSize) | ||
681 | ? Constants.RegionSize - 6 | ||
682 | : grp.AbsolutePosition.Y, | ||
683 | grp.AbsolutePosition.Z); | ||
684 | |||
685 | Vector3 originalPosition = grp.AbsolutePosition; | ||
686 | |||
687 | grp.AbsolutePosition = inventoryStoredPosition; | ||
688 | |||
689 | // If we're being called from a script, then trying to serialize that same script's state will not complete | ||
690 | // in any reasonable time period. Therefore, we'll avoid it. The worst that can happen is that if | ||
691 | // the client/server crashes rather than logging out normally, the attachment's scripts will resume | ||
692 | // without state on relog. Arguably, this is what we want anyway. | ||
693 | string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp, false); | ||
694 | |||
695 | grp.AbsolutePosition = originalPosition; | ||
696 | |||
697 | AssetBase asset = m_scene.CreateAsset( | ||
698 | grp.GetPartName(grp.LocalId), | ||
699 | grp.GetPartDescription(grp.LocalId), | ||
700 | (sbyte)AssetType.Object, | ||
701 | Utils.StringToBytes(sceneObjectXml), | ||
702 | remoteClient.AgentId); | ||
703 | |||
704 | m_scene.AssetService.Store(asset); | ||
705 | |||
706 | InventoryItemBase item = new InventoryItemBase(); | ||
707 | item.CreatorId = grp.RootPart.CreatorID.ToString(); | ||
708 | item.CreatorData = grp.RootPart.CreatorData; | ||
709 | item.Owner = remoteClient.AgentId; | ||
710 | item.ID = UUID.Random(); | ||
711 | item.AssetID = asset.FullID; | ||
712 | item.Description = asset.Description; | ||
713 | item.Name = asset.Name; | ||
714 | item.AssetType = asset.Type; | ||
715 | item.InvType = (int)InventoryType.Object; | ||
716 | |||
717 | InventoryFolderBase folder = m_scene.InventoryService.GetFolderForType(remoteClient.AgentId, AssetType.Object); | ||
718 | if (folder != null) | ||
719 | item.Folder = folder.ID; | ||
720 | else // oopsies | ||
721 | item.Folder = UUID.Zero; | ||
722 | |||
723 | if ((remoteClient.AgentId != grp.RootPart.OwnerID) && m_scene.Permissions.PropagatePermissions()) | ||
724 | { | ||
725 | item.BasePermissions = grp.RootPart.NextOwnerMask; | ||
726 | item.CurrentPermissions = grp.RootPart.NextOwnerMask; | ||
727 | item.NextPermissions = grp.RootPart.NextOwnerMask; | ||
728 | item.EveryOnePermissions = grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask; | ||
729 | item.GroupPermissions = grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask; | ||
730 | } | ||
731 | else | ||
732 | { | ||
733 | item.BasePermissions = grp.RootPart.BaseMask; | ||
734 | item.CurrentPermissions = grp.RootPart.OwnerMask; | ||
735 | item.NextPermissions = grp.RootPart.NextOwnerMask; | ||
736 | item.EveryOnePermissions = grp.RootPart.EveryoneMask; | ||
737 | item.GroupPermissions = grp.RootPart.GroupMask; | ||
738 | } | ||
739 | item.CreationDate = Util.UnixTimeSinceEpoch(); | ||
740 | |||
741 | // sets itemID so client can show item as 'attached' in inventory | ||
742 | grp.SetFromItemID(item.ID); | ||
743 | |||
744 | if (m_scene.AddInventoryItem(item)) | ||
745 | { | ||
746 | remoteClient.SendInventoryItemCreateUpdate(item, 0); | ||
747 | } | ||
748 | else | ||
749 | { | ||
750 | if (m_dialogModule != null) | ||
751 | m_dialogModule.SendAlertToUser(remoteClient, "Operation failed"); | ||
752 | } | ||
753 | |||
754 | itemID = item.ID; | ||
755 | return item.AssetID; | ||
756 | } | ||
659 | } | 757 | } |
660 | } | 758 | } |