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.cs787
1 files changed, 491 insertions, 296 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index 8810903..f5b9825 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 }
217 } 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 }
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 {
311 m_items[item.ItemID].OldItemID = item.OldItemID;
312 m_items[item.ItemID].PermsMask = 0;
313 m_items[item.ItemID].PermsGranter = UUID.Zero;
314 }
315 362
363 m_items[item.ItemID].OldItemID = item.OldItemID;
364 m_items[item.ItemID].PermsMask = 0;
365 m_items[item.ItemID].PermsGranter = UUID.Zero;
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,23 +753,24 @@ 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
585 public TaskInventoryItem GetInventoryItem(string name) 762 public TaskInventoryItem GetInventoryItem(string name)
586 { 763 {
587 lock (m_items) 764 m_items.LockItemsForRead(true);
765 foreach (TaskInventoryItem item in m_items.Values)
588 { 766 {
589 foreach (TaskInventoryItem item in m_items.Values) 767 if (item.Name == name)
590 { 768 {
591 if (item.Name == name) 769 return item;
592 return item; 770 m_items.LockItemsForRead(false);
593 } 771 }
594 } 772 }
773 m_items.LockItemsForRead(false);
595 774
596 return null; 775 return null;
597 } 776 }
@@ -600,15 +779,16 @@ namespace OpenSim.Region.Framework.Scenes
600 { 779 {
601 List<TaskInventoryItem> items = new List<TaskInventoryItem>(); 780 List<TaskInventoryItem> items = new List<TaskInventoryItem>();
602 781
603 lock (m_items) 782 m_items.LockItemsForRead(true);
783
784 foreach (TaskInventoryItem item in m_items.Values)
604 { 785 {
605 foreach (TaskInventoryItem item in m_items.Values) 786 if (item.Name == name)
606 { 787 items.Add(item);
607 if (item.Name == name)
608 items.Add(item);
609 }
610 } 788 }
611 789
790 m_items.LockItemsForRead(false);
791
612 return items; 792 return items;
613 } 793 }
614 794
@@ -627,6 +807,10 @@ namespace OpenSim.Region.Framework.Scenes
627 string xmlData = Utils.BytesToString(rezAsset.Data); 807 string xmlData = Utils.BytesToString(rezAsset.Data);
628 SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); 808 SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
629 809
810 group.RootPart.AttachPoint = group.RootPart.Shape.State;
811 group.RootPart.AttachOffset = group.AbsolutePosition;
812 group.RootPart.AttachRotation = group.GroupRotation;
813
630 group.ResetIDs(); 814 group.ResetIDs();
631 815
632 SceneObjectPart rootPart = group.GetPart(group.UUID); 816 SceneObjectPart rootPart = group.GetPart(group.UUID);
@@ -701,8 +885,9 @@ namespace OpenSim.Region.Framework.Scenes
701 885
702 public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged) 886 public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged)
703 { 887 {
704 TaskInventoryItem it = GetInventoryItem(item.ItemID); 888 m_items.LockItemsForWrite(true);
705 if (it != null) 889
890 if (m_items.ContainsKey(item.ItemID))
706 { 891 {
707// m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name); 892// m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name);
708 893
@@ -715,14 +900,10 @@ namespace OpenSim.Region.Framework.Scenes
715 item.GroupID = m_part.GroupID; 900 item.GroupID = m_part.GroupID;
716 901
717 if (item.AssetID == UUID.Zero) 902 if (item.AssetID == UUID.Zero)
718 item.AssetID = it.AssetID; 903 item.AssetID = m_items[item.ItemID].AssetID;
719 904
720 lock (m_items) 905 m_items[item.ItemID] = item;
721 { 906 m_inventorySerial++;
722 m_items[item.ItemID] = item;
723 m_inventorySerial++;
724 }
725
726 if (fireScriptEvents) 907 if (fireScriptEvents)
727 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 908 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
728 909
@@ -731,7 +912,7 @@ namespace OpenSim.Region.Framework.Scenes
731 HasInventoryChanged = true; 912 HasInventoryChanged = true;
732 m_part.ParentGroup.HasGroupChanged = true; 913 m_part.ParentGroup.HasGroupChanged = true;
733 } 914 }
734 915 m_items.LockItemsForWrite(false);
735 return true; 916 return true;
736 } 917 }
737 else 918 else
@@ -742,8 +923,9 @@ namespace OpenSim.Region.Framework.Scenes
742 item.ItemID, m_part.Name, m_part.UUID, 923 item.ItemID, m_part.Name, m_part.UUID,
743 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); 924 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
744 } 925 }
745 return false; 926 m_items.LockItemsForWrite(false);
746 927
928 return false;
747 } 929 }
748 930
749 /// <summary> 931 /// <summary>
@@ -754,43 +936,59 @@ namespace OpenSim.Region.Framework.Scenes
754 /// in this prim's inventory.</returns> 936 /// in this prim's inventory.</returns>
755 public int RemoveInventoryItem(UUID itemID) 937 public int RemoveInventoryItem(UUID itemID)
756 { 938 {
757 TaskInventoryItem item = GetInventoryItem(itemID); 939 m_items.LockItemsForRead(true);
758 if (item != null) 940
941 if (m_items.ContainsKey(itemID))
759 { 942 {
760 int type = m_items[itemID].InvType; 943 int type = m_items[itemID].InvType;
944 m_items.LockItemsForRead(false);
761 if (type == 10) // Script 945 if (type == 10) // Script
762 { 946 {
763 m_part.RemoveScriptEvents(itemID);
764 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); 947 m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID);
765 } 948 }
949 m_items.LockItemsForWrite(true);
766 m_items.Remove(itemID); 950 m_items.Remove(itemID);
951 m_items.LockItemsForWrite(false);
767 m_inventorySerial++; 952 m_inventorySerial++;
768 m_part.TriggerScriptChangedEvent(Changed.INVENTORY); 953 m_part.TriggerScriptChangedEvent(Changed.INVENTORY);
769 954
770 HasInventoryChanged = true; 955 HasInventoryChanged = true;
771 m_part.ParentGroup.HasGroupChanged = true; 956 m_part.ParentGroup.HasGroupChanged = true;
772 957
773 if (!ContainsScripts()) 958 int scriptcount = 0;
959 m_items.LockItemsForRead(true);
960 foreach (TaskInventoryItem item in m_items.Values)
961 {
962 if (item.Type == 10)
963 {
964 scriptcount++;
965 }
966 }
967 m_items.LockItemsForRead(false);
968
969
970 if (scriptcount <= 0)
971 {
774 m_part.RemFlag(PrimFlags.Scripted); 972 m_part.RemFlag(PrimFlags.Scripted);
973 }
775 974
776 m_part.ScheduleFullUpdate(); 975 m_part.ScheduleFullUpdate();
777 976
778 return type; 977 return type;
779
780 } 978 }
781 else 979 else
782 { 980 {
981 m_items.LockItemsForRead(false);
783 m_log.ErrorFormat( 982 m_log.ErrorFormat(
784 "[PRIM INVENTORY]: " + 983 "[PRIM INVENTORY]: " +
785 "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory", 984 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
786 itemID, m_part.Name, m_part.UUID, 985 itemID, m_part.Name, m_part.UUID);
787 m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
788 } 986 }
789 987
790 return -1; 988 return -1;
791 } 989 }
792 990
793 private bool CreateInventoryFile() 991 private bool CreateInventoryFileName()
794 { 992 {
795// m_log.DebugFormat( 993// m_log.DebugFormat(
796// "[PRIM INVENTORY]: Creating inventory file for {0} {1} {2}, serial {3}", 994// "[PRIM INVENTORY]: Creating inventory file for {0} {1} {2}, serial {3}",
@@ -799,116 +997,125 @@ namespace OpenSim.Region.Framework.Scenes
799 if (m_inventoryFileName == String.Empty || 997 if (m_inventoryFileName == String.Empty ||
800 m_inventoryFileNameSerial < m_inventorySerial) 998 m_inventoryFileNameSerial < m_inventorySerial)
801 { 999 {
802 // Something changed, we need to create a new file
803 m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp"; 1000 m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp";
804 m_inventoryFileNameSerial = m_inventorySerial; 1001 m_inventoryFileNameSerial = m_inventorySerial;
805 1002
806 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); 1003 return true;
1004 }
1005
1006 return false;
1007 }
1008
1009 /// <summary>
1010 /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client
1011 /// </summary>
1012 /// <param name="xferManager"></param>
1013 public void RequestInventoryFile(IClientAPI client, IXfer xferManager)
1014 {
1015 bool changed = CreateInventoryFileName();
1016
1017 bool includeAssets = false;
1018 if (m_part.ParentGroup.Scene.Permissions.CanEditObjectInventory(m_part.UUID, client.AgentId))
1019 includeAssets = true;
1020
1021 if (m_inventoryPrivileged != includeAssets)
1022 changed = true;
1023
1024 InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero);
807 1025
808 lock (m_items) 1026 Items.LockItemsForRead(true);
1027
1028 if (m_inventorySerial == 0) // No inventory
1029 {
1030 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
1031 Items.LockItemsForRead(false);
1032 return;
1033 }
1034
1035 if (m_items.Count == 0) // No inventory
1036 {
1037 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
1038 Items.LockItemsForRead(false);
1039 return;
1040 }
1041
1042 if (!changed)
1043 {
1044 if (m_inventoryFileData.Length > 2)
809 { 1045 {
810 foreach (TaskInventoryItem item in m_items.Values) 1046 xferManager.AddNewFile(m_inventoryFileName,
811 { 1047 m_inventoryFileData);
812// m_log.DebugFormat( 1048 client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial,
813// "[PRIM INVENTORY]: Adding item {0} {1} for serial {2} on prim {3} {4} {5}", 1049 Util.StringToBytes256(m_inventoryFileName));
814// item.Name, item.ItemID, m_inventorySerial, m_part.Name, m_part.UUID, m_part.LocalId);
815 1050
816 UUID ownerID = item.OwnerID; 1051 Items.LockItemsForRead(false);
817 uint everyoneMask = 0; 1052 return;
818 uint baseMask = item.BasePermissions; 1053 }
819 uint ownerMask = item.CurrentPermissions; 1054 }
820 uint groupMask = item.GroupPermissions;
821 1055
822 invString.AddItemStart(); 1056 m_inventoryPrivileged = includeAssets;
823 invString.AddNameValueLine("item_id", item.ItemID.ToString());
824 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
825 1057
826 invString.AddPermissionsStart(); 1058 foreach (TaskInventoryItem item in m_items.Values)
1059 {
1060 UUID ownerID = item.OwnerID;
1061 uint everyoneMask = 0;
1062 uint baseMask = item.BasePermissions;
1063 uint ownerMask = item.CurrentPermissions;
1064 uint groupMask = item.GroupPermissions;
827 1065
828 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); 1066 invString.AddItemStart();
829 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); 1067 invString.AddNameValueLine("item_id", item.ItemID.ToString());
830 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask)); 1068 invString.AddNameValueLine("parent_id", m_part.UUID.ToString());
831 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
832 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
833 1069
834 invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); 1070 invString.AddPermissionsStart();
835 invString.AddNameValueLine("owner_id", ownerID.ToString());
836 1071
837 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); 1072 invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask));
1073 invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask));
1074 invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask));
1075 invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask));
1076 invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions));
838 1077
839 invString.AddNameValueLine("group_id", item.GroupID.ToString()); 1078 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
840 invString.AddSectionEnd(); 1079 invString.AddNameValueLine("owner_id", ownerID.ToString());
841 1080
842 invString.AddNameValueLine("asset_id", item.AssetID.ToString()); 1081 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
843 invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type));
844 invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType));
845 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
846 1082
847 invString.AddSaleStart(); 1083 invString.AddNameValueLine("group_id", item.GroupID.ToString());
848 invString.AddNameValueLine("sale_type", "not"); 1084 invString.AddSectionEnd();
849 invString.AddNameValueLine("sale_price", "0");
850 invString.AddSectionEnd();
851 1085
852 invString.AddNameValueLine("name", item.Name + "|"); 1086 if (includeAssets)
853 invString.AddNameValueLine("desc", item.Description + "|"); 1087 invString.AddNameValueLine("asset_id", item.AssetID.ToString());
1088 else
1089 invString.AddNameValueLine("asset_id", UUID.Zero.ToString());
1090 invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type));
1091 invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType));
1092 invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags));
854 1093
855 invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); 1094 invString.AddSaleStart();
856 invString.AddSectionEnd(); 1095 invString.AddNameValueLine("sale_type", "not");
857 } 1096 invString.AddNameValueLine("sale_price", "0");
858 } 1097 invString.AddSectionEnd();
859 1098
860 m_inventoryFileData = Utils.StringToBytes(invString.BuildString); 1099 invString.AddNameValueLine("name", item.Name + "|");
1100 invString.AddNameValueLine("desc", item.Description + "|");
861 1101
862 return true; 1102 invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
1103 invString.AddSectionEnd();
863 } 1104 }
864 1105
865 // No need to recreate, the existing file is fine 1106 Items.LockItemsForRead(false);
866 return false;
867 }
868 1107
869 /// <summary> 1108 m_inventoryFileData = Utils.StringToBytes(invString.BuildString);
870 /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client
871 /// </summary>
872 /// <param name="xferManager"></param>
873 public void RequestInventoryFile(IClientAPI client, IXfer xferManager)
874 {
875 lock (m_items)
876 {
877 // Don't send a inventory xfer name if there are no items. Doing so causes viewer 3 to crash when rezzing
878 // a new script if any previous deletion has left the prim inventory empty.
879 if (m_items.Count == 0) // No inventory
880 {
881// m_log.DebugFormat(
882// "[PRIM INVENTORY]: Not sending inventory data for part {0} {1} {2} for {3} since no items",
883// m_part.Name, m_part.LocalId, m_part.UUID, client.Name);
884
885 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
886 return;
887 }
888 1109
889 CreateInventoryFile(); 1110 if (m_inventoryFileData.Length > 2)
890 1111 {
891 // In principle, we should only do the rest if the inventory changed; 1112 xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData);
892 // by sending m_inventorySerial to the client, it ought to know 1113 client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial,
893 // that nothing changed and that it doesn't need to request the file. 1114 Util.StringToBytes256(m_inventoryFileName));
894 // Unfortunately, it doesn't look like the client optimizes this; 1115 return;
895 // the client seems to always come back and request the Xfer,
896 // no matter what value m_inventorySerial has.
897 // FIXME: Could probably be > 0 here rather than > 2
898 if (m_inventoryFileData.Length > 2)
899 {
900 // Add the file for Xfer
901 // m_log.DebugFormat(
902 // "[PRIM INVENTORY]: Adding inventory file {0} (length {1}) for transfer on {2} {3} {4}",
903 // m_inventoryFileName, m_inventoryFileData.Length, m_part.Name, m_part.UUID, m_part.LocalId);
904
905 xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData);
906 }
907
908 // Tell the client we're ready to Xfer the file
909 client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial,
910 Util.StringToBytes256(m_inventoryFileName));
911 } 1116 }
1117
1118 client.SendTaskInventory(m_part.UUID, 0, new byte[0]);
912 } 1119 }
913 1120
914 /// <summary> 1121 /// <summary>
@@ -917,13 +1124,19 @@ namespace OpenSim.Region.Framework.Scenes
917 /// <param name="datastore"></param> 1124 /// <param name="datastore"></param>
918 public void ProcessInventoryBackup(ISimulationDataService datastore) 1125 public void ProcessInventoryBackup(ISimulationDataService datastore)
919 { 1126 {
920 if (HasInventoryChanged) 1127// Removed this because linking will cause an immediate delete of the new
921 { 1128// child prim from the database and the subsequent storing of the prim sees
922 HasInventoryChanged = false; 1129// the inventory of it as unchanged and doesn't store it at all. The overhead
923 List<TaskInventoryItem> items = GetInventoryItems(); 1130// of storing prim inventory needlessly is much less than the aggravation
924 datastore.StorePrimInventory(m_part.UUID, items); 1131// of prim inventory loss.
1132// if (HasInventoryChanged)
1133// {
1134 Items.LockItemsForRead(true);
1135 datastore.StorePrimInventory(m_part.UUID, Items.Values);
1136 Items.LockItemsForRead(false);
925 1137
926 } 1138 HasInventoryChanged = false;
1139// }
927 } 1140 }
928 1141
929 public class InventoryStringBuilder 1142 public class InventoryStringBuilder
@@ -989,87 +1202,63 @@ namespace OpenSim.Region.Framework.Scenes
989 { 1202 {
990 uint mask=0x7fffffff; 1203 uint mask=0x7fffffff;
991 1204
992 lock (m_items) 1205 foreach (TaskInventoryItem item in m_items.Values)
993 { 1206 {
994 foreach (TaskInventoryItem item in m_items.Values) 1207 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
1208 mask &= ~((uint)PermissionMask.Copy >> 13);
1209 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
1210 mask &= ~((uint)PermissionMask.Transfer >> 13);
1211 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
1212 mask &= ~((uint)PermissionMask.Modify >> 13);
1213
1214 if (item.InvType == (int)InventoryType.Object)
995 { 1215 {
996 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) 1216 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
997 mask &= ~((uint)PermissionMask.Copy >> 13); 1217 mask &= ~((uint)PermissionMask.Copy >> 13);
998 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) 1218 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
999 mask &= ~((uint)PermissionMask.Transfer >> 13); 1219 mask &= ~((uint)PermissionMask.Transfer >> 13);
1000 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) 1220 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1001 mask &= ~((uint)PermissionMask.Modify >> 13); 1221 mask &= ~((uint)PermissionMask.Modify >> 13);
1002
1003 if (item.InvType != (int)InventoryType.Object)
1004 {
1005 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0)
1006 mask &= ~((uint)PermissionMask.Copy >> 13);
1007 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0)
1008 mask &= ~((uint)PermissionMask.Transfer >> 13);
1009 if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0)
1010 mask &= ~((uint)PermissionMask.Modify >> 13);
1011 }
1012 else
1013 {
1014 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
1015 mask &= ~((uint)PermissionMask.Copy >> 13);
1016 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
1017 mask &= ~((uint)PermissionMask.Transfer >> 13);
1018 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1019 mask &= ~((uint)PermissionMask.Modify >> 13);
1020 }
1021
1022 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
1023 mask &= ~(uint)PermissionMask.Copy;
1024 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1025 mask &= ~(uint)PermissionMask.Transfer;
1026 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
1027 mask &= ~(uint)PermissionMask.Modify;
1028 } 1222 }
1223
1224 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
1225 mask &= ~(uint)PermissionMask.Copy;
1226 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
1227 mask &= ~(uint)PermissionMask.Transfer;
1228 if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
1229 mask &= ~(uint)PermissionMask.Modify;
1029 } 1230 }
1030
1031 return mask; 1231 return mask;
1032 } 1232 }
1033 1233
1034 public void ApplyNextOwnerPermissions() 1234 public void ApplyNextOwnerPermissions()
1035 { 1235 {
1036 lock (m_items) 1236 foreach (TaskInventoryItem item in m_items.Values)
1037 { 1237 {
1038 foreach (TaskInventoryItem item in m_items.Values) 1238 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
1039 { 1239 {
1040// m_log.DebugFormat ( 1240 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
1041// "[SCENE OBJECT PART INVENTORY]: Applying next permissions {0} to {1} in {2} with current {3}, base {4}, everyone {5}", 1241 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
1042// item.NextPermissions, item.Name, m_part.Name, item.CurrentPermissions, item.BasePermissions, item.EveryonePermissions); 1242 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
1043 1243 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
1044 if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) 1244 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1045 { 1245 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
1046 if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
1047 item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
1048 if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
1049 item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
1050 if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
1051 item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
1052 }
1053
1054 item.CurrentPermissions &= item.NextPermissions;
1055 item.BasePermissions &= item.NextPermissions;
1056 item.EveryonePermissions &= item.NextPermissions;
1057 item.OwnerChanged = true;
1058 item.PermsMask = 0;
1059 item.PermsGranter = UUID.Zero;
1060 } 1246 }
1247 item.CurrentPermissions &= item.NextPermissions;
1248 item.BasePermissions &= item.NextPermissions;
1249 item.EveryonePermissions &= item.NextPermissions;
1250 item.OwnerChanged = true;
1251 item.PermsMask = 0;
1252 item.PermsGranter = UUID.Zero;
1061 } 1253 }
1062 } 1254 }
1063 1255
1064 public void ApplyGodPermissions(uint perms) 1256 public void ApplyGodPermissions(uint perms)
1065 { 1257 {
1066 lock (m_items) 1258 foreach (TaskInventoryItem item in m_items.Values)
1067 { 1259 {
1068 foreach (TaskInventoryItem item in m_items.Values) 1260 item.CurrentPermissions = perms;
1069 { 1261 item.BasePermissions = perms;
1070 item.CurrentPermissions = perms;
1071 item.BasePermissions = perms;
1072 }
1073 } 1262 }
1074 1263
1075 m_inventorySerial++; 1264 m_inventorySerial++;
@@ -1082,14 +1271,11 @@ namespace OpenSim.Region.Framework.Scenes
1082 /// <returns></returns> 1271 /// <returns></returns>
1083 public bool ContainsScripts() 1272 public bool ContainsScripts()
1084 { 1273 {
1085 lock (m_items) 1274 foreach (TaskInventoryItem item in m_items.Values)
1086 { 1275 {
1087 foreach (TaskInventoryItem item in m_items.Values) 1276 if (item.InvType == (int)InventoryType.LSL)
1088 { 1277 {
1089 if (item.InvType == (int)InventoryType.LSL) 1278 return true;
1090 {
1091 return true;
1092 }
1093 } 1279 }
1094 } 1280 }
1095 1281
@@ -1103,17 +1289,15 @@ namespace OpenSim.Region.Framework.Scenes
1103 public int ScriptCount() 1289 public int ScriptCount()
1104 { 1290 {
1105 int count = 0; 1291 int count = 0;
1106 lock (m_items) 1292 Items.LockItemsForRead(true);
1293 foreach (TaskInventoryItem item in m_items.Values)
1107 { 1294 {
1108 foreach (TaskInventoryItem item in m_items.Values) 1295 if (item.InvType == (int)InventoryType.LSL)
1109 { 1296 {
1110 if (item.InvType == (int)InventoryType.LSL) 1297 count++;
1111 {
1112 count++;
1113 }
1114 } 1298 }
1115 } 1299 }
1116 1300 Items.LockItemsForRead(false);
1117 return count; 1301 return count;
1118 } 1302 }
1119 /// <summary> 1303 /// <summary>
@@ -1149,11 +1333,8 @@ namespace OpenSim.Region.Framework.Scenes
1149 { 1333 {
1150 List<UUID> ret = new List<UUID>(); 1334 List<UUID> ret = new List<UUID>();
1151 1335
1152 lock (m_items) 1336 foreach (TaskInventoryItem item in m_items.Values)
1153 { 1337 ret.Add(item.ItemID);
1154 foreach (TaskInventoryItem item in m_items.Values)
1155 ret.Add(item.ItemID);
1156 }
1157 1338
1158 return ret; 1339 return ret;
1159 } 1340 }
@@ -1162,8 +1343,9 @@ namespace OpenSim.Region.Framework.Scenes
1162 { 1343 {
1163 List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); 1344 List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
1164 1345
1165 lock (m_items) 1346 Items.LockItemsForRead(true);
1166 ret = new List<TaskInventoryItem>(m_items.Values); 1347 ret = new List<TaskInventoryItem>(m_items.Values);
1348 Items.LockItemsForRead(false);
1167 1349
1168 return ret; 1350 return ret;
1169 } 1351 }
@@ -1172,18 +1354,24 @@ namespace OpenSim.Region.Framework.Scenes
1172 { 1354 {
1173 List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); 1355 List<TaskInventoryItem> ret = new List<TaskInventoryItem>();
1174 1356
1175 lock (m_items) 1357 Items.LockItemsForRead(true);
1176 { 1358
1177 foreach (TaskInventoryItem item in m_items.Values) 1359 foreach (TaskInventoryItem item in m_items.Values)
1178 if (item.InvType == (int)type) 1360 if (item.InvType == (int)type)
1179 ret.Add(item); 1361 ret.Add(item);
1180 } 1362
1363 Items.LockItemsForRead(false);
1181 1364
1182 return ret; 1365 return ret;
1183 } 1366 }
1184 1367
1185 public Dictionary<UUID, string> GetScriptStates() 1368 public Dictionary<UUID, string> GetScriptStates()
1186 { 1369 {
1370 return GetScriptStates(false);
1371 }
1372
1373 public Dictionary<UUID, string> GetScriptStates(bool oldIDs)
1374 {
1187 Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); 1375 Dictionary<UUID, string> ret = new Dictionary<UUID, string>();
1188 1376
1189 if (m_part.ParentGroup.Scene == null) // Group not in a scene 1377 if (m_part.ParentGroup.Scene == null) // Group not in a scene
@@ -1205,14 +1393,21 @@ namespace OpenSim.Region.Framework.Scenes
1205 string n = e.GetXMLState(item.ItemID); 1393 string n = e.GetXMLState(item.ItemID);
1206 if (n != String.Empty) 1394 if (n != String.Empty)
1207 { 1395 {
1208 if (!ret.ContainsKey(item.ItemID)) 1396 if (oldIDs)
1209 ret[item.ItemID] = n; 1397 {
1398 if (!ret.ContainsKey(item.OldItemID))
1399 ret[item.OldItemID] = n;
1400 }
1401 else
1402 {
1403 if (!ret.ContainsKey(item.ItemID))
1404 ret[item.ItemID] = n;
1405 }
1210 break; 1406 break;
1211 } 1407 }
1212 } 1408 }
1213 } 1409 }
1214 } 1410 }
1215
1216 return ret; 1411 return ret;
1217 } 1412 }
1218 1413
@@ -1245,4 +1440,4 @@ namespace OpenSim.Region.Framework.Scenes
1245 } 1440 }
1246 } 1441 }
1247 } 1442 }
1248} \ No newline at end of file 1443}