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.cs769
1 files changed, 483 insertions, 286 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index aacad98..36cb09a 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -48,6 +48,9 @@ namespace OpenSim.Region.Framework.Scenes
48 private string m_inventoryFileName = String.Empty; 48 private string m_inventoryFileName = String.Empty;
49 private byte[] m_inventoryFileData = new byte[0]; 49 private byte[] m_inventoryFileData = new byte[0];
50 private uint m_inventoryFileNameSerial = 0; 50 private uint m_inventoryFileNameSerial = 0;
51 private bool m_inventoryPrivileged = false;
52
53 private Dictionary<UUID, ArrayList> m_scriptErrors = new Dictionary<UUID, ArrayList>();
51 54
52 /// <value> 55 /// <value>
53 /// The part to which the inventory belongs. 56 /// The part to which the inventory belongs.
@@ -84,11 +87,14 @@ namespace OpenSim.Region.Framework.Scenes
84 /// </value> 87 /// </value>
85 protected internal TaskInventoryDictionary Items 88 protected internal TaskInventoryDictionary Items
86 { 89 {
87 get { return m_items; } 90 get {
91 return m_items;
92 }
88 set 93 set
89 { 94 {
90 m_items = value; 95 m_items = value;
91 m_inventorySerial++; 96 m_inventorySerial++;
97 QueryScriptStates();
92 } 98 }
93 } 99 }
94 100
@@ -123,38 +129,45 @@ namespace OpenSim.Region.Framework.Scenes
123 public void ResetInventoryIDs() 129 public void ResetInventoryIDs()
124 { 130 {
125 if (null == m_part) 131 if (null == m_part)
126 return; 132 m_items.LockItemsForWrite(true);
127 133
128 lock (m_items) 134 if (Items.Count == 0)
129 { 135 {
130 if (0 == m_items.Count) 136 m_items.LockItemsForWrite(false);
131 return; 137 return;
138 }
132 139
133 IList<TaskInventoryItem> items = GetInventoryItems(); 140 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
134 m_items.Clear(); 141 Items.Clear();
135 142
136 foreach (TaskInventoryItem item in items) 143 foreach (TaskInventoryItem item in items)
137 { 144 {
138 item.ResetIDs(m_part.UUID); 145 item.ResetIDs(m_part.UUID);
139 m_items.Add(item.ItemID, item); 146 Items.Add(item.ItemID, item);
140 }
141 } 147 }
148 m_items.LockItemsForWrite(false);
142 } 149 }
143 150
144 public void ResetObjectID() 151 public void ResetObjectID()
145 { 152 {
146 lock (Items) 153 m_items.LockItemsForWrite(true);
154
155 if (Items.Count == 0)
147 { 156 {
148 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); 157 m_items.LockItemsForWrite(false);
149 Items.Clear(); 158 return;
150
151 foreach (TaskInventoryItem item in items)
152 {
153 item.ParentPartID = m_part.UUID;
154 item.ParentID = m_part.UUID;
155 Items.Add(item.ItemID, item);
156 }
157 } 159 }
160
161 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
162 Items.Clear();
163
164 foreach (TaskInventoryItem item in items)
165 {
166 item.ParentPartID = m_part.UUID;
167 item.ParentID = m_part.UUID;
168 Items.Add(item.ItemID, item);
169 }
170 m_items.LockItemsForWrite(false);
158 } 171 }
159 172
160 /// <summary> 173 /// <summary>
@@ -163,12 +176,11 @@ namespace OpenSim.Region.Framework.Scenes
163 /// <param name="ownerId"></param> 176 /// <param name="ownerId"></param>
164 public void ChangeInventoryOwner(UUID ownerId) 177 public void ChangeInventoryOwner(UUID ownerId)
165 { 178 {
166 lock (Items) 179 m_items.LockItemsForWrite(true);
180 if (0 == Items.Count)
167 { 181 {
168 if (0 == Items.Count) 182 m_items.LockItemsForWrite(false);
169 { 183 return;
170 return;
171 }
172 } 184 }
173 185
174 HasInventoryChanged = true; 186 HasInventoryChanged = true;
@@ -184,6 +196,7 @@ namespace OpenSim.Region.Framework.Scenes
184 item.PermsGranter = UUID.Zero; 196 item.PermsGranter = UUID.Zero;
185 item.OwnerChanged = true; 197 item.OwnerChanged = true;
186 } 198 }
199 m_items.LockItemsForWrite(false);
187 } 200 }
188 201
189 /// <summary> 202 /// <summary>
@@ -192,12 +205,11 @@ namespace OpenSim.Region.Framework.Scenes
192 /// <param name="groupID"></param> 205 /// <param name="groupID"></param>
193 public void ChangeInventoryGroup(UUID groupID) 206 public void ChangeInventoryGroup(UUID groupID)
194 { 207 {
195 lock (Items) 208 m_items.LockItemsForWrite(true);
209 if (0 == Items.Count)
196 { 210 {
197 if (0 == Items.Count) 211 m_items.LockItemsForWrite(false);
198 { 212 return;
199 return;
200 }
201 } 213 }
202 214
203 // Don't let this set the HasGroupChanged flag for attachments 215 // Don't let this set the HasGroupChanged flag for attachments
@@ -209,12 +221,45 @@ namespace OpenSim.Region.Framework.Scenes
209 m_part.ParentGroup.HasGroupChanged = true; 221 m_part.ParentGroup.HasGroupChanged = true;
210 } 222 }
211 223
212 List<TaskInventoryItem> items = GetInventoryItems(); 224 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values);
213 foreach (TaskInventoryItem item in items) 225 foreach (TaskInventoryItem item in items)
214 { 226 {
215 if (groupID != item.GroupID) 227 if (groupID != item.GroupID)
228 {
216 item.GroupID = groupID; 229 item.GroupID = groupID;
230 }
231 }
232 m_items.LockItemsForWrite(false);
233 }
234
235 private void QueryScriptStates()
236 {
237 if (m_part == null || m_part.ParentGroup == null)
238 return;
239
240 IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
241 if (engines == null) // No engine at all
242 return;
243
244 Items.LockItemsForRead(true);
245 foreach (TaskInventoryItem item in Items.Values)
246 {
247 if (item.InvType == (int)InventoryType.LSL)
248 {
249 foreach (IScriptModule e in engines)
250 {
251 bool running;
252
253 if (e.HasScript(item.ItemID, out running))
254 {
255 item.ScriptRunning = running;
256 break;
257 }
258 }
259 }
217 } 260 }
261
262 Items.LockItemsForRead(false);
218 } 263 }
219 264
220 /// <summary> 265 /// <summary>
@@ -257,7 +302,10 @@ namespace OpenSim.Region.Framework.Scenes
257 { 302 {
258 List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL); 303 List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL);
259 foreach (TaskInventoryItem item in scripts) 304 foreach (TaskInventoryItem item in scripts)
305 {
260 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted); 306 RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
307 m_part.RemoveScriptEvents(item.ItemID);
308 }
261 } 309 }
262 310
263 /// <summary> 311 /// <summary>
@@ -271,7 +319,10 @@ namespace OpenSim.Region.Framework.Scenes
271// item.Name, item.ItemID, m_part.Name, m_part.UUID, m_part.ParentGroup.Scene.RegionInfo.RegionName); 319// item.Name, item.ItemID, m_part.Name, m_part.UUID, m_part.ParentGroup.Scene.RegionInfo.RegionName);
272 320
273 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) 321 if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID))
322 {
323 StoreScriptError(item.ItemID, "no permission");
274 return; 324 return;
325 }
275 326
276 m_part.AddFlag(PrimFlags.Scripted); 327 m_part.AddFlag(PrimFlags.Scripted);
277 328
@@ -280,14 +331,13 @@ namespace OpenSim.Region.Framework.Scenes
280 if (stateSource == 2 && // Prim crossing 331 if (stateSource == 2 && // Prim crossing
281 m_part.ParentGroup.Scene.m_trustBinaries) 332 m_part.ParentGroup.Scene.m_trustBinaries)
282 { 333 {
283 lock (m_items) 334 m_items.LockItemsForWrite(true);
284 { 335 m_items[item.ItemID].PermsMask = 0;
285 m_items[item.ItemID].PermsMask = 0; 336 m_items[item.ItemID].PermsGranter = UUID.Zero;
286 m_items[item.ItemID].PermsGranter = UUID.Zero; 337 m_items.LockItemsForWrite(false);
287 }
288
289 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 338 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
290 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); 339 m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource);
340 StoreScriptErrors(item.ItemID, null);
291 m_part.ParentGroup.AddActiveScriptCount(1); 341 m_part.ParentGroup.AddActiveScriptCount(1);
292 m_part.ScheduleFullUpdate(); 342 m_part.ScheduleFullUpdate();
293 return; 343 return;
@@ -296,6 +346,8 @@ namespace OpenSim.Region.Framework.Scenes
296 AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); 346 AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString());
297 if (null == asset) 347 if (null == asset)
298 { 348 {
349 string msg = String.Format("asset ID {0} could not be found", item.AssetID);
350 StoreScriptError(item.ItemID, msg);
299 m_log.ErrorFormat( 351 m_log.ErrorFormat(
300 "[PRIM INVENTORY]: Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", 352 "[PRIM INVENTORY]: Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
301 item.Name, item.ItemID, m_part.AbsolutePosition, 353 item.Name, item.ItemID, m_part.AbsolutePosition,
@@ -306,16 +358,21 @@ namespace OpenSim.Region.Framework.Scenes
306 if (m_part.ParentGroup.m_savedScriptState != null) 358 if (m_part.ParentGroup.m_savedScriptState != null)
307 item.OldItemID = RestoreSavedScriptState(item.LoadedItemID, item.OldItemID, item.ItemID); 359 item.OldItemID = RestoreSavedScriptState(item.LoadedItemID, item.OldItemID, item.ItemID);
308 360
309 lock (m_items) 361 m_items.LockItemsForWrite(true);
310 { 362
311 m_items[item.ItemID].OldItemID = item.OldItemID; 363 m_items[item.ItemID].OldItemID = item.OldItemID;
312 m_items[item.ItemID].PermsMask = 0; 364 m_items[item.ItemID].PermsMask = 0;
313 m_items[item.ItemID].PermsGranter = UUID.Zero; 365 m_items[item.ItemID].PermsGranter = UUID.Zero;
314 }
315 366
367 m_items.LockItemsForWrite(false);
368
316 string script = Utils.BytesToString(asset.Data); 369 string script = Utils.BytesToString(asset.Data);
317 m_part.ParentGroup.Scene.EventManager.TriggerRezScript( 370 m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
318 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); 371 m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
372 StoreScriptErrors(item.ItemID, null);
373 if (!item.ScriptRunning)
374 m_part.ParentGroup.Scene.EventManager.TriggerStopScript(
375 m_part.LocalId, item.ItemID);
319 m_part.ParentGroup.AddActiveScriptCount(1); 376 m_part.ParentGroup.AddActiveScriptCount(1);
320 m_part.ScheduleFullUpdate(); 377 m_part.ScheduleFullUpdate();
321 } 378 }
@@ -386,20 +443,146 @@ namespace OpenSim.Region.Framework.Scenes
386 443
387 /// <summary> 444 /// <summary>
388 /// Start a script which is in this prim's inventory. 445 /// Start a script which is in this prim's inventory.
446 /// Some processing may occur in the background, but this routine returns asap.
389 /// </summary> 447 /// </summary>
390 /// <param name="itemId"> 448 /// <param name="itemId">
391 /// A <see cref="UUID"/> 449 /// A <see cref="UUID"/>
392 /// </param> 450 /// </param>
393 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) 451 public void CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
394 { 452 {
395 TaskInventoryItem item = GetInventoryItem(itemId); 453 lock (m_scriptErrors)
396 if (item != null) 454 {
397 CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); 455 // Indicate to CreateScriptInstanceInternal() we don't want it to wait for completion
456 m_scriptErrors.Remove(itemId);
457 }
458 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
459 }
460
461 private void CreateScriptInstanceInternal(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
462 {
463 m_items.LockItemsForRead(true);
464 if (m_items.ContainsKey(itemId))
465 {
466 if (m_items.ContainsKey(itemId))
467 {
468 m_items.LockItemsForRead(false);
469 CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource);
470 }
471 else
472 {
473 m_items.LockItemsForRead(false);
474 string msg = String.Format("couldn't be found for prim {0}, {1} at {2} in {3}", m_part.Name, m_part.UUID,
475 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
476 StoreScriptError(itemId, msg);
477 m_log.ErrorFormat(
478 "[PRIM INVENTORY]: " +
479 "Couldn't start script with ID {0} since it {1}", itemId, msg);
480 }
481 }
398 else 482 else
483 {
484 m_items.LockItemsForRead(false);
485 string msg = String.Format("couldn't be found for prim {0}, {1}", m_part.Name, m_part.UUID);
486 StoreScriptError(itemId, msg);
399 m_log.ErrorFormat( 487 m_log.ErrorFormat(
400 "[PRIM INVENTORY]: Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", 488 "[PRIM INVENTORY]: Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
401 itemId, m_part.Name, m_part.UUID, 489 itemId, m_part.Name, m_part.UUID,
402 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 490 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
491 }
492
493 }
494
495 /// <summary>
496 /// Start a script which is in this prim's inventory and return any compilation error messages.
497 /// </summary>
498 /// <param name="itemId">
499 /// A <see cref="UUID"/>
500 /// </param>
501 public ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource)
502 {
503 ArrayList errors;
504
505 // Indicate to CreateScriptInstanceInternal() we want it to
506 // post any compilation/loading error messages
507 lock (m_scriptErrors)
508 {
509 m_scriptErrors[itemId] = null;
510 }
511
512 // Perform compilation/loading
513 CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource);
514
515 // Wait for and retrieve any errors
516 lock (m_scriptErrors)
517 {
518 while ((errors = m_scriptErrors[itemId]) == null)
519 {
520 if (!System.Threading.Monitor.Wait(m_scriptErrors, 15000))
521 {
522 m_log.ErrorFormat(
523 "[PRIM INVENTORY]: " +
524 "timedout waiting for script {0} errors", itemId);
525 errors = m_scriptErrors[itemId];
526 if (errors == null)
527 {
528 errors = new ArrayList(1);
529 errors.Add("timedout waiting for errors");
530 }
531 break;
532 }
533 }
534 m_scriptErrors.Remove(itemId);
535 }
536 return errors;
537 }
538
539 // Signal to CreateScriptInstanceEr() that compilation/loading is complete
540 private void StoreScriptErrors(UUID itemId, ArrayList errors)
541 {
542 lock (m_scriptErrors)
543 {
544 // If compilation/loading initiated via CreateScriptInstance(),
545 // it does not want the errors, so just get out
546 if (!m_scriptErrors.ContainsKey(itemId))
547 {
548 return;
549 }
550
551 // Initiated via CreateScriptInstanceEr(), if we know what the
552 // errors are, save them and wake CreateScriptInstanceEr().
553 if (errors != null)
554 {
555 m_scriptErrors[itemId] = errors;
556 System.Threading.Monitor.PulseAll(m_scriptErrors);
557 return;
558 }
559 }
560
561 // Initiated via CreateScriptInstanceEr() but we don't know what
562 // the errors are yet, so retrieve them from the script engine.
563 // This may involve some waiting internal to GetScriptErrors().
564 errors = GetScriptErrors(itemId);
565
566 // Get a default non-null value to indicate success.
567 if (errors == null)
568 {
569 errors = new ArrayList();
570 }
571
572 // Post to CreateScriptInstanceEr() and wake it up
573 lock (m_scriptErrors)
574 {
575 m_scriptErrors[itemId] = errors;
576 System.Threading.Monitor.PulseAll(m_scriptErrors);
577 }
578 }
579
580 // Like StoreScriptErrors(), but just posts a single string message
581 private void StoreScriptError(UUID itemId, string message)
582 {
583 ArrayList errors = new ArrayList(1);
584 errors.Add(message);
585 StoreScriptErrors(itemId, errors);
403 } 586 }
404 587
405 /// <summary> 588 /// <summary>
@@ -412,15 +595,7 @@ namespace OpenSim.Region.Framework.Scenes
412 /// </param> 595 /// </param>
413 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) 596 public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted)
414 { 597 {
415 bool scriptPresent = false; 598 if (m_items.ContainsKey(itemId))
416
417 lock (m_items)
418 {
419 if (m_items.ContainsKey(itemId))
420 scriptPresent = true;
421 }
422
423 if (scriptPresent)
424 { 599 {
425 if (!sceneObjectBeingDeleted) 600 if (!sceneObjectBeingDeleted)
426 m_part.RemoveScriptEvents(itemId); 601 m_part.RemoveScriptEvents(itemId);
@@ -445,14 +620,16 @@ namespace OpenSim.Region.Framework.Scenes
445 /// <returns></returns> 620 /// <returns></returns>
446 private bool InventoryContainsName(string name) 621 private bool InventoryContainsName(string name)
447 { 622 {
448 lock (m_items) 623 m_items.LockItemsForRead(true);
624 foreach (TaskInventoryItem item in m_items.Values)
449 { 625 {
450 foreach (TaskInventoryItem item in m_items.Values) 626 if (item.Name == name)
451 { 627 {
452 if (item.Name == name) 628 m_items.LockItemsForRead(false);
453 return true; 629 return true;
454 } 630 }
455 } 631 }
632 m_items.LockItemsForRead(false);
456 return false; 633 return false;
457 } 634 }
458 635
@@ -494,8 +671,9 @@ namespace OpenSim.Region.Framework.Scenes
494 /// <param name="item"></param> 671 /// <param name="item"></param>
495 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) 672 public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
496 { 673 {
497 List<TaskInventoryItem> il = GetInventoryItems(); 674 m_items.LockItemsForRead(true);
498 675 List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values);
676 m_items.LockItemsForRead(false);
499 foreach (TaskInventoryItem i in il) 677 foreach (TaskInventoryItem i in il)
500 { 678 {
501 if (i.Name == item.Name) 679 if (i.Name == item.Name)
@@ -533,14 +711,14 @@ namespace OpenSim.Region.Framework.Scenes
533 item.Name = name; 711 item.Name = name;
534 item.GroupID = m_part.GroupID; 712 item.GroupID = m_part.GroupID;
535 713
536 lock (m_items) 714 m_items.LockItemsForWrite(true);
537 m_items.Add(item.ItemID, item); 715 m_items.Add(item.ItemID, item);
538 716 m_items.LockItemsForWrite(false);
539 if (allowedDrop) 717 if (allowedDrop)
540 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); 718 m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP);
541 else 719 else
542 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 720 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
543 721
544 m_inventorySerial++; 722 m_inventorySerial++;
545 //m_inventorySerial += 2; 723 //m_inventorySerial += 2;
546 HasInventoryChanged = true; 724 HasInventoryChanged = true;
@@ -556,15 +734,15 @@ namespace OpenSim.Region.Framework.Scenes
556 /// <param name="items"></param> 734 /// <param name="items"></param>
557 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) 735 public void RestoreInventoryItems(ICollection<TaskInventoryItem> items)
558 { 736 {
559 lock (m_items) 737 m_items.LockItemsForWrite(true);
738 foreach (TaskInventoryItem item in items)
560 { 739 {
561 foreach (TaskInventoryItem item in items) 740 m_items.Add(item.ItemID, item);
562 { 741// m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
563 m_items.Add(item.ItemID, item);
564// m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
565 }
566 m_inventorySerial++;
567 } 742 }
743 m_items.LockItemsForWrite(false);
744
745 m_inventorySerial++;
568 } 746 }
569 747
570 /// <summary> 748 /// <summary>
@@ -575,10 +753,9 @@ namespace OpenSim.Region.Framework.Scenes
575 public TaskInventoryItem GetInventoryItem(UUID itemId) 753 public TaskInventoryItem GetInventoryItem(UUID itemId)
576 { 754 {
577 TaskInventoryItem item; 755 TaskInventoryItem item;
578 756 m_items.LockItemsForRead(true);
579 lock (m_items) 757 m_items.TryGetValue(itemId, out item);
580 m_items.TryGetValue(itemId, out item); 758 m_items.LockItemsForRead(false);
581
582 return item; 759 return item;
583 } 760 }
584 761
@@ -594,15 +771,16 @@ namespace OpenSim.Region.Framework.Scenes
594 { 771 {
595 List<TaskInventoryItem> items = new List<TaskInventoryItem>(); 772 List<TaskInventoryItem> items = new List<TaskInventoryItem>();
596 773
597 lock (m_items) 774 m_items.LockItemsForRead(true);
775
776 foreach (TaskInventoryItem item in m_items.Values)
598 { 777 {
599 foreach (TaskInventoryItem item in m_items.Values) 778 if (item.Name == name)
600 { 779 items.Add(item);
601 if (item.Name == name)
602 items.Add(item);
603 }
604 } 780 }
605 781
782 m_items.LockItemsForRead(false);
783
606 return items; 784 return items;
607 } 785 }
608 786
@@ -621,6 +799,9 @@ namespace OpenSim.Region.Framework.Scenes
621 string xmlData = Utils.BytesToString(rezAsset.Data); 799 string xmlData = Utils.BytesToString(rezAsset.Data);
622 SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); 800 SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
623 801
802 group.RootPart.AttachPoint = group.RootPart.Shape.State;
803 group.RootPart.AttachOffset = group.AbsolutePosition;
804
624 group.ResetIDs(); 805 group.ResetIDs();
625 806
626 SceneObjectPart rootPart = group.GetPart(group.UUID); 807 SceneObjectPart rootPart = group.GetPart(group.UUID);
@@ -695,8 +876,9 @@ namespace OpenSim.Region.Framework.Scenes
695 876
696 public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged) 877 public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged)
697 { 878 {
698 TaskInventoryItem it = GetInventoryItem(item.ItemID); 879 m_items.LockItemsForWrite(true);
699 if (it != null) 880
881 if (m_items.ContainsKey(item.ItemID))
700 { 882 {
701// m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name); 883// m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name);
702 884
@@ -709,14 +891,10 @@ namespace OpenSim.Region.Framework.Scenes
709 item.GroupID = m_part.GroupID; 891 item.GroupID = m_part.GroupID;
710 892
711 if (item.AssetID == UUID.Zero) 893 if (item.AssetID == UUID.Zero)
712 item.AssetID = it.AssetID; 894 item.AssetID = m_items[item.ItemID].AssetID;
713 895
714 lock (m_items) 896 m_items[item.ItemID] = item;
715 { 897 m_inventorySerial++;
716 m_items[item.ItemID] = item;
717 m_inventorySerial++;
718 }
719
720 if (fireScriptEvents) 898 if (fireScriptEvents)
721 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 899 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
722 900
@@ -725,7 +903,7 @@ namespace OpenSim.Region.Framework.Scenes
725 HasInventoryChanged = true; 903 HasInventoryChanged = true;
726 m_part.ParentGroup.HasGroupChanged = true; 904 m_part.ParentGroup.HasGroupChanged = true;
727 } 905 }
728 906 m_items.LockItemsForWrite(false);
729 return true; 907 return true;
730 } 908 }
731 else 909 else
@@ -736,8 +914,9 @@ namespace OpenSim.Region.Framework.Scenes
736 item.ItemID, m_part.Name, m_part.UUID, 914 item.ItemID, m_part.Name, m_part.UUID,
737 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 915 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
738 } 916 }
739 return false; 917 m_items.LockItemsForWrite(false);
740 918
919 return false;
741 } 920 }
742 921
743 /// <summary> 922 /// <summary>
@@ -748,43 +927,59 @@ namespace OpenSim.Region.Framework.Scenes
748 /// in this prim's inventory.</returns> 927 /// in this prim's inventory.</returns>
749 public int RemoveInventoryItem(UUID itemID) 928 public int RemoveInventoryItem(UUID itemID)
750 { 929 {
751 TaskInventoryItem item = GetInventoryItem(itemID); 930 m_items.LockItemsForRead(true);
752 if (item != null) 931
932 if (m_items.ContainsKey(itemID))
753 { 933 {
754 int type = m_items[itemID].InvType; 934 int type = m_items[itemID].InvType;
935 m_items.LockItemsForRead(false);
755 if (type == 10) // Script 936 if (type == 10) // Script
756 { 937 {
757 m_part.RemoveScriptEvents(itemID);
758 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); 938 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
759 } 939 }
940 m_items.LockItemsForWrite(true);
760 m_items.Remove(itemID); 941 m_items.Remove(itemID);
942 m_items.LockItemsForWrite(false);
761 m_inventorySerial++; 943 m_inventorySerial++;
762 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 944 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
763 945
764 HasInventoryChanged = true; 946 HasInventoryChanged = true;
765 m_part.ParentGroup.HasGroupChanged = true; 947 m_part.ParentGroup.HasGroupChanged = true;
766 948
767 if (!ContainsScripts()) 949 int scriptcount = 0;
950 m_items.LockItemsForRead(true);
951 foreach (TaskInventoryItem item in m_items.Values)
952 {
953 if (item.Type == 10)
954 {
955 scriptcount++;
956 }
957 }
958 m_items.LockItemsForRead(false);
959
960
961 if (scriptcount <= 0)
962 {
768 m_part.RemFlag(PrimFlags.Scripted); 963 m_part.RemFlag(PrimFlags.Scripted);
964 }
769 965
770 m_part.ScheduleFullUpdate(); 966 m_part.ScheduleFullUpdate();
771 967
772 return type; 968 return type;
773
774 } 969 }
775 else 970 else
776 { 971 {
972 m_items.LockItemsForRead(false);
777 m_log.ErrorFormat( 973 m_log.ErrorFormat(
778 "[PRIM INVENTORY]: " + 974 "[PRIM INVENTORY]: " +
779 "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory", 975 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
780 itemID, m_part.Name, m_part.UUID, 976 itemID, m_part.Name, m_part.UUID);
781 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
782 } 977 }
783 978
784 return -1; 979 return -1;
785 } 980 }
786 981
787 private bool CreateInventoryFile() 982 private bool CreateInventoryFileName()
788 { 983 {
789// m_log.DebugFormat( 984// m_log.DebugFormat(
790// "[PRIM INVENTORY]: Creating inventory file for {0} {1} {2}, serial {3}", 985// "[PRIM INVENTORY]: Creating inventory file for {0} {1} {2}, serial {3}",
@@ -793,116 +988,125 @@ namespace OpenSim.Region.Framework.Scenes
793 if (m_inventoryFileName == String.Empty || 988 if (m_inventoryFileName == String.Empty ||
794 m_inventoryFileNameSerial < m_inventorySerial) 989 m_inventoryFileNameSerial < m_inventorySerial)
795 { 990 {
796 // Something changed, we need to create a new file
797 m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp"; 991 m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp";
798 m_inventoryFileNameSerial = m_inventorySerial; 992 m_inventoryFileNameSerial = m_inventorySerial;
799 993
800 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); 994 return true;
995 }
996
997 return false;
998 }
999
1000 /// <summary>
1001 /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client
1002 /// </summary>
1003 /// <param name="xferManager"></param>
1004 public void RequestInventoryFile(IClientAPI client, IXfer xferManager)
1005 {
1006 bool changed = CreateInventoryFileName();
1007
1008 bool includeAssets = false;
1009 if (m_part.ParentGroup.Scene.Permissions.CanEditObjectInventory(m_part.UUID, client.AgentId))
1010 includeAssets = true;
1011
1012 if (m_inventoryPrivileged != includeAssets)
1013 changed = true;
1014
1015 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
801 1016
802 lock (m_items) 1017 Items.LockItemsForRead(true);
1018
1019 if (m_inventorySerial == 0) // No inventory
1020 {
1021 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
1022 Items.LockItemsForRead(false);
1023 return;
1024 }
1025
1026 if (m_items.Count == 0) // No inventory
1027 {
1028 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
1029 Items.LockItemsForRead(false);
1030 return;
1031 }
1032
1033 if (!changed)
1034 {
1035 if (m_inventoryFileData.Length > 2)
803 { 1036 {
804 foreach (TaskInventoryItem item in m_items.Values) 1037 xferManager.AddNewFile(m_inventoryFileName,
805 { 1038 m_inventoryFileData);
806// m_log.DebugFormat( 1039 client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial,
807// "[PRIM INVENTORY]: Adding item {0} {1} for serial {2} on prim {3} {4} {5}", 1040 Util.StringToBytes256(m_inventoryFileName));
808// item.Name, item.ItemID, m_inventorySerial, m_part.Name, m_part.UUID, m_part.LocalId);
809 1041
810 UUID ownerID = item.OwnerID; 1042 Items.LockItemsForRead(false);
811 uint everyoneMask = 0; 1043 return;
812 uint baseMask = item.BasePermissions; 1044 }
813 uint ownerMask = item.CurrentPermissions; 1045 }
814 uint groupMask = item.GroupPermissions;
815 1046
816 invString.AddItemStart(); 1047 m_inventoryPrivileged = includeAssets;
817 invString.AddNameValueLine("item_id", item.ItemID.ToString());
818 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
819 1048
820 invString.AddPermissionsStart(); 1049 foreach (TaskInventoryItem item in m_items.Values)
1050 {
1051 UUID ownerID = item.OwnerID;
1052 uint everyoneMask = 0;
1053 uint baseMask = item.BasePermissions;
1054 uint ownerMask = item.CurrentPermissions;
1055 uint groupMask = item.GroupPermissions;
821 1056
822 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); 1057 invString.AddItemStart();
823 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); 1058 invString.AddNameValueLine("item_id", item.ItemID.ToString());
824 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask)); 1059 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
825 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
826 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
827 1060
828 invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); 1061 invString.AddPermissionsStart();
829 invString.AddNameValueLine("owner_id", ownerID.ToString());
830 1062
831 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); 1063 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
1064 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
1065 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask));
1066 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
1067 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
832 1068
833 invString.AddNameValueLine("group_id", item.GroupID.ToString()); 1069 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
834 invString.AddSectionEnd(); 1070 invString.AddNameValueLine("owner_id", ownerID.ToString());
835 1071
836 invString.AddNameValueLine("asset_id", item.AssetID.ToString()); 1072 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
837 invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type));
838 invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType));
839 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
840 1073
841 invString.AddSaleStart(); 1074 invString.AddNameValueLine("group_id", item.GroupID.ToString());
842 invString.AddNameValueLine("sale_type", "not"); 1075 invString.AddSectionEnd();
843 invString.AddNameValueLine("sale_price", "0");
844 invString.AddSectionEnd();
845 1076
846 invString.AddNameValueLine("name", item.Name + "|"); 1077 if (includeAssets)
847 invString.AddNameValueLine("desc", item.Description + "|"); 1078 invString.AddNameValueLine("asset_id", item.AssetID.ToString());
1079 else
1080 invString.AddNameValueLine("asset_id", UUID.Zero.ToString());
1081 invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type));
1082 invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType));
1083 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
848 1084
849 invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); 1085 invString.AddSaleStart();
850 invString.AddSectionEnd(); 1086 invString.AddNameValueLine("sale_type", "not");
851 } 1087 invString.AddNameValueLine("sale_price", "0");
852 } 1088 invString.AddSectionEnd();
853 1089
854 m_inventoryFileData = Utils.StringToBytes(invString.BuildString); 1090 invString.AddNameValueLine("name", item.Name + "|");
1091 invString.AddNameValueLine("desc", item.Description + "|");
855 1092
856 return true; 1093 invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
1094 invString.AddSectionEnd();
857 } 1095 }
858 1096
859 // No need to recreate, the existing file is fine 1097 Items.LockItemsForRead(false);
860 return false;
861 }
862 1098
863 /// <summary> 1099 m_inventoryFileData = Utils.StringToBytes(invString.BuildString);
864 /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client
865 /// </summary>
866 /// <param name="xferManager"></param>
867 public void RequestInventoryFile(IClientAPI client, IXfer xferManager)
868 {
869 lock (m_items)
870 {
871 // Don't send a inventory xfer name if there are no items. Doing so causes viewer 3 to crash when rezzing
872 // a new script if any previous deletion has left the prim inventory empty.
873 if (m_items.Count == 0) // No inventory
874 {
875// m_log.DebugFormat(
876// "[PRIM INVENTORY]: Not sending inventory data for part {0} {1} {2} for {3} since no items",
877// m_part.Name, m_part.LocalId, m_part.UUID, client.Name);
878
879 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
880 return;
881 }
882 1100
883 CreateInventoryFile(); 1101 if (m_inventoryFileData.Length > 2)
884 1102 {
885 // In principle, we should only do the rest if the inventory changed; 1103 xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData);
886 // by sending m_inventorySerial to the client, it ought to know 1104 client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial,
887 // that nothing changed and that it doesn't need to request the file. 1105 Util.StringToBytes256(m_inventoryFileName));
888 // Unfortunately, it doesn't look like the client optimizes this; 1106 return;
889 // the client seems to always come back and request the Xfer,
890 // no matter what value m_inventorySerial has.
891 // FIXME: Could probably be > 0 here rather than > 2
892 if (m_inventoryFileData.Length > 2)
893 {
894 // Add the file for Xfer
895 // m_log.DebugFormat(
896 // "[PRIM INVENTORY]: Adding inventory file {0} (length {1}) for transfer on {2} {3} {4}",
897 // m_inventoryFileName, m_inventoryFileData.Length, m_part.Name, m_part.UUID, m_part.LocalId);
898
899 xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData);
900 }
901
902 // Tell the client we're ready to Xfer the file
903 client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial,
904 Util.StringToBytes256(m_inventoryFileName));
905 } 1107 }
1108
1109 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
906 } 1110 }
907 1111
908 /// <summary> 1112 /// <summary>
@@ -911,13 +1115,19 @@ namespace OpenSim.Region.Framework.Scenes
911 /// <param name="datastore"></param> 1115 /// <param name="datastore"></param>
912 public void ProcessInventoryBackup(ISimulationDataService datastore) 1116 public void ProcessInventoryBackup(ISimulationDataService datastore)
913 { 1117 {
914 if (HasInventoryChanged) 1118// Removed this because linking will cause an immediate delete of the new
915 { 1119// child prim from the database and the subsequent storing of the prim sees
916 HasInventoryChanged = false; 1120// the inventory of it as unchanged and doesn't store it at all. The overhead
917 List<TaskInventoryItem> items = GetInventoryItems(); 1121// of storing prim inventory needlessly is much less than the aggravation
918 datastore.StorePrimInventory(m_part.UUID, items); 1122// of prim inventory loss.
1123// if (HasInventoryChanged)
1124// {
1125 Items.LockItemsForRead(true);
1126 datastore.StorePrimInventory(m_part.UUID, Items.Values);
1127 Items.LockItemsForRead(false);
919 1128
920 } 1129 HasInventoryChanged = false;
1130// }
921 } 1131 }
922 1132
923 public class InventoryStringBuilder 1133 public class InventoryStringBuilder
@@ -983,82 +1193,63 @@ namespace OpenSim.Region.Framework.Scenes
983 { 1193 {
984 uint mask=0x7fffffff; 1194 uint mask=0x7fffffff;
985 1195
986 lock (m_items) 1196 foreach (TaskInventoryItem item in m_items.Values)
987 { 1197 {
988 foreach (TaskInventoryItem item in m_items.Values) 1198 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
1199 mask &= ~((uint)PermissionMask.Copy >> 13);
1200 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
1201 mask &= ~((uint)PermissionMask.Transfer >> 13);
1202 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
1203 mask &= ~((uint)PermissionMask.Modify >> 13);
1204
1205 if (item.InvType == (int)InventoryType.Object)
989 { 1206 {
990 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) 1207 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
991 mask &= ~((uint)PermissionMask.Copy >> 13); 1208 mask &= ~((uint)PermissionMask.Copy >> 13);
992 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) 1209 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
993 mask &= ~((uint)PermissionMask.Transfer >> 13); 1210 mask &= ~((uint)PermissionMask.Transfer >> 13);
994 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) 1211 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
995 mask &= ~((uint)PermissionMask.Modify >> 13); 1212 mask &= ~((uint)PermissionMask.Modify >> 13);
996
997 if (item.InvType != (int)InventoryType.Object)
998 {
999 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
1000 mask &= ~((uint)PermissionMask.Copy >> 13);
1001 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
1002 mask &= ~((uint)PermissionMask.Transfer >> 13);
1003 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
1004 mask &= ~((uint)PermissionMask.Modify >> 13);
1005 }
1006 else
1007 {
1008 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
1009 mask &= ~((uint)PermissionMask.Copy >> 13);
1010 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
1011 mask &= ~((uint)PermissionMask.Transfer >> 13);
1012 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1013 mask &= ~((uint)PermissionMask.Modify >> 13);
1014 }
1015
1016 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
1017 mask &= ~(uint)PermissionMask.Copy;
1018 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1019 mask &= ~(uint)PermissionMask.Transfer;
1020 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
1021 mask &= ~(uint)PermissionMask.Modify;
1022 } 1213 }
1214
1215 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
1216 mask &= ~(uint)PermissionMask.Copy;
1217 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1218 mask &= ~(uint)PermissionMask.Transfer;
1219 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
1220 mask &= ~(uint)PermissionMask.Modify;
1023 } 1221 }
1024
1025 return mask; 1222 return mask;
1026 } 1223 }
1027 1224
1028 public void ApplyNextOwnerPermissions() 1225 public void ApplyNextOwnerPermissions()
1029 { 1226 {
1030 lock (m_items) 1227 foreach (TaskInventoryItem item in m_items.Values)
1031 { 1228 {
1032 foreach (TaskInventoryItem item in m_items.Values) 1229 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
1033 { 1230 {
1034 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) 1231 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
1035 { 1232 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
1036 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) 1233 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
1037 item.CurrentPermissions &= ~(uint)PermissionMask.Copy; 1234 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
1038 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) 1235 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1039 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; 1236 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
1040 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1041 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
1042 }
1043 item.CurrentPermissions &= item.NextPermissions;
1044 item.BasePermissions &= item.NextPermissions;
1045 item.EveryonePermissions &= item.NextPermissions;
1046 item.OwnerChanged = true;
1047 item.PermsMask = 0;
1048 item.PermsGranter = UUID.Zero;
1049 } 1237 }
1238 item.OwnerChanged = true;
1239 item.CurrentPermissions &= item.NextPermissions;
1240 item.BasePermissions &= item.NextPermissions;
1241 item.EveryonePermissions &= item.NextPermissions;
1242 item.PermsMask = 0;
1243 item.PermsGranter = UUID.Zero;
1050 } 1244 }
1051 } 1245 }
1052 1246
1053 public void ApplyGodPermissions(uint perms) 1247 public void ApplyGodPermissions(uint perms)
1054 { 1248 {
1055 lock (m_items) 1249 foreach (TaskInventoryItem item in m_items.Values)
1056 { 1250 {
1057 foreach (TaskInventoryItem item in m_items.Values) 1251 item.CurrentPermissions = perms;
1058 { 1252 item.BasePermissions = perms;
1059 item.CurrentPermissions = perms;
1060 item.BasePermissions = perms;
1061 }
1062 } 1253 }
1063 1254
1064 m_inventorySerial++; 1255 m_inventorySerial++;
@@ -1071,14 +1262,11 @@ namespace OpenSim.Region.Framework.Scenes
1071 /// <returns></returns> 1262 /// <returns></returns>
1072 public bool ContainsScripts() 1263 public bool ContainsScripts()
1073 { 1264 {
1074 lock (m_items) 1265 foreach (TaskInventoryItem item in m_items.Values)
1075 { 1266 {
1076 foreach (TaskInventoryItem item in m_items.Values) 1267 if (item.InvType == (int)InventoryType.LSL)
1077 { 1268 {
1078 if (item.InvType == (int)InventoryType.LSL) 1269 return true;
1079 {
1080 return true;
1081 }
1082 } 1270 }
1083 } 1271 }
1084 1272
@@ -1092,17 +1280,15 @@ namespace OpenSim.Region.Framework.Scenes
1092 public int ScriptCount() 1280 public int ScriptCount()
1093 { 1281 {
1094 int count = 0; 1282 int count = 0;
1095 lock (m_items) 1283 Items.LockItemsForRead(true);
1284 foreach (TaskInventoryItem item in m_items.Values)
1096 { 1285 {
1097 foreach (TaskInventoryItem item in m_items.Values) 1286 if (item.InvType == (int)InventoryType.LSL)
1098 { 1287 {
1099 if (item.InvType == (int)InventoryType.LSL) 1288 count++;
1100 {
1101 count++;
1102 }
1103 } 1289 }
1104 } 1290 }
1105 1291 Items.LockItemsForRead(false);
1106 return count; 1292 return count;
1107 } 1293 }
1108 /// <summary> 1294 /// <summary>
@@ -1138,11 +1324,8 @@ namespace OpenSim.Region.Framework.Scenes
1138 { 1324 {
1139 List<UUID> ret = new List<UUID>(); 1325 List<UUID> ret = new List<UUID>();
1140 1326
1141 lock (m_items) 1327 foreach (TaskInventoryItem item in m_items.Values)
1142 { 1328 ret.Add(item.ItemID);
1143 foreach (TaskInventoryItem item in m_items.Values)
1144 ret.Add(item.ItemID);
1145 }
1146 1329
1147 return ret; 1330 return ret;
1148 } 1331 }
@@ -1151,8 +1334,9 @@ namespace OpenSim.Region.Framework.Scenes
1151 { 1334 {
1152 List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); 1335 List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
1153 1336
1154 lock (m_items) 1337 Items.LockItemsForRead(true);
1155 ret = new List<TaskInventoryItem>(m_items.Values); 1338 ret = new List<TaskInventoryItem>(m_items.Values);
1339 Items.LockItemsForRead(false);
1156 1340
1157 return ret; 1341 return ret;
1158 } 1342 }
@@ -1161,18 +1345,24 @@ namespace OpenSim.Region.Framework.Scenes
1161 { 1345 {
1162 List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); 1346 List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
1163 1347
1164 lock (m_items) 1348 Items.LockItemsForRead(true);
1165 { 1349
1166 foreach (TaskInventoryItem item in m_items.Values) 1350 foreach (TaskInventoryItem item in m_items.Values)
1167 if (item.InvType == (int)type) 1351 if (item.InvType == (int)type)
1168 ret.Add(item); 1352 ret.Add(item);
1169 } 1353
1354 Items.LockItemsForRead(false);
1170 1355
1171 return ret; 1356 return ret;
1172 } 1357 }
1173 1358
1174 public Dictionary<UUID, string> GetScriptStates() 1359 public Dictionary<UUID, string> GetScriptStates()
1175 { 1360 {
1361 return GetScriptStates(false);
1362 }
1363
1364 public Dictionary<UUID, string> GetScriptStates(bool oldIDs)
1365 {
1176 Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); 1366 Dictionary<UUID, string> ret = new Dictionary<UUID, string>();
1177 1367
1178 if (m_part.ParentGroup.Scene == null) // Group not in a scene 1368 if (m_part.ParentGroup.Scene == null) // Group not in a scene
@@ -1194,14 +1384,21 @@ namespace OpenSim.Region.Framework.Scenes
1194 string n = e.GetXMLState(item.ItemID); 1384 string n = e.GetXMLState(item.ItemID);
1195 if (n != String.Empty) 1385 if (n != String.Empty)
1196 { 1386 {
1197 if (!ret.ContainsKey(item.ItemID)) 1387 if (oldIDs)
1198 ret[item.ItemID] = n; 1388 {
1389 if (!ret.ContainsKey(item.OldItemID))
1390 ret[item.OldItemID] = n;
1391 }
1392 else
1393 {
1394 if (!ret.ContainsKey(item.ItemID))
1395 ret[item.ItemID] = n;
1396 }
1199 break; 1397 break;
1200 } 1398 }
1201 } 1399 }
1202 } 1400 }
1203 } 1401 }
1204
1205 return ret; 1402 return ret;
1206 } 1403 }
1207 1404