diff options
author | Oren Hurvitz | 2014-05-05 11:06:49 +0300 |
---|---|---|
committer | Oren Hurvitz | 2014-05-06 07:28:44 +0100 |
commit | 1e5cff32fc41356971d6ad601cbee7ad62472c76 (patch) | |
tree | be61c0ae3f814ec2a54d1b0ef63d42f86fce2600 /OpenSim/Region/Framework | |
parent | Log whenever an inventory operation is blocked because the item/folder isn't ... (diff) | |
download | opensim-SC-1e5cff32fc41356971d6ad601cbee7ad62472c76.zip opensim-SC-1e5cff32fc41356971d6ad601cbee7ad62472c76.tar.gz opensim-SC-1e5cff32fc41356971d6ad601cbee7ad62472c76.tar.bz2 opensim-SC-1e5cff32fc41356971d6ad601cbee7ad62472c76.tar.xz |
Show more meaningful error messages when failed to give an item to another user
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 39 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs | 10 |
2 files changed, 35 insertions, 14 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index bb9f457..27cd5c6 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | |||
@@ -46,7 +46,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
46 | { | 46 | { |
47 | public partial class Scene | 47 | public partial class Scene |
48 | { | 48 | { |
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
50 | private static readonly string LogHeader = "[SCENE INVENTORY]"; | 50 | private static readonly string LogHeader = "[SCENE INVENTORY]"; |
51 | 51 | ||
52 | /// <summary> | 52 | /// <summary> |
@@ -534,9 +534,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
534 | /// <param name="recipientClient"></param> | 534 | /// <param name="recipientClient"></param> |
535 | /// <param name="senderId">ID of the sender of the item</param> | 535 | /// <param name="senderId">ID of the sender of the item</param> |
536 | /// <param name="itemId"></param> | 536 | /// <param name="itemId"></param> |
537 | public virtual void GiveInventoryItem(IClientAPI recipientClient, UUID senderId, UUID itemId) | 537 | public virtual void GiveInventoryItem(IClientAPI recipientClient, UUID senderId, UUID itemId, out string message) |
538 | { | 538 | { |
539 | InventoryItemBase itemCopy = GiveInventoryItem(recipientClient.AgentId, senderId, itemId); | 539 | InventoryItemBase itemCopy = GiveInventoryItem(recipientClient.AgentId, senderId, itemId, out message); |
540 | 540 | ||
541 | if (itemCopy != null) | 541 | if (itemCopy != null) |
542 | recipientClient.SendBulkUpdateInventory(itemCopy); | 542 | recipientClient.SendBulkUpdateInventory(itemCopy); |
@@ -549,9 +549,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
549 | /// <param name="senderId">ID of the sender of the item</param> | 549 | /// <param name="senderId">ID of the sender of the item</param> |
550 | /// <param name="itemId"></param> | 550 | /// <param name="itemId"></param> |
551 | /// <returns>The inventory item copy given, null if the give was unsuccessful</returns> | 551 | /// <returns>The inventory item copy given, null if the give was unsuccessful</returns> |
552 | public virtual InventoryItemBase GiveInventoryItem(UUID recipient, UUID senderId, UUID itemId) | 552 | public virtual InventoryItemBase GiveInventoryItem(UUID recipient, UUID senderId, UUID itemId, out string message) |
553 | { | 553 | { |
554 | return GiveInventoryItem(recipient, senderId, itemId, UUID.Zero); | 554 | return GiveInventoryItem(recipient, senderId, itemId, UUID.Zero, out message); |
555 | } | 555 | } |
556 | 556 | ||
557 | /// <summary> | 557 | /// <summary> |
@@ -568,12 +568,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
568 | /// The inventory item copy given, null if the give was unsuccessful | 568 | /// The inventory item copy given, null if the give was unsuccessful |
569 | /// </returns> | 569 | /// </returns> |
570 | public virtual InventoryItemBase GiveInventoryItem( | 570 | public virtual InventoryItemBase GiveInventoryItem( |
571 | UUID recipient, UUID senderId, UUID itemId, UUID recipientFolderId) | 571 | UUID recipient, UUID senderId, UUID itemId, UUID recipientFolderId, out string message) |
572 | { | 572 | { |
573 | //Console.WriteLine("Scene.Inventory.cs: GiveInventoryItem"); | 573 | //Console.WriteLine("Scene.Inventory.cs: GiveInventoryItem"); |
574 | 574 | ||
575 | if (!Permissions.CanTransferUserInventory(itemId, senderId, recipient)) | 575 | if (!Permissions.CanTransferUserInventory(itemId, senderId, recipient)) |
576 | { | ||
577 | message = "Not allowed to transfer this item."; | ||
576 | return null; | 578 | return null; |
579 | } | ||
577 | 580 | ||
578 | InventoryItemBase item = new InventoryItemBase(itemId, senderId); | 581 | InventoryItemBase item = new InventoryItemBase(itemId, senderId); |
579 | item = InventoryService.GetItem(item); | 582 | item = InventoryService.GetItem(item); |
@@ -582,6 +585,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
582 | { | 585 | { |
583 | m_log.WarnFormat( | 586 | m_log.WarnFormat( |
584 | "[AGENT INVENTORY]: Failed to find item {0} sent by {1} to {2}", itemId, senderId, recipient); | 587 | "[AGENT INVENTORY]: Failed to find item {0} sent by {1} to {2}", itemId, senderId, recipient); |
588 | message = string.Format("Item not found: {0}.", itemId); | ||
585 | return null; | 589 | return null; |
586 | } | 590 | } |
587 | 591 | ||
@@ -590,6 +594,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
590 | m_log.WarnFormat( | 594 | m_log.WarnFormat( |
591 | "[AGENT INVENTORY]: Attempt to send item {0} {1} to {2} failed because sender {3} did not match item owner {4}", | 595 | "[AGENT INVENTORY]: Attempt to send item {0} {1} to {2} failed because sender {3} did not match item owner {4}", |
592 | item.Name, item.ID, recipient, senderId, item.Owner); | 596 | item.Name, item.ID, recipient, senderId, item.Owner); |
597 | message = "Sender did not match item owner."; | ||
593 | return null; | 598 | return null; |
594 | } | 599 | } |
595 | 600 | ||
@@ -600,7 +605,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
600 | if (!Permissions.BypassPermissions()) | 605 | if (!Permissions.BypassPermissions()) |
601 | { | 606 | { |
602 | if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0) | 607 | if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0) |
608 | { | ||
609 | message = "Item doesn't have the Transfer permission."; | ||
603 | return null; | 610 | return null; |
611 | } | ||
604 | } | 612 | } |
605 | 613 | ||
606 | // Insert a copy of the item into the recipient | 614 | // Insert a copy of the item into the recipient |
@@ -736,9 +744,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
736 | InventoryFolderBase root = InventoryService.GetRootFolder(recipient); | 744 | InventoryFolderBase root = InventoryService.GetRootFolder(recipient); |
737 | 745 | ||
738 | if (root != null) | 746 | if (root != null) |
747 | { | ||
739 | itemCopy.Folder = root.ID; | 748 | itemCopy.Folder = root.ID; |
749 | } | ||
740 | else | 750 | else |
741 | return null; // No destination | 751 | { |
752 | message = "Can't find a folder to add the item to."; | ||
753 | return null; | ||
754 | } | ||
742 | } | 755 | } |
743 | } | 756 | } |
744 | 757 | ||
@@ -763,6 +776,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
763 | } | 776 | } |
764 | } | 777 | } |
765 | 778 | ||
779 | message = null; | ||
766 | return itemCopy; | 780 | return itemCopy; |
767 | } | 781 | } |
768 | 782 | ||
@@ -780,7 +794,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
780 | /// <returns> | 794 | /// <returns> |
781 | /// The inventory folder copy given, null if the copy was unsuccessful | 795 | /// The inventory folder copy given, null if the copy was unsuccessful |
782 | /// </returns> | 796 | /// </returns> |
783 | public virtual InventoryFolderBase GiveInventoryFolder( | 797 | public virtual InventoryFolderBase GiveInventoryFolder(IClientAPI client, |
784 | UUID recipientId, UUID senderId, UUID folderId, UUID recipientParentFolderId) | 798 | UUID recipientId, UUID senderId, UUID folderId, UUID recipientParentFolderId) |
785 | { | 799 | { |
786 | //// Retrieve the folder from the sender | 800 | //// Retrieve the folder from the sender |
@@ -815,13 +829,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
815 | InventoryCollection contents = InventoryService.GetFolderContent(senderId, folderId); | 829 | InventoryCollection contents = InventoryService.GetFolderContent(senderId, folderId); |
816 | foreach (InventoryFolderBase childFolder in contents.Folders) | 830 | foreach (InventoryFolderBase childFolder in contents.Folders) |
817 | { | 831 | { |
818 | GiveInventoryFolder(recipientId, senderId, childFolder.ID, newFolder.ID); | 832 | GiveInventoryFolder(client, recipientId, senderId, childFolder.ID, newFolder.ID); |
819 | } | 833 | } |
820 | 834 | ||
821 | // Give all the items | 835 | // Give all the items |
822 | foreach (InventoryItemBase item in contents.Items) | 836 | foreach (InventoryItemBase item in contents.Items) |
823 | { | 837 | { |
824 | GiveInventoryItem(recipientId, senderId, item.ID, newFolder.ID); | 838 | string message; |
839 | if (GiveInventoryItem(recipientId, senderId, item.ID, newFolder.ID, out message) == null) | ||
840 | { | ||
841 | if (client != null) | ||
842 | client.SendAgentAlertMessage(message, false); | ||
843 | } | ||
825 | } | 844 | } |
826 | 845 | ||
827 | return newFolder; | 846 | return newFolder; |
diff --git a/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs index e50b4da..0736278 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/UserInventoryTests.cs | |||
@@ -95,7 +95,9 @@ namespace OpenSim.Region.Framework.Tests | |||
95 | UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002)); | 95 | UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002)); |
96 | InventoryItemBase item1 = UserInventoryHelpers.CreateInventoryItem(scene, "item1", user1.PrincipalID); | 96 | InventoryItemBase item1 = UserInventoryHelpers.CreateInventoryItem(scene, "item1", user1.PrincipalID); |
97 | 97 | ||
98 | scene.GiveInventoryItem(user2.PrincipalID, user1.PrincipalID, item1.ID); | 98 | string message; |
99 | |||
100 | scene.GiveInventoryItem(user2.PrincipalID, user1.PrincipalID, item1.ID, out message); | ||
99 | 101 | ||
100 | InventoryItemBase retrievedItem1 | 102 | InventoryItemBase retrievedItem1 |
101 | = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, user2.PrincipalID, "Notecards/item1"); | 103 | = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, user2.PrincipalID, "Notecards/item1"); |
@@ -103,7 +105,7 @@ namespace OpenSim.Region.Framework.Tests | |||
103 | Assert.That(retrievedItem1, Is.Not.Null); | 105 | Assert.That(retrievedItem1, Is.Not.Null); |
104 | 106 | ||
105 | // Try giving back the freshly received item | 107 | // Try giving back the freshly received item |
106 | scene.GiveInventoryItem(user1.PrincipalID, user2.PrincipalID, retrievedItem1.ID); | 108 | scene.GiveInventoryItem(user1.PrincipalID, user2.PrincipalID, retrievedItem1.ID, out message); |
107 | 109 | ||
108 | List<InventoryItemBase> reretrievedItems | 110 | List<InventoryItemBase> reretrievedItems |
109 | = UserInventoryHelpers.GetInventoryItems(scene.InventoryService, user1.PrincipalID, "Notecards/item1"); | 111 | = UserInventoryHelpers.GetInventoryItems(scene.InventoryService, user1.PrincipalID, "Notecards/item1"); |
@@ -123,7 +125,7 @@ namespace OpenSim.Region.Framework.Tests | |||
123 | InventoryFolderBase folder1 | 125 | InventoryFolderBase folder1 |
124 | = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, "folder1", false); | 126 | = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, "folder1", false); |
125 | 127 | ||
126 | scene.GiveInventoryFolder(user2.PrincipalID, user1.PrincipalID, folder1.ID, UUID.Zero); | 128 | scene.GiveInventoryFolder(null, user2.PrincipalID, user1.PrincipalID, folder1.ID, UUID.Zero); |
127 | 129 | ||
128 | InventoryFolderBase retrievedFolder1 | 130 | InventoryFolderBase retrievedFolder1 |
129 | = UserInventoryHelpers.GetInventoryFolder(scene.InventoryService, user2.PrincipalID, "folder1"); | 131 | = UserInventoryHelpers.GetInventoryFolder(scene.InventoryService, user2.PrincipalID, "folder1"); |
@@ -131,7 +133,7 @@ namespace OpenSim.Region.Framework.Tests | |||
131 | Assert.That(retrievedFolder1, Is.Not.Null); | 133 | Assert.That(retrievedFolder1, Is.Not.Null); |
132 | 134 | ||
133 | // Try giving back the freshly received folder | 135 | // Try giving back the freshly received folder |
134 | scene.GiveInventoryFolder(user1.PrincipalID, user2.PrincipalID, retrievedFolder1.ID, UUID.Zero); | 136 | scene.GiveInventoryFolder(null, user1.PrincipalID, user2.PrincipalID, retrievedFolder1.ID, UUID.Zero); |
135 | 137 | ||
136 | List<InventoryFolderBase> reretrievedFolders | 138 | List<InventoryFolderBase> reretrievedFolders |
137 | = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, "folder1"); | 139 | = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, "folder1"); |