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