diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs | 292 |
1 files changed, 187 insertions, 105 deletions
diff --git a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs index cb686e2..b6ec558 100644 --- a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs +++ b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs | |||
@@ -59,7 +59,7 @@ namespace OpenSim.Services.HypergridService | |||
59 | 59 | ||
60 | private UserAccountCache m_Cache; | 60 | private UserAccountCache m_Cache; |
61 | 61 | ||
62 | private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID,List<XInventoryFolder>>(); | 62 | private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID, List<XInventoryFolder>>(); |
63 | 63 | ||
64 | public HGSuitcaseInventoryService(IConfigSource config, string configName) | 64 | public HGSuitcaseInventoryService(IConfigSource config, string configName) |
65 | : base(config, configName) | 65 | : base(config, configName) |
@@ -104,11 +104,72 @@ namespace OpenSim.Services.HypergridService | |||
104 | return false; | 104 | return false; |
105 | } | 105 | } |
106 | 106 | ||
107 | |||
108 | public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID) | 107 | public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID) |
109 | { | 108 | { |
110 | // NOGO for this inventory service | 109 | XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); |
111 | return new List<InventoryFolderBase>(); | 110 | XInventoryFolder root = GetRootXFolder(principalID); |
111 | |||
112 | List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID); | ||
113 | if (tree == null || (tree != null && tree.Count == 0)) | ||
114 | return null; | ||
115 | |||
116 | List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); | ||
117 | foreach (XInventoryFolder x in tree) | ||
118 | { | ||
119 | folders.Add(ConvertToOpenSim(x)); | ||
120 | } | ||
121 | |||
122 | SetAsRootFolder(suitcase, root); | ||
123 | folders.Add(ConvertToOpenSim(suitcase)); | ||
124 | |||
125 | return folders; | ||
126 | } | ||
127 | |||
128 | public override InventoryCollection GetUserInventory(UUID userID) | ||
129 | { | ||
130 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID); | ||
131 | InventoryCollection userInventory = new InventoryCollection(); | ||
132 | userInventory.UserID = userID; | ||
133 | userInventory.Folders = new List<InventoryFolderBase>(); | ||
134 | userInventory.Items = new List<InventoryItemBase>(); | ||
135 | |||
136 | XInventoryFolder suitcase = GetSuitcaseXFolder(userID); | ||
137 | XInventoryFolder root = GetRootXFolder(userID); | ||
138 | |||
139 | List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID); | ||
140 | if (tree == null || (tree != null && tree.Count == 0)) | ||
141 | { | ||
142 | SetAsRootFolder(suitcase, root); | ||
143 | userInventory.Folders.Add(ConvertToOpenSim(suitcase)); | ||
144 | return userInventory; | ||
145 | } | ||
146 | |||
147 | List<InventoryItemBase> items; | ||
148 | foreach (XInventoryFolder f in tree) | ||
149 | { | ||
150 | // Add the items of this subfolder | ||
151 | items = GetFolderItems(userID, f.folderID); | ||
152 | if (items != null && items.Count > 0) | ||
153 | { | ||
154 | userInventory.Items.AddRange(items); | ||
155 | } | ||
156 | |||
157 | // Add the folder itself | ||
158 | userInventory.Folders.Add(ConvertToOpenSim(f)); | ||
159 | } | ||
160 | |||
161 | items = GetFolderItems(userID, suitcase.folderID); | ||
162 | if (items != null && items.Count > 0) | ||
163 | { | ||
164 | userInventory.Items.AddRange(items); | ||
165 | } | ||
166 | |||
167 | SetAsRootFolder(suitcase, root); | ||
168 | userInventory.Folders.Add(ConvertToOpenSim(suitcase)); | ||
169 | |||
170 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items", | ||
171 | userID, userInventory.Folders.Count, userInventory.Items.Count); | ||
172 | return userInventory; | ||
112 | } | 173 | } |
113 | 174 | ||
114 | public override InventoryFolderBase GetRootFolder(UUID principalID) | 175 | public override InventoryFolderBase GetRootFolder(UUID principalID) |
@@ -131,51 +192,92 @@ namespace OpenSim.Services.HypergridService | |||
131 | { | 192 | { |
132 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID); | 193 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID); |
133 | // make one, and let's add it to the user's inventory as a direct child of the root folder | 194 | // make one, and let's add it to the user's inventory as a direct child of the root folder |
195 | // In the DB we tag it as type 100, but we use -1 (Unknown) outside | ||
134 | suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase"); | 196 | suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase"); |
135 | if (suitcase == null) | 197 | if (suitcase == null) |
136 | m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder"); | 198 | m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder"); |
137 | |||
138 | m_Database.StoreFolder(suitcase); | 199 | m_Database.StoreFolder(suitcase); |
200 | |||
201 | // Create System folders | ||
202 | CreateSystemFolders(principalID, suitcase.folderID); | ||
139 | } | 203 | } |
140 | 204 | ||
141 | // Now let's change the folder ID to match that of the real root folder | 205 | SetAsRootFolder(suitcase, root); |
142 | SetAsRootFolder(suitcase, root.folderID); | ||
143 | 206 | ||
144 | return ConvertToOpenSim(suitcase); | 207 | return ConvertToOpenSim(suitcase); |
145 | } | 208 | } |
146 | 209 | ||
210 | protected void CreateSystemFolders(UUID principalID, UUID rootID) | ||
211 | { | ||
212 | m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase..."); | ||
213 | XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID); | ||
214 | |||
215 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; })) | ||
216 | CreateFolder(principalID, rootID, (int)AssetType.Animation, "Animations"); | ||
217 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; })) | ||
218 | CreateFolder(principalID, rootID, (int)AssetType.Bodypart, "Body Parts"); | ||
219 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; })) | ||
220 | CreateFolder(principalID, rootID, (int)AssetType.CallingCard, "Calling Cards"); | ||
221 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; })) | ||
222 | CreateFolder(principalID, rootID, (int)AssetType.Clothing, "Clothing"); | ||
223 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; })) | ||
224 | CreateFolder(principalID, rootID, (int)AssetType.Gesture, "Gestures"); | ||
225 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; })) | ||
226 | CreateFolder(principalID, rootID, (int)AssetType.Landmark, "Landmarks"); | ||
227 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; })) | ||
228 | CreateFolder(principalID, rootID, (int)AssetType.LostAndFoundFolder, "Lost And Found"); | ||
229 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; })) | ||
230 | CreateFolder(principalID, rootID, (int)AssetType.Notecard, "Notecards"); | ||
231 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; })) | ||
232 | CreateFolder(principalID, rootID, (int)AssetType.Object, "Objects"); | ||
233 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; })) | ||
234 | CreateFolder(principalID, rootID, (int)AssetType.SnapshotFolder, "Photo Album"); | ||
235 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; })) | ||
236 | CreateFolder(principalID, rootID, (int)AssetType.LSLText, "Scripts"); | ||
237 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; })) | ||
238 | CreateFolder(principalID, rootID, (int)AssetType.Sound, "Sounds"); | ||
239 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; })) | ||
240 | CreateFolder(principalID, rootID, (int)AssetType.Texture, "Textures"); | ||
241 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; })) | ||
242 | CreateFolder(principalID, rootID, (int)AssetType.TrashFolder, "Trash"); | ||
243 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.FavoriteFolder) return true; return false; })) | ||
244 | CreateFolder(principalID, rootID, (int)AssetType.FavoriteFolder, "Favorites"); | ||
245 | if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CurrentOutfitFolder) return true; return false; })) | ||
246 | CreateFolder(principalID, rootID, (int)AssetType.CurrentOutfitFolder, "Current Outfit"); | ||
247 | |||
248 | } | ||
249 | |||
147 | public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) | 250 | public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) |
148 | { | 251 | { |
149 | //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type); | 252 | //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type); |
150 | return GetRootFolder(principalID); | 253 | XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); |
254 | XInventoryFolder[] folders = m_Database.GetFolders( | ||
255 | new string[] { "agentID", "type", "parentFolderID" }, | ||
256 | new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() }); | ||
257 | |||
258 | if (folders.Length == 0) | ||
259 | { | ||
260 | m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no folder for type {0} for user {1}", type, principalID); | ||
261 | return null; | ||
262 | } | ||
263 | |||
264 | m_log.DebugFormat( | ||
265 | "[HG SUITCASE INVENTORY SERVICE]: Found folder {0} {1} for type {2} for user {3}", | ||
266 | folders[0].folderName, folders[0].folderID, type, principalID); | ||
267 | |||
268 | return ConvertToOpenSim(folders[0]); | ||
151 | } | 269 | } |
152 | 270 | ||
153 | public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID) | 271 | public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID) |
154 | { | 272 | { |
155 | InventoryCollection coll = null; | 273 | InventoryCollection coll = null; |
156 | XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); | 274 | XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); |
157 | XInventoryFolder root = GetRootXFolder(principalID); | ||
158 | 275 | ||
159 | if (!IsWithinSuitcaseTree(folderID, root, suitcase)) | 276 | if (!IsWithinSuitcaseTree(folderID, suitcase)) |
160 | return new InventoryCollection(); | 277 | return new InventoryCollection(); |
161 | 278 | ||
162 | if (folderID == root.folderID) // someone's asking for the root folder, we'll give them the suitcase | 279 | coll = base.GetFolderContent(principalID, folderID); |
163 | { | 280 | |
164 | if (suitcase != null) | ||
165 | { | ||
166 | coll = base.GetFolderContent(principalID, suitcase.folderID); | ||
167 | foreach (InventoryFolderBase f in coll.Folders) | ||
168 | f.ParentID = root.folderID; | ||
169 | foreach (InventoryItemBase i in coll.Items) | ||
170 | i.Folder = root.folderID; | ||
171 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetFolderContent for root folder returned content for suitcase folder"); | ||
172 | } | ||
173 | } | ||
174 | else | ||
175 | { | ||
176 | coll = base.GetFolderContent(principalID, folderID); | ||
177 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetFolderContent for non-root folder {0}", folderID); | ||
178 | } | ||
179 | if (coll == null) | 281 | if (coll == null) |
180 | { | 282 | { |
181 | m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID); | 283 | m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID); |
@@ -188,10 +290,9 @@ namespace OpenSim.Services.HypergridService | |||
188 | { | 290 | { |
189 | // Let's do a bit of sanity checking, more than the base service does | 291 | // Let's do a bit of sanity checking, more than the base service does |
190 | // make sure the given folder exists under the suitcase tree of this user | 292 | // make sure the given folder exists under the suitcase tree of this user |
191 | XInventoryFolder root = GetRootXFolder(principalID); | ||
192 | XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); | 293 | XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); |
193 | 294 | ||
194 | if (!IsWithinSuitcaseTree(folderID, root, suitcase)) | 295 | if (!IsWithinSuitcaseTree(folderID, suitcase)) |
195 | return new List<InventoryItemBase>(); | 296 | return new List<InventoryItemBase>(); |
196 | 297 | ||
197 | return base.GetFolderItems(principalID, folderID); | 298 | return base.GetFolderItems(principalID, folderID); |
@@ -199,52 +300,40 @@ namespace OpenSim.Services.HypergridService | |||
199 | 300 | ||
200 | public override bool AddFolder(InventoryFolderBase folder) | 301 | public override bool AddFolder(InventoryFolderBase folder) |
201 | { | 302 | { |
303 | m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID); | ||
202 | // Let's do a bit of sanity checking, more than the base service does | 304 | // Let's do a bit of sanity checking, more than the base service does |
203 | // make sure the given folder's parent folder exists under the suitcase tree of this user | 305 | // make sure the given folder's parent folder exists under the suitcase tree of this user |
204 | XInventoryFolder root = GetRootXFolder(folder.Owner); | ||
205 | XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); | 306 | XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); |
206 | 307 | ||
207 | if (!IsWithinSuitcaseTree(folder.ParentID, root, suitcase)) | 308 | if (!IsWithinSuitcaseTree(folder.ParentID, suitcase)) |
208 | return false; | 309 | return false; |
209 | 310 | ||
210 | // OK, it's legit | 311 | // OK, it's legit |
211 | // Check if it's under the Root folder directly | ||
212 | if (folder.ParentID == root.folderID) | ||
213 | { | ||
214 | // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead | ||
215 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder for root folder for user {0}. Adding in suitcase instead", folder.Owner); | ||
216 | folder.ParentID = suitcase.folderID; | ||
217 | } | ||
218 | |||
219 | return base.AddFolder(folder); | 312 | return base.AddFolder(folder); |
220 | } | 313 | } |
221 | 314 | ||
222 | public bool UpdateFolder(InventoryFolderBase folder) | 315 | public override bool UpdateFolder(InventoryFolderBase folder) |
223 | { | 316 | { |
224 | XInventoryFolder root = GetRootXFolder(folder.Owner); | ||
225 | XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); | 317 | XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); |
226 | 318 | ||
227 | if (!IsWithinSuitcaseTree(folder.ID, root, suitcase)) | 319 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version); |
320 | if (!IsWithinSuitcaseTree(folder.ID, suitcase)) | ||
321 | { | ||
322 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name); | ||
228 | return false; | 323 | return false; |
324 | } | ||
229 | 325 | ||
326 | // For all others | ||
230 | return base.UpdateFolder(folder); | 327 | return base.UpdateFolder(folder); |
231 | } | 328 | } |
232 | 329 | ||
233 | public override bool MoveFolder(InventoryFolderBase folder) | 330 | public override bool MoveFolder(InventoryFolderBase folder) |
234 | { | 331 | { |
235 | XInventoryFolder root = GetRootXFolder(folder.Owner); | ||
236 | XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); | 332 | XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); |
237 | 333 | ||
238 | if (!IsWithinSuitcaseTree(folder.ID, root, suitcase) || !IsWithinSuitcaseTree(folder.ParentID, root, suitcase)) | 334 | if (!IsWithinSuitcaseTree(folder.ID, suitcase) || !IsWithinSuitcaseTree(folder.ParentID, suitcase)) |
239 | return false; | 335 | return false; |
240 | 336 | ||
241 | if (folder.ParentID == root.folderID) | ||
242 | { | ||
243 | // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead | ||
244 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveFolder to root folder for user {0}. Moving it to suitcase instead", folder.Owner); | ||
245 | folder.ParentID = suitcase.folderID; | ||
246 | } | ||
247 | |||
248 | return base.MoveFolder(folder); | 337 | return base.MoveFolder(folder); |
249 | } | 338 | } |
250 | 339 | ||
@@ -264,31 +353,21 @@ namespace OpenSim.Services.HypergridService | |||
264 | { | 353 | { |
265 | // Let's do a bit of sanity checking, more than the base service does | 354 | // Let's do a bit of sanity checking, more than the base service does |
266 | // make sure the given folder's parent folder exists under the suitcase tree of this user | 355 | // make sure the given folder's parent folder exists under the suitcase tree of this user |
267 | XInventoryFolder root = GetRootXFolder(item.Owner); | ||
268 | XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner); | 356 | XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner); |
269 | 357 | ||
270 | if (!IsWithinSuitcaseTree(item.Folder, root, suitcase)) | 358 | if (!IsWithinSuitcaseTree(item.Folder, suitcase)) |
271 | return false; | 359 | return false; |
272 | 360 | ||
273 | // OK, it's legit | 361 | // OK, it's legit |
274 | // Check if it's under the Root folder directly | ||
275 | if (item.Folder == root.folderID) | ||
276 | { | ||
277 | // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead | ||
278 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: AddItem for root folder for user {0}. Adding in suitcase instead", item.Owner); | ||
279 | item.Folder = suitcase.folderID; | ||
280 | } | ||
281 | |||
282 | return base.AddItem(item); | 362 | return base.AddItem(item); |
283 | 363 | ||
284 | } | 364 | } |
285 | 365 | ||
286 | public override bool UpdateItem(InventoryItemBase item) | 366 | public override bool UpdateItem(InventoryItemBase item) |
287 | { | 367 | { |
288 | XInventoryFolder root = GetRootXFolder(item.Owner); | ||
289 | XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner); | 368 | XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner); |
290 | 369 | ||
291 | if (!IsWithinSuitcaseTree(item.Folder, root, suitcase)) | 370 | if (!IsWithinSuitcaseTree(item.Folder, suitcase)) |
292 | return false; | 371 | return false; |
293 | 372 | ||
294 | return base.UpdateItem(item); | 373 | return base.UpdateItem(item); |
@@ -298,68 +377,64 @@ namespace OpenSim.Services.HypergridService | |||
298 | { | 377 | { |
299 | // Principal is b0rked. *sigh* | 378 | // Principal is b0rked. *sigh* |
300 | 379 | ||
301 | XInventoryFolder root = GetRootXFolder(items[0].Owner); | ||
302 | XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner); | 380 | XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner); |
303 | 381 | ||
304 | if (!IsWithinSuitcaseTree(items[0].Folder, root, suitcase)) | 382 | if (!IsWithinSuitcaseTree(items[0].Folder, suitcase)) |
305 | return false; | 383 | return false; |
306 | 384 | ||
307 | foreach (InventoryItemBase it in items) | ||
308 | if (it.Folder == root.folderID) | ||
309 | { | ||
310 | // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead | ||
311 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveItem to root folder for user {0}. Moving it to suitcase instead", it.Owner); | ||
312 | it.Folder = suitcase.folderID; | ||
313 | } | ||
314 | |||
315 | return base.MoveItems(principalID, items); | 385 | return base.MoveItems(principalID, items); |
316 | 386 | ||
317 | } | 387 | } |
318 | 388 | ||
319 | // Let these pass. Use inherited methods. | ||
320 | public override bool DeleteItems(UUID principalID, List<UUID> itemIDs) | 389 | public override bool DeleteItems(UUID principalID, List<UUID> itemIDs) |
321 | { | 390 | { |
322 | return false; | 391 | return false; |
323 | } | 392 | } |
324 | 393 | ||
325 | public override InventoryItemBase GetItem(InventoryItemBase item) | 394 | public new InventoryItemBase GetItem(InventoryItemBase item) |
326 | { | 395 | { |
327 | InventoryItemBase it = base.GetItem(item); | 396 | InventoryItemBase it = base.GetItem(item); |
328 | XInventoryFolder root = GetRootXFolder(it.Owner); | 397 | if (it == null) |
398 | { | ||
399 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve item {0} ({1}) in folder {2}", | ||
400 | item.Name, item.ID, item.Folder); | ||
401 | return null; | ||
402 | } | ||
329 | XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner); | 403 | XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner); |
330 | 404 | if (suitcase == null) | |
331 | if (it != null) | ||
332 | { | 405 | { |
333 | if (!IsWithinSuitcaseTree(it.Folder, root, suitcase)) | 406 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Root or Suitcase are null for user {0}", |
334 | return null; | 407 | it.Owner); |
408 | return null; | ||
409 | } | ||
335 | 410 | ||
336 | if (it.Folder == suitcase.folderID) | 411 | if (!IsWithinSuitcaseTree(it.Folder, suitcase)) |
337 | it.Folder = root.folderID; | 412 | { |
413 | m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase", | ||
414 | it.Name, it.Folder); | ||
415 | return null; | ||
416 | } | ||
338 | 417 | ||
339 | // UserAccount user = m_Cache.GetUser(it.CreatorId); | 418 | // UserAccount user = m_Cache.GetUser(it.CreatorId); |
340 | 419 | ||
341 | // // Adjust the creator data | 420 | // // Adjust the creator data |
342 | // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty)) | 421 | // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty)) |
343 | // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName; | 422 | // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName; |
344 | //} | 423 | //} |
345 | } | ||
346 | 424 | ||
347 | return it; | 425 | return it; |
348 | } | 426 | } |
349 | 427 | ||
350 | public override InventoryFolderBase GetFolder(InventoryFolderBase folder) | 428 | public new InventoryFolderBase GetFolder(InventoryFolderBase folder) |
351 | { | 429 | { |
352 | InventoryFolderBase f = base.GetFolder(folder); | 430 | InventoryFolderBase f = base.GetFolder(folder); |
353 | XInventoryFolder root = GetRootXFolder(f.Owner); | ||
354 | XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner); | ||
355 | 431 | ||
356 | if (f != null) | 432 | if (f != null) |
357 | { | 433 | { |
358 | if (!IsWithinSuitcaseTree(f.ID, root, suitcase)) | 434 | XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner); |
359 | return null; | ||
360 | 435 | ||
361 | if (f.ParentID == suitcase.folderID) | 436 | if (!IsWithinSuitcaseTree(f.ID, suitcase)) |
362 | f.ParentID = root.folderID; | 437 | return null; |
363 | } | 438 | } |
364 | 439 | ||
365 | return f; | 440 | return f; |
@@ -409,20 +484,19 @@ namespace OpenSim.Services.HypergridService | |||
409 | return null; | 484 | return null; |
410 | } | 485 | } |
411 | 486 | ||
412 | private void SetAsRootFolder(XInventoryFolder suitcase, UUID rootID) | 487 | private void SetAsRootFolder(XInventoryFolder suitcase, XInventoryFolder root) |
413 | { | 488 | { |
414 | suitcase.folderID = rootID; | 489 | suitcase.type = (short)AssetType.Folder; |
415 | suitcase.parentFolderID = UUID.Zero; | ||
416 | } | 490 | } |
417 | 491 | ||
418 | private List<XInventoryFolder> GetFolderTree(UUID root) | 492 | private List<XInventoryFolder> GetFolderTree(UUID folder) |
419 | { | 493 | { |
420 | List<XInventoryFolder> t = null; | 494 | List<XInventoryFolder> t = null; |
421 | if (m_SuitcaseTrees.TryGetValue(root, out t)) | 495 | if (m_SuitcaseTrees.TryGetValue(folder, out t)) |
422 | return t; | 496 | return t; |
423 | 497 | ||
424 | t = GetFolderTreeRecursive(root); | 498 | t = GetFolderTreeRecursive(folder); |
425 | m_SuitcaseTrees.AddOrUpdate(root, t, 120); | 499 | m_SuitcaseTrees.AddOrUpdate(folder, t, 120); |
426 | return t; | 500 | return t; |
427 | } | 501 | } |
428 | 502 | ||
@@ -447,10 +521,17 @@ namespace OpenSim.Services.HypergridService | |||
447 | 521 | ||
448 | } | 522 | } |
449 | 523 | ||
450 | private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder root, XInventoryFolder suitcase) | 524 | /// <summary> |
525 | /// Return true if the folderID is a subfolder of the Suitcase or the suitcase folder itself | ||
526 | /// </summary> | ||
527 | /// <param name="folderID"></param> | ||
528 | /// <param name="root"></param> | ||
529 | /// <param name="suitcase"></param> | ||
530 | /// <returns></returns> | ||
531 | private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder suitcase) | ||
451 | { | 532 | { |
452 | List<XInventoryFolder> tree = new List<XInventoryFolder>(); | 533 | List<XInventoryFolder> tree = new List<XInventoryFolder>(); |
453 | tree.Add(root); // Warp! the tree is the real root folder plus the children of the suitcase folder | 534 | tree.Add(suitcase); // Warp! the tree is the real root folder plus the children of the suitcase folder |
454 | tree.AddRange(GetFolderTree(suitcase.folderID)); | 535 | tree.AddRange(GetFolderTree(suitcase.folderID)); |
455 | XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl) | 536 | XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl) |
456 | { | 537 | { |
@@ -463,4 +544,5 @@ namespace OpenSim.Services.HypergridService | |||
463 | } | 544 | } |
464 | #endregion | 545 | #endregion |
465 | } | 546 | } |
547 | |||
466 | } | 548 | } |