diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | 124 |
1 files changed, 61 insertions, 63 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index ab7e932..2dea14d 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | |||
@@ -289,21 +289,22 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
289 | if (!Enabled) | 289 | if (!Enabled) |
290 | return false; | 290 | return false; |
291 | 291 | ||
292 | if (AttachObjectInternal(sp, group, attachmentPt, silent, temp, append)) | 292 | return AttachObjectInternal(sp, group, attachmentPt, silent, temp, append); |
293 | { | ||
294 | m_scene.EventManager.TriggerOnAttach(group.LocalId, group.FromItemID, sp.UUID); | ||
295 | return true; | ||
296 | } | ||
297 | |||
298 | return false; | ||
299 | } | 293 | } |
300 | |||
301 | private bool AttachObjectInternal(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool temp, bool append) | ||
302 | { | ||
303 | // m_log.DebugFormat( | ||
304 | // "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})", | ||
305 | // group.Name, group.LocalId, sp.Name, attachmentPt, silent); | ||
306 | 294 | ||
295 | /// <summary> | ||
296 | /// Internal method which actually does all the work for attaching an object. | ||
297 | /// </summary> | ||
298 | /// <returns>The object attached.</returns> | ||
299 | /// <param name='sp'></param> | ||
300 | /// <param name='group'>The object to attach.</param> | ||
301 | /// <param name='attachmentPt'></param> | ||
302 | /// <param name='silent'></param> | ||
303 | /// <param name='temp'></param> | ||
304 | /// <param name='resumeScripts'>If true then scripts are resumed on the attached object.</param> | ||
305 | private bool AttachObjectInternal( | ||
306 | IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool temp, bool resumeScripts) | ||
307 | { | ||
307 | if (group.GetSittingAvatarsCount() != 0) | 308 | if (group.GetSittingAvatarsCount() != 0) |
308 | { | 309 | { |
309 | // m_log.WarnFormat( | 310 | // m_log.WarnFormat( |
@@ -314,6 +315,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
314 | } | 315 | } |
315 | 316 | ||
316 | List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); | 317 | List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); |
318 | |||
317 | if (attachments.Contains(group)) | 319 | if (attachments.Contains(group)) |
318 | { | 320 | { |
319 | // m_log.WarnFormat( | 321 | // m_log.WarnFormat( |
@@ -374,6 +376,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
374 | UpdateUserInventoryWithAttachment(sp, group, attachmentPt, temp, append); | 376 | UpdateUserInventoryWithAttachment(sp, group, attachmentPt, temp, append); |
375 | 377 | ||
376 | AttachToAgent(sp, group, attachmentPt, attachPos, silent); | 378 | AttachToAgent(sp, group, attachmentPt, attachPos, silent); |
379 | |||
380 | if (resumeScripts) | ||
381 | { | ||
382 | // Fire after attach, so we don't get messy perms dialogs | ||
383 | // 4 == AttachedRez | ||
384 | group.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 4); | ||
385 | group.ResumeScripts(); | ||
386 | } | ||
387 | |||
388 | // Do this last so that event listeners have access to all the effects of the attachment | ||
389 | m_scene.EventManager.TriggerOnAttach(group.LocalId, group.FromItemID, sp.UUID); | ||
377 | } | 390 | } |
378 | 391 | ||
379 | return true; | 392 | return true; |
@@ -400,8 +413,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
400 | return null; | 413 | return null; |
401 | 414 | ||
402 | // m_log.DebugFormat( | 415 | // m_log.DebugFormat( |
403 | // "[ATTACHMENTS MODULE]: RezSingleAttachmentFromInventory to point {0} from item {1} for {2}", | 416 | // "[ATTACHMENTS MODULE]: RezSingleAttachmentFromInventory to point {0} from item {1} for {2} in {3}", |
404 | // (AttachmentPoint)AttachmentPt, itemID, sp.Name); | 417 | // (AttachmentPoint)AttachmentPt, itemID, sp.Name, m_scene.Name); |
405 | 418 | ||
406 | bool append = (AttachmentPt & 0x80) != 0; | 419 | bool append = (AttachmentPt & 0x80) != 0; |
407 | AttachmentPt &= 0x7f; | 420 | AttachmentPt &= 0x7f; |
@@ -533,6 +546,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
533 | return; | 546 | return; |
534 | } | 547 | } |
535 | 548 | ||
549 | // m_log.DebugFormat( | ||
550 | // "[ATTACHMENTS MODULE]: Detaching object {0} {1} for {2} in {3}", | ||
551 | // so.Name, so.LocalId, sp.Name, m_scene.Name); | ||
552 | |||
536 | // Scripts MUST be snapshotted before the object is | 553 | // Scripts MUST be snapshotted before the object is |
537 | // removed from the scene because doing otherwise will | 554 | // removed from the scene because doing otherwise will |
538 | // clobber the run flag | 555 | // clobber the run flag |
@@ -854,61 +871,42 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
854 | return null; | 871 | return null; |
855 | } | 872 | } |
856 | 873 | ||
857 | // Remove any previous attachments | ||
858 | List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); | ||
859 | string previousAttachmentScriptedState = null; | ||
860 | |||
861 | // At the moment we can only deal with a single attachment | ||
862 | if (attachments.Count != 0) | ||
863 | DetachSingleAttachmentToInv(sp, attachments[0]); | ||
864 | |||
865 | lock (sp.AttachmentsSyncLock) | ||
866 | { | ||
867 | // m_log.DebugFormat( | 874 | // m_log.DebugFormat( |
868 | // "[ATTACHMENTS MODULE]: Rezzed single object {0} for attachment to {1} on point {2} in {3}", | 875 | // "[ATTACHMENTS MODULE]: Rezzed single object {0} for attachment to {1} on point {2} in {3}", |
869 | // objatt.Name, sp.Name, attachmentPt, m_scene.Name); | 876 | // objatt.Name, sp.Name, attachmentPt, m_scene.Name); |
870 | 877 | ||
871 | // HasGroupChanged is being set from within RezObject. Ideally it would be set by the caller. | 878 | // HasGroupChanged is being set from within RezObject. Ideally it would be set by the caller. |
872 | objatt.HasGroupChanged = false; | 879 | objatt.HasGroupChanged = false; |
873 | bool tainted = false; | 880 | bool tainted = false; |
874 | if (attachmentPt != 0 && attachmentPt != objatt.AttachmentPoint) | 881 | if (attachmentPt != 0 && attachmentPt != objatt.AttachmentPoint) |
875 | tainted = true; | 882 | tainted = true; |
876 | 883 | ||
877 | // FIXME: Detect whether it's really likely for AttachObject to throw an exception in the normal | 884 | // FIXME: Detect whether it's really likely for AttachObject to throw an exception in the normal |
878 | // course of events. If not, then it's probably not worth trying to recover the situation | 885 | // course of events. If not, then it's probably not worth trying to recover the situation |
879 | // since this is more likely to trigger further exceptions and confuse later debugging. If | 886 | // since this is more likely to trigger further exceptions and confuse later debugging. If |
880 | // exceptions can be thrown in expected error conditions (not NREs) then make this consistent | 887 | // exceptions can be thrown in expected error conditions (not NREs) then make this consistent |
881 | // since other normal error conditions will simply return false instead. | 888 | // since other normal error conditions will simply return false instead. |
882 | // This will throw if the attachment fails | 889 | // This will throw if the attachment fails |
883 | try | 890 | try |
884 | { | 891 | { |
885 | AttachObjectInternal(sp, objatt, attachmentPt, false, false, append); | 892 | AttachObjectInternal(sp, objatt, attachmentPt, false, false, append); |
886 | } | 893 | } |
887 | catch (Exception e) | 894 | catch (Exception e) |
888 | { | 895 | { |
889 | m_log.ErrorFormat( | 896 | m_log.ErrorFormat( |
890 | "[ATTACHMENTS MODULE]: Failed to attach {0} {1} for {2}, exception {3}{4}", | 897 | "[ATTACHMENTS MODULE]: Failed to attach {0} {1} for {2}, exception {3}{4}", |
891 | objatt.Name, objatt.UUID, sp.Name, e.Message, e.StackTrace); | 898 | objatt.Name, objatt.UUID, sp.Name, e.Message, e.StackTrace); |
892 | |||
893 | // Make sure the object doesn't stick around and bail | ||
894 | sp.RemoveAttachment(objatt); | ||
895 | m_scene.DeleteSceneObject(objatt, false); | ||
896 | return null; | ||
897 | } | ||
898 | |||
899 | if (tainted) | ||
900 | objatt.HasGroupChanged = true; | ||
901 | 899 | ||
902 | // Fire after attach, so we don't get messy perms dialogs | 900 | // Make sure the object doesn't stick around and bail |
903 | // 4 == AttachedRez | 901 | sp.RemoveAttachment(objatt); |
904 | objatt.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 4); | 902 | m_scene.DeleteSceneObject(objatt, false); |
905 | objatt.ResumeScripts(); | 903 | return null; |
904 | } | ||
906 | 905 | ||
907 | // Do this last so that event listeners have access to all the effects of the attachment | 906 | if (tainted) |
908 | m_scene.EventManager.TriggerOnAttach(objatt.LocalId, itemID, sp.UUID); | 907 | objatt.HasGroupChanged = true; |
909 | 908 | ||
910 | return objatt; | 909 | return objatt; |
911 | } | ||
912 | } | 910 | } |
913 | 911 | ||
914 | /// <summary> | 912 | /// <summary> |