aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-02-20 14:04:29 +0000
committerJustin Clarke Casey2009-02-20 14:04:29 +0000
commit01f70de2ea562f78991084be01a83295f8f2be0b (patch)
treeff43706bf83039ce9d9c6c5bfffe56f2df1d1c86 /OpenSim
parentRevert previous commit (diff)
downloadopensim-SC-01f70de2ea562f78991084be01a83295f8f2be0b.zip
opensim-SC-01f70de2ea562f78991084be01a83295f8f2be0b.tar.gz
opensim-SC-01f70de2ea562f78991084be01a83295f8f2be0b.tar.bz2
opensim-SC-01f70de2ea562f78991084be01a83295f8f2be0b.tar.xz
* Consistently lock part.TaskInventory as pointed out in http://opensimulator.org/mantis/view.php?id=3159
* Not locking causes enumeration exceptions as described in this matis * part.TaskInventory needs to be locked for every access as it's a dictionary * Extra locking will hopefully not cause any major issues - in places where the enumeration of the dictionary performs other lock or long running operations, the dictionary is cloned instead
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/TaskInventoryDictionary.cs4
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs19
-rw-r--r--OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs7
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs34
-rw-r--r--OpenSim/Region/Framework/Scenes/UuidGatherer.cs6
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs517
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs28
7 files changed, 414 insertions, 201 deletions
diff --git a/OpenSim/Framework/TaskInventoryDictionary.cs b/OpenSim/Framework/TaskInventoryDictionary.cs
index 4a1aa17..defac23 100644
--- a/OpenSim/Framework/TaskInventoryDictionary.cs
+++ b/OpenSim/Framework/TaskInventoryDictionary.cs
@@ -36,9 +36,9 @@ namespace OpenSim.Framework
36{ 36{
37 /// <summary> 37 /// <summary>
38 /// A dictionary for task inventory. 38 /// A dictionary for task inventory.
39 ///
40 /// This class is not thread safe. Callers must synchronize on Dictionary methods.
41 /// </summary> 39 /// </summary>
40 /// This class is not thread safe. Callers must synchronize on Dictionary methods or Clone() this object before
41 /// iterating over it.
42 public class TaskInventoryDictionary : Dictionary<UUID, TaskInventoryItem>, 42 public class TaskInventoryDictionary : Dictionary<UUID, TaskInventoryItem>,
43 ICloneable, IXmlSerializable 43 ICloneable, IXmlSerializable
44 { 44 {
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
index d7ab5fd..fe1c42b 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveReadRequest.cs
@@ -202,16 +202,19 @@ namespace OpenSim.Region.CoreModules.World.Archiver
202 // Fix ownership/creator of inventory items 202 // Fix ownership/creator of inventory items
203 // Not doing so results in inventory items 203 // Not doing so results in inventory items
204 // being no copy/no mod for everyone 204 // being no copy/no mod for everyone
205 TaskInventoryDictionary inv = part.TaskInventory; 205 lock (part.TaskInventory)
206 foreach (KeyValuePair<UUID, TaskInventoryItem> kvp in inv)
207 { 206 {
208 if (!ResolveUserUuid(kvp.Value.OwnerID)) 207 TaskInventoryDictionary inv = part.TaskInventory;
208 foreach (KeyValuePair<UUID, TaskInventoryItem> kvp in inv)
209 { 209 {
210 kvp.Value.OwnerID = masterAvatarId; 210 if (!ResolveUserUuid(kvp.Value.OwnerID))
211 } 211 {
212 if (!ResolveUserUuid(kvp.Value.CreatorID)) 212 kvp.Value.OwnerID = masterAvatarId;
213 { 213 }
214 kvp.Value.CreatorID = masterAvatarId; 214 if (!ResolveUserUuid(kvp.Value.CreatorID))
215 {
216 kvp.Value.CreatorID = masterAvatarId;
217 }
215 } 218 }
216 } 219 }
217 } 220 }
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs
index 1a3c4c8..f7db908 100644
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs
+++ b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs
@@ -226,9 +226,12 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid
226 { 226 {
227 TaskInventoryDictionary tinv = sog.RootPart.TaskInventory; 227 TaskInventoryDictionary tinv = sog.RootPart.TaskInventory;
228 228
229 foreach (TaskInventoryItem titem in tinv.Values) 229 lock (tinv)
230 { 230 {
231 uuids.Add(titem.AssetID, (InventoryType)titem.Type == InventoryType.Texture); 231 foreach (TaskInventoryItem titem in tinv.Values)
232 {
233 uuids.Add(titem.AssetID, (InventoryType)titem.Type == InventoryType.Texture);
234 }
232 } 235 }
233 } 236 }
234 237
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index ec3fdf1..27c22eb 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -1710,12 +1710,15 @@ if (m_shape != null) {
1710 info.AddValue("m_inventoryFileName", Inventory.GetInventoryFileName()); 1710 info.AddValue("m_inventoryFileName", Inventory.GetInventoryFileName());
1711 info.AddValue("m_folderID", UUID); 1711 info.AddValue("m_folderID", UUID);
1712 info.AddValue("PhysActor", PhysActor); 1712 info.AddValue("PhysActor", PhysActor);
1713 1713
1714 Dictionary<Guid, TaskInventoryItem> TaskInventory_work = new Dictionary<Guid, TaskInventoryItem>(); 1714 Dictionary<Guid, TaskInventoryItem> TaskInventory_work = new Dictionary<Guid, TaskInventoryItem>();
1715 1715
1716 foreach (UUID id in TaskInventory.Keys) 1716 lock (TaskInventory)
1717 { 1717 {
1718 TaskInventory_work.Add(id.Guid, TaskInventory[id]); 1718 foreach (UUID id in TaskInventory.Keys)
1719 {
1720 TaskInventory_work.Add(id.Guid, TaskInventory[id]);
1721 }
1719 } 1722 }
1720 1723
1721 info.AddValue("TaskInventory", TaskInventory_work); 1724 info.AddValue("TaskInventory", TaskInventory_work);
@@ -2166,13 +2169,16 @@ if (m_shape != null) {
2166 { 2169 {
2167 //Trys to fetch sound id from prim's inventory. 2170 //Trys to fetch sound id from prim's inventory.
2168 //Prim's inventory doesn't support non script items yet 2171 //Prim's inventory doesn't support non script items yet
2169 SceneObjectPart op = this; 2172
2170 foreach (KeyValuePair<UUID, TaskInventoryItem> item in op.TaskInventory) 2173 lock (TaskInventory)
2171 { 2174 {
2172 if (item.Value.Name == sound) 2175 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2173 { 2176 {
2174 soundID = item.Value.ItemID; 2177 if (item.Value.Name == sound)
2175 break; 2178 {
2179 soundID = item.Value.ItemID;
2180 break;
2181 }
2176 } 2182 }
2177 } 2183 }
2178 } 2184 }
@@ -2486,13 +2492,15 @@ if (m_shape != null) {
2486 if (!UUID.TryParse(sound, out soundID)) 2492 if (!UUID.TryParse(sound, out soundID))
2487 { 2493 {
2488 // search sound file from inventory 2494 // search sound file from inventory
2489 SceneObjectPart op = this; 2495 lock (TaskInventory)
2490 foreach (KeyValuePair<UUID, TaskInventoryItem> item in op.TaskInventory)
2491 { 2496 {
2492 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 2497 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2493 { 2498 {
2494 soundID = item.Value.ItemID; 2499 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
2495 break; 2500 {
2501 soundID = item.Value.ItemID;
2502 break;
2503 }
2496 } 2504 }
2497 } 2505 }
2498 } 2506 }
diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
index bc8896e..7b2fae0 100644
--- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
+++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
@@ -140,9 +140,11 @@ namespace OpenSim.Region.Framework.Scenes
140 // If the prim is a sculpt then preserve this information too 140 // If the prim is a sculpt then preserve this information too
141 if (part.Shape.SculptTexture != UUID.Zero) 141 if (part.Shape.SculptTexture != UUID.Zero)
142 assetUuids[part.Shape.SculptTexture] = 1; 142 assetUuids[part.Shape.SculptTexture] = 1;
143 143
144 TaskInventoryDictionary taskDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
145
144 // Now analyze this prim's inventory items to preserve all the uuids that they reference 146 // Now analyze this prim's inventory items to preserve all the uuids that they reference
145 foreach (TaskInventoryItem tii in part.TaskInventory.Values) 147 foreach (TaskInventoryItem tii in taskDictionary.Values)
146 { 148 {
147 //m_log.DebugFormat("[ARCHIVER]: Analysing item asset type {0}", tii.Type); 149 //m_log.DebugFormat("[ARCHIVER]: Analysing item asset type {0}", tii.Type);
148 150
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 5f6ea16..7e4a5a0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -250,12 +250,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
250 { 250 {
251 UUID invItemID = new UUID(); 251 UUID invItemID = new UUID();
252 252
253 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 253 lock (m_host.TaskInventory)
254 { 254 {
255 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID) 255 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
256 { 256 {
257 invItemID = inv.Key; 257 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
258 break; 258 {
259 invItemID = inv.Key;
260 break;
261 }
259 } 262 }
260 } 263 }
261 264
@@ -265,29 +268,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
265 private UUID InventoryKey(string name, int type) 268 private UUID InventoryKey(string name, int type)
266 { 269 {
267 m_host.AddScriptLPS(1); 270 m_host.AddScriptLPS(1);
268 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 271
272 lock (m_host.TaskInventory)
269 { 273 {
270 if (inv.Value.Name == name) 274 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
271 { 275 {
272 if (inv.Value.Type != type) 276 if (inv.Value.Name == name)
273 return UUID.Zero; 277 {
278 if (inv.Value.Type != type)
279 return UUID.Zero;
274 280
275 return inv.Value.AssetID; 281 return inv.Value.AssetID;
282 }
276 } 283 }
277 } 284 }
285
278 return UUID.Zero; 286 return UUID.Zero;
279 } 287 }
280 288
281 private UUID InventoryKey(string name) 289 private UUID InventoryKey(string name)
282 { 290 {
283 m_host.AddScriptLPS(1); 291 m_host.AddScriptLPS(1);
284 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 292
293 lock (m_host.TaskInventory)
285 { 294 {
286 if (inv.Value.Name == name) 295 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
287 { 296 {
288 return inv.Value.AssetID; 297 if (inv.Value.Name == name)
298 {
299 return inv.Value.AssetID;
300 }
289 } 301 }
290 } 302 }
303
291 return UUID.Zero; 304 return UUID.Zero;
292 } 305 }
293 306
@@ -2376,16 +2389,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2376 2389
2377 m_host.AddScriptLPS(1); 2390 m_host.AddScriptLPS(1);
2378 2391
2379 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 2392 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2393
2394 lock (m_host.TaskInventory)
2395 {
2396 item = m_host.TaskInventory[invItemID];
2397 }
2398
2399 if (item.PermsGranter == UUID.Zero)
2380 return 0; 2400 return 0;
2381 2401
2382 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0) 2402 if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
2383 { 2403 {
2384 LSLError("No permissions to give money"); 2404 LSLError("No permissions to give money");
2385 return 0; 2405 return 0;
2386 } 2406 }
2387 2407
2388 UUID toID=new UUID(); 2408 UUID toID = new UUID();
2389 2409
2390 if (!UUID.TryParse(destination, out toID)) 2410 if (!UUID.TryParse(destination, out toID))
2391 { 2411 {
@@ -2393,7 +2413,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2393 return 0; 2413 return 0;
2394 } 2414 }
2395 2415
2396 IMoneyModule money=World.RequestModuleInterface<IMoneyModule>(); 2416 IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
2397 2417
2398 if (money == null) 2418 if (money == null)
2399 { 2419 {
@@ -2401,7 +2421,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2401 return 0; 2421 return 0;
2402 } 2422 }
2403 2423
2404 bool result=money.ObjectGiveMoney(m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount); 2424 bool result
2425 = money.ObjectGiveMoney(
2426 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
2405 2427
2406 if (result) 2428 if (result)
2407 return 1; 2429 return 1;
@@ -2447,8 +2469,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2447 2469
2448 if (dist > m_ScriptDistanceFactor * 10.0f) 2470 if (dist > m_ScriptDistanceFactor * 10.0f)
2449 return; 2471 return;
2472
2473 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
2450 2474
2451 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 2475 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory)
2452 { 2476 {
2453 if (inv.Value.Name == inventory) 2477 if (inv.Value.Name == inventory)
2454 { 2478 {
@@ -2500,6 +2524,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2500 return; 2524 return;
2501 } 2525 }
2502 } 2526 }
2527
2503 llSay(0, "Could not find object " + inventory); 2528 llSay(0, "Could not find object " + inventory);
2504 } 2529 }
2505 2530
@@ -2571,18 +2596,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2571 2596
2572 public void llTakeControls(int controls, int accept, int pass_on) 2597 public void llTakeControls(int controls, int accept, int pass_on)
2573 { 2598 {
2574 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 2599 TaskInventoryItem item;
2600
2601 lock (m_host.TaskInventory)
2575 { 2602 {
2576 return; 2603 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2604 return;
2605 else
2606 item = m_host.TaskInventory[InventorySelf()];
2577 } 2607 }
2578 2608
2579 if (m_host.TaskInventory[InventorySelf()].PermsGranter != UUID.Zero) 2609 if (item.PermsGranter != UUID.Zero)
2580 { 2610 {
2581 ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[InventorySelf()].PermsGranter); 2611 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
2582 2612
2583 if (presence != null) 2613 if (presence != null)
2584 { 2614 {
2585 if ((m_host.TaskInventory[InventorySelf()].PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 2615 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
2586 { 2616 {
2587 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID); 2617 presence.RegisterControlEventsToScript(controls, accept, pass_on, m_localID, m_itemID);
2588 } 2618 }
@@ -2593,26 +2623,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2593 } 2623 }
2594 2624
2595 public void llReleaseControls() 2625 public void llReleaseControls()
2596 { 2626 {
2597 m_host.AddScriptLPS(1); 2627 TaskInventoryItem item;
2598 2628
2599 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 2629 lock (m_host.TaskInventory)
2600 { 2630 {
2601 return; 2631 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2632 return;
2633 else
2634 item = m_host.TaskInventory[InventorySelf()];
2602 } 2635 }
2636
2637 m_host.AddScriptLPS(1);
2603 2638
2604 if (m_host.TaskInventory[InventorySelf()].PermsGranter != UUID.Zero) 2639 if (item.PermsGranter != UUID.Zero)
2605 { 2640 {
2606 ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[InventorySelf()].PermsGranter); 2641 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
2607 2642
2608 if (presence != null) 2643 if (presence != null)
2609 { 2644 {
2610 if ((m_host.TaskInventory[InventorySelf()].PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 2645 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
2611 { 2646 {
2612 // Unregister controls from Presence 2647 // Unregister controls from Presence
2613 presence.UnRegisterControlEventsToScript(m_localID, m_itemID); 2648 presence.UnRegisterControlEventsToScript(m_localID, m_itemID);
2614 // Remove Take Control permission. 2649 // Remove Take Control permission.
2615 m_host.TaskInventory[InventorySelf()].PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS; 2650 item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
2616 } 2651 }
2617 } 2652 }
2618 } 2653 }
@@ -2838,16 +2873,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2838 { 2873 {
2839 m_host.AddScriptLPS(1); 2874 m_host.AddScriptLPS(1);
2840 2875
2841 UUID invItemID=InventorySelf(); 2876 UUID invItemID = InventorySelf();
2842 if (invItemID == UUID.Zero) 2877 if (invItemID == UUID.Zero)
2843 return; 2878 return;
2844 2879
2845 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 2880 TaskInventoryItem item;
2881
2882 lock (m_host.TaskInventory)
2883 {
2884 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2885 return;
2886 else
2887 item = m_host.TaskInventory[InventorySelf()];
2888 }
2889
2890 if (item.PermsGranter == UUID.Zero)
2846 return; 2891 return;
2847 2892
2848 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0) 2893 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
2849 { 2894 {
2850 ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[invItemID].PermsGranter); 2895 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
2851 2896
2852 if (presence != null) 2897 if (presence != null)
2853 { 2898 {
@@ -2868,11 +2913,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2868 UUID invItemID=InventorySelf(); 2913 UUID invItemID=InventorySelf();
2869 if (invItemID == UUID.Zero) 2914 if (invItemID == UUID.Zero)
2870 return; 2915 return;
2916
2917 TaskInventoryItem item;
2918
2919 lock (m_host.TaskInventory)
2920 {
2921 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2922 return;
2923 else
2924 item = m_host.TaskInventory[InventorySelf()];
2925 }
2871 2926
2872 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 2927 if (item.PermsGranter == UUID.Zero)
2873 return; 2928 return;
2874 2929
2875 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0) 2930 if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION) != 0)
2876 { 2931 {
2877 UUID animID = new UUID(); 2932 UUID animID = new UUID();
2878 2933
@@ -2881,7 +2936,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2881 animID=InventoryKey(anim); 2936 animID=InventoryKey(anim);
2882 } 2937 }
2883 2938
2884 ScenePresence presence = World.GetScenePresence(m_host.TaskInventory[invItemID].PermsGranter); 2939 ScenePresence presence = World.GetScenePresence(item.PermsGranter);
2885 2940
2886 if (presence != null) 2941 if (presence != null)
2887 { 2942 {
@@ -2929,22 +2984,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2929 2984
2930 public void llRequestPermissions(string agent, int perm) 2985 public void llRequestPermissions(string agent, int perm)
2931 { 2986 {
2932 UUID agentID=new UUID(); 2987 UUID agentID = new UUID();
2933 2988
2934 if (!UUID.TryParse(agent, out agentID)) 2989 if (!UUID.TryParse(agent, out agentID))
2935 return; 2990 return;
2936 2991
2937 UUID invItemID=InventorySelf(); 2992 UUID invItemID = InventorySelf();
2938 2993
2939 if (invItemID == UUID.Zero) 2994 if (invItemID == UUID.Zero)
2940 return; // Not in a prim? How?? 2995 return; // Not in a prim? How??
2996
2997 TaskInventoryItem item;
2998
2999 lock (m_host.TaskInventory)
3000 {
3001 item = m_host.TaskInventory[invItemID];
3002 }
2941 3003
2942 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3004 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
2943 { 3005 {
2944 llReleaseControls(); 3006 llReleaseControls();
2945 3007
2946 m_host.TaskInventory[invItemID].PermsGranter=UUID.Zero; 3008 item.PermsGranter = UUID.Zero;
2947 m_host.TaskInventory[invItemID].PermsMask=0; 3009 item.PermsMask = 0;
2948 3010
2949 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3011 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
2950 "run_time_permissions", new Object[] { 3012 "run_time_permissions", new Object[] {
@@ -2954,7 +3016,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2954 return; 3016 return;
2955 } 3017 }
2956 3018
2957 if ( m_host.TaskInventory[invItemID].PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3019 if (item.PermsGranter != agentID || (perm & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
2958 llReleaseControls(); 3020 llReleaseControls();
2959 3021
2960 m_host.AddScriptLPS(1); 3022 m_host.AddScriptLPS(1);
@@ -2969,8 +3031,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2969 3031
2970 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3032 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
2971 { 3033 {
2972 m_host.TaskInventory[invItemID].PermsGranter=agentID; 3034 lock (m_host.TaskInventory)
2973 m_host.TaskInventory[invItemID].PermsMask=perm; 3035 {
3036 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3037 m_host.TaskInventory[invItemID].PermsMask = perm;
3038 }
2974 3039
2975 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3040 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
2976 "run_time_permissions", new Object[] { 3041 "run_time_permissions", new Object[] {
@@ -2990,8 +3055,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2990 3055
2991 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3056 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
2992 { 3057 {
2993 m_host.TaskInventory[invItemID].PermsGranter=agentID; 3058 lock (m_host.TaskInventory)
2994 m_host.TaskInventory[invItemID].PermsMask=perm; 3059 {
3060 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3061 m_host.TaskInventory[invItemID].PermsMask = perm;
3062 }
2995 3063
2996 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3064 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
2997 "run_time_permissions", new Object[] { 3065 "run_time_permissions", new Object[] {
@@ -3006,19 +3074,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3006 3074
3007 if (presence != null) 3075 if (presence != null)
3008 { 3076 {
3009 string ownerName=resolveName(m_host.ParentGroup.RootPart.OwnerID); 3077 string ownerName = resolveName(m_host.ParentGroup.RootPart.OwnerID);
3010 if (ownerName == String.Empty) 3078 if (ownerName == String.Empty)
3011 ownerName="(hippos)"; 3079 ownerName = "(hippos)";
3012 3080
3013 if (!m_waitingForScriptAnswer) 3081 if (!m_waitingForScriptAnswer)
3014 { 3082 {
3015 m_host.TaskInventory[invItemID].PermsGranter=agentID; 3083 lock (m_host.TaskInventory)
3016 m_host.TaskInventory[invItemID].PermsMask=0; 3084 {
3017 presence.ControllingClient.OnScriptAnswer+=handleScriptAnswer; 3085 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3086 m_host.TaskInventory[invItemID].PermsMask = 0;
3087 }
3088
3089 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3018 m_waitingForScriptAnswer=true; 3090 m_waitingForScriptAnswer=true;
3019 } 3091 }
3020 3092
3021 presence.ControllingClient.SendScriptQuestion(m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm); 3093 presence.ControllingClient.SendScriptQuestion(
3094 m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm);
3095
3022 return; 3096 return;
3023 } 3097 }
3024 3098
@@ -3034,7 +3108,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3034 if (taskID != m_host.UUID) 3108 if (taskID != m_host.UUID)
3035 return; 3109 return;
3036 3110
3037 UUID invItemID=InventorySelf(); 3111 UUID invItemID = InventorySelf();
3038 3112
3039 if (invItemID == UUID.Zero) 3113 if (invItemID == UUID.Zero)
3040 return; 3114 return;
@@ -3044,8 +3118,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3044 3118
3045 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3119 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3046 llReleaseControls(); 3120 llReleaseControls();
3121
3122 lock (m_host.TaskInventory)
3123 {
3124 m_host.TaskInventory[invItemID].PermsMask = answer;
3125 }
3047 3126
3048 m_host.TaskInventory[invItemID].PermsMask=answer;
3049 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3127 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3050 "run_time_permissions", new Object[] { 3128 "run_time_permissions", new Object[] {
3051 new LSL_Integer(answer) }, 3129 new LSL_Integer(answer) },
@@ -3056,11 +3134,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3056 { 3134 {
3057 m_host.AddScriptLPS(1); 3135 m_host.AddScriptLPS(1);
3058 3136
3059 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3137 lock (m_host.TaskInventory)
3060 { 3138 {
3061 if (item.Type == 10 && item.ItemID == m_itemID) 3139 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3062 { 3140 {
3063 return item.PermsGranter.ToString(); 3141 if (item.Type == 10 && item.ItemID == m_itemID)
3142 {
3143 return item.PermsGranter.ToString();
3144 }
3064 } 3145 }
3065 } 3146 }
3066 3147
@@ -3071,14 +3152,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3071 { 3152 {
3072 m_host.AddScriptLPS(1); 3153 m_host.AddScriptLPS(1);
3073 3154
3074 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3155 lock (m_host.TaskInventory)
3075 { 3156 {
3076 if (item.Type == 10 && item.ItemID == m_itemID) 3157 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3077 { 3158 {
3078 int perms = item.PermsMask; 3159 if (item.Type == 10 && item.ItemID == m_itemID)
3079 if (m_automaticLinkPermission) 3160 {
3080 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; 3161 int perms = item.PermsMask;
3081 return perms; 3162 if (m_automaticLinkPermission)
3163 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3164 return perms;
3165 }
3082 } 3166 }
3083 } 3167 }
3084 3168
@@ -3111,7 +3195,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3111 { 3195 {
3112 m_host.AddScriptLPS(1); 3196 m_host.AddScriptLPS(1);
3113 UUID invItemID = InventorySelf(); 3197 UUID invItemID = InventorySelf();
3114 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3198
3199 TaskInventoryItem item;
3200 lock (m_host.TaskInventory)
3201 {
3202 item = m_host.TaskInventory[invItemID];
3203 }
3204
3205 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3115 && !m_automaticLinkPermission) 3206 && !m_automaticLinkPermission)
3116 { 3207 {
3117 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3208 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
@@ -3119,7 +3210,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3119 } 3210 }
3120 3211
3121 IClientAPI client = null; 3212 IClientAPI client = null;
3122 ScenePresence sp = World.GetScenePresence(m_host.TaskInventory[invItemID].PermsGranter); 3213 ScenePresence sp = World.GetScenePresence(item.PermsGranter);
3123 if (sp != null) 3214 if (sp != null)
3124 client = sp.ControllingClient; 3215 client = sp.ControllingClient;
3125 3216
@@ -3162,18 +3253,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3162 { 3253 {
3163 m_host.AddScriptLPS(1); 3254 m_host.AddScriptLPS(1);
3164 UUID invItemID = InventorySelf(); 3255 UUID invItemID = InventorySelf();
3165 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3256
3166 && !m_automaticLinkPermission) 3257 lock (m_host.TaskInventory)
3167 { 3258 {
3168 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3259 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3169 return; 3260 && !m_automaticLinkPermission)
3261 {
3262 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
3263 return;
3264 }
3170 } 3265 }
3266
3171 if (linknum < ScriptBaseClass.LINK_THIS) 3267 if (linknum < ScriptBaseClass.LINK_THIS)
3172 return; 3268 return;
3269
3173 SceneObjectGroup parentPrim = m_host.ParentGroup; 3270 SceneObjectGroup parentPrim = m_host.ParentGroup;
3271
3174 if (parentPrim.RootPart.AttachmentPoint != 0) 3272 if (parentPrim.RootPart.AttachmentPoint != 0)
3175 return; // Fail silently if attached 3273 return; // Fail silently if attached
3176 SceneObjectPart childPrim = null; 3274 SceneObjectPart childPrim = null;
3275
3177 switch (linknum) 3276 switch (linknum)
3178 { 3277 {
3179 case ScriptBaseClass.LINK_ROOT: 3278 case ScriptBaseClass.LINK_ROOT:
@@ -3236,8 +3335,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3236 SceneObjectGroup parentPrim = m_host.ParentGroup; 3335 SceneObjectGroup parentPrim = m_host.ParentGroup;
3237 if (parentPrim.RootPart.AttachmentPoint != 0) 3336 if (parentPrim.RootPart.AttachmentPoint != 0)
3238 return; // Fail silently if attached 3337 return; // Fail silently if attached
3338
3239 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values); 3339 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values);
3240 parts.Remove(parentPrim.RootPart); 3340 parts.Remove(parentPrim.RootPart);
3341
3241 foreach (SceneObjectPart part in parts) 3342 foreach (SceneObjectPart part in parts)
3242 { 3343 {
3243 parentPrim.DelinkFromGroup(part.LocalId, true); 3344 parentPrim.DelinkFromGroup(part.LocalId, true);
@@ -3330,13 +3431,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3330 { 3431 {
3331 m_host.AddScriptLPS(1); 3432 m_host.AddScriptLPS(1);
3332 int count = 0; 3433 int count = 0;
3333 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 3434
3435 lock (m_host.TaskInventory)
3334 { 3436 {
3335 if (inv.Value.Type == type || type == -1) 3437 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3336 { 3438 {
3337 count = count + 1; 3439 if (inv.Value.Type == type || type == -1)
3440 {
3441 count = count + 1;
3442 }
3338 } 3443 }
3339 } 3444 }
3445
3340 return count; 3446 return count;
3341 } 3447 }
3342 3448
@@ -3344,13 +3450,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3344 { 3450 {
3345 m_host.AddScriptLPS(1); 3451 m_host.AddScriptLPS(1);
3346 ArrayList keys = new ArrayList(); 3452 ArrayList keys = new ArrayList();
3347 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 3453
3454 lock (m_host.TaskInventory)
3348 { 3455 {
3349 if (inv.Value.Type == type || type == -1) 3456 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3350 { 3457 {
3351 keys.Add(inv.Value.Name); 3458 if (inv.Value.Type == type || type == -1)
3459 {
3460 keys.Add(inv.Value.Name);
3461 }
3352 } 3462 }
3353 } 3463 }
3464
3354 if (keys.Count == 0) 3465 if (keys.Count == 0)
3355 { 3466 {
3356 return String.Empty; 3467 return String.Empty;
@@ -3386,15 +3497,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3386 } 3497 }
3387 3498
3388 // move the first object found with this inventory name 3499 // move the first object found with this inventory name
3389 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 3500 lock (m_host.TaskInventory)
3390 { 3501 {
3391 if (inv.Value.Name == inventory) 3502 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3392 { 3503 {
3393 found = true; 3504 if (inv.Value.Name == inventory)
3394 objId = inv.Key; 3505 {
3395 assetType = inv.Value.Type; 3506 found = true;
3396 objName = inv.Value.Name; 3507 objId = inv.Key;
3397 break; 3508 assetType = inv.Value.Type;
3509 objName = inv.Value.Name;
3510 break;
3511 }
3398 } 3512 }
3399 } 3513 }
3400 3514
@@ -3443,12 +3557,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3443 public void llRemoveInventory(string name) 3557 public void llRemoveInventory(string name)
3444 { 3558 {
3445 m_host.AddScriptLPS(1); 3559 m_host.AddScriptLPS(1);
3446 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3560
3561 lock (m_host.TaskInventory)
3447 { 3562 {
3448 if (item.Name == name) 3563 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3449 { 3564 {
3450 m_host.Inventory.RemoveInventoryItem(item.ItemID); 3565 if (item.Name == name)
3451 return; 3566 {
3567 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3568 return;
3569 }
3452 } 3570 }
3453 } 3571 }
3454 } 3572 }
@@ -3536,7 +3654,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3536 { 3654 {
3537 m_host.AddScriptLPS(1); 3655 m_host.AddScriptLPS(1);
3538 3656
3539 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3657 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
3658
3659 foreach (TaskInventoryItem item in itemDictionary.Values)
3540 { 3660 {
3541 if (item.Type == 3 && item.Name == name) 3661 if (item.Type == 3 && item.Name == name)
3542 { 3662 {
@@ -3623,12 +3743,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3623 UUID soundId = UUID.Zero; 3743 UUID soundId = UUID.Zero;
3624 if (!UUID.TryParse(impact_sound, out soundId)) 3744 if (!UUID.TryParse(impact_sound, out soundId))
3625 { 3745 {
3626 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3746 lock (m_host.TaskInventory)
3627 { 3747 {
3628 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 3748 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3629 { 3749 {
3630 soundId = item.AssetID; 3750 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
3631 break; 3751 {
3752 soundId = item.AssetID;
3753 break;
3754 }
3632 } 3755 }
3633 } 3756 }
3634 } 3757 }
@@ -3675,7 +3798,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3675 UUID partItemID; 3798 UUID partItemID;
3676 foreach (SceneObjectPart part in parts) 3799 foreach (SceneObjectPart part in parts)
3677 { 3800 {
3678 foreach (TaskInventoryItem item in part.TaskInventory.Values) 3801 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
3802
3803 foreach (TaskInventoryItem item in itemsDictionary.Values)
3679 { 3804 {
3680 if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT) 3805 if (item.Type == ScriptBaseClass.INVENTORY_SCRIPT)
3681 { 3806 {
@@ -3684,7 +3809,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3684 if (m_host.ParentGroup.Children.Count == 1) 3809 if (m_host.ParentGroup.Children.Count == 1)
3685 linkNumber = 0; 3810 linkNumber = 0;
3686 3811
3687
3688 object[] resobj = new object[] 3812 object[] resobj = new object[]
3689 { 3813 {
3690 new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id) 3814 new LSL_Integer(linkNumber), new LSL_Integer(num), new LSL_String(msg), new LSL_String(id)
@@ -3875,22 +3999,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3875 3999
3876 public LSL_String llGetScriptName() 4000 public LSL_String llGetScriptName()
3877 { 4001 {
3878
3879 string result = String.Empty; 4002 string result = String.Empty;
3880 4003
3881 m_host.AddScriptLPS(1); 4004 m_host.AddScriptLPS(1);
3882 4005
3883 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4006 lock (m_host.TaskInventory)
3884 { 4007 {
3885 if (item.Type == 10 && item.ItemID == m_itemID) 4008 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3886 { 4009 {
3887 result = item.Name!=null?item.Name:String.Empty; 4010 if (item.Type == 10 && item.ItemID == m_itemID)
3888 break; 4011 {
4012 result = item.Name!=null?item.Name:String.Empty;
4013 break;
4014 }
3889 } 4015 }
3890 } 4016 }
3891 4017
3892 return result; 4018 return result;
3893
3894 } 4019 }
3895 4020
3896 // this function to understand which shape it is (taken from meshmerizer) 4021 // this function to understand which shape it is (taken from meshmerizer)
@@ -4142,20 +4267,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4142 public LSL_String llGetInventoryKey(string name) 4267 public LSL_String llGetInventoryKey(string name)
4143 { 4268 {
4144 m_host.AddScriptLPS(1); 4269 m_host.AddScriptLPS(1);
4145 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4270
4271 lock (m_host.TaskInventory)
4146 { 4272 {
4147 if (inv.Value.Name == name) 4273 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4148 { 4274 {
4149 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) 4275 if (inv.Value.Name == name)
4150 {
4151 return inv.Value.AssetID.ToString();
4152 }
4153 else
4154 { 4276 {
4155 return UUID.Zero.ToString(); 4277 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
4278 {
4279 return inv.Value.AssetID.ToString();
4280 }
4281 else
4282 {
4283 return UUID.Zero.ToString();
4284 }
4156 } 4285 }
4157 }
4158 } 4286 }
4287 }
4288
4159 return UUID.Zero.ToString(); 4289 return UUID.Zero.ToString();
4160 } 4290 }
4161 4291
@@ -5540,11 +5670,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5540 5670
5541 private UUID GetTaskInventoryItem(string name) 5671 private UUID GetTaskInventoryItem(string name)
5542 { 5672 {
5543 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 5673 lock (m_host.TaskInventory)
5544 { 5674 {
5545 if (inv.Value.Name == name) 5675 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
5546 return inv.Key; 5676 {
5677 if (inv.Value.Name == name)
5678 return inv.Key;
5679 }
5547 } 5680 }
5681
5548 return UUID.Zero; 5682 return UUID.Zero;
5549 } 5683 }
5550 5684
@@ -5853,16 +5987,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5853 } 5987 }
5854 5988
5855 // copy the first script found with this inventory name 5989 // copy the first script found with this inventory name
5856 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 5990 lock (m_host.TaskInventory)
5857 { 5991 {
5858 if (inv.Value.Name == name) 5992 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
5859 { 5993 {
5860 // make sure the object is a script 5994 if (inv.Value.Name == name)
5861 if (10 == inv.Value.Type)
5862 { 5995 {
5863 found = true; 5996 // make sure the object is a script
5864 srcId = inv.Key; 5997 if (10 == inv.Value.Type)
5865 break; 5998 {
5999 found = true;
6000 srcId = inv.Key;
6001 break;
6002 }
5866 } 6003 }
5867 } 6004 }
5868 } 6005 }
@@ -7614,25 +7751,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7614 public LSL_Integer llGetInventoryPermMask(string item, int mask) 7751 public LSL_Integer llGetInventoryPermMask(string item, int mask)
7615 { 7752 {
7616 m_host.AddScriptLPS(1); 7753 m_host.AddScriptLPS(1);
7617 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 7754
7755 lock (m_host.TaskInventory)
7618 { 7756 {
7619 if (inv.Value.Name == item) 7757 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
7620 { 7758 {
7621 switch (mask) 7759 if (inv.Value.Name == item)
7622 { 7760 {
7623 case 0: 7761 switch (mask)
7624 return (int)inv.Value.BasePermissions; 7762 {
7625 case 1: 7763 case 0:
7626 return (int)inv.Value.CurrentPermissions; 7764 return (int)inv.Value.BasePermissions;
7627 case 2: 7765 case 1:
7628 return (int)inv.Value.GroupPermissions; 7766 return (int)inv.Value.CurrentPermissions;
7629 case 3: 7767 case 2:
7630 return (int)inv.Value.EveryonePermissions; 7768 return (int)inv.Value.GroupPermissions;
7631 case 4: 7769 case 3:
7632 return (int)inv.Value.NextPermissions; 7770 return (int)inv.Value.EveryonePermissions;
7771 case 4:
7772 return (int)inv.Value.NextPermissions;
7773 }
7633 } 7774 }
7634 } 7775 }
7635 } 7776 }
7777
7636 return -1; 7778 return -1;
7637 } 7779 }
7638 7780
@@ -7645,14 +7787,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7645 public LSL_String llGetInventoryCreator(string item) 7787 public LSL_String llGetInventoryCreator(string item)
7646 { 7788 {
7647 m_host.AddScriptLPS(1); 7789 m_host.AddScriptLPS(1);
7648 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 7790
7791 lock (m_host.TaskInventory)
7649 { 7792 {
7650 if (inv.Value.Name == item) 7793 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
7651 { 7794 {
7652 return inv.Value.CreatorID.ToString(); 7795 if (inv.Value.Name == item)
7796 {
7797 return inv.Value.CreatorID.ToString();
7798 }
7653 } 7799 }
7654 } 7800 }
7801
7655 llSay(0, "No item name '" + item + "'"); 7802 llSay(0, "No item name '" + item + "'");
7803
7656 return String.Empty; 7804 return String.Empty;
7657 } 7805 }
7658 7806
@@ -8143,13 +8291,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8143 public LSL_Integer llGetInventoryType(string name) 8291 public LSL_Integer llGetInventoryType(string name)
8144 { 8292 {
8145 m_host.AddScriptLPS(1); 8293 m_host.AddScriptLPS(1);
8146 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 8294
8295 lock (m_host.TaskInventory)
8147 { 8296 {
8148 if (inv.Value.Name == name) 8297 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8149 { 8298 {
8150 return inv.Value.Type; 8299 if (inv.Value.Name == name)
8300 {
8301 return inv.Value.Type;
8302 }
8151 } 8303 }
8152 } 8304 }
8305
8153 return -1; 8306 return -1;
8154 } 8307 }
8155 8308
@@ -8174,16 +8327,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8174 public LSL_Vector llGetCameraPos() 8327 public LSL_Vector llGetCameraPos()
8175 { 8328 {
8176 m_host.AddScriptLPS(1); 8329 m_host.AddScriptLPS(1);
8177 UUID invItemID=InventorySelf(); 8330 UUID invItemID = InventorySelf();
8331
8178 if (invItemID == UUID.Zero) 8332 if (invItemID == UUID.Zero)
8179 return new LSL_Vector(); 8333 return new LSL_Vector();
8180 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 8334
8181 return new LSL_Vector(); 8335 lock (m_host.TaskInventory)
8182 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
8183 { 8336 {
8184 ShoutError("No permissions to track the camera"); 8337 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
8185 return new LSL_Vector(); 8338 return new LSL_Vector();
8339
8340 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
8341 {
8342 ShoutError("No permissions to track the camera");
8343 return new LSL_Vector();
8344 }
8186 } 8345 }
8346
8187 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 8347 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
8188 if (presence != null) 8348 if (presence != null)
8189 { 8349 {
@@ -8196,21 +8356,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8196 public LSL_Rotation llGetCameraRot() 8356 public LSL_Rotation llGetCameraRot()
8197 { 8357 {
8198 m_host.AddScriptLPS(1); 8358 m_host.AddScriptLPS(1);
8199 UUID invItemID=InventorySelf(); 8359 UUID invItemID = InventorySelf();
8200 if (invItemID == UUID.Zero) 8360 if (invItemID == UUID.Zero)
8201 return new LSL_Rotation(); 8361 return new LSL_Rotation();
8202 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 8362
8203 return new LSL_Rotation(); 8363 lock (m_host.TaskInventory)
8204 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
8205 { 8364 {
8206 ShoutError("No permissions to track the camera"); 8365 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
8207 return new LSL_Rotation(); 8366 return new LSL_Rotation();
8367
8368 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
8369 {
8370 ShoutError("No permissions to track the camera");
8371 return new LSL_Rotation();
8372 }
8208 } 8373 }
8374
8209 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 8375 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
8210 if (presence != null) 8376 if (presence != null)
8211 { 8377 {
8212 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W); 8378 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
8213 } 8379 }
8380
8214 return new LSL_Rotation(); 8381 return new LSL_Rotation();
8215 } 8382 }
8216 8383
@@ -8345,17 +8512,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8345 m_host.AddScriptLPS(1); 8512 m_host.AddScriptLPS(1);
8346 8513
8347 // our key in the object we are in 8514 // our key in the object we are in
8348 UUID invItemID=InventorySelf(); 8515 UUID invItemID = InventorySelf();
8349 if (invItemID == UUID.Zero) return; 8516 if (invItemID == UUID.Zero) return;
8350 8517
8351 // the object we are in 8518 // the object we are in
8352 UUID objectID = m_host.ParentUUID; 8519 UUID objectID = m_host.ParentUUID;
8353 if (objectID == UUID.Zero) return; 8520 if (objectID == UUID.Zero) return;
8354 8521
8355 // we need the permission first, to know which avatar we want to set the camera for 8522 UUID agentID;
8356 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter; 8523 lock (m_host.TaskInventory)
8357 if (agentID == UUID.Zero) return; 8524 {
8358 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 8525 // we need the permission first, to know which avatar we want to set the camera for
8526 agentID = m_host.TaskInventory[invItemID].PermsGranter;
8527
8528 if (agentID == UUID.Zero) return;
8529 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
8530 }
8359 8531
8360 ScenePresence presence = World.GetScenePresence(agentID); 8532 ScenePresence presence = World.GetScenePresence(agentID);
8361 8533
@@ -8404,9 +8576,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8404 if (objectID == UUID.Zero) return; 8576 if (objectID == UUID.Zero) return;
8405 8577
8406 // we need the permission first, to know which avatar we want to clear the camera for 8578 // we need the permission first, to know which avatar we want to clear the camera for
8407 UUID agentID = m_host.TaskInventory[invItemID].PermsGranter; 8579 UUID agentID;
8408 if (agentID == UUID.Zero) return; 8580 lock (m_host.TaskInventory)
8409 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 8581 {
8582 agentID = m_host.TaskInventory[invItemID].PermsGranter;
8583 if (agentID == UUID.Zero) return;
8584 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
8585 }
8410 8586
8411 ScenePresence presence = World.GetScenePresence(agentID); 8587 ScenePresence presence = World.GetScenePresence(agentID);
8412 8588
@@ -8816,14 +8992,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8816 return new LSL_List(); 8992 return new LSL_List();
8817 } 8993 }
8818 8994
8819
8820 internal UUID ScriptByName(string name) 8995 internal UUID ScriptByName(string name)
8821 { 8996 {
8822 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 8997 lock (m_host.TaskInventory)
8823 { 8998 {
8824 if (item.Type == 10 && item.Name == name) 8999 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
8825 return item.ItemID; 9000 {
9001 if (item.Type == 10 && item.Name == name)
9002 return item.ItemID;
9003 }
8826 } 9004 }
9005
8827 return UUID.Zero; 9006 return UUID.Zero;
8828 } 9007 }
8829 9008
@@ -8858,7 +9037,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8858 { 9037 {
8859 m_host.AddScriptLPS(1); 9038 m_host.AddScriptLPS(1);
8860 9039
8861 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 9040 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
9041
9042 foreach (TaskInventoryItem item in itemsDictionary.Values)
8862 { 9043 {
8863 if (item.Type == 7 && item.Name == name) 9044 if (item.Type == 7 && item.Name == name)
8864 { 9045 {
@@ -8900,7 +9081,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8900 { 9081 {
8901 m_host.AddScriptLPS(1); 9082 m_host.AddScriptLPS(1);
8902 9083
8903 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 9084 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
9085
9086 foreach (TaskInventoryItem item in itemsDictionary.Values)
8904 { 9087 {
8905 if (item.Type == 7 && item.Name == name) 9088 if (item.Type == 7 && item.Name == name)
8906 { 9089 {
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 96c1698..20e70d0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -231,9 +231,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
231 m_stateSource = stateSource; 231 m_stateSource = stateSource;
232 m_postOnRez = postOnRez; 232 m_postOnRez = postOnRez;
233 233
234 if (part != null && part.TaskInventory.ContainsKey(m_ItemID)) 234 if (part != null)
235 { 235 {
236 m_thisScriptTask = part.TaskInventory[m_ItemID]; 236 lock (part.TaskInventory)
237 {
238 if (part.TaskInventory.ContainsKey(m_ItemID))
239 {
240 m_thisScriptTask = part.TaskInventory[m_ItemID];
241 }
242 }
237 } 243 }
238 244
239 ApiManager am = new ApiManager(); 245 ApiManager am = new ApiManager();
@@ -399,15 +405,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
399 405
400 private void ReleaseControls() 406 private void ReleaseControls()
401 { 407 {
402 SceneObjectPart part=m_Engine.World.GetSceneObjectPart(m_LocalID); 408 SceneObjectPart part = m_Engine.World.GetSceneObjectPart(m_LocalID);
403 if (part != null && part.TaskInventory.ContainsKey(m_ItemID)) 409
410 if (part != null)
404 { 411 {
405 UUID permsGranter = part.TaskInventory[m_ItemID].PermsGranter; 412 int permsMask;
406 int permsMask = part.TaskInventory[m_ItemID].PermsMask; 413 UUID permsGranter;
414 lock (part.TaskInventory)
415 {
416 if (!part.TaskInventory.ContainsKey(m_ItemID))
417 return;
418
419 permsGranter = part.TaskInventory[m_ItemID].PermsGranter;
420 permsMask = part.TaskInventory[m_ItemID].PermsMask;
421 }
407 422
408 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 423 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
409 { 424 {
410
411 ScenePresence presence = m_Engine.World.GetScenePresence(permsGranter); 425 ScenePresence presence = m_Engine.World.GetScenePresence(permsGranter);
412 if (presence != null) 426 if (presence != null)
413 presence.UnRegisterControlEventsToScript(m_LocalID, m_ItemID); 427 presence.UnRegisterControlEventsToScript(m_LocalID, m_ItemID);