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.cs570
1 files changed, 371 insertions, 199 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index 6a204c3..8fcfcc5 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -47,6 +47,8 @@ namespace OpenSim.Region.Framework.Scenes
47 47
48 private string m_inventoryFileName = String.Empty; 48 private string m_inventoryFileName = String.Empty;
49 private int m_inventoryFileNameSerial = 0; 49 private int m_inventoryFileNameSerial = 0;
50
51 private Dictionary<UUID, ArrayList> m_scriptErrors = new Dictionary<UUID, ArrayList>();
50 52
51 /// <value> 53 /// <value>
52 /// The part to which the inventory belongs. 54 /// The part to which the inventory belongs.
@@ -83,7 +85,9 @@ namespace OpenSim.Region.Framework.Scenes
83 /// </value> 85 /// </value>
84 protected internal TaskInventoryDictionary Items 86 protected internal TaskInventoryDictionary Items
85 { 87 {
86 get { return m_items; } 88 get {
89 return m_items;
90 }
87 set 91 set
88 { 92 {
89 m_items = value; 93 m_items = value;
@@ -119,39 +123,45 @@ namespace OpenSim.Region.Framework.Scenes
119 /// <param name="linkNum">Link number for the part</param> 123 /// <param name="linkNum">Link number for the part</param>
120 public void ResetInventoryIDs() 124 public void ResetInventoryIDs()
121 { 125 {
122 if (null == m_part || null == m_part.ParentGroup) 126 m_items.LockItemsForWrite(true);
123 return; 127
124 128 if (Items.Count == 0)
125 lock (m_items)
126 { 129 {
127 if (0 == m_items.Count) 130 m_items.LockItemsForWrite(false);
128 return; 131 return;
132 }
129 133
130 IList<TaskInventoryItem> items = GetInventoryItems(); 134 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
131 m_items.Clear(); 135 Items.Clear();
132 136
133 foreach (TaskInventoryItem item in items) 137 foreach (TaskInventoryItem item in items)
134 { 138 {
135 item.ResetIDs(m_part.UUID); 139 item.ResetIDs(m_part.UUID);
136 m_items.Add(item.ItemID, item); 140 Items.Add(item.ItemID, item);
137 }
138 } 141 }
142 m_items.LockItemsForWrite(false);
139 } 143 }
140 144
141 public void ResetObjectID() 145 public void ResetObjectID()
142 { 146 {
143 lock (Items) 147 m_items.LockItemsForWrite(true);
148
149 if (Items.Count == 0)
144 { 150 {
145 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 151 m_items.LockItemsForWrite(false);
146 Items.Clear(); 152 return;
147
148 foreach (TaskInventoryItem item in items)
149 {
150 item.ParentPartID = m_part.UUID;
151 item.ParentID = m_part.UUID;
152 Items.Add(item.ItemID, item);
153 }
154 } 153 }
154
155 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
156 Items.Clear();
157
158 foreach (TaskInventoryItem item in items)
159 {
160 item.ParentPartID = m_part.UUID;
161 item.ParentID = m_part.UUID;
162 Items.Add(item.ItemID, item);
163 }
164 m_items.LockItemsForWrite(false);
155 } 165 }
156 166
157 /// <summary> 167 /// <summary>
@@ -160,12 +170,11 @@ namespace OpenSim.Region.Framework.Scenes
160 /// <param name="ownerId"></param> 170 /// <param name="ownerId"></param>
161 public void ChangeInventoryOwner(UUID ownerId) 171 public void ChangeInventoryOwner(UUID ownerId)
162 { 172 {
163 lock (Items) 173 m_items.LockItemsForWrite(true);
174 if (0 == Items.Count)
164 { 175 {
165 if (0 == Items.Count) 176 m_items.LockItemsForWrite(false);
166 { 177 return;
167 return;
168 }
169 } 178 }
170 179
171 HasInventoryChanged = true; 180 HasInventoryChanged = true;
@@ -179,6 +188,7 @@ namespace OpenSim.Region.Framework.Scenes
179 item.OwnerID = ownerId; 188 item.OwnerID = ownerId;
180 } 189 }
181 } 190 }
191 m_items.LockItemsForWrite(false);
182 } 192 }
183 193
184 /// <summary> 194 /// <summary>
@@ -187,12 +197,11 @@ namespace OpenSim.Region.Framework.Scenes
187 /// <param name="groupID"></param> 197 /// <param name="groupID"></param>
188 public void ChangeInventoryGroup(UUID groupID) 198 public void ChangeInventoryGroup(UUID groupID)
189 { 199 {
190 lock (Items) 200 m_items.LockItemsForWrite(true);
201 if (0 == Items.Count)
191 { 202 {
192 if (0 == Items.Count) 203 m_items.LockItemsForWrite(false);
193 { 204 return;
194 return;
195 }
196 } 205 }
197 206
198 // Don't let this set the HasGroupChanged flag for attachments 207 // Don't let this set the HasGroupChanged flag for attachments
@@ -204,12 +213,15 @@ namespace OpenSim.Region.Framework.Scenes
204 m_part.ParentGroup.HasGroupChanged = true; 213 m_part.ParentGroup.HasGroupChanged = true;
205 } 214 }
206 215
207 List<TaskInventoryItem> items = GetInventoryItems(); 216 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
208 foreach (TaskInventoryItem item in items) 217 foreach (TaskInventoryItem item in items)
209 { 218 {
210 if (groupID != item.GroupID) 219 if (groupID != item.GroupID)
220 {
211 item.GroupID = groupID; 221 item.GroupID = groupID;
222 }
212 } 223 }
224 m_items.LockItemsForWrite(false);
213 } 225 }
214 226
215 /// <summary> 227 /// <summary>
@@ -217,9 +229,14 @@ namespace OpenSim.Region.Framework.Scenes
217 /// </summary> 229 /// </summary>
218 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource) 230 public void CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource)
219 { 231 {
220 List<TaskInventoryItem> scripts = GetInventoryScripts(); 232 Items.LockItemsForRead(true);
221 foreach (TaskInventoryItem item in scripts) 233 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
222 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); 234 Items.LockItemsForRead(false);
235 foreach (TaskInventoryItem item in items)
236 {
237 if ((int)InventoryType.LSL == item.InvType)
238 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
239 }
223 } 240 }
224 241
225 public ArrayList GetScriptErrors(UUID itemID) 242 public ArrayList GetScriptErrors(UUID itemID)
@@ -252,9 +269,18 @@ namespace OpenSim.Region.Framework.Scenes
252 /// </param> 269 /// </param>
253 public void RemoveScriptInstances(bool sceneObjectBeingDeleted) 270 public void RemoveScriptInstances(bool sceneObjectBeingDeleted)
254 { 271 {
255 List<TaskInventoryItem> scripts = GetInventoryScripts(); 272 Items.LockItemsForRead(true);
256 foreach (TaskInventoryItem item in scripts) 273 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
257 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted); 274 Items.LockItemsForRead(false);
275
276 foreach (TaskInventoryItem item in items)
277 {
278 if ((int)InventoryType.LSL == item.InvType)
279 {
280 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
281 m_part.RemoveScriptEvents(item.ItemID);
282 }
283 }
258 } 284 }
259 285
260 /// <summary> 286 /// <summary>
@@ -270,7 +296,10 @@ namespace OpenSim.Region.Framework.Scenes
270 // item.Name, item.ItemID, Name, UUID); 296 // item.Name, item.ItemID, Name, UUID);
271 297
272 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) 298 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID))
299 {
300 StoreScriptError(item.ItemID, "no permission");
273 return; 301 return;
302 }
274 303
275 m_part.AddFlag(PrimFlags.Scripted); 304 m_part.AddFlag(PrimFlags.Scripted);
276 305
@@ -279,14 +308,13 @@ namespace OpenSim.Region.Framework.Scenes
279 if (stateSource == 2 && // Prim crossing 308 if (stateSource == 2 && // Prim crossing
280 m_part.ParentGroup.Scene.m_trustBinaries) 309 m_part.ParentGroup.Scene.m_trustBinaries)
281 { 310 {
282 lock (m_items) 311 m_items.LockItemsForWrite(true);
283 { 312 m_items[item.ItemID].PermsMask = 0;
284 m_items[item.ItemID].PermsMask = 0; 313 m_items[item.ItemID].PermsGranter = UUID.Zero;
285 m_items[item.ItemID].PermsGranter = UUID.Zero; 314 m_items.LockItemsForWrite(false);
286 }
287
288 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 315 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
289 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); 316 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
317 StoreScriptErrors(item.ItemID, null);
290 m_part.ParentGroup.AddActiveScriptCount(1); 318 m_part.ParentGroup.AddActiveScriptCount(1);
291 m_part.ScheduleFullUpdate(); 319 m_part.ScheduleFullUpdate();
292 return; 320 return;
@@ -295,6 +323,8 @@ namespace OpenSim.Region.Framework.Scenes
295 AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); 323 AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString());
296 if (null == asset) 324 if (null == asset)
297 { 325 {
326 string msg = String.Format("asset ID {0} could not be found", item.AssetID);
327 StoreScriptError(item.ItemID, msg);
298 m_log.ErrorFormat( 328 m_log.ErrorFormat(
299 "[PRIM INVENTORY]: " + 329 "[PRIM INVENTORY]: " +
300 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", 330 "Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
@@ -306,15 +336,17 @@ namespace OpenSim.Region.Framework.Scenes
306 if (m_part.ParentGroup.m_savedScriptState != null) 336 if (m_part.ParentGroup.m_savedScriptState != null)
307 RestoreSavedScriptState(item.OldItemID, item.ItemID); 337 RestoreSavedScriptState(item.OldItemID, item.ItemID);
308 338
309 lock (m_items) 339 m_items.LockItemsForWrite(true);
310 { 340
311 m_items[item.ItemID].PermsMask = 0; 341 m_items[item.ItemID].PermsMask = 0;
312 m_items[item.ItemID].PermsGranter = UUID.Zero; 342 m_items[item.ItemID].PermsGranter = UUID.Zero;
313 } 343
344 m_items.LockItemsForWrite(false);
314 345
315 string script = Utils.BytesToString(asset.Data); 346 string script = Utils.BytesToString(asset.Data);
316 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 347 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
317 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); 348 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
349 StoreScriptErrors(item.ItemID, null);
318 m_part.ParentGroup.AddActiveScriptCount(1); 350 m_part.ParentGroup.AddActiveScriptCount(1);
319 m_part.ScheduleFullUpdate(); 351 m_part.ScheduleFullUpdate();
320 } 352 }
@@ -378,21 +410,145 @@ namespace OpenSim.Region.Framework.Scenes
378 410
379 /// <summary> 411 /// <summary>
380 /// Start a script which is in this prim's inventory. 412 /// Start a script which is in this prim's inventory.
413 /// Some processing may occur in the background, but this routine returns asap.
381 /// </summary> 414 /// </summary>
382 /// <param name="itemId"> 415 /// <param name="itemId">
383 /// A <see cref="UUID"/> 416 /// A <see cref="UUID"/>
384 /// </param> 417 /// </param>
385 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 418 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
386 { 419 {
387 TaskInventoryItem item = GetInventoryItem(itemId); 420 lock (m_scriptErrors)
388 if (item != null) 421 {
389 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); 422 // Indicate to CreateScriptInstanceInternal() we don't want it to wait for completion
423 m_scriptErrors.Remove(itemId);
424 }
425 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
426 }
427
428 private void CreateScriptInstanceInternal(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
429 {
430 m_items.LockItemsForRead(true);
431 if (m_items.ContainsKey(itemId))
432 {
433 if (m_items.ContainsKey(itemId))
434 {
435 m_items.LockItemsForRead(false);
436 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource);
437 }
438 else
439 {
440 m_items.LockItemsForRead(false);
441 string msg = String.Format("couldn't be found for prim {0}, {1} at {2} in {3}", m_part.Name, m_part.UUID,
442 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
443 StoreScriptError(itemId, msg);
444 m_log.ErrorFormat(
445 "[PRIM INVENTORY]: " +
446 "Couldn't start script with ID {0} since it {1}", itemId, msg);
447 }
448 }
390 else 449 else
450 {
451 m_items.LockItemsForRead(false);
452 string msg = String.Format("couldn't be found for prim {0}, {1}", m_part.Name, m_part.UUID);
453 StoreScriptError(itemId, msg);
391 m_log.ErrorFormat( 454 m_log.ErrorFormat(
392 "[PRIM INVENTORY]: " + 455 "[PRIM INVENTORY]: " +
393 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", 456 "Couldn't start script with ID {0} since it {1}", itemId, msg);
394 itemId, m_part.Name, m_part.UUID, 457 }
395 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 458
459 }
460
461 /// <summary>
462 /// Start a script which is in this prim's inventory and return any compilation error messages.
463 /// </summary>
464 /// <param name="itemId">
465 /// A <see cref="UUID"/>
466 /// </param>
467 public ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
468 {
469 ArrayList errors;
470
471 // Indicate to CreateScriptInstanceInternal() we want it to
472 // post any compilation/loading error messages
473 lock (m_scriptErrors)
474 {
475 m_scriptErrors[itemId] = null;
476 }
477
478 // Perform compilation/loading
479 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
480
481 // Wait for and retrieve any errors
482 lock (m_scriptErrors)
483 {
484 while ((errors = m_scriptErrors[itemId]) == null)
485 {
486 if (!System.Threading.Monitor.Wait(m_scriptErrors, 15000))
487 {
488 m_log.ErrorFormat(
489 "[PRIM INVENTORY]: " +
490 "timedout waiting for script {0} errors", itemId);
491 errors = m_scriptErrors[itemId];
492 if (errors == null)
493 {
494 errors = new ArrayList(1);
495 errors.Add("timedout waiting for errors");
496 }
497 break;
498 }
499 }
500 m_scriptErrors.Remove(itemId);
501 }
502 return errors;
503 }
504
505 // Signal to CreateScriptInstanceEr() that compilation/loading is complete
506 private void StoreScriptErrors(UUID itemId, ArrayList errors)
507 {
508 lock (m_scriptErrors)
509 {
510 // If compilation/loading initiated via CreateScriptInstance(),
511 // it does not want the errors, so just get out
512 if (!m_scriptErrors.ContainsKey(itemId))
513 {
514 return;
515 }
516
517 // Initiated via CreateScriptInstanceEr(), if we know what the
518 // errors are, save them and wake CreateScriptInstanceEr().
519 if (errors != null)
520 {
521 m_scriptErrors[itemId] = errors;
522 System.Threading.Monitor.PulseAll(m_scriptErrors);
523 return;
524 }
525 }
526
527 // Initiated via CreateScriptInstanceEr() but we don't know what
528 // the errors are yet, so retrieve them from the script engine.
529 // This may involve some waiting internal to GetScriptErrors().
530 errors = GetScriptErrors(itemId);
531
532 // Get a default non-null value to indicate success.
533 if (errors == null)
534 {
535 errors = new ArrayList();
536 }
537
538 // Post to CreateScriptInstanceEr() and wake it up
539 lock (m_scriptErrors)
540 {
541 m_scriptErrors[itemId] = errors;
542 System.Threading.Monitor.PulseAll(m_scriptErrors);
543 }
544 }
545
546 // Like StoreScriptErrors(), but just posts a single string message
547 private void StoreScriptError(UUID itemId, string message)
548 {
549 ArrayList errors = new ArrayList(1);
550 errors.Add(message);
551 StoreScriptErrors(itemId, errors);
396 } 552 }
397 553
398 /// <summary> 554 /// <summary>
@@ -405,15 +561,7 @@ namespace OpenSim.Region.Framework.Scenes
405 /// </param> 561 /// </param>
406 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) 562 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
407 { 563 {
408 bool scriptPresent = false; 564 if (m_items.ContainsKey(itemId))
409
410 lock (m_items)
411 {
412 if (m_items.ContainsKey(itemId))
413 scriptPresent = true;
414 }
415
416 if (scriptPresent)
417 { 565 {
418 if (!sceneObjectBeingDeleted) 566 if (!sceneObjectBeingDeleted)
419 m_part.RemoveScriptEvents(itemId); 567 m_part.RemoveScriptEvents(itemId);
@@ -438,14 +586,16 @@ namespace OpenSim.Region.Framework.Scenes
438 /// <returns></returns> 586 /// <returns></returns>
439 private bool InventoryContainsName(string name) 587 private bool InventoryContainsName(string name)
440 { 588 {
441 lock (m_items) 589 m_items.LockItemsForRead(true);
590 foreach (TaskInventoryItem item in m_items.Values)
442 { 591 {
443 foreach (TaskInventoryItem item in m_items.Values) 592 if (item.Name == name)
444 { 593 {
445 if (item.Name == name) 594 m_items.LockItemsForRead(false);
446 return true; 595 return true;
447 } 596 }
448 } 597 }
598 m_items.LockItemsForRead(false);
449 return false; 599 return false;
450 } 600 }
451 601
@@ -487,8 +637,9 @@ namespace OpenSim.Region.Framework.Scenes
487 /// <param name="item"></param> 637 /// <param name="item"></param>
488 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) 638 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
489 { 639 {
490 List<TaskInventoryItem> il = GetInventoryItems(); 640 m_items.LockItemsForRead(true);
491 641 List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values);
642 m_items.LockItemsForRead(false);
492 foreach (TaskInventoryItem i in il) 643 foreach (TaskInventoryItem i in il)
493 { 644 {
494 if (i.Name == item.Name) 645 if (i.Name == item.Name)
@@ -526,14 +677,14 @@ namespace OpenSim.Region.Framework.Scenes
526 item.Name = name; 677 item.Name = name;
527 item.GroupID = m_part.GroupID; 678 item.GroupID = m_part.GroupID;
528 679
529 lock (m_items) 680 m_items.LockItemsForWrite(true);
530 m_items.Add(item.ItemID, item); 681 m_items.Add(item.ItemID, item);
531 682 m_items.LockItemsForWrite(false);
532 if (allowedDrop) 683 if (allowedDrop)
533 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); 684 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
534 else 685 else
535 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 686 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
536 687
537 m_inventorySerial++; 688 m_inventorySerial++;
538 //m_inventorySerial += 2; 689 //m_inventorySerial += 2;
539 HasInventoryChanged = true; 690 HasInventoryChanged = true;
@@ -549,15 +700,15 @@ namespace OpenSim.Region.Framework.Scenes
549 /// <param name="items"></param> 700 /// <param name="items"></param>
550 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) 701 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
551 { 702 {
552 lock (m_items) 703 m_items.LockItemsForWrite(true);
704 foreach (TaskInventoryItem item in items)
553 { 705 {
554 foreach (TaskInventoryItem item in items) 706 m_items.Add(item.ItemID, item);
555 { 707// m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
556 m_items.Add(item.ItemID, item);
557// m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
558 }
559 m_inventorySerial++;
560 } 708 }
709 m_items.LockItemsForWrite(false);
710
711 m_inventorySerial++;
561 } 712 }
562 713
563 /// <summary> 714 /// <summary>
@@ -568,10 +719,9 @@ namespace OpenSim.Region.Framework.Scenes
568 public TaskInventoryItem GetInventoryItem(UUID itemId) 719 public TaskInventoryItem GetInventoryItem(UUID itemId)
569 { 720 {
570 TaskInventoryItem item; 721 TaskInventoryItem item;
571 722 m_items.LockItemsForRead(true);
572 lock (m_items) 723 m_items.TryGetValue(itemId, out item);
573 m_items.TryGetValue(itemId, out item); 724 m_items.LockItemsForRead(false);
574
575 return item; 725 return item;
576 } 726 }
577 727
@@ -587,15 +737,16 @@ namespace OpenSim.Region.Framework.Scenes
587 { 737 {
588 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(); 738 IList<TaskInventoryItem> items = new List<TaskInventoryItem>();
589 739
590 lock (m_items) 740 m_items.LockItemsForRead(true);
741
742 foreach (TaskInventoryItem item in m_items.Values)
591 { 743 {
592 foreach (TaskInventoryItem item in m_items.Values) 744 if (item.Name == name)
593 { 745 items.Add(item);
594 if (item.Name == name)
595 items.Add(item);
596 }
597 } 746 }
598 747
748 m_items.LockItemsForRead(false);
749
599 return items; 750 return items;
600 } 751 }
601 752
@@ -678,9 +829,9 @@ namespace OpenSim.Region.Framework.Scenes
678 829
679 public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged) 830 public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged)
680 { 831 {
681 TaskInventoryItem it = GetInventoryItem(item.ItemID); 832 m_items.LockItemsForWrite(true);
682 if (it != null)
683 833
834 if (m_items.ContainsKey(item.ItemID))
684 { 835 {
685 item.ParentID = m_part.UUID; 836 item.ParentID = m_part.UUID;
686 item.ParentPartID = m_part.UUID; 837 item.ParentPartID = m_part.UUID;
@@ -692,14 +843,10 @@ namespace OpenSim.Region.Framework.Scenes
692 item.GroupID = m_part.GroupID; 843 item.GroupID = m_part.GroupID;
693 844
694 if (item.AssetID == UUID.Zero) 845 if (item.AssetID == UUID.Zero)
695 item.AssetID = it.AssetID; 846 item.AssetID = m_items[item.ItemID].AssetID;
696
697 lock (m_items)
698 {
699 m_items[item.ItemID] = item;
700 m_inventorySerial++;
701 }
702 847
848 m_items[item.ItemID] = item;
849 m_inventorySerial++;
703 if (fireScriptEvents) 850 if (fireScriptEvents)
704 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 851 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
705 if (considerChanged) 852 if (considerChanged)
@@ -707,6 +854,7 @@ namespace OpenSim.Region.Framework.Scenes
707 HasInventoryChanged = true; 854 HasInventoryChanged = true;
708 m_part.ParentGroup.HasGroupChanged = true; 855 m_part.ParentGroup.HasGroupChanged = true;
709 } 856 }
857 m_items.LockItemsForWrite(false);
710 return true; 858 return true;
711 } 859 }
712 else 860 else
@@ -717,8 +865,9 @@ namespace OpenSim.Region.Framework.Scenes
717 item.ItemID, m_part.Name, m_part.UUID, 865 item.ItemID, m_part.Name, m_part.UUID,
718 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 866 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
719 } 867 }
720 return false; 868 m_items.LockItemsForWrite(false);
721 869
870 return false;
722 } 871 }
723 872
724 /// <summary> 873 /// <summary>
@@ -729,37 +878,53 @@ namespace OpenSim.Region.Framework.Scenes
729 /// in this prim's inventory.</returns> 878 /// in this prim's inventory.</returns>
730 public int RemoveInventoryItem(UUID itemID) 879 public int RemoveInventoryItem(UUID itemID)
731 { 880 {
732 TaskInventoryItem item = GetInventoryItem(itemID); 881 m_items.LockItemsForRead(true);
733 if (item != null) 882
883 if (m_items.ContainsKey(itemID))
734 { 884 {
735 int type = m_items[itemID].InvType; 885 int type = m_items[itemID].InvType;
886 m_items.LockItemsForRead(false);
736 if (type == 10) // Script 887 if (type == 10) // Script
737 { 888 {
738 m_part.RemoveScriptEvents(itemID);
739 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); 889 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
740 } 890 }
891 m_items.LockItemsForWrite(true);
741 m_items.Remove(itemID); 892 m_items.Remove(itemID);
893 m_items.LockItemsForWrite(false);
742 m_inventorySerial++; 894 m_inventorySerial++;
743 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 895 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
744 896
745 HasInventoryChanged = true; 897 HasInventoryChanged = true;
746 m_part.ParentGroup.HasGroupChanged = true; 898 m_part.ParentGroup.HasGroupChanged = true;
747 899
748 if (!ContainsScripts()) 900 int scriptcount = 0;
901 m_items.LockItemsForRead(true);
902 foreach (TaskInventoryItem item in m_items.Values)
903 {
904 if (item.Type == 10)
905 {
906 scriptcount++;
907 }
908 }
909 m_items.LockItemsForRead(false);
910
911
912 if (scriptcount <= 0)
913 {
749 m_part.RemFlag(PrimFlags.Scripted); 914 m_part.RemFlag(PrimFlags.Scripted);
915 }
750 916
751 m_part.ScheduleFullUpdate(); 917 m_part.ScheduleFullUpdate();
752 918
753 return type; 919 return type;
754
755 } 920 }
756 else 921 else
757 { 922 {
923 m_items.LockItemsForRead(false);
758 m_log.ErrorFormat( 924 m_log.ErrorFormat(
759 "[PRIM INVENTORY]: " + 925 "[PRIM INVENTORY]: " +
760 "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory", 926 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
761 itemID, m_part.Name, m_part.UUID, 927 itemID, m_part.Name, m_part.UUID);
762 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
763 } 928 }
764 929
765 return -1; 930 return -1;
@@ -867,6 +1032,8 @@ namespace OpenSim.Region.Framework.Scenes
867 invString.AddSectionEnd(); 1032 invString.AddSectionEnd();
868 } 1033 }
869 } 1034 }
1035 int count = m_items.Count;
1036 m_items.LockItemsForRead(false);
870 1037
871 fileData = Utils.StringToBytes(invString.BuildString); 1038 fileData = Utils.StringToBytes(invString.BuildString);
872 1039
@@ -887,10 +1054,11 @@ namespace OpenSim.Region.Framework.Scenes
887 { 1054 {
888 if (HasInventoryChanged) 1055 if (HasInventoryChanged)
889 { 1056 {
890 HasInventoryChanged = false; 1057 Items.LockItemsForRead(true);
891 List<TaskInventoryItem> items = GetInventoryItems(); 1058 datastore.StorePrimInventory(m_part.UUID, Items.Values);
892 datastore.StorePrimInventory(m_part.UUID, items); 1059 Items.LockItemsForRead(false);
893 1060
1061 HasInventoryChanged = false;
894 } 1062 }
895 } 1063 }
896 1064
@@ -957,89 +1125,75 @@ namespace OpenSim.Region.Framework.Scenes
957 { 1125 {
958 uint mask=0x7fffffff; 1126 uint mask=0x7fffffff;
959 1127
960 lock (m_items) 1128 foreach (TaskInventoryItem item in m_items.Values)
961 { 1129 {
962 foreach (TaskInventoryItem item in m_items.Values) 1130 if (item.InvType != (int)InventoryType.Object)
963 { 1131 {
964 if (item.InvType != (int)InventoryType.Object) 1132 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
965 { 1133 mask &= ~((uint)PermissionMask.Copy >> 13);
966 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) 1134 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
967 mask &= ~((uint)PermissionMask.Copy >> 13); 1135 mask &= ~((uint)PermissionMask.Transfer >> 13);
968 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) 1136 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
969 mask &= ~((uint)PermissionMask.Transfer >> 13); 1137 mask &= ~((uint)PermissionMask.Modify >> 13);
970 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) 1138 }
971 mask &= ~((uint)PermissionMask.Modify >> 13); 1139 else
972 } 1140 {
973 else 1141 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
974 { 1142 mask &= ~((uint)PermissionMask.Copy >> 13);
975 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 1143 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
976 mask &= ~((uint)PermissionMask.Copy >> 13); 1144 mask &= ~((uint)PermissionMask.Transfer >> 13);
977 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 1145 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
978 mask &= ~((uint)PermissionMask.Transfer >> 13); 1146 mask &= ~((uint)PermissionMask.Modify >> 13);
979 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
980 mask &= ~((uint)PermissionMask.Modify >> 13);
981 }
982
983 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
984 mask &= ~(uint)PermissionMask.Copy;
985 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
986 mask &= ~(uint)PermissionMask.Transfer;
987 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
988 mask &= ~(uint)PermissionMask.Modify;
989 } 1147 }
1148
1149 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
1150 mask &= ~(uint)PermissionMask.Copy;
1151 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1152 mask &= ~(uint)PermissionMask.Transfer;
1153 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
1154 mask &= ~(uint)PermissionMask.Modify;
990 } 1155 }
991
992 return mask; 1156 return mask;
993 } 1157 }
994 1158
995 public void ApplyNextOwnerPermissions() 1159 public void ApplyNextOwnerPermissions()
996 { 1160 {
997 lock (m_items) 1161 foreach (TaskInventoryItem item in m_items.Values)
998 { 1162 {
999 foreach (TaskInventoryItem item in m_items.Values) 1163 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
1000 { 1164 {
1001 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) 1165 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
1002 { 1166 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
1003 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 1167 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
1004 item.CurrentPermissions &= ~(uint)PermissionMask.Copy; 1168 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
1005 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 1169 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1006 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; 1170 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
1007 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1008 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
1009 }
1010 item.CurrentPermissions &= item.NextPermissions;
1011 item.BasePermissions &= item.NextPermissions;
1012 item.EveryonePermissions &= item.NextPermissions;
1013 item.OwnerChanged = true;
1014 } 1171 }
1172 item.OwnerChanged = true;
1173 item.CurrentPermissions &= item.NextPermissions;
1174 item.BasePermissions &= item.NextPermissions;
1175 item.EveryonePermissions &= item.NextPermissions;
1015 } 1176 }
1016 } 1177 }
1017 1178
1018 public void ApplyGodPermissions(uint perms) 1179 public void ApplyGodPermissions(uint perms)
1019 { 1180 {
1020 lock (m_items) 1181 foreach (TaskInventoryItem item in m_items.Values)
1021 { 1182 {
1022 foreach (TaskInventoryItem item in m_items.Values) 1183 item.CurrentPermissions = perms;
1023 { 1184 item.BasePermissions = perms;
1024 item.CurrentPermissions = perms;
1025 item.BasePermissions = perms;
1026 }
1027 } 1185 }
1028 } 1186 }
1029 1187
1030 public bool ContainsScripts() 1188 public bool ContainsScripts()
1031 { 1189 {
1032 lock (m_items) 1190 foreach (TaskInventoryItem item in m_items.Values)
1033 { 1191 {
1034 foreach (TaskInventoryItem item in m_items.Values) 1192 if (item.InvType == (int)InventoryType.LSL)
1035 { 1193 {
1036 if (item.InvType == (int)InventoryType.LSL) 1194 return true;
1037 {
1038 return true;
1039 }
1040 } 1195 }
1041 } 1196 }
1042
1043 return false; 1197 return false;
1044 } 1198 }
1045 1199
@@ -1047,11 +1201,8 @@ namespace OpenSim.Region.Framework.Scenes
1047 { 1201 {
1048 List<UUID> ret = new List<UUID>(); 1202 List<UUID> ret = new List<UUID>();
1049 1203
1050 lock (m_items) 1204 foreach (TaskInventoryItem item in m_items.Values)
1051 { 1205 ret.Add(item.ItemID);
1052 foreach (TaskInventoryItem item in m_items.Values)
1053 ret.Add(item.ItemID);
1054 }
1055 1206
1056 return ret; 1207 return ret;
1057 } 1208 }
@@ -1082,31 +1233,46 @@ namespace OpenSim.Region.Framework.Scenes
1082 1233
1083 public Dictionary<UUID, string> GetScriptStates() 1234 public Dictionary<UUID, string> GetScriptStates()
1084 { 1235 {
1236 return GetScriptStates(false);
1237 }
1238
1239 public Dictionary<UUID, string> GetScriptStates(bool oldIDs)
1240 {
1085 IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>(); 1241 IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
1086 1242
1087 Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); 1243 Dictionary<UUID, string> ret = new Dictionary<UUID, string>();
1088 if (engines == null) // No engine at all 1244 if (engines == null) // No engine at all
1089 return ret; 1245 return ret;
1090 1246
1091 List<TaskInventoryItem> scripts = GetInventoryScripts(); 1247 Items.LockItemsForRead(true);
1092 1248 foreach (TaskInventoryItem item in m_items.Values)
1093 foreach (TaskInventoryItem item in scripts)
1094 { 1249 {
1095 foreach (IScriptModule e in engines) 1250 if (item.InvType == (int)InventoryType.LSL)
1096 { 1251 {
1097 if (e != null) 1252 foreach (IScriptModule e in engines)
1098 { 1253 {
1099 string n = e.GetXMLState(item.ItemID); 1254 if (e != null)
1100 if (n != String.Empty)
1101 { 1255 {
1102 if (!ret.ContainsKey(item.ItemID)) 1256 string n = e.GetXMLState(item.ItemID);
1103 ret[item.ItemID] = n; 1257 if (n != String.Empty)
1104 break; 1258 {
1259 if (oldIDs)
1260 {
1261 if (!ret.ContainsKey(item.OldItemID))
1262 ret[item.OldItemID] = n;
1263 }
1264 else
1265 {
1266 if (!ret.ContainsKey(item.ItemID))
1267 ret[item.ItemID] = n;
1268 }
1269 break;
1270 }
1105 } 1271 }
1106 } 1272 }
1107 } 1273 }
1108 } 1274 }
1109 1275 Items.LockItemsForRead(false);
1110 return ret; 1276 return ret;
1111 } 1277 }
1112 1278
@@ -1116,21 +1282,27 @@ namespace OpenSim.Region.Framework.Scenes
1116 if (engines == null) 1282 if (engines == null)
1117 return; 1283 return;
1118 1284
1119 List<TaskInventoryItem> scripts = GetInventoryScripts();
1120 1285
1121 foreach (TaskInventoryItem item in scripts) 1286 Items.LockItemsForRead(true);
1287
1288 foreach (TaskInventoryItem item in m_items.Values)
1122 { 1289 {
1123 foreach (IScriptModule engine in engines) 1290 if (item.InvType == (int)InventoryType.LSL)
1124 { 1291 {
1125 if (engine != null) 1292 foreach (IScriptModule engine in engines)
1126 { 1293 {
1127 if (item.OwnerChanged) 1294 if (engine != null)
1128 engine.PostScriptEvent(item.ItemID, "changed", new Object[] { (int)Changed.OWNER }); 1295 {
1129 item.OwnerChanged = false; 1296 if (item.OwnerChanged)
1130 engine.ResumeScript(item.ItemID); 1297 engine.PostScriptEvent(item.ItemID, "changed", new Object[] { (int)Changed.OWNER });
1298 item.OwnerChanged = false;
1299 engine.ResumeScript(item.ItemID);
1300 }
1131 } 1301 }
1132 } 1302 }
1133 } 1303 }
1304
1305 Items.LockItemsForRead(false);
1134 } 1306 }
1135 } 1307 }
1136} 1308}