aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 14:54:35 +0100
committerUbitUmarov2015-09-01 14:54:35 +0100
commit371c9dd2af01a2e7422ec901ee1f80757284a78c (patch)
tree058d2a513cacb12efcce0c0df0ae14ad135dbfe2 /OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
parentremove lixo (diff)
parentdont change camera on crossings (diff)
downloadopensim-SC-371c9dd2af01a2e7422ec901ee1f80757284a78c.zip
opensim-SC-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.gz
opensim-SC-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.bz2
opensim-SC-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.xz
bad merge?
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs178
1 files changed, 151 insertions, 27 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
index 2f67c4e..b24dc0c 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
@@ -41,6 +41,7 @@ using OpenSim.Region.Framework;
41using OpenSim.Region.Framework.Interfaces; 41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes; 42using OpenSim.Region.Framework.Scenes;
43using OpenSim.Region.Framework.Scenes.Serialization; 43using OpenSim.Region.Framework.Scenes.Serialization;
44using OpenSim.Services.Interfaces;
44 45
45namespace OpenSim.Region.CoreModules.Avatar.Attachments 46namespace OpenSim.Region.CoreModules.Avatar.Attachments
46{ 47{
@@ -303,6 +304,40 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
303 if (DebugLevel > 0) 304 if (DebugLevel > 0)
304 m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name); 305 m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name);
305 306
307 XmlDocument doc = new XmlDocument();
308 string stateData = String.Empty;
309
310 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
311 if (attServ != null)
312 {
313 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
314 stateData = attServ.Get(sp.UUID.ToString());
315 if (stateData != String.Empty)
316 {
317 try
318 {
319 doc.LoadXml(stateData);
320 }
321 catch { }
322 }
323 }
324
325 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
326
327 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
328 if (nodes.Count > 0)
329 {
330 foreach (XmlNode n in nodes)
331 {
332 XmlElement elem = (XmlElement)n;
333 string itemID = elem.GetAttribute("ItemID");
334 string xml = elem.InnerXml;
335
336 itemData[new UUID(itemID)] = xml;
337 }
338 }
339
340
306 List<AvatarAttachment> attachments = sp.Appearance.GetAttachments(); 341 List<AvatarAttachment> attachments = sp.Appearance.GetAttachments();
307 342
308 // Let's get all items at once, so they get cached 343 // Let's get all items at once, so they get cached
@@ -330,10 +365,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
330 365
331 try 366 try
332 { 367 {
368 string xmlData;
369 XmlDocument d = null;
370 UUID asset;
371 if (itemData.TryGetValue(attach.ItemID, out xmlData))
372 {
373 d = new XmlDocument();
374 d.LoadXml(xmlData);
375 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", attach.ItemID);
376 }
377
333 // If we're an NPC then skip all the item checks and manipulations since we don't have an 378 // If we're an NPC then skip all the item checks and manipulations since we don't have an
334 // inventory right now. 379 // inventory right now.
335 RezSingleAttachmentFromInventoryInternal( 380 RezSingleAttachmentFromInventoryInternal(
336 sp, sp.PresenceType == PresenceType.Npc ? UUID.Zero : attach.ItemID, attach.AssetID, attachmentPt, true); 381 sp, sp.PresenceType == PresenceType.Npc ? UUID.Zero : attach.ItemID, attach.AssetID, attachmentPt, true, d);
337 } 382 }
338 catch (Exception e) 383 catch (Exception e)
339 { 384 {
@@ -361,6 +406,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
361 406
362 Dictionary<SceneObjectGroup, string> scriptStates = new Dictionary<SceneObjectGroup, string>(); 407 Dictionary<SceneObjectGroup, string> scriptStates = new Dictionary<SceneObjectGroup, string>();
363 408
409<<<<<<< HEAD
364 foreach (SceneObjectGroup so in attachments) 410 foreach (SceneObjectGroup so in attachments)
365 { 411 {
366 // Scripts MUST be snapshotted before the object is 412 // Scripts MUST be snapshotted before the object is
@@ -376,12 +422,36 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
376 } 422 }
377 423
378 lock (sp.AttachmentsSyncLock) 424 lock (sp.AttachmentsSyncLock)
425=======
426 if (sp.PresenceType != PresenceType.Npc)
427>>>>>>> avn/ubitvar
379 { 428 {
380 foreach (SceneObjectGroup so in attachments) 429 foreach (SceneObjectGroup so in attachments)
381 UpdateDetachedObject(sp, so, scriptStates[so]); 430 {
382 431 // Scripts MUST be snapshotted before the object is
383 sp.ClearAttachments(); 432 // removed from the scene because doing otherwise will
433 // clobber the run flag
434 // This must be done outside the sp.AttachmentSyncLock so that there is no risk of a deadlock from
435 // scripts performing attachment operations at the same time. Getting object states stops the scripts.
436 scriptStates[so] = PrepareScriptInstanceForSave(so, false);
437 }
438
439 lock (sp.AttachmentsSyncLock)
440 {
441 foreach (SceneObjectGroup so in attachments)
442 UpdateDetachedObject(sp, so, scriptStates[so]);
443 sp.ClearAttachments();
444 }
384 } 445 }
446 else
447 {
448 lock (sp.AttachmentsSyncLock)
449 {
450 foreach (SceneObjectGroup so in attachments)
451 UpdateDetachedObject(sp, so, String.Empty);
452 sp.ClearAttachments();
453 }
454 }
385 } 455 }
386 456
387 public void DeleteAttachmentsFromScene(IScenePresence sp, bool silent) 457 public void DeleteAttachmentsFromScene(IScenePresence sp, bool silent)
@@ -402,12 +472,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
402 sp.ClearAttachments(); 472 sp.ClearAttachments();
403 } 473 }
404 474
405 public bool AttachObject( 475 public bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool useAttachData, bool addToInventory, bool append)
406 IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool addToInventory, bool append)
407 { 476 {
408 if (!Enabled) 477 if (!Enabled)
409 return false; 478 return false;
410 479
480<<<<<<< HEAD
411 group.DetachFromBackup(); 481 group.DetachFromBackup();
412 482
413 bool success = AttachObjectInternal(sp, group, attachmentPt, silent, addToInventory, false, append); 483 bool success = AttachObjectInternal(sp, group, attachmentPt, silent, addToInventory, false, append);
@@ -416,6 +486,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
416 group.AttachToBackup(); 486 group.AttachToBackup();
417 487
418 return success; 488 return success;
489=======
490 return AttachObjectInternal(sp, group, attachmentPt, silent, useAttachData, addToInventory, false, append);
491>>>>>>> avn/ubitvar
419 } 492 }
420 493
421 /// <summary> 494 /// <summary>
@@ -428,10 +501,21 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
428 /// <param name='silent'></param> 501 /// <param name='silent'></param>
429 /// <param name='addToInventory'>If true then add object to user inventory.</param> 502 /// <param name='addToInventory'>If true then add object to user inventory.</param>
430 /// <param name='resumeScripts'>If true then scripts are resumed on the attached object.</param> 503 /// <param name='resumeScripts'>If true then scripts are resumed on the attached object.</param>
431 /// <param name='append'>Append to attachment point rather than replace.</param> 504 private bool AttachObjectInternal(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool useAttachData, bool addToInventory, bool resumeScripts, bool append)
432 private bool AttachObjectInternal(
433 IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool addToInventory, bool resumeScripts, bool append)
434 { 505 {
506// m_log.DebugFormat(
507// "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})",
508// group.Name, group.LocalId, sp.Name, attachmentPt, silent);
509
510 if (sp.GetAttachments().Contains(group))
511 {
512// m_log.WarnFormat(
513// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached",
514// group.Name, group.LocalId, sp.Name, AttachmentPt);
515
516 return false;
517 }
518
435 if (group.GetSittingAvatarsCount() != 0) 519 if (group.GetSittingAvatarsCount() != 0)
436 { 520 {
437 if (DebugLevel > 0) 521 if (DebugLevel > 0)
@@ -443,6 +527,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
443 } 527 }
444 528
445 Vector3 attachPos = group.AbsolutePosition; 529 Vector3 attachPos = group.AbsolutePosition;
530
531 // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should
532 // be removed when that functionality is implemented in opensim
533 attachmentPt &= 0x7f;
534
446 // If the attachment point isn't the same as the one previously used 535 // If the attachment point isn't the same as the one previously used
447 // set it's offset position = 0 so that it appears on the attachment point 536 // set it's offset position = 0 so that it appears on the attachment point
448 // and not in a weird location somewhere unknown. 537 // and not in a weird location somewhere unknown.
@@ -481,9 +570,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
481 attachPos = Vector3.Zero; 570 attachPos = Vector3.Zero;
482 } 571 }
483 572
484 group.AttachmentPoint = attachmentPt;
485 group.AbsolutePosition = attachPos;
486
487 List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); 573 List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt);
488 574
489 if (attachments.Contains(group)) 575 if (attachments.Contains(group))
@@ -516,6 +602,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
516 602
517 lock (sp.AttachmentsSyncLock) 603 lock (sp.AttachmentsSyncLock)
518 { 604 {
605 group.AttachmentPoint = attachmentPt;
606 group.AbsolutePosition = attachPos;
607
519 if (addToInventory && sp.PresenceType != PresenceType.Npc) 608 if (addToInventory && sp.PresenceType != PresenceType.Npc)
520 UpdateUserInventoryWithAttachment(sp, group, attachmentPt, append); 609 UpdateUserInventoryWithAttachment(sp, group, attachmentPt, append);
521 610
@@ -546,7 +635,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
546 ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group, append); 635 ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group, append);
547 } 636 }
548 637
549 public SceneObjectGroup RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt) 638 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt)
639 {
640 return RezSingleAttachmentFromInventory(sp, itemID, AttachmentPt, null);
641 }
642
643 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt, XmlDocument doc)
550 { 644 {
551 if (!Enabled) 645 if (!Enabled)
552 return null; 646 return null;
@@ -584,7 +678,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
584 bool append = (AttachmentPt & 0x80) != 0; 678 bool append = (AttachmentPt & 0x80) != 0;
585 AttachmentPt &= 0x7f; 679 AttachmentPt &= 0x7f;
586 680
587 return RezSingleAttachmentFromInventoryInternal(sp, itemID, UUID.Zero, AttachmentPt, append); 681 return RezSingleAttachmentFromInventoryInternal(sp, itemID, UUID.Zero, AttachmentPt, append, doc);
588 } 682 }
589 683
590 public void RezMultipleAttachmentsFromInventory(IScenePresence sp, List<KeyValuePair<UUID, uint>> rezlist) 684 public void RezMultipleAttachmentsFromInventory(IScenePresence sp, List<KeyValuePair<UUID, uint>> rezlist)
@@ -649,26 +743,36 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
649 if (changed && m_scene.AvatarFactory != null) 743 if (changed && m_scene.AvatarFactory != null)
650 m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID); 744 m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID);
651 745
746 so.RootPart.Shape.LastAttachPoint = (byte)so.AttachmentPoint;
747
652 sp.RemoveAttachment(so); 748 sp.RemoveAttachment(so);
653 so.FromItemID = UUID.Zero; 749 so.FromItemID = UUID.Zero;
654 750
751 so.AttachedAvatar = UUID.Zero;
752 so.ClearPartAttachmentData();
753
655 SceneObjectPart rootPart = so.RootPart; 754 SceneObjectPart rootPart = so.RootPart;
755
756 rootPart.SetParentLocalId(0);
656 so.AbsolutePosition = absolutePos; 757 so.AbsolutePosition = absolutePos;
657 if (absoluteRot != Quaternion.Identity) 758 if (absoluteRot != Quaternion.Identity)
658 { 759 {
659 so.UpdateGroupRotationR(absoluteRot); 760 so.UpdateGroupRotationR(absoluteRot);
660 } 761 }
661 so.AttachedAvatar = UUID.Zero; 762
662 rootPart.SetParentLocalId(0); 763 rootPart.RemFlag(PrimFlags.TemporaryOnRez);
663 so.ClearPartAttachmentData(); 764
664 rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive); 765 // not physical, not temporary, phaton, not volume detector
766// so.UpdatePrimFlags(rootPart.LocalId,false,false,true,rootPart.VolumeDetectActive);
767
768 // restore full physical state instead
769 so.ApplyPhysics();
770
665 so.HasGroupChanged = true; 771 so.HasGroupChanged = true;
666 so.RootPart.Shape.LastAttachPoint = (byte)so.AttachmentPoint;
667 rootPart.Rezzed = DateTime.Now; 772 rootPart.Rezzed = DateTime.Now;
668 rootPart.RemFlag(PrimFlags.TemporaryOnRez);
669 so.AttachToBackup(); 773 so.AttachToBackup();
670 m_scene.EventManager.TriggerParcelPrimCountTainted(); 774 m_scene.EventManager.TriggerParcelPrimCountTainted();
671 rootPart.ScheduleFullUpdate(); 775
672 rootPart.ClearUndoState(); 776 rootPart.ClearUndoState();
673 777
674 List<UUID> uuids = new List<UUID>(); 778 List<UUID> uuids = new List<UUID>();
@@ -678,6 +782,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
678 } 782 }
679 783
680 m_scene.EventManager.TriggerOnAttach(so.LocalId, so.UUID, UUID.Zero); 784 m_scene.EventManager.TriggerOnAttach(so.LocalId, so.UUID, UUID.Zero);
785
786 // Attach (NULL) stops scripts. We don't want that. Resume them.
787 so.ResumeScripts();
788 so.ScheduleGroupForTerseUpdate();
789 so.RootPart.ScheduleFullUpdate();
681 } 790 }
682 791
683 public void DetachSingleAttachmentToInv(IScenePresence sp, SceneObjectGroup so) 792 public void DetachSingleAttachmentToInv(IScenePresence sp, SceneObjectGroup so)
@@ -848,8 +957,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
848 957
849 so.AttachedAvatar = sp.UUID; 958 so.AttachedAvatar = sp.UUID;
850 959
851 if (so.RootPart.PhysActor != null) 960 foreach (SceneObjectPart part in so.Parts)
852 so.RootPart.RemoveFromPhysics(); 961 {
962// if (part.KeyframeMotion != null)
963// part.KeyframeMotion.Suspend();
964
965 if (part.PhysActor != null)
966 {
967 part.RemoveFromPhysics();
968 }
969 }
853 970
854 so.AbsolutePosition = attachOffset; 971 so.AbsolutePosition = attachOffset;
855 so.RootPart.AttachedPos = attachOffset; 972 so.RootPart.AttachedPos = attachOffset;
@@ -971,6 +1088,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
971 // Remove the object from the scene so no more updates 1088 // Remove the object from the scene so no more updates
972 // are sent. Doing this before the below changes will ensure 1089 // are sent. Doing this before the below changes will ensure
973 // updates can't cause "HUD artefacts" 1090 // updates can't cause "HUD artefacts"
1091
974 m_scene.DeleteSceneObject(so, false, false); 1092 m_scene.DeleteSceneObject(so, false, false);
975 1093
976 // Prepare sog for storage 1094 // Prepare sog for storage
@@ -992,7 +1110,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
992 } 1110 }
993 1111
994 protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal( 1112 protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal(
995 IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt, bool append) 1113 IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt, bool append, XmlDocument doc)
996 { 1114 {
997 if (m_invAccessModule == null) 1115 if (m_invAccessModule == null)
998 return null; 1116 return null;
@@ -1043,7 +1161,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
1043 // This will throw if the attachment fails 1161 // This will throw if the attachment fails
1044 try 1162 try
1045 { 1163 {
1046 AttachObjectInternal(sp, objatt, attachmentPt, false, true, true, append); 1164 if (doc != null)
1165 {
1166 objatt.LoadScriptState(doc);
1167 objatt.ResetOwnerChangeFlag();
1168 }
1169
1170 AttachObjectInternal(sp, objatt, attachmentPt, false, true, true, true, append);
1047 } 1171 }
1048 catch (Exception e) 1172 catch (Exception e)
1049 { 1173 {
@@ -1197,7 +1321,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
1197 AttachmentPt &= 0x7f; 1321 AttachmentPt &= 0x7f;
1198 1322
1199 // Calls attach with a Zero position 1323 // Calls attach with a Zero position
1200 if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, true, append)) 1324 if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, false, true, append))
1201 { 1325 {
1202 if (DebugLevel > 0) 1326 if (DebugLevel > 0)
1203 m_log.Debug( 1327 m_log.Debug(
@@ -1205,7 +1329,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
1205 + ", AttachmentPoint: " + AttachmentPt); 1329 + ", AttachmentPoint: " + AttachmentPt);
1206 1330
1207 // Save avatar attachment information 1331 // Save avatar attachment information
1208 m_scene.EventManager.TriggerOnAttach(objectLocalID, part.ParentGroup.FromItemID, remoteClient.AgentId); 1332 m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID);
1209 } 1333 }
1210 } 1334 }
1211 catch (Exception e) 1335 catch (Exception e)