aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/AvatarAppearance.cs
diff options
context:
space:
mode:
authorTom2011-09-14 19:11:32 -0700
committerTom2011-09-14 19:11:32 -0700
commit5484c9b585a2a6289456e9492ac2989d489b555c (patch)
treec9b79199722fe09c993c237dce40febf731264e3 /OpenSim/Framework/AvatarAppearance.cs
parentMerge fixes, and fix the build (diff)
parentDon't try and delete attachments for child agent close (diff)
downloadopensim-SC_OLD-5484c9b585a2a6289456e9492ac2989d489b555c.zip
opensim-SC_OLD-5484c9b585a2a6289456e9492ac2989d489b555c.tar.gz
opensim-SC_OLD-5484c9b585a2a6289456e9492ac2989d489b555c.tar.bz2
opensim-SC_OLD-5484c9b585a2a6289456e9492ac2989d489b555c.tar.xz
Bring us up to date.
Diffstat (limited to 'OpenSim/Framework/AvatarAppearance.cs')
-rw-r--r--OpenSim/Framework/AvatarAppearance.cs72
1 files changed, 55 insertions, 17 deletions
diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs
index a68de57..21e2233 100644
--- a/OpenSim/Framework/AvatarAppearance.cs
+++ b/OpenSim/Framework/AvatarAppearance.cs
@@ -405,31 +405,40 @@ namespace OpenSim.Framework
405 /// </remarks> 405 /// </remarks>
406 public List<AvatarAttachment> GetAttachments() 406 public List<AvatarAttachment> GetAttachments()
407 { 407 {
408
409
408 lock (m_attachments) 410 lock (m_attachments)
409 { 411 {
410 List<AvatarAttachment> alist = new List<AvatarAttachment>(); 412 List<AvatarAttachment> alist = new List<AvatarAttachment>();
411 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments) 413 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
412 { 414 {
413 foreach (AvatarAttachment attach in kvp.Value) 415 foreach (AvatarAttachment attach in kvp.Value)
414 alist.Add(new AvatarAttachment(attach)); 416 alist.Add(new AvatarAttachment(attach));
415 } 417 }
416 418 return alist;
417 return alist; 419 } }
418 }
419 }
420 420
421 internal void AppendAttachment(AvatarAttachment attach) 421 internal void AppendAttachment(AvatarAttachment attach)
422 { 422 {
423// m_log.DebugFormat(
424// "[AVATAR APPEARNCE]: Appending itemID={0}, assetID={1} at {2}",
425// attach.ItemID, attach.AssetID, attach.AttachPoint);
426
423 lock (m_attachments) 427 lock (m_attachments)
424 { 428 {
425 if (!m_attachments.ContainsKey(attach.AttachPoint)) 429 if (!m_attachments.ContainsKey(attach.AttachPoint))
426 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>(); 430 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
431
427 m_attachments[attach.AttachPoint].Add(attach); 432 m_attachments[attach.AttachPoint].Add(attach);
428 } 433 }
429 } 434 }
430 435
431 internal void ReplaceAttachment(AvatarAttachment attach) 436 internal void ReplaceAttachment(AvatarAttachment attach)
432 { 437 {
438// m_log.DebugFormat(
439// "[AVATAR APPEARANCE]: Replacing itemID={0}, assetID={1} at {2}",
440// attach.ItemID, attach.AssetID, attach.AttachPoint);
441
433 lock (m_attachments) 442 lock (m_attachments)
434 { 443 {
435 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>(); 444 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
@@ -438,7 +447,7 @@ namespace OpenSim.Framework
438 } 447 }
439 448
440 /// <summary> 449 /// <summary>
441 /// Add an attachment 450 /// Set an attachment
442 /// </summary> 451 /// </summary>
443 /// <remarks> 452 /// <remarks>
444 /// If the attachpoint has the 453 /// If the attachpoint has the
@@ -454,13 +463,13 @@ namespace OpenSim.Framework
454 /// </returns> 463 /// </returns>
455 public bool SetAttachment(int attachpoint, UUID item, UUID asset) 464 public bool SetAttachment(int attachpoint, UUID item, UUID asset)
456 { 465 {
457 if (attachpoint == 0)
458 return false;
459
460// m_log.DebugFormat( 466// m_log.DebugFormat(
461// "[AVATAR APPEARANCE]: Setting attachment at {0} with item ID {1}, asset ID {2}", 467// "[AVATAR APPEARANCE]: Setting attachment at {0} with item ID {1}, asset ID {2}",
462// attachpoint, item, asset); 468// attachpoint, item, asset);
463 469
470 if (attachpoint == 0)
471 return false;
472
464 if (item == UUID.Zero) 473 if (item == UUID.Zero)
465 { 474 {
466 lock (m_attachments) 475 lock (m_attachments)
@@ -470,12 +479,21 @@ namespace OpenSim.Framework
470 m_attachments.Remove(attachpoint); 479 m_attachments.Remove(attachpoint);
471 return true; 480 return true;
472 } 481 }
473 return false;
474 } 482 }
483
484 return false;
475 } 485 }
476 486
477 // check if the item is already attached at this point 487 // When a user logs in, the attachment item ids are pulled from persistence in the Avatars table. However,
478 if (GetAttachpoint(item) == (attachpoint & 0x7F)) 488 // the asset ids are not saved. When the avatar enters a simulator the attachments are set again. If
489 // we simply perform an item check here then the asset ids (which are now present) are never set, and NPC attachments
490 // later fail unless the attachment is detached and reattached.
491 //
492 // Therefore, we will carry on with the set if the existing attachment has no asset id.
493 AvatarAttachment existingAttachment = GetAttachmentForItem(item);
494 if (existingAttachment != null
495 && existingAttachment.AssetID != UUID.Zero
496 && existingAttachment.AttachPoint == (attachpoint & 0x7F))
479 { 497 {
480 // m_log.DebugFormat("[AVATAR APPEARANCE] attempt to attach an already attached item {0}",item); 498 // m_log.DebugFormat("[AVATAR APPEARANCE] attempt to attach an already attached item {0}",item);
481 return false; 499 return false;
@@ -492,9 +510,30 @@ namespace OpenSim.Framework
492 { 510 {
493 ReplaceAttachment(new AvatarAttachment(attachpoint,item, asset)); 511 ReplaceAttachment(new AvatarAttachment(attachpoint,item, asset));
494 } 512 }
513
495 return true; 514 return true;
496 } 515 }
497 516
517 /// <summary>
518 /// If the item is already attached, return it.
519 /// </summary>
520 /// <param name="itemID"></param>
521 /// <returns>Returns null if this item is not attached.</returns>
522 public AvatarAttachment GetAttachmentForItem(UUID itemID)
523 {
524 lock (m_attachments)
525 {
526 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
527 {
528 int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
529 if (index >= 0)
530 return kvp.Value[index];
531 }
532 }
533
534 return null;
535 }
536
498 public int GetAttachpoint(UUID itemID) 537 public int GetAttachpoint(UUID itemID)
499 { 538 {
500 lock (m_attachments) 539 lock (m_attachments)
@@ -505,9 +544,8 @@ namespace OpenSim.Framework
505 if (index >= 0) 544 if (index >= 0)
506 return kvp.Key; 545 return kvp.Key;
507 } 546 }
508
509 return 0;
510 } 547 }
548 return 0;
511 } 549 }
512 550
513 public bool DetachAttachment(UUID itemID) 551 public bool DetachAttachment(UUID itemID)
@@ -521,23 +559,23 @@ namespace OpenSim.Framework
521 { 559 {
522 // Remove it from the list of attachments at that attach point 560 // Remove it from the list of attachments at that attach point
523 m_attachments[kvp.Key].RemoveAt(index); 561 m_attachments[kvp.Key].RemoveAt(index);
524 562
525 // And remove the list if there are no more attachments here 563 // And remove the list if there are no more attachments here
526 if (m_attachments[kvp.Key].Count == 0) 564 if (m_attachments[kvp.Key].Count == 0)
527 m_attachments.Remove(kvp.Key); 565 m_attachments.Remove(kvp.Key);
566
528 return true; 567 return true;
529 } 568 }
530 } 569 }
531 } 570 }
571
532 return false; 572 return false;
533 } 573 }
534 574
535 public void ClearAttachments() 575 public void ClearAttachments()
536 { 576 {
537 lock (m_attachments) 577 lock (m_attachments)
538 {
539 m_attachments.Clear(); 578 m_attachments.Clear();
540 }
541 } 579 }
542 580
543 #region Packing Functions 581 #region Packing Functions