diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs | 400 |
1 files changed, 194 insertions, 206 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs index 73b0a35..5d19025 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs | |||
@@ -222,7 +222,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
222 | deletes[g.OwnerID].Add(g); | 222 | deletes[g.OwnerID].Add(g); |
223 | } | 223 | } |
224 | 224 | ||
225 | // This is pethod scoped and will be returned. It will be the | 225 | // This is method scoped and will be returned. It will be the |
226 | // last created asset id | 226 | // last created asset id |
227 | UUID assetID = UUID.Zero; | 227 | UUID assetID = UUID.Zero; |
228 | 228 | ||
@@ -230,8 +230,8 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
230 | // with distinct destinations as well. | 230 | // with distinct destinations as well. |
231 | foreach (List<SceneObjectGroup> objlist in deletes.Values) | 231 | foreach (List<SceneObjectGroup> objlist in deletes.Values) |
232 | { | 232 | { |
233 | Dictionary<UUID, string> xmlStrings = | 233 | CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero); |
234 | new Dictionary<UUID, string>(); | 234 | Dictionary<UUID, Vector3> originalPositions = new Dictionary<UUID, Vector3>(); |
235 | 235 | ||
236 | foreach (SceneObjectGroup objectGroup in objlist) | 236 | foreach (SceneObjectGroup objectGroup in objlist) |
237 | { | 237 | { |
@@ -245,7 +245,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
245 | : objectGroup.AbsolutePosition.X, | 245 | : objectGroup.AbsolutePosition.X, |
246 | objectGroup.AbsolutePosition.Z); | 246 | objectGroup.AbsolutePosition.Z); |
247 | 247 | ||
248 | Vector3 originalPosition = objectGroup.AbsolutePosition; | 248 | originalPositions[objectGroup.UUID] = objectGroup.AbsolutePosition; |
249 | 249 | ||
250 | objectGroup.AbsolutePosition = inventoryStoredPosition; | 250 | objectGroup.AbsolutePosition = inventoryStoredPosition; |
251 | 251 | ||
@@ -259,209 +259,37 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
259 | (uint)PermissionMask.Modify); | 259 | (uint)PermissionMask.Modify); |
260 | objectGroup.RootPart.NextOwnerMask |= | 260 | objectGroup.RootPart.NextOwnerMask |= |
261 | (uint)PermissionMask.Move; | 261 | (uint)PermissionMask.Move; |
262 | 262 | ||
263 | string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(objectGroup); | 263 | coa.Add(objectGroup); |
264 | |||
265 | objectGroup.AbsolutePosition = originalPosition; | ||
266 | |||
267 | xmlStrings[objectGroup.UUID] = sceneObjectXml; | ||
268 | } | 264 | } |
269 | 265 | ||
270 | string itemXml; | 266 | string itemXml; |
271 | 267 | ||
272 | if (objlist.Count > 1) | 268 | if (objlist.Count > 1) |
273 | { | 269 | itemXml = CoalescedSceneObjectsSerializer.ToXml(coa); |
274 | float minX, minY, minZ; | ||
275 | float maxX, maxY, maxZ; | ||
276 | |||
277 | Vector3[] offsets = m_Scene.GetCombinedBoundingBox(objlist, | ||
278 | out minX, out maxX, out minY, out maxY, | ||
279 | out minZ, out maxZ); | ||
280 | |||
281 | // CreateWrapper | ||
282 | XmlDocument itemDoc = new XmlDocument(); | ||
283 | XmlElement root = itemDoc.CreateElement("", "CoalescedObject", ""); | ||
284 | itemDoc.AppendChild(root); | ||
285 | |||
286 | // Embed the offsets into the group XML | ||
287 | for ( int i = 0 ; i < objlist.Count ; i++ ) | ||
288 | { | ||
289 | XmlDocument doc = new XmlDocument(); | ||
290 | SceneObjectGroup g = objlist[i]; | ||
291 | doc.LoadXml(xmlStrings[g.UUID]); | ||
292 | XmlElement e = (XmlElement)doc.SelectSingleNode("/SceneObjectGroup"); | ||
293 | e.SetAttribute("offsetx", offsets[i].X.ToString()); | ||
294 | e.SetAttribute("offsety", offsets[i].Y.ToString()); | ||
295 | e.SetAttribute("offsetz", offsets[i].Z.ToString()); | ||
296 | |||
297 | XmlNode objectNode = itemDoc.ImportNode(e, true); | ||
298 | root.AppendChild(objectNode); | ||
299 | } | ||
300 | |||
301 | float sizeX = maxX - minX; | ||
302 | float sizeY = maxY - minY; | ||
303 | float sizeZ = maxZ - minZ; | ||
304 | |||
305 | root.SetAttribute("x", sizeX.ToString()); | ||
306 | root.SetAttribute("y", sizeY.ToString()); | ||
307 | root.SetAttribute("z", sizeZ.ToString()); | ||
308 | |||
309 | itemXml = itemDoc.InnerXml; | ||
310 | } | ||
311 | else | 270 | else |
312 | { | 271 | itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0]); |
313 | itemXml = xmlStrings[objlist[0].UUID]; | 272 | |
314 | } | 273 | // Restore the position of each group now that it has been stored to inventory. |
315 | 274 | foreach (SceneObjectGroup objectGroup in objlist) | |
316 | // Get the user info of the item destination | 275 | objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID]; |
317 | // | ||
318 | UUID userID = UUID.Zero; | ||
319 | |||
320 | if (action == DeRezAction.Take || action == DeRezAction.TakeCopy || | ||
321 | action == DeRezAction.SaveToExistingUserInventoryItem) | ||
322 | { | ||
323 | // Take or take copy require a taker | ||
324 | // Saving changes requires a local user | ||
325 | // | ||
326 | if (remoteClient == null) | ||
327 | return UUID.Zero; | ||
328 | |||
329 | userID = remoteClient.AgentId; | ||
330 | } | ||
331 | else | ||
332 | { | ||
333 | // All returns / deletes go to the object owner | ||
334 | // | ||
335 | |||
336 | userID = objlist[0].RootPart.OwnerID; | ||
337 | } | ||
338 | 276 | ||
339 | if (userID == UUID.Zero) // Can't proceed | 277 | InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID); |
340 | { | 278 | if (item == null) |
341 | return UUID.Zero; | 279 | return UUID.Zero; |
342 | } | 280 | |
343 | 281 | // Can't know creator is the same, so null it in inventory | |
344 | // If we're returning someone's item, it goes back to the | 282 | if (objlist.Count > 1) |
345 | // owner's Lost And Found folder. | ||
346 | // Delete is treated like return in this case | ||
347 | // Deleting your own items makes them go to trash | ||
348 | // | ||
349 | |||
350 | InventoryFolderBase folder = null; | ||
351 | InventoryItemBase item = null; | ||
352 | |||
353 | if (DeRezAction.SaveToExistingUserInventoryItem == action) | ||
354 | { | 283 | { |
355 | item = new InventoryItemBase(objlist[0].RootPart.FromUserInventoryItemID, userID); | 284 | item.CreatorId = UUID.Zero.ToString(); |
356 | item = m_Scene.InventoryService.GetItem(item); | 285 | item.Flags = (uint)InventoryItemFlags.ObjectHasMultipleItems; |
357 | |||
358 | //item = userInfo.RootFolder.FindItem( | ||
359 | // objectGroup.RootPart.FromUserInventoryItemID); | ||
360 | |||
361 | if (null == item) | ||
362 | { | ||
363 | m_log.DebugFormat( | ||
364 | "[AGENT INVENTORY]: Object {0} {1} scheduled for save to inventory has already been deleted.", | ||
365 | objlist[0].Name, objlist[0].UUID); | ||
366 | return UUID.Zero; | ||
367 | } | ||
368 | } | 286 | } |
369 | else | 287 | else |
370 | { | 288 | { |
371 | // Folder magic | 289 | item.CreatorId = objlist[0].RootPart.CreatorID.ToString(); |
372 | // | 290 | item.SaleType = objlist[0].RootPart.ObjectSaleType; |
373 | if (action == DeRezAction.Delete) | 291 | item.SalePrice = objlist[0].RootPart.SalePrice; |
374 | { | 292 | } |
375 | // Deleting someone else's item | ||
376 | // | ||
377 | if (remoteClient == null || | ||
378 | objlist[0].OwnerID != remoteClient.AgentId) | ||
379 | { | ||
380 | |||
381 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder); | ||
382 | } | ||
383 | else | ||
384 | { | ||
385 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.TrashFolder); | ||
386 | } | ||
387 | } | ||
388 | else if (action == DeRezAction.Return) | ||
389 | { | ||
390 | |||
391 | // Dump to lost + found unconditionally | ||
392 | // | ||
393 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder); | ||
394 | } | ||
395 | |||
396 | if (folderID == UUID.Zero && folder == null) | ||
397 | { | ||
398 | if (action == DeRezAction.Delete) | ||
399 | { | ||
400 | // Deletes go to trash by default | ||
401 | // | ||
402 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.TrashFolder); | ||
403 | } | ||
404 | else | ||
405 | { | ||
406 | if (remoteClient == null || | ||
407 | objlist[0].OwnerID != remoteClient.AgentId) | ||
408 | { | ||
409 | // Taking copy of another person's item. Take to | ||
410 | // Objects folder. | ||
411 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.Object); | ||
412 | } | ||
413 | else | ||
414 | { | ||
415 | // Catch all. Use lost & found | ||
416 | // | ||
417 | |||
418 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder); | ||
419 | } | ||
420 | } | ||
421 | } | ||
422 | |||
423 | // Override and put into where it came from, if it came | ||
424 | // from anywhere in inventory | ||
425 | // | ||
426 | if (action == DeRezAction.Take || action == DeRezAction.TakeCopy) | ||
427 | { | ||
428 | if (objlist[0].RootPart.FromFolderID != UUID.Zero) | ||
429 | { | ||
430 | InventoryFolderBase f = new InventoryFolderBase(objlist[0].RootPart.FromFolderID, userID); | ||
431 | folder = m_Scene.InventoryService.GetFolder(f); | ||
432 | } | ||
433 | } | ||
434 | |||
435 | if (folder == null) // None of the above | ||
436 | { | ||
437 | folder = new InventoryFolderBase(folderID); | ||
438 | |||
439 | if (folder == null) // Nowhere to put it | ||
440 | { | ||
441 | return UUID.Zero; | ||
442 | } | ||
443 | } | ||
444 | |||
445 | item = new InventoryItemBase(); | ||
446 | // Can't know creator is the same, so null it in inventory | ||
447 | if (objlist.Count > 1) | ||
448 | item.CreatorId = UUID.Zero.ToString(); | ||
449 | else | ||
450 | item.CreatorId = objlist[0].RootPart.CreatorID.ToString(); | ||
451 | item.ID = UUID.Random(); | ||
452 | item.InvType = (int)InventoryType.Object; | ||
453 | item.Folder = folder.ID; | ||
454 | item.Owner = userID; | ||
455 | if (objlist.Count > 1) | ||
456 | { | ||
457 | item.Flags = (uint)InventoryItemFlags.ObjectHasMultipleItems; | ||
458 | } | ||
459 | else | ||
460 | { | ||
461 | item.SaleType = objlist[0].RootPart.ObjectSaleType; | ||
462 | item.SalePrice = objlist[0].RootPart.SalePrice; | ||
463 | } | ||
464 | } | ||
465 | 293 | ||
466 | AssetBase asset = CreateAsset( | 294 | AssetBase asset = CreateAsset( |
467 | objlist[0].GetPartName(objlist[0].RootPart.LocalId), | 295 | objlist[0].GetPartName(objlist[0].RootPart.LocalId), |
@@ -470,17 +298,16 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
470 | Utils.StringToBytes(itemXml), | 298 | Utils.StringToBytes(itemXml), |
471 | objlist[0].OwnerID.ToString()); | 299 | objlist[0].OwnerID.ToString()); |
472 | m_Scene.AssetService.Store(asset); | 300 | m_Scene.AssetService.Store(asset); |
473 | assetID = asset.FullID; | 301 | |
302 | item.AssetID = asset.FullID; | ||
303 | assetID = asset.FullID; | ||
474 | 304 | ||
475 | if (DeRezAction.SaveToExistingUserInventoryItem == action) | 305 | if (DeRezAction.SaveToExistingUserInventoryItem == action) |
476 | { | 306 | { |
477 | item.AssetID = asset.FullID; | ||
478 | m_Scene.InventoryService.UpdateItem(item); | 307 | m_Scene.InventoryService.UpdateItem(item); |
479 | } | 308 | } |
480 | else | 309 | else |
481 | { | 310 | { |
482 | item.AssetID = asset.FullID; | ||
483 | |||
484 | uint effectivePerms = (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify | PermissionMask.Move) | 7; | 311 | uint effectivePerms = (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify | PermissionMask.Move) | 7; |
485 | foreach (SceneObjectGroup grp in objlist) | 312 | foreach (SceneObjectGroup grp in objlist) |
486 | effectivePerms &= grp.GetEffectivePermissions(); | 313 | effectivePerms &= grp.GetEffectivePermissions(); |
@@ -545,9 +372,156 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
545 | } | 372 | } |
546 | } | 373 | } |
547 | } | 374 | } |
375 | |||
548 | return assetID; | 376 | return assetID; |
549 | } | 377 | } |
378 | |||
379 | /// <summary> | ||
380 | /// Create an item using details for the given scene object. | ||
381 | /// </summary> | ||
382 | /// <param name="action"></param> | ||
383 | /// <param name="remoteClient"></param> | ||
384 | /// <param name="so"></param> | ||
385 | /// <param name="folderID"></param> | ||
386 | /// <returns></returns> | ||
387 | protected InventoryItemBase CreateItemForObject( | ||
388 | DeRezAction action, IClientAPI remoteClient, SceneObjectGroup so, UUID folderID) | ||
389 | { | ||
390 | // Get the user info of the item destination | ||
391 | // | ||
392 | UUID userID = UUID.Zero; | ||
393 | |||
394 | if (action == DeRezAction.Take || action == DeRezAction.TakeCopy || | ||
395 | action == DeRezAction.SaveToExistingUserInventoryItem) | ||
396 | { | ||
397 | // Take or take copy require a taker | ||
398 | // Saving changes requires a local user | ||
399 | // | ||
400 | if (remoteClient == null) | ||
401 | return null; | ||
402 | |||
403 | userID = remoteClient.AgentId; | ||
404 | } | ||
405 | else | ||
406 | { | ||
407 | // All returns / deletes go to the object owner | ||
408 | // | ||
409 | userID = so.RootPart.OwnerID; | ||
410 | } | ||
411 | |||
412 | if (userID == UUID.Zero) // Can't proceed | ||
413 | { | ||
414 | return null; | ||
415 | } | ||
416 | |||
417 | // If we're returning someone's item, it goes back to the | ||
418 | // owner's Lost And Found folder. | ||
419 | // Delete is treated like return in this case | ||
420 | // Deleting your own items makes them go to trash | ||
421 | // | ||
422 | |||
423 | InventoryFolderBase folder = null; | ||
424 | InventoryItemBase item = null; | ||
425 | |||
426 | if (DeRezAction.SaveToExistingUserInventoryItem == action) | ||
427 | { | ||
428 | item = new InventoryItemBase(so.RootPart.FromUserInventoryItemID, userID); | ||
429 | item = m_Scene.InventoryService.GetItem(item); | ||
430 | |||
431 | //item = userInfo.RootFolder.FindItem( | ||
432 | // objectGroup.RootPart.FromUserInventoryItemID); | ||
433 | |||
434 | if (null == item) | ||
435 | { | ||
436 | m_log.DebugFormat( | ||
437 | "[AGENT INVENTORY]: Object {0} {1} scheduled for save to inventory has already been deleted.", | ||
438 | so.Name, so.UUID); | ||
439 | |||
440 | return null; | ||
441 | } | ||
442 | } | ||
443 | else | ||
444 | { | ||
445 | // Folder magic | ||
446 | // | ||
447 | if (action == DeRezAction.Delete) | ||
448 | { | ||
449 | // Deleting someone else's item | ||
450 | // | ||
451 | if (remoteClient == null || | ||
452 | so.OwnerID != remoteClient.AgentId) | ||
453 | { | ||
454 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder); | ||
455 | } | ||
456 | else | ||
457 | { | ||
458 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.TrashFolder); | ||
459 | } | ||
460 | } | ||
461 | else if (action == DeRezAction.Return) | ||
462 | { | ||
463 | // Dump to lost + found unconditionally | ||
464 | // | ||
465 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder); | ||
466 | } | ||
550 | 467 | ||
468 | if (folderID == UUID.Zero && folder == null) | ||
469 | { | ||
470 | if (action == DeRezAction.Delete) | ||
471 | { | ||
472 | // Deletes go to trash by default | ||
473 | // | ||
474 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.TrashFolder); | ||
475 | } | ||
476 | else | ||
477 | { | ||
478 | if (remoteClient == null || so.OwnerID != remoteClient.AgentId) | ||
479 | { | ||
480 | // Taking copy of another person's item. Take to | ||
481 | // Objects folder. | ||
482 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.Object); | ||
483 | } | ||
484 | else | ||
485 | { | ||
486 | // Catch all. Use lost & found | ||
487 | // | ||
488 | |||
489 | folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder); | ||
490 | } | ||
491 | } | ||
492 | } | ||
493 | |||
494 | // Override and put into where it came from, if it came | ||
495 | // from anywhere in inventory | ||
496 | // | ||
497 | if (action == DeRezAction.Take || action == DeRezAction.TakeCopy) | ||
498 | { | ||
499 | if (so.RootPart.FromFolderID != UUID.Zero) | ||
500 | { | ||
501 | InventoryFolderBase f = new InventoryFolderBase(so.RootPart.FromFolderID, userID); | ||
502 | folder = m_Scene.InventoryService.GetFolder(f); | ||
503 | } | ||
504 | } | ||
505 | |||
506 | if (folder == null) // None of the above | ||
507 | { | ||
508 | folder = new InventoryFolderBase(folderID); | ||
509 | |||
510 | if (folder == null) // Nowhere to put it | ||
511 | { | ||
512 | return null; | ||
513 | } | ||
514 | } | ||
515 | |||
516 | item = new InventoryItemBase(); | ||
517 | item.ID = UUID.Random(); | ||
518 | item.InvType = (int)InventoryType.Object; | ||
519 | item.Folder = folder.ID; | ||
520 | item.Owner = userID; | ||
521 | } | ||
522 | |||
523 | return item; | ||
524 | } | ||
551 | 525 | ||
552 | /// <summary> | 526 | /// <summary> |
553 | /// Rez an object into the scene from the user's inventory | 527 | /// Rez an object into the scene from the user's inventory |
@@ -659,9 +633,18 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
659 | itemId, n.OuterXml); | 633 | itemId, n.OuterXml); |
660 | objlist.Add(g); | 634 | objlist.Add(g); |
661 | XmlElement el = (XmlElement)n; | 635 | XmlElement el = (XmlElement)n; |
662 | float x = Convert.ToSingle(el.GetAttribute("offsetx")); | 636 | |
663 | float y = Convert.ToSingle(el.GetAttribute("offsety")); | 637 | string rawX = el.GetAttribute("offsetx"); |
664 | float z = Convert.ToSingle(el.GetAttribute("offsetz")); | 638 | string rawY = el.GetAttribute("offsety"); |
639 | string rawZ = el.GetAttribute("offsetz"); | ||
640 | // | ||
641 | // m_log.DebugFormat( | ||
642 | // "[INVENTORY ACCESS MODULE]: Converting coalesced object {0} offset <{1}, {2}, {3}>", | ||
643 | // g.Name, rawX, rawY, rawZ); | ||
644 | |||
645 | float x = Convert.ToSingle(rawX); | ||
646 | float y = Convert.ToSingle(rawY); | ||
647 | float z = Convert.ToSingle(rawZ); | ||
665 | veclist.Add(new Vector3(x, y, z)); | 648 | veclist.Add(new Vector3(x, y, z)); |
666 | } | 649 | } |
667 | } | 650 | } |
@@ -753,10 +736,15 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
753 | // affect the name stored in the serialization, transfer | 736 | // affect the name stored in the serialization, transfer |
754 | // the correct name from the inventory to the | 737 | // the correct name from the inventory to the |
755 | // object itself before we rez. | 738 | // object itself before we rez. |
756 | rootPart.Name = item.Name; | 739 | // |
757 | rootPart.Description = item.Description; | 740 | // Only do these for the first object if we are rezzing a coalescence. |
758 | rootPart.ObjectSaleType = item.SaleType; | 741 | if (i == 0) |
759 | rootPart.SalePrice = item.SalePrice; | 742 | { |
743 | rootPart.Name = item.Name; | ||
744 | rootPart.Description = item.Description; | ||
745 | rootPart.ObjectSaleType = item.SaleType; | ||
746 | rootPart.SalePrice = item.SalePrice; | ||
747 | } | ||
760 | 748 | ||
761 | group.SetGroup(remoteClient.ActiveGroupId, remoteClient); | 749 | group.SetGroup(remoteClient.ActiveGroupId, remoteClient); |
762 | if ((rootPart.OwnerID != item.Owner) || | 750 | if ((rootPart.OwnerID != item.Owner) || |