diff options
author | Justin Clark-Casey (justincc) | 2011-09-01 23:14:50 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-09-01 23:14:50 +0100 |
commit | 712d44635a0f4552fbac4c6423ab88e027cef8a2 (patch) | |
tree | ed38e6cacfe35bfd41cef58781117b5b7f676260 /OpenSim/Region | |
parent | use group.RootPart in IAM.RezObject() rather than group.GetChildPart(group.UU... (diff) | |
download | opensim-SC-712d44635a0f4552fbac4c6423ab88e027cef8a2.zip opensim-SC-712d44635a0f4552fbac4c6423ab88e027cef8a2.tar.gz opensim-SC-712d44635a0f4552fbac4c6423ab88e027cef8a2.tar.bz2 opensim-SC-712d44635a0f4552fbac4c6423ab88e027cef8a2.tar.xz |
refactor: Move sanity checks to the top of IAM.RezObject() to make the code more readable
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs | 434 |
1 files changed, 215 insertions, 219 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs index e0ff5a8..5778dff 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs | |||
@@ -700,276 +700,272 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
700 | RayStart, RayEnd, RayTargetID, Quaternion.Identity, | 700 | RayStart, RayEnd, RayTargetID, Quaternion.Identity, |
701 | BypassRayCast, bRayEndIsIntersection, true, scale, false); | 701 | BypassRayCast, bRayEndIsIntersection, true, scale, false); |
702 | 702 | ||
703 | // Rez object | ||
704 | InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId); | 703 | InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId); |
705 | item = m_Scene.InventoryService.GetItem(item); | 704 | item = m_Scene.InventoryService.GetItem(item); |
706 | 705 | ||
707 | if (item != null) | 706 | if (item == null) |
708 | { | 707 | { |
709 | item.Owner = remoteClient.AgentId; | 708 | m_log.WarnFormat( |
709 | "[InventoryAccessModule]: Could not find item {0} for {1} in RezObject()", | ||
710 | itemID, remoteClient.Name); | ||
710 | 711 | ||
711 | AssetBase rezAsset = m_Scene.AssetService.Get(item.AssetID.ToString()); | 712 | return null; |
713 | } | ||
712 | 714 | ||
713 | SceneObjectGroup group = null; | 715 | item.Owner = remoteClient.AgentId; |
716 | AssetBase rezAsset = m_Scene.AssetService.Get(item.AssetID.ToString()); | ||
714 | 717 | ||
715 | if (rezAsset != null) | 718 | if (rezAsset == null) |
716 | { | 719 | { |
717 | UUID itemId = UUID.Zero; | 720 | m_log.WarnFormat( |
721 | "[InventoryAccessModule]: Could not find asset {0} for item {1} {2} for {3} in RezObject()", | ||
722 | item.AssetID, item.Name, item.ID, remoteClient.Name); | ||
718 | 723 | ||
719 | // If we have permission to copy then link the rezzed object back to the user inventory | 724 | return null; |
720 | // item that it came from. This allows us to enable 'save object to inventory' | 725 | } |
721 | if (!m_Scene.Permissions.BypassPermissions()) | ||
722 | { | ||
723 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy && (item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0) | ||
724 | { | ||
725 | itemId = item.ID; | ||
726 | } | ||
727 | } | ||
728 | else | ||
729 | { | ||
730 | if ((item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0) | ||
731 | { | ||
732 | // Brave new fullperm world | ||
733 | itemId = item.ID; | ||
734 | } | ||
735 | } | ||
736 | 726 | ||
737 | string xmlData = Utils.BytesToString(rezAsset.Data); | 727 | SceneObjectGroup group = null; |
738 | List<SceneObjectGroup> objlist = | 728 | UUID itemId = UUID.Zero; |
739 | new List<SceneObjectGroup>(); | ||
740 | List<Vector3> veclist = new List<Vector3>(); | ||
741 | 729 | ||
742 | XmlDocument doc = new XmlDocument(); | 730 | // If we have permission to copy then link the rezzed object back to the user inventory |
743 | doc.LoadXml(xmlData); | 731 | // item that it came from. This allows us to enable 'save object to inventory' |
744 | XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject"); | 732 | if (!m_Scene.Permissions.BypassPermissions()) |
745 | if (e == null || attachment) // Single | 733 | { |
746 | { | 734 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy && (item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0) |
747 | SceneObjectGroup g = | 735 | { |
748 | SceneObjectSerializer.FromOriginalXmlFormat( | 736 | itemId = item.ID; |
749 | itemId, xmlData); | 737 | } |
750 | objlist.Add(g); | 738 | } |
751 | veclist.Add(new Vector3(0, 0, 0)); | 739 | else |
752 | 740 | { | |
753 | float offsetHeight = 0; | 741 | if ((item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0) |
754 | pos = m_Scene.GetNewRezLocation( | 742 | { |
755 | RayStart, RayEnd, RayTargetID, Quaternion.Identity, | 743 | // Brave new fullperm world |
756 | BypassRayCast, bRayEndIsIntersection, true, g.GetAxisAlignedBoundingBox(out offsetHeight), false); | 744 | itemId = item.ID; |
757 | pos.Z += offsetHeight; | 745 | } |
758 | } | 746 | } |
759 | else | 747 | |
760 | { | 748 | string xmlData = Utils.BytesToString(rezAsset.Data); |
761 | XmlElement coll = (XmlElement)e; | 749 | List<SceneObjectGroup> objlist = |
762 | float bx = Convert.ToSingle(coll.GetAttribute("x")); | 750 | new List<SceneObjectGroup>(); |
763 | float by = Convert.ToSingle(coll.GetAttribute("y")); | 751 | List<Vector3> veclist = new List<Vector3>(); |
764 | float bz = Convert.ToSingle(coll.GetAttribute("z")); | ||
765 | Vector3 bbox = new Vector3(bx, by, bz); | ||
766 | 752 | ||
767 | pos = m_Scene.GetNewRezLocation(RayStart, RayEnd, | 753 | XmlDocument doc = new XmlDocument(); |
768 | RayTargetID, Quaternion.Identity, | 754 | doc.LoadXml(xmlData); |
769 | BypassRayCast, bRayEndIsIntersection, true, | 755 | XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject"); |
770 | bbox, false); | 756 | if (e == null || attachment) // Single |
757 | { | ||
758 | SceneObjectGroup g = | ||
759 | SceneObjectSerializer.FromOriginalXmlFormat( | ||
760 | itemId, xmlData); | ||
761 | objlist.Add(g); | ||
762 | veclist.Add(new Vector3(0, 0, 0)); | ||
763 | |||
764 | float offsetHeight = 0; | ||
765 | pos = m_Scene.GetNewRezLocation( | ||
766 | RayStart, RayEnd, RayTargetID, Quaternion.Identity, | ||
767 | BypassRayCast, bRayEndIsIntersection, true, g.GetAxisAlignedBoundingBox(out offsetHeight), false); | ||
768 | pos.Z += offsetHeight; | ||
769 | } | ||
770 | else | ||
771 | { | ||
772 | XmlElement coll = (XmlElement)e; | ||
773 | float bx = Convert.ToSingle(coll.GetAttribute("x")); | ||
774 | float by = Convert.ToSingle(coll.GetAttribute("y")); | ||
775 | float bz = Convert.ToSingle(coll.GetAttribute("z")); | ||
776 | Vector3 bbox = new Vector3(bx, by, bz); | ||
771 | 777 | ||
772 | pos -= bbox / 2; | 778 | pos = m_Scene.GetNewRezLocation(RayStart, RayEnd, |
779 | RayTargetID, Quaternion.Identity, | ||
780 | BypassRayCast, bRayEndIsIntersection, true, | ||
781 | bbox, false); | ||
773 | 782 | ||
774 | XmlNodeList groups = e.SelectNodes("SceneObjectGroup"); | 783 | pos -= bbox / 2; |
775 | foreach (XmlNode n in groups) | 784 | |
776 | { | 785 | XmlNodeList groups = e.SelectNodes("SceneObjectGroup"); |
777 | SceneObjectGroup g = | 786 | foreach (XmlNode n in groups) |
778 | SceneObjectSerializer.FromOriginalXmlFormat( | 787 | { |
779 | itemId, n.OuterXml); | 788 | SceneObjectGroup g = |
780 | objlist.Add(g); | 789 | SceneObjectSerializer.FromOriginalXmlFormat( |
781 | XmlElement el = (XmlElement)n; | 790 | itemId, n.OuterXml); |
782 | 791 | objlist.Add(g); | |
783 | string rawX = el.GetAttribute("offsetx"); | 792 | XmlElement el = (XmlElement)n; |
784 | string rawY = el.GetAttribute("offsety"); | 793 | |
785 | string rawZ = el.GetAttribute("offsetz"); | 794 | string rawX = el.GetAttribute("offsetx"); |
795 | string rawY = el.GetAttribute("offsety"); | ||
796 | string rawZ = el.GetAttribute("offsetz"); | ||
786 | // | 797 | // |
787 | // m_log.DebugFormat( | 798 | // m_log.DebugFormat( |
788 | // "[INVENTORY ACCESS MODULE]: Converting coalesced object {0} offset <{1}, {2}, {3}>", | 799 | // "[INVENTORY ACCESS MODULE]: Converting coalesced object {0} offset <{1}, {2}, {3}>", |
789 | // g.Name, rawX, rawY, rawZ); | 800 | // g.Name, rawX, rawY, rawZ); |
790 | |||
791 | float x = Convert.ToSingle(rawX); | ||
792 | float y = Convert.ToSingle(rawY); | ||
793 | float z = Convert.ToSingle(rawZ); | ||
794 | veclist.Add(new Vector3(x, y, z)); | ||
795 | } | ||
796 | } | ||
797 | 801 | ||
798 | int primcount = 0; | 802 | float x = Convert.ToSingle(rawX); |
799 | foreach (SceneObjectGroup g in objlist) | 803 | float y = Convert.ToSingle(rawY); |
800 | primcount += g.PrimCount; | 804 | float z = Convert.ToSingle(rawZ); |
805 | veclist.Add(new Vector3(x, y, z)); | ||
806 | } | ||
807 | } | ||
801 | 808 | ||
802 | if (!m_Scene.Permissions.CanRezObject( | 809 | int primcount = 0; |
803 | primcount, remoteClient.AgentId, pos) | 810 | foreach (SceneObjectGroup g in objlist) |
804 | && !attachment) | 811 | primcount += g.PrimCount; |
805 | { | ||
806 | // The client operates in no fail mode. It will | ||
807 | // have already removed the item from the folder | ||
808 | // if it's no copy. | ||
809 | // Put it back if it's not an attachment | ||
810 | // | ||
811 | if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!attachment)) | ||
812 | remoteClient.SendBulkUpdateInventory(item); | ||
813 | 812 | ||
814 | return null; | 813 | if (!m_Scene.Permissions.CanRezObject( |
815 | } | 814 | primcount, remoteClient.AgentId, pos) |
815 | && !attachment) | ||
816 | { | ||
817 | // The client operates in no fail mode. It will | ||
818 | // have already removed the item from the folder | ||
819 | // if it's no copy. | ||
820 | // Put it back if it's not an attachment | ||
821 | // | ||
822 | if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!attachment)) | ||
823 | remoteClient.SendBulkUpdateInventory(item); | ||
816 | 824 | ||
817 | for (int i = 0 ; i < objlist.Count; i++) | 825 | return null; |
818 | { | 826 | } |
819 | group = objlist[i]; | 827 | |
828 | for (int i = 0 ; i < objlist.Count; i++) | ||
829 | { | ||
830 | group = objlist[i]; | ||
820 | 831 | ||
821 | // Vector3 storedPosition = group.AbsolutePosition; | 832 | // Vector3 storedPosition = group.AbsolutePosition; |
822 | if (group.UUID == UUID.Zero) | 833 | if (group.UUID == UUID.Zero) |
823 | { | 834 | { |
824 | m_log.Debug("[InventoryAccessModule]: Inventory object has UUID.Zero! Position 3"); | 835 | m_log.Debug("[InventoryAccessModule]: Inventory object has UUID.Zero! Position 3"); |
825 | } | 836 | } |
826 | 837 | ||
827 | group.RootPart.FromFolderID = item.Folder; | 838 | group.RootPart.FromFolderID = item.Folder; |
828 | 839 | ||
829 | // If it's rezzed in world, select it. Much easier to | 840 | // If it's rezzed in world, select it. Much easier to |
830 | // find small items. | 841 | // find small items. |
831 | // | 842 | // |
832 | if (!attachment) | 843 | if (!attachment) |
833 | { | 844 | { |
834 | group.RootPart.CreateSelected = true; | 845 | group.RootPart.CreateSelected = true; |
835 | foreach (SceneObjectPart child in group.Parts) | 846 | foreach (SceneObjectPart child in group.Parts) |
836 | child.CreateSelected = true; | 847 | child.CreateSelected = true; |
837 | } | 848 | } |
838 | 849 | ||
839 | group.ResetIDs(); | 850 | group.ResetIDs(); |
840 | 851 | ||
841 | if (attachment) | 852 | if (attachment) |
842 | { | 853 | { |
843 | group.RootPart.Flags |= PrimFlags.Phantom; | 854 | group.RootPart.Flags |= PrimFlags.Phantom; |
844 | group.IsAttachment = true; | 855 | group.IsAttachment = true; |
845 | } | 856 | } |
846 | 857 | ||
847 | // If we're rezzing an attachment then don't ask | 858 | // If we're rezzing an attachment then don't ask |
848 | // AddNewSceneObject() to update the client since | 859 | // AddNewSceneObject() to update the client since |
849 | // we'll be doing that later on. Scheduling more than | 860 | // we'll be doing that later on. Scheduling more than |
850 | // one full update during the attachment | 861 | // one full update during the attachment |
851 | // process causes some clients to fail to display the | 862 | // process causes some clients to fail to display the |
852 | // attachment properly. | 863 | // attachment properly. |
853 | m_Scene.AddNewSceneObject(group, true, false); | 864 | m_Scene.AddNewSceneObject(group, true, false); |
854 | 865 | ||
855 | // if attachment we set it's asset id so object updates | 866 | // if attachment we set it's asset id so object updates |
856 | // can reflect that, if not, we set it's position in world. | 867 | // can reflect that, if not, we set it's position in world. |
857 | if (!attachment) | 868 | if (!attachment) |
858 | { | 869 | { |
859 | group.ScheduleGroupForFullUpdate(); | 870 | group.ScheduleGroupForFullUpdate(); |
860 | |||
861 | group.AbsolutePosition = pos + veclist[i]; | ||
862 | } | ||
863 | else | ||
864 | { | ||
865 | group.SetFromItemID(itemID); | ||
866 | } | ||
867 | 871 | ||
868 | SceneObjectPart rootPart = group.RootPart; | 872 | group.AbsolutePosition = pos + veclist[i]; |
873 | } | ||
874 | else | ||
875 | { | ||
876 | group.SetFromItemID(itemID); | ||
877 | } | ||
869 | 878 | ||
870 | // Since renaming the item in the inventory does not | 879 | SceneObjectPart rootPart = group.RootPart; |
871 | // affect the name stored in the serialization, transfer | ||
872 | // the correct name from the inventory to the | ||
873 | // object itself before we rez. | ||
874 | // | ||
875 | // Only do these for the first object if we are rezzing a coalescence. | ||
876 | if (i == 0) | ||
877 | { | ||
878 | rootPart.Name = item.Name; | ||
879 | rootPart.Description = item.Description; | ||
880 | rootPart.ObjectSaleType = item.SaleType; | ||
881 | rootPart.SalePrice = item.SalePrice; | ||
882 | } | ||
883 | 880 | ||
884 | group.SetGroup(remoteClient.ActiveGroupId, remoteClient); | 881 | // Since renaming the item in the inventory does not |
885 | if ((rootPart.OwnerID != item.Owner) || | 882 | // affect the name stored in the serialization, transfer |
886 | (item.CurrentPermissions & 16) != 0) | 883 | // the correct name from the inventory to the |
887 | { | 884 | // object itself before we rez. |
888 | //Need to kill the for sale here | 885 | // |
889 | rootPart.ObjectSaleType = 0; | 886 | // Only do these for the first object if we are rezzing a coalescence. |
890 | rootPart.SalePrice = 10; | 887 | if (i == 0) |
888 | { | ||
889 | rootPart.Name = item.Name; | ||
890 | rootPart.Description = item.Description; | ||
891 | rootPart.ObjectSaleType = item.SaleType; | ||
892 | rootPart.SalePrice = item.SalePrice; | ||
893 | } | ||
891 | 894 | ||
892 | if (m_Scene.Permissions.PropagatePermissions()) | 895 | group.SetGroup(remoteClient.ActiveGroupId, remoteClient); |
893 | { | 896 | if ((rootPart.OwnerID != item.Owner) || |
894 | foreach (SceneObjectPart part in group.Parts) | 897 | (item.CurrentPermissions & 16) != 0) |
895 | { | 898 | { |
896 | if ((item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0) | 899 | //Need to kill the for sale here |
897 | { | 900 | rootPart.ObjectSaleType = 0; |
898 | part.EveryoneMask = item.EveryOnePermissions; | 901 | rootPart.SalePrice = 10; |
899 | part.NextOwnerMask = item.NextPermissions; | ||
900 | } | ||
901 | part.GroupMask = 0; // DO NOT propagate here | ||
902 | } | ||
903 | |||
904 | group.ApplyNextOwnerPermissions(); | ||
905 | } | ||
906 | } | ||
907 | 902 | ||
903 | if (m_Scene.Permissions.PropagatePermissions()) | ||
904 | { | ||
908 | foreach (SceneObjectPart part in group.Parts) | 905 | foreach (SceneObjectPart part in group.Parts) |
909 | { | 906 | { |
910 | if ((part.OwnerID != item.Owner) || | 907 | if ((item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0) |
911 | (item.CurrentPermissions & 16) != 0) | ||
912 | { | 908 | { |
913 | part.LastOwnerID = part.OwnerID; | 909 | part.EveryoneMask = item.EveryOnePermissions; |
914 | part.OwnerID = item.Owner; | 910 | part.NextOwnerMask = item.NextPermissions; |
915 | part.Inventory.ChangeInventoryOwner(item.Owner); | ||
916 | part.GroupMask = 0; // DO NOT propagate here | ||
917 | } | 911 | } |
918 | part.EveryoneMask = item.EveryOnePermissions; | 912 | part.GroupMask = 0; // DO NOT propagate here |
919 | part.NextOwnerMask = item.NextPermissions; | ||
920 | } | 913 | } |
921 | 914 | ||
922 | rootPart.TrimPermissions(); | 915 | group.ApplyNextOwnerPermissions(); |
923 | |||
924 | if (!attachment) | ||
925 | { | ||
926 | if (group.RootPart.Shape.PCode == (byte)PCode.Prim) | ||
927 | group.ClearPartAttachmentData(); | ||
928 | |||
929 | // Fire on_rez | ||
930 | group.CreateScriptInstances(0, true, m_Scene.DefaultScriptEngine, 1); | ||
931 | rootPart.ParentGroup.ResumeScripts(); | ||
932 | |||
933 | rootPart.ScheduleFullUpdate(); | ||
934 | } | ||
935 | |||
936 | // m_log.DebugFormat( | ||
937 | // "[InventoryAccessModule]: Rezzed {0} {1} {2} for {3}", | ||
938 | // group.Name, group.LocalId, group.UUID, remoteClient.Name); | ||
939 | } | 916 | } |
917 | } | ||
940 | 918 | ||
941 | if (!m_Scene.Permissions.BypassPermissions()) | 919 | foreach (SceneObjectPart part in group.Parts) |
920 | { | ||
921 | if ((part.OwnerID != item.Owner) || | ||
922 | (item.CurrentPermissions & 16) != 0) | ||
942 | { | 923 | { |
943 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) | 924 | part.LastOwnerID = part.OwnerID; |
944 | { | 925 | part.OwnerID = item.Owner; |
945 | // If this is done on attachments, no | 926 | part.Inventory.ChangeInventoryOwner(item.Owner); |
946 | // copy ones will be lost, so avoid it | 927 | part.GroupMask = 0; // DO NOT propagate here |
947 | // | ||
948 | if (!attachment) | ||
949 | { | ||
950 | List<UUID> uuids = new List<UUID>(); | ||
951 | uuids.Add(item.ID); | ||
952 | m_Scene.InventoryService.DeleteItems(item.Owner, uuids); | ||
953 | } | ||
954 | } | ||
955 | } | 928 | } |
929 | part.EveryoneMask = item.EveryOnePermissions; | ||
930 | part.NextOwnerMask = item.NextPermissions; | ||
956 | } | 931 | } |
957 | else | 932 | |
933 | rootPart.TrimPermissions(); | ||
934 | |||
935 | if (!attachment) | ||
958 | { | 936 | { |
959 | m_log.WarnFormat( | 937 | if (group.RootPart.Shape.PCode == (byte)PCode.Prim) |
960 | "[InventoryAccessModule]: Could not find asset {0} for item {1} {2} for {3} in RezObject()", item.AssetID, item.Name, item.ID, remoteClient.Name); | 938 | group.ClearPartAttachmentData(); |
939 | |||
940 | // Fire on_rez | ||
941 | group.CreateScriptInstances(0, true, m_Scene.DefaultScriptEngine, 1); | ||
942 | rootPart.ParentGroup.ResumeScripts(); | ||
943 | |||
944 | rootPart.ScheduleFullUpdate(); | ||
961 | } | 945 | } |
962 | 946 | ||
963 | return group; | 947 | // m_log.DebugFormat( |
948 | // "[InventoryAccessModule]: Rezzed {0} {1} {2} for {3}", | ||
949 | // group.Name, group.LocalId, group.UUID, remoteClient.Name); | ||
964 | } | 950 | } |
965 | else | 951 | |
952 | if (!m_Scene.Permissions.BypassPermissions()) | ||
966 | { | 953 | { |
967 | m_log.WarnFormat( | 954 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) |
968 | "[InventoryAccessModule]: Could not find item {0} for {1} in RezObject()", | 955 | { |
969 | itemID, remoteClient.Name); | 956 | // If this is done on attachments, no |
957 | // copy ones will be lost, so avoid it | ||
958 | // | ||
959 | if (!attachment) | ||
960 | { | ||
961 | List<UUID> uuids = new List<UUID>(); | ||
962 | uuids.Add(item.ID); | ||
963 | m_Scene.InventoryService.DeleteItems(item.Owner, uuids); | ||
964 | } | ||
965 | } | ||
970 | } | 966 | } |
971 | 967 | ||
972 | return null; | 968 | return group; |
973 | } | 969 | } |
974 | 970 | ||
975 | protected void AddUserData(SceneObjectGroup sog) | 971 | protected void AddUserData(SceneObjectGroup sog) |