diff options
author | Melanie Thielker | 2016-08-20 22:41:53 +0100 |
---|---|---|
committer | Melanie Thielker | 2016-08-20 22:42:32 +0100 |
commit | 82244cca68328db002e2c00a693d64781737cf7c (patch) | |
tree | 4c86d53a2d6d5eb3dde70601ba0821eaf7110bf1 /OpenSim/Services/UserAccountService/UserAccountService.cs | |
parent | fix GetLandData(...) in land connectors not suporting large regions (diff) | |
download | opensim-SC_OLD-82244cca68328db002e2c00a693d64781737cf7c.zip opensim-SC_OLD-82244cca68328db002e2c00a693d64781737cf7c.tar.gz opensim-SC_OLD-82244cca68328db002e2c00a693d64781737cf7c.tar.bz2 opensim-SC_OLD-82244cca68328db002e2c00a693d64781737cf7c.tar.xz |
Allow creation of user appearance from a model avatar. Thank you,
Cinder, for this patch.
Signed-off-by: Melanie Thielker <melanie@t-data.com>
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/UserAccountService/UserAccountService.cs | 211 |
1 files changed, 209 insertions, 2 deletions
diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs index 668fe53..bb50536 100644 --- a/OpenSim/Services/UserAccountService/UserAccountService.cs +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs | |||
@@ -544,7 +544,8 @@ namespace OpenSim.Services.UserAccountService | |||
544 | /// <param name="lastName"></param> | 544 | /// <param name="lastName"></param> |
545 | /// <param name="password"></param> | 545 | /// <param name="password"></param> |
546 | /// <param name="email"></param> | 546 | /// <param name="email"></param> |
547 | public UserAccount CreateUser(UUID scopeID, UUID principalID, string firstName, string lastName, string password, string email) | 547 | /// <param name="model"></param> |
548 | public UserAccount CreateUser(UUID scopeID, UUID principalID, string firstName, string lastName, string password, string email, string model = "") | ||
548 | { | 549 | { |
549 | UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); | 550 | UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); |
550 | if (null == account) | 551 | if (null == account) |
@@ -603,7 +604,12 @@ namespace OpenSim.Services.UserAccountService | |||
603 | } | 604 | } |
604 | 605 | ||
605 | if (m_CreateDefaultAvatarEntries) | 606 | if (m_CreateDefaultAvatarEntries) |
606 | CreateDefaultAppearanceEntries(account.PrincipalID); | 607 | { |
608 | if (String.IsNullOrEmpty(model)) | ||
609 | CreateDefaultAppearanceEntries(account.PrincipalID); | ||
610 | else | ||
611 | EstablishAppearance(account.PrincipalID, model); | ||
612 | } | ||
607 | } | 613 | } |
608 | 614 | ||
609 | m_log.InfoFormat( | 615 | m_log.InfoFormat( |
@@ -734,6 +740,7 @@ namespace OpenSim.Services.UserAccountService | |||
734 | wearables[AvatarWearable.PANTS] = new AvatarWearable(pants.ID, pants.AssetID); | 740 | wearables[AvatarWearable.PANTS] = new AvatarWearable(pants.ID, pants.AssetID); |
735 | 741 | ||
736 | AvatarAppearance ap = new AvatarAppearance(); | 742 | AvatarAppearance ap = new AvatarAppearance(); |
743 | // this loop works, but is questionable | ||
737 | for (int i = 0; i < 6; i++) | 744 | for (int i = 0; i < 6; i++) |
738 | { | 745 | { |
739 | ap.SetWearable(i, wearables[i]); | 746 | ap.SetWearable(i, wearables[i]); |
@@ -742,5 +749,205 @@ namespace OpenSim.Services.UserAccountService | |||
742 | m_AvatarService.SetAppearance(principalID, ap); | 749 | m_AvatarService.SetAppearance(principalID, ap); |
743 | } | 750 | } |
744 | } | 751 | } |
752 | |||
753 | protected void EstablishAppearance(UUID destinationAgent, string model) | ||
754 | { | ||
755 | m_log.DebugFormat("[USER ACCOUNT SERVICE]: Establishing new appearance for {0} - {1}", | ||
756 | destinationAgent.ToString(), model); | ||
757 | |||
758 | string[] modelSpecifiers = model.Split(); | ||
759 | if (modelSpecifiers.Length != 2) | ||
760 | { | ||
761 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Invalid model name \'{0}\'. Falling back to Ruth for {1}", | ||
762 | model, destinationAgent); | ||
763 | CreateDefaultAppearanceEntries(destinationAgent); | ||
764 | return; | ||
765 | } | ||
766 | |||
767 | // Does the source model exist? | ||
768 | UserAccount modelAccount = GetUserAccount(UUID.Zero, modelSpecifiers[0], modelSpecifiers[1]); | ||
769 | if (modelAccount == null) | ||
770 | { | ||
771 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Requested model \'{0}\' not found. Falling back to Ruth for {1}", | ||
772 | model, destinationAgent); | ||
773 | CreateDefaultAppearanceEntries(destinationAgent); | ||
774 | return; | ||
775 | } | ||
776 | |||
777 | // Does the source model have an established appearance herself? | ||
778 | AvatarAppearance modelAppearance = m_AvatarService.GetAppearance(modelAccount.PrincipalID); | ||
779 | if (modelAppearance == null) | ||
780 | { | ||
781 | m_log.WarnFormat("USER ACCOUNT SERVICE]: Requested model \'{0}\' does not have an established appearance. Falling back to Ruth for {1}", | ||
782 | model, destinationAgent); | ||
783 | CreateDefaultAppearanceEntries(destinationAgent); | ||
784 | return; | ||
785 | } | ||
786 | |||
787 | try | ||
788 | { | ||
789 | CopyWearablesAndAttachments(destinationAgent, modelAccount.PrincipalID, modelAppearance); | ||
790 | |||
791 | m_AvatarService.SetAppearance(destinationAgent, modelAppearance); | ||
792 | } | ||
793 | catch (Exception e) | ||
794 | { | ||
795 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring appearance for {0} : {1}", | ||
796 | destinationAgent, e.Message); | ||
797 | } | ||
798 | |||
799 | m_log.DebugFormat("[USER ACCOUNT SERVICE]: Finished establishing appearance for {0}", | ||
800 | destinationAgent.ToString()); | ||
801 | } | ||
802 | |||
803 | /// <summary> | ||
804 | /// This method is called by EstablishAppearance to do a copy all inventory items | ||
805 | /// worn or attached to the Clothing inventory folder of the receiving avatar. | ||
806 | /// In parallel the avatar wearables and attachments are updated. | ||
807 | /// </summary> | ||
808 | private void CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance) | ||
809 | { | ||
810 | // Get Clothing folder of receiver | ||
811 | InventoryFolderBase destinationFolder = m_InventoryService.GetFolderForType(destination, FolderType.Clothing); | ||
812 | |||
813 | if (destinationFolder == null) | ||
814 | throw new Exception("Cannot locate folder(s)"); | ||
815 | |||
816 | // Missing destination folder? This should *never* be the case | ||
817 | if (destinationFolder.Type != (short)FolderType.Clothing) | ||
818 | { | ||
819 | destinationFolder = new InventoryFolderBase(); | ||
820 | |||
821 | destinationFolder.ID = UUID.Random(); | ||
822 | destinationFolder.Name = "Clothing"; | ||
823 | destinationFolder.Owner = destination; | ||
824 | destinationFolder.Type = (short)AssetType.Clothing; | ||
825 | destinationFolder.ParentID = m_InventoryService.GetRootFolder(destination).ID; | ||
826 | destinationFolder.Version = 1; | ||
827 | m_InventoryService.AddFolder(destinationFolder); // store base record | ||
828 | m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Created folder for destination {0}", source); | ||
829 | } | ||
830 | |||
831 | // Wearables | ||
832 | AvatarWearable[] wearables = avatarAppearance.Wearables; | ||
833 | AvatarWearable wearable; | ||
834 | |||
835 | for (int i = 0; i < wearables.Length; i++) | ||
836 | { | ||
837 | wearable = wearables[i]; | ||
838 | if (wearable[0].ItemID != UUID.Zero) | ||
839 | { | ||
840 | // Get inventory item and copy it | ||
841 | InventoryItemBase item = m_InventoryService.GetItem(source, wearable[0].ItemID); | ||
842 | |||
843 | if (item != null) | ||
844 | { | ||
845 | InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination); | ||
846 | destinationItem.Name = item.Name; | ||
847 | destinationItem.Owner = destination; | ||
848 | destinationItem.Description = item.Description; | ||
849 | destinationItem.InvType = item.InvType; | ||
850 | destinationItem.CreatorId = item.CreatorId; | ||
851 | destinationItem.CreatorData = item.CreatorData; | ||
852 | destinationItem.NextPermissions = item.NextPermissions; | ||
853 | destinationItem.CurrentPermissions = item.CurrentPermissions; | ||
854 | destinationItem.BasePermissions = item.BasePermissions; | ||
855 | destinationItem.EveryOnePermissions = item.EveryOnePermissions; | ||
856 | destinationItem.GroupPermissions = item.GroupPermissions; | ||
857 | destinationItem.AssetType = item.AssetType; | ||
858 | destinationItem.AssetID = item.AssetID; | ||
859 | destinationItem.GroupID = item.GroupID; | ||
860 | destinationItem.GroupOwned = item.GroupOwned; | ||
861 | destinationItem.SalePrice = item.SalePrice; | ||
862 | destinationItem.SaleType = item.SaleType; | ||
863 | destinationItem.Flags = item.Flags; | ||
864 | destinationItem.CreationDate = item.CreationDate; | ||
865 | destinationItem.Folder = destinationFolder.ID; | ||
866 | ApplyNextOwnerPermissions(destinationItem); | ||
867 | |||
868 | m_InventoryService.AddItem(destinationItem); | ||
869 | m_log.DebugFormat("[USER ACCOUNT SERVICE]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); | ||
870 | |||
871 | // Wear item | ||
872 | AvatarWearable newWearable = new AvatarWearable(); | ||
873 | newWearable.Wear(destinationItem.ID, wearable[0].AssetID); | ||
874 | avatarAppearance.SetWearable(i, newWearable); | ||
875 | } | ||
876 | else | ||
877 | { | ||
878 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring {0} to folder {1}", wearable[0].ItemID, destinationFolder.ID); | ||
879 | } | ||
880 | } | ||
881 | } | ||
882 | |||
883 | // Attachments | ||
884 | List<AvatarAttachment> attachments = avatarAppearance.GetAttachments(); | ||
885 | |||
886 | foreach (AvatarAttachment attachment in attachments) | ||
887 | { | ||
888 | int attachpoint = attachment.AttachPoint; | ||
889 | UUID itemID = attachment.ItemID; | ||
890 | |||
891 | if (itemID != UUID.Zero) | ||
892 | { | ||
893 | // Get inventory item and copy it | ||
894 | InventoryItemBase item = m_InventoryService.GetItem(source, itemID); | ||
895 | |||
896 | if (item != null) | ||
897 | { | ||
898 | InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination); | ||
899 | destinationItem.Name = item.Name; | ||
900 | destinationItem.Owner = destination; | ||
901 | destinationItem.Description = item.Description; | ||
902 | destinationItem.InvType = item.InvType; | ||
903 | destinationItem.CreatorId = item.CreatorId; | ||
904 | destinationItem.CreatorData = item.CreatorData; | ||
905 | destinationItem.NextPermissions = item.NextPermissions; | ||
906 | destinationItem.CurrentPermissions = item.CurrentPermissions; | ||
907 | destinationItem.BasePermissions = item.BasePermissions; | ||
908 | destinationItem.EveryOnePermissions = item.EveryOnePermissions; | ||
909 | destinationItem.GroupPermissions = item.GroupPermissions; | ||
910 | destinationItem.AssetType = item.AssetType; | ||
911 | destinationItem.AssetID = item.AssetID; | ||
912 | destinationItem.GroupID = item.GroupID; | ||
913 | destinationItem.GroupOwned = item.GroupOwned; | ||
914 | destinationItem.SalePrice = item.SalePrice; | ||
915 | destinationItem.SaleType = item.SaleType; | ||
916 | destinationItem.Flags = item.Flags; | ||
917 | destinationItem.CreationDate = item.CreationDate; | ||
918 | destinationItem.Folder = destinationFolder.ID; | ||
919 | ApplyNextOwnerPermissions(destinationItem); | ||
920 | |||
921 | m_InventoryService.AddItem(destinationItem); | ||
922 | m_log.DebugFormat("[USER ACCOUNT SERVICE]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); | ||
923 | |||
924 | // Attach item | ||
925 | avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID); | ||
926 | m_log.DebugFormat("[USER ACCOUNT SERVICE]: Attached {0}", destinationItem.ID); | ||
927 | } | ||
928 | else | ||
929 | { | ||
930 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID); | ||
931 | } | ||
932 | } | ||
933 | } | ||
934 | } | ||
935 | |||
936 | /// <summary> | ||
937 | /// Apply next owner permissions. | ||
938 | /// </summary> | ||
939 | private void ApplyNextOwnerPermissions(InventoryItemBase item) | ||
940 | { | ||
941 | if (item.InvType == (int)InventoryType.Object) | ||
942 | { | ||
943 | uint perms = item.CurrentPermissions; | ||
944 | PermissionsUtil.ApplyFoldedPermissions(item.CurrentPermissions, ref perms); | ||
945 | item.CurrentPermissions = perms; | ||
946 | } | ||
947 | |||
948 | item.CurrentPermissions &= item.NextPermissions; | ||
949 | item.BasePermissions &= item.NextPermissions; | ||
950 | item.EveryOnePermissions &= item.NextPermissions; | ||
951 | } | ||
745 | } | 952 | } |
746 | } | 953 | } |