aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/UserAccountService/UserAccountService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/UserAccountService/UserAccountService.cs')
-rw-r--r--OpenSim/Services/UserAccountService/UserAccountService.cs223
1 files changed, 218 insertions, 5 deletions
diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs
index 668fe53..706d475 100644
--- a/OpenSim/Services/UserAccountService/UserAccountService.cs
+++ b/OpenSim/Services/UserAccountService/UserAccountService.cs
@@ -92,7 +92,7 @@ namespace OpenSim.Services.UserAccountService
92 m_RootInstance = this; 92 m_RootInstance = this;
93 MainConsole.Instance.Commands.AddCommand("Users", false, 93 MainConsole.Instance.Commands.AddCommand("Users", false,
94 "create user", 94 "create user",
95 "create user [<first> [<last> [<pass> [<email> [<user id>]]]]]", 95 "create user [<first> [<last> [<pass> [<email> [<user id> [<model>]]]]]]",
96 "Create a new user", HandleCreateUser); 96 "Create a new user", HandleCreateUser);
97 97
98 MainConsole.Instance.Commands.AddCommand("Users", false, 98 MainConsole.Instance.Commands.AddCommand("Users", false,
@@ -353,7 +353,7 @@ namespace OpenSim.Services.UserAccountService
353 /// <summary> 353 /// <summary>
354 /// Handle the create user command from the console. 354 /// Handle the create user command from the console.
355 /// </summary> 355 /// </summary>
356 /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param> 356 /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email, userID, model name </param>
357 protected void HandleCreateUser(string module, string[] cmdparams) 357 protected void HandleCreateUser(string module, string[] cmdparams)
358 { 358 {
359 string firstName; 359 string firstName;
@@ -361,6 +361,7 @@ namespace OpenSim.Services.UserAccountService
361 string password; 361 string password;
362 string email; 362 string email;
363 string rawPrincipalId; 363 string rawPrincipalId;
364 string model;
364 365
365 List<char> excluded = new List<char>(new char[]{' '}); 366 List<char> excluded = new List<char>(new char[]{' '});
366 367
@@ -385,11 +386,16 @@ namespace OpenSim.Services.UserAccountService
385 else 386 else
386 rawPrincipalId = cmdparams[6]; 387 rawPrincipalId = cmdparams[6];
387 388
389 if (cmdparams.Length < 8)
390 model = MainConsole.Instance.CmdPrompt("Model name","");
391 else
392 model = cmdparams[7];
393
388 UUID principalId = UUID.Zero; 394 UUID principalId = UUID.Zero;
389 if (!UUID.TryParse(rawPrincipalId, out principalId)) 395 if (!UUID.TryParse(rawPrincipalId, out principalId))
390 throw new Exception(string.Format("ID {0} is not a valid UUID", rawPrincipalId)); 396 throw new Exception(string.Format("ID {0} is not a valid UUID", rawPrincipalId));
391 397
392 CreateUser(UUID.Zero, principalId, firstName, lastName, password, email); 398 CreateUser(UUID.Zero, principalId, firstName, lastName, password, email, model);
393 } 399 }
394 400
395 protected void HandleShowAccount(string module, string[] cmdparams) 401 protected void HandleShowAccount(string module, string[] cmdparams)
@@ -544,7 +550,8 @@ namespace OpenSim.Services.UserAccountService
544 /// <param name="lastName"></param> 550 /// <param name="lastName"></param>
545 /// <param name="password"></param> 551 /// <param name="password"></param>
546 /// <param name="email"></param> 552 /// <param name="email"></param>
547 public UserAccount CreateUser(UUID scopeID, UUID principalID, string firstName, string lastName, string password, string email) 553 /// <param name="model"></param>
554 public UserAccount CreateUser(UUID scopeID, UUID principalID, string firstName, string lastName, string password, string email, string model = "")
548 { 555 {
549 UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); 556 UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
550 if (null == account) 557 if (null == account)
@@ -603,7 +610,12 @@ namespace OpenSim.Services.UserAccountService
603 } 610 }
604 611
605 if (m_CreateDefaultAvatarEntries) 612 if (m_CreateDefaultAvatarEntries)
606 CreateDefaultAppearanceEntries(account.PrincipalID); 613 {
614 if (String.IsNullOrEmpty(model))
615 CreateDefaultAppearanceEntries(account.PrincipalID);
616 else
617 EstablishAppearance(account.PrincipalID, model);
618 }
607 } 619 }
608 620
609 m_log.InfoFormat( 621 m_log.InfoFormat(
@@ -734,6 +746,7 @@ namespace OpenSim.Services.UserAccountService
734 wearables[AvatarWearable.PANTS] = new AvatarWearable(pants.ID, pants.AssetID); 746 wearables[AvatarWearable.PANTS] = new AvatarWearable(pants.ID, pants.AssetID);
735 747
736 AvatarAppearance ap = new AvatarAppearance(); 748 AvatarAppearance ap = new AvatarAppearance();
749 // this loop works, but is questionable
737 for (int i = 0; i < 6; i++) 750 for (int i = 0; i < 6; i++)
738 { 751 {
739 ap.SetWearable(i, wearables[i]); 752 ap.SetWearable(i, wearables[i]);
@@ -742,5 +755,205 @@ namespace OpenSim.Services.UserAccountService
742 m_AvatarService.SetAppearance(principalID, ap); 755 m_AvatarService.SetAppearance(principalID, ap);
743 } 756 }
744 } 757 }
758
759 protected void EstablishAppearance(UUID destinationAgent, string model)
760 {
761 m_log.DebugFormat("[USER ACCOUNT SERVICE]: Establishing new appearance for {0} - {1}",
762 destinationAgent.ToString(), model);
763
764 string[] modelSpecifiers = model.Split();
765 if (modelSpecifiers.Length != 2)
766 {
767 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Invalid model name \'{0}\'. Falling back to Ruth for {1}",
768 model, destinationAgent);
769 CreateDefaultAppearanceEntries(destinationAgent);
770 return;
771 }
772
773 // Does the source model exist?
774 UserAccount modelAccount = GetUserAccount(UUID.Zero, modelSpecifiers[0], modelSpecifiers[1]);
775 if (modelAccount == null)
776 {
777 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Requested model \'{0}\' not found. Falling back to Ruth for {1}",
778 model, destinationAgent);
779 CreateDefaultAppearanceEntries(destinationAgent);
780 return;
781 }
782
783 // Does the source model have an established appearance herself?
784 AvatarAppearance modelAppearance = m_AvatarService.GetAppearance(modelAccount.PrincipalID);
785 if (modelAppearance == null)
786 {
787 m_log.WarnFormat("USER ACCOUNT SERVICE]: Requested model \'{0}\' does not have an established appearance. Falling back to Ruth for {1}",
788 model, destinationAgent);
789 CreateDefaultAppearanceEntries(destinationAgent);
790 return;
791 }
792
793 try
794 {
795 CopyWearablesAndAttachments(destinationAgent, modelAccount.PrincipalID, modelAppearance);
796
797 m_AvatarService.SetAppearance(destinationAgent, modelAppearance);
798 }
799 catch (Exception e)
800 {
801 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring appearance for {0} : {1}",
802 destinationAgent, e.Message);
803 }
804
805 m_log.DebugFormat("[USER ACCOUNT SERVICE]: Finished establishing appearance for {0}",
806 destinationAgent.ToString());
807 }
808
809 /// <summary>
810 /// This method is called by EstablishAppearance to do a copy all inventory items
811 /// worn or attached to the Clothing inventory folder of the receiving avatar.
812 /// In parallel the avatar wearables and attachments are updated.
813 /// </summary>
814 private void CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance)
815 {
816 // Get Clothing folder of receiver
817 InventoryFolderBase destinationFolder = m_InventoryService.GetFolderForType(destination, FolderType.Clothing);
818
819 if (destinationFolder == null)
820 throw new Exception("Cannot locate folder(s)");
821
822 // Missing destination folder? This should *never* be the case
823 if (destinationFolder.Type != (short)FolderType.Clothing)
824 {
825 destinationFolder = new InventoryFolderBase();
826
827 destinationFolder.ID = UUID.Random();
828 destinationFolder.Name = "Clothing";
829 destinationFolder.Owner = destination;
830 destinationFolder.Type = (short)AssetType.Clothing;
831 destinationFolder.ParentID = m_InventoryService.GetRootFolder(destination).ID;
832 destinationFolder.Version = 1;
833 m_InventoryService.AddFolder(destinationFolder); // store base record
834 m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Created folder for destination {0}", source);
835 }
836
837 // Wearables
838 AvatarWearable[] wearables = avatarAppearance.Wearables;
839 AvatarWearable wearable;
840
841 for (int i = 0; i < wearables.Length; i++)
842 {
843 wearable = wearables[i];
844 if (wearable[0].ItemID != UUID.Zero)
845 {
846 // Get inventory item and copy it
847 InventoryItemBase item = m_InventoryService.GetItem(source, wearable[0].ItemID);
848
849 if (item != null)
850 {
851 InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
852 destinationItem.Name = item.Name;
853 destinationItem.Owner = destination;
854 destinationItem.Description = item.Description;
855 destinationItem.InvType = item.InvType;
856 destinationItem.CreatorId = item.CreatorId;
857 destinationItem.CreatorData = item.CreatorData;
858 destinationItem.NextPermissions = item.NextPermissions;
859 destinationItem.CurrentPermissions = item.CurrentPermissions;
860 destinationItem.BasePermissions = item.BasePermissions;
861 destinationItem.EveryOnePermissions = item.EveryOnePermissions;
862 destinationItem.GroupPermissions = item.GroupPermissions;
863 destinationItem.AssetType = item.AssetType;
864 destinationItem.AssetID = item.AssetID;
865 destinationItem.GroupID = item.GroupID;
866 destinationItem.GroupOwned = item.GroupOwned;
867 destinationItem.SalePrice = item.SalePrice;
868 destinationItem.SaleType = item.SaleType;
869 destinationItem.Flags = item.Flags;
870 destinationItem.CreationDate = item.CreationDate;
871 destinationItem.Folder = destinationFolder.ID;
872 ApplyNextOwnerPermissions(destinationItem);
873
874 m_InventoryService.AddItem(destinationItem);
875 m_log.DebugFormat("[USER ACCOUNT SERVICE]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);
876
877 // Wear item
878 AvatarWearable newWearable = new AvatarWearable();
879 newWearable.Wear(destinationItem.ID, wearable[0].AssetID);
880 avatarAppearance.SetWearable(i, newWearable);
881 }
882 else
883 {
884 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring {0} to folder {1}", wearable[0].ItemID, destinationFolder.ID);
885 }
886 }
887 }
888
889 // Attachments
890 List<AvatarAttachment> attachments = avatarAppearance.GetAttachments();
891
892 foreach (AvatarAttachment attachment in attachments)
893 {
894 int attachpoint = attachment.AttachPoint;
895 UUID itemID = attachment.ItemID;
896
897 if (itemID != UUID.Zero)
898 {
899 // Get inventory item and copy it
900 InventoryItemBase item = m_InventoryService.GetItem(source, itemID);
901
902 if (item != null)
903 {
904 InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
905 destinationItem.Name = item.Name;
906 destinationItem.Owner = destination;
907 destinationItem.Description = item.Description;
908 destinationItem.InvType = item.InvType;
909 destinationItem.CreatorId = item.CreatorId;
910 destinationItem.CreatorData = item.CreatorData;
911 destinationItem.NextPermissions = item.NextPermissions;
912 destinationItem.CurrentPermissions = item.CurrentPermissions;
913 destinationItem.BasePermissions = item.BasePermissions;
914 destinationItem.EveryOnePermissions = item.EveryOnePermissions;
915 destinationItem.GroupPermissions = item.GroupPermissions;
916 destinationItem.AssetType = item.AssetType;
917 destinationItem.AssetID = item.AssetID;
918 destinationItem.GroupID = item.GroupID;
919 destinationItem.GroupOwned = item.GroupOwned;
920 destinationItem.SalePrice = item.SalePrice;
921 destinationItem.SaleType = item.SaleType;
922 destinationItem.Flags = item.Flags;
923 destinationItem.CreationDate = item.CreationDate;
924 destinationItem.Folder = destinationFolder.ID;
925 ApplyNextOwnerPermissions(destinationItem);
926
927 m_InventoryService.AddItem(destinationItem);
928 m_log.DebugFormat("[USER ACCOUNT SERVICE]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);
929
930 // Attach item
931 avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
932 m_log.DebugFormat("[USER ACCOUNT SERVICE]: Attached {0}", destinationItem.ID);
933 }
934 else
935 {
936 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID);
937 }
938 }
939 }
940 }
941
942 /// <summary>
943 /// Apply next owner permissions.
944 /// </summary>
945 private void ApplyNextOwnerPermissions(InventoryItemBase item)
946 {
947 if (item.InvType == (int)InventoryType.Object)
948 {
949 uint perms = item.CurrentPermissions;
950 PermissionsUtil.ApplyFoldedPermissions(item.CurrentPermissions, ref perms);
951 item.CurrentPermissions = perms;
952 }
953
954 item.CurrentPermissions &= item.NextPermissions;
955 item.BasePermissions &= item.NextPermissions;
956 item.EveryOnePermissions &= item.NextPermissions;
957 }
745 } 958 }
746} 959}