diff options
author | Dan Lake | 2011-10-03 16:44:32 -0700 |
---|---|---|
committer | Dan Lake | 2011-10-03 16:44:32 -0700 |
commit | 460946ad62b682c7a942751f192ca9e96b662f0e (patch) | |
tree | 3ea7d72402d5b61221bb2c0bcd5fb9b5e7551d5f /OpenSim/Region/CoreModules | |
parent | Remove usage of Linden packet types from inside Attachments Module and interface (diff) | |
download | opensim-SC_OLD-460946ad62b682c7a942751f192ca9e96b662f0e.zip opensim-SC_OLD-460946ad62b682c7a942751f192ca9e96b662f0e.tar.gz opensim-SC_OLD-460946ad62b682c7a942751f192ca9e96b662f0e.tar.bz2 opensim-SC_OLD-460946ad62b682c7a942751f192ca9e96b662f0e.tar.xz |
Removed redundant code in AttachmentsModule and simplified interfaces which converted back and forth between ScenePresence and IClientAPI. More to be done still.
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | 158 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | 10 |
2 files changed, 73 insertions, 95 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index 48695a4..78b9afc 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | |||
@@ -152,7 +152,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
152 | if (sp.PresenceType == PresenceType.Npc) | 152 | if (sp.PresenceType == PresenceType.Npc) |
153 | RezSingleAttachmentFromInventoryInternal(sp, UUID.Zero, attach.AssetID, p); | 153 | RezSingleAttachmentFromInventoryInternal(sp, UUID.Zero, attach.AssetID, p); |
154 | else | 154 | else |
155 | RezSingleAttachmentFromInventory(sp.ControllingClient, attach.ItemID, p); | 155 | RezSingleAttachmentFromInventory(sp, attach.ItemID, p); |
156 | } | 156 | } |
157 | catch (Exception e) | 157 | catch (Exception e) |
158 | { | 158 | { |
@@ -204,7 +204,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
204 | /// <param name="objectLocalID"></param> | 204 | /// <param name="objectLocalID"></param> |
205 | /// <param name="AttachmentPt"></param> | 205 | /// <param name="AttachmentPt"></param> |
206 | /// <param name="silent"></param> | 206 | /// <param name="silent"></param> |
207 | public void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent) | 207 | private void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent) |
208 | { | 208 | { |
209 | // m_log.DebugFormat( | 209 | // m_log.DebugFormat( |
210 | // "[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})", | 210 | // "[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})", |
@@ -258,25 +258,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
258 | m_log.ErrorFormat("[ATTACHMENTS MODULE]: exception upon Attach Object {0}{1}", e.Message, e.StackTrace); | 258 | m_log.ErrorFormat("[ATTACHMENTS MODULE]: exception upon Attach Object {0}{1}", e.Message, e.StackTrace); |
259 | } | 259 | } |
260 | } | 260 | } |
261 | |||
262 | public bool AttachObject(IClientAPI remoteClient, SceneObjectGroup group, uint AttachmentPt, bool silent) | ||
263 | { | ||
264 | if (!Enabled) | ||
265 | return false; | ||
266 | |||
267 | ScenePresence sp = m_scene.GetScenePresence(remoteClient.AgentId); | ||
268 | |||
269 | if (sp == null) | ||
270 | { | ||
271 | m_log.ErrorFormat( | ||
272 | "[ATTACHMENTS MODULE]: Could not find presence for client {0} {1}", remoteClient.Name, remoteClient.AgentId); | ||
273 | return false; | ||
274 | } | ||
275 | |||
276 | return AttachObject(sp, group, AttachmentPt, silent); | ||
277 | } | ||
278 | 261 | ||
279 | private bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent) | 262 | public bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent) |
280 | { | 263 | { |
281 | lock (sp.AttachmentsSyncLock) | 264 | lock (sp.AttachmentsSyncLock) |
282 | { | 265 | { |
@@ -356,29 +339,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
356 | } | 339 | } |
357 | 340 | ||
358 | return true; | 341 | return true; |
342 | } | ||
343 | |||
344 | private void RezMultipleAttachmentsFromInventory(IClientAPI remoteClient, List<KeyValuePair<UUID, uint>> rezlist) | ||
345 | { | ||
346 | if (!Enabled) | ||
347 | return; | ||
348 | |||
349 | ScenePresence sp; | ||
350 | if (m_scene.TryGetScenePresence(remoteClient.AgentId, out sp)) | ||
351 | RezMultipleAttachmentsFromInventory(sp, rezlist); | ||
352 | else | ||
353 | m_log.ErrorFormat( | ||
354 | "[ATTACHMENTS MODULE]: Could not find presence for client {0} {1} in RezMultipleAttachmentsFromInventory()", | ||
355 | remoteClient.Name, remoteClient.AgentId); | ||
356 | return; | ||
359 | } | 357 | } |
360 | 358 | ||
361 | public void RezMultipleAttachmentsFromInventory( | 359 | public void RezMultipleAttachmentsFromInventory(IScenePresence sp, List<KeyValuePair<UUID, uint>> rezlist) |
362 | IClientAPI remoteClient, | ||
363 | List<KeyValuePair<UUID, uint>> rezlist) | ||
364 | { | 360 | { |
365 | if (!Enabled) | 361 | if (!Enabled) |
366 | return; | 362 | return; |
367 | 363 | ||
368 | ScenePresence sp = m_scene.GetScenePresence(remoteClient.AgentId); | 364 | // m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing multiple attachments from inventory for {0}", sp.Name); |
369 | |||
370 | if (sp == null) | ||
371 | { | ||
372 | m_log.ErrorFormat( | ||
373 | "[ATTACHMENTS MODULE]: Could not find presence for client {0} {1} in RezMultipleAttachmentsFromInventory()", | ||
374 | remoteClient.Name, remoteClient.AgentId); | ||
375 | return; | ||
376 | } | ||
377 | |||
378 | lock (sp.AttachmentsSyncLock) | 365 | lock (sp.AttachmentsSyncLock) |
379 | { | 366 | { |
380 | // m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing multiple attachments from inventory for {0}", sp.Name); | ||
381 | |||
382 | foreach (KeyValuePair<UUID, uint> rez in rezlist) | 367 | foreach (KeyValuePair<UUID, uint> rez in rezlist) |
383 | { | 368 | { |
384 | RezSingleAttachmentFromInventory(sp, rez.Key, rez.Value); | 369 | RezSingleAttachmentFromInventory(sp, rez.Key, rez.Value); |
@@ -386,7 +371,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
386 | } | 371 | } |
387 | } | 372 | } |
388 | 373 | ||
389 | public ISceneEntity RezSingleAttachmentFromInventory(IClientAPI remoteClient, UUID itemID, uint AttachmentPt) | 374 | private ISceneEntity RezSingleAttachmentFromInventory(IClientAPI remoteClient, UUID itemID, uint AttachmentPt) |
390 | { | 375 | { |
391 | if (!Enabled) | 376 | if (!Enabled) |
392 | return null; | 377 | return null; |
@@ -408,7 +393,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
408 | return RezSingleAttachmentFromInventory(sp, itemID, AttachmentPt); | 393 | return RezSingleAttachmentFromInventory(sp, itemID, AttachmentPt); |
409 | } | 394 | } |
410 | 395 | ||
411 | public ISceneEntity RezSingleAttachmentFromInventory(ScenePresence sp, UUID itemID, uint AttachmentPt) | 396 | public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt) |
412 | { | 397 | { |
413 | if (!Enabled) | 398 | if (!Enabled) |
414 | return null; | 399 | return null; |
@@ -593,23 +578,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
593 | DetachSingleAttachmentToInv(itemID, presence); | 578 | DetachSingleAttachmentToInv(itemID, presence); |
594 | } | 579 | } |
595 | } | 580 | } |
581 | } | ||
582 | |||
583 | private void DetachSingleAttachmentToGround(uint soLocalId, IClientAPI remoteClient) | ||
584 | { | ||
585 | if (!Enabled) | ||
586 | return; | ||
587 | |||
588 | ScenePresence sp; | ||
589 | if (m_scene.TryGetScenePresence(remoteClient.AgentId, out sp)) | ||
590 | DetachSingleAttachmentToGround(sp, soLocalId); | ||
596 | } | 591 | } |
597 | 592 | ||
598 | public void DetachSingleAttachmentToGround(uint soLocalId, IClientAPI remoteClient) | 593 | public void DetachSingleAttachmentToGround(IScenePresence sp, uint soLocalId) |
599 | { | 594 | { |
600 | if (!Enabled) | 595 | if (!Enabled) |
601 | return; | 596 | return; |
602 | 597 | ||
603 | // m_log.DebugFormat( | 598 | // m_log.DebugFormat( |
604 | // "[ATTACHMENTS MODULE]: DetachSingleAttachmentToGround() for {0}, object {1}", | 599 | // "[ATTACHMENTS MODULE]: DetachSingleAttachmentToGround() for {0}, object {1}", |
605 | // remoteClient.Name, soLocalId); | 600 | // sp.UUID, soLocalId); |
606 | 601 | ||
607 | SceneObjectGroup so = m_scene.GetGroupByPrim(soLocalId); | 602 | SceneObjectGroup so = m_scene.GetGroupByPrim(soLocalId); |
608 | 603 | ||
609 | if (so == null) | 604 | if (so == null) |
610 | return; | 605 | return; |
611 | 606 | ||
612 | if (so.AttachedAvatar != remoteClient.AgentId) | 607 | if (so.AttachedAvatar != sp.UUID) |
613 | return; | 608 | return; |
614 | 609 | ||
615 | UUID inventoryID = so.GetFromItemID(); | 610 | UUID inventoryID = so.GetFromItemID(); |
@@ -618,57 +613,40 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
618 | // "[ATTACHMENTS MODULE]: In DetachSingleAttachmentToGround(), object is {0} {1}, associated item is {2}", | 613 | // "[ATTACHMENTS MODULE]: In DetachSingleAttachmentToGround(), object is {0} {1}, associated item is {2}", |
619 | // so.Name, so.LocalId, inventoryID); | 614 | // so.Name, so.LocalId, inventoryID); |
620 | 615 | ||
621 | ScenePresence presence; | 616 | lock (sp.AttachmentsSyncLock) |
622 | if (m_scene.TryGetScenePresence(remoteClient.AgentId, out presence)) | ||
623 | { | 617 | { |
624 | lock (presence.AttachmentsSyncLock) | 618 | if (!m_scene.Permissions.CanRezObject( |
625 | { | 619 | so.PrimCount, sp.UUID, sp.AbsolutePosition)) |
626 | if (!m_scene.Permissions.CanRezObject( | 620 | return; |
627 | so.PrimCount, remoteClient.AgentId, presence.AbsolutePosition)) | 621 | |
628 | return; | 622 | bool changed = sp.Appearance.DetachAttachment(inventoryID); |
629 | 623 | if (changed && m_scene.AvatarFactory != null) | |
630 | bool changed = presence.Appearance.DetachAttachment(inventoryID); | 624 | m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID); |
631 | if (changed && m_scene.AvatarFactory != null) | 625 | |
632 | m_scene.AvatarFactory.QueueAppearanceSave(remoteClient.AgentId); | 626 | sp.RemoveAttachment(so); |
633 | 627 | ||
634 | presence.RemoveAttachment(so); | 628 | SceneObjectPart rootPart = so.RootPart; |
635 | DetachSceneObjectToGround(so, presence); | 629 | rootPart.FromItemID = UUID.Zero; |
636 | 630 | so.AbsolutePosition = sp.AbsolutePosition; | |
637 | List<UUID> uuids = new List<UUID>(); | 631 | so.AttachedAvatar = UUID.Zero; |
638 | uuids.Add(inventoryID); | 632 | rootPart.SetParentLocalId(0); |
639 | m_scene.InventoryService.DeleteItems(remoteClient.AgentId, uuids); | 633 | so.ClearPartAttachmentData(); |
640 | remoteClient.SendRemoveInventoryItem(inventoryID); | 634 | rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive, m_scene.m_physicalPrim); |
641 | } | 635 | so.HasGroupChanged = true; |
642 | 636 | rootPart.Rezzed = DateTime.Now; | |
643 | m_scene.EventManager.TriggerOnAttach(so.LocalId, so.UUID, UUID.Zero); | 637 | rootPart.RemFlag(PrimFlags.TemporaryOnRez); |
638 | so.AttachToBackup(); | ||
639 | m_scene.EventManager.TriggerParcelPrimCountTainted(); | ||
640 | rootPart.ScheduleFullUpdate(); | ||
641 | rootPart.ClearUndoState(); | ||
642 | |||
643 | List<UUID> uuids = new List<UUID>(); | ||
644 | uuids.Add(inventoryID); | ||
645 | m_scene.InventoryService.DeleteItems(sp.UUID, uuids); | ||
646 | sp.ControllingClient.SendRemoveInventoryItem(inventoryID); | ||
644 | } | 647 | } |
645 | } | ||
646 | 648 | ||
647 | /// <summary> | 649 | m_scene.EventManager.TriggerOnAttach(so.LocalId, so.UUID, UUID.Zero); |
648 | /// Detach the given scene object to the ground. | ||
649 | /// </summary> | ||
650 | /// <remarks> | ||
651 | /// The caller has to take care of all the other work in updating avatar appearance, inventory, etc. | ||
652 | /// </remarks> | ||
653 | /// <param name="so">The scene object to detach.</param> | ||
654 | /// <param name="sp">The scene presence from which the scene object is being detached.</param> | ||
655 | private void DetachSceneObjectToGround(SceneObjectGroup so, ScenePresence sp) | ||
656 | { | ||
657 | SceneObjectPart rootPart = so.RootPart; | ||
658 | |||
659 | rootPart.FromItemID = UUID.Zero; | ||
660 | so.AbsolutePosition = sp.AbsolutePosition; | ||
661 | so.AttachedAvatar = UUID.Zero; | ||
662 | rootPart.SetParentLocalId(0); | ||
663 | so.ClearPartAttachmentData(); | ||
664 | rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive, m_scene.m_physicalPrim); | ||
665 | so.HasGroupChanged = true; | ||
666 | rootPart.Rezzed = DateTime.Now; | ||
667 | rootPart.RemFlag(PrimFlags.TemporaryOnRez); | ||
668 | so.AttachToBackup(); | ||
669 | m_scene.EventManager.TriggerParcelPrimCountTainted(); | ||
670 | rootPart.ScheduleFullUpdate(); | ||
671 | rootPart.ClearUndoState(); | ||
672 | } | 650 | } |
673 | 651 | ||
674 | // What makes this method odd and unique is it tries to detach using an UUID.... Yay for standards. | 652 | // What makes this method odd and unique is it tries to detach using an UUID.... Yay for standards. |
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs index ff3358f..832c6eb 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | |||
@@ -106,7 +106,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
106 | 106 | ||
107 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName).ParentGroup; | 107 | SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName).ParentGroup; |
108 | 108 | ||
109 | m_attMod.AttachObject(m_presence.ControllingClient, so, (uint)AttachmentPoint.Chest, false); | 109 | m_attMod.AttachObject(m_presence, so, (uint)AttachmentPoint.Chest, false); |
110 | 110 | ||
111 | // Check status on scene presence | 111 | // Check status on scene presence |
112 | Assert.That(m_presence.HasAttachments(), Is.True); | 112 | Assert.That(m_presence.HasAttachments(), Is.True); |
@@ -140,7 +140,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
140 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); | 140 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); |
141 | 141 | ||
142 | m_attMod.RezSingleAttachmentFromInventory( | 142 | m_attMod.RezSingleAttachmentFromInventory( |
143 | m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); | 143 | m_presence, attItemId, (uint)AttachmentPoint.Chest); |
144 | 144 | ||
145 | // Check scene presence status | 145 | // Check scene presence status |
146 | Assert.That(m_presence.HasAttachments(), Is.True); | 146 | Assert.That(m_presence.HasAttachments(), Is.True); |
@@ -174,8 +174,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
174 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); | 174 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); |
175 | 175 | ||
176 | ISceneEntity so = m_attMod.RezSingleAttachmentFromInventory( | 176 | ISceneEntity so = m_attMod.RezSingleAttachmentFromInventory( |
177 | m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); | 177 | m_presence, attItemId, (uint)AttachmentPoint.Chest); |
178 | m_attMod.DetachSingleAttachmentToGround(so.LocalId, m_presence.ControllingClient); | 178 | m_attMod.DetachSingleAttachmentToGround(m_presence, so.LocalId); |
179 | 179 | ||
180 | // Check scene presence status | 180 | // Check scene presence status |
181 | Assert.That(m_presence.HasAttachments(), Is.False); | 181 | Assert.That(m_presence.HasAttachments(), Is.False); |
@@ -208,7 +208,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | |||
208 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); | 208 | scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); |
209 | 209 | ||
210 | m_attMod.RezSingleAttachmentFromInventory( | 210 | m_attMod.RezSingleAttachmentFromInventory( |
211 | m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); | 211 | m_presence, attItemId, (uint)AttachmentPoint.Chest); |
212 | m_attMod.DetachSingleAttachmentToInv(attItemId, m_presence.ControllingClient); | 212 | m_attMod.DetachSingleAttachmentToInv(attItemId, m_presence.ControllingClient); |
213 | 213 | ||
214 | // Check status on scene presence | 214 | // Check status on scene presence |