aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar
diff options
context:
space:
mode:
authorMelanie2012-07-11 03:56:50 +0100
committerMelanie2012-07-11 03:56:50 +0100
commit0bc8238a6c25bc42438caee0cf42deec00f26b8e (patch)
treea046cace418e2e7714818c60242698d0dd9cb4f4 /OpenSim/Region/CoreModules/Avatar
parentMerge branch 'avination' into careminster (diff)
parentIf a part has a sit target and an avatar is already sitting, allow another av... (diff)
downloadopensim-SC-0bc8238a6c25bc42438caee0cf42deec00f26b8e.zip
opensim-SC-0bc8238a6c25bc42438caee0cf42deec00f26b8e.tar.gz
opensim-SC-0bc8238a6c25bc42438caee0cf42deec00f26b8e.tar.bz2
opensim-SC-0bc8238a6c25bc42438caee0cf42deec00f26b8e.tar.xz
Merge branch 'master' into careminster
Conflicts: OpenSim/Framework/Watchdog.cs OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs OpenSim/Region/Framework/Scenes/Scene.cs OpenSim/Region/Framework/Scenes/SceneObjectPart.cs OpenSim/Region/Framework/Scenes/ScenePresence.cs
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs161
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs44
2 files changed, 105 insertions, 100 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
index 1fa5ec0..2bb60d5 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
@@ -257,16 +257,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
257 257
258 lock (sp.AttachmentsSyncLock) 258 lock (sp.AttachmentsSyncLock)
259 { 259 {
260 foreach (SceneObjectGroup grp in sp.GetAttachments()) 260 foreach (SceneObjectGroup so in sp.GetAttachments())
261 { 261 {
262 grp.Scene.DeleteSceneObject(grp, false); 262 // We can only remove the script instances from the script engine after we've retrieved their xml state
263 // when we update the attachment item.
264 m_scene.DeleteSceneObject(so, false, false);
263 265
264 if (saveChanged || saveAllScripted) 266 if (saveChanged || saveAllScripted)
265 { 267 {
266 grp.IsAttachment = false; 268 so.IsAttachment = false;
267 grp.AbsolutePosition = grp.RootPart.AttachedPos; 269 so.AbsolutePosition = so.RootPart.AttachedPos;
268 UpdateKnownItem(sp, grp, saveAllScripted); 270 UpdateKnownItem(sp, so, saveAllScripted);
269 } 271 }
272
273 so.RemoveScriptInstances(true);
270 } 274 }
271 275
272 sp.ClearAttachments(); 276 sp.ClearAttachments();
@@ -297,6 +301,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
297// m_log.DebugFormat( 301// m_log.DebugFormat(
298// "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})", 302// "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})",
299// group.Name, group.LocalId, sp.Name, attachmentPt, silent); 303// group.Name, group.LocalId, sp.Name, attachmentPt, silent);
304
305 if (group.GetSittingAvatarsCount() != 0)
306 {
307// m_log.WarnFormat(
308// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since {4} avatars are still sitting on it",
309// group.Name, group.LocalId, sp.Name, attachmentPt, group.GetSittingAvatarsCount());
310
311 return false;
312 }
300 313
301 if (sp.GetAttachments(attachmentPt).Contains(group)) 314 if (sp.GetAttachments(attachmentPt).Contains(group))
302 { 315 {
@@ -357,30 +370,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
357 group.AttachmentPoint = attachmentPt; 370 group.AttachmentPoint = attachmentPt;
358 group.AbsolutePosition = attachPos; 371 group.AbsolutePosition = attachPos;
359 372
360 // We also don't want to do any of the inventory operations for an NPC.
361 if (sp.PresenceType != PresenceType.Npc) 373 if (sp.PresenceType != PresenceType.Npc)
362 { 374 UpdateUserInventoryWithAttachment(sp, group, attachmentPt);
363 // Remove any previous attachments
364 List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt);
365
366 // At the moment we can only deal with a single attachment
367 if (attachments.Count != 0)
368 {
369 if (attachments[0].FromItemID != UUID.Zero)
370 DetachSingleAttachmentToInvInternal(sp, attachments[0]);
371 else
372 m_log.WarnFormat(
373 "[ATTACHMENTS MODULE]: When detaching existing attachment {0} {1} at point {2} to make way for {3} {4} for {5}, couldn't find the associated item ID to adjust inventory attachment record!",
374 attachments[0].Name, attachments[0].LocalId, attachmentPt, group.Name, group.LocalId, sp.Name);
375 }
376
377 // Add the new attachment to inventory if we don't already have it.
378 UUID newAttachmentItemID = group.FromItemID;
379 if (newAttachmentItemID == UUID.Zero)
380 newAttachmentItemID = AddSceneObjectAsNewAttachmentInInv(sp, group).ID;
381
382 ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group);
383 }
384 375
385 AttachToAgent(sp, group, attachmentPt, attachPos, silent); 376 AttachToAgent(sp, group, attachmentPt, attachPos, silent);
386 } 377 }
@@ -388,6 +379,30 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
388 return true; 379 return true;
389 } 380 }
390 381
382 private void UpdateUserInventoryWithAttachment(IScenePresence sp, SceneObjectGroup group, uint attachmentPt)
383 {
384 // Remove any previous attachments
385 List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt);
386
387 // At the moment we can only deal with a single attachment
388 if (attachments.Count != 0)
389 {
390 if (attachments[0].FromItemID != UUID.Zero)
391 DetachSingleAttachmentToInvInternal(sp, attachments[0]);
392 else
393 m_log.WarnFormat(
394 "[ATTACHMENTS MODULE]: When detaching existing attachment {0} {1} at point {2} to make way for {3} {4} for {5}, couldn't find the associated item ID to adjust inventory attachment record!",
395 attachments[0].Name, attachments[0].LocalId, attachmentPt, group.Name, group.LocalId, sp.Name);
396 }
397
398 // Add the new attachment to inventory if we don't already have it.
399 UUID newAttachmentItemID = group.FromItemID;
400 if (newAttachmentItemID == UUID.Zero)
401 newAttachmentItemID = AddSceneObjectAsNewAttachmentInInv(sp, group).ID;
402
403 ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group);
404 }
405
391 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt) 406 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt)
392 { 407 {
393 return RezSingleAttachmentFromInventory(sp, itemID, AttachmentPt, true, null); 408 return RezSingleAttachmentFromInventory(sp, itemID, AttachmentPt, true, null);
@@ -721,79 +736,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
721 // "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}", 736 // "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}",
722 // grp.Name, grp.LocalId, remoteClient.Name); 737 // grp.Name, grp.LocalId, remoteClient.Name);
723 738
724// Vector3 inventoryStoredPosition = new Vector3 739 InventoryItemBase newItem
725// (((grp.AbsolutePosition.X > (int)Constants.RegionSize) 740 = m_invAccessModule.CopyToInventory(
726// ? (float)Constants.RegionSize - 6 741 DeRezAction.TakeCopy,
727// : grp.AbsolutePosition.X) 742 m_scene.InventoryService.GetFolderForType(sp.UUID, AssetType.Object).ID,
728// , 743 new List<SceneObjectGroup> { grp },
729// (grp.AbsolutePosition.Y > (int)Constants.RegionSize) 744 sp.ControllingClient, true)[0];
730// ? (float)Constants.RegionSize - 6
731// : grp.AbsolutePosition.Y,
732// grp.AbsolutePosition.Z);
733//
734// Vector3 originalPosition = grp.AbsolutePosition;
735//
736// grp.AbsolutePosition = inventoryStoredPosition;
737
738 // If we're being called from a script, then trying to serialize that same script's state will not complete
739 // in any reasonable time period. Therefore, we'll avoid it. The worst that can happen is that if
740 // the client/server crashes rather than logging out normally, the attachment's scripts will resume
741 // without state on relog. Arguably, this is what we want anyway.
742 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp, false);
743
744// grp.AbsolutePosition = originalPosition;
745
746 AssetBase asset = m_scene.CreateAsset(
747 grp.GetPartName(grp.LocalId),
748 grp.GetPartDescription(grp.LocalId),
749 (sbyte)AssetType.Object,
750 Utils.StringToBytes(sceneObjectXml),
751 sp.UUID);
752
753 m_scene.AssetService.Store(asset);
754
755 InventoryItemBase item = new InventoryItemBase();
756 item.CreatorId = grp.RootPart.CreatorID.ToString();
757 item.CreatorData = grp.RootPart.CreatorData;
758 item.Owner = sp.UUID;
759 item.ID = UUID.Random();
760 item.AssetID = asset.FullID;
761 item.Description = asset.Description;
762 item.Name = asset.Name;
763 item.AssetType = asset.Type;
764 item.InvType = (int)InventoryType.Object;
765
766 InventoryFolderBase folder = m_scene.InventoryService.GetFolderForType(sp.UUID, AssetType.Object);
767 if (folder != null)
768 item.Folder = folder.ID;
769 else // oopsies
770 item.Folder = UUID.Zero;
771
772 // Nix the special bits we used to use for slam and the folded perms
773 uint allowablePermissionsMask = (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify | PermissionMask.Move);
774
775 if ((sp.UUID != grp.RootPart.OwnerID) && m_scene.Permissions.PropagatePermissions())
776 {
777 item.BasePermissions = grp.RootPart.BaseMask & grp.RootPart.NextOwnerMask & allowablePermissionsMask;
778 item.CurrentPermissions = grp.RootPart.BaseMask & grp.RootPart.NextOwnerMask & allowablePermissionsMask;
779 item.NextPermissions = grp.RootPart.NextOwnerMask & allowablePermissionsMask;
780 item.EveryOnePermissions = grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask & allowablePermissionsMask;
781 item.GroupPermissions = grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask & allowablePermissionsMask;
782 }
783 else
784 {
785 item.BasePermissions = grp.RootPart.BaseMask & allowablePermissionsMask;
786 item.CurrentPermissions = grp.RootPart.OwnerMask & allowablePermissionsMask;
787 item.NextPermissions = grp.RootPart.NextOwnerMask & allowablePermissionsMask;
788 item.EveryOnePermissions = grp.RootPart.EveryoneMask & allowablePermissionsMask;
789 item.GroupPermissions = grp.RootPart.GroupMask & allowablePermissionsMask;
790 }
791 item.CreationDate = Util.UnixTimeSinceEpoch();
792 745
793 // sets itemID so client can show item as 'attached' in inventory 746 // sets itemID so client can show item as 'attached' in inventory
794 grp.FromItemID = item.ID; 747 grp.FromItemID = newItem.ID;
795 748
796 return item; 749 return newItem;
797 } 750 }
798 751
799 private void DetachSingleAttachmentToInvInternal(IScenePresence sp, SceneObjectGroup so) 752 private void DetachSingleAttachmentToInvInternal(IScenePresence sp, SceneObjectGroup so)
@@ -802,7 +755,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
802 755
803 m_scene.EventManager.TriggerOnAttach(so.LocalId, so.FromItemID, UUID.Zero); 756 m_scene.EventManager.TriggerOnAttach(so.LocalId, so.FromItemID, UUID.Zero);
804 sp.RemoveAttachment(so); 757 sp.RemoveAttachment(so);
805 m_scene.DeleteSceneObject(so, false); 758
759 // We can only remove the script instances from the script engine after we've retrieved their xml state
760 // when we update the attachment item.
761 m_scene.DeleteSceneObject(so, false, false);
806 762
807 // Prepare sog for storage 763 // Prepare sog for storage
808 so.AttachedAvatar = UUID.Zero; 764 so.AttachedAvatar = UUID.Zero;
@@ -811,6 +767,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
811 so.AbsolutePosition = so.RootPart.AttachedPos; 767 so.AbsolutePosition = so.RootPart.AttachedPos;
812 768
813 UpdateKnownItem(sp, so, true); 769 UpdateKnownItem(sp, so, true);
770 so.RemoveScriptInstances(true);
814 } 771 }
815 772
816 protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal( 773 protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal(
@@ -920,7 +877,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
920 item = m_scene.InventoryService.GetItem(item); 877 item = m_scene.InventoryService.GetItem(item);
921 bool changed = sp.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID); 878 bool changed = sp.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID);
922 if (changed && m_scene.AvatarFactory != null) 879 if (changed && m_scene.AvatarFactory != null)
880 {
881// m_log.DebugFormat(
882// "[ATTACHMENTS MODULE]: Queueing appearance save for {0}, attachment {1} point {2} in ShowAttachInUserInventory()",
883// sp.Name, att.Name, AttachmentPt);
884
923 m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID); 885 m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID);
886 }
924 } 887 }
925 888
926 #endregion 889 #endregion
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
index 2eb0ac5..8423d43 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
@@ -118,7 +118,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
118 118
119 Scene scene = CreateDefaultTestScene(); 119 Scene scene = CreateDefaultTestScene();
120 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); 120 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
121 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); 121 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
122 122
123 string attName = "att"; 123 string attName = "att";
124 124
@@ -149,9 +149,41 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
149 InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, AssetType.Object); 149 InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, AssetType.Object);
150 Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID)); 150 Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID));
151 151
152 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
153
152// TestHelpers.DisableLogging(); 154// TestHelpers.DisableLogging();
153 } 155 }
154 156
157 /// <summary>
158 /// Test that we do not attempt to attach an in-world object that someone else is sitting on.
159 /// </summary>
160 [Test]
161 public void TestAddSatOnAttachmentFromGround()
162 {
163 TestHelpers.InMethod();
164// TestHelpers.EnableLogging();
165
166 Scene scene = CreateDefaultTestScene();
167 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
168 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
169
170 string attName = "att";
171
172 SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName, sp.UUID);
173
174 UserAccount ua2 = UserAccountHelpers.CreateUserWithInventory(scene, 0x2);
175 ScenePresence sp2 = SceneHelpers.AddScenePresence(scene, ua2);
176
177 // Put avatar within 10m of the prim so that sit doesn't fail.
178 sp2.AbsolutePosition = new Vector3(0, 0, 0);
179 sp2.HandleAgentRequestSit(sp2.ControllingClient, sp2.UUID, so.UUID, Vector3.Zero);
180
181 scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, false);
182
183 Assert.That(sp.HasAttachments(), Is.False);
184 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
185 }
186
155 [Test] 187 [Test]
156 public void TestAddAttachmentFromInventory() 188 public void TestAddAttachmentFromInventory()
157 { 189 {
@@ -181,6 +213,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
181 // Check appearance status 213 // Check appearance status
182 Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1)); 214 Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
183 Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest)); 215 Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
216
217 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
184 } 218 }
185 219
186 [Test] 220 [Test]
@@ -239,6 +273,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
239 273
240 // Check item status 274 // Check item status
241 Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo(0)); 275 Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo(0));
276
277 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(0));
242 } 278 }
243 279
244 /// <summary> 280 /// <summary>
@@ -300,6 +336,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
300 Assert.That(retreivedAttachments[0].ItemID, Is.EqualTo(attItem.ID)); 336 Assert.That(retreivedAttachments[0].ItemID, Is.EqualTo(attItem.ID));
301 Assert.That(retreivedAttachments[0].AssetID, Is.EqualTo(attItem.AssetID)); 337 Assert.That(retreivedAttachments[0].AssetID, Is.EqualTo(attItem.AssetID));
302 Assert.That(presence.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest)); 338 Assert.That(presence.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
339
340 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
303 } 341 }
304 342
305 [Test] 343 [Test]
@@ -399,6 +437,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
399 Assert.That(actualSceneBAtt.Name, Is.EqualTo(attItem.Name)); 437 Assert.That(actualSceneBAtt.Name, Is.EqualTo(attItem.Name));
400 Assert.That(actualSceneBAtt.AttachmentPoint, Is.EqualTo((uint)AttachmentPoint.Chest)); 438 Assert.That(actualSceneBAtt.AttachmentPoint, Is.EqualTo((uint)AttachmentPoint.Chest));
401 439
440 Assert.That(sceneB.GetSceneObjectGroups().Count, Is.EqualTo(1));
441
402 // Check attachments have been removed from sceneA 442 // Check attachments have been removed from sceneA
403 ScenePresence afterTeleportSceneASp = sceneA.GetScenePresence(ua1.PrincipalID); 443 ScenePresence afterTeleportSceneASp = sceneA.GetScenePresence(ua1.PrincipalID);
404 444
@@ -410,6 +450,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
410 // This is the actual attachment, which should no longer exist 450 // This is the actual attachment, which should no longer exist
411 List<SceneObjectGroup> actualSceneAAttachments = afterTeleportSceneASp.GetAttachments(); 451 List<SceneObjectGroup> actualSceneAAttachments = afterTeleportSceneASp.GetAttachments();
412 Assert.That(actualSceneAAttachments.Count, Is.EqualTo(0)); 452 Assert.That(actualSceneAAttachments.Count, Is.EqualTo(0));
453
454 Assert.That(sceneA.GetSceneObjectGroups().Count, Is.EqualTo(0));
413 } 455 }
414 456
415 // I'm commenting this test because scene setup NEEDS InventoryService to 457 // I'm commenting this test because scene setup NEEDS InventoryService to