aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs596
1 files changed, 291 insertions, 305 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index 298ede9..3317dd3 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -82,7 +82,9 @@ namespace OpenSim.Region.Framework.Scenes
82 /// </value> 82 /// </value>
83 protected internal TaskInventoryDictionary Items 83 protected internal TaskInventoryDictionary Items
84 { 84 {
85 get { return m_items; } 85 get {
86 return m_items;
87 }
86 set 88 set
87 { 89 {
88 m_items = value; 90 m_items = value;
@@ -118,22 +120,25 @@ namespace OpenSim.Region.Framework.Scenes
118 /// <param name="linkNum">Link number for the part</param> 120 /// <param name="linkNum">Link number for the part</param>
119 public void ResetInventoryIDs() 121 public void ResetInventoryIDs()
120 { 122 {
121 lock (Items) 123 m_items.LockItemsForWrite(true);
124
125 if (0 == Items.Count)
122 { 126 {
123 if (0 == Items.Count) 127 m_items.LockItemsForWrite(false);
124 return; 128 return;
129 }
125 130
126 HasInventoryChanged = true; 131 HasInventoryChanged = true;
127 m_part.ParentGroup.HasGroupChanged = true; 132 m_part.ParentGroup.HasGroupChanged = true;
128 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 133 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
129 Items.Clear(); 134 Items.Clear();
130 135
131 foreach (TaskInventoryItem item in items) 136 foreach (TaskInventoryItem item in items)
132 { 137 {
133 item.ResetIDs(m_part.UUID); 138 item.ResetIDs(m_part.UUID);
134 Items.Add(item.ItemID, item); 139 Items.Add(item.ItemID, item);
135 }
136 } 140 }
141 m_items.LockItemsForWrite(false);
137 } 142 }
138 143
139 /// <summary> 144 /// <summary>
@@ -142,25 +147,25 @@ namespace OpenSim.Region.Framework.Scenes
142 /// <param name="ownerId"></param> 147 /// <param name="ownerId"></param>
143 public void ChangeInventoryOwner(UUID ownerId) 148 public void ChangeInventoryOwner(UUID ownerId)
144 { 149 {
145 lock (Items) 150 m_items.LockItemsForWrite(true);
151 if (0 == Items.Count)
146 { 152 {
147 if (0 == Items.Count) 153 m_items.LockItemsForWrite(false);
148 { 154 return;
149 return; 155 }
150 }
151 156
152 HasInventoryChanged = true; 157 HasInventoryChanged = true;
153 m_part.ParentGroup.HasGroupChanged = true; 158 m_part.ParentGroup.HasGroupChanged = true;
154 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 159 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
155 foreach (TaskInventoryItem item in items) 160 foreach (TaskInventoryItem item in items)
161 {
162 if (ownerId != item.OwnerID)
156 { 163 {
157 if (ownerId != item.OwnerID) 164 item.LastOwnerID = item.OwnerID;
158 { 165 item.OwnerID = ownerId;
159 item.LastOwnerID = item.OwnerID;
160 item.OwnerID = ownerId;
161 }
162 } 166 }
163 } 167 }
168 m_items.LockItemsForWrite(false);
164 } 169 }
165 170
166 /// <summary> 171 /// <summary>
@@ -169,24 +174,24 @@ namespace OpenSim.Region.Framework.Scenes
169 /// <param name="groupID"></param> 174 /// <param name="groupID"></param>
170 public void ChangeInventoryGroup(UUID groupID) 175 public void ChangeInventoryGroup(UUID groupID)
171 { 176 {
172 lock (Items) 177 m_items.LockItemsForWrite(true);
178 if (0 == Items.Count)
173 { 179 {
174 if (0 == Items.Count) 180 m_items.LockItemsForWrite(false);
175 { 181 return;
176 return; 182 }
177 }
178 183
179 HasInventoryChanged = true; 184 HasInventoryChanged = true;
180 m_part.ParentGroup.HasGroupChanged = true; 185 m_part.ParentGroup.HasGroupChanged = true;
181 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 186 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
182 foreach (TaskInventoryItem item in items) 187 foreach (TaskInventoryItem item in items)
188 {
189 if (groupID != item.GroupID)
183 { 190 {
184 if (groupID != item.GroupID) 191 item.GroupID = groupID;
185 {
186 item.GroupID = groupID;
187 }
188 } 192 }
189 } 193 }
194 m_items.LockItemsForWrite(false);
190 } 195 }
191 196
192 /// <summary> 197 /// <summary>
@@ -194,14 +199,14 @@ namespace OpenSim.Region.Framework.Scenes
194 /// </summary> 199 /// </summary>
195 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource) 200 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
196 { 201 {
197 lock (m_items) 202 Items.LockItemsForRead(true);
203 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
204 Items.LockItemsForRead(false);
205 foreach (TaskInventoryItem item in items)
198 { 206 {
199 foreach (TaskInventoryItem item in Items.Values) 207 if ((int)InventoryType.LSL == item.InvType)
200 { 208 {
201 if ((int)InventoryType.LSL == item.InvType) 209 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
202 {
203 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
204 }
205 } 210 }
206 } 211 }
207 } 212 }
@@ -236,16 +241,20 @@ namespace OpenSim.Region.Framework.Scenes
236 /// </param> 241 /// </param>
237 public void RemoveScriptInstances(bool sceneObjectBeingDeleted) 242 public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
238 { 243 {
239 lock (Items) 244 Items.LockItemsForRead(true);
245 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
246 Items.LockItemsForRead(false);
247
248 foreach (TaskInventoryItem item in items)
240 { 249 {
241 foreach (TaskInventoryItem item in Items.Values) 250 if ((int)InventoryType.LSL == item.InvType)
242 { 251 {
243 if ((int)InventoryType.LSL == item.InvType) 252 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
244 { 253 m_part.RemoveScriptEvents(item.ItemID);
245 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
246 }
247 } 254 }
248 } 255 }
256
257
249 } 258 }
250 259
251 /// <summary> 260 /// <summary>
@@ -270,12 +279,10 @@ namespace OpenSim.Region.Framework.Scenes
270 if (stateSource == 1 && // Prim crossing 279 if (stateSource == 1 && // Prim crossing
271 m_part.ParentGroup.Scene.m_trustBinaries) 280 m_part.ParentGroup.Scene.m_trustBinaries)
272 { 281 {
273 lock (m_items) 282 m_items.LockItemsForWrite(true);
274 { 283 m_items[item.ItemID].PermsMask = 0;
275 m_items[item.ItemID].PermsMask = 0; 284 m_items[item.ItemID].PermsGranter = UUID.Zero;
276 m_items[item.ItemID].PermsGranter = UUID.Zero; 285 m_items.LockItemsForWrite(false);
277 }
278
279 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 286 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
280 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); 287 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
281 m_part.ParentGroup.AddActiveScriptCount(1); 288 m_part.ParentGroup.AddActiveScriptCount(1);
@@ -283,38 +290,35 @@ namespace OpenSim.Region.Framework.Scenes
283 return; 290 return;
284 } 291 }
285 292
286 m_part.ParentGroup.Scene.AssetService.Get( 293 m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString(), this, delegate(string id, object sender, AssetBase asset)
287 item.AssetID.ToString(), this, delegate(string id, object sender, AssetBase asset) 294 {
288 { 295 if (null == asset)
289 if (null == asset) 296 {
290 { 297 m_log.ErrorFormat(
291 m_log.ErrorFormat( 298 "[PRIM INVENTORY]: " +
292 "[PRIM INVENTORY]: " + 299 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
293 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", 300 item.Name, item.ItemID, m_part.AbsolutePosition,
294 item.Name, item.ItemID, m_part.AbsolutePosition, 301 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID);
295 m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID); 302 }
296 } 303 else
297 else 304 {
298 { 305 if (m_part.ParentGroup.m_savedScriptState != null)
299 if (m_part.ParentGroup.m_savedScriptState != null) 306 RestoreSavedScriptState(item.OldItemID, item.ItemID);
300 RestoreSavedScriptState(item.OldItemID, item.ItemID); 307 m_items.LockItemsForWrite(true);
301 308 m_items[item.ItemID].PermsMask = 0;
302 lock (m_items) 309 m_items[item.ItemID].PermsGranter = UUID.Zero;
303 { 310 m_items.LockItemsForWrite(false);
304 m_items[item.ItemID].PermsMask = 0; 311 string script = Utils.BytesToString(asset.Data);
305 m_items[item.ItemID].PermsGranter = UUID.Zero; 312 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
306 } 313 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
307 314 m_part.ParentGroup.AddActiveScriptCount(1);
308 string script = Utils.BytesToString(asset.Data); 315 m_part.ScheduleFullUpdate();
309 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 316 }
310 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); 317 });
311 m_part.ParentGroup.AddActiveScriptCount(1);
312 m_part.ScheduleFullUpdate();
313 }
314 }
315 );
316 } 318 }
317 } 319 }
320
321 static System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
318 322
319 private void RestoreSavedScriptState(UUID oldID, UUID newID) 323 private void RestoreSavedScriptState(UUID oldID, UUID newID)
320 { 324 {
@@ -379,14 +383,17 @@ namespace OpenSim.Region.Framework.Scenes
379 /// </param> 383 /// </param>
380 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 384 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
381 { 385 {
382 lock (m_items) 386 m_items.LockItemsForRead(true);
387 if (m_items.ContainsKey(itemId))
383 { 388 {
384 if (m_items.ContainsKey(itemId)) 389 if (m_items.ContainsKey(itemId))
385 { 390 {
391 m_items.LockItemsForRead(false);
386 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource); 392 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource);
387 } 393 }
388 else 394 else
389 { 395 {
396 m_items.LockItemsForRead(false);
390 m_log.ErrorFormat( 397 m_log.ErrorFormat(
391 "[PRIM INVENTORY]: " + 398 "[PRIM INVENTORY]: " +
392 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", 399 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
@@ -394,6 +401,15 @@ namespace OpenSim.Region.Framework.Scenes
394 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 401 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
395 } 402 }
396 } 403 }
404 else
405 {
406 m_items.LockItemsForRead(false);
407 m_log.ErrorFormat(
408 "[PRIM INVENTORY]: " +
409 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2}",
410 itemId, m_part.Name, m_part.UUID);
411 }
412
397 } 413 }
398 414
399 /// <summary> 415 /// <summary>
@@ -406,15 +422,7 @@ namespace OpenSim.Region.Framework.Scenes
406 /// </param> 422 /// </param>
407 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) 423 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
408 { 424 {
409 bool scriptPresent = false; 425 if (m_items.ContainsKey(itemId))
410
411 lock (m_items)
412 {
413 if (m_items.ContainsKey(itemId))
414 scriptPresent = true;
415 }
416
417 if (scriptPresent)
418 { 426 {
419 if (!sceneObjectBeingDeleted) 427 if (!sceneObjectBeingDeleted)
420 m_part.RemoveScriptEvents(itemId); 428 m_part.RemoveScriptEvents(itemId);
@@ -440,11 +448,16 @@ namespace OpenSim.Region.Framework.Scenes
440 /// <returns></returns> 448 /// <returns></returns>
441 private bool InventoryContainsName(string name) 449 private bool InventoryContainsName(string name)
442 { 450 {
443 foreach (TaskInventoryItem item in Items.Values) 451 m_items.LockItemsForRead(true);
452 foreach (TaskInventoryItem item in m_items.Values)
444 { 453 {
445 if (item.Name == name) 454 if (item.Name == name)
455 {
456 m_items.LockItemsForRead(false);
446 return true; 457 return true;
458 }
447 } 459 }
460 m_items.LockItemsForRead(false);
448 return false; 461 return false;
449 } 462 }
450 463
@@ -486,13 +499,9 @@ namespace OpenSim.Region.Framework.Scenes
486 /// <param name="item"></param> 499 /// <param name="item"></param>
487 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) 500 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
488 { 501 {
489 List<TaskInventoryItem> il; 502 m_items.LockItemsForRead(true);
490 503 List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values);
491 lock (m_items) 504 m_items.LockItemsForRead(false);
492 {
493 il = new List<TaskInventoryItem>(m_items.Values);
494 }
495
496 foreach (TaskInventoryItem i in il) 505 foreach (TaskInventoryItem i in il)
497 { 506 {
498 if (i.Name == item.Name) 507 if (i.Name == item.Name)
@@ -529,15 +538,14 @@ namespace OpenSim.Region.Framework.Scenes
529 item.ParentPartID = m_part.UUID; 538 item.ParentPartID = m_part.UUID;
530 item.Name = name; 539 item.Name = name;
531 540
532 lock (m_items) 541 m_items.LockItemsForWrite(true);
533 { 542 m_items.Add(item.ItemID, item);
534 m_items.Add(item.ItemID, item); 543 m_items.LockItemsForWrite(false);
535
536 if (allowedDrop) 544 if (allowedDrop)
537 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); 545 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
538 else 546 else
539 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 547 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
540 } 548
541 549
542 m_inventorySerial++; 550 m_inventorySerial++;
543 //m_inventorySerial += 2; 551 //m_inventorySerial += 2;
@@ -554,14 +562,13 @@ namespace OpenSim.Region.Framework.Scenes
554 /// <param name="items"></param> 562 /// <param name="items"></param>
555 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) 563 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
556 { 564 {
557 lock (m_items) 565 m_items.LockItemsForWrite(true);
566 foreach (TaskInventoryItem item in items)
558 { 567 {
559 foreach (TaskInventoryItem item in items) 568 m_items.Add(item.ItemID, item);
560 { 569 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
561 m_items.Add(item.ItemID, item);
562 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
563 }
564 } 570 }
571 m_items.LockItemsForWrite(false);
565 572
566 m_inventorySerial++; 573 m_inventorySerial++;
567 } 574 }
@@ -574,10 +581,9 @@ namespace OpenSim.Region.Framework.Scenes
574 public TaskInventoryItem GetInventoryItem(UUID itemId) 581 public TaskInventoryItem GetInventoryItem(UUID itemId)
575 { 582 {
576 TaskInventoryItem item; 583 TaskInventoryItem item;
577 584 m_items.LockItemsForRead(true);
578 lock (m_items) 585 m_items.TryGetValue(itemId, out item);
579 m_items.TryGetValue(itemId, out item); 586 m_items.LockItemsForRead(false);
580
581 return item; 587 return item;
582 } 588 }
583 589
@@ -613,46 +619,46 @@ namespace OpenSim.Region.Framework.Scenes
613 /// <returns>false if the item did not exist, true if the update occurred successfully</returns> 619 /// <returns>false if the item did not exist, true if the update occurred successfully</returns>
614 public bool UpdateInventoryItem(TaskInventoryItem item) 620 public bool UpdateInventoryItem(TaskInventoryItem item)
615 { 621 {
616 lock (m_items) 622 m_items.LockItemsForWrite(true);
623
624 if (m_items.ContainsKey(item.ItemID))
617 { 625 {
618 if (m_items.ContainsKey(item.ItemID)) 626 item.ParentID = m_part.UUID;
627 item.ParentPartID = m_part.UUID;
628 item.Flags = m_items[item.ItemID].Flags;
629 if (item.AssetID == UUID.Zero)
619 { 630 {
620 item.ParentID = m_part.UUID; 631 item.AssetID = m_items[item.ItemID].AssetID;
621 item.ParentPartID = m_part.UUID; 632 }
622 item.Flags = m_items[item.ItemID].Flags; 633 else if ((InventoryType)item.Type == InventoryType.Notecard)
623 if (item.AssetID == UUID.Zero) 634 {
624 { 635 ScenePresence presence = m_part.ParentGroup.Scene.GetScenePresence(item.OwnerID);
625 item.AssetID = m_items[item.ItemID].AssetID;
626 }
627 else if ((InventoryType)item.Type == InventoryType.Notecard)
628 {
629 ScenePresence presence = m_part.ParentGroup.Scene.GetScenePresence(item.OwnerID);
630 636
631 if (presence != null) 637 if (presence != null)
632 { 638 {
633 presence.ControllingClient.SendAgentAlertMessage( 639 presence.ControllingClient.SendAgentAlertMessage(
634 "Notecard saved", false); 640 "Notecard saved", false);
635 }
636 } 641 }
642 }
637 643
638 m_items[item.ItemID] = item; 644 m_items[item.ItemID] = item;
639 m_inventorySerial++; 645 m_inventorySerial++;
640 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 646 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
641
642 HasInventoryChanged = true;
643 m_part.ParentGroup.HasGroupChanged = true;
644 647
645 return true; 648 HasInventoryChanged = true;
646 } 649 m_part.ParentGroup.HasGroupChanged = true;
647 else 650 m_items.LockItemsForWrite(false);
648 { 651 return true;
649 m_log.ErrorFormat( 652 }
650 "[PRIM INVENTORY]: " + 653 else
651 "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory", 654 {
652 item.ItemID, m_part.Name, m_part.UUID, 655 m_log.ErrorFormat(
653 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 656 "[PRIM INVENTORY]: " +
654 } 657 "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
658 item.ItemID, m_part.Name, m_part.UUID,
659 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
655 } 660 }
661 m_items.LockItemsForWrite(false);
656 662
657 return false; 663 return false;
658 } 664 }
@@ -665,53 +671,54 @@ namespace OpenSim.Region.Framework.Scenes
665 /// in this prim's inventory.</returns> 671 /// in this prim's inventory.</returns>
666 public int RemoveInventoryItem(UUID itemID) 672 public int RemoveInventoryItem(UUID itemID)
667 { 673 {
668 lock (m_items) 674 m_items.LockItemsForRead(true);
675
676 if (m_items.ContainsKey(itemID))
669 { 677 {
670 if (m_items.ContainsKey(itemID)) 678 int type = m_items[itemID].InvType;
679 m_items.LockItemsForRead(false);
680 if (type == 10) // Script
671 { 681 {
672 int type = m_items[itemID].InvType; 682 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
673 if (type == 10) // Script 683 }
674 { 684 m_items.LockItemsForWrite(true);
675 m_part.RemoveScriptEvents(itemID); 685 m_items.Remove(itemID);
676 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); 686 m_items.LockItemsForWrite(false);
677 } 687 m_inventorySerial++;
678 m_items.Remove(itemID); 688 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
679 m_inventorySerial++;
680 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
681
682 HasInventoryChanged = true;
683 m_part.ParentGroup.HasGroupChanged = true;
684 689
685 int scriptcount = 0; 690 HasInventoryChanged = true;
686 lock (m_items) 691 m_part.ParentGroup.HasGroupChanged = true;
687 {
688 foreach (TaskInventoryItem item in m_items.Values)
689 {
690 if (item.Type == 10)
691 {
692 scriptcount++;
693 }
694 }
695 }
696 692
697 if (scriptcount <= 0) 693 int scriptcount = 0;
694 m_items.LockItemsForRead(true);
695 foreach (TaskInventoryItem item in m_items.Values)
696 {
697 if (item.Type == 10)
698 { 698 {
699 m_part.RemFlag(PrimFlags.Scripted); 699 scriptcount++;
700 } 700 }
701
702 m_part.ScheduleFullUpdate();
703
704 return type;
705 } 701 }
706 else 702 m_items.LockItemsForRead(false);
703
704
705 if (scriptcount <= 0)
707 { 706 {
708 m_log.ErrorFormat( 707 m_part.RemFlag(PrimFlags.Scripted);
709 "[PRIM INVENTORY]: " +
710 "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
711 itemID, m_part.Name, m_part.UUID,
712 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
713 } 708 }
709
710 m_part.ScheduleFullUpdate();
711
712 return type;
713 }
714 else
715 {
716 m_log.ErrorFormat(
717 "[PRIM INVENTORY]: " +
718 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
719 itemID, m_part.Name, m_part.UUID);
714 } 720 }
721 m_items.LockItemsForWrite(false);
715 722
716 return -1; 723 return -1;
717 } 724 }
@@ -764,52 +771,53 @@ namespace OpenSim.Region.Framework.Scenes
764 // isn't available (such as drag from prim inventory to agent inventory) 771 // isn't available (such as drag from prim inventory to agent inventory)
765 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); 772 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
766 773
767 lock (m_items) 774 m_items.LockItemsForRead(true);
775
776 foreach (TaskInventoryItem item in m_items.Values)
768 { 777 {
769 foreach (TaskInventoryItem item in m_items.Values) 778 UUID ownerID = item.OwnerID;
770 { 779 uint everyoneMask = 0;
771 UUID ownerID = item.OwnerID; 780 uint baseMask = item.BasePermissions;
772 uint everyoneMask = 0; 781 uint ownerMask = item.CurrentPermissions;
773 uint baseMask = item.BasePermissions;
774 uint ownerMask = item.CurrentPermissions;
775 782
776 invString.AddItemStart(); 783 invString.AddItemStart();
777 invString.AddNameValueLine("item_id", item.ItemID.ToString()); 784 invString.AddNameValueLine("item_id", item.ItemID.ToString());
778 invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); 785 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
779 786
780 invString.AddPermissionsStart(); 787 invString.AddPermissionsStart();
781 788
782 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); 789 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
783 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); 790 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
784 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(0)); 791 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(0));
785 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); 792 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
786 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); 793 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
787 794
788 invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); 795 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
789 invString.AddNameValueLine("owner_id", ownerID.ToString()); 796 invString.AddNameValueLine("owner_id", ownerID.ToString());
790 797
791 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); 798 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
792 799
793 invString.AddNameValueLine("group_id", item.GroupID.ToString()); 800 invString.AddNameValueLine("group_id", item.GroupID.ToString());
794 invString.AddSectionEnd(); 801 invString.AddSectionEnd();
795 802
796 invString.AddNameValueLine("asset_id", item.AssetID.ToString()); 803 invString.AddNameValueLine("asset_id", item.AssetID.ToString());
797 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]); 804 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]);
798 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]); 805 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]);
799 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); 806 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
800 807
801 invString.AddSaleStart(); 808 invString.AddSaleStart();
802 invString.AddNameValueLine("sale_type", "not"); 809 invString.AddNameValueLine("sale_type", "not");
803 invString.AddNameValueLine("sale_price", "0"); 810 invString.AddNameValueLine("sale_price", "0");
804 invString.AddSectionEnd(); 811 invString.AddSectionEnd();
805 812
806 invString.AddNameValueLine("name", item.Name + "|"); 813 invString.AddNameValueLine("name", item.Name + "|");
807 invString.AddNameValueLine("desc", item.Description + "|"); 814 invString.AddNameValueLine("desc", item.Description + "|");
808 815
809 invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); 816 invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
810 invString.AddSectionEnd(); 817 invString.AddSectionEnd();
811 }
812 } 818 }
819 int count = m_items.Count;
820 m_items.LockItemsForRead(false);
813 821
814 fileData = Utils.StringToBytes(invString.BuildString); 822 fileData = Utils.StringToBytes(invString.BuildString);
815 823
@@ -830,10 +838,9 @@ namespace OpenSim.Region.Framework.Scenes
830 { 838 {
831 if (HasInventoryChanged) 839 if (HasInventoryChanged)
832 { 840 {
833 lock (Items) 841 Items.LockItemsForRead(true);
834 { 842 datastore.StorePrimInventory(m_part.UUID, Items.Values);
835 datastore.StorePrimInventory(m_part.UUID, Items.Values); 843 Items.LockItemsForRead(false);
836 }
837 844
838 HasInventoryChanged = false; 845 HasInventoryChanged = false;
839 } 846 }
@@ -902,61 +909,54 @@ namespace OpenSim.Region.Framework.Scenes
902 { 909 {
903 uint mask=0x7fffffff; 910 uint mask=0x7fffffff;
904 911
905 lock (m_items) 912 foreach (TaskInventoryItem item in m_items.Values)
906 { 913 {
907 foreach (TaskInventoryItem item in m_items.Values) 914 if (item.InvType != (int)InventoryType.Object)
908 { 915 {
909 if (item.InvType != (int)InventoryType.Object) 916 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
910 { 917 mask &= ~((uint)PermissionMask.Copy >> 13);
911 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) 918 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
912 mask &= ~((uint)PermissionMask.Copy >> 13); 919 mask &= ~((uint)PermissionMask.Transfer >> 13);
913 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) 920 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
914 mask &= ~((uint)PermissionMask.Transfer >> 13); 921 mask &= ~((uint)PermissionMask.Modify >> 13);
915 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) 922 }
916 mask &= ~((uint)PermissionMask.Modify >> 13); 923 else
917 } 924 {
918 else 925 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
919 { 926 mask &= ~((uint)PermissionMask.Copy >> 13);
920 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 927 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
921 mask &= ~((uint)PermissionMask.Copy >> 13); 928 mask &= ~((uint)PermissionMask.Transfer >> 13);
922 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 929 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
923 mask &= ~((uint)PermissionMask.Transfer >> 13); 930 mask &= ~((uint)PermissionMask.Modify >> 13);
924 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
925 mask &= ~((uint)PermissionMask.Modify >> 13);
926 }
927
928 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
929 mask &= ~(uint)PermissionMask.Copy;
930 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
931 mask &= ~(uint)PermissionMask.Transfer;
932 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
933 mask &= ~(uint)PermissionMask.Modify;
934 } 931 }
932
933 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
934 mask &= ~(uint)PermissionMask.Copy;
935 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
936 mask &= ~(uint)PermissionMask.Transfer;
937 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
938 mask &= ~(uint)PermissionMask.Modify;
935 } 939 }
936
937 return mask; 940 return mask;
938 } 941 }
939 942
940 public void ApplyNextOwnerPermissions() 943 public void ApplyNextOwnerPermissions()
941 { 944 {
942 lock (m_items) 945 foreach (TaskInventoryItem item in m_items.Values)
943 { 946 {
944 foreach (TaskInventoryItem item in m_items.Values) 947 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
945 { 948 {
946 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) 949 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
947 { 950 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
948 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 951 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
949 item.CurrentPermissions &= ~(uint)PermissionMask.Copy; 952 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
950 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 953 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
951 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; 954 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
952 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) 955 item.CurrentPermissions |= 8;
953 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
954 item.CurrentPermissions |= 8;
955 }
956 item.CurrentPermissions &= item.NextPermissions;
957 item.BasePermissions &= item.NextPermissions;
958 item.EveryonePermissions &= item.NextPermissions;
959 } 956 }
957 item.CurrentPermissions &= item.NextPermissions;
958 item.BasePermissions &= item.NextPermissions;
959 item.EveryonePermissions &= item.NextPermissions;
960 } 960 }
961 961
962 m_part.TriggerScriptChangedEvent(Changed.OWNER); 962 m_part.TriggerScriptChangedEvent(Changed.OWNER);
@@ -964,29 +964,22 @@ namespace OpenSim.Region.Framework.Scenes
964 964
965 public void ApplyGodPermissions(uint perms) 965 public void ApplyGodPermissions(uint perms)
966 { 966 {
967 lock (m_items) 967 foreach (TaskInventoryItem item in m_items.Values)
968 { 968 {
969 foreach (TaskInventoryItem item in m_items.Values) 969 item.CurrentPermissions = perms;
970 { 970 item.BasePermissions = perms;
971 item.CurrentPermissions = perms;
972 item.BasePermissions = perms;
973 }
974 } 971 }
975 } 972 }
976 973
977 public bool ContainsScripts() 974 public bool ContainsScripts()
978 { 975 {
979 lock (m_items) 976 foreach (TaskInventoryItem item in m_items.Values)
980 { 977 {
981 foreach (TaskInventoryItem item in m_items.Values) 978 if (item.InvType == (int)InventoryType.LSL)
982 { 979 {
983 if (item.InvType == (int)InventoryType.LSL) 980 return true;
984 {
985 return true;
986 }
987 } 981 }
988 } 982 }
989
990 return false; 983 return false;
991 } 984 }
992 985
@@ -994,11 +987,8 @@ namespace OpenSim.Region.Framework.Scenes
994 { 987 {
995 List<UUID> ret = new List<UUID>(); 988 List<UUID> ret = new List<UUID>();
996 989
997 lock (m_items) 990 foreach (TaskInventoryItem item in m_items.Values)
998 { 991 ret.Add(item.ItemID);
999 foreach (TaskInventoryItem item in m_items.Values)
1000 ret.Add(item.ItemID);
1001 }
1002 992
1003 return ret; 993 return ret;
1004 } 994 }
@@ -1011,30 +1001,26 @@ namespace OpenSim.Region.Framework.Scenes
1011 if (engines == null) // No engine at all 1001 if (engines == null) // No engine at all
1012 return ret; 1002 return ret;
1013 1003
1014 lock (m_items) 1004 foreach (TaskInventoryItem item in m_items.Values)
1015 { 1005 {
1016 foreach (TaskInventoryItem item in m_items.Values) 1006 if (item.InvType == (int)InventoryType.LSL)
1017 { 1007 {
1018 if (item.InvType == (int)InventoryType.LSL) 1008 foreach (IScriptModule e in engines)
1019 { 1009 {
1020 foreach (IScriptModule e in engines) 1010 if (e != null)
1021 { 1011 {
1022 if (e != null) 1012 string n = e.GetXMLState(item.ItemID);
1013 if (n != String.Empty)
1023 { 1014 {
1024 string n = e.GetXMLState(item.ItemID); 1015 if (!ret.ContainsKey(item.ItemID))
1025 if (n != String.Empty) 1016 ret[item.ItemID] = n;
1026 { 1017 break;
1027 if (!ret.ContainsKey(item.ItemID))
1028 ret[item.ItemID] = n;
1029 break;
1030 }
1031 } 1018 }
1032 } 1019 }
1033 } 1020 }
1034 } 1021 }
1035 } 1022 }
1036
1037 return ret; 1023 return ret;
1038 } 1024 }
1039 } 1025 }
1040} \ No newline at end of file 1026}