diff options
author | Jeff Ames | 2009-05-31 16:26:18 +0000 |
---|---|---|
committer | Jeff Ames | 2009-05-31 16:26:18 +0000 |
commit | db2c4ab94cc40bf16910806fd4fe0d9a2b7cbd8f (patch) | |
tree | 59640d71ec7a7dcae97e261ba3197df0d5e688e3 /OpenSim/Grid/UserServer.Modules | |
parent | * Adds MRM scripting commands, World.Objects.Create(Vector3 position) and Wor... (diff) | |
download | opensim-SC-db2c4ab94cc40bf16910806fd4fe0d9a2b7cbd8f.zip opensim-SC-db2c4ab94cc40bf16910806fd4fe0d9a2b7cbd8f.tar.gz opensim-SC-db2c4ab94cc40bf16910806fd4fe0d9a2b7cbd8f.tar.bz2 opensim-SC-db2c4ab94cc40bf16910806fd4fe0d9a2b7cbd8f.tar.xz |
Update svn properties.
Diffstat (limited to 'OpenSim/Grid/UserServer.Modules')
-rw-r--r-- | OpenSim/Grid/UserServer.Modules/AvatarCreationModule.cs | 1056 |
1 files changed, 528 insertions, 528 deletions
diff --git a/OpenSim/Grid/UserServer.Modules/AvatarCreationModule.cs b/OpenSim/Grid/UserServer.Modules/AvatarCreationModule.cs index 644dce7..7b4e04b 100644 --- a/OpenSim/Grid/UserServer.Modules/AvatarCreationModule.cs +++ b/OpenSim/Grid/UserServer.Modules/AvatarCreationModule.cs | |||
@@ -1,528 +1,528 @@ | |||
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 OpenSim Project nor the | 12 | * * Neither the name of the OpenSim 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 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Threading; | 32 | using System.Threading; |
33 | using log4net; | 33 | using log4net; |
34 | using Nwc.XmlRpc; | 34 | using Nwc.XmlRpc; |
35 | using OpenMetaverse; | 35 | using OpenMetaverse; |
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenSim.Framework.Console; | 37 | using OpenSim.Framework.Console; |
38 | using OpenSim.Framework.Communications; | 38 | using OpenSim.Framework.Communications; |
39 | using OpenSim.Framework.Servers; | 39 | using OpenSim.Framework.Servers; |
40 | using OpenSim.Framework.Servers.HttpServer; | 40 | using OpenSim.Framework.Servers.HttpServer; |
41 | using OpenSim.Grid.Framework; | 41 | using OpenSim.Grid.Framework; |
42 | 42 | ||
43 | 43 | ||
44 | namespace OpenSim.Grid.UserServer.Modules | 44 | namespace 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 inventory into a target avatar", RunCommand); | 72 | "Clone the template avatar 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 merge of its existing clothes | 148 | //remove clothes and attachments from target avatar so that the end result isn't a merge 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 | foreach (InventoryItemBase item in templateItems) | 207 | foreach (InventoryItemBase item in templateItems) |
208 | { | 208 | { |
209 | 209 | ||
210 | UUID clonedItemId = CloneInventoryItem(avID, toFolder.ID, item, modifyPermissions); | 210 | UUID clonedItemId = CloneInventoryItem(avID, toFolder.ID, item, modifyPermissions); |
211 | if (clonedItemId != UUID.Zero) | 211 | if (clonedItemId != UUID.Zero) |
212 | { | 212 | { |
213 | int appearanceType = ItemIsPartOfAppearance(item, appearance); | 213 | int appearanceType = ItemIsPartOfAppearance(item, appearance); |
214 | if (appearanceType >= 0) | 214 | if (appearanceType >= 0) |
215 | { | 215 | { |
216 | UpdateAvatarAppearance(avID, appearanceType, clonedItemId, item.AssetID); | 216 | UpdateAvatarAppearance(avID, appearanceType, clonedItemId, item.AssetID); |
217 | } | 217 | } |
218 | 218 | ||
219 | if (appearance != null) | 219 | if (appearance != null) |
220 | { | 220 | { |
221 | int attachment = appearance.GetAttachpoint(item.ID); | 221 | int attachment = appearance.GetAttachpoint(item.ID); |
222 | if (attachment > 0) | 222 | if (attachment > 0) |
223 | { | 223 | { |
224 | UpdateAvatarAttachment(avID, attachment, clonedItemId, item.AssetID); | 224 | UpdateAvatarAttachment(avID, attachment, clonedItemId, item.AssetID); |
225 | } | 225 | } |
226 | } | 226 | } |
227 | success = true; | 227 | success = true; |
228 | } | 228 | } |
229 | } | 229 | } |
230 | } | 230 | } |
231 | 231 | ||
232 | List<InventoryFolderBase> subFolders = FindSubFolders(templateFolder.ID.Guid, templateFolders); | 232 | List<InventoryFolderBase> subFolders = FindSubFolders(templateFolder.ID.Guid, templateFolders); |
233 | foreach (InventoryFolderBase subFolder in subFolders) | 233 | foreach (InventoryFolderBase subFolder in subFolders) |
234 | { | 234 | { |
235 | if (subFolder.Name.ToLower() != "trash") | 235 | if (subFolder.Name.ToLower() != "trash") |
236 | { | 236 | { |
237 | success = CloneFolder(avatarInventory, avID, toFolder.ID, appearance, subFolder, templateFolders, modifyPermissions); | 237 | success = CloneFolder(avatarInventory, avID, toFolder.ID, appearance, subFolder, templateFolders, modifyPermissions); |
238 | } | 238 | } |
239 | } | 239 | } |
240 | } | 240 | } |
241 | else | 241 | else |
242 | { | 242 | { |
243 | m_log.Info("[AvatarAppearance] Failed to find the template folder"); | 243 | m_log.Info("[AvatarAppearance] Failed to find the template folder"); |
244 | } | 244 | } |
245 | return success; | 245 | return success; |
246 | } | 246 | } |
247 | 247 | ||
248 | private UUID CloneInventoryItem(UUID avatarID, UUID avatarFolder, InventoryItemBase item, bool modifyPerms) | 248 | private UUID CloneInventoryItem(UUID avatarID, UUID avatarFolder, InventoryItemBase item, bool modifyPerms) |
249 | { | 249 | { |
250 | if (avatarFolder != UUID.Zero) | 250 | if (avatarFolder != UUID.Zero) |
251 | { | 251 | { |
252 | InventoryItemBase clonedItem = new InventoryItemBase(); | 252 | InventoryItemBase clonedItem = new InventoryItemBase(); |
253 | clonedItem.Owner = avatarID; | 253 | clonedItem.Owner = avatarID; |
254 | clonedItem.AssetID = item.AssetID; | 254 | clonedItem.AssetID = item.AssetID; |
255 | clonedItem.AssetType = item.AssetType; | 255 | clonedItem.AssetType = item.AssetType; |
256 | clonedItem.BasePermissions = item.BasePermissions; | 256 | clonedItem.BasePermissions = item.BasePermissions; |
257 | clonedItem.CreationDate = item.CreationDate; | 257 | clonedItem.CreationDate = item.CreationDate; |
258 | clonedItem.CreatorId = item.CreatorId; | 258 | clonedItem.CreatorId = item.CreatorId; |
259 | clonedItem.CreatorIdAsUuid = item.CreatorIdAsUuid; | 259 | clonedItem.CreatorIdAsUuid = item.CreatorIdAsUuid; |
260 | clonedItem.CurrentPermissions = item.CurrentPermissions; | 260 | clonedItem.CurrentPermissions = item.CurrentPermissions; |
261 | clonedItem.Description = item.Description; | 261 | clonedItem.Description = item.Description; |
262 | clonedItem.EveryOnePermissions = item.EveryOnePermissions; | 262 | clonedItem.EveryOnePermissions = item.EveryOnePermissions; |
263 | clonedItem.Flags = item.Flags; | 263 | clonedItem.Flags = item.Flags; |
264 | clonedItem.Folder = avatarFolder; | 264 | clonedItem.Folder = avatarFolder; |
265 | clonedItem.GroupID = item.GroupID; | 265 | clonedItem.GroupID = item.GroupID; |
266 | clonedItem.GroupOwned = item.GroupOwned; | 266 | clonedItem.GroupOwned = item.GroupOwned; |
267 | clonedItem.GroupPermissions = item.GroupPermissions; | 267 | clonedItem.GroupPermissions = item.GroupPermissions; |
268 | clonedItem.ID = UUID.Random(); | 268 | clonedItem.ID = UUID.Random(); |
269 | clonedItem.InvType = item.InvType; | 269 | clonedItem.InvType = item.InvType; |
270 | clonedItem.Name = item.Name; | 270 | clonedItem.Name = item.Name; |
271 | clonedItem.NextPermissions = item.NextPermissions; | 271 | clonedItem.NextPermissions = item.NextPermissions; |
272 | clonedItem.SalePrice = item.SalePrice; | 272 | clonedItem.SalePrice = item.SalePrice; |
273 | clonedItem.SaleType = item.SaleType; | 273 | clonedItem.SaleType = item.SaleType; |
274 | 274 | ||
275 | if (modifyPerms) | 275 | if (modifyPerms) |
276 | { | 276 | { |
277 | ModifyPermissions(ref clonedItem); | 277 | ModifyPermissions(ref clonedItem); |
278 | } | 278 | } |
279 | 279 | ||
280 | SynchronousRestObjectRequester.MakeRequest<InventoryItemBase, bool>( | 280 | SynchronousRestObjectRequester.MakeRequest<InventoryItemBase, bool>( |
281 | "POST", m_inventoryServerUrl + "AddNewItem/", clonedItem); | 281 | "POST", m_inventoryServerUrl + "AddNewItem/", clonedItem); |
282 | 282 | ||
283 | return clonedItem.ID; | 283 | return clonedItem.ID; |
284 | } | 284 | } |
285 | 285 | ||
286 | return UUID.Zero; | 286 | return UUID.Zero; |
287 | } | 287 | } |
288 | 288 | ||
289 | private void UpdateAvatarAppearance(UUID avatarID, int wearableType, UUID itemID, UUID assetID) | 289 | private void UpdateAvatarAppearance(UUID avatarID, int wearableType, UUID itemID, UUID assetID) |
290 | { | 290 | { |
291 | AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID); | 291 | AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID); |
292 | if (appearance == null) | 292 | if (appearance == null) |
293 | { | 293 | { |
294 | appearance = CreateDefaultAppearance(avatarID); | 294 | appearance = CreateDefaultAppearance(avatarID); |
295 | } | 295 | } |
296 | 296 | ||
297 | appearance.Wearables[wearableType].AssetID = assetID; | 297 | appearance.Wearables[wearableType].AssetID = assetID; |
298 | appearance.Wearables[wearableType].ItemID = itemID; | 298 | appearance.Wearables[wearableType].ItemID = itemID; |
299 | 299 | ||
300 | m_userDataBaseService.UpdateUserAppearance(avatarID, appearance); | 300 | m_userDataBaseService.UpdateUserAppearance(avatarID, appearance); |
301 | 301 | ||
302 | } | 302 | } |
303 | 303 | ||
304 | private void UpdateAvatarAttachment(UUID avatarID, int attachmentPoint, UUID itemID, UUID assetID) | 304 | private void UpdateAvatarAttachment(UUID avatarID, int attachmentPoint, UUID itemID, UUID assetID) |
305 | { | 305 | { |
306 | AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID); | 306 | AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID); |
307 | if (appearance == null) | 307 | if (appearance == null) |
308 | { | 308 | { |
309 | appearance = CreateDefaultAppearance(avatarID); | 309 | appearance = CreateDefaultAppearance(avatarID); |
310 | } | 310 | } |
311 | 311 | ||
312 | appearance.SetAttachment(attachmentPoint, itemID, assetID); | 312 | appearance.SetAttachment(attachmentPoint, itemID, assetID); |
313 | 313 | ||
314 | m_userDataBaseService.UpdateUserAppearance(avatarID, appearance); | 314 | m_userDataBaseService.UpdateUserAppearance(avatarID, appearance); |
315 | 315 | ||
316 | } | 316 | } |
317 | 317 | ||
318 | private void RemoveClothesAndAttachments(UUID avatarID) | 318 | private void RemoveClothesAndAttachments(UUID avatarID) |
319 | { | 319 | { |
320 | AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID); | 320 | AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID); |
321 | if (appearance == null) | 321 | if (appearance == null) |
322 | { | 322 | { |
323 | appearance = CreateDefaultAppearance(avatarID); | 323 | appearance = CreateDefaultAppearance(avatarID); |
324 | } | 324 | } |
325 | 325 | ||
326 | appearance.ClearWearables(); | 326 | appearance.ClearWearables(); |
327 | appearance.ClearAttachments(); | 327 | appearance.ClearAttachments(); |
328 | m_userDataBaseService.UpdateUserAppearance(avatarID, appearance); | 328 | m_userDataBaseService.UpdateUserAppearance(avatarID, appearance); |
329 | 329 | ||
330 | } | 330 | } |
331 | 331 | ||
332 | private UUID FindFolderID(string name, List<InventoryFolderBase> folders) | 332 | private UUID FindFolderID(string name, List<InventoryFolderBase> folders) |
333 | { | 333 | { |
334 | foreach (InventoryFolderBase folder in folders) | 334 | foreach (InventoryFolderBase folder in folders) |
335 | { | 335 | { |
336 | if (folder.Name == name) | 336 | if (folder.Name == name) |
337 | { | 337 | { |
338 | return folder.ID; | 338 | return folder.ID; |
339 | } | 339 | } |
340 | } | 340 | } |
341 | return UUID.Zero; | 341 | return UUID.Zero; |
342 | } | 342 | } |
343 | 343 | ||
344 | private InventoryFolderBase FindFolder(string name, List<InventoryFolderBase> folders) | 344 | private InventoryFolderBase FindFolder(string name, List<InventoryFolderBase> folders) |
345 | { | 345 | { |
346 | foreach (InventoryFolderBase folder in folders) | 346 | foreach (InventoryFolderBase folder in folders) |
347 | { | 347 | { |
348 | if (folder.Name == name) | 348 | if (folder.Name == name) |
349 | { | 349 | { |
350 | return folder; | 350 | return folder; |
351 | } | 351 | } |
352 | } | 352 | } |
353 | return null; | 353 | return null; |
354 | } | 354 | } |
355 | 355 | ||
356 | private InventoryFolderBase FindFolder(string name, Guid parentFolderID, List<InventoryFolderBase> folders) | 356 | private InventoryFolderBase FindFolder(string name, Guid parentFolderID, List<InventoryFolderBase> folders) |
357 | { | 357 | { |
358 | foreach (InventoryFolderBase folder in folders) | 358 | foreach (InventoryFolderBase folder in folders) |
359 | { | 359 | { |
360 | if ((folder.Name == name) && (folder.ParentID.Guid == parentFolderID)) | 360 | if ((folder.Name == name) && (folder.ParentID.Guid == parentFolderID)) |
361 | { | 361 | { |
362 | return folder; | 362 | return folder; |
363 | } | 363 | } |
364 | } | 364 | } |
365 | return null; | 365 | return null; |
366 | } | 366 | } |
367 | 367 | ||
368 | private InventoryItemBase GetItem(string itemName, List<InventoryItemBase> items) | 368 | private InventoryItemBase GetItem(string itemName, List<InventoryItemBase> items) |
369 | { | 369 | { |
370 | foreach (InventoryItemBase item in items) | 370 | foreach (InventoryItemBase item in items) |
371 | { | 371 | { |
372 | if (item.Name.ToLower() == itemName.ToLower()) | 372 | if (item.Name.ToLower() == itemName.ToLower()) |
373 | { | 373 | { |
374 | return item; | 374 | return item; |
375 | } | 375 | } |
376 | } | 376 | } |
377 | return null; | 377 | return null; |
378 | } | 378 | } |
379 | 379 | ||
380 | private List<InventoryFolderBase> FindSubFolders(Guid parentFolderID, List<InventoryFolderBase> folders) | 380 | private List<InventoryFolderBase> FindSubFolders(Guid parentFolderID, List<InventoryFolderBase> folders) |
381 | { | 381 | { |
382 | List<InventoryFolderBase> subFolders = new List<InventoryFolderBase>(); | 382 | List<InventoryFolderBase> subFolders = new List<InventoryFolderBase>(); |
383 | foreach (InventoryFolderBase folder in folders) | 383 | foreach (InventoryFolderBase folder in folders) |
384 | { | 384 | { |
385 | if (folder.ParentID.Guid == parentFolderID) | 385 | if (folder.ParentID.Guid == parentFolderID) |
386 | { | 386 | { |
387 | subFolders.Add(folder); | 387 | subFolders.Add(folder); |
388 | } | 388 | } |
389 | } | 389 | } |
390 | return subFolders; | 390 | return subFolders; |
391 | } | 391 | } |
392 | 392 | ||
393 | protected virtual void ModifyPermissions(ref InventoryItemBase item) | 393 | protected virtual void ModifyPermissions(ref InventoryItemBase item) |
394 | { | 394 | { |
395 | // Propagate Permissions | 395 | // Propagate Permissions |
396 | item.BasePermissions = item.BasePermissions & item.NextPermissions; | 396 | item.BasePermissions = item.BasePermissions & item.NextPermissions; |
397 | item.CurrentPermissions = item.BasePermissions; | 397 | item.CurrentPermissions = item.BasePermissions; |
398 | item.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions; | 398 | item.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions; |
399 | item.GroupPermissions = item.GroupPermissions & item.NextPermissions; | 399 | item.GroupPermissions = item.GroupPermissions & item.NextPermissions; |
400 | 400 | ||
401 | //set all items to +mod/+copy/- transfer | 401 | //set all items to +mod/+copy/- transfer |
402 | //if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0) | 402 | //if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0) |
403 | // item.CurrentPermissions |= (uint)PermissionMask.Modify; | 403 | // item.CurrentPermissions |= (uint)PermissionMask.Modify; |
404 | 404 | ||
405 | //if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) | 405 | //if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) |
406 | // item.CurrentPermissions |= (uint)PermissionMask.Copy; | 406 | // item.CurrentPermissions |= (uint)PermissionMask.Copy; |
407 | 407 | ||
408 | //if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) != 0) | 408 | //if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) != 0) |
409 | // item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; | 409 | // item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; |
410 | 410 | ||
411 | //if ((item.NextPermissions & (uint)PermissionMask.Modify) == 0) | 411 | //if ((item.NextPermissions & (uint)PermissionMask.Modify) == 0) |
412 | // item.NextPermissions |= (uint)PermissionMask.Modify; | 412 | // item.NextPermissions |= (uint)PermissionMask.Modify; |
413 | 413 | ||
414 | //if ((item.NextPermissions & (uint)PermissionMask.Copy) == 0) | 414 | //if ((item.NextPermissions & (uint)PermissionMask.Copy) == 0) |
415 | // item.NextPermissions |= (uint)PermissionMask.Copy; | 415 | // item.NextPermissions |= (uint)PermissionMask.Copy; |
416 | 416 | ||
417 | //if ((item.NextPermissions & (uint)PermissionMask.Transfer) != 0) | 417 | //if ((item.NextPermissions & (uint)PermissionMask.Transfer) != 0) |
418 | // item.NextPermissions &= ~(uint)PermissionMask.Transfer; | 418 | // item.NextPermissions &= ~(uint)PermissionMask.Transfer; |
419 | 419 | ||
420 | //if ((item.EveryOnePermissions & (uint)PermissionMask.Transfer) != 0) | 420 | //if ((item.EveryOnePermissions & (uint)PermissionMask.Transfer) != 0) |
421 | // item.EveryOnePermissions &= ~(uint)PermissionMask.Transfer; | 421 | // item.EveryOnePermissions &= ~(uint)PermissionMask.Transfer; |
422 | } | 422 | } |
423 | 423 | ||
424 | private AvatarAppearance CreateDefaultAppearance(UUID avatarId) | 424 | private AvatarAppearance CreateDefaultAppearance(UUID avatarId) |
425 | { | 425 | { |
426 | AvatarAppearance appearance = null; | 426 | AvatarAppearance appearance = null; |
427 | AvatarWearable[] wearables; | 427 | AvatarWearable[] wearables; |
428 | byte[] visualParams; | 428 | byte[] visualParams; |
429 | GetDefaultAvatarAppearance(out wearables, out visualParams); | 429 | GetDefaultAvatarAppearance(out wearables, out visualParams); |
430 | appearance = new AvatarAppearance(avatarId, wearables, visualParams); | 430 | appearance = new AvatarAppearance(avatarId, wearables, visualParams); |
431 | 431 | ||
432 | return appearance; | 432 | return appearance; |
433 | } | 433 | } |
434 | 434 | ||
435 | private static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams) | 435 | private static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams) |
436 | { | 436 | { |
437 | visualParams = GetDefaultVisualParams(); | 437 | visualParams = GetDefaultVisualParams(); |
438 | wearables = AvatarWearable.DefaultWearables; | 438 | wearables = AvatarWearable.DefaultWearables; |
439 | } | 439 | } |
440 | 440 | ||
441 | private static byte[] GetDefaultVisualParams() | 441 | private static byte[] GetDefaultVisualParams() |
442 | { | 442 | { |
443 | byte[] visualParams; | 443 | byte[] visualParams; |
444 | visualParams = new byte[218]; | 444 | visualParams = new byte[218]; |
445 | for (int i = 0; i < 218; i++) | 445 | for (int i = 0; i < 218; i++) |
446 | { | 446 | { |
447 | visualParams[i] = 100; | 447 | visualParams[i] = 100; |
448 | } | 448 | } |
449 | return visualParams; | 449 | return visualParams; |
450 | } | 450 | } |
451 | 451 | ||
452 | private int ItemIsPartOfAppearance(InventoryItemBase item, AvatarAppearance appearance) | 452 | private int ItemIsPartOfAppearance(InventoryItemBase item, AvatarAppearance appearance) |
453 | { | 453 | { |
454 | if (appearance != null) | 454 | if (appearance != null) |
455 | { | 455 | { |
456 | if (appearance.BodyItem == item.ID) | 456 | if (appearance.BodyItem == item.ID) |
457 | return (int)WearableType.Shape; | 457 | return (int)WearableType.Shape; |
458 | 458 | ||
459 | if (appearance.EyesItem == item.ID) | 459 | if (appearance.EyesItem == item.ID) |
460 | return (int)WearableType.Eyes; | 460 | return (int)WearableType.Eyes; |
461 | 461 | ||
462 | if (appearance.GlovesItem == item.ID) | 462 | if (appearance.GlovesItem == item.ID) |
463 | return (int)WearableType.Gloves; | 463 | return (int)WearableType.Gloves; |
464 | 464 | ||
465 | if (appearance.HairItem == item.ID) | 465 | if (appearance.HairItem == item.ID) |
466 | return (int)WearableType.Hair; | 466 | return (int)WearableType.Hair; |
467 | 467 | ||
468 | if (appearance.JacketItem == item.ID) | 468 | if (appearance.JacketItem == item.ID) |
469 | return (int)WearableType.Jacket; | 469 | return (int)WearableType.Jacket; |
470 | 470 | ||
471 | if (appearance.PantsItem == item.ID) | 471 | if (appearance.PantsItem == item.ID) |
472 | return (int)WearableType.Pants; | 472 | return (int)WearableType.Pants; |
473 | 473 | ||
474 | if (appearance.ShirtItem == item.ID) | 474 | if (appearance.ShirtItem == item.ID) |
475 | return (int)WearableType.Shirt; | 475 | return (int)WearableType.Shirt; |
476 | 476 | ||
477 | if (appearance.ShoesItem == item.ID) | 477 | if (appearance.ShoesItem == item.ID) |
478 | return (int)WearableType.Shoes; | 478 | return (int)WearableType.Shoes; |
479 | 479 | ||
480 | if (appearance.SkinItem == item.ID) | 480 | if (appearance.SkinItem == item.ID) |
481 | return (int)WearableType.Skin; | 481 | return (int)WearableType.Skin; |
482 | 482 | ||
483 | if (appearance.SkirtItem == item.ID) | 483 | if (appearance.SkirtItem == item.ID) |
484 | return (int)WearableType.Skirt; | 484 | return (int)WearableType.Skirt; |
485 | 485 | ||
486 | if (appearance.SocksItem == item.ID) | 486 | if (appearance.SocksItem == item.ID) |
487 | return (int)WearableType.Socks; | 487 | return (int)WearableType.Socks; |
488 | 488 | ||
489 | if (appearance.UnderPantsItem == item.ID) | 489 | if (appearance.UnderPantsItem == item.ID) |
490 | return (int)WearableType.Underpants; | 490 | return (int)WearableType.Underpants; |
491 | 491 | ||
492 | if (appearance.UnderShirtItem == item.ID) | 492 | if (appearance.UnderShirtItem == item.ID) |
493 | return (int)WearableType.Undershirt; | 493 | return (int)WearableType.Undershirt; |
494 | } | 494 | } |
495 | return -1; | 495 | return -1; |
496 | } | 496 | } |
497 | #endregion | 497 | #endregion |
498 | 498 | ||
499 | 499 | ||
500 | } | 500 | } |
501 | public enum PermissionMask | 501 | public enum PermissionMask |
502 | { | 502 | { |
503 | None = 0, | 503 | None = 0, |
504 | Transfer = 8192, | 504 | Transfer = 8192, |
505 | Modify = 16384, | 505 | Modify = 16384, |
506 | Copy = 32768, | 506 | Copy = 32768, |
507 | Move = 524288, | 507 | Move = 524288, |
508 | Damage = 1048576, | 508 | Damage = 1048576, |
509 | All = 2147483647, | 509 | All = 2147483647, |
510 | } | 510 | } |
511 | 511 | ||
512 | public enum WearableType | 512 | public enum WearableType |
513 | { | 513 | { |
514 | Shape = 0, | 514 | Shape = 0, |
515 | Skin = 1, | 515 | Skin = 1, |
516 | Hair = 2, | 516 | Hair = 2, |
517 | Eyes = 3, | 517 | Eyes = 3, |
518 | Shirt = 4, | 518 | Shirt = 4, |
519 | Pants = 5, | 519 | Pants = 5, |
520 | Shoes = 6, | 520 | Shoes = 6, |
521 | Socks = 7, | 521 | Socks = 7, |
522 | Jacket = 8, | 522 | Jacket = 8, |
523 | Gloves = 9, | 523 | Gloves = 9, |
524 | Undershirt = 10, | 524 | Undershirt = 10, |
525 | Underpants = 11, | 525 | Underpants = 11, |
526 | Skirt = 12, | 526 | Skirt = 12, |
527 | } | 527 | } |
528 | } | 528 | } |