aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Grid/UserServer.Modules/AvatarCreationModule.cs1088
1 files changed, 544 insertions, 544 deletions
diff --git a/OpenSim/Grid/UserServer.Modules/AvatarCreationModule.cs b/OpenSim/Grid/UserServer.Modules/AvatarCreationModule.cs
index d69ae51..aab7af6 100644
--- a/OpenSim/Grid/UserServer.Modules/AvatarCreationModule.cs
+++ b/OpenSim/Grid/UserServer.Modules/AvatarCreationModule.cs
@@ -1,545 +1,545 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the 12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection; 31using System.Reflection;
32using System.Threading; 32using System.Threading;
33using log4net; 33using log4net;
34using Nwc.XmlRpc; 34using Nwc.XmlRpc;
35using OpenMetaverse; 35using OpenMetaverse;
36using OpenSim.Framework; 36using OpenSim.Framework;
37using OpenSim.Framework.Console; 37using OpenSim.Framework.Console;
38using OpenSim.Framework.Communications; 38using OpenSim.Framework.Communications;
39using OpenSim.Framework.Servers; 39using OpenSim.Framework.Servers;
40using OpenSim.Framework.Servers.HttpServer; 40using OpenSim.Framework.Servers.HttpServer;
41using OpenSim.Grid.Framework; 41using OpenSim.Grid.Framework;
42 42
43 43
44namespace OpenSim.Grid.UserServer.Modules 44namespace OpenSim.Grid.UserServer.Modules
45{ 45{
46 public class AvatarCreationModule 46 public class AvatarCreationModule
47 { 47 {
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 49
50 private UserDataBaseService m_userDataBaseService; 50 private UserDataBaseService m_userDataBaseService;
51 // private BaseHttpServer m_httpServer; 51 // private BaseHttpServer m_httpServer;
52 private UserConfig m_config; 52 private UserConfig m_config;
53 53
54 private string m_inventoryServerUrl; 54 private string m_inventoryServerUrl;
55 private IInterServiceInventoryServices m_inventoryService; 55 private IInterServiceInventoryServices m_inventoryService;
56 56
57 public AvatarCreationModule(UserDataBaseService userDataBaseService, UserConfig config, IInterServiceInventoryServices inventoryService) 57 public AvatarCreationModule(UserDataBaseService userDataBaseService, UserConfig config, IInterServiceInventoryServices inventoryService)
58 { 58 {
59 m_config = config; 59 m_config = config;
60 m_userDataBaseService = userDataBaseService; 60 m_userDataBaseService = userDataBaseService;
61 m_inventoryService = inventoryService; 61 m_inventoryService = inventoryService;
62 m_inventoryServerUrl = config.InventoryUrl.OriginalString; 62 m_inventoryServerUrl = config.InventoryUrl.OriginalString;
63 } 63 }
64 64
65 public void Initialise(IGridServiceCore core) 65 public void Initialise(IGridServiceCore core)
66 { 66 {
67 CommandConsole console; 67 CommandConsole console;
68 if (core.TryGet<CommandConsole>(out console)) 68 if (core.TryGet<CommandConsole>(out console))
69 { 69 {
70 console.Commands.AddCommand("userserver", false, "clone avatar", 70 console.Commands.AddCommand("userserver", false, "clone avatar",
71 "clone avatar <TemplateAvatarFirstName> <TemplateAvatarLastName> <TargetAvatarFirstName> <TargetAvatarLastName>", 71 "clone avatar <TemplateAvatarFirstName> <TemplateAvatarLastName> <TargetAvatarFirstName> <TargetAvatarLastName>",
72 "Clone the template avatar's inventory into a target avatar", RunCommand); 72 "Clone the template avatar's inventory into a target avatar", RunCommand);
73 } 73 }
74 } 74 }
75 75
76 public void PostInitialise() 76 public void PostInitialise()
77 { 77 {
78 78
79 } 79 }
80 80
81 public void RegisterHandlers(BaseHttpServer httpServer) 81 public void RegisterHandlers(BaseHttpServer httpServer)
82 { 82 {
83 } 83 }
84 84
85 public void RunCommand(string module, string[] cmd) 85 public void RunCommand(string module, string[] cmd)
86 { 86 {
87 if ((cmd.Length == 6) && (cmd[0] == "clone") && (cmd[1] == "avatar")) 87 if ((cmd.Length == 6) && (cmd[0] == "clone") && (cmd[1] == "avatar"))
88 { 88 {
89 try 89 try
90 { 90 {
91 string tFirst = cmd[2]; 91 string tFirst = cmd[2];
92 string tLast = cmd[3]; 92 string tLast = cmd[3];
93 93
94 string nFirst = cmd[4]; 94 string nFirst = cmd[4];
95 string nLast = cmd[5]; 95 string nLast = cmd[5];
96 96
97 UserProfileData templateAvatar = m_userDataBaseService.GetUserProfile(tFirst, tLast); 97 UserProfileData templateAvatar = m_userDataBaseService.GetUserProfile(tFirst, tLast);
98 UserProfileData newAvatar = m_userDataBaseService.GetUserProfile(nFirst, nLast); 98 UserProfileData newAvatar = m_userDataBaseService.GetUserProfile(nFirst, nLast);
99 99
100 if (templateAvatar == null) 100 if (templateAvatar == null)
101 { 101 {
102 m_log.ErrorFormat("[AvatarAppearance] Clone Avatar: Could not find template avatar {0} , {1}", tFirst, tLast); 102 m_log.ErrorFormat("[AvatarAppearance] Clone Avatar: Could not find template avatar {0} , {1}", tFirst, tLast);
103 return; 103 return;
104 } 104 }
105 105
106 if (newAvatar == null) 106 if (newAvatar == null)
107 { 107 {
108 m_log.ErrorFormat("[AvatarAppearance] Clone Avatar: Could not find target avatar {0} , {1}", nFirst, nLast); 108 m_log.ErrorFormat("[AvatarAppearance] Clone Avatar: Could not find target avatar {0} , {1}", nFirst, nLast);
109 return; 109 return;
110 } 110 }
111 Guid avatar = newAvatar.ID.Guid; 111 Guid avatar = newAvatar.ID.Guid;
112 Guid template = templateAvatar.ID.Guid; 112 Guid template = templateAvatar.ID.Guid;
113 CloneAvatar(avatar, template, true, true); 113 CloneAvatar(avatar, template, true, true);
114 114
115 } 115 }
116 catch (Exception e) 116 catch (Exception e)
117 { 117 {
118 m_log.Error("Error: " + e.ToString()); 118 m_log.Error("Error: " + e.ToString());
119 } 119 }
120 } 120 }
121 } 121 }
122 #region Avatar Appearance Creation 122 #region Avatar Appearance Creation
123 123
124 public bool CloneAvatar(Guid avatarID, Guid templateID, bool modifyPermissions, bool removeTargetsClothes) 124 public bool CloneAvatar(Guid avatarID, Guid templateID, bool modifyPermissions, bool removeTargetsClothes)
125 { 125 {
126 m_log.InfoFormat("[AvatarAppearance] Starting to clone avatar {0} inventory to avatar {1}", templateID.ToString(), avatarID.ToString()); 126 m_log.InfoFormat("[AvatarAppearance] Starting to clone avatar {0} inventory to avatar {1}", templateID.ToString(), avatarID.ToString());
127 Guid bodyFolder = Guid.Empty; 127 Guid bodyFolder = Guid.Empty;
128 Guid clothesFolder = Guid.Empty; 128 Guid clothesFolder = Guid.Empty;
129 bool success = false; 129 bool success = false;
130 130
131 UUID avID = new UUID(avatarID); 131 UUID avID = new UUID(avatarID);
132 List<InventoryFolderBase> avatarInventory = m_inventoryService.GetInventorySkeleton(avID); 132 List<InventoryFolderBase> avatarInventory = m_inventoryService.GetInventorySkeleton(avID);
133 if ((avatarInventory == null) || (avatarInventory.Count == 0)) 133 if ((avatarInventory == null) || (avatarInventory.Count == 0))
134 { 134 {
135 m_log.InfoFormat("[AvatarAppearance] No inventory found for user {0} , so creating it", avID.ToString()); 135 m_log.InfoFormat("[AvatarAppearance] No inventory found for user {0} , so creating it", avID.ToString());
136 m_inventoryService.CreateNewUserInventory(avID); 136 m_inventoryService.CreateNewUserInventory(avID);
137 Thread.Sleep(5000); 137 Thread.Sleep(5000);
138 avatarInventory = m_inventoryService.GetInventorySkeleton(avID); 138 avatarInventory = m_inventoryService.GetInventorySkeleton(avID);
139 } 139 }
140 140
141 if ((avatarInventory != null) && (avatarInventory.Count > 0)) 141 if ((avatarInventory != null) && (avatarInventory.Count > 0))
142 { 142 {
143 UUID tempOwnID = new UUID(templateID); 143 UUID tempOwnID = new UUID(templateID);
144 AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(tempOwnID); 144 AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(tempOwnID);
145 145
146 if (removeTargetsClothes) 146 if (removeTargetsClothes)
147 { 147 {
148 //remove clothes and attachments from target avatar so that the end result isn't a merger of its existing clothes 148 //remove clothes and attachments from target avatar so that the end result isn't a merger of its existing clothes
149 // and the clothes from the template avatar. 149 // and the clothes from the template avatar.
150 RemoveClothesAndAttachments(avID); 150 RemoveClothesAndAttachments(avID);
151 } 151 }
152 152
153 List<InventoryFolderBase> templateInventory = m_inventoryService.GetInventorySkeleton(tempOwnID); 153 List<InventoryFolderBase> templateInventory = m_inventoryService.GetInventorySkeleton(tempOwnID);
154 if ((templateInventory != null) && (templateInventory.Count != 0)) 154 if ((templateInventory != null) && (templateInventory.Count != 0))
155 { 155 {
156 for (int i = 0; i < templateInventory.Count; i++) 156 for (int i = 0; i < templateInventory.Count; i++)
157 { 157 {
158 if (templateInventory[i].ParentID == UUID.Zero) 158 if (templateInventory[i].ParentID == UUID.Zero)
159 { 159 {
160 success = CloneFolder(avatarInventory, avID, UUID.Zero, appearance, templateInventory[i], templateInventory, modifyPermissions); 160 success = CloneFolder(avatarInventory, avID, UUID.Zero, appearance, templateInventory[i], templateInventory, modifyPermissions);
161 break; 161 break;
162 } 162 }
163 } 163 }
164 } 164 }
165 else 165 else
166 { 166 {
167 m_log.InfoFormat("[AvatarAppearance] Failed to find the template owner's {0} inventory", tempOwnID); 167 m_log.InfoFormat("[AvatarAppearance] Failed to find the template owner's {0} inventory", tempOwnID);
168 } 168 }
169 } 169 }
170 m_log.InfoFormat("[AvatarAppearance] finished cloning avatar with result: {0}", success); 170 m_log.InfoFormat("[AvatarAppearance] finished cloning avatar with result: {0}", success);
171 return success; 171 return success;
172 } 172 }
173 173
174 private bool CloneFolder(List<InventoryFolderBase> avatarInventory, UUID avID, UUID parentFolder, AvatarAppearance appearance, InventoryFolderBase templateFolder, List<InventoryFolderBase> templateFolders, bool modifyPermissions) 174 private bool CloneFolder(List<InventoryFolderBase> avatarInventory, UUID avID, UUID parentFolder, AvatarAppearance appearance, InventoryFolderBase templateFolder, List<InventoryFolderBase> templateFolders, bool modifyPermissions)
175 { 175 {
176 bool success = false; 176 bool success = false;
177 UUID templateFolderId = templateFolder.ID; 177 UUID templateFolderId = templateFolder.ID;
178 if (templateFolderId != UUID.Zero) 178 if (templateFolderId != UUID.Zero)
179 { 179 {
180 InventoryFolderBase toFolder = FindFolder(templateFolder.Name, parentFolder.Guid, avatarInventory); 180 InventoryFolderBase toFolder = FindFolder(templateFolder.Name, parentFolder.Guid, avatarInventory);
181 if (toFolder == null) 181 if (toFolder == null)
182 { 182 {
183 //create new folder 183 //create new folder
184 toFolder = new InventoryFolderBase(); 184 toFolder = new InventoryFolderBase();
185 toFolder.ID = UUID.Random(); 185 toFolder.ID = UUID.Random();
186 toFolder.Name = templateFolder.Name; 186 toFolder.Name = templateFolder.Name;
187 toFolder.Owner = avID; 187 toFolder.Owner = avID;
188 toFolder.Type = templateFolder.Type; 188 toFolder.Type = templateFolder.Type;
189 toFolder.Version = 1; 189 toFolder.Version = 1;
190 toFolder.ParentID = parentFolder; 190 toFolder.ParentID = parentFolder;
191 if (!SynchronousRestObjectRequester.MakeRequest<InventoryFolderBase, bool>( 191 if (!SynchronousRestObjectRequester.MakeRequest<InventoryFolderBase, bool>(
192 "POST", m_inventoryServerUrl + "CreateFolder/", toFolder)) 192 "POST", m_inventoryServerUrl + "CreateFolder/", toFolder))
193 { 193 {
194 m_log.InfoFormat("[AvatarApperance] Couldn't make new folder {0} in users inventory", toFolder.Name); 194 m_log.InfoFormat("[AvatarApperance] Couldn't make new folder {0} in users inventory", toFolder.Name);
195 return false; 195 return false;
196 } 196 }
197 else 197 else
198 { 198 {
199 // m_log.InfoFormat("made new folder {0} in users inventory", toFolder.Name); 199 // m_log.InfoFormat("made new folder {0} in users inventory", toFolder.Name);
200 } 200 }
201 } 201 }
202 202
203 List<InventoryItemBase> templateItems = SynchronousRestObjectRequester.MakeRequest<Guid, List<InventoryItemBase>>( 203 List<InventoryItemBase> templateItems = SynchronousRestObjectRequester.MakeRequest<Guid, List<InventoryItemBase>>(
204 "POST", m_inventoryServerUrl + "GetItems/", templateFolderId.Guid); 204 "POST", m_inventoryServerUrl + "GetItems/", templateFolderId.Guid);
205 if ((templateItems != null) && (templateItems.Count > 0)) 205 if ((templateItems != null) && (templateItems.Count > 0))
206 { 206 {
207 List<ClothesAttachment> wornClothes = new List<ClothesAttachment>(); 207 List<ClothesAttachment> wornClothes = new List<ClothesAttachment>();
208 List<ClothesAttachment> attachedItems = new List<ClothesAttachment>(); 208 List<ClothesAttachment> attachedItems = new List<ClothesAttachment>();
209 209
210 foreach (InventoryItemBase item in templateItems) 210 foreach (InventoryItemBase item in templateItems)
211 { 211 {
212 212
213 UUID clonedItemId = CloneInventoryItem(avID, toFolder.ID, item, modifyPermissions); 213 UUID clonedItemId = CloneInventoryItem(avID, toFolder.ID, item, modifyPermissions);
214 if (clonedItemId != UUID.Zero) 214 if (clonedItemId != UUID.Zero)
215 { 215 {
216 int appearanceType = ItemIsPartOfAppearance(item, appearance); 216 int appearanceType = ItemIsPartOfAppearance(item, appearance);
217 if (appearanceType >= 0) 217 if (appearanceType >= 0)
218 { 218 {
219 // UpdateAvatarAppearance(avID, appearanceType, clonedItemId, item.AssetID); 219 // UpdateAvatarAppearance(avID, appearanceType, clonedItemId, item.AssetID);
220 wornClothes.Add(new ClothesAttachment(appearanceType, clonedItemId, item.AssetID)); 220 wornClothes.Add(new ClothesAttachment(appearanceType, clonedItemId, item.AssetID));
221 } 221 }
222 222
223 if (appearance != null) 223 if (appearance != null)
224 { 224 {
225 int attachment = appearance.GetAttachpoint(item.ID); 225 int attachment = appearance.GetAttachpoint(item.ID);
226 if (attachment > 0) 226 if (attachment > 0)
227 { 227 {
228 //UpdateAvatarAttachment(avID, attachment, clonedItemId, item.AssetID); 228 //UpdateAvatarAttachment(avID, attachment, clonedItemId, item.AssetID);
229 attachedItems.Add(new ClothesAttachment(attachment, clonedItemId, item.AssetID)); 229 attachedItems.Add(new ClothesAttachment(attachment, clonedItemId, item.AssetID));
230 } 230 }
231 } 231 }
232 success = true; 232 success = true;
233 } 233 }
234 } 234 }
235 235
236 if ((wornClothes.Count > 0) || (attachedItems.Count > 0)) 236 if ((wornClothes.Count > 0) || (attachedItems.Count > 0))
237 { 237 {
238 //Update the worn clothes and attachments 238 //Update the worn clothes and attachments
239 AvatarAppearance targetAppearance = GetAppearance(avID); 239 AvatarAppearance targetAppearance = GetAppearance(avID);
240 if (targetAppearance != null) 240 if (targetAppearance != null)
241 { 241 {
242 foreach (ClothesAttachment wornItem in wornClothes) 242 foreach (ClothesAttachment wornItem in wornClothes)
243 { 243 {
244 targetAppearance.Wearables[wornItem.Type].AssetID = wornItem.AssetID; 244 targetAppearance.Wearables[wornItem.Type].AssetID = wornItem.AssetID;
245 targetAppearance.Wearables[wornItem.Type].ItemID = wornItem.ItemID; 245 targetAppearance.Wearables[wornItem.Type].ItemID = wornItem.ItemID;
246 } 246 }
247 247
248 foreach (ClothesAttachment wornItem in attachedItems) 248 foreach (ClothesAttachment wornItem in attachedItems)
249 { 249 {
250 targetAppearance.SetAttachment(wornItem.Type, wornItem.ItemID, wornItem.AssetID); 250 targetAppearance.SetAttachment(wornItem.Type, wornItem.ItemID, wornItem.AssetID);
251 } 251 }
252 252
253 m_userDataBaseService.UpdateUserAppearance(avID, targetAppearance); 253 m_userDataBaseService.UpdateUserAppearance(avID, targetAppearance);
254 wornClothes.Clear(); 254 wornClothes.Clear();
255 attachedItems.Clear(); 255 attachedItems.Clear();
256 } 256 }
257 } 257 }
258 } 258 }
259 259
260 List<InventoryFolderBase> subFolders = FindSubFolders(templateFolder.ID.Guid, templateFolders); 260 List<InventoryFolderBase> subFolders = FindSubFolders(templateFolder.ID.Guid, templateFolders);
261 foreach (InventoryFolderBase subFolder in subFolders) 261 foreach (InventoryFolderBase subFolder in subFolders)
262 { 262 {
263 if (subFolder.Name.ToLower() != "trash") 263 if (subFolder.Name.ToLower() != "trash")
264 { 264 {
265 success = CloneFolder(avatarInventory, avID, toFolder.ID, appearance, subFolder, templateFolders, modifyPermissions); 265 success = CloneFolder(avatarInventory, avID, toFolder.ID, appearance, subFolder, templateFolders, modifyPermissions);
266 } 266 }
267 } 267 }
268 } 268 }
269 else 269 else
270 { 270 {
271 m_log.Info("[AvatarAppearance] Failed to find the template folder"); 271 m_log.Info("[AvatarAppearance] Failed to find the template folder");
272 } 272 }
273 return success; 273 return success;
274 } 274 }
275 275
276 private UUID CloneInventoryItem(UUID avatarID, UUID avatarFolder, InventoryItemBase item, bool modifyPerms) 276 private UUID CloneInventoryItem(UUID avatarID, UUID avatarFolder, InventoryItemBase item, bool modifyPerms)
277 { 277 {
278 if (avatarFolder != UUID.Zero) 278 if (avatarFolder != UUID.Zero)
279 { 279 {
280 InventoryItemBase clonedItem = new InventoryItemBase(); 280 InventoryItemBase clonedItem = new InventoryItemBase();
281 clonedItem.Owner = avatarID; 281 clonedItem.Owner = avatarID;
282 clonedItem.AssetID = item.AssetID; 282 clonedItem.AssetID = item.AssetID;
283 clonedItem.AssetType = item.AssetType; 283 clonedItem.AssetType = item.AssetType;
284 clonedItem.BasePermissions = item.BasePermissions; 284 clonedItem.BasePermissions = item.BasePermissions;
285 clonedItem.CreationDate = item.CreationDate; 285 clonedItem.CreationDate = item.CreationDate;
286 clonedItem.CreatorId = item.CreatorId; 286 clonedItem.CreatorId = item.CreatorId;
287 clonedItem.CreatorIdAsUuid = item.CreatorIdAsUuid; 287 clonedItem.CreatorIdAsUuid = item.CreatorIdAsUuid;
288 clonedItem.CurrentPermissions = item.CurrentPermissions; 288 clonedItem.CurrentPermissions = item.CurrentPermissions;
289 clonedItem.Description = item.Description; 289 clonedItem.Description = item.Description;
290 clonedItem.EveryOnePermissions = item.EveryOnePermissions; 290 clonedItem.EveryOnePermissions = item.EveryOnePermissions;
291 clonedItem.Flags = item.Flags; 291 clonedItem.Flags = item.Flags;
292 clonedItem.Folder = avatarFolder; 292 clonedItem.Folder = avatarFolder;
293 clonedItem.GroupID = item.GroupID; 293 clonedItem.GroupID = item.GroupID;
294 clonedItem.GroupOwned = item.GroupOwned; 294 clonedItem.GroupOwned = item.GroupOwned;
295 clonedItem.GroupPermissions = item.GroupPermissions; 295 clonedItem.GroupPermissions = item.GroupPermissions;
296 clonedItem.ID = UUID.Random(); 296 clonedItem.ID = UUID.Random();
297 clonedItem.InvType = item.InvType; 297 clonedItem.InvType = item.InvType;
298 clonedItem.Name = item.Name; 298 clonedItem.Name = item.Name;
299 clonedItem.NextPermissions = item.NextPermissions; 299 clonedItem.NextPermissions = item.NextPermissions;
300 clonedItem.SalePrice = item.SalePrice; 300 clonedItem.SalePrice = item.SalePrice;
301 clonedItem.SaleType = item.SaleType; 301 clonedItem.SaleType = item.SaleType;
302 302
303 if (modifyPerms) 303 if (modifyPerms)
304 { 304 {
305 ModifyPermissions(ref clonedItem); 305 ModifyPermissions(ref clonedItem);
306 } 306 }
307 307
308 SynchronousRestObjectRequester.MakeRequest<InventoryItemBase, bool>( 308 SynchronousRestObjectRequester.MakeRequest<InventoryItemBase, bool>(
309 "POST", m_inventoryServerUrl + "AddNewItem/", clonedItem); 309 "POST", m_inventoryServerUrl + "AddNewItem/", clonedItem);
310 310
311 return clonedItem.ID; 311 return clonedItem.ID;
312 } 312 }
313 313
314 return UUID.Zero; 314 return UUID.Zero;
315 } 315 }
316 316
317 private void UpdateAvatarAppearance(UUID avatarID, int wearableType, UUID itemID, UUID assetID) 317 private void UpdateAvatarAppearance(UUID avatarID, int wearableType, UUID itemID, UUID assetID)
318 { 318 {
319 AvatarAppearance appearance = GetAppearance(avatarID); 319 AvatarAppearance appearance = GetAppearance(avatarID);
320 320
321 appearance.Wearables[wearableType].AssetID = assetID; 321 appearance.Wearables[wearableType].AssetID = assetID;
322 appearance.Wearables[wearableType].ItemID = itemID; 322 appearance.Wearables[wearableType].ItemID = itemID;
323 323
324 m_userDataBaseService.UpdateUserAppearance(avatarID, appearance); 324 m_userDataBaseService.UpdateUserAppearance(avatarID, appearance);
325 } 325 }
326 326
327 327
328 private void UpdateAvatarAttachment(UUID avatarID, int attachmentPoint, UUID itemID, UUID assetID) 328 private void UpdateAvatarAttachment(UUID avatarID, int attachmentPoint, UUID itemID, UUID assetID)
329 { 329 {
330 AvatarAppearance appearance = GetAppearance(avatarID); 330 AvatarAppearance appearance = GetAppearance(avatarID);
331 331
332 appearance.SetAttachment(attachmentPoint, itemID, assetID); 332 appearance.SetAttachment(attachmentPoint, itemID, assetID);
333 333
334 m_userDataBaseService.UpdateUserAppearance(avatarID, appearance); 334 m_userDataBaseService.UpdateUserAppearance(avatarID, appearance);
335 } 335 }
336 336
337 private void RemoveClothesAndAttachments(UUID avatarID) 337 private void RemoveClothesAndAttachments(UUID avatarID)
338 { 338 {
339 AvatarAppearance appearance = GetAppearance(avatarID); 339 AvatarAppearance appearance = GetAppearance(avatarID);
340 340
341 appearance.ClearWearables(); 341 appearance.ClearWearables();
342 appearance.ClearAttachments(); 342 appearance.ClearAttachments();
343 m_userDataBaseService.UpdateUserAppearance(avatarID, appearance); 343 m_userDataBaseService.UpdateUserAppearance(avatarID, appearance);
344 344
345 } 345 }
346 346
347 private AvatarAppearance GetAppearance(UUID avatarID) 347 private AvatarAppearance GetAppearance(UUID avatarID)
348 { 348 {
349 AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID); 349 AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID);
350 if (appearance == null) 350 if (appearance == null)
351 { 351 {
352 appearance = CreateDefaultAppearance(avatarID); 352 appearance = CreateDefaultAppearance(avatarID);
353 } 353 }
354 return appearance; 354 return appearance;
355 } 355 }
356 356
357 private UUID FindFolderID(string name, List<InventoryFolderBase> folders) 357 private UUID FindFolderID(string name, List<InventoryFolderBase> folders)
358 { 358 {
359 foreach (InventoryFolderBase folder in folders) 359 foreach (InventoryFolderBase folder in folders)
360 { 360 {
361 if (folder.Name == name) 361 if (folder.Name == name)
362 { 362 {
363 return folder.ID; 363 return folder.ID;
364 } 364 }
365 } 365 }
366 return UUID.Zero; 366 return UUID.Zero;
367 } 367 }
368 368
369 private InventoryFolderBase FindFolder(string name, List<InventoryFolderBase> folders) 369 private InventoryFolderBase FindFolder(string name, List<InventoryFolderBase> folders)
370 { 370 {
371 foreach (InventoryFolderBase folder in folders) 371 foreach (InventoryFolderBase folder in folders)
372 { 372 {
373 if (folder.Name == name) 373 if (folder.Name == name)
374 { 374 {
375 return folder; 375 return folder;
376 } 376 }
377 } 377 }
378 return null; 378 return null;
379 } 379 }
380 380
381 private InventoryFolderBase FindFolder(string name, Guid parentFolderID, List<InventoryFolderBase> folders) 381 private InventoryFolderBase FindFolder(string name, Guid parentFolderID, List<InventoryFolderBase> folders)
382 { 382 {
383 foreach (InventoryFolderBase folder in folders) 383 foreach (InventoryFolderBase folder in folders)
384 { 384 {
385 if ((folder.Name == name) && (folder.ParentID.Guid == parentFolderID)) 385 if ((folder.Name == name) && (folder.ParentID.Guid == parentFolderID))
386 { 386 {
387 return folder; 387 return folder;
388 } 388 }
389 } 389 }
390 return null; 390 return null;
391 } 391 }
392 392
393 private InventoryItemBase GetItem(string itemName, List<InventoryItemBase> items) 393 private InventoryItemBase GetItem(string itemName, List<InventoryItemBase> items)
394 { 394 {
395 foreach (InventoryItemBase item in items) 395 foreach (InventoryItemBase item in items)
396 { 396 {
397 if (item.Name.ToLower() == itemName.ToLower()) 397 if (item.Name.ToLower() == itemName.ToLower())
398 { 398 {
399 return item; 399 return item;
400 } 400 }
401 } 401 }
402 return null; 402 return null;
403 } 403 }
404 404
405 private List<InventoryFolderBase> FindSubFolders(Guid parentFolderID, List<InventoryFolderBase> folders) 405 private List<InventoryFolderBase> FindSubFolders(Guid parentFolderID, List<InventoryFolderBase> folders)
406 { 406 {
407 List<InventoryFolderBase> subFolders = new List<InventoryFolderBase>(); 407 List<InventoryFolderBase> subFolders = new List<InventoryFolderBase>();
408 foreach (InventoryFolderBase folder in folders) 408 foreach (InventoryFolderBase folder in folders)
409 { 409 {
410 if (folder.ParentID.Guid == parentFolderID) 410 if (folder.ParentID.Guid == parentFolderID)
411 { 411 {
412 subFolders.Add(folder); 412 subFolders.Add(folder);
413 } 413 }
414 } 414 }
415 return subFolders; 415 return subFolders;
416 } 416 }
417 417
418 protected virtual void ModifyPermissions(ref InventoryItemBase item) 418 protected virtual void ModifyPermissions(ref InventoryItemBase item)
419 { 419 {
420 // Propagate Permissions 420 // Propagate Permissions
421 item.BasePermissions = item.BasePermissions & item.NextPermissions; 421 item.BasePermissions = item.BasePermissions & item.NextPermissions;
422 item.CurrentPermissions = item.BasePermissions; 422 item.CurrentPermissions = item.BasePermissions;
423 item.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions; 423 item.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
424 item.GroupPermissions = item.GroupPermissions & item.NextPermissions; 424 item.GroupPermissions = item.GroupPermissions & item.NextPermissions;
425 425
426 } 426 }
427 427
428 private AvatarAppearance CreateDefaultAppearance(UUID avatarId) 428 private AvatarAppearance CreateDefaultAppearance(UUID avatarId)
429 { 429 {
430 AvatarAppearance appearance = null; 430 AvatarAppearance appearance = null;
431 AvatarWearable[] wearables; 431 AvatarWearable[] wearables;
432 byte[] visualParams; 432 byte[] visualParams;
433 GetDefaultAvatarAppearance(out wearables, out visualParams); 433 GetDefaultAvatarAppearance(out wearables, out visualParams);
434 appearance = new AvatarAppearance(avatarId, wearables, visualParams); 434 appearance = new AvatarAppearance(avatarId, wearables, visualParams);
435 435
436 return appearance; 436 return appearance;
437 } 437 }
438 438
439 private static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams) 439 private static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams)
440 { 440 {
441 visualParams = GetDefaultVisualParams(); 441 visualParams = GetDefaultVisualParams();
442 wearables = AvatarWearable.DefaultWearables; 442 wearables = AvatarWearable.DefaultWearables;
443 } 443 }
444 444
445 private static byte[] GetDefaultVisualParams() 445 private static byte[] GetDefaultVisualParams()
446 { 446 {
447 byte[] visualParams; 447 byte[] visualParams;
448 visualParams = new byte[218]; 448 visualParams = new byte[218];
449 for (int i = 0; i < 218; i++) 449 for (int i = 0; i < 218; i++)
450 { 450 {
451 visualParams[i] = 100; 451 visualParams[i] = 100;
452 } 452 }
453 return visualParams; 453 return visualParams;
454 } 454 }
455 455
456 private int ItemIsPartOfAppearance(InventoryItemBase item, AvatarAppearance appearance) 456 private int ItemIsPartOfAppearance(InventoryItemBase item, AvatarAppearance appearance)
457 { 457 {
458 if (appearance != null) 458 if (appearance != null)
459 { 459 {
460 if (appearance.BodyItem == item.ID) 460 if (appearance.BodyItem == item.ID)
461 return (int)WearableType.Shape; 461 return (int)WearableType.Shape;
462 462
463 if (appearance.EyesItem == item.ID) 463 if (appearance.EyesItem == item.ID)
464 return (int)WearableType.Eyes; 464 return (int)WearableType.Eyes;
465 465
466 if (appearance.GlovesItem == item.ID) 466 if (appearance.GlovesItem == item.ID)
467 return (int)WearableType.Gloves; 467 return (int)WearableType.Gloves;
468 468
469 if (appearance.HairItem == item.ID) 469 if (appearance.HairItem == item.ID)
470 return (int)WearableType.Hair; 470 return (int)WearableType.Hair;
471 471
472 if (appearance.JacketItem == item.ID) 472 if (appearance.JacketItem == item.ID)
473 return (int)WearableType.Jacket; 473 return (int)WearableType.Jacket;
474 474
475 if (appearance.PantsItem == item.ID) 475 if (appearance.PantsItem == item.ID)
476 return (int)WearableType.Pants; 476 return (int)WearableType.Pants;
477 477
478 if (appearance.ShirtItem == item.ID) 478 if (appearance.ShirtItem == item.ID)
479 return (int)WearableType.Shirt; 479 return (int)WearableType.Shirt;
480 480
481 if (appearance.ShoesItem == item.ID) 481 if (appearance.ShoesItem == item.ID)
482 return (int)WearableType.Shoes; 482 return (int)WearableType.Shoes;
483 483
484 if (appearance.SkinItem == item.ID) 484 if (appearance.SkinItem == item.ID)
485 return (int)WearableType.Skin; 485 return (int)WearableType.Skin;
486 486
487 if (appearance.SkirtItem == item.ID) 487 if (appearance.SkirtItem == item.ID)
488 return (int)WearableType.Skirt; 488 return (int)WearableType.Skirt;
489 489
490 if (appearance.SocksItem == item.ID) 490 if (appearance.SocksItem == item.ID)
491 return (int)WearableType.Socks; 491 return (int)WearableType.Socks;
492 492
493 if (appearance.UnderPantsItem == item.ID) 493 if (appearance.UnderPantsItem == item.ID)
494 return (int)WearableType.Underpants; 494 return (int)WearableType.Underpants;
495 495
496 if (appearance.UnderShirtItem == item.ID) 496 if (appearance.UnderShirtItem == item.ID)
497 return (int)WearableType.Undershirt; 497 return (int)WearableType.Undershirt;
498 } 498 }
499 return -1; 499 return -1;
500 } 500 }
501 #endregion 501 #endregion
502 502
503 public enum PermissionMask 503 public enum PermissionMask
504 { 504 {
505 None = 0, 505 None = 0,
506 Transfer = 8192, 506 Transfer = 8192,
507 Modify = 16384, 507 Modify = 16384,
508 Copy = 32768, 508 Copy = 32768,
509 Move = 524288, 509 Move = 524288,
510 Damage = 1048576, 510 Damage = 1048576,
511 All = 2147483647, 511 All = 2147483647,
512 } 512 }
513 513
514 public enum WearableType 514 public enum WearableType
515 { 515 {
516 Shape = 0, 516 Shape = 0,
517 Skin = 1, 517 Skin = 1,
518 Hair = 2, 518 Hair = 2,
519 Eyes = 3, 519 Eyes = 3,
520 Shirt = 4, 520 Shirt = 4,
521 Pants = 5, 521 Pants = 5,
522 Shoes = 6, 522 Shoes = 6,
523 Socks = 7, 523 Socks = 7,
524 Jacket = 8, 524 Jacket = 8,
525 Gloves = 9, 525 Gloves = 9,
526 Undershirt = 10, 526 Undershirt = 10,
527 Underpants = 11, 527 Underpants = 11,
528 Skirt = 12, 528 Skirt = 12,
529 } 529 }
530 530
531 public class ClothesAttachment 531 public class ClothesAttachment
532 { 532 {
533 public int Type; 533 public int Type;
534 public UUID ItemID; 534 public UUID ItemID;
535 public UUID AssetID; 535 public UUID AssetID;
536 536
537 public ClothesAttachment(int type, UUID itemID, UUID assetID) 537 public ClothesAttachment(int type, UUID itemID, UUID assetID)
538 { 538 {
539 Type = type; 539 Type = type;
540 ItemID = itemID; 540 ItemID = itemID;
541 AssetID = assetID; 541 AssetID = assetID;
542 } 542 }
543 } 543 }
544 } 544 }
545} \ No newline at end of file 545} \ No newline at end of file