aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs473
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs676
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs36
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs32
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs21
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Constants.cs76
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs76
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs261
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs424
13 files changed, 1487 insertions, 596 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
new file mode 100644
index 0000000..d4250c1
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
@@ -0,0 +1,473 @@
1using System;
2using System.Reflection;
3using System.Collections;
4using System.Collections.Generic;
5using System.Runtime.Remoting.Lifetime;
6using OpenMetaverse;
7using Nini.Config;
8using OpenSim;
9using OpenSim.Framework;
10using OpenSim.Region.CoreModules.World.Meta7Windlight;
11using OpenSim.Region.Framework.Interfaces;
12using OpenSim.Region.Framework.Scenes;
13using OpenSim.Region.ScriptEngine.Shared;
14using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
15using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
16using OpenSim.Region.ScriptEngine.Interfaces;
17using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
18
19using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
20using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
21using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
22using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
23using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
24using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
25using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
26
27namespace OpenSim.Region.ScriptEngine.Shared.Api
28{
29 [Serializable]
30 public class CM_Api : MarshalByRefObject, ICM_Api, IScriptApi
31 {
32 internal IScriptEngine m_ScriptEngine;
33 internal SceneObjectPart m_host;
34 internal uint m_localID;
35 internal UUID m_itemID;
36 internal bool m_CMFunctionsEnabled = false;
37 internal IScriptModuleComms m_comms = null;
38
39 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
40 {
41 m_ScriptEngine = ScriptEngine;
42 m_host = host;
43 m_localID = localID;
44 m_itemID = itemID;
45
46 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false))
47 m_CMFunctionsEnabled = true;
48
49 m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
50 if (m_comms == null)
51 m_CMFunctionsEnabled = false;
52 }
53
54 public override Object InitializeLifetimeService()
55 {
56 ILease lease = (ILease)base.InitializeLifetimeService();
57
58 if (lease.CurrentState == LeaseState.Initial)
59 {
60 lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
61 // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
62 // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
63 }
64 return lease;
65 }
66
67 public Scene World
68 {
69 get { return m_ScriptEngine.World; }
70 }
71
72 //
73 //Dumps an error message on the debug console.
74 //
75
76 internal void CMShoutError(string message)
77 {
78 if (message.Length > 1023)
79 message = message.Substring(0, 1023);
80
81 World.SimChat(Utils.StringToBytes(message),
82 ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
83
84 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
85 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
86 }
87
88 /// <summary>
89 /// Get the current Windlight scene
90 /// </summary>
91 /// <returns>List of windlight parameters</returns>
92 public LSL_List cmGetWindlightScene(LSL_List rules)
93 {
94 if (!m_CMFunctionsEnabled)
95 {
96 CMShoutError("Careminster functions are not enabled.");
97 return new LSL_List();
98 }
99 m_host.AddScriptLPS(1);
100 RegionMeta7WindlightData wl = m_host.ParentGroup.Scene.RegionInfo.WindlightSettings;
101
102 LSL_List values = new LSL_List();
103 int idx = 0;
104 while (idx < rules.Length)
105 {
106 uint rule = (uint)rules.GetLSLIntegerItem(idx);
107 LSL_List toadd = new LSL_List();
108
109 switch (rule)
110 {
111 case (int)ScriptBaseClass.WL_AMBIENT:
112 toadd.Add(new LSL_Rotation(wl.ambient.X, wl.ambient.Y, wl.ambient.Z, wl.ambient.W));
113 break;
114 case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
115 toadd.Add(new LSL_Vector(wl.bigWaveDirection.X, wl.bigWaveDirection.Y, 0.0f));
116 break;
117 case (int)ScriptBaseClass.WL_BLUE_DENSITY:
118 toadd.Add(new LSL_Rotation(wl.blueDensity.X, wl.blueDensity.Y, wl.blueDensity.Z, wl.blueDensity.W));
119 break;
120 case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
121 toadd.Add(new LSL_Float(wl.blurMultiplier));
122 break;
123 case (int)ScriptBaseClass.WL_CLOUD_COLOR:
124 toadd.Add(new LSL_Rotation(wl.cloudColor.X, wl.cloudColor.Y, wl.cloudColor.Z, wl.cloudColor.W));
125 break;
126 case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
127 toadd.Add(new LSL_Float(wl.cloudCoverage));
128 break;
129 case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
130 toadd.Add(new LSL_Vector(wl.cloudDetailXYDensity.X, wl.cloudDetailXYDensity.Y, wl.cloudDetailXYDensity.Z));
131 break;
132 case (int)ScriptBaseClass.WL_CLOUD_SCALE:
133 toadd.Add(new LSL_Float(wl.cloudScale));
134 break;
135 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
136 toadd.Add(new LSL_Float(wl.cloudScrollX));
137 break;
138 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
139 toadd.Add(new LSL_Integer(wl.cloudScrollXLock ? 1 : 0));
140 break;
141 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
142 toadd.Add(new LSL_Float(wl.cloudScrollY));
143 break;
144 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
145 toadd.Add(new LSL_Integer(wl.cloudScrollYLock ? 1 : 0));
146 break;
147 case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
148 toadd.Add(new LSL_Vector(wl.cloudXYDensity.X, wl.cloudXYDensity.Y, wl.cloudXYDensity.Z));
149 break;
150 case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
151 toadd.Add(new LSL_Float(wl.densityMultiplier));
152 break;
153 case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
154 toadd.Add(new LSL_Float(wl.distanceMultiplier));
155 break;
156 case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
157 toadd.Add(new LSL_Integer(wl.drawClassicClouds ? 1 : 0));
158 break;
159 case (int)ScriptBaseClass.WL_EAST_ANGLE:
160 toadd.Add(new LSL_Float(wl.eastAngle));
161 break;
162 case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
163 toadd.Add(new LSL_Float(wl.fresnelOffset));
164 break;
165 case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
166 toadd.Add(new LSL_Float(wl.fresnelScale));
167 break;
168 case (int)ScriptBaseClass.WL_HAZE_DENSITY:
169 toadd.Add(new LSL_Float(wl.hazeDensity));
170 break;
171 case (int)ScriptBaseClass.WL_HAZE_HORIZON:
172 toadd.Add(new LSL_Float(wl.hazeHorizon));
173 break;
174 case (int)ScriptBaseClass.WL_HORIZON:
175 toadd.Add(new LSL_Rotation(wl.horizon.X, wl.horizon.Y, wl.horizon.Z, wl.horizon.W));
176 break;
177 case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
178 toadd.Add(new LSL_Vector(wl.littleWaveDirection.X, wl.littleWaveDirection.Y, 0.0f));
179 break;
180 case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
181 toadd.Add(new LSL_Integer(wl.maxAltitude));
182 break;
183 case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
184 toadd.Add(new LSL_Key(wl.normalMapTexture.ToString()));
185 break;
186 case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
187 toadd.Add(new LSL_Vector(wl.reflectionWaveletScale.X, wl.reflectionWaveletScale.Y, wl.reflectionWaveletScale.Z));
188 break;
189 case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
190 toadd.Add(new LSL_Float(wl.refractScaleAbove));
191 break;
192 case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
193 toadd.Add(new LSL_Float(wl.refractScaleBelow));
194 break;
195 case (int)ScriptBaseClass.WL_SCENE_GAMMA:
196 toadd.Add(new LSL_Float(wl.sceneGamma));
197 break;
198 case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
199 toadd.Add(new LSL_Float(wl.starBrightness));
200 break;
201 case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
202 toadd.Add(new LSL_Float(wl.sunGlowFocus));
203 break;
204 case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
205 toadd.Add(new LSL_Float(wl.sunGlowSize));
206 break;
207 case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
208 toadd.Add(new LSL_Rotation(wl.sunMoonColor.X, wl.sunMoonColor.Y, wl.sunMoonColor.Z, wl.sunMoonColor.W));
209 break;
210 case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
211 toadd.Add(new LSL_Float(wl.underwaterFogModifier));
212 break;
213 case (int)ScriptBaseClass.WL_WATER_COLOR:
214 toadd.Add(new LSL_Vector(wl.waterColor.X, wl.waterColor.Y, wl.waterColor.Z));
215 break;
216 case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
217 toadd.Add(new LSL_Float(wl.waterFogDensityExponent));
218 break;
219 }
220
221 if (toadd.Length > 0)
222 {
223 values.Add(rule);
224 values.Add(toadd.Data[0]);
225 }
226 idx++;
227 }
228
229
230 return values;
231
232 }
233
234 private RegionMeta7WindlightData getWindlightProfileFromRules(LSL_List rules)
235 {
236 RegionMeta7WindlightData wl = (RegionMeta7WindlightData)m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.Clone();
237
238 LSL_List values = new LSL_List();
239 int idx = 0;
240 while (idx < rules.Length)
241 {
242 uint rule = (uint)rules.GetLSLIntegerItem(idx);
243 LSL_Types.Quaternion iQ;
244 LSL_Types.Vector3 iV;
245 switch (rule)
246 {
247 case (int)ScriptBaseClass.WL_AMBIENT:
248 idx++;
249 iQ = rules.GetQuaternionItem(idx);
250 wl.ambient = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
251 break;
252 case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
253 idx++;
254 iV = rules.GetVector3Item(idx);
255 wl.bigWaveDirection = new Vector2((float)iV.x, (float)iV.y);
256 break;
257 case (int)ScriptBaseClass.WL_BLUE_DENSITY:
258 idx++;
259 iQ = rules.GetQuaternionItem(idx);
260 wl.blueDensity = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
261 break;
262 case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
263 idx++;
264 wl.blurMultiplier = (float)rules.GetLSLFloatItem(idx);
265 break;
266 case (int)ScriptBaseClass.WL_CLOUD_COLOR:
267 idx++;
268 iQ = rules.GetQuaternionItem(idx);
269 wl.cloudColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
270 break;
271 case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
272 idx++;
273 wl.cloudCoverage = (float)rules.GetLSLFloatItem(idx);
274 break;
275 case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
276 idx++;
277 iV = rules.GetVector3Item(idx);
278 wl.cloudDetailXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
279 break;
280 case (int)ScriptBaseClass.WL_CLOUD_SCALE:
281 idx++;
282 wl.cloudScale = (float)rules.GetLSLFloatItem(idx);
283 break;
284 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
285 idx++;
286 wl.cloudScrollX = (float)rules.GetLSLFloatItem(idx);
287 break;
288 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
289 idx++;
290 wl.cloudScrollXLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
291 break;
292 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
293 idx++;
294 wl.cloudScrollY = (float)rules.GetLSLFloatItem(idx);
295 break;
296 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
297 idx++;
298 wl.cloudScrollYLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
299 break;
300 case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
301 idx++;
302 iV = rules.GetVector3Item(idx);
303 wl.cloudDetailXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
304 break;
305 case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
306 idx++;
307 wl.densityMultiplier = (float)rules.GetLSLFloatItem(idx);
308 break;
309 case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
310 idx++;
311 wl.distanceMultiplier = (float)rules.GetLSLFloatItem(idx);
312 break;
313 case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
314 idx++;
315 wl.drawClassicClouds = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
316 break;
317 case (int)ScriptBaseClass.WL_EAST_ANGLE:
318 idx++;
319 wl.eastAngle = (float)rules.GetLSLFloatItem(idx);
320 break;
321 case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
322 idx++;
323 wl.fresnelOffset = (float)rules.GetLSLFloatItem(idx);
324 break;
325 case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
326 idx++;
327 wl.fresnelScale = (float)rules.GetLSLFloatItem(idx);
328 break;
329 case (int)ScriptBaseClass.WL_HAZE_DENSITY:
330 idx++;
331 wl.hazeDensity = (float)rules.GetLSLFloatItem(idx);
332 break;
333 case (int)ScriptBaseClass.WL_HAZE_HORIZON:
334 idx++;
335 wl.hazeHorizon = (float)rules.GetLSLFloatItem(idx);
336 break;
337 case (int)ScriptBaseClass.WL_HORIZON:
338 idx++;
339 iQ = rules.GetQuaternionItem(idx);
340 wl.horizon = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
341 break;
342 case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
343 idx++;
344 iV = rules.GetVector3Item(idx);
345 wl.littleWaveDirection = new Vector2((float)iV.x, (float)iV.y);
346 break;
347 case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
348 idx++;
349 wl.maxAltitude = (ushort)rules.GetLSLIntegerItem(idx).value;
350 break;
351 case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
352 idx++;
353 wl.normalMapTexture = new UUID(rules.GetLSLStringItem(idx).m_string);
354 break;
355 case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
356 idx++;
357 iV = rules.GetVector3Item(idx);
358 wl.reflectionWaveletScale = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
359 break;
360 case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
361 idx++;
362 wl.refractScaleAbove = (float)rules.GetLSLFloatItem(idx);
363 break;
364 case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
365 idx++;
366 wl.refractScaleBelow = (float)rules.GetLSLFloatItem(idx);
367 break;
368 case (int)ScriptBaseClass.WL_SCENE_GAMMA:
369 idx++;
370 wl.sceneGamma = (float)rules.GetLSLFloatItem(idx);
371 break;
372 case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
373 idx++;
374 wl.starBrightness = (float)rules.GetLSLFloatItem(idx);
375 break;
376 case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
377 idx++;
378 wl.sunGlowFocus = (float)rules.GetLSLFloatItem(idx);
379 break;
380 case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
381 idx++;
382 wl.sunGlowSize = (float)rules.GetLSLFloatItem(idx);
383 break;
384 case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
385 idx++;
386 iQ = rules.GetQuaternionItem(idx);
387 wl.sunMoonColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
388 break;
389 case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
390 idx++;
391 wl.underwaterFogModifier = (float)rules.GetLSLFloatItem(idx);
392 break;
393 case (int)ScriptBaseClass.WL_WATER_COLOR:
394 idx++;
395 iV = rules.GetVector3Item(idx);
396 wl.waterColor = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
397 break;
398 case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
399 idx++;
400 wl.waterFogDensityExponent = (float)rules.GetLSLFloatItem(idx);
401 break;
402 }
403 idx++;
404 }
405 return wl;
406 }
407 /// <summary>
408 /// Set the current Windlight scene
409 /// </summary>
410 /// <param name="rules"></param>
411 /// <returns>success: true or false</returns>
412 public int cmSetWindlightScene(LSL_List rules)
413 {
414 if (!m_CMFunctionsEnabled)
415 {
416 CMShoutError("Careminster functions are not enabled.");
417 return 0;
418 }
419 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200)
420 {
421 CMShoutError("cmSetWindlightScene can only be used by estate managers or owners.");
422 return 0;
423 }
424 int success = 0;
425 m_host.AddScriptLPS(1);
426 if (Meta7WindlightModule.EnableWindlight)
427 {
428 RegionMeta7WindlightData wl = getWindlightProfileFromRules(rules);
429 m_host.ParentGroup.Scene.StoreWindlightProfile(wl);
430 success = 1;
431 }
432 else
433 {
434 CMShoutError("Windlight module is disabled");
435 return 0;
436 }
437 return success;
438 }
439 /// <summary>
440 /// Set the current Windlight scene to a target avatar
441 /// </summary>
442 /// <param name="rules"></param>
443 /// <returns>success: true or false</returns>
444 public int cmSetWindlightSceneTargeted(LSL_List rules, LSL_Key target)
445 {
446 if (!m_CMFunctionsEnabled)
447 {
448 CMShoutError("Careminster functions are not enabled.");
449 return 0;
450 }
451 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200)
452 {
453 CMShoutError("cmSetWindlightSceneTargeted can only be used by estate managers or owners.");
454 return 0;
455 }
456 int success = 0;
457 m_host.AddScriptLPS(1);
458 if (Meta7WindlightModule.EnableWindlight)
459 {
460 RegionMeta7WindlightData wl = getWindlightProfileFromRules(rules);
461 World.EventManager.TriggerOnSendNewWindlightProfileTargeted(wl, new UUID(target.m_string));
462 success = 1;
463 }
464 else
465 {
466 CMShoutError("Windlight module is disabled");
467 return 0;
468 }
469 return success;
470 }
471
472 }
473}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 39b597e..76c79da 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);
@@ -218,7 +221,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
218 221
219 public List<SceneObjectPart> GetLinkParts(int linkType) 222 public List<SceneObjectPart> GetLinkParts(int linkType)
220 { 223 {
221 List<SceneObjectPart> ret = new List<SceneObjectPart>(); 224 List<SceneObjectPart> ret = new List<SceneObjectPart>();
225 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
226 return ret;
222 ret.Add(m_host); 227 ret.Add(m_host);
223 228
224 switch (linkType) 229 switch (linkType)
@@ -272,40 +277,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
272 protected UUID InventorySelf() 277 protected UUID InventorySelf()
273 { 278 {
274 UUID invItemID = new UUID(); 279 UUID invItemID = new UUID();
275 280 bool unlock = false;
276 lock (m_host.TaskInventory) 281 if (!m_host.TaskInventory.IsReadLockedByMe())
282 {
283 m_host.TaskInventory.LockItemsForRead(true);
284 unlock = true;
285 }
286 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
277 { 287 {
278 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 288 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
279 { 289 {
280 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID) 290 invItemID = inv.Key;
281 { 291 break;
282 invItemID = inv.Key;
283 break;
284 }
285 } 292 }
286 } 293 }
287 294 if (unlock)
295 {
296 m_host.TaskInventory.LockItemsForRead(false);
297 }
288 return invItemID; 298 return invItemID;
289 } 299 }
290 300
291 protected UUID InventoryKey(string name, int type) 301 protected UUID InventoryKey(string name, int type)
292 { 302 {
293 m_host.AddScriptLPS(1); 303 m_host.AddScriptLPS(1);
294 304 m_host.TaskInventory.LockItemsForRead(true);
295 lock (m_host.TaskInventory) 305
306 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
296 { 307 {
297 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 308 if (inv.Value.Name == name)
298 { 309 {
299 if (inv.Value.Name == name) 310 m_host.TaskInventory.LockItemsForRead(false);
311
312 if (inv.Value.Type != type)
300 { 313 {
301 if (inv.Value.Type != type) 314 return UUID.Zero;
302 return UUID.Zero;
303
304 return inv.Value.AssetID;
305 } 315 }
316
317 return inv.Value.AssetID;
306 } 318 }
307 } 319 }
308 320
321 m_host.TaskInventory.LockItemsForRead(false);
309 return UUID.Zero; 322 return UUID.Zero;
310 } 323 }
311 324
@@ -313,17 +326,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
313 { 326 {
314 m_host.AddScriptLPS(1); 327 m_host.AddScriptLPS(1);
315 328
316 lock (m_host.TaskInventory) 329
330 m_host.TaskInventory.LockItemsForRead(true);
331
332 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
317 { 333 {
318 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 334 if (inv.Value.Name == name)
319 { 335 {
320 if (inv.Value.Name == name) 336 m_host.TaskInventory.LockItemsForRead(false);
321 { 337 return inv.Value.AssetID;
322 return inv.Value.AssetID;
323 }
324 } 338 }
325 } 339 }
326 340
341 m_host.TaskInventory.LockItemsForRead(false);
342
343
327 return UUID.Zero; 344 return UUID.Zero;
328 } 345 }
329 346
@@ -1121,7 +1138,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1121 } 1138 }
1122 1139
1123 public void llSetStatus(int status, int value) 1140 public void llSetStatus(int status, int value)
1124 { 1141 {
1142 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
1143 return;
1125 m_host.AddScriptLPS(1); 1144 m_host.AddScriptLPS(1);
1126 1145
1127 int statusrotationaxis = 0; 1146 int statusrotationaxis = 0;
@@ -1275,7 +1294,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1275 } 1294 }
1276 1295
1277 protected void SetScale(SceneObjectPart part, LSL_Vector scale) 1296 protected void SetScale(SceneObjectPart part, LSL_Vector scale)
1278 { 1297 {
1279 // TODO: this needs to trigger a persistance save as well 1298 // TODO: this needs to trigger a persistance save as well
1280 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) 1299 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1281 return; 1300 return;
@@ -1334,7 +1353,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1334 } 1353 }
1335 1354
1336 protected void SetColor(SceneObjectPart part, LSL_Vector color, int face) 1355 protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
1337 { 1356 {
1357 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1358 return;
1359
1338 Primitive.TextureEntry tex = part.Shape.Textures; 1360 Primitive.TextureEntry tex = part.Shape.Textures;
1339 Color4 texcolor; 1361 Color4 texcolor;
1340 if (face >= 0 && face < GetNumberOfSides(part)) 1362 if (face >= 0 && face < GetNumberOfSides(part))
@@ -1371,7 +1393,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1371 } 1393 }
1372 1394
1373 public void SetTexGen(SceneObjectPart part, int face,int style) 1395 public void SetTexGen(SceneObjectPart part, int face,int style)
1374 { 1396 {
1397 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1398 return;
1399
1375 Primitive.TextureEntry tex = part.Shape.Textures; 1400 Primitive.TextureEntry tex = part.Shape.Textures;
1376 MappingType textype; 1401 MappingType textype;
1377 textype = MappingType.Default; 1402 textype = MappingType.Default;
@@ -1401,7 +1426,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1401 } 1426 }
1402 1427
1403 public void SetGlow(SceneObjectPart part, int face, float glow) 1428 public void SetGlow(SceneObjectPart part, int face, float glow)
1404 { 1429 {
1430 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1431 return;
1432
1405 Primitive.TextureEntry tex = part.Shape.Textures; 1433 Primitive.TextureEntry tex = part.Shape.Textures;
1406 if (face >= 0 && face < GetNumberOfSides(part)) 1434 if (face >= 0 && face < GetNumberOfSides(part))
1407 { 1435 {
@@ -1426,7 +1454,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1426 } 1454 }
1427 1455
1428 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump) 1456 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
1429 { 1457 {
1458 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1459 return;
1430 1460
1431 Shininess sval = new Shininess(); 1461 Shininess sval = new Shininess();
1432 1462
@@ -1476,7 +1506,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1476 } 1506 }
1477 1507
1478 public void SetFullBright(SceneObjectPart part, int face, bool bright) 1508 public void SetFullBright(SceneObjectPart part, int face, bool bright)
1479 { 1509 {
1510 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1511 return;
1512
1480 Primitive.TextureEntry tex = part.Shape.Textures; 1513 Primitive.TextureEntry tex = part.Shape.Textures;
1481 if (face >= 0 && face < GetNumberOfSides(part)) 1514 if (face >= 0 && face < GetNumberOfSides(part))
1482 { 1515 {
@@ -1543,7 +1576,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1543 } 1576 }
1544 1577
1545 protected void SetAlpha(SceneObjectPart part, double alpha, int face) 1578 protected void SetAlpha(SceneObjectPart part, double alpha, int face)
1546 { 1579 {
1580 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1581 return;
1582
1547 Primitive.TextureEntry tex = part.Shape.Textures; 1583 Primitive.TextureEntry tex = part.Shape.Textures;
1548 Color4 texcolor; 1584 Color4 texcolor;
1549 if (face >= 0 && face < GetNumberOfSides(part)) 1585 if (face >= 0 && face < GetNumberOfSides(part))
@@ -1588,8 +1624,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1588 /// <param name="Force"></param> 1624 /// <param name="Force"></param>
1589 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction, 1625 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
1590 float wind, float tension, LSL_Vector Force) 1626 float wind, float tension, LSL_Vector Force)
1591 { 1627 {
1592 if (part == null) 1628 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1593 return; 1629 return;
1594 1630
1595 if (flexi) 1631 if (flexi)
@@ -1623,8 +1659,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1623 /// <param name="radius"></param> 1659 /// <param name="radius"></param>
1624 /// <param name="falloff"></param> 1660 /// <param name="falloff"></param>
1625 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff) 1661 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
1626 { 1662 {
1627 if (part == null) 1663 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1628 return; 1664 return;
1629 1665
1630 if (light) 1666 if (light)
@@ -1709,7 +1745,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1709 } 1745 }
1710 1746
1711 protected void SetTexture(SceneObjectPart part, string texture, int face) 1747 protected void SetTexture(SceneObjectPart part, string texture, int face)
1712 { 1748 {
1749 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1750 return;
1751
1713 UUID textureID=new UUID(); 1752 UUID textureID=new UUID();
1714 1753
1715 if (!UUID.TryParse(texture, out textureID)) 1754 if (!UUID.TryParse(texture, out textureID))
@@ -1754,7 +1793,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1754 } 1793 }
1755 1794
1756 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) 1795 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
1757 { 1796 {
1797 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1798 return;
1799
1758 Primitive.TextureEntry tex = part.Shape.Textures; 1800 Primitive.TextureEntry tex = part.Shape.Textures;
1759 if (face >= 0 && face < GetNumberOfSides(part)) 1801 if (face >= 0 && face < GetNumberOfSides(part))
1760 { 1802 {
@@ -1790,7 +1832,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1790 } 1832 }
1791 1833
1792 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) 1834 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
1793 { 1835 {
1836 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1837 return;
1838
1794 Primitive.TextureEntry tex = part.Shape.Textures; 1839 Primitive.TextureEntry tex = part.Shape.Textures;
1795 if (face >= 0 && face < GetNumberOfSides(part)) 1840 if (face >= 0 && face < GetNumberOfSides(part))
1796 { 1841 {
@@ -1826,7 +1871,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1826 } 1871 }
1827 1872
1828 protected void RotateTexture(SceneObjectPart part, double rotation, int face) 1873 protected void RotateTexture(SceneObjectPart part, double rotation, int face)
1829 { 1874 {
1875 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1876 return;
1877
1830 Primitive.TextureEntry tex = part.Shape.Textures; 1878 Primitive.TextureEntry tex = part.Shape.Textures;
1831 if (face >= 0 && face < GetNumberOfSides(part)) 1879 if (face >= 0 && face < GetNumberOfSides(part))
1832 { 1880 {
@@ -1896,7 +1944,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1896 } 1944 }
1897 1945
1898 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos) 1946 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos)
1899 { 1947 {
1948 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1949 return;
1950
1900 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos) 1951 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
1901 LSL_Vector currentPos = llGetLocalPos(); 1952 LSL_Vector currentPos = llGetLocalPos();
1902 1953
@@ -1990,7 +2041,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1990 } 2041 }
1991 2042
1992 protected void SetRot(SceneObjectPart part, Quaternion rot) 2043 protected void SetRot(SceneObjectPart part, Quaternion rot)
1993 { 2044 {
2045 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2046 return;
2047
1994 part.UpdateRotation(rot); 2048 part.UpdateRotation(rot);
1995 // Update rotation does not move the object in the physics scene if it's a linkset. 2049 // Update rotation does not move the object in the physics scene if it's a linkset.
1996 2050
@@ -2555,12 +2609,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2555 2609
2556 m_host.AddScriptLPS(1); 2610 m_host.AddScriptLPS(1);
2557 2611
2612 m_host.TaskInventory.LockItemsForRead(true);
2558 TaskInventoryItem item = m_host.TaskInventory[invItemID]; 2613 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2559 2614 m_host.TaskInventory.LockItemsForRead(false);
2560 lock (m_host.TaskInventory)
2561 {
2562 item = m_host.TaskInventory[invItemID];
2563 }
2564 2615
2565 if (item.PermsGranter == UUID.Zero) 2616 if (item.PermsGranter == UUID.Zero)
2566 return 0; 2617 return 0;
@@ -2635,6 +2686,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2635 if (dist > m_ScriptDistanceFactor * 10.0f) 2686 if (dist > m_ScriptDistanceFactor * 10.0f)
2636 return; 2687 return;
2637 2688
2689 //Clone is thread-safe
2638 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 2690 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
2639 2691
2640 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory) 2692 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory)
@@ -2720,6 +2772,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2720 // Orient the object to the angle calculated 2772 // Orient the object to the angle calculated
2721 llSetRot(rot); 2773 llSetRot(rot);
2722 } 2774 }
2775
2776 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
2777 {
2778 m_host.AddScriptLPS(1);
2779// NotImplemented("llRotLookAt");
2780 m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping);
2781
2782 }
2723 2783
2724 public void llStopLookAt() 2784 public void llStopLookAt()
2725 { 2785 {
@@ -2767,13 +2827,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2767 { 2827 {
2768 TaskInventoryItem item; 2828 TaskInventoryItem item;
2769 2829
2770 lock (m_host.TaskInventory) 2830 m_host.TaskInventory.LockItemsForRead(true);
2831 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2771 { 2832 {
2772 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 2833 m_host.TaskInventory.LockItemsForRead(false);
2773 return; 2834 return;
2774 else
2775 item = m_host.TaskInventory[InventorySelf()];
2776 } 2835 }
2836 else
2837 {
2838 item = m_host.TaskInventory[InventorySelf()];
2839 }
2840 m_host.TaskInventory.LockItemsForRead(false);
2777 2841
2778 if (item.PermsGranter != UUID.Zero) 2842 if (item.PermsGranter != UUID.Zero)
2779 { 2843 {
@@ -2795,13 +2859,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2795 { 2859 {
2796 TaskInventoryItem item; 2860 TaskInventoryItem item;
2797 2861
2862 m_host.TaskInventory.LockItemsForRead(true);
2798 lock (m_host.TaskInventory) 2863 lock (m_host.TaskInventory)
2799 { 2864 {
2865
2800 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 2866 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2867 {
2868 m_host.TaskInventory.LockItemsForRead(false);
2801 return; 2869 return;
2870 }
2802 else 2871 else
2872 {
2803 item = m_host.TaskInventory[InventorySelf()]; 2873 item = m_host.TaskInventory[InventorySelf()];
2874 }
2804 } 2875 }
2876 m_host.TaskInventory.LockItemsForRead(false);
2805 2877
2806 m_host.AddScriptLPS(1); 2878 m_host.AddScriptLPS(1);
2807 2879
@@ -2838,13 +2910,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2838 2910
2839 TaskInventoryItem item; 2911 TaskInventoryItem item;
2840 2912
2841 lock (m_host.TaskInventory) 2913 m_host.TaskInventory.LockItemsForRead(true);
2914
2915 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2842 { 2916 {
2843 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 2917 m_host.TaskInventory.LockItemsForRead(false);
2844 return; 2918 return;
2845 else
2846 item = m_host.TaskInventory[InventorySelf()];
2847 } 2919 }
2920 else
2921 {
2922 item = m_host.TaskInventory[InventorySelf()];
2923 }
2924
2925 m_host.TaskInventory.LockItemsForRead(false);
2848 2926
2849 if (item.PermsGranter != m_host.OwnerID) 2927 if (item.PermsGranter != m_host.OwnerID)
2850 return; 2928 return;
@@ -2870,13 +2948,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2870 2948
2871 TaskInventoryItem item; 2949 TaskInventoryItem item;
2872 2950
2873 lock (m_host.TaskInventory) 2951 m_host.TaskInventory.LockItemsForRead(true);
2952
2953 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2874 { 2954 {
2875 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 2955 m_host.TaskInventory.LockItemsForRead(false);
2876 return; 2956 return;
2877 else
2878 item = m_host.TaskInventory[InventorySelf()];
2879 } 2957 }
2958 else
2959 {
2960 item = m_host.TaskInventory[InventorySelf()];
2961 }
2962 m_host.TaskInventory.LockItemsForRead(false);
2963
2880 2964
2881 if (item.PermsGranter != m_host.OwnerID) 2965 if (item.PermsGranter != m_host.OwnerID)
2882 return; 2966 return;
@@ -2912,8 +2996,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2912 return m_host.OwnerID.ToString(); 2996 return m_host.OwnerID.ToString();
2913 } 2997 }
2914 2998
2999 [DebuggerNonUserCode]
2915 public void llInstantMessage(string user, string message) 3000 public void llInstantMessage(string user, string message)
2916 { 3001 {
3002 UUID result;
3003 if (!UUID.TryParse(user, out result))
3004 {
3005 throw new Exception(String.Format("An invalid key of '{0} was passed to llInstantMessage", user));
3006 return;
3007 }
3008
3009
2917 m_host.AddScriptLPS(1); 3010 m_host.AddScriptLPS(1);
2918 3011
2919 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. 3012 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
@@ -2928,7 +3021,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2928 UUID friendTransactionID = UUID.Random(); 3021 UUID friendTransactionID = UUID.Random();
2929 3022
2930 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 3023 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
2931 3024
2932 GridInstantMessage msg = new GridInstantMessage(); 3025 GridInstantMessage msg = new GridInstantMessage();
2933 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; 3026 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
2934 msg.toAgentID = new Guid(user); // toAgentID.Guid; 3027 msg.toAgentID = new Guid(user); // toAgentID.Guid;
@@ -3077,13 +3170,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3077 m_host.AddScriptLPS(1); 3170 m_host.AddScriptLPS(1);
3078 } 3171 }
3079 3172
3080 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3081 {
3082 m_host.AddScriptLPS(1);
3083// NotImplemented("llRotLookAt");
3084 m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping);
3085 }
3086
3087 public LSL_Integer llStringLength(string str) 3173 public LSL_Integer llStringLength(string str)
3088 { 3174 {
3089 m_host.AddScriptLPS(1); 3175 m_host.AddScriptLPS(1);
@@ -3107,14 +3193,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3107 3193
3108 TaskInventoryItem item; 3194 TaskInventoryItem item;
3109 3195
3110 lock (m_host.TaskInventory) 3196 m_host.TaskInventory.LockItemsForRead(true);
3197 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3111 { 3198 {
3112 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3199 m_host.TaskInventory.LockItemsForRead(false);
3113 return; 3200 return;
3114 else
3115 item = m_host.TaskInventory[InventorySelf()];
3116 } 3201 }
3117 3202 else
3203 {
3204 item = m_host.TaskInventory[InventorySelf()];
3205 }
3206 m_host.TaskInventory.LockItemsForRead(false);
3118 if (item.PermsGranter == UUID.Zero) 3207 if (item.PermsGranter == UUID.Zero)
3119 return; 3208 return;
3120 3209
@@ -3144,13 +3233,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3144 3233
3145 TaskInventoryItem item; 3234 TaskInventoryItem item;
3146 3235
3147 lock (m_host.TaskInventory) 3236 m_host.TaskInventory.LockItemsForRead(true);
3237 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3148 { 3238 {
3149 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3239 m_host.TaskInventory.LockItemsForRead(false);
3150 return; 3240 return;
3151 else
3152 item = m_host.TaskInventory[InventorySelf()];
3153 } 3241 }
3242 else
3243 {
3244 item = m_host.TaskInventory[InventorySelf()];
3245 }
3246 m_host.TaskInventory.LockItemsForRead(false);
3247
3154 3248
3155 if (item.PermsGranter == UUID.Zero) 3249 if (item.PermsGranter == UUID.Zero)
3156 return; 3250 return;
@@ -3223,10 +3317,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3223 3317
3224 TaskInventoryItem item; 3318 TaskInventoryItem item;
3225 3319
3226 lock (m_host.TaskInventory) 3320
3321 m_host.TaskInventory.LockItemsForRead(true);
3322 if (!m_host.TaskInventory.ContainsKey(invItemID))
3323 {
3324 m_host.TaskInventory.LockItemsForRead(false);
3325 return;
3326 }
3327 else
3227 { 3328 {
3228 item = m_host.TaskInventory[invItemID]; 3329 item = m_host.TaskInventory[invItemID];
3229 } 3330 }
3331 m_host.TaskInventory.LockItemsForRead(false);
3230 3332
3231 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3333 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3232 { 3334 {
@@ -3258,11 +3360,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3258 3360
3259 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3361 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3260 { 3362 {
3261 lock (m_host.TaskInventory) 3363 m_host.TaskInventory.LockItemsForWrite(true);
3262 { 3364 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3263 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3365 m_host.TaskInventory[invItemID].PermsMask = perm;
3264 m_host.TaskInventory[invItemID].PermsMask = perm; 3366 m_host.TaskInventory.LockItemsForWrite(false);
3265 }
3266 3367
3267 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3368 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3268 "run_time_permissions", new Object[] { 3369 "run_time_permissions", new Object[] {
@@ -3282,11 +3383,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3282 3383
3283 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3384 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3284 { 3385 {
3285 lock (m_host.TaskInventory) 3386 m_host.TaskInventory.LockItemsForWrite(true);
3286 { 3387 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3287 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3388 m_host.TaskInventory[invItemID].PermsMask = perm;
3288 m_host.TaskInventory[invItemID].PermsMask = perm; 3389 m_host.TaskInventory.LockItemsForWrite(false);
3289 }
3290 3390
3291 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3391 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3292 "run_time_permissions", new Object[] { 3392 "run_time_permissions", new Object[] {
@@ -3307,11 +3407,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3307 3407
3308 if (!m_waitingForScriptAnswer) 3408 if (!m_waitingForScriptAnswer)
3309 { 3409 {
3310 lock (m_host.TaskInventory) 3410 m_host.TaskInventory.LockItemsForWrite(true);
3311 { 3411 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3312 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3412 m_host.TaskInventory[invItemID].PermsMask = 0;
3313 m_host.TaskInventory[invItemID].PermsMask = 0; 3413 m_host.TaskInventory.LockItemsForWrite(false);
3314 }
3315 3414
3316 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3415 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3317 m_waitingForScriptAnswer=true; 3416 m_waitingForScriptAnswer=true;
@@ -3346,10 +3445,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3346 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3445 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3347 llReleaseControls(); 3446 llReleaseControls();
3348 3447
3349 lock (m_host.TaskInventory) 3448
3350 { 3449 m_host.TaskInventory.LockItemsForWrite(true);
3351 m_host.TaskInventory[invItemID].PermsMask = answer; 3450 m_host.TaskInventory[invItemID].PermsMask = answer;
3352 } 3451 m_host.TaskInventory.LockItemsForWrite(false);
3452
3353 3453
3354 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3454 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3355 "run_time_permissions", new Object[] { 3455 "run_time_permissions", new Object[] {
@@ -3361,16 +3461,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3361 { 3461 {
3362 m_host.AddScriptLPS(1); 3462 m_host.AddScriptLPS(1);
3363 3463
3364 lock (m_host.TaskInventory) 3464 m_host.TaskInventory.LockItemsForRead(true);
3465
3466 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3365 { 3467 {
3366 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3468 if (item.Type == 10 && item.ItemID == m_itemID)
3367 { 3469 {
3368 if (item.Type == 10 && item.ItemID == m_itemID) 3470 m_host.TaskInventory.LockItemsForRead(false);
3369 { 3471 return item.PermsGranter.ToString();
3370 return item.PermsGranter.ToString();
3371 }
3372 } 3472 }
3373 } 3473 }
3474 m_host.TaskInventory.LockItemsForRead(false);
3374 3475
3375 return UUID.Zero.ToString(); 3476 return UUID.Zero.ToString();
3376 } 3477 }
@@ -3379,19 +3480,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3379 { 3480 {
3380 m_host.AddScriptLPS(1); 3481 m_host.AddScriptLPS(1);
3381 3482
3382 lock (m_host.TaskInventory) 3483 m_host.TaskInventory.LockItemsForRead(true);
3484
3485 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3383 { 3486 {
3384 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3487 if (item.Type == 10 && item.ItemID == m_itemID)
3385 { 3488 {
3386 if (item.Type == 10 && item.ItemID == m_itemID) 3489 int perms = item.PermsMask;
3387 { 3490 if (m_automaticLinkPermission)
3388 int perms = item.PermsMask; 3491 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3389 if (m_automaticLinkPermission) 3492 m_host.TaskInventory.LockItemsForRead(false);
3390 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; 3493 return perms;
3391 return perms;
3392 }
3393 } 3494 }
3394 } 3495 }
3496 m_host.TaskInventory.LockItemsForRead(false);
3395 3497
3396 return 0; 3498 return 0;
3397 } 3499 }
@@ -3424,11 +3526,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3424 UUID invItemID = InventorySelf(); 3526 UUID invItemID = InventorySelf();
3425 3527
3426 TaskInventoryItem item; 3528 TaskInventoryItem item;
3427 lock (m_host.TaskInventory) 3529 m_host.TaskInventory.LockItemsForRead(true);
3428 { 3530 item = m_host.TaskInventory[invItemID];
3429 item = m_host.TaskInventory[invItemID]; 3531 m_host.TaskInventory.LockItemsForRead(false);
3430 } 3532
3431
3432 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3533 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3433 && !m_automaticLinkPermission) 3534 && !m_automaticLinkPermission)
3434 { 3535 {
@@ -3481,16 +3582,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3481 m_host.AddScriptLPS(1); 3582 m_host.AddScriptLPS(1);
3482 UUID invItemID = InventorySelf(); 3583 UUID invItemID = InventorySelf();
3483 3584
3484 lock (m_host.TaskInventory) 3585 m_host.TaskInventory.LockItemsForRead(true);
3485 {
3486 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3586 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3487 && !m_automaticLinkPermission) 3587 && !m_automaticLinkPermission)
3488 { 3588 {
3489 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3589 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
3590 m_host.TaskInventory.LockItemsForRead(false);
3490 return; 3591 return;
3491 } 3592 }
3492 } 3593 m_host.TaskInventory.LockItemsForRead(false);
3493 3594
3494 if (linknum < ScriptBaseClass.LINK_THIS) 3595 if (linknum < ScriptBaseClass.LINK_THIS)
3495 return; 3596 return;
3496 3597
@@ -3667,17 +3768,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3667 m_host.AddScriptLPS(1); 3768 m_host.AddScriptLPS(1);
3668 int count = 0; 3769 int count = 0;
3669 3770
3670 lock (m_host.TaskInventory) 3771 m_host.TaskInventory.LockItemsForRead(true);
3772 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3671 { 3773 {
3672 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 3774 if (inv.Value.Type == type || type == -1)
3673 { 3775 {
3674 if (inv.Value.Type == type || type == -1) 3776 count = count + 1;
3675 {
3676 count = count + 1;
3677 }
3678 } 3777 }
3679 } 3778 }
3680 3779
3780 m_host.TaskInventory.LockItemsForRead(false);
3681 return count; 3781 return count;
3682 } 3782 }
3683 3783
@@ -3686,16 +3786,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3686 m_host.AddScriptLPS(1); 3786 m_host.AddScriptLPS(1);
3687 ArrayList keys = new ArrayList(); 3787 ArrayList keys = new ArrayList();
3688 3788
3689 lock (m_host.TaskInventory) 3789 m_host.TaskInventory.LockItemsForRead(true);
3790 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3690 { 3791 {
3691 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 3792 if (inv.Value.Type == type || type == -1)
3692 { 3793 {
3693 if (inv.Value.Type == type || type == -1) 3794 keys.Add(inv.Value.Name);
3694 {
3695 keys.Add(inv.Value.Name);
3696 }
3697 } 3795 }
3698 } 3796 }
3797 m_host.TaskInventory.LockItemsForRead(false);
3699 3798
3700 if (keys.Count == 0) 3799 if (keys.Count == 0)
3701 { 3800 {
@@ -3732,20 +3831,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3732 } 3831 }
3733 3832
3734 // move the first object found with this inventory name 3833 // move the first object found with this inventory name
3735 lock (m_host.TaskInventory) 3834 m_host.TaskInventory.LockItemsForRead(true);
3835 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3736 { 3836 {
3737 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 3837 if (inv.Value.Name == inventory)
3738 { 3838 {
3739 if (inv.Value.Name == inventory) 3839 found = true;
3740 { 3840 objId = inv.Key;
3741 found = true; 3841 assetType = inv.Value.Type;
3742 objId = inv.Key; 3842 objName = inv.Value.Name;
3743 assetType = inv.Value.Type; 3843 break;
3744 objName = inv.Value.Name;
3745 break;
3746 }
3747 } 3844 }
3748 } 3845 }
3846 m_host.TaskInventory.LockItemsForRead(false);
3749 3847
3750 if (!found) 3848 if (!found)
3751 { 3849 {
@@ -3790,24 +3888,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3790 ScriptSleep(3000); 3888 ScriptSleep(3000);
3791 } 3889 }
3792 3890
3891 [DebuggerNonUserCode]
3793 public void llRemoveInventory(string name) 3892 public void llRemoveInventory(string name)
3794 { 3893 {
3795 m_host.AddScriptLPS(1); 3894 m_host.AddScriptLPS(1);
3796 3895
3797 lock (m_host.TaskInventory) 3896 m_host.TaskInventory.LockItemsForRead(true);
3897 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3798 { 3898 {
3799 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3899 if (item.Name == name)
3800 { 3900 {
3801 if (item.Name == name) 3901 if (item.ItemID == m_itemID)
3802 { 3902 throw new ScriptDeleteException();
3803 if (item.ItemID == m_itemID) 3903 else
3804 throw new ScriptDeleteException(); 3904 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3805 else 3905
3806 m_host.Inventory.RemoveInventoryItem(item.ItemID); 3906 m_host.TaskInventory.LockItemsForRead(false);
3807 return; 3907 return;
3808 }
3809 } 3908 }
3810 } 3909 }
3910 m_host.TaskInventory.LockItemsForRead(false);
3811 } 3911 }
3812 3912
3813 public void llSetText(string text, LSL_Vector color, double alpha) 3913 public void llSetText(string text, LSL_Vector color, double alpha)
@@ -3897,6 +3997,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3897 { 3997 {
3898 m_host.AddScriptLPS(1); 3998 m_host.AddScriptLPS(1);
3899 3999
4000 //Clone is thread safe
3900 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 4001 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
3901 4002
3902 foreach (TaskInventoryItem item in itemDictionary.Values) 4003 foreach (TaskInventoryItem item in itemDictionary.Values)
@@ -3987,17 +4088,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3987 UUID soundId = UUID.Zero; 4088 UUID soundId = UUID.Zero;
3988 if (!UUID.TryParse(impact_sound, out soundId)) 4089 if (!UUID.TryParse(impact_sound, out soundId))
3989 { 4090 {
3990 lock (m_host.TaskInventory) 4091 m_host.TaskInventory.LockItemsForRead(true);
4092 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3991 { 4093 {
3992 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4094 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
3993 { 4095 {
3994 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 4096 soundId = item.AssetID;
3995 { 4097 break;
3996 soundId = item.AssetID;
3997 break;
3998 }
3999 } 4098 }
4000 } 4099 }
4100 m_host.TaskInventory.LockItemsForRead(false);
4001 } 4101 }
4002 m_host.CollisionSound = soundId; 4102 m_host.CollisionSound = soundId;
4003 m_host.CollisionSoundVolume = (float)impact_volume; 4103 m_host.CollisionSoundVolume = (float)impact_volume;
@@ -4043,6 +4143,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4043 UUID partItemID; 4143 UUID partItemID;
4044 foreach (SceneObjectPart part in parts) 4144 foreach (SceneObjectPart part in parts)
4045 { 4145 {
4146 //Clone is thread safe
4046 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); 4147 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
4047 4148
4048 foreach (TaskInventoryItem item in itemsDictionary.Values) 4149 foreach (TaskInventoryItem item in itemsDictionary.Values)
@@ -4257,17 +4358,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4257 4358
4258 m_host.AddScriptLPS(1); 4359 m_host.AddScriptLPS(1);
4259 4360
4260 lock (m_host.TaskInventory) 4361 m_host.TaskInventory.LockItemsForRead(true);
4362 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4261 { 4363 {
4262 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4364 if (item.Type == 10 && item.ItemID == m_itemID)
4263 { 4365 {
4264 if (item.Type == 10 && item.ItemID == m_itemID) 4366 result = item.Name!=null?item.Name:String.Empty;
4265 { 4367 break;
4266 result = item.Name!=null?item.Name:String.Empty;
4267 break;
4268 }
4269 } 4368 }
4270 } 4369 }
4370 m_host.TaskInventory.LockItemsForRead(false);
4271 4371
4272 return result; 4372 return result;
4273 } 4373 }
@@ -4525,23 +4625,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4525 { 4625 {
4526 m_host.AddScriptLPS(1); 4626 m_host.AddScriptLPS(1);
4527 4627
4528 lock (m_host.TaskInventory) 4628 m_host.TaskInventory.LockItemsForRead(true);
4629 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4529 { 4630 {
4530 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4631 if (inv.Value.Name == name)
4531 { 4632 {
4532 if (inv.Value.Name == name) 4633 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
4533 { 4634 {
4534 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) 4635 m_host.TaskInventory.LockItemsForRead(false);
4535 { 4636 return inv.Value.AssetID.ToString();
4536 return inv.Value.AssetID.ToString(); 4637 }
4537 } 4638 else
4538 else 4639 {
4539 { 4640 m_host.TaskInventory.LockItemsForRead(false);
4540 return UUID.Zero.ToString(); 4641 return UUID.Zero.ToString();
4541 }
4542 } 4642 }
4543 } 4643 }
4544 } 4644 }
4645 m_host.TaskInventory.LockItemsForRead(false);
4545 4646
4546 return UUID.Zero.ToString(); 4647 return UUID.Zero.ToString();
4547 } 4648 }
@@ -6037,14 +6138,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6037 6138
6038 protected UUID GetTaskInventoryItem(string name) 6139 protected UUID GetTaskInventoryItem(string name)
6039 { 6140 {
6040 lock (m_host.TaskInventory) 6141 m_host.TaskInventory.LockItemsForRead(true);
6142 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6041 { 6143 {
6042 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6144 if (inv.Value.Name == name)
6043 { 6145 {
6044 if (inv.Value.Name == name) 6146 m_host.TaskInventory.LockItemsForRead(false);
6045 return inv.Key; 6147 return inv.Key;
6046 } 6148 }
6047 } 6149 }
6150 m_host.TaskInventory.LockItemsForRead(false);
6048 6151
6049 return UUID.Zero; 6152 return UUID.Zero;
6050 } 6153 }
@@ -6360,22 +6463,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6360 } 6463 }
6361 6464
6362 // copy the first script found with this inventory name 6465 // copy the first script found with this inventory name
6363 lock (m_host.TaskInventory) 6466 m_host.TaskInventory.LockItemsForRead(true);
6467 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6364 { 6468 {
6365 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6469 if (inv.Value.Name == name)
6366 { 6470 {
6367 if (inv.Value.Name == name) 6471 // make sure the object is a script
6472 if (10 == inv.Value.Type)
6368 { 6473 {
6369 // make sure the object is a script 6474 found = true;
6370 if (10 == inv.Value.Type) 6475 srcId = inv.Key;
6371 { 6476 break;
6372 found = true;
6373 srcId = inv.Key;
6374 break;
6375 }
6376 } 6477 }
6377 } 6478 }
6378 } 6479 }
6480 m_host.TaskInventory.LockItemsForRead(false);
6379 6481
6380 if (!found) 6482 if (!found)
6381 { 6483 {
@@ -6457,8 +6559,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6457 } 6559 }
6458 6560
6459 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist) 6561 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist)
6460 { 6562 {
6461 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 6563 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6564 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6565 return shapeBlock;
6462 6566
6463 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && 6567 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
6464 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && 6568 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
@@ -6528,7 +6632,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6528 } 6632 }
6529 6633
6530 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge) 6634 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge)
6531 { 6635 {
6636 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6637 return;
6638
6532 ObjectShapePacket.ObjectDataBlock shapeBlock; 6639 ObjectShapePacket.ObjectDataBlock shapeBlock;
6533 6640
6534 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 6641 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6577,7 +6684,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6577 } 6684 }
6578 6685
6579 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge) 6686 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge)
6580 { 6687 {
6688 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6689 return;
6690
6581 ObjectShapePacket.ObjectDataBlock shapeBlock; 6691 ObjectShapePacket.ObjectDataBlock shapeBlock;
6582 6692
6583 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 6693 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6619,7 +6729,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6619 } 6729 }
6620 6730
6621 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector holesize, LSL_Vector topshear, LSL_Vector profilecut, LSL_Vector taper_a, float revolutions, float radiusoffset, float skew, byte fudge) 6731 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector holesize, LSL_Vector topshear, LSL_Vector profilecut, LSL_Vector taper_a, float revolutions, float radiusoffset, float skew, byte fudge)
6622 { 6732 {
6733 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6734 return;
6735
6623 ObjectShapePacket.ObjectDataBlock shapeBlock; 6736 ObjectShapePacket.ObjectDataBlock shapeBlock;
6624 6737
6625 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 6738 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6740,7 +6853,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6740 } 6853 }
6741 6854
6742 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type) 6855 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type)
6743 { 6856 {
6857 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6858 return;
6859
6744 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 6860 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6745 UUID sculptId; 6861 UUID sculptId;
6746 6862
@@ -6774,14 +6890,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6774 } 6890 }
6775 6891
6776 public void llSetPrimitiveParams(LSL_List rules) 6892 public void llSetPrimitiveParams(LSL_List rules)
6777 { 6893 {
6778 m_host.AddScriptLPS(1); 6894 m_host.AddScriptLPS(1);
6779 SetPrimParams(m_host, rules); 6895 SetPrimParams(m_host, rules);
6780 } 6896 }
6781 6897
6782 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) 6898 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
6783 { 6899 {
6784 m_host.AddScriptLPS(1); 6900 m_host.AddScriptLPS(1);
6785 6901
6786 List<SceneObjectPart> parts = GetLinkParts(linknumber); 6902 List<SceneObjectPart> parts = GetLinkParts(linknumber);
6787 6903
@@ -6790,7 +6906,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6790 } 6906 }
6791 6907
6792 protected void SetPrimParams(SceneObjectPart part, LSL_List rules) 6908 protected void SetPrimParams(SceneObjectPart part, LSL_List rules)
6793 { 6909 {
6910 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6911 return;
6912
6794 int idx = 0; 6913 int idx = 0;
6795 6914
6796 while (idx < rules.Length) 6915 while (idx < rules.Length)
@@ -8195,28 +8314,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8195 { 8314 {
8196 m_host.AddScriptLPS(1); 8315 m_host.AddScriptLPS(1);
8197 8316
8198 lock (m_host.TaskInventory) 8317 m_host.TaskInventory.LockItemsForRead(true);
8318 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8199 { 8319 {
8200 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 8320 if (inv.Value.Name == item)
8201 { 8321 {
8202 if (inv.Value.Name == item) 8322 m_host.TaskInventory.LockItemsForRead(false);
8323 switch (mask)
8203 { 8324 {
8204 switch (mask) 8325 case 0:
8205 { 8326 return (int)inv.Value.BasePermissions;
8206 case 0: 8327 case 1:
8207 return (int)inv.Value.BasePermissions; 8328 return (int)inv.Value.CurrentPermissions;
8208 case 1: 8329 case 2:
8209 return (int)inv.Value.CurrentPermissions; 8330 return (int)inv.Value.GroupPermissions;
8210 case 2: 8331 case 3:
8211 return (int)inv.Value.GroupPermissions; 8332 return (int)inv.Value.EveryonePermissions;
8212 case 3: 8333 case 4:
8213 return (int)inv.Value.EveryonePermissions; 8334 return (int)inv.Value.NextPermissions;
8214 case 4:
8215 return (int)inv.Value.NextPermissions;
8216 }
8217 } 8335 }
8218 } 8336 }
8219 } 8337 }
8338 m_host.TaskInventory.LockItemsForRead(false);
8220 8339
8221 return -1; 8340 return -1;
8222 } 8341 }
@@ -8231,16 +8350,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8231 { 8350 {
8232 m_host.AddScriptLPS(1); 8351 m_host.AddScriptLPS(1);
8233 8352
8234 lock (m_host.TaskInventory) 8353 m_host.TaskInventory.LockItemsForRead(true);
8354 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8235 { 8355 {
8236 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 8356 if (inv.Value.Name == item)
8237 { 8357 {
8238 if (inv.Value.Name == item) 8358 m_host.TaskInventory.LockItemsForRead(false);
8239 { 8359 return inv.Value.CreatorID.ToString();
8240 return inv.Value.CreatorID.ToString();
8241 }
8242 } 8360 }
8243 } 8361 }
8362 m_host.TaskInventory.LockItemsForRead(false);
8244 8363
8245 llSay(0, "No item name '" + item + "'"); 8364 llSay(0, "No item name '" + item + "'");
8246 8365
@@ -8764,16 +8883,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8764 { 8883 {
8765 m_host.AddScriptLPS(1); 8884 m_host.AddScriptLPS(1);
8766 8885
8767 lock (m_host.TaskInventory) 8886 m_host.TaskInventory.LockItemsForRead(true);
8887 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8768 { 8888 {
8769 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 8889 if (inv.Value.Name == name)
8770 { 8890 {
8771 if (inv.Value.Name == name) 8891 m_host.TaskInventory.LockItemsForRead(false);
8772 { 8892 return inv.Value.Type;
8773 return inv.Value.Type;
8774 }
8775 } 8893 }
8776 } 8894 }
8895 m_host.TaskInventory.LockItemsForRead(false);
8777 8896
8778 return -1; 8897 return -1;
8779 } 8898 }
@@ -8804,17 +8923,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8804 if (invItemID == UUID.Zero) 8923 if (invItemID == UUID.Zero)
8805 return new LSL_Vector(); 8924 return new LSL_Vector();
8806 8925
8807 lock (m_host.TaskInventory) 8926 m_host.TaskInventory.LockItemsForRead(true);
8927 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
8808 { 8928 {
8809 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 8929 m_host.TaskInventory.LockItemsForRead(false);
8810 return new LSL_Vector(); 8930 return new LSL_Vector();
8931 }
8811 8932
8812 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 8933 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
8813 { 8934 {
8814 ShoutError("No permissions to track the camera"); 8935 ShoutError("No permissions to track the camera");
8815 return new LSL_Vector(); 8936 m_host.TaskInventory.LockItemsForRead(false);
8816 } 8937 return new LSL_Vector();
8817 } 8938 }
8939 m_host.TaskInventory.LockItemsForRead(false);
8818 8940
8819 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 8941 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
8820 if (presence != null) 8942 if (presence != null)
@@ -8832,17 +8954,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8832 if (invItemID == UUID.Zero) 8954 if (invItemID == UUID.Zero)
8833 return new LSL_Rotation(); 8955 return new LSL_Rotation();
8834 8956
8835 lock (m_host.TaskInventory) 8957 m_host.TaskInventory.LockItemsForRead(true);
8958 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
8836 { 8959 {
8837 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 8960 m_host.TaskInventory.LockItemsForRead(false);
8838 return new LSL_Rotation(); 8961 return new LSL_Rotation();
8839
8840 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
8841 {
8842 ShoutError("No permissions to track the camera");
8843 return new LSL_Rotation();
8844 }
8845 } 8962 }
8963 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
8964 {
8965 ShoutError("No permissions to track the camera");
8966 m_host.TaskInventory.LockItemsForRead(false);
8967 return new LSL_Rotation();
8968 }
8969 m_host.TaskInventory.LockItemsForRead(false);
8846 8970
8847 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 8971 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
8848 if (presence != null) 8972 if (presence != null)
@@ -8992,14 +9116,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8992 if (objectID == UUID.Zero) return; 9116 if (objectID == UUID.Zero) return;
8993 9117
8994 UUID agentID; 9118 UUID agentID;
8995 lock (m_host.TaskInventory) 9119 m_host.TaskInventory.LockItemsForRead(true);
8996 { 9120 // we need the permission first, to know which avatar we want to set the camera for
8997 // we need the permission first, to know which avatar we want to set the camera for 9121 agentID = m_host.TaskInventory[invItemID].PermsGranter;
8998 agentID = m_host.TaskInventory[invItemID].PermsGranter;
8999 9122
9000 if (agentID == UUID.Zero) return; 9123 if (agentID == UUID.Zero)
9001 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 9124 {
9125 m_host.TaskInventory.LockItemsForRead(false);
9126 return;
9127 }
9128 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
9129 {
9130 m_host.TaskInventory.LockItemsForRead(false);
9131 return;
9002 } 9132 }
9133 m_host.TaskInventory.LockItemsForRead(false);
9003 9134
9004 ScenePresence presence = World.GetScenePresence(agentID); 9135 ScenePresence presence = World.GetScenePresence(agentID);
9005 9136
@@ -9049,12 +9180,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9049 9180
9050 // we need the permission first, to know which avatar we want to clear the camera for 9181 // we need the permission first, to know which avatar we want to clear the camera for
9051 UUID agentID; 9182 UUID agentID;
9052 lock (m_host.TaskInventory) 9183 m_host.TaskInventory.LockItemsForRead(true);
9184 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9185 if (agentID == UUID.Zero)
9053 { 9186 {
9054 agentID = m_host.TaskInventory[invItemID].PermsGranter; 9187 m_host.TaskInventory.LockItemsForRead(false);
9055 if (agentID == UUID.Zero) return; 9188 return;
9056 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 9189 }
9190 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
9191 {
9192 m_host.TaskInventory.LockItemsForRead(false);
9193 return;
9057 } 9194 }
9195 m_host.TaskInventory.LockItemsForRead(false);
9058 9196
9059 ScenePresence presence = World.GetScenePresence(agentID); 9197 ScenePresence presence = World.GetScenePresence(agentID);
9060 9198
@@ -9511,15 +9649,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9511 9649
9512 internal UUID ScriptByName(string name) 9650 internal UUID ScriptByName(string name)
9513 { 9651 {
9514 lock (m_host.TaskInventory) 9652 m_host.TaskInventory.LockItemsForRead(true);
9653
9654 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
9515 { 9655 {
9516 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 9656 if (item.Type == 10 && item.Name == name)
9517 { 9657 {
9518 if (item.Type == 10 && item.Name == name) 9658 m_host.TaskInventory.LockItemsForRead(false);
9519 return item.ItemID; 9659 return item.ItemID;
9520 } 9660 }
9521 } 9661 }
9522 9662
9663 m_host.TaskInventory.LockItemsForRead(false);
9664
9523 return UUID.Zero; 9665 return UUID.Zero;
9524 } 9666 }
9525 9667
@@ -9560,6 +9702,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9560 { 9702 {
9561 m_host.AddScriptLPS(1); 9703 m_host.AddScriptLPS(1);
9562 9704
9705 //Clone is thread safe
9563 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 9706 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
9564 9707
9565 UUID assetID = UUID.Zero; 9708 UUID assetID = UUID.Zero;
@@ -9622,6 +9765,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9622 { 9765 {
9623 m_host.AddScriptLPS(1); 9766 m_host.AddScriptLPS(1);
9624 9767
9768 //Clone is thread safe
9625 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 9769 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
9626 9770
9627 UUID assetID = UUID.Zero; 9771 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 d8b9159..a5be251 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/Implementation/Plugins/Timer.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
index eeb59d9..2fd33fe 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
@@ -109,25 +109,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
109 if (Timers.Count == 0) 109 if (Timers.Count == 0)
110 return; 110 return;
111 111
112 Dictionary<string, TimerClass>.ValueCollection tvals;
112 lock (TimerListLock) 113 lock (TimerListLock)
113 { 114 {
114 // Go through all timers 115 // Go through all timers
115 Dictionary<string, TimerClass>.ValueCollection tvals = Timers.Values; 116 tvals = Timers.Values;
116 foreach (TimerClass ts in tvals) 117 }
118
119 foreach (TimerClass ts in tvals)
120 {
121 // Time has passed?
122 if (ts.next < DateTime.Now.Ticks)
117 { 123 {
118 // Time has passed? 124 //m_log.Debug("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next);
119 if (ts.next < DateTime.Now.Ticks) 125 // Add it to queue
120 { 126 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
121 //m_log.Debug("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next); 127 new EventParams("timer", new Object[0],
122 // Add it to queue 128 new DetectParams[0]));
123 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID, 129 // set next interval
124 new EventParams("timer", new Object[0], 130
125 new DetectParams[0])); 131 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
126 // set next interval 132 ts.next = DateTime.Now.Ticks + ts.interval;
127
128 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
129 ts.next = DateTime.Now.Ticks + ts.interval;
130 }
131 } 133 }
132 } 134 }
133 } 135 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs
new file mode 100644
index 0000000..ef990a1
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs
@@ -0,0 +1,21 @@
1using System.Collections;
2using OpenSim.Region.ScriptEngine.Interfaces;
3
4using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
5using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
6using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
7using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
8using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
9using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
10using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
11
12namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
13{
14 public interface ICM_Api
15 {
16 // Windlight Functions
17 LSL_List cmGetWindlightScene(LSL_List rules);
18 int cmSetWindlightScene(LSL_List rules);
19 int cmSetWindlightSceneTargeted(LSL_List rules, key target);
20 }
21}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 60b8050..f5921e1 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -80,7 +80,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
80 // Avatar Info Commands 80 // Avatar Info Commands
81 string osGetAgentIP(string agent); 81 string osGetAgentIP(string agent);
82 LSL_List osGetAgents(); 82 LSL_List osGetAgents();
83 83
84 // Teleport commands 84 // Teleport commands
85 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 85 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
86 void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 86 void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Constants.cs
new file mode 100644
index 0000000..7b67fa3
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Constants.cs
@@ -0,0 +1,76 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
30using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
31using LSLInteger = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
32
33namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
34{
35 public partial class ScriptBaseClass
36 {
37 // Constants for cmWindlight*
38 public const int WL_WATER_COLOR = 0;
39 public const int WL_WATER_FOG_DENSITY_EXPONENT = 1;
40 public const int WL_UNDERWATER_FOG_MODIFIER = 2;
41 public const int WL_REFLECTION_WAVELET_SCALE = 3;
42 public const int WL_FRESNEL_SCALE = 4;
43 public const int WL_FRESNEL_OFFSET = 5;
44 public const int WL_REFRACT_SCALE_ABOVE = 6;
45 public const int WL_REFRACT_SCALE_BELOW = 7;
46 public const int WL_BLUR_MULTIPLIER = 8;
47 public const int WL_BIG_WAVE_DIRECTION = 9;
48 public const int WL_LITTLE_WAVE_DIRECTION = 10;
49 public const int WL_NORMAL_MAP_TEXTURE = 11;
50 public const int WL_HORIZON = 12;
51 public const int WL_HAZE_HORIZON = 13;
52 public const int WL_BLUE_DENSITY = 14;
53 public const int WL_HAZE_DENSITY = 15;
54 public const int WL_DENSITY_MULTIPLIER = 16;
55 public const int WL_DISTANCE_MULTIPLIER = 17;
56 public const int WL_MAX_ALTITUDE = 18;
57 public const int WL_SUN_MOON_COLOR = 19;
58 public const int WL_AMBIENT = 20;
59 public const int WL_EAST_ANGLE = 21;
60 public const int WL_SUN_GLOW_FOCUS = 22;
61 public const int WL_SUN_GLOW_SIZE = 23;
62 public const int WL_SCENE_GAMMA = 24;
63 public const int WL_STAR_BRIGHTNESS = 25;
64 public const int WL_CLOUD_COLOR = 26;
65 public const int WL_CLOUD_XY_DENSITY = 27;
66 public const int WL_CLOUD_COVERAGE = 28;
67 public const int WL_CLOUD_SCALE = 29;
68 public const int WL_CLOUD_DETAIL_XY_DENSITY = 30;
69 public const int WL_CLOUD_SCROLL_X = 31;
70 public const int WL_CLOUD_SCROLL_Y = 32;
71 public const int WL_CLOUD_SCROLL_Y_LOCK = 33;
72 public const int WL_CLOUD_SCROLL_X_LOCK = 34;
73 public const int WL_DRAW_CLASSIC_CLOUDS = 35;
74
75 }
76}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs
new file mode 100644
index 0000000..5bc3a88
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs
@@ -0,0 +1,76 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Runtime.Remoting.Lifetime;
30using System.Threading;
31using System.Reflection;
32using System.Collections;
33using System.Collections.Generic;
34using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.ScriptEngine.Interfaces;
37using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
38using integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
39using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
40using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
41using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
42using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
43using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
44using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
45using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
46
47namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
48{
49 public partial class ScriptBaseClass : MarshalByRefObject
50 {
51 public ICM_Api m_CM_Functions;
52
53 public void ApiTypeCM(IScriptApi api)
54 {
55 if (!(api is ICM_Api))
56 return;
57
58 m_CM_Functions = (ICM_Api)api;
59 }
60
61 public LSL_List cmGetWindlightScene(LSL_List rules)
62 {
63 return m_CM_Functions.cmGetWindlightScene(rules);
64 }
65
66 public int cmSetWindlightScene(LSL_List rules)
67 {
68 return m_CM_Functions.cmSetWindlightScene(rules);
69 }
70
71 public int cmSetWindlightSceneTargeted(LSL_List rules, key target)
72 {
73 return m_CM_Functions.cmSetWindlightSceneTargeted(rules, target);
74 }
75 }
76}
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/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp
index 98bbc68..23138ef 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp
@@ -17,6 +17,8 @@
17 <excludeFiles /> 17 <excludeFiles />
18 </DeploymentInformation> 18 </DeploymentInformation>
19 <Contents> 19 <Contents>
20 <File name="./CM_Constants.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
21 <File name="./CM_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
20 <File name="./Executor.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 22 <File name="./Executor.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
21 <File name="./LSL_Constants.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 23 <File name="./LSL_Constants.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
22 <File name="./LSL_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 24 <File name="./LSL_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
index edbbc2a..b138da3 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 d30d2dc..6ecafd4 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;
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 6dd94bb..d65107e 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -30,6 +30,7 @@ using System.IO;
30using System.Threading; 30using System.Threading;
31using System.Collections; 31using System.Collections;
32using System.Collections.Generic; 32using System.Collections.Generic;
33using System.Diagnostics; //for [DebuggerNonUserCode]
33using System.Security; 34using System.Security;
34using System.Security.Policy; 35using System.Security.Policy;
35using System.Reflection; 36using System.Reflection;
@@ -102,6 +103,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
102 private Dictionary<UUID, IScriptInstance> m_Scripts = 103 private Dictionary<UUID, IScriptInstance> m_Scripts =
103 new Dictionary<UUID, IScriptInstance>(); 104 new Dictionary<UUID, IScriptInstance>();
104 105
106 private OpenMetaverse.ReaderWriterLockSlim m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
107
105 // Maps the asset ID to the assembly 108 // Maps the asset ID to the assembly
106 109
107 private Dictionary<UUID, string> m_Assemblies = 110 private Dictionary<UUID, string> m_Assemblies =
@@ -123,6 +126,71 @@ namespace OpenSim.Region.ScriptEngine.XEngine
123 private ScriptCompileQueue m_CompileQueue = new ScriptCompileQueue(); 126 private ScriptCompileQueue m_CompileQueue = new ScriptCompileQueue();
124 IWorkItemResult m_CurrentCompile = null; 127 IWorkItemResult m_CurrentCompile = null;
125 128
129 private void lockScriptsForRead(bool locked)
130 {
131 if (locked)
132 {
133 if (m_scriptsLock.RecursiveReadCount > 0)
134 {
135 m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
136 m_scriptsLock.ExitReadLock();
137 }
138 if (m_scriptsLock.RecursiveWriteCount > 0)
139 {
140 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
141 m_scriptsLock.ExitWriteLock();
142 }
143
144 while (!m_scriptsLock.TryEnterReadLock(60000))
145 {
146 m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire READ lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
147 if (m_scriptsLock.IsWriteLockHeld)
148 {
149 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
150 }
151 }
152 }
153 else
154 {
155 if (m_scriptsLock.RecursiveReadCount > 0)
156 {
157 m_scriptsLock.ExitReadLock();
158 }
159 }
160 }
161 private void lockScriptsForWrite(bool locked)
162 {
163 if (locked)
164 {
165 if (m_scriptsLock.RecursiveReadCount > 0)
166 {
167 m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
168 m_scriptsLock.ExitReadLock();
169 }
170 if (m_scriptsLock.RecursiveWriteCount > 0)
171 {
172 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
173 m_scriptsLock.ExitWriteLock();
174 }
175
176 while (!m_scriptsLock.TryEnterWriteLock(60000))
177 {
178 m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire WRITE lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
179 if (m_scriptsLock.IsWriteLockHeld)
180 {
181 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
182 }
183 }
184 }
185 else
186 {
187 if (m_scriptsLock.RecursiveWriteCount > 0)
188 {
189 m_scriptsLock.ExitWriteLock();
190 }
191 }
192 }
193
126 public string ScriptEngineName 194 public string ScriptEngineName
127 { 195 {
128 get { return "XEngine"; } 196 get { return "XEngine"; }
@@ -262,43 +330,45 @@ namespace OpenSim.Region.ScriptEngine.XEngine
262 330
263 public void RemoveRegion(Scene scene) 331 public void RemoveRegion(Scene scene)
264 { 332 {
265 lock (m_Scripts) 333 lockScriptsForRead(true);
334 foreach (IScriptInstance instance in m_Scripts.Values)
266 { 335 {
267 foreach (IScriptInstance instance in m_Scripts.Values) 336 // Force a final state save
337 //
338 if (m_Assemblies.ContainsKey(instance.AssetID))
268 { 339 {
269 // Force a final state save 340 string assembly = m_Assemblies[instance.AssetID];
270 // 341 instance.SaveState(assembly);
271 if (m_Assemblies.ContainsKey(instance.AssetID)) 342 }
272 {
273 string assembly = m_Assemblies[instance.AssetID];
274 instance.SaveState(assembly);
275 }
276 343
277 // Clear the event queue and abort the instance thread 344 // Clear the event queue and abort the instance thread
278 // 345 //
279 instance.ClearQueue(); 346 instance.ClearQueue();
280 instance.Stop(0); 347 instance.Stop(0);
281 348
282 // Release events, timer, etc 349 // Release events, timer, etc
283 // 350 //
284 instance.DestroyScriptInstance(); 351 instance.DestroyScriptInstance();
285 352
286 // Unload scripts and app domains 353 // Unload scripts and app domains
287 // Must be done explicitly because they have infinite 354 // Must be done explicitly because they have infinite
288 // lifetime 355 // lifetime
289 // 356 //
290 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 357 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
291 if (m_DomainScripts[instance.AppDomain].Count == 0) 358 if (m_DomainScripts[instance.AppDomain].Count == 0)
292 { 359 {
293 m_DomainScripts.Remove(instance.AppDomain); 360 m_DomainScripts.Remove(instance.AppDomain);
294 UnloadAppDomain(instance.AppDomain); 361 UnloadAppDomain(instance.AppDomain);
295 }
296 } 362 }
297 m_Scripts.Clear();
298 m_PrimObjects.Clear();
299 m_Assemblies.Clear();
300 m_DomainScripts.Clear();
301 } 363 }
364 lockScriptsForRead(false);
365 lockScriptsForWrite(true);
366 m_Scripts.Clear();
367 lockScriptsForWrite(false);
368 m_PrimObjects.Clear();
369 m_Assemblies.Clear();
370 m_DomainScripts.Clear();
371
302 lock (m_ScriptEngines) 372 lock (m_ScriptEngines)
303 { 373 {
304 m_ScriptEngines.Remove(this); 374 m_ScriptEngines.Remove(this);
@@ -357,22 +427,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine
357 427
358 List<IScriptInstance> instances = new List<IScriptInstance>(); 428 List<IScriptInstance> instances = new List<IScriptInstance>();
359 429
360 lock (m_Scripts) 430 lockScriptsForRead(true);
361 { 431 foreach (IScriptInstance instance in m_Scripts.Values)
362 foreach (IScriptInstance instance in m_Scripts.Values)
363 instances.Add(instance); 432 instances.Add(instance);
364 } 433 lockScriptsForRead(false);
365 434
366 foreach (IScriptInstance i in instances) 435 foreach (IScriptInstance i in instances)
367 { 436 {
368 string assembly = String.Empty; 437 string assembly = String.Empty;
369 438
370 lock (m_Scripts) 439
371 {
372 if (!m_Assemblies.ContainsKey(i.AssetID)) 440 if (!m_Assemblies.ContainsKey(i.AssetID))
373 continue; 441 continue;
374 assembly = m_Assemblies[i.AssetID]; 442 assembly = m_Assemblies[i.AssetID];
375 } 443
376 444
377 i.SaveState(assembly); 445 i.SaveState(assembly);
378 } 446 }
@@ -684,172 +752,183 @@ namespace OpenSim.Region.ScriptEngine.XEngine
684 } 752 }
685 } 753 }
686 754
687 lock (m_Scripts) 755
756
757 ScriptInstance instance = null;
758 // Create the object record
759 lockScriptsForRead(true);
760 if ((!m_Scripts.ContainsKey(itemID)) ||
761 (m_Scripts[itemID].AssetID != assetID))
688 { 762 {
689 ScriptInstance instance = null; 763 lockScriptsForRead(false);
690 // Create the object record
691 764
692 if ((!m_Scripts.ContainsKey(itemID)) || 765 UUID appDomain = assetID;
693 (m_Scripts[itemID].AssetID != assetID))
694 {
695 UUID appDomain = assetID;
696 766
697 if (part.ParentGroup.IsAttachment) 767 if (part.ParentGroup.IsAttachment)
698 appDomain = part.ParentGroup.RootPart.UUID; 768 appDomain = part.ParentGroup.RootPart.UUID;
699 769
700 if (!m_AppDomains.ContainsKey(appDomain)) 770 if (!m_AppDomains.ContainsKey(appDomain))
771 {
772 try
701 { 773 {
702 try 774 AppDomainSetup appSetup = new AppDomainSetup();
703 { 775 // appSetup.ApplicationBase = Path.Combine(
704 AppDomainSetup appSetup = new AppDomainSetup(); 776 // "ScriptEngines",
705// appSetup.ApplicationBase = Path.Combine( 777 // m_Scene.RegionInfo.RegionID.ToString());
706// "ScriptEngines", 778
707// m_Scene.RegionInfo.RegionID.ToString()); 779 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
708 780 Evidence evidence = new Evidence(baseEvidence);
709 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; 781
710 Evidence evidence = new Evidence(baseEvidence); 782 AppDomain sandbox;
711 783 if (m_AppDomainLoading)
712 AppDomain sandbox; 784 sandbox = AppDomain.CreateDomain(
713 if (m_AppDomainLoading) 785 m_Scene.RegionInfo.RegionID.ToString(),
714 sandbox = AppDomain.CreateDomain( 786 evidence, appSetup);
715 m_Scene.RegionInfo.RegionID.ToString(), 787 else
716 evidence, appSetup); 788 sandbox = AppDomain.CurrentDomain;
717 else 789
718 sandbox = AppDomain.CurrentDomain; 790 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
719 791 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
720 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); 792 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet");
721 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); 793 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet);
722 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); 794 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement);
723 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); 795 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup;
724 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); 796 //sandbox.SetAppDomainPolicy(sandboxPolicy);
725 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup; 797
726 //sandbox.SetAppDomainPolicy(sandboxPolicy); 798 m_AppDomains[appDomain] = sandbox;
727 799
728 m_AppDomains[appDomain] = sandbox; 800 m_AppDomains[appDomain].AssemblyResolve +=
729 801 new ResolveEventHandler(
730 m_AppDomains[appDomain].AssemblyResolve += 802 AssemblyResolver.OnAssemblyResolve);
731 new ResolveEventHandler( 803 m_DomainScripts[appDomain] = new List<UUID>();
732 AssemblyResolver.OnAssemblyResolve);
733 m_DomainScripts[appDomain] = new List<UUID>();
734 }
735 catch (Exception e)
736 {
737 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
738 m_ScriptErrorMessage += "Exception creating app domain:\n";
739 m_ScriptFailCount++;
740 lock (m_AddingAssemblies)
741 {
742 m_AddingAssemblies[assembly]--;
743 }
744 return false;
745 }
746 } 804 }
747 m_DomainScripts[appDomain].Add(itemID); 805 catch (Exception e)
748
749 instance = new ScriptInstance(this, part,
750 itemID, assetID, assembly,
751 m_AppDomains[appDomain],
752 part.ParentGroup.RootPart.Name,
753 item.Name, startParam, postOnRez,
754 stateSource, m_MaxScriptQueue);
755
756 m_log.DebugFormat("[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}",
757 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, part.ParentGroup.RootPart.AbsolutePosition.ToString());
758
759 if (presence != null)
760 { 806 {
761 ShowScriptSaveResponse(item.OwnerID, 807 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
762 assetID, "Compile successful", true); 808 m_ScriptErrorMessage += "Exception creating app domain:\n";
809 m_ScriptFailCount++;
810 lock (m_AddingAssemblies)
811 {
812 m_AddingAssemblies[assembly]--;
813 }
814 return false;
763 } 815 }
816 }
817 m_DomainScripts[appDomain].Add(itemID);
764 818
765 instance.AppDomain = appDomain; 819 instance = new ScriptInstance(this, part,
766 instance.LineMap = linemap; 820 itemID, assetID, assembly,
821 m_AppDomains[appDomain],
822 part.ParentGroup.RootPart.Name,
823 item.Name, startParam, postOnRez,
824 stateSource, m_MaxScriptQueue);
767 825
768 m_Scripts[itemID] = instance; 826 m_log.DebugFormat("[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}",
769 } 827 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, part.ParentGroup.RootPart.AbsolutePosition.ToString());
770 828
771 lock (m_PrimObjects) 829 if (presence != null)
772 { 830 {
773 if (!m_PrimObjects.ContainsKey(localID)) 831 ShowScriptSaveResponse(item.OwnerID,
774 m_PrimObjects[localID] = new List<UUID>(); 832 assetID, "Compile successful", true);
833 }
775 834
776 if (!m_PrimObjects[localID].Contains(itemID)) 835 instance.AppDomain = appDomain;
777 m_PrimObjects[localID].Add(itemID); 836 instance.LineMap = linemap;
837 lockScriptsForWrite(true);
838 m_Scripts[itemID] = instance;
839 lockScriptsForWrite(false);
840 }
841 else
842 {
843 lockScriptsForRead(false);
844 }
845 lock (m_PrimObjects)
846 {
847 if (!m_PrimObjects.ContainsKey(localID))
848 m_PrimObjects[localID] = new List<UUID>();
778 849
779 } 850 if (!m_PrimObjects[localID].Contains(itemID))
851 m_PrimObjects[localID].Add(itemID);
780 852
781 if (!m_Assemblies.ContainsKey(assetID)) 853 }
782 m_Assemblies[assetID] = assembly;
783 854
784 lock (m_AddingAssemblies) 855 if (!m_Assemblies.ContainsKey(assetID))
785 { 856 m_Assemblies[assetID] = assembly;
786 m_AddingAssemblies[assembly]--;
787 }
788 857
789 if (instance!=null) 858 lock (m_AddingAssemblies)
790 instance.Init(); 859 {
860 m_AddingAssemblies[assembly]--;
791 } 861 }
862
863 if (instance!=null)
864 instance.Init();
865
792 return true; 866 return true;
793 } 867 }
794 868
795 public void OnRemoveScript(uint localID, UUID itemID) 869 public void OnRemoveScript(uint localID, UUID itemID)
796 { 870 {
797 lock (m_Scripts) 871 lockScriptsForRead(true);
872 // Do we even have it?
873 if (!m_Scripts.ContainsKey(itemID))
798 { 874 {
799 // Do we even have it? 875 lockScriptsForRead(false);
800 if (!m_Scripts.ContainsKey(itemID)) 876 return;
801 return; 877 }
802 878
803 IScriptInstance instance=m_Scripts[itemID];
804 m_Scripts.Remove(itemID);
805 879
806 instance.ClearQueue(); 880 IScriptInstance instance=m_Scripts[itemID];
807 instance.Stop(0); 881 lockScriptsForRead(false);
882 lockScriptsForWrite(true);
883 m_Scripts.Remove(itemID);
884 lockScriptsForWrite(false);
885 instance.ClearQueue();
886 instance.Stop(0);
808 887
809 SceneObjectPart part = 888 SceneObjectPart part =
810 m_Scene.GetSceneObjectPart(localID); 889 m_Scene.GetSceneObjectPart(localID);
811 890
812 if (part != null) 891 if (part != null)
813 part.RemoveScriptEvents(itemID); 892 part.RemoveScriptEvents(itemID);
814 893
815// bool objectRemoved = false; 894// bool objectRemoved = false;
816 895
817 lock (m_PrimObjects) 896 lock (m_PrimObjects)
897 {
898 // Remove the script from it's prim
899 if (m_PrimObjects.ContainsKey(localID))
818 { 900 {
819 // Remove the script from it's prim 901 // Remove inventory item record
820 if (m_PrimObjects.ContainsKey(localID)) 902 if (m_PrimObjects[localID].Contains(itemID))
821 { 903 m_PrimObjects[localID].Remove(itemID);
822 // Remove inventory item record
823 if (m_PrimObjects[localID].Contains(itemID))
824 m_PrimObjects[localID].Remove(itemID);
825 904
826 // If there are no more scripts, remove prim 905 // If there are no more scripts, remove prim
827 if (m_PrimObjects[localID].Count == 0) 906 if (m_PrimObjects[localID].Count == 0)
828 { 907 {
829 m_PrimObjects.Remove(localID); 908 m_PrimObjects.Remove(localID);
830// objectRemoved = true; 909// objectRemoved = true;
831 }
832 } 910 }
833 } 911 }
912 }
834 913
835 instance.RemoveState(); 914 instance.RemoveState();
836 instance.DestroyScriptInstance(); 915 instance.DestroyScriptInstance();
837 916
838 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 917 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
839 if (m_DomainScripts[instance.AppDomain].Count == 0) 918 if (m_DomainScripts[instance.AppDomain].Count == 0)
840 { 919 {
841 m_DomainScripts.Remove(instance.AppDomain); 920 m_DomainScripts.Remove(instance.AppDomain);
842 UnloadAppDomain(instance.AppDomain); 921 UnloadAppDomain(instance.AppDomain);
843 } 922 }
844 923
845 instance = null; 924 instance = null;
846 925
847 ObjectRemoved handlerObjectRemoved = OnObjectRemoved; 926 ObjectRemoved handlerObjectRemoved = OnObjectRemoved;
848 if (handlerObjectRemoved != null) 927 if (handlerObjectRemoved != null)
849 handlerObjectRemoved(part.UUID); 928 handlerObjectRemoved(part.UUID);
850 929
851 CleanAssemblies(); 930 CleanAssemblies();
852 } 931
853 932
854 ScriptRemoved handlerScriptRemoved = OnScriptRemoved; 933 ScriptRemoved handlerScriptRemoved = OnScriptRemoved;
855 if (handlerScriptRemoved != null) 934 if (handlerScriptRemoved != null)
@@ -1102,12 +1181,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1102 private IScriptInstance GetInstance(UUID itemID) 1181 private IScriptInstance GetInstance(UUID itemID)
1103 { 1182 {
1104 IScriptInstance instance; 1183 IScriptInstance instance;
1105 lock (m_Scripts) 1184 lockScriptsForRead(true);
1185 if (!m_Scripts.ContainsKey(itemID))
1106 { 1186 {
1107 if (!m_Scripts.ContainsKey(itemID)) 1187 lockScriptsForRead(false);
1108 return null; 1188 return null;
1109 instance = m_Scripts[itemID];
1110 } 1189 }
1190 instance = m_Scripts[itemID];
1191 lockScriptsForRead(false);
1111 return instance; 1192 return instance;
1112 } 1193 }
1113 1194
@@ -1131,6 +1212,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1131 return false; 1212 return false;
1132 } 1213 }
1133 1214
1215 [DebuggerNonUserCode]
1134 public void ApiResetScript(UUID itemID) 1216 public void ApiResetScript(UUID itemID)
1135 { 1217 {
1136 IScriptInstance instance = GetInstance(itemID); 1218 IScriptInstance instance = GetInstance(itemID);
@@ -1182,6 +1264,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1182 return UUID.Zero; 1264 return UUID.Zero;
1183 } 1265 }
1184 1266
1267 [DebuggerNonUserCode]
1185 public void SetState(UUID itemID, string newState) 1268 public void SetState(UUID itemID, string newState)
1186 { 1269 {
1187 IScriptInstance instance = GetInstance(itemID); 1270 IScriptInstance instance = GetInstance(itemID);
@@ -1202,11 +1285,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1202 { 1285 {
1203 List<IScriptInstance> instances = new List<IScriptInstance>(); 1286 List<IScriptInstance> instances = new List<IScriptInstance>();
1204 1287
1205 lock (m_Scripts) 1288 lockScriptsForRead(true);
1206 { 1289 foreach (IScriptInstance instance in m_Scripts.Values)
1207 foreach (IScriptInstance instance in m_Scripts.Values)
1208 instances.Add(instance); 1290 instances.Add(instance);
1209 } 1291 lockScriptsForRead(false);
1210 1292
1211 foreach (IScriptInstance i in instances) 1293 foreach (IScriptInstance i in instances)
1212 { 1294 {