aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Scene.Inventory.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs740
1 files changed, 55 insertions, 685 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index b04871e..1875c48 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -35,7 +35,7 @@ using OpenMetaverse;
35using OpenMetaverse.Packets; 35using OpenMetaverse.Packets;
36using log4net; 36using log4net;
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Framework.Communications.Cache; 38
39using OpenSim.Region.Framework; 39using OpenSim.Region.Framework;
40using OpenSim.Region.Framework.Interfaces; 40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes.Serialization; 41using OpenSim.Region.Framework.Scenes.Serialization;
@@ -101,12 +101,6 @@ namespace OpenSim.Region.Framework.Scenes
101 { 101 {
102 userlevel = 1; 102 userlevel = 1;
103 } 103 }
104 // TODO: remove this cruft once MasterAvatar is fully deprecated
105 //
106 if (m_regInfo.MasterAvatarAssignedUUID == AgentID)
107 {
108 userlevel = 2;
109 }
110 EventManager.TriggerOnNewInventoryItemUploadComplete(AgentID, item.AssetID, item.Name, userlevel); 104 EventManager.TriggerOnNewInventoryItemUploadComplete(AgentID, item.AssetID, item.Name, userlevel);
111 } 105 }
112 else 106 else
@@ -132,70 +126,17 @@ namespace OpenSim.Region.Framework.Scenes
132 } 126 }
133 127
134 /// <summary> 128 /// <summary>
135 /// Capability originating call to update the asset of an item in an agent's inventory
136 /// </summary>
137 /// <param name="remoteClient"></param>
138 /// <param name="itemID"></param>
139 /// <param name="data"></param>
140 /// <returns></returns>
141 public virtual UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data)
142 {
143 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
144 item = InventoryService.GetItem(item);
145
146 if (item != null)
147 {
148 if ((InventoryType)item.InvType == InventoryType.Notecard)
149 {
150 if (!Permissions.CanEditNotecard(itemID, UUID.Zero, remoteClient.AgentId))
151 {
152 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit notecard", false);
153 return UUID.Zero;
154 }
155
156 remoteClient.SendAgentAlertMessage("Notecard saved", false);
157 }
158 else if ((InventoryType)item.InvType == InventoryType.LSL)
159 {
160 if (!Permissions.CanEditScript(itemID, UUID.Zero, remoteClient.AgentId))
161 {
162 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false);
163 return UUID.Zero;
164 }
165
166 remoteClient.SendAgentAlertMessage("Script saved", false);
167 }
168
169 AssetBase asset =
170 CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data);
171 item.AssetID = asset.FullID;
172 AssetService.Store(asset);
173
174 InventoryService.UpdateItem(item);
175
176 // remoteClient.SendInventoryItemCreateUpdate(item);
177 return (asset.FullID);
178 }
179 else
180 {
181 m_log.ErrorFormat(
182 "[AGENT INVENTORY]: Could not find item {0} for caps inventory update",
183 itemID);
184 }
185
186 return UUID.Zero;
187 }
188
189 /// <summary>
190 /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, UUID, byte[])</see> 129 /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, UUID, byte[])</see>
191 /// </summary> 130 /// </summary>
192 public UUID CapsUpdateInventoryItemAsset(UUID avatarId, UUID itemID, byte[] data) 131 public UUID CapsUpdateInventoryItemAsset(UUID avatarId, UUID itemID, byte[] data)
193 { 132 {
194 ScenePresence avatar; 133 ScenePresence avatar;
195 134
196 if (TryGetAvatar(avatarId, out avatar)) 135 if (TryGetScenePresence(avatarId, out avatar))
197 { 136 {
198 return CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data); 137 IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
138 if (invAccess != null)
139 return invAccess.CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data);
199 } 140 }
200 else 141 else
201 { 142 {
@@ -251,7 +192,7 @@ namespace OpenSim.Region.Framework.Scenes
251 return new ArrayList(); 192 return new ArrayList();
252 } 193 }
253 194
254 AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data); 195 AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data, remoteClient.AgentId);
255 AssetService.Store(asset); 196 AssetService.Store(asset);
256 197
257 if (isScriptRunning) 198 if (isScriptRunning)
@@ -289,7 +230,7 @@ namespace OpenSim.Region.Framework.Scenes
289 { 230 {
290 ScenePresence avatar; 231 ScenePresence avatar;
291 232
292 if (TryGetAvatar(avatarId, out avatar)) 233 if (TryGetScenePresence(avatarId, out avatar))
293 { 234 {
294 return CapsUpdateTaskInventoryScriptAsset( 235 return CapsUpdateTaskInventoryScriptAsset(
295 avatar.ControllingClient, itemId, primId, isScriptRunning, data); 236 avatar.ControllingClient, itemId, primId, isScriptRunning, data);
@@ -478,7 +419,11 @@ namespace OpenSim.Region.Framework.Scenes
478 itemCopy.SaleType = item.SaleType; 419 itemCopy.SaleType = item.SaleType;
479 420
480 if (InventoryService.AddItem(itemCopy)) 421 if (InventoryService.AddItem(itemCopy))
481 TransferInventoryAssets(itemCopy, senderId, recipient); 422 {
423 IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
424 if (invAccess != null)
425 invAccess.TransferInventoryAssets(itemCopy, senderId, recipient);
426 }
482 427
483 if (!Permissions.BypassPermissions()) 428 if (!Permissions.BypassPermissions())
484 { 429 {
@@ -500,10 +445,6 @@ namespace OpenSim.Region.Framework.Scenes
500 445
501 } 446 }
502 447
503 protected virtual void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver)
504 {
505 }
506
507 /// <summary> 448 /// <summary>
508 /// Give an entire inventory folder from one user to another. The entire contents (including all descendent 449 /// Give an entire inventory folder from one user to another. The entire contents (including all descendent
509 /// folders) is given. 450 /// folders) is given.
@@ -573,7 +514,9 @@ namespace OpenSim.Region.Framework.Scenes
573 "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}", 514 "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
574 remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName); 515 remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);
575 516
576 InventoryItemBase item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(oldItemID); 517 InventoryItemBase item = null;
518 if (LibraryService != null && LibraryService.LibraryRootFolder != null)
519 item = LibraryService.LibraryRootFolder.FindItem(oldItemID);
577 520
578 if (item == null) 521 if (item == null)
579 { 522 {
@@ -627,15 +570,9 @@ namespace OpenSim.Region.Framework.Scenes
627 /// <summary> 570 /// <summary>
628 /// Create a new asset data structure. 571 /// Create a new asset data structure.
629 /// </summary> 572 /// </summary>
630 /// <param name="name"></param> 573 private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data, UUID creatorID)
631 /// <param name="description"></param>
632 /// <param name="invType"></param>
633 /// <param name="assetType"></param>
634 /// <param name="data"></param>
635 /// <returns></returns>
636 private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data)
637 { 574 {
638 AssetBase asset = new AssetBase(UUID.Random(), name, assetType); 575 AssetBase asset = new AssetBase(UUID.Random(), name, assetType, creatorID.ToString());
639 asset.Description = description; 576 asset.Description = description;
640 asset.Data = (data == null) ? new byte[1] : data; 577 asset.Data = (data == null) ? new byte[1] : data;
641 578
@@ -745,13 +682,9 @@ namespace OpenSim.Region.Framework.Scenes
745 682
746 if (transactionID == UUID.Zero) 683 if (transactionID == UUID.Zero)
747 { 684 {
748 CachedUserInfo userInfo 685 ScenePresence presence;
749 = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 686 if (TryGetScenePresence(remoteClient.AgentId, out presence))
750
751 if (userInfo != null)
752 { 687 {
753 ScenePresence presence;
754 TryGetAvatar(remoteClient.AgentId, out presence);
755 byte[] data = null; 688 byte[] data = null;
756 689
757 if (invType == (sbyte)InventoryType.Landmark && presence != null) 690 if (invType == (sbyte)InventoryType.Landmark && presence != null)
@@ -765,7 +698,7 @@ namespace OpenSim.Region.Framework.Scenes
765 data = Encoding.ASCII.GetBytes(strdata); 698 data = Encoding.ASCII.GetBytes(strdata);
766 } 699 }
767 700
768 AssetBase asset = CreateAsset(name, description, assetType, data); 701 AssetBase asset = CreateAsset(name, description, assetType, data, remoteClient.AgentId);
769 AssetService.Store(asset); 702 AssetService.Store(asset);
770 703
771 CreateNewInventoryItem(remoteClient, remoteClient.AgentId.ToString(), folderID, asset.Name, 0, callbackID, asset, invType, nextOwnerMask, creationDate); 704 CreateNewInventoryItem(remoteClient, remoteClient.AgentId.ToString(), folderID, asset.Name, 0, callbackID, asset, invType, nextOwnerMask, creationDate);
@@ -773,7 +706,7 @@ namespace OpenSim.Region.Framework.Scenes
773 else 706 else
774 { 707 {
775 m_log.ErrorFormat( 708 m_log.ErrorFormat(
776 "userInfo for agent uuid {0} unexpectedly null in CreateNewInventoryItem", 709 "ScenePresence for agent uuid {0} unexpectedly not found in CreateNewInventoryItem",
777 remoteClient.AgentId); 710 remoteClient.AgentId);
778 } 711 }
779 } 712 }
@@ -1012,7 +945,7 @@ namespace OpenSim.Region.Framework.Scenes
1012 { 945 {
1013 ScenePresence avatar; 946 ScenePresence avatar;
1014 947
1015 if (TryGetAvatar(avatarId, out avatar)) 948 if (TryGetScenePresence(avatarId, out avatar))
1016 { 949 {
1017 return MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId); 950 return MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId);
1018 } 951 }
@@ -1126,7 +1059,7 @@ namespace OpenSim.Region.Framework.Scenes
1126 1059
1127 ScenePresence avatar; 1060 ScenePresence avatar;
1128 1061
1129 if (TryGetAvatar(srcTaskItem.OwnerID, out avatar)) 1062 if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
1130 { 1063 {
1131 destPart.GetProperties(avatar.ControllingClient); 1064 destPart.GetProperties(avatar.ControllingClient);
1132 } 1065 }
@@ -1154,7 +1087,7 @@ namespace OpenSim.Region.Framework.Scenes
1154 } 1087 }
1155 1088
1156 ScenePresence avatar = null; 1089 ScenePresence avatar = null;
1157 if (TryGetAvatar(destID, out avatar)) 1090 if (TryGetScenePresence(destID, out avatar))
1158 { 1091 {
1159 //profile.SendInventoryDecendents(avatar.ControllingClient, 1092 //profile.SendInventoryDecendents(avatar.ControllingClient,
1160 // profile.RootFolder.ID, true, false); 1093 // profile.RootFolder.ID, true, false);
@@ -1170,15 +1103,21 @@ namespace OpenSim.Region.Framework.Scenes
1170 1103
1171 private void SendInventoryUpdate(IClientAPI client, InventoryFolderBase folder, bool fetchFolders, bool fetchItems) 1104 private void SendInventoryUpdate(IClientAPI client, InventoryFolderBase folder, bool fetchFolders, bool fetchItems)
1172 { 1105 {
1173 m_log.DebugFormat("[AGENT INVENTORY]: Send Inventory Folder {0} Update to {1} {2}", folder.Name, client.FirstName, client.LastName); 1106 if (folder == null)
1107 return;
1108
1109 // Fetch the folder contents
1174 InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID); 1110 InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID);
1175 InventoryFolderBase containingFolder = new InventoryFolderBase(); 1111
1176 containingFolder.ID = folder.ID; 1112 // Fetch the folder itself to get its current version
1177 containingFolder.Owner = client.AgentId; 1113 InventoryFolderBase containingFolder = new InventoryFolderBase(folder.ID, client.AgentId);
1178 containingFolder = InventoryService.GetFolder(containingFolder); 1114 containingFolder = InventoryService.GetFolder(containingFolder);
1179 int version = containingFolder.Version;
1180 1115
1181 client.SendInventoryFolderDetails(client.AgentId, folder.ID, contents.Items, contents.Folders, version, fetchFolders, fetchItems); 1116 //m_log.DebugFormat("[AGENT INVENTORY]: Sending inventory folder contents ({0} nodes) for \"{1}\" to {2} {3}",
1117 // contents.Folders.Count + contents.Items.Count, containingFolder.Name, client.FirstName, client.LastName);
1118
1119 if (containingFolder != null)
1120 client.SendInventoryFolderDetails(client.AgentId, folder.ID, contents.Items, contents.Folders, containingFolder.Version, fetchFolders, fetchItems);
1182 } 1121 }
1183 1122
1184 /// <summary> 1123 /// <summary>
@@ -1220,9 +1159,9 @@ namespace OpenSim.Region.Framework.Scenes
1220 item = InventoryService.GetItem(item); 1159 item = InventoryService.GetItem(item);
1221 1160
1222 // Try library 1161 // Try library
1223 if (null == item) 1162 if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
1224 { 1163 {
1225 item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(itemID); 1164 item = LibraryService.LibraryRootFolder.FindItem(itemID);
1226 } 1165 }
1227 1166
1228 if (item != null) 1167 if (item != null)
@@ -1289,9 +1228,9 @@ namespace OpenSim.Region.Framework.Scenes
1289 1228
1290 // Try library 1229 // Try library
1291 // XXX clumsy, possibly should be one call 1230 // XXX clumsy, possibly should be one call
1292 if (null == item) 1231 if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
1293 { 1232 {
1294 item = CommsManager.UserProfileCacheService.LibraryRoot.FindItem(itemID); 1233 item = LibraryService.LibraryRootFolder.FindItem(itemID);
1295 } 1234 }
1296 1235
1297 if (item != null) 1236 if (item != null)
@@ -1348,7 +1287,9 @@ namespace OpenSim.Region.Framework.Scenes
1348 itemBase.InvType, part.UUID, remoteClient.AgentId)) 1287 itemBase.InvType, part.UUID, remoteClient.AgentId))
1349 return; 1288 return;
1350 1289
1351 AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}")); 1290 AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType,
1291 Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"),
1292 remoteClient.AgentId);
1352 AssetService.Store(asset); 1293 AssetService.Store(asset);
1353 1294
1354 TaskInventoryItem taskItem = new TaskInventoryItem(); 1295 TaskInventoryItem taskItem = new TaskInventoryItem();
@@ -1483,7 +1424,7 @@ namespace OpenSim.Region.Framework.Scenes
1483 1424
1484 ScenePresence avatar; 1425 ScenePresence avatar;
1485 1426
1486 if (TryGetAvatar(srcTaskItem.OwnerID, out avatar)) 1427 if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
1487 { 1428 {
1488 destPart.GetProperties(avatar.ControllingClient); 1429 destPart.GetProperties(avatar.ControllingClient);
1489 } 1430 }
@@ -1617,237 +1558,6 @@ namespace OpenSim.Region.Framework.Scenes
1617 } 1558 }
1618 } 1559 }
1619 1560
1620 /// <summary>
1621 /// Delete a scene object from a scene and place in the given avatar's inventory.
1622 /// Returns the UUID of the newly created asset.
1623 /// </summary>
1624 /// <param name="action"></param>
1625 /// <param name="folderID"></param>
1626 /// <param name="objectGroup"></param>
1627 /// <param name="remoteClient"> </param>
1628 public virtual UUID DeleteToInventory(DeRezAction action, UUID folderID,
1629 SceneObjectGroup objectGroup, IClientAPI remoteClient)
1630 {
1631 UUID assetID = UUID.Zero;
1632
1633 Vector3 inventoryStoredPosition = new Vector3
1634 (((objectGroup.AbsolutePosition.X > (int)Constants.RegionSize)
1635 ? 250
1636 : objectGroup.AbsolutePosition.X)
1637 ,
1638 (objectGroup.AbsolutePosition.X > (int)Constants.RegionSize)
1639 ? 250
1640 : objectGroup.AbsolutePosition.X,
1641 objectGroup.AbsolutePosition.Z);
1642
1643 Vector3 originalPosition = objectGroup.AbsolutePosition;
1644
1645 objectGroup.AbsolutePosition = inventoryStoredPosition;
1646
1647 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(objectGroup);
1648
1649 objectGroup.AbsolutePosition = originalPosition;
1650
1651 // Get the user info of the item destination
1652 //
1653 UUID userID = UUID.Zero;
1654
1655 if (action == DeRezAction.Take || action == DeRezAction.TakeCopy ||
1656 action == DeRezAction.SaveToExistingUserInventoryItem)
1657 {
1658 // Take or take copy require a taker
1659 // Saving changes requires a local user
1660 //
1661 if (remoteClient == null)
1662 return UUID.Zero;
1663
1664 userID = remoteClient.AgentId;
1665 }
1666 else
1667 {
1668 // All returns / deletes go to the object owner
1669 //
1670
1671 userID = objectGroup.RootPart.OwnerID;
1672 }
1673
1674 if (userID == UUID.Zero) // Can't proceed
1675 {
1676 return UUID.Zero;
1677 }
1678
1679 // If we're returning someone's item, it goes back to the
1680 // owner's Lost And Found folder.
1681 // Delete is treated like return in this case
1682 // Deleting your own items makes them go to trash
1683 //
1684
1685 InventoryFolderBase folder = null;
1686 InventoryItemBase item = null;
1687
1688 if (DeRezAction.SaveToExistingUserInventoryItem == action)
1689 {
1690 item = new InventoryItemBase(objectGroup.RootPart.FromUserInventoryItemID, userID);
1691 item = InventoryService.GetItem(item);
1692
1693 //item = userInfo.RootFolder.FindItem(
1694 // objectGroup.RootPart.FromUserInventoryItemID);
1695
1696 if (null == item)
1697 {
1698 m_log.DebugFormat(
1699 "[AGENT INVENTORY]: Object {0} {1} scheduled for save to inventory has already been deleted.",
1700 objectGroup.Name, objectGroup.UUID);
1701 return UUID.Zero;
1702 }
1703 }
1704 else
1705 {
1706 // Folder magic
1707 //
1708 if (action == DeRezAction.Delete)
1709 {
1710 // Deleting someone else's item
1711 //
1712
1713
1714 if (remoteClient == null ||
1715 objectGroup.OwnerID != remoteClient.AgentId)
1716 {
1717 // Folder skeleton may not be loaded and we
1718 // have to wait for the inventory to find
1719 // the destination folder
1720 //
1721 folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
1722 }
1723 else
1724 {
1725 // Assume inventory skeleton was loaded during login
1726 // and all folders can be found
1727 //
1728 folder = InventoryService.GetFolderForType(userID, AssetType.TrashFolder);
1729 }
1730 }
1731 else if (action == DeRezAction.Return)
1732 {
1733
1734 // Dump to lost + found unconditionally
1735 //
1736 folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
1737 }
1738
1739 if (folderID == UUID.Zero && folder == null)
1740 {
1741 if (action == DeRezAction.Delete)
1742 {
1743 // Deletes go to trash by default
1744 //
1745 folder = InventoryService.GetFolderForType(userID, AssetType.TrashFolder);
1746 }
1747 else
1748 {
1749 // Catch all. Use lost & found
1750 //
1751
1752 folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
1753 }
1754 }
1755
1756 if (folder == null) // None of the above
1757 {
1758 //folder = userInfo.RootFolder.FindFolder(folderID);
1759 folder = new InventoryFolderBase(folderID);
1760
1761 if (folder == null) // Nowhere to put it
1762 {
1763 return UUID.Zero;
1764 }
1765 }
1766
1767 item = new InventoryItemBase();
1768 item.CreatorId = objectGroup.RootPart.CreatorID.ToString();
1769 item.ID = UUID.Random();
1770 item.InvType = (int)InventoryType.Object;
1771 item.Folder = folder.ID;
1772 item.Owner = userID;
1773 }
1774
1775 AssetBase asset = CreateAsset(
1776 objectGroup.GetPartName(objectGroup.RootPart.LocalId),
1777 objectGroup.GetPartDescription(objectGroup.RootPart.LocalId),
1778 (sbyte)AssetType.Object,
1779 Utils.StringToBytes(sceneObjectXml));
1780 AssetService.Store(asset);
1781 assetID = asset.FullID;
1782
1783 if (DeRezAction.SaveToExistingUserInventoryItem == action)
1784 {
1785 item.AssetID = asset.FullID;
1786 InventoryService.UpdateItem(item);
1787 }
1788 else
1789 {
1790 item.AssetID = asset.FullID;
1791
1792 if (remoteClient != null && (remoteClient.AgentId != objectGroup.RootPart.OwnerID) && Permissions.PropagatePermissions())
1793 {
1794 uint perms=objectGroup.GetEffectivePermissions();
1795 uint nextPerms=(perms & 7) << 13;
1796 if ((nextPerms & (uint)PermissionMask.Copy) == 0)
1797 perms &= ~(uint)PermissionMask.Copy;
1798 if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
1799 perms &= ~(uint)PermissionMask.Transfer;
1800 if ((nextPerms & (uint)PermissionMask.Modify) == 0)
1801 perms &= ~(uint)PermissionMask.Modify;
1802
1803 item.BasePermissions = perms & objectGroup.RootPart.NextOwnerMask;
1804 item.CurrentPermissions = item.BasePermissions;
1805 item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
1806 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask & objectGroup.RootPart.NextOwnerMask;
1807 item.GroupPermissions = objectGroup.RootPart.GroupMask & objectGroup.RootPart.NextOwnerMask;
1808 item.CurrentPermissions |= 8; // Slam!
1809 }
1810 else
1811 {
1812 uint ownerPerms = objectGroup.GetEffectivePermissions();
1813 if ((objectGroup.RootPart.OwnerMask & (uint)PermissionMask.Modify) != 0)
1814 ownerPerms |= (uint)PermissionMask.Modify;
1815
1816 item.BasePermissions = ownerPerms;
1817 item.CurrentPermissions = ownerPerms;
1818
1819 item.NextPermissions = objectGroup.RootPart.NextOwnerMask;
1820 item.EveryOnePermissions = objectGroup.RootPart.EveryoneMask;
1821 item.GroupPermissions = objectGroup.RootPart.GroupMask;
1822
1823 item.CurrentPermissions |= 8; // Slam!
1824 }
1825
1826 // TODO: add the new fields (Flags, Sale info, etc)
1827 item.CreationDate = Util.UnixTimeSinceEpoch();
1828 item.Description = asset.Description;
1829 item.Name = asset.Name;
1830 item.AssetType = asset.Type;
1831
1832 InventoryService.AddItem(item);
1833
1834 if (remoteClient != null && item.Owner == remoteClient.AgentId)
1835 {
1836 remoteClient.SendInventoryItemCreateUpdate(item, 0);
1837 }
1838 else
1839 {
1840 ScenePresence notifyUser = GetScenePresence(item.Owner);
1841 if (notifyUser != null)
1842 {
1843 notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item, 0);
1844 }
1845 }
1846 }
1847
1848 return assetID;
1849 }
1850
1851 public void UpdateKnownItem(IClientAPI remoteClient, SceneObjectGroup grp, UUID itemID, UUID agentID) 1561 public void UpdateKnownItem(IClientAPI remoteClient, SceneObjectGroup grp, UUID itemID, UUID agentID)
1852 { 1562 {
1853 SceneObjectGroup objectGroup = grp; 1563 SceneObjectGroup objectGroup = grp;
@@ -1874,7 +1584,8 @@ namespace OpenSim.Region.Framework.Scenes
1874 objectGroup.GetPartName(objectGroup.LocalId), 1584 objectGroup.GetPartName(objectGroup.LocalId),
1875 objectGroup.GetPartDescription(objectGroup.LocalId), 1585 objectGroup.GetPartDescription(objectGroup.LocalId),
1876 (sbyte)AssetType.Object, 1586 (sbyte)AssetType.Object,
1877 Utils.StringToBytes(sceneObjectXml)); 1587 Utils.StringToBytes(sceneObjectXml),
1588 remoteClient.AgentId);
1878 AssetService.Store(asset); 1589 AssetService.Store(asset);
1879 1590
1880 item.AssetID = asset.FullID; 1591 item.AssetID = asset.FullID;
@@ -1921,7 +1632,8 @@ namespace OpenSim.Region.Framework.Scenes
1921 grp.GetPartName(grp.LocalId), 1632 grp.GetPartName(grp.LocalId),
1922 grp.GetPartDescription(grp.LocalId), 1633 grp.GetPartDescription(grp.LocalId),
1923 (sbyte)AssetType.Object, 1634 (sbyte)AssetType.Object,
1924 Utils.StringToBytes(sceneObjectXml)); 1635 Utils.StringToBytes(sceneObjectXml),
1636 remoteClient.AgentId);
1925 AssetService.Store(asset); 1637 AssetService.Store(asset);
1926 1638
1927 InventoryItemBase item = new InventoryItemBase(); 1639 InventoryItemBase item = new InventoryItemBase();
@@ -1988,225 +1700,11 @@ namespace OpenSim.Region.Framework.Scenes
1988 UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection, 1700 UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
1989 bool RezSelected, bool RemoveItem, UUID fromTaskID) 1701 bool RezSelected, bool RemoveItem, UUID fromTaskID)
1990 { 1702 {
1991 RezObject( 1703 IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
1992 remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection, 1704 if (invAccess != null)
1993 RezSelected, RemoveItem, fromTaskID, false); 1705 invAccess.RezObject(
1994 } 1706 remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
1995 1707 RezSelected, RemoveItem, fromTaskID, false);
1996 /// <summary>
1997 /// Rez an object into the scene from the user's inventory
1998 /// </summary>
1999 /// <param name="remoteClient"></param>
2000 /// <param name="itemID"></param>
2001 /// <param name="RayEnd"></param>
2002 /// <param name="RayStart"></param>
2003 /// <param name="RayTargetID"></param>
2004 /// <param name="BypassRayCast"></param>
2005 /// <param name="RayEndIsIntersection"></param>
2006 /// <param name="RezSelected"></param>
2007 /// <param name="RemoveItem"></param>
2008 /// <param name="fromTaskID"></param>
2009 /// <param name="attachment"></param>
2010 /// <returns>The SceneObjectGroup rezzed or null if rez was unsuccessful.</returns>
2011 public virtual SceneObjectGroup RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
2012 UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
2013 bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
2014 {
2015 // Work out position details
2016 byte bRayEndIsIntersection = (byte)0;
2017
2018 if (RayEndIsIntersection)
2019 {
2020 bRayEndIsIntersection = (byte)1;
2021 }
2022 else
2023 {
2024 bRayEndIsIntersection = (byte)0;
2025 }
2026
2027 Vector3 scale = new Vector3(0.5f, 0.5f, 0.5f);
2028
2029
2030 Vector3 pos = GetNewRezLocation(
2031 RayStart, RayEnd, RayTargetID, Quaternion.Identity,
2032 BypassRayCast, bRayEndIsIntersection,true,scale, false);
2033
2034 // Rez object
2035 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
2036 item = InventoryService.GetItem(item);
2037
2038 if (item != null)
2039 {
2040 AssetBase rezAsset = AssetService.Get(item.AssetID.ToString());
2041
2042 if (rezAsset != null)
2043 {
2044 UUID itemId = UUID.Zero;
2045
2046 // If we have permission to copy then link the rezzed object back to the user inventory
2047 // item that it came from. This allows us to enable 'save object to inventory'
2048 if (!Permissions.BypassPermissions())
2049 {
2050 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy)
2051 {
2052 itemId = item.ID;
2053 }
2054 }
2055 else
2056 {
2057 // Brave new fullperm world
2058 //
2059 itemId = item.ID;
2060 }
2061
2062 string xmlData = Utils.BytesToString(rezAsset.Data);
2063 SceneObjectGroup group
2064 = SceneObjectSerializer.FromOriginalXmlFormat(itemId, xmlData);
2065
2066 if (!Permissions.CanRezObject(
2067 group.Children.Count, remoteClient.AgentId, pos)
2068 && !attachment)
2069 {
2070 // The client operates in no fail mode. It will
2071 // have already removed the item from the folder
2072 // if it's no copy.
2073 // Put it back if it's not an attachment
2074 //
2075 if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!attachment))
2076 remoteClient.SendBulkUpdateInventory(item);
2077 return null;
2078 }
2079
2080 group.ResetIDs();
2081
2082 if (attachment)
2083 {
2084 group.RootPart.ObjectFlags |= (uint)PrimFlags.Phantom;
2085 group.RootPart.IsAttachment = true;
2086 }
2087
2088 AddNewSceneObject(group, true);
2089
2090 // m_log.InfoFormat("ray end point for inventory rezz is {0} {1} {2} ", RayEnd.X, RayEnd.Y, RayEnd.Z);
2091 // if attachment we set it's asset id so object updates can reflect that
2092 // if not, we set it's position in world.
2093 if (!attachment)
2094 {
2095 float offsetHeight = 0;
2096 pos = GetNewRezLocation(
2097 RayStart, RayEnd, RayTargetID, Quaternion.Identity,
2098 BypassRayCast, bRayEndIsIntersection, true, group.GetAxisAlignedBoundingBox(out offsetHeight), false);
2099 pos.Z += offsetHeight;
2100 group.AbsolutePosition = pos;
2101 // m_log.InfoFormat("rezx point for inventory rezz is {0} {1} {2} and offsetheight was {3}", pos.X, pos.Y, pos.Z, offsetHeight);
2102
2103 }
2104 else
2105 {
2106 group.SetFromItemID(itemID);
2107 }
2108
2109 SceneObjectPart rootPart = null;
2110 try
2111 {
2112 rootPart = group.GetChildPart(group.UUID);
2113 }
2114 catch (NullReferenceException)
2115 {
2116 string isAttachment = "";
2117
2118 if (attachment)
2119 isAttachment = " Object was an attachment";
2120
2121 m_log.Error("[AGENT INVENTORY]: Error rezzing ItemID: " + itemID + " object has no rootpart." + isAttachment);
2122 }
2123
2124 // Since renaming the item in the inventory does not affect the name stored
2125 // in the serialization, transfer the correct name from the inventory to the
2126 // object itself before we rez.
2127 rootPart.Name = item.Name;
2128 rootPart.Description = item.Description;
2129
2130 List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
2131
2132 group.SetGroup(remoteClient.ActiveGroupId, remoteClient);
2133 if (rootPart.OwnerID != item.Owner)
2134 {
2135 //Need to kill the for sale here
2136 rootPart.ObjectSaleType = 0;
2137 rootPart.SalePrice = 10;
2138
2139 if (Permissions.PropagatePermissions())
2140 {
2141 if ((item.CurrentPermissions & 8) != 0)
2142 {
2143 foreach (SceneObjectPart part in partList)
2144 {
2145 part.EveryoneMask = item.EveryOnePermissions;
2146 part.NextOwnerMask = item.NextPermissions;
2147 part.GroupMask = 0; // DO NOT propagate here
2148 }
2149 }
2150 group.ApplyNextOwnerPermissions();
2151 }
2152 }
2153
2154 foreach (SceneObjectPart part in partList)
2155 {
2156 if (part.OwnerID != item.Owner)
2157 {
2158 part.LastOwnerID = part.OwnerID;
2159 part.OwnerID = item.Owner;
2160 part.Inventory.ChangeInventoryOwner(item.Owner);
2161 }
2162 else if (((item.CurrentPermissions & 8) != 0) && (!attachment)) // Slam!
2163 {
2164 part.EveryoneMask = item.EveryOnePermissions;
2165 part.NextOwnerMask = item.NextPermissions;
2166
2167 part.GroupMask = 0; // DO NOT propagate here
2168 }
2169 }
2170
2171 rootPart.TrimPermissions();
2172
2173 if (!attachment)
2174 {
2175 if (group.RootPart.Shape.PCode == (byte)PCode.Prim)
2176 {
2177 group.ClearPartAttachmentData();
2178 }
2179 }
2180
2181 if (!attachment)
2182 {
2183 // Fire on_rez
2184 group.CreateScriptInstances(0, true, DefaultScriptEngine, 0);
2185
2186 rootPart.ScheduleFullUpdate();
2187 }
2188
2189 if (!Permissions.BypassPermissions())
2190 {
2191 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
2192 {
2193 // If this is done on attachments, no
2194 // copy ones will be lost, so avoid it
2195 //
2196 if (!attachment)
2197 {
2198 List<UUID> uuids = new List<UUID>();
2199 uuids.Add(item.ID);
2200 InventoryService.DeleteItems(item.Owner, uuids);
2201 }
2202 }
2203 }
2204
2205 return rootPart.ParentGroup;
2206 }
2207 }
2208
2209 return null;
2210 } 1708 }
2211 1709
2212 /// <summary> 1710 /// <summary>
@@ -2349,122 +1847,12 @@ namespace OpenSim.Region.Framework.Scenes
2349 EventManager.TriggerOnAttach(localID, itemID, avatarID); 1847 EventManager.TriggerOnAttach(localID, itemID, avatarID);
2350 } 1848 }
2351 1849
2352 /// <summary>
2353 /// Called when the client receives a request to rez a single attachment on to the avatar from inventory
2354 /// (RezSingleAttachmentFromInv packet).
2355 /// </summary>
2356 /// <param name="remoteClient"></param>
2357 /// <param name="itemID"></param>
2358 /// <param name="AttachmentPt"></param>
2359 /// <returns></returns>
2360 public UUID RezSingleAttachment(IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
2361 {
2362 m_log.DebugFormat("[USER INVENTORY]: Rezzing single attachment from item {0} for {1}", itemID, remoteClient.Name);
2363
2364 SceneObjectGroup att = m_sceneGraph.RezSingleAttachment(remoteClient, itemID, AttachmentPt);
2365
2366 if (att == null)
2367 {
2368 DetachSingleAttachmentToInv(itemID, remoteClient);
2369 return UUID.Zero;
2370 }
2371
2372 return RezSingleAttachment(att, remoteClient, itemID, AttachmentPt);
2373 }
2374
2375 /// <summary>
2376 /// Update the user inventory to reflect an attachment
2377 /// </summary>
2378 /// <param name="att"></param>
2379 /// <param name="remoteClient"></param>
2380 /// <param name="itemID"></param>
2381 /// <param name="AttachmentPt"></param>
2382 /// <returns></returns>
2383 public UUID RezSingleAttachment(SceneObjectGroup att, IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
2384 {
2385 m_log.DebugFormat(
2386 "[USER INVENTORY]: Updating inventory of {0} to show attachment of {1} (item ID {2})",
2387 remoteClient.Name, att.Name, itemID);
2388
2389 if (!att.IsDeleted)
2390 AttachmentPt = att.RootPart.AttachmentPoint;
2391
2392 ScenePresence presence;
2393 if (TryGetAvatar(remoteClient.AgentId, out presence))
2394 {
2395 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
2396 item = InventoryService.GetItem(item);
2397
2398 presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/);
2399 }
2400 return att.UUID;
2401 }
2402
2403 public void RezMultipleAttachments(IClientAPI remoteClient, RezMultipleAttachmentsFromInvPacket.HeaderDataBlock header, 1850 public void RezMultipleAttachments(IClientAPI remoteClient, RezMultipleAttachmentsFromInvPacket.HeaderDataBlock header,
2404 RezMultipleAttachmentsFromInvPacket.ObjectDataBlock[] objects) 1851 RezMultipleAttachmentsFromInvPacket.ObjectDataBlock[] objects)
2405 { 1852 {
2406 foreach (RezMultipleAttachmentsFromInvPacket.ObjectDataBlock obj in objects) 1853 foreach (RezMultipleAttachmentsFromInvPacket.ObjectDataBlock obj in objects)
2407 { 1854 {
2408 RezSingleAttachment(remoteClient, obj.ItemID, obj.AttachmentPt); 1855 AttachmentsModule.RezSingleAttachmentFromInventory(remoteClient, obj.ItemID, obj.AttachmentPt);
2409 }
2410 }
2411
2412 /// <summary>
2413 /// Attach an object.
2414 /// </summary>
2415 /// <param name="controllingClient"></param>
2416 /// <param name="localID"></param>
2417 /// <param name="attachPoint"></param>
2418 /// <param name="rot"></param>
2419 /// <param name="pos"></param>
2420 /// <param name="silent"></param>
2421 /// <returns>true if the object was successfully attached, false otherwise</returns>
2422 public bool AttachObject(IClientAPI controllingClient, uint localID, uint attachPoint, Quaternion rot, Vector3 pos, bool silent)
2423 {
2424 return m_sceneGraph.AttachObject(controllingClient, localID, attachPoint, rot, pos, silent);
2425 }
2426
2427 /// <summary>
2428 /// This registers the item as attached in a user's inventory
2429 /// </summary>
2430 /// <param name="remoteClient"></param>
2431 /// <param name="AttachmentPt"></param>
2432 /// <param name="itemID"></param>
2433 /// <param name="att"></param>
2434 public void AttachObject(IClientAPI remoteClient, uint AttachmentPt, UUID itemID, SceneObjectGroup att)
2435 {
2436// m_log.DebugFormat(
2437// "[USER INVENTORY]: Updating attachment {0} for {1} at {2} using item ID {3}",
2438// att.Name, remoteClient.Name, AttachmentPt, itemID);
2439
2440 if (UUID.Zero == itemID)
2441 {
2442 m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error inventory item ID.");
2443 return;
2444 }
2445
2446 if (0 == AttachmentPt)
2447 {
2448 m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error attachment point.");
2449 return;
2450 }
2451
2452 if (null == att.RootPart)
2453 {
2454 m_log.Error("[SCENE INVENTORY]: Unable to save attachment for a prim without the rootpart!");
2455 return;
2456 }
2457
2458 ScenePresence presence;
2459 if (TryGetAvatar(remoteClient.AgentId, out presence))
2460 {
2461 // XXYY!!
2462 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
2463 item = InventoryService.GetItem(item);
2464 presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/);
2465
2466 if (m_AvatarFactory != null)
2467 m_AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
2468 } 1856 }
2469 } 1857 }
2470 1858
@@ -2477,7 +1865,7 @@ namespace OpenSim.Region.Framework.Scenes
2477 UUID inventoryID = part.ParentGroup.GetFromItemID(); 1865 UUID inventoryID = part.ParentGroup.GetFromItemID();
2478 1866
2479 ScenePresence presence; 1867 ScenePresence presence;
2480 if (TryGetAvatar(remoteClient.AgentId, out presence)) 1868 if (TryGetScenePresence(remoteClient.AgentId, out presence))
2481 { 1869 {
2482 if (!Permissions.CanRezObject(part.ParentGroup.Children.Count, remoteClient.AgentId, presence.AbsolutePosition)) 1870 if (!Permissions.CanRezObject(part.ParentGroup.Children.Count, remoteClient.AgentId, presence.AbsolutePosition))
2483 return; 1871 return;
@@ -2498,24 +1886,6 @@ namespace OpenSim.Region.Framework.Scenes
2498 SendAttachEvent(part.ParentGroup.LocalId, itemID, UUID.Zero); 1886 SendAttachEvent(part.ParentGroup.LocalId, itemID, UUID.Zero);
2499 } 1887 }
2500 1888
2501 public void DetachSingleAttachmentToInv(UUID itemID, IClientAPI remoteClient)
2502 {
2503 ScenePresence presence;
2504 if (TryGetAvatar(remoteClient.AgentId, out presence))
2505 {
2506 presence.Appearance.DetachAttachment(itemID);
2507
2508 // Save avatar attachment information
2509 if (m_AvatarFactory != null)
2510 {
2511 m_log.Info("[SCENE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId + ", ItemID: " + itemID);
2512 m_AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
2513 }
2514 }
2515
2516 m_sceneGraph.DetachSingleAttachmentToInv(itemID, remoteClient);
2517 }
2518
2519 public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID) 1889 public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID)
2520 { 1890 {
2521 EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID); 1891 EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID);