aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs107
1 files changed, 89 insertions, 18 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
index 2818712..95cc6b7 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{
@@ -295,6 +296,40 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
295 if (DebugLevel > 0) 296 if (DebugLevel > 0)
296 m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name); 297 m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name);
297 298
299 XmlDocument doc = new XmlDocument();
300 string stateData = String.Empty;
301
302 IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>();
303 if (attServ != null)
304 {
305 m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service");
306 stateData = attServ.Get(sp.UUID.ToString());
307 if (stateData != String.Empty)
308 {
309 try
310 {
311 doc.LoadXml(stateData);
312 }
313 catch { }
314 }
315 }
316
317 Dictionary<UUID, string> itemData = new Dictionary<UUID, string>();
318
319 XmlNodeList nodes = doc.GetElementsByTagName("Attachment");
320 if (nodes.Count > 0)
321 {
322 foreach (XmlNode n in nodes)
323 {
324 XmlElement elem = (XmlElement)n;
325 string itemID = elem.GetAttribute("ItemID");
326 string xml = elem.InnerXml;
327
328 itemData[new UUID(itemID)] = xml;
329 }
330 }
331
332
298 List<AvatarAttachment> attachments = sp.Appearance.GetAttachments(); 333 List<AvatarAttachment> attachments = sp.Appearance.GetAttachments();
299 foreach (AvatarAttachment attach in attachments) 334 foreach (AvatarAttachment attach in attachments)
300 { 335 {
@@ -314,10 +349,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
314 349
315 try 350 try
316 { 351 {
352 string xmlData;
353 XmlDocument d = null;
354 UUID asset;
355 if (itemData.TryGetValue(attach.ItemID, out xmlData))
356 {
357 d = new XmlDocument();
358 d.LoadXml(xmlData);
359 m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", attach.ItemID);
360 }
361
317 // If we're an NPC then skip all the item checks and manipulations since we don't have an 362 // If we're an NPC then skip all the item checks and manipulations since we don't have an
318 // inventory right now. 363 // inventory right now.
319 RezSingleAttachmentFromInventoryInternal( 364 RezSingleAttachmentFromInventoryInternal(
320 sp, sp.PresenceType == PresenceType.Npc ? UUID.Zero : attach.ItemID, attach.AssetID, attachmentPt, true); 365 sp, sp.PresenceType == PresenceType.Npc ? UUID.Zero : attach.ItemID, attach.AssetID, attachmentPt, true, d);
321 } 366 }
322 catch (Exception e) 367 catch (Exception e)
323 { 368 {
@@ -380,13 +425,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
380 sp.ClearAttachments(); 425 sp.ClearAttachments();
381 } 426 }
382 427
383 public bool AttachObject( 428 public bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool useAttachData, bool addToInventory, bool append)
384 IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool addToInventory, bool append)
385 { 429 {
386 if (!Enabled) 430 if (!Enabled)
387 return false; 431 return false;
388 432
389 return AttachObjectInternal(sp, group, attachmentPt, silent, addToInventory, false, append); 433 return AttachObjectInternal(sp, group, attachmentPt, silent, useAttachData, addToInventory, false, append);
390 } 434 }
391 435
392 /// <summary> 436 /// <summary>
@@ -399,10 +443,21 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
399 /// <param name='silent'></param> 443 /// <param name='silent'></param>
400 /// <param name='addToInventory'>If true then add object to user inventory.</param> 444 /// <param name='addToInventory'>If true then add object to user inventory.</param>
401 /// <param name='resumeScripts'>If true then scripts are resumed on the attached object.</param> 445 /// <param name='resumeScripts'>If true then scripts are resumed on the attached object.</param>
402 /// <param name='append'>Append to attachment point rather than replace.</param> 446 private bool AttachObjectInternal(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool useAttachData, bool addToInventory, bool resumeScripts, bool append)
403 private bool AttachObjectInternal(
404 IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool addToInventory, bool resumeScripts, bool append)
405 { 447 {
448// m_log.DebugFormat(
449// "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})",
450// group.Name, group.LocalId, sp.Name, attachmentPt, silent);
451
452 if (sp.GetAttachments().Contains(group))
453 {
454// m_log.WarnFormat(
455// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached",
456// group.Name, group.LocalId, sp.Name, AttachmentPt);
457
458 return false;
459 }
460
406 if (group.GetSittingAvatarsCount() != 0) 461 if (group.GetSittingAvatarsCount() != 0)
407 { 462 {
408 if (DebugLevel > 0) 463 if (DebugLevel > 0)
@@ -414,6 +469,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
414 } 469 }
415 470
416 Vector3 attachPos = group.AbsolutePosition; 471 Vector3 attachPos = group.AbsolutePosition;
472
473 // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should
474 // be removed when that functionality is implemented in opensim
475 attachmentPt &= 0x7f;
476
417 // If the attachment point isn't the same as the one previously used 477 // If the attachment point isn't the same as the one previously used
418 // set it's offset position = 0 so that it appears on the attachment point 478 // set it's offset position = 0 so that it appears on the attachment point
419 // and not in a weird location somewhere unknown. 479 // and not in a weird location somewhere unknown.
@@ -422,7 +482,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
422 attachPos = Vector3.Zero; 482 attachPos = Vector3.Zero;
423 } 483 }
424 484
425 // AttachmentPt 0 means the client chose to 'wear' the attachment. 485 // AttachmentPt 0 (default) means the client chose to 'wear' the attachment.
426 if (attachmentPt == (uint)AttachmentPoint.Default) 486 if (attachmentPt == (uint)AttachmentPoint.Default)
427 { 487 {
428 // Check object for stored attachment point 488 // Check object for stored attachment point
@@ -437,9 +497,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
437 attachPos = Vector3.Zero; 497 attachPos = Vector3.Zero;
438 } 498 }
439 499
440 group.AttachmentPoint = attachmentPt;
441 group.AbsolutePosition = attachPos;
442
443 List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); 500 List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt);
444 501
445 if (attachments.Contains(group)) 502 if (attachments.Contains(group))
@@ -472,6 +529,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
472 529
473 lock (sp.AttachmentsSyncLock) 530 lock (sp.AttachmentsSyncLock)
474 { 531 {
532 group.AttachmentPoint = attachmentPt;
533 group.AbsolutePosition = attachPos;
534
475 if (addToInventory && sp.PresenceType != PresenceType.Npc) 535 if (addToInventory && sp.PresenceType != PresenceType.Npc)
476 UpdateUserInventoryWithAttachment(sp, group, attachmentPt, append); 536 UpdateUserInventoryWithAttachment(sp, group, attachmentPt, append);
477 537
@@ -502,7 +562,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
502 ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group, append); 562 ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group, append);
503 } 563 }
504 564
505 public SceneObjectGroup RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt) 565 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt)
566 {
567 return RezSingleAttachmentFromInventory(sp, itemID, AttachmentPt, null);
568 }
569
570 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt, XmlDocument doc)
506 { 571 {
507 if (!Enabled) 572 if (!Enabled)
508 return null; 573 return null;
@@ -540,7 +605,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
540 bool append = (AttachmentPt & 0x80) != 0; 605 bool append = (AttachmentPt & 0x80) != 0;
541 AttachmentPt &= 0x7f; 606 AttachmentPt &= 0x7f;
542 607
543 return RezSingleAttachmentFromInventoryInternal(sp, itemID, UUID.Zero, AttachmentPt, append); 608 return RezSingleAttachmentFromInventoryInternal(sp, itemID, UUID.Zero, AttachmentPt, append, doc);
544 } 609 }
545 610
546 public void RezMultipleAttachmentsFromInventory(IScenePresence sp, List<KeyValuePair<UUID, uint>> rezlist) 611 public void RezMultipleAttachmentsFromInventory(IScenePresence sp, List<KeyValuePair<UUID, uint>> rezlist)
@@ -617,7 +682,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
617 so.AttachedAvatar = UUID.Zero; 682 so.AttachedAvatar = UUID.Zero;
618 rootPart.SetParentLocalId(0); 683 rootPart.SetParentLocalId(0);
619 so.ClearPartAttachmentData(); 684 so.ClearPartAttachmentData();
620 rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive); 685 rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive,false);
621 so.HasGroupChanged = true; 686 so.HasGroupChanged = true;
622 rootPart.Rezzed = DateTime.Now; 687 rootPart.Rezzed = DateTime.Now;
623 rootPart.RemFlag(PrimFlags.TemporaryOnRez); 688 rootPart.RemFlag(PrimFlags.TemporaryOnRez);
@@ -950,7 +1015,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
950 } 1015 }
951 1016
952 protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal( 1017 protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal(
953 IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt, bool append) 1018 IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt, bool append, XmlDocument doc)
954 { 1019 {
955 if (m_invAccessModule == null) 1020 if (m_invAccessModule == null)
956 return null; 1021 return null;
@@ -994,7 +1059,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
994 // This will throw if the attachment fails 1059 // This will throw if the attachment fails
995 try 1060 try
996 { 1061 {
997 AttachObjectInternal(sp, objatt, attachmentPt, false, true, true, append); 1062 if (doc != null)
1063 {
1064 objatt.LoadScriptState(doc);
1065 objatt.ResetOwnerChangeFlag();
1066 }
1067
1068 AttachObjectInternal(sp, objatt, attachmentPt, false, true, true, true, append);
998 } 1069 }
999 catch (Exception e) 1070 catch (Exception e)
1000 { 1071 {
@@ -1148,7 +1219,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
1148 AttachmentPt &= 0x7f; 1219 AttachmentPt &= 0x7f;
1149 1220
1150 // Calls attach with a Zero position 1221 // Calls attach with a Zero position
1151 if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, true, append)) 1222 if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, false, true, append))
1152 { 1223 {
1153 if (DebugLevel > 0) 1224 if (DebugLevel > 0)
1154 m_log.Debug( 1225 m_log.Debug(
@@ -1210,4 +1281,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
1210 1281
1211 #endregion 1282 #endregion
1212 } 1283 }
1213} \ No newline at end of file 1284}