aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs554
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs36
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs261
5 files changed, 476 insertions, 379 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 9c62775..a94cd46 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Diagnostics; //for [DebuggerNonUserCode]
31using System.Runtime.Remoting.Lifetime; 32using System.Runtime.Remoting.Lifetime;
32using System.Text; 33using System.Text;
33using System.Threading; 34using System.Threading;
@@ -151,6 +152,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
151 get { return m_ScriptEngine.World; } 152 get { return m_ScriptEngine.World; }
152 } 153 }
153 154
155 [DebuggerNonUserCode]
154 public void state(string newState) 156 public void state(string newState)
155 { 157 {
156 m_ScriptEngine.SetState(m_itemID, newState); 158 m_ScriptEngine.SetState(m_itemID, newState);
@@ -160,6 +162,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
160 /// Reset the named script. The script must be present 162 /// Reset the named script. The script must be present
161 /// in the same prim. 163 /// in the same prim.
162 /// </summary> 164 /// </summary>
165 [DebuggerNonUserCode]
163 public void llResetScript() 166 public void llResetScript()
164 { 167 {
165 m_host.AddScriptLPS(1); 168 m_host.AddScriptLPS(1);
@@ -272,40 +275,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
272 protected UUID InventorySelf() 275 protected UUID InventorySelf()
273 { 276 {
274 UUID invItemID = new UUID(); 277 UUID invItemID = new UUID();
275 278 bool unlock = false;
276 lock (m_host.TaskInventory) 279 if (!m_host.TaskInventory.IsReadLockedByMe())
280 {
281 m_host.TaskInventory.LockItemsForRead(true);
282 unlock = true;
283 }
284 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
277 { 285 {
278 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 286 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
279 { 287 {
280 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID) 288 invItemID = inv.Key;
281 { 289 break;
282 invItemID = inv.Key;
283 break;
284 }
285 } 290 }
286 } 291 }
287 292 if (unlock)
293 {
294 m_host.TaskInventory.LockItemsForRead(false);
295 }
288 return invItemID; 296 return invItemID;
289 } 297 }
290 298
291 protected UUID InventoryKey(string name, int type) 299 protected UUID InventoryKey(string name, int type)
292 { 300 {
293 m_host.AddScriptLPS(1); 301 m_host.AddScriptLPS(1);
294 302 m_host.TaskInventory.LockItemsForRead(true);
295 lock (m_host.TaskInventory) 303
304 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
296 { 305 {
297 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 306 if (inv.Value.Name == name)
298 { 307 {
299 if (inv.Value.Name == name) 308 m_host.TaskInventory.LockItemsForRead(false);
309
310 if (inv.Value.Type != type)
300 { 311 {
301 if (inv.Value.Type != type) 312 return UUID.Zero;
302 return UUID.Zero;
303
304 return inv.Value.AssetID;
305 } 313 }
314
315 return inv.Value.AssetID;
306 } 316 }
307 } 317 }
308 318
319 m_host.TaskInventory.LockItemsForRead(false);
309 return UUID.Zero; 320 return UUID.Zero;
310 } 321 }
311 322
@@ -313,17 +324,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
313 { 324 {
314 m_host.AddScriptLPS(1); 325 m_host.AddScriptLPS(1);
315 326
316 lock (m_host.TaskInventory) 327
328 m_host.TaskInventory.LockItemsForRead(true);
329
330 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
317 { 331 {
318 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 332 if (inv.Value.Name == name)
319 { 333 {
320 if (inv.Value.Name == name) 334 m_host.TaskInventory.LockItemsForRead(false);
321 { 335 return inv.Value.AssetID;
322 return inv.Value.AssetID;
323 }
324 } 336 }
325 } 337 }
326 338
339 m_host.TaskInventory.LockItemsForRead(false);
340
341
327 return UUID.Zero; 342 return UUID.Zero;
328 } 343 }
329 344
@@ -2534,12 +2549,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2534 2549
2535 m_host.AddScriptLPS(1); 2550 m_host.AddScriptLPS(1);
2536 2551
2552 m_host.TaskInventory.LockItemsForRead(true);
2537 TaskInventoryItem item = m_host.TaskInventory[invItemID]; 2553 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2538 2554 m_host.TaskInventory.LockItemsForRead(false);
2539 lock (m_host.TaskInventory)
2540 {
2541 item = m_host.TaskInventory[invItemID];
2542 }
2543 2555
2544 if (item.PermsGranter == UUID.Zero) 2556 if (item.PermsGranter == UUID.Zero)
2545 return 0; 2557 return 0;
@@ -2614,6 +2626,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2614 if (dist > m_ScriptDistanceFactor * 10.0f) 2626 if (dist > m_ScriptDistanceFactor * 10.0f)
2615 return; 2627 return;
2616 2628
2629 //Clone is thread-safe
2617 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 2630 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
2618 2631
2619 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory) 2632 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory)
@@ -2699,11 +2712,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2699 // Orient the object to the angle calculated 2712 // Orient the object to the angle calculated
2700 llSetRot(rot); 2713 llSetRot(rot);
2701 } 2714 }
2715
2716 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
2717 {
2718 m_host.AddScriptLPS(1);
2719// NotImplemented("llRotLookAt");
2720 m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping);
2721
2722 }
2723
2702 2724
2703 public void llStopLookAt() 2725 public void llStopLookAt()
2704 { 2726 {
2705 m_host.AddScriptLPS(1); 2727 m_host.AddScriptLPS(1);
2706 NotImplemented("llStopLookAt"); 2728// NotImplemented("llStopLookAt");
2729 m_host.StopLookAt();
2707 } 2730 }
2708 2731
2709 public void llSetTimerEvent(double sec) 2732 public void llSetTimerEvent(double sec)
@@ -2737,13 +2760,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2737 { 2760 {
2738 TaskInventoryItem item; 2761 TaskInventoryItem item;
2739 2762
2740 lock (m_host.TaskInventory) 2763 m_host.TaskInventory.LockItemsForRead(true);
2764 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2741 { 2765 {
2742 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 2766 m_host.TaskInventory.LockItemsForRead(false);
2743 return; 2767 return;
2744 else 2768 }
2745 item = m_host.TaskInventory[InventorySelf()]; 2769 else
2770 {
2771 item = m_host.TaskInventory[InventorySelf()];
2746 } 2772 }
2773 m_host.TaskInventory.LockItemsForRead(false);
2747 2774
2748 if (item.PermsGranter != UUID.Zero) 2775 if (item.PermsGranter != UUID.Zero)
2749 { 2776 {
@@ -2765,13 +2792,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2765 { 2792 {
2766 TaskInventoryItem item; 2793 TaskInventoryItem item;
2767 2794
2795 m_host.TaskInventory.LockItemsForRead(true);
2768 lock (m_host.TaskInventory) 2796 lock (m_host.TaskInventory)
2769 { 2797 {
2798
2770 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 2799 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2800 {
2801 m_host.TaskInventory.LockItemsForRead(false);
2771 return; 2802 return;
2803 }
2772 else 2804 else
2805 {
2773 item = m_host.TaskInventory[InventorySelf()]; 2806 item = m_host.TaskInventory[InventorySelf()];
2807 }
2774 } 2808 }
2809 m_host.TaskInventory.LockItemsForRead(false);
2775 2810
2776 m_host.AddScriptLPS(1); 2811 m_host.AddScriptLPS(1);
2777 2812
@@ -2808,13 +2843,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2808 2843
2809 TaskInventoryItem item; 2844 TaskInventoryItem item;
2810 2845
2811 lock (m_host.TaskInventory) 2846 m_host.TaskInventory.LockItemsForRead(true);
2847
2848 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2812 { 2849 {
2813 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 2850 m_host.TaskInventory.LockItemsForRead(false);
2814 return; 2851 return;
2815 else
2816 item = m_host.TaskInventory[InventorySelf()];
2817 } 2852 }
2853 else
2854 {
2855 item = m_host.TaskInventory[InventorySelf()];
2856 }
2857
2858 m_host.TaskInventory.LockItemsForRead(false);
2818 2859
2819 if (item.PermsGranter != m_host.OwnerID) 2860 if (item.PermsGranter != m_host.OwnerID)
2820 return; 2861 return;
@@ -2840,13 +2881,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2840 2881
2841 TaskInventoryItem item; 2882 TaskInventoryItem item;
2842 2883
2843 lock (m_host.TaskInventory) 2884 m_host.TaskInventory.LockItemsForRead(true);
2885
2886 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2844 { 2887 {
2845 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 2888 m_host.TaskInventory.LockItemsForRead(false);
2846 return; 2889 return;
2847 else
2848 item = m_host.TaskInventory[InventorySelf()];
2849 } 2890 }
2891 else
2892 {
2893 item = m_host.TaskInventory[InventorySelf()];
2894 }
2895 m_host.TaskInventory.LockItemsForRead(false);
2896
2850 2897
2851 if (item.PermsGranter != m_host.OwnerID) 2898 if (item.PermsGranter != m_host.OwnerID)
2852 return; 2899 return;
@@ -3047,12 +3094,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3047 m_host.AddScriptLPS(1); 3094 m_host.AddScriptLPS(1);
3048 } 3095 }
3049 3096
3050 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3051 {
3052 m_host.AddScriptLPS(1);
3053 NotImplemented("llRotLookAt");
3054 }
3055
3056 public LSL_Integer llStringLength(string str) 3097 public LSL_Integer llStringLength(string str)
3057 { 3098 {
3058 m_host.AddScriptLPS(1); 3099 m_host.AddScriptLPS(1);
@@ -3076,14 +3117,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3076 3117
3077 TaskInventoryItem item; 3118 TaskInventoryItem item;
3078 3119
3079 lock (m_host.TaskInventory) 3120 m_host.TaskInventory.LockItemsForRead(true);
3121 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3080 { 3122 {
3081 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3123 m_host.TaskInventory.LockItemsForRead(false);
3082 return; 3124 return;
3083 else
3084 item = m_host.TaskInventory[InventorySelf()];
3085 } 3125 }
3086 3126 else
3127 {
3128 item = m_host.TaskInventory[InventorySelf()];
3129 }
3130 m_host.TaskInventory.LockItemsForRead(false);
3087 if (item.PermsGranter == UUID.Zero) 3131 if (item.PermsGranter == UUID.Zero)
3088 return; 3132 return;
3089 3133
@@ -3113,13 +3157,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3113 3157
3114 TaskInventoryItem item; 3158 TaskInventoryItem item;
3115 3159
3116 lock (m_host.TaskInventory) 3160 m_host.TaskInventory.LockItemsForRead(true);
3161 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3117 { 3162 {
3118 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3163 m_host.TaskInventory.LockItemsForRead(false);
3119 return; 3164 return;
3120 else 3165 }
3121 item = m_host.TaskInventory[InventorySelf()]; 3166 else
3167 {
3168 item = m_host.TaskInventory[InventorySelf()];
3122 } 3169 }
3170 m_host.TaskInventory.LockItemsForRead(false);
3171
3123 3172
3124 if (item.PermsGranter == UUID.Zero) 3173 if (item.PermsGranter == UUID.Zero)
3125 return; 3174 return;
@@ -3192,10 +3241,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3192 3241
3193 TaskInventoryItem item; 3242 TaskInventoryItem item;
3194 3243
3195 lock (m_host.TaskInventory) 3244
3245 m_host.TaskInventory.LockItemsForRead(true);
3246 if (!m_host.TaskInventory.ContainsKey(invItemID))
3247 {
3248 m_host.TaskInventory.LockItemsForRead(false);
3249 return;
3250 }
3251 else
3196 { 3252 {
3197 item = m_host.TaskInventory[invItemID]; 3253 item = m_host.TaskInventory[invItemID];
3198 } 3254 }
3255 m_host.TaskInventory.LockItemsForRead(false);
3199 3256
3200 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3257 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3201 { 3258 {
@@ -3227,11 +3284,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3227 3284
3228 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3285 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3229 { 3286 {
3230 lock (m_host.TaskInventory) 3287 m_host.TaskInventory.LockItemsForWrite(true);
3231 { 3288 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3232 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3289 m_host.TaskInventory[invItemID].PermsMask = perm;
3233 m_host.TaskInventory[invItemID].PermsMask = perm; 3290 m_host.TaskInventory.LockItemsForWrite(false);
3234 }
3235 3291
3236 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3292 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3237 "run_time_permissions", new Object[] { 3293 "run_time_permissions", new Object[] {
@@ -3251,11 +3307,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3251 3307
3252 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3308 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3253 { 3309 {
3254 lock (m_host.TaskInventory) 3310 m_host.TaskInventory.LockItemsForWrite(true);
3255 { 3311 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3256 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3312 m_host.TaskInventory[invItemID].PermsMask = perm;
3257 m_host.TaskInventory[invItemID].PermsMask = perm; 3313 m_host.TaskInventory.LockItemsForWrite(false);
3258 }
3259 3314
3260 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3315 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3261 "run_time_permissions", new Object[] { 3316 "run_time_permissions", new Object[] {
@@ -3276,11 +3331,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3276 3331
3277 if (!m_waitingForScriptAnswer) 3332 if (!m_waitingForScriptAnswer)
3278 { 3333 {
3279 lock (m_host.TaskInventory) 3334 m_host.TaskInventory.LockItemsForWrite(true);
3280 { 3335 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3281 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3336 m_host.TaskInventory[invItemID].PermsMask = 0;
3282 m_host.TaskInventory[invItemID].PermsMask = 0; 3337 m_host.TaskInventory.LockItemsForWrite(false);
3283 }
3284 3338
3285 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3339 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3286 m_waitingForScriptAnswer=true; 3340 m_waitingForScriptAnswer=true;
@@ -3315,10 +3369,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3315 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3369 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3316 llReleaseControls(); 3370 llReleaseControls();
3317 3371
3318 lock (m_host.TaskInventory) 3372
3319 { 3373 m_host.TaskInventory.LockItemsForWrite(true);
3320 m_host.TaskInventory[invItemID].PermsMask = answer; 3374 m_host.TaskInventory[invItemID].PermsMask = answer;
3321 } 3375 m_host.TaskInventory.LockItemsForWrite(false);
3376
3322 3377
3323 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3378 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3324 "run_time_permissions", new Object[] { 3379 "run_time_permissions", new Object[] {
@@ -3330,16 +3385,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3330 { 3385 {
3331 m_host.AddScriptLPS(1); 3386 m_host.AddScriptLPS(1);
3332 3387
3333 lock (m_host.TaskInventory) 3388 m_host.TaskInventory.LockItemsForRead(true);
3389
3390 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3334 { 3391 {
3335 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3392 if (item.Type == 10 && item.ItemID == m_itemID)
3336 { 3393 {
3337 if (item.Type == 10 && item.ItemID == m_itemID) 3394 m_host.TaskInventory.LockItemsForRead(false);
3338 { 3395 return item.PermsGranter.ToString();
3339 return item.PermsGranter.ToString();
3340 }
3341 } 3396 }
3342 } 3397 }
3398 m_host.TaskInventory.LockItemsForRead(false);
3343 3399
3344 return UUID.Zero.ToString(); 3400 return UUID.Zero.ToString();
3345 } 3401 }
@@ -3348,19 +3404,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3348 { 3404 {
3349 m_host.AddScriptLPS(1); 3405 m_host.AddScriptLPS(1);
3350 3406
3351 lock (m_host.TaskInventory) 3407 m_host.TaskInventory.LockItemsForRead(true);
3408
3409 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3352 { 3410 {
3353 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3411 if (item.Type == 10 && item.ItemID == m_itemID)
3354 { 3412 {
3355 if (item.Type == 10 && item.ItemID == m_itemID) 3413 int perms = item.PermsMask;
3356 { 3414 if (m_automaticLinkPermission)
3357 int perms = item.PermsMask; 3415 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3358 if (m_automaticLinkPermission) 3416 m_host.TaskInventory.LockItemsForRead(false);
3359 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; 3417 return perms;
3360 return perms;
3361 }
3362 } 3418 }
3363 } 3419 }
3420 m_host.TaskInventory.LockItemsForRead(false);
3364 3421
3365 return 0; 3422 return 0;
3366 } 3423 }
@@ -3393,11 +3450,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3393 UUID invItemID = InventorySelf(); 3450 UUID invItemID = InventorySelf();
3394 3451
3395 TaskInventoryItem item; 3452 TaskInventoryItem item;
3396 lock (m_host.TaskInventory) 3453 m_host.TaskInventory.LockItemsForRead(true);
3397 { 3454 item = m_host.TaskInventory[invItemID];
3398 item = m_host.TaskInventory[invItemID]; 3455 m_host.TaskInventory.LockItemsForRead(false);
3399 } 3456
3400
3401 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3457 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3402 && !m_automaticLinkPermission) 3458 && !m_automaticLinkPermission)
3403 { 3459 {
@@ -3450,16 +3506,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3450 m_host.AddScriptLPS(1); 3506 m_host.AddScriptLPS(1);
3451 UUID invItemID = InventorySelf(); 3507 UUID invItemID = InventorySelf();
3452 3508
3453 lock (m_host.TaskInventory) 3509 m_host.TaskInventory.LockItemsForRead(true);
3454 {
3455 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3510 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3456 && !m_automaticLinkPermission) 3511 && !m_automaticLinkPermission)
3457 { 3512 {
3458 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3513 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
3514 m_host.TaskInventory.LockItemsForRead(false);
3459 return; 3515 return;
3460 } 3516 }
3461 } 3517 m_host.TaskInventory.LockItemsForRead(false);
3462 3518
3463 if (linknum < ScriptBaseClass.LINK_THIS) 3519 if (linknum < ScriptBaseClass.LINK_THIS)
3464 return; 3520 return;
3465 3521
@@ -3628,17 +3684,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3628 m_host.AddScriptLPS(1); 3684 m_host.AddScriptLPS(1);
3629 int count = 0; 3685 int count = 0;
3630 3686
3631 lock (m_host.TaskInventory) 3687 m_host.TaskInventory.LockItemsForRead(true);
3688 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3632 { 3689 {
3633 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 3690 if (inv.Value.Type == type || type == -1)
3634 { 3691 {
3635 if (inv.Value.Type == type || type == -1) 3692 count = count + 1;
3636 {
3637 count = count + 1;
3638 }
3639 } 3693 }
3640 } 3694 }
3641 3695
3696 m_host.TaskInventory.LockItemsForRead(false);
3642 return count; 3697 return count;
3643 } 3698 }
3644 3699
@@ -3647,16 +3702,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3647 m_host.AddScriptLPS(1); 3702 m_host.AddScriptLPS(1);
3648 ArrayList keys = new ArrayList(); 3703 ArrayList keys = new ArrayList();
3649 3704
3650 lock (m_host.TaskInventory) 3705 m_host.TaskInventory.LockItemsForRead(true);
3706 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3651 { 3707 {
3652 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 3708 if (inv.Value.Type == type || type == -1)
3653 { 3709 {
3654 if (inv.Value.Type == type || type == -1) 3710 keys.Add(inv.Value.Name);
3655 {
3656 keys.Add(inv.Value.Name);
3657 }
3658 } 3711 }
3659 } 3712 }
3713 m_host.TaskInventory.LockItemsForRead(false);
3660 3714
3661 if (keys.Count == 0) 3715 if (keys.Count == 0)
3662 { 3716 {
@@ -3693,20 +3747,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3693 } 3747 }
3694 3748
3695 // move the first object found with this inventory name 3749 // move the first object found with this inventory name
3696 lock (m_host.TaskInventory) 3750 m_host.TaskInventory.LockItemsForRead(true);
3751 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3697 { 3752 {
3698 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 3753 if (inv.Value.Name == inventory)
3699 { 3754 {
3700 if (inv.Value.Name == inventory) 3755 found = true;
3701 { 3756 objId = inv.Key;
3702 found = true; 3757 assetType = inv.Value.Type;
3703 objId = inv.Key; 3758 objName = inv.Value.Name;
3704 assetType = inv.Value.Type; 3759 break;
3705 objName = inv.Value.Name;
3706 break;
3707 }
3708 } 3760 }
3709 } 3761 }
3762 m_host.TaskInventory.LockItemsForRead(false);
3710 3763
3711 if (!found) 3764 if (!found)
3712 { 3765 {
@@ -3751,24 +3804,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3751 ScriptSleep(3000); 3804 ScriptSleep(3000);
3752 } 3805 }
3753 3806
3807 [DebuggerNonUserCode]
3754 public void llRemoveInventory(string name) 3808 public void llRemoveInventory(string name)
3755 { 3809 {
3756 m_host.AddScriptLPS(1); 3810 m_host.AddScriptLPS(1);
3757 3811
3758 lock (m_host.TaskInventory) 3812 m_host.TaskInventory.LockItemsForRead(true);
3813 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3759 { 3814 {
3760 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3815 if (item.Name == name)
3761 { 3816 {
3762 if (item.Name == name) 3817 if (item.ItemID == m_itemID)
3763 { 3818 throw new ScriptDeleteException();
3764 if (item.ItemID == m_itemID) 3819 else
3765 throw new ScriptDeleteException(); 3820 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3766 else 3821
3767 m_host.Inventory.RemoveInventoryItem(item.ItemID); 3822 m_host.TaskInventory.LockItemsForRead(false);
3768 return; 3823 return;
3769 }
3770 } 3824 }
3771 } 3825 }
3826 m_host.TaskInventory.LockItemsForRead(false);
3772 } 3827 }
3773 3828
3774 public void llSetText(string text, LSL_Vector color, double alpha) 3829 public void llSetText(string text, LSL_Vector color, double alpha)
@@ -3857,6 +3912,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3857 { 3912 {
3858 m_host.AddScriptLPS(1); 3913 m_host.AddScriptLPS(1);
3859 3914
3915 //Clone is thread safe
3860 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 3916 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
3861 3917
3862 foreach (TaskInventoryItem item in itemDictionary.Values) 3918 foreach (TaskInventoryItem item in itemDictionary.Values)
@@ -3947,17 +4003,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3947 UUID soundId = UUID.Zero; 4003 UUID soundId = UUID.Zero;
3948 if (!UUID.TryParse(impact_sound, out soundId)) 4004 if (!UUID.TryParse(impact_sound, out soundId))
3949 { 4005 {
3950 lock (m_host.TaskInventory) 4006 m_host.TaskInventory.LockItemsForRead(true);
4007 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3951 { 4008 {
3952 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4009 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
3953 { 4010 {
3954 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 4011 soundId = item.AssetID;
3955 { 4012 break;
3956 soundId = item.AssetID;
3957 break;
3958 }
3959 } 4013 }
3960 } 4014 }
4015 m_host.TaskInventory.LockItemsForRead(false);
3961 } 4016 }
3962 m_host.CollisionSound = soundId; 4017 m_host.CollisionSound = soundId;
3963 m_host.CollisionSoundVolume = (float)impact_volume; 4018 m_host.CollisionSoundVolume = (float)impact_volume;
@@ -4003,6 +4058,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4003 UUID partItemID; 4058 UUID partItemID;
4004 foreach (SceneObjectPart part in parts) 4059 foreach (SceneObjectPart part in parts)
4005 { 4060 {
4061 //Clone is thread safe
4006 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); 4062 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
4007 4063
4008 foreach (TaskInventoryItem item in itemsDictionary.Values) 4064 foreach (TaskInventoryItem item in itemsDictionary.Values)
@@ -4210,17 +4266,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4210 4266
4211 m_host.AddScriptLPS(1); 4267 m_host.AddScriptLPS(1);
4212 4268
4213 lock (m_host.TaskInventory) 4269 m_host.TaskInventory.LockItemsForRead(true);
4270 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4214 { 4271 {
4215 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4272 if (item.Type == 10 && item.ItemID == m_itemID)
4216 { 4273 {
4217 if (item.Type == 10 && item.ItemID == m_itemID) 4274 result = item.Name!=null?item.Name:String.Empty;
4218 { 4275 break;
4219 result = item.Name!=null?item.Name:String.Empty;
4220 break;
4221 }
4222 } 4276 }
4223 } 4277 }
4278 m_host.TaskInventory.LockItemsForRead(false);
4224 4279
4225 return result; 4280 return result;
4226 } 4281 }
@@ -4478,23 +4533,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4478 { 4533 {
4479 m_host.AddScriptLPS(1); 4534 m_host.AddScriptLPS(1);
4480 4535
4481 lock (m_host.TaskInventory) 4536 m_host.TaskInventory.LockItemsForRead(true);
4537 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4482 { 4538 {
4483 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4539 if (inv.Value.Name == name)
4484 { 4540 {
4485 if (inv.Value.Name == name) 4541 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
4486 { 4542 {
4487 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) 4543 m_host.TaskInventory.LockItemsForRead(false);
4488 { 4544 return inv.Value.AssetID.ToString();
4489 return inv.Value.AssetID.ToString(); 4545 }
4490 } 4546 else
4491 else 4547 {
4492 { 4548 m_host.TaskInventory.LockItemsForRead(false);
4493 return UUID.Zero.ToString(); 4549 return UUID.Zero.ToString();
4494 }
4495 } 4550 }
4496 } 4551 }
4497 } 4552 }
4553 m_host.TaskInventory.LockItemsForRead(false);
4498 4554
4499 return UUID.Zero.ToString(); 4555 return UUID.Zero.ToString();
4500 } 4556 }
@@ -5989,14 +6045,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5989 6045
5990 protected UUID GetTaskInventoryItem(string name) 6046 protected UUID GetTaskInventoryItem(string name)
5991 { 6047 {
5992 lock (m_host.TaskInventory) 6048 m_host.TaskInventory.LockItemsForRead(true);
6049 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
5993 { 6050 {
5994 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6051 if (inv.Value.Name == name)
5995 { 6052 {
5996 if (inv.Value.Name == name) 6053 m_host.TaskInventory.LockItemsForRead(false);
5997 return inv.Key; 6054 return inv.Key;
5998 } 6055 }
5999 } 6056 }
6057 m_host.TaskInventory.LockItemsForRead(false);
6000 6058
6001 return UUID.Zero; 6059 return UUID.Zero;
6002 } 6060 }
@@ -6307,22 +6365,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6307 } 6365 }
6308 6366
6309 // copy the first script found with this inventory name 6367 // copy the first script found with this inventory name
6310 lock (m_host.TaskInventory) 6368 m_host.TaskInventory.LockItemsForRead(true);
6369 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6311 { 6370 {
6312 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6371 if (inv.Value.Name == name)
6313 { 6372 {
6314 if (inv.Value.Name == name) 6373 // make sure the object is a script
6374 if (10 == inv.Value.Type)
6315 { 6375 {
6316 // make sure the object is a script 6376 found = true;
6317 if (10 == inv.Value.Type) 6377 srcId = inv.Key;
6318 { 6378 break;
6319 found = true;
6320 srcId = inv.Key;
6321 break;
6322 }
6323 } 6379 }
6324 } 6380 }
6325 } 6381 }
6382 m_host.TaskInventory.LockItemsForRead(false);
6326 6383
6327 if (!found) 6384 if (!found)
6328 { 6385 {
@@ -8125,28 +8182,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8125 { 8182 {
8126 m_host.AddScriptLPS(1); 8183 m_host.AddScriptLPS(1);
8127 8184
8128 lock (m_host.TaskInventory) 8185 m_host.TaskInventory.LockItemsForRead(true);
8186 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8129 { 8187 {
8130 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 8188 if (inv.Value.Name == item)
8131 { 8189 {
8132 if (inv.Value.Name == item) 8190 m_host.TaskInventory.LockItemsForRead(false);
8191 switch (mask)
8133 { 8192 {
8134 switch (mask) 8193 case 0:
8135 { 8194 return (int)inv.Value.BasePermissions;
8136 case 0: 8195 case 1:
8137 return (int)inv.Value.BasePermissions; 8196 return (int)inv.Value.CurrentPermissions;
8138 case 1: 8197 case 2:
8139 return (int)inv.Value.CurrentPermissions; 8198 return (int)inv.Value.GroupPermissions;
8140 case 2: 8199 case 3:
8141 return (int)inv.Value.GroupPermissions; 8200 return (int)inv.Value.EveryonePermissions;
8142 case 3: 8201 case 4:
8143 return (int)inv.Value.EveryonePermissions; 8202 return (int)inv.Value.NextPermissions;
8144 case 4:
8145 return (int)inv.Value.NextPermissions;
8146 }
8147 } 8203 }
8148 } 8204 }
8149 } 8205 }
8206 m_host.TaskInventory.LockItemsForRead(false);
8150 8207
8151 return -1; 8208 return -1;
8152 } 8209 }
@@ -8161,16 +8218,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8161 { 8218 {
8162 m_host.AddScriptLPS(1); 8219 m_host.AddScriptLPS(1);
8163 8220
8164 lock (m_host.TaskInventory) 8221 m_host.TaskInventory.LockItemsForRead(true);
8222 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8165 { 8223 {
8166 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 8224 if (inv.Value.Name == item)
8167 { 8225 {
8168 if (inv.Value.Name == item) 8226 m_host.TaskInventory.LockItemsForRead(false);
8169 { 8227 return inv.Value.CreatorID.ToString();
8170 return inv.Value.CreatorID.ToString();
8171 }
8172 } 8228 }
8173 } 8229 }
8230 m_host.TaskInventory.LockItemsForRead(false);
8174 8231
8175 llSay(0, "No item name '" + item + "'"); 8232 llSay(0, "No item name '" + item + "'");
8176 8233
@@ -8694,16 +8751,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8694 { 8751 {
8695 m_host.AddScriptLPS(1); 8752 m_host.AddScriptLPS(1);
8696 8753
8697 lock (m_host.TaskInventory) 8754 m_host.TaskInventory.LockItemsForRead(true);
8755 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8698 { 8756 {
8699 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 8757 if (inv.Value.Name == name)
8700 { 8758 {
8701 if (inv.Value.Name == name) 8759 m_host.TaskInventory.LockItemsForRead(false);
8702 { 8760 return inv.Value.Type;
8703 return inv.Value.Type;
8704 }
8705 } 8761 }
8706 } 8762 }
8763 m_host.TaskInventory.LockItemsForRead(false);
8707 8764
8708 return -1; 8765 return -1;
8709 } 8766 }
@@ -8734,17 +8791,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8734 if (invItemID == UUID.Zero) 8791 if (invItemID == UUID.Zero)
8735 return new LSL_Vector(); 8792 return new LSL_Vector();
8736 8793
8737 lock (m_host.TaskInventory) 8794 m_host.TaskInventory.LockItemsForRead(true);
8795 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
8738 { 8796 {
8739 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 8797 m_host.TaskInventory.LockItemsForRead(false);
8740 return new LSL_Vector(); 8798 return new LSL_Vector();
8799 }
8741 8800
8742 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 8801 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
8743 { 8802 {
8744 ShoutError("No permissions to track the camera"); 8803 ShoutError("No permissions to track the camera");
8745 return new LSL_Vector(); 8804 m_host.TaskInventory.LockItemsForRead(false);
8746 } 8805 return new LSL_Vector();
8747 } 8806 }
8807 m_host.TaskInventory.LockItemsForRead(false);
8748 8808
8749 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 8809 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
8750 if (presence != null) 8810 if (presence != null)
@@ -8762,17 +8822,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8762 if (invItemID == UUID.Zero) 8822 if (invItemID == UUID.Zero)
8763 return new LSL_Rotation(); 8823 return new LSL_Rotation();
8764 8824
8765 lock (m_host.TaskInventory) 8825 m_host.TaskInventory.LockItemsForRead(true);
8826 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
8766 { 8827 {
8767 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 8828 m_host.TaskInventory.LockItemsForRead(false);
8768 return new LSL_Rotation(); 8829 return new LSL_Rotation();
8769
8770 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
8771 {
8772 ShoutError("No permissions to track the camera");
8773 return new LSL_Rotation();
8774 }
8775 } 8830 }
8831 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
8832 {
8833 ShoutError("No permissions to track the camera");
8834 m_host.TaskInventory.LockItemsForRead(false);
8835 return new LSL_Rotation();
8836 }
8837 m_host.TaskInventory.LockItemsForRead(false);
8776 8838
8777 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 8839 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
8778 if (presence != null) 8840 if (presence != null)
@@ -8922,14 +8984,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8922 if (objectID == UUID.Zero) return; 8984 if (objectID == UUID.Zero) return;
8923 8985
8924 UUID agentID; 8986 UUID agentID;
8925 lock (m_host.TaskInventory) 8987 m_host.TaskInventory.LockItemsForRead(true);
8926 { 8988 // we need the permission first, to know which avatar we want to set the camera for
8927 // we need the permission first, to know which avatar we want to set the camera for 8989 agentID = m_host.TaskInventory[invItemID].PermsGranter;
8928 agentID = m_host.TaskInventory[invItemID].PermsGranter;
8929 8990
8930 if (agentID == UUID.Zero) return; 8991 if (agentID == UUID.Zero)
8931 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 8992 {
8993 m_host.TaskInventory.LockItemsForRead(false);
8994 return;
8932 } 8995 }
8996 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
8997 {
8998 m_host.TaskInventory.LockItemsForRead(false);
8999 return;
9000 }
9001 m_host.TaskInventory.LockItemsForRead(false);
8933 9002
8934 ScenePresence presence = World.GetScenePresence(agentID); 9003 ScenePresence presence = World.GetScenePresence(agentID);
8935 9004
@@ -8979,12 +9048,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8979 9048
8980 // we need the permission first, to know which avatar we want to clear the camera for 9049 // we need the permission first, to know which avatar we want to clear the camera for
8981 UUID agentID; 9050 UUID agentID;
8982 lock (m_host.TaskInventory) 9051 m_host.TaskInventory.LockItemsForRead(true);
9052 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9053 if (agentID == UUID.Zero)
9054 {
9055 m_host.TaskInventory.LockItemsForRead(false);
9056 return;
9057 }
9058 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
8983 { 9059 {
8984 agentID = m_host.TaskInventory[invItemID].PermsGranter; 9060 m_host.TaskInventory.LockItemsForRead(false);
8985 if (agentID == UUID.Zero) return; 9061 return;
8986 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
8987 } 9062 }
9063 m_host.TaskInventory.LockItemsForRead(false);
8988 9064
8989 ScenePresence presence = World.GetScenePresence(agentID); 9065 ScenePresence presence = World.GetScenePresence(agentID);
8990 9066
@@ -9441,15 +9517,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9441 9517
9442 internal UUID ScriptByName(string name) 9518 internal UUID ScriptByName(string name)
9443 { 9519 {
9444 lock (m_host.TaskInventory) 9520 m_host.TaskInventory.LockItemsForRead(true);
9521
9522 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
9445 { 9523 {
9446 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 9524 if (item.Type == 10 && item.Name == name)
9447 { 9525 {
9448 if (item.Type == 10 && item.Name == name) 9526 m_host.TaskInventory.LockItemsForRead(false);
9449 return item.ItemID; 9527 return item.ItemID;
9450 } 9528 }
9451 } 9529 }
9452 9530
9531 m_host.TaskInventory.LockItemsForRead(false);
9532
9453 return UUID.Zero; 9533 return UUID.Zero;
9454 } 9534 }
9455 9535
@@ -9490,6 +9570,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9490 { 9570 {
9491 m_host.AddScriptLPS(1); 9571 m_host.AddScriptLPS(1);
9492 9572
9573 //Clone is thread safe
9493 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 9574 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
9494 9575
9495 UUID assetID = UUID.Zero; 9576 UUID assetID = UUID.Zero;
@@ -9552,6 +9633,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9552 { 9633 {
9553 m_host.AddScriptLPS(1); 9634 m_host.AddScriptLPS(1);
9554 9635
9636 //Clone is thread safe
9555 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 9637 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
9556 9638
9557 UUID assetID = UUID.Zero; 9639 UUID assetID = UUID.Zero;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 7fdbac8..83322eb 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -728,18 +728,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
728 if (target != null) 728 if (target != null)
729 { 729 {
730 UUID animID=UUID.Zero; 730 UUID animID=UUID.Zero;
731 lock (m_host.TaskInventory) 731 m_host.TaskInventory.LockItemsForRead(true);
732 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
732 { 733 {
733 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 734 if (inv.Value.Name == animation)
734 { 735 {
735 if (inv.Value.Name == animation) 736 if (inv.Value.Type == (int)AssetType.Animation)
736 { 737 animID = inv.Value.AssetID;
737 if (inv.Value.Type == (int)AssetType.Animation) 738 continue;
738 animID = inv.Value.AssetID;
739 continue;
740 }
741 } 739 }
742 } 740 }
741 m_host.TaskInventory.LockItemsForRead(false);
743 if (animID == UUID.Zero) 742 if (animID == UUID.Zero)
744 target.Animator.AddAnimation(animation, m_host.UUID); 743 target.Animator.AddAnimation(animation, m_host.UUID);
745 else 744 else
@@ -761,18 +760,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
761 if (target != null) 760 if (target != null)
762 { 761 {
763 UUID animID=UUID.Zero; 762 UUID animID=UUID.Zero;
764 lock (m_host.TaskInventory) 763 m_host.TaskInventory.LockItemsForRead(true);
764 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
765 { 765 {
766 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 766 if (inv.Value.Name == animation)
767 { 767 {
768 if (inv.Value.Name == animation) 768 if (inv.Value.Type == (int)AssetType.Animation)
769 { 769 animID = inv.Value.AssetID;
770 if (inv.Value.Type == (int)AssetType.Animation) 770 continue;
771 animID = inv.Value.AssetID;
772 continue;
773 }
774 } 771 }
775 } 772 }
773 m_host.TaskInventory.LockItemsForRead(false);
776 774
777 if (animID == UUID.Zero) 775 if (animID == UUID.Zero)
778 target.Animator.RemoveAnimation(animation); 776 target.Animator.RemoveAnimation(animation);
@@ -1541,6 +1539,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1541 1539
1542 if (!UUID.TryParse(name, out assetID)) 1540 if (!UUID.TryParse(name, out assetID))
1543 { 1541 {
1542 m_host.TaskInventory.LockItemsForRead(true);
1544 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1543 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1545 { 1544 {
1546 if (item.Type == 7 && item.Name == name) 1545 if (item.Type == 7 && item.Name == name)
@@ -1548,6 +1547,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1548 assetID = item.AssetID; 1547 assetID = item.AssetID;
1549 } 1548 }
1550 } 1549 }
1550 m_host.TaskInventory.LockItemsForRead(false);
1551 } 1551 }
1552 1552
1553 if (assetID == UUID.Zero) 1553 if (assetID == UUID.Zero)
@@ -1594,6 +1594,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1594 1594
1595 if (!UUID.TryParse(name, out assetID)) 1595 if (!UUID.TryParse(name, out assetID))
1596 { 1596 {
1597 m_host.TaskInventory.LockItemsForRead(true);
1597 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1598 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1598 { 1599 {
1599 if (item.Type == 7 && item.Name == name) 1600 if (item.Type == 7 && item.Name == name)
@@ -1601,6 +1602,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1601 assetID = item.AssetID; 1602 assetID = item.AssetID;
1602 } 1603 }
1603 } 1604 }
1605 m_host.TaskInventory.LockItemsForRead(false);
1604 } 1606 }
1605 1607
1606 if (assetID == UUID.Zero) 1608 if (assetID == UUID.Zero)
@@ -1651,6 +1653,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1651 1653
1652 if (!UUID.TryParse(name, out assetID)) 1654 if (!UUID.TryParse(name, out assetID))
1653 { 1655 {
1656 m_host.TaskInventory.LockItemsForRead(true);
1654 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1657 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1655 { 1658 {
1656 if (item.Type == 7 && item.Name == name) 1659 if (item.Type == 7 && item.Name == name)
@@ -1658,6 +1661,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1658 assetID = item.AssetID; 1661 assetID = item.AssetID;
1659 } 1662 }
1660 } 1663 }
1664 m_host.TaskInventory.LockItemsForRead(false);
1661 } 1665 }
1662 1666
1663 if (assetID == UUID.Zero) 1667 if (assetID == UUID.Zero)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
index 7f67599..15e0408 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Diagnostics; //for [DebuggerNonUserCode]
30using System.Reflection; 31using System.Reflection;
31using System.Runtime.Remoting.Lifetime; 32using System.Runtime.Remoting.Lifetime;
32using OpenSim.Region.ScriptEngine.Shared; 33using OpenSim.Region.ScriptEngine.Shared;
@@ -131,6 +132,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
131 return (eventFlags); 132 return (eventFlags);
132 } 133 }
133 134
135 [DebuggerNonUserCode]
134 public void ExecuteEvent(string state, string FunctionName, object[] args) 136 public void ExecuteEvent(string state, string FunctionName, object[] args)
135 { 137 {
136 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. 138 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
index 121159c..a44abb0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
@@ -33,6 +33,7 @@ using System.Threading;
33using System.Reflection; 33using System.Reflection;
34using System.Collections; 34using System.Collections;
35using System.Collections.Generic; 35using System.Collections.Generic;
36using System.Diagnostics; //for [DebuggerNonUserCode]
36using OpenSim.Region.ScriptEngine.Interfaces; 37using OpenSim.Region.ScriptEngine.Interfaces;
37using OpenSim.Region.ScriptEngine.Shared; 38using OpenSim.Region.ScriptEngine.Shared;
38using OpenSim.Region.ScriptEngine.Shared.Api.Runtime; 39using OpenSim.Region.ScriptEngine.Shared.Api.Runtime;
@@ -90,6 +91,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
90 return (int)m_Executor.GetStateEventFlags(state); 91 return (int)m_Executor.GetStateEventFlags(state);
91 } 92 }
92 93
94 [DebuggerNonUserCode]
93 public void ExecuteEvent(string state, string FunctionName, object[] args) 95 public void ExecuteEvent(string state, string FunctionName, object[] args)
94 { 96 {
95 m_Executor.ExecuteEvent(state, FunctionName, args); 97 m_Executor.ExecuteEvent(state, FunctionName, args);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 41b5d49..0f4a9ad 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Diagnostics; //for [DebuggerNonUserCode]
30using System.Runtime.Remoting; 31using System.Runtime.Remoting;
31using System.Runtime.Remoting.Lifetime; 32using System.Runtime.Remoting.Lifetime;
32using System.Threading; 33using System.Threading;
@@ -237,13 +238,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
237 238
238 if (part != null) 239 if (part != null)
239 { 240 {
240 lock (part.TaskInventory) 241 part.TaskInventory.LockItemsForRead(true);
242 if (part.TaskInventory.ContainsKey(m_ItemID))
241 { 243 {
242 if (part.TaskInventory.ContainsKey(m_ItemID)) 244 m_thisScriptTask = part.TaskInventory[m_ItemID];
243 {
244 m_thisScriptTask = part.TaskInventory[m_ItemID];
245 }
246 } 245 }
246 part.TaskInventory.LockItemsForRead(false);
247 } 247 }
248 248
249 ApiManager am = new ApiManager(); 249 ApiManager am = new ApiManager();
@@ -428,14 +428,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
428 { 428 {
429 int permsMask; 429 int permsMask;
430 UUID permsGranter; 430 UUID permsGranter;
431 lock (part.TaskInventory) 431 part.TaskInventory.LockItemsForRead(true);
432 if (!part.TaskInventory.ContainsKey(m_ItemID))
432 { 433 {
433 if (!part.TaskInventory.ContainsKey(m_ItemID)) 434 part.TaskInventory.LockItemsForRead(false);
434 return; 435 return;
435
436 permsGranter = part.TaskInventory[m_ItemID].PermsGranter;
437 permsMask = part.TaskInventory[m_ItemID].PermsMask;
438 } 436 }
437 permsGranter = part.TaskInventory[m_ItemID].PermsGranter;
438 permsMask = part.TaskInventory[m_ItemID].PermsMask;
439 part.TaskInventory.LockItemsForRead(false);
439 440
440 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 441 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
441 { 442 {
@@ -544,6 +545,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
544 return true; 545 return true;
545 } 546 }
546 547
548 [DebuggerNonUserCode] //Prevents the debugger from farting in this function
547 public void SetState(string state) 549 public void SetState(string state)
548 { 550 {
549 if (state == State) 551 if (state == State)
@@ -555,7 +557,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
555 new DetectParams[0])); 557 new DetectParams[0]));
556 PostEvent(new EventParams("state_entry", new Object[0], 558 PostEvent(new EventParams("state_entry", new Object[0],
557 new DetectParams[0])); 559 new DetectParams[0]));
558 560
559 throw new EventAbortException(); 561 throw new EventAbortException();
560 } 562 }
561 563
@@ -638,154 +640,158 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
638 /// <returns></returns> 640 /// <returns></returns>
639 public object EventProcessor() 641 public object EventProcessor()
640 { 642 {
643
644 EventParams data = null;
645
646 lock (m_EventQueue)
647 {
641 lock (m_Script) 648 lock (m_Script)
642 { 649 {
643 EventParams data = null; 650 data = (EventParams) m_EventQueue.Dequeue();
644 651 if (data == null) // Shouldn't happen
645 lock (m_EventQueue)
646 { 652 {
647 data = (EventParams) m_EventQueue.Dequeue(); 653 if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown))
648 if (data == null) // Shouldn't happen
649 { 654 {
650 if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) 655 m_CurrentResult = m_Engine.QueueEventHandler(this);
651 {
652 m_CurrentResult = m_Engine.QueueEventHandler(this);
653 }
654 else
655 {
656 m_CurrentResult = null;
657 }
658 return 0;
659 } 656 }
660 657 else
661 if (data.EventName == "timer")
662 m_TimerQueued = false;
663 if (data.EventName == "control")
664 { 658 {
665 if (m_ControlEventsInQueue > 0) 659 m_CurrentResult = null;
666 m_ControlEventsInQueue--;
667 } 660 }
668 if (data.EventName == "collision") 661 return 0;
669 m_CollisionInQueue = false;
670 } 662 }
671
672 //m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this);
673 663
674 m_DetectParams = data.DetectParams; 664 if (data.EventName == "timer")
675 665 m_TimerQueued = false;
676 if (data.EventName == "state") // Hardcoded state change 666 if (data.EventName == "control")
677 { 667 {
678 // m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}", 668 if (m_ControlEventsInQueue > 0)
679 // m_PrimName, m_ScriptName, data.Params[0].ToString()); 669 m_ControlEventsInQueue--;
680 m_State=data.Params[0].ToString(); 670 }
681 AsyncCommandManager.RemoveScript(m_Engine, 671 if (data.EventName == "collision")
682 m_LocalID, m_ItemID); 672 m_CollisionInQueue = false;
673 }
674 }
675 lock(m_Script)
676 {
677
678 //m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this);
683 679
684 SceneObjectPart part = m_Engine.World.GetSceneObjectPart( 680 m_DetectParams = data.DetectParams;
685 m_LocalID); 681
686 if (part != null) 682 if (data.EventName == "state") // Hardcoded state change
687 { 683 {
688 part.SetScriptEvents(m_ItemID, 684// m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}",
689 (int)m_Script.GetStateEventFlags(State)); 685// m_PrimName, m_ScriptName, data.Params[0].ToString());
690 } 686 m_State=data.Params[0].ToString();
687 AsyncCommandManager.RemoveScript(m_Engine,
688 m_LocalID, m_ItemID);
689
690 SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
691 m_LocalID);
692 if (part != null)
693 {
694 part.SetScriptEvents(m_ItemID,
695 (int)m_Script.GetStateEventFlags(State));
691 } 696 }
692 else 697 }
698 else
699 {
700 if (m_Engine.World.PipeEventsForScript(m_LocalID) ||
701 data.EventName == "control") // Don't freeze avies!
693 { 702 {
694 if (m_Engine.World.PipeEventsForScript(m_LocalID) || 703 SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
695 data.EventName == "control") // Don't freeze avies! 704 m_LocalID);
696 { 705 // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
697 SceneObjectPart part = m_Engine.World.GetSceneObjectPart( 706 // m_PrimName, m_ScriptName, data.EventName, m_State);
698 m_LocalID);
699 // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
700 // m_PrimName, m_ScriptName, data.EventName, m_State);
701 707
702 try 708 try
703 { 709 {
704 m_CurrentEvent = data.EventName; 710 m_CurrentEvent = data.EventName;
705 m_EventStart = DateTime.Now; 711 m_EventStart = DateTime.Now;
706 m_InEvent = true; 712 m_InEvent = true;
707 713
708 m_Script.ExecuteEvent(State, data.EventName, data.Params); 714 m_Script.ExecuteEvent(State, data.EventName, data.Params);
709 715
710 m_InEvent = false; 716 m_InEvent = false;
711 m_CurrentEvent = String.Empty; 717 m_CurrentEvent = String.Empty;
712 718
713 if (m_SaveState) 719 if (m_SaveState)
714 { 720 {
715 // This will be the very first event we deliver 721 // This will be the very first event we deliver
716 // (state_entry) in default state 722 // (state_entry) in default state
717 // 723 //
718 724
719 SaveState(m_Assembly); 725 SaveState(m_Assembly);
720 726
721 m_SaveState = false; 727 m_SaveState = false;
722 }
723 } 728 }
724 catch (Exception e) 729 }
725 { 730 catch (Exception e)
726 // m_log.DebugFormat("[SCRIPT] Exception: {0}", e.Message); 731 {
727 m_InEvent = false; 732 // m_log.DebugFormat("[SCRIPT] Exception: {0}", e.Message);
728 m_CurrentEvent = String.Empty; 733 m_InEvent = false;
734 m_CurrentEvent = String.Empty;
729 735
730 if ((!(e is TargetInvocationException) || (!(e.InnerException is SelfDeleteException) && !(e.InnerException is ScriptDeleteException))) && !(e is ThreadAbortException)) 736 if ((!(e is TargetInvocationException) || (!(e.InnerException is SelfDeleteException) && !(e.InnerException is ScriptDeleteException))) && !(e is ThreadAbortException))
731 { 737 {
732 try 738 try
733 {
734 // DISPLAY ERROR INWORLD
735 string text = FormatException(e);
736
737 if (text.Length > 1000)
738 text = text.Substring(0, 1000);
739 m_Engine.World.SimChat(Utils.StringToBytes(text),
740 ChatTypeEnum.DebugChannel, 2147483647,
741 part.AbsolutePosition,
742 part.Name, part.UUID, false);
743 }
744 catch (Exception)
745 {
746 }
747 // catch (Exception e2) // LEGIT: User Scripting
748 // {
749 // m_log.Error("[SCRIPT]: "+
750 // "Error displaying error in-world: " +
751 // e2.ToString());
752 // m_log.Error("[SCRIPT]: " +
753 // "Errormessage: Error compiling script:\r\n" +
754 // e.ToString());
755 // }
756 }
757 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
758 { 739 {
759 m_InSelfDelete = true; 740 // DISPLAY ERROR INWORLD
760 if (part != null && part.ParentGroup != null) 741 string text = FormatException(e);
761 m_Engine.World.DeleteSceneObject(part.ParentGroup, false); 742
743 if (text.Length > 1000)
744 text = text.Substring(0, 1000);
745 m_Engine.World.SimChat(Utils.StringToBytes(text),
746 ChatTypeEnum.DebugChannel, 2147483647,
747 part.AbsolutePosition,
748 part.Name, part.UUID, false);
762 } 749 }
763 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) 750 catch (Exception)
764 { 751 {
765 m_InSelfDelete = true;
766 if (part != null && part.ParentGroup != null)
767 part.Inventory.RemoveInventoryItem(m_ItemID);
768 } 752 }
753 // catch (Exception e2) // LEGIT: User Scripting
754 // {
755 // m_log.Error("[SCRIPT]: "+
756 // "Error displaying error in-world: " +
757 // e2.ToString());
758 // m_log.Error("[SCRIPT]: " +
759 // "Errormessage: Error compiling script:\r\n" +
760 // e.ToString());
761 // }
762 }
763 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
764 {
765 m_InSelfDelete = true;
766 if (part != null && part.ParentGroup != null)
767 m_Engine.World.DeleteSceneObject(part.ParentGroup, false);
768 }
769 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException))
770 {
771 m_InSelfDelete = true;
772 if (part != null && part.ParentGroup != null)
773 part.Inventory.RemoveInventoryItem(m_ItemID);
769 } 774 }
770 } 775 }
771 } 776 }
777 }
772 778
773 lock (m_EventQueue) 779 lock (m_EventQueue)
780 {
781 if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown))
774 { 782 {
775 if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) 783 m_CurrentResult = m_Engine.QueueEventHandler(this);
776 { 784 }
777 m_CurrentResult = m_Engine.QueueEventHandler(this); 785 else
778 } 786 {
779 else 787 m_CurrentResult = null;
780 {
781 m_CurrentResult = null;
782 }
783 } 788 }
789 }
784 790
785 m_DetectParams = null; 791 m_DetectParams = null;
786 792
787 return 0; 793 return 0;
788 } 794 }
789 } 795 }
790 796
791 public int EventTime() 797 public int EventTime()
@@ -824,6 +830,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
824 new Object[0], new DetectParams[0])); 830 new Object[0], new DetectParams[0]));
825 } 831 }
826 832
833 [DebuggerNonUserCode] //Stops the VS debugger from farting in this function
827 public void ApiResetScript() 834 public void ApiResetScript()
828 { 835 {
829 // bool running = Running; 836 // bool running = Running;