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/LSL_Api.cs1392
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs3
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs36
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs13
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs32
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs1
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs15
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs40
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs12
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs422
14 files changed, 1321 insertions, 653 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 712bd7d..fb191e6 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);
@@ -216,9 +219,62 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
216 } 219 }
217 } 220 }
218 221
222 public List<ScenePresence> GetLinkAvatars(int linkType)
223 {
224 List<ScenePresence> ret = new List<ScenePresence>();
225 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
226 return ret;
227
228 List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
229
230 switch (linkType)
231 {
232 case ScriptBaseClass.LINK_SET:
233 return avs;
234
235 case ScriptBaseClass.LINK_ROOT:
236 return ret;
237
238 case ScriptBaseClass.LINK_ALL_OTHERS:
239 return avs;
240
241 case ScriptBaseClass.LINK_ALL_CHILDREN:
242 return avs;
243
244 case ScriptBaseClass.LINK_THIS:
245 return ret;
246
247 default:
248 if (linkType < 0)
249 return ret;
250
251 int partCount = m_host.ParentGroup.GetPartCount();
252
253 if (linkType <= partCount)
254 {
255 return ret;
256 }
257 else
258 {
259 linkType = linkType - partCount;
260 if (linkType > avs.Count)
261 {
262 return ret;
263 }
264 else
265 {
266 ret.Add(avs[linkType-1]);
267 return ret;
268 }
269 }
270 }
271 }
272
219 public List<SceneObjectPart> GetLinkParts(int linkType) 273 public List<SceneObjectPart> GetLinkParts(int linkType)
220 { 274 {
221 List<SceneObjectPart> ret = new List<SceneObjectPart>(); 275 List<SceneObjectPart> ret = new List<SceneObjectPart>();
276 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
277 return ret;
222 ret.Add(m_host); 278 ret.Add(m_host);
223 279
224 switch (linkType) 280 switch (linkType)
@@ -272,40 +328,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
272 protected UUID InventorySelf() 328 protected UUID InventorySelf()
273 { 329 {
274 UUID invItemID = new UUID(); 330 UUID invItemID = new UUID();
275 331 bool unlock = false;
276 lock (m_host.TaskInventory) 332 if (!m_host.TaskInventory.IsReadLockedByMe())
277 { 333 {
278 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 334 m_host.TaskInventory.LockItemsForRead(true);
335 unlock = true;
336 }
337 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
338 {
339 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
279 { 340 {
280 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID) 341 invItemID = inv.Key;
281 { 342 break;
282 invItemID = inv.Key;
283 break;
284 }
285 } 343 }
286 } 344 }
287 345 if (unlock)
346 {
347 m_host.TaskInventory.LockItemsForRead(false);
348 }
288 return invItemID; 349 return invItemID;
289 } 350 }
290 351
291 protected UUID InventoryKey(string name, int type) 352 protected UUID InventoryKey(string name, int type)
292 { 353 {
293 m_host.AddScriptLPS(1); 354 m_host.AddScriptLPS(1);
294 355 m_host.TaskInventory.LockItemsForRead(true);
295 lock (m_host.TaskInventory) 356
357 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
296 { 358 {
297 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 359 if (inv.Value.Name == name)
298 { 360 {
299 if (inv.Value.Name == name) 361 m_host.TaskInventory.LockItemsForRead(false);
362
363 if (inv.Value.Type != type)
300 { 364 {
301 if (inv.Value.Type != type) 365 return UUID.Zero;
302 return UUID.Zero;
303
304 return inv.Value.AssetID;
305 } 366 }
367
368 return inv.Value.AssetID;
306 } 369 }
307 } 370 }
308 371
372 m_host.TaskInventory.LockItemsForRead(false);
309 return UUID.Zero; 373 return UUID.Zero;
310 } 374 }
311 375
@@ -313,17 +377,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
313 { 377 {
314 m_host.AddScriptLPS(1); 378 m_host.AddScriptLPS(1);
315 379
316 lock (m_host.TaskInventory) 380
381 m_host.TaskInventory.LockItemsForRead(true);
382
383 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
317 { 384 {
318 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 385 if (inv.Value.Name == name)
319 { 386 {
320 if (inv.Value.Name == name) 387 m_host.TaskInventory.LockItemsForRead(false);
321 { 388 return inv.Value.AssetID;
322 return inv.Value.AssetID;
323 }
324 } 389 }
325 } 390 }
326 391
392 m_host.TaskInventory.LockItemsForRead(false);
393
394
327 return UUID.Zero; 395 return UUID.Zero;
328 } 396 }
329 397
@@ -485,25 +553,33 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
485 return remainder; 553 return remainder;
486 } 554 }
487 555
488 // Old implementation of llRot2Euler, now normalized 556 public LSL_Vector llRot2Euler(LSL_Rotation q1)
489
490 public LSL_Vector llRot2Euler(LSL_Rotation r)
491 { 557 {
492 m_host.AddScriptLPS(1); 558 m_host.AddScriptLPS(1);
493 //This implementation is from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions. ckrinke 559 LSL_Vector eul = new LSL_Vector();
494 LSL_Rotation t = new LSL_Rotation(r.x * r.x, r.y * r.y, r.z * r.z, r.s * r.s); 560
495 double m = (t.x + t.y + t.z + t.s); 561 double sqw = q1.s*q1.s;
496 if (m == 0) return new LSL_Vector(); 562 double sqx = q1.x*q1.x;
497 double n = 2 * (r.y * r.s + r.x * r.z); 563 double sqy = q1.z*q1.z;
498 double p = m * m - n * n; 564 double sqz = q1.y*q1.y;
499 if (p > 0) 565 double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
500 return new LSL_Vector(NormalizeAngle(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s))), 566 double test = q1.x*q1.z + q1.y*q1.s;
501 NormalizeAngle(Math.Atan2(n, Math.Sqrt(p))), 567 if (test > 0.4999*unit) { // singularity at north pole
502 NormalizeAngle(Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s)))); 568 eul.z = 2 * Math.Atan2(q1.x,q1.s);
503 else if (n > 0) 569 eul.y = Math.PI/2;
504 return new LSL_Vector(0.0, Math.PI * 0.5, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z))); 570 eul.x = 0;
505 else 571 return eul;
506 return new LSL_Vector(0.0, -Math.PI * 0.5, NormalizeAngle(Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z))); 572 }
573 if (test < -0.4999*unit) { // singularity at south pole
574 eul.z = -2 * Math.Atan2(q1.x,q1.s);
575 eul.y = -Math.PI/2;
576 eul.x = 0;
577 return eul;
578 }
579 eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
580 eul.y = Math.Asin(2*test/unit);
581 eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
582 return eul;
507 } 583 }
508 584
509 /* From wiki: 585 /* From wiki:
@@ -705,77 +781,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
705 { 781 {
706 //A and B should both be normalized 782 //A and B should both be normalized
707 m_host.AddScriptLPS(1); 783 m_host.AddScriptLPS(1);
708 LSL_Rotation rotBetween; 784 /* This method is more accurate than the SL one, and thus causes problems
709 // Check for zero vectors. If either is zero, return zero rotation. Otherwise, 785 for scripts that deal with the SL inaccuracy around 180-degrees -.- .._.
710 // continue calculation. 786
711 if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f)) 787 double dotProduct = LSL_Vector.Dot(a, b);
712 { 788 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
713 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); 789 double magProduct = LSL_Vector.Mag(a) * LSL_Vector.Mag(b);
714 } 790 double angle = Math.Acos(dotProduct / magProduct);
715 else 791 LSL_Vector axis = LSL_Vector.Norm(crossProduct);
716 { 792 double s = Math.Sin(angle / 2);
717 a = LSL_Vector.Norm(a); 793
718 b = LSL_Vector.Norm(b); 794 double x = axis.x * s;
719 double dotProduct = LSL_Vector.Dot(a, b); 795 double y = axis.y * s;
720 // There are two degenerate cases possible. These are for vectors 180 or 796 double z = axis.z * s;
721 // 0 degrees apart. These have to be detected and handled individually. 797 double w = Math.Cos(angle / 2);
722 // 798
723 // Check for vectors 180 degrees apart. 799 if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w))
724 // A dot product of -1 would mean the angle between vectors is 180 degrees. 800 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
725 if (dotProduct < -0.9999999f) 801
726 { 802 return new LSL_Rotation((float)x, (float)y, (float)z, (float)w);
727 // First assume X axis is orthogonal to the vectors. 803 */
728 LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f); 804
729 orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a)); 805 // This method mimics the 180 errors found in SL
730 // Check for near zero vector. A very small non-zero number here will create 806 // See www.euclideanspace.com... angleBetween
731 // a rotation in an undesired direction. 807 LSL_Vector vec_a = a;
732 if (LSL_Vector.Mag(orthoVector) > 0.0001) 808 LSL_Vector vec_b = b;
733 { 809
734 rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f); 810 // Eliminate zero length
735 } 811 LSL_Float vec_a_mag = LSL_Vector.Mag(vec_a);
736 // If the magnitude of the vector was near zero, then assume the X axis is not 812 LSL_Float vec_b_mag = LSL_Vector.Mag(vec_b);
737 // orthogonal and use the Z axis instead. 813 if (vec_a_mag < 0.00001 ||
738 else 814 vec_b_mag < 0.00001)
739 { 815 {
740 // Set 180 z rotation. 816 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
741 rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f); 817 }
742 } 818
743 } 819 // Normalize
744 // Check for parallel vectors. 820 vec_a = llVecNorm(vec_a);
745 // A dot product of 1 would mean the angle between vectors is 0 degrees. 821 vec_b = llVecNorm(vec_b);
746 else if (dotProduct > 0.9999999f) 822
747 { 823 // Calculate axis and rotation angle
748 // Set zero rotation. 824 LSL_Vector axis = vec_a % vec_b;
749 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); 825 LSL_Float cos_theta = vec_a * vec_b;
750 } 826
751 else 827 // Check if parallel
752 { 828 if (cos_theta > 0.99999)
753 // All special checks have been performed so get the axis of rotation. 829 {
754 LSL_Vector crossProduct = LSL_Vector.Cross(a, b); 830 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
755 // Quarternion s value is the length of the unit vector + dot product. 831 }
756 double qs = 1.0 + dotProduct; 832
757 rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs); 833 // Check if anti-parallel
758 // Normalize the rotation. 834 else if (cos_theta < -0.99999)
759 double mag = LSL_Rotation.Mag(rotBetween); 835 {
760 // We shouldn't have to worry about a divide by zero here. The qs value will be 836 LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (vec_a.x / (vec_a * vec_a) * vec_a);
761 // non-zero because we already know if we're here, then the dotProduct is not -1 so 837 if (LSL_Vector.Mag(orthog_axis) < 0.000001) orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
762 // qs will not be zero. Also, we've already handled the input vectors being zero so the 838 return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
763 // crossProduct vector should also not be zero. 839 }
764 rotBetween.x = rotBetween.x / mag; 840 else // other rotation
765 rotBetween.y = rotBetween.y / mag; 841 {
766 rotBetween.z = rotBetween.z / mag; 842 LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
767 rotBetween.s = rotBetween.s / mag; 843 axis = llVecNorm(axis);
768 // Check for undefined values and set zero rotation if any found. This code might not actually be required 844 double x, y, z, s, t;
769 // any longer since zero vectors are checked for at the top. 845 s = Math.Cos(theta);
770 if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s)) 846 t = Math.Sin(theta);
771 { 847 x = axis.x * t;
772 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); 848 y = axis.y * t;
773 } 849 z = axis.z * t;
774 } 850 return new LSL_Rotation(x,y,z,s);
775 } 851 }
776 return rotBetween; 852 }
777 } 853
778
779 public void llWhisper(int channelID, string text) 854 public void llWhisper(int channelID, string text)
780 { 855 {
781 m_host.AddScriptLPS(1); 856 m_host.AddScriptLPS(1);
@@ -1099,10 +1174,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1099 return detectedParams.TouchUV; 1174 return detectedParams.TouchUV;
1100 } 1175 }
1101 1176
1177 [DebuggerNonUserCode]
1102 public virtual void llDie() 1178 public virtual void llDie()
1103 { 1179 {
1104 m_host.AddScriptLPS(1); 1180 m_host.AddScriptLPS(1);
1105 throw new SelfDeleteException(); 1181 if (!m_host.IsAttachment) throw new SelfDeleteException();
1106 } 1182 }
1107 1183
1108 public LSL_Float llGround(LSL_Vector offset) 1184 public LSL_Float llGround(LSL_Vector offset)
@@ -1175,6 +1251,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1175 1251
1176 public void llSetStatus(int status, int value) 1252 public void llSetStatus(int status, int value)
1177 { 1253 {
1254 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
1255 return;
1178 m_host.AddScriptLPS(1); 1256 m_host.AddScriptLPS(1);
1179 1257
1180 int statusrotationaxis = 0; 1258 int statusrotationaxis = 0;
@@ -1404,6 +1482,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1404 { 1482 {
1405 m_host.AddScriptLPS(1); 1483 m_host.AddScriptLPS(1);
1406 1484
1485 SetColor(m_host, color, face);
1486 }
1487
1488 protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
1489 {
1490 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1491 return;
1492
1493 Primitive.TextureEntry tex = part.Shape.Textures;
1494 Color4 texcolor;
1495 if (face >= 0 && face < GetNumberOfSides(part))
1496 {
1497 texcolor = tex.CreateFace((uint)face).RGBA;
1498 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1499 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1500 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1501 tex.FaceTextures[face].RGBA = texcolor;
1502 part.UpdateTexture(tex);
1503 return;
1504 }
1505 else if (face == ScriptBaseClass.ALL_SIDES)
1506 {
1507 for (uint i = 0; i < GetNumberOfSides(part); i++)
1508 {
1509 if (tex.FaceTextures[i] != null)
1510 {
1511 texcolor = tex.FaceTextures[i].RGBA;
1512 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1513 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1514 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1515 tex.FaceTextures[i].RGBA = texcolor;
1516 }
1517 texcolor = tex.DefaultTexture.RGBA;
1518 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1519 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1520 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1521 tex.DefaultTexture.RGBA = texcolor;
1522 }
1523 part.UpdateTexture(tex);
1524 return;
1525 }
1526
1407 if (face == ScriptBaseClass.ALL_SIDES) 1527 if (face == ScriptBaseClass.ALL_SIDES)
1408 face = SceneObjectPart.ALL_SIDES; 1528 face = SceneObjectPart.ALL_SIDES;
1409 1529
@@ -1412,6 +1532,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1412 1532
1413 public void SetTexGen(SceneObjectPart part, int face,int style) 1533 public void SetTexGen(SceneObjectPart part, int face,int style)
1414 { 1534 {
1535 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1536 return;
1537
1415 Primitive.TextureEntry tex = part.Shape.Textures; 1538 Primitive.TextureEntry tex = part.Shape.Textures;
1416 MappingType textype; 1539 MappingType textype;
1417 textype = MappingType.Default; 1540 textype = MappingType.Default;
@@ -1442,6 +1565,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1442 1565
1443 public void SetGlow(SceneObjectPart part, int face, float glow) 1566 public void SetGlow(SceneObjectPart part, int face, float glow)
1444 { 1567 {
1568 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1569 return;
1570
1445 Primitive.TextureEntry tex = part.Shape.Textures; 1571 Primitive.TextureEntry tex = part.Shape.Textures;
1446 if (face >= 0 && face < GetNumberOfSides(part)) 1572 if (face >= 0 && face < GetNumberOfSides(part))
1447 { 1573 {
@@ -1467,6 +1593,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1467 1593
1468 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump) 1594 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
1469 { 1595 {
1596 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1597 return;
1470 1598
1471 Shininess sval = new Shininess(); 1599 Shininess sval = new Shininess();
1472 1600
@@ -1517,6 +1645,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1517 1645
1518 public void SetFullBright(SceneObjectPart part, int face, bool bright) 1646 public void SetFullBright(SceneObjectPart part, int face, bool bright)
1519 { 1647 {
1648 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1649 return;
1650
1520 Primitive.TextureEntry tex = part.Shape.Textures; 1651 Primitive.TextureEntry tex = part.Shape.Textures;
1521 if (face >= 0 && face < GetNumberOfSides(part)) 1652 if (face >= 0 && face < GetNumberOfSides(part))
1522 { 1653 {
@@ -1577,13 +1708,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1577 m_host.AddScriptLPS(1); 1708 m_host.AddScriptLPS(1);
1578 1709
1579 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1710 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1580 1711 if (parts.Count > 0)
1581 foreach (SceneObjectPart part in parts) 1712 {
1582 SetAlpha(part, alpha, face); 1713 try
1714 {
1715 parts[0].ParentGroup.areUpdatesSuspended = true;
1716 foreach (SceneObjectPart part in parts)
1717 SetAlpha(part, alpha, face);
1718 }
1719 finally
1720 {
1721 parts[0].ParentGroup.areUpdatesSuspended = false;
1722 }
1723 }
1583 } 1724 }
1584 1725
1585 protected void SetAlpha(SceneObjectPart part, double alpha, int face) 1726 protected void SetAlpha(SceneObjectPart part, double alpha, int face)
1586 { 1727 {
1728 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1729 return;
1730
1587 Primitive.TextureEntry tex = part.Shape.Textures; 1731 Primitive.TextureEntry tex = part.Shape.Textures;
1588 Color4 texcolor; 1732 Color4 texcolor;
1589 if (face >= 0 && face < GetNumberOfSides(part)) 1733 if (face >= 0 && face < GetNumberOfSides(part))
@@ -1629,7 +1773,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1629 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction, 1773 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
1630 float wind, float tension, LSL_Vector Force) 1774 float wind, float tension, LSL_Vector Force)
1631 { 1775 {
1632 if (part == null) 1776 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1633 return; 1777 return;
1634 1778
1635 if (flexi) 1779 if (flexi)
@@ -1664,7 +1808,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1664 /// <param name="falloff"></param> 1808 /// <param name="falloff"></param>
1665 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff) 1809 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
1666 { 1810 {
1667 if (part == null) 1811 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1668 return; 1812 return;
1669 1813
1670 if (light) 1814 if (light)
@@ -1741,15 +1885,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1741 m_host.AddScriptLPS(1); 1885 m_host.AddScriptLPS(1);
1742 1886
1743 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1887 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1744 1888 if (parts.Count > 0)
1745 foreach (SceneObjectPart part in parts) 1889 {
1746 SetTexture(part, texture, face); 1890 try
1747 1891 {
1892 parts[0].ParentGroup.areUpdatesSuspended = true;
1893 foreach (SceneObjectPart part in parts)
1894 SetTexture(part, texture, face);
1895 }
1896 finally
1897 {
1898 parts[0].ParentGroup.areUpdatesSuspended = false;
1899 }
1900 }
1748 ScriptSleep(200); 1901 ScriptSleep(200);
1749 } 1902 }
1750 1903
1751 protected void SetTexture(SceneObjectPart part, string texture, int face) 1904 protected void SetTexture(SceneObjectPart part, string texture, int face)
1752 { 1905 {
1906 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1907 return;
1908
1753 UUID textureID=new UUID(); 1909 UUID textureID=new UUID();
1754 1910
1755 if (!UUID.TryParse(texture, out textureID)) 1911 if (!UUID.TryParse(texture, out textureID))
@@ -1795,6 +1951,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1795 1951
1796 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) 1952 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
1797 { 1953 {
1954 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1955 return;
1956
1798 Primitive.TextureEntry tex = part.Shape.Textures; 1957 Primitive.TextureEntry tex = part.Shape.Textures;
1799 if (face >= 0 && face < GetNumberOfSides(part)) 1958 if (face >= 0 && face < GetNumberOfSides(part))
1800 { 1959 {
@@ -1831,6 +1990,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1831 1990
1832 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) 1991 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
1833 { 1992 {
1993 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1994 return;
1995
1834 Primitive.TextureEntry tex = part.Shape.Textures; 1996 Primitive.TextureEntry tex = part.Shape.Textures;
1835 if (face >= 0 && face < GetNumberOfSides(part)) 1997 if (face >= 0 && face < GetNumberOfSides(part))
1836 { 1998 {
@@ -1867,6 +2029,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1867 2029
1868 protected void RotateTexture(SceneObjectPart part, double rotation, int face) 2030 protected void RotateTexture(SceneObjectPart part, double rotation, int face)
1869 { 2031 {
2032 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2033 return;
2034
1870 Primitive.TextureEntry tex = part.Shape.Textures; 2035 Primitive.TextureEntry tex = part.Shape.Textures;
1871 if (face >= 0 && face < GetNumberOfSides(part)) 2036 if (face >= 0 && face < GetNumberOfSides(part))
1872 { 2037 {
@@ -1937,6 +2102,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1937 2102
1938 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos) 2103 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos)
1939 { 2104 {
2105 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2106 return;
2107
1940 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos) 2108 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
1941 LSL_Vector currentPos = llGetLocalPos(); 2109 LSL_Vector currentPos = llGetLocalPos();
1942 2110
@@ -2023,6 +2191,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2023 2191
2024 protected void SetRot(SceneObjectPart part, Quaternion rot) 2192 protected void SetRot(SceneObjectPart part, Quaternion rot)
2025 { 2193 {
2194 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2195 return;
2196
2026 part.UpdateRotation(rot); 2197 part.UpdateRotation(rot);
2027 // Update rotation does not move the object in the physics scene if it's a linkset. 2198 // Update rotation does not move the object in the physics scene if it's a linkset.
2028 2199
@@ -2642,12 +2813,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2642 2813
2643 m_host.AddScriptLPS(1); 2814 m_host.AddScriptLPS(1);
2644 2815
2816 m_host.TaskInventory.LockItemsForRead(true);
2645 TaskInventoryItem item = m_host.TaskInventory[invItemID]; 2817 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2646 2818 m_host.TaskInventory.LockItemsForRead(false);
2647 lock (m_host.TaskInventory)
2648 {
2649 item = m_host.TaskInventory[invItemID];
2650 }
2651 2819
2652 if (item.PermsGranter == UUID.Zero) 2820 if (item.PermsGranter == UUID.Zero)
2653 return 0; 2821 return 0;
@@ -2722,6 +2890,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2722 if (dist > m_ScriptDistanceFactor * 10.0f) 2890 if (dist > m_ScriptDistanceFactor * 10.0f)
2723 return; 2891 return;
2724 2892
2893 //Clone is thread-safe
2725 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 2894 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
2726 2895
2727 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory) 2896 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory)
@@ -2784,6 +2953,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2784 2953
2785 public void llLookAt(LSL_Vector target, double strength, double damping) 2954 public void llLookAt(LSL_Vector target, double strength, double damping)
2786 { 2955 {
2956 /*
2787 m_host.AddScriptLPS(1); 2957 m_host.AddScriptLPS(1);
2788 // Determine where we are looking from 2958 // Determine where we are looking from
2789 LSL_Vector from = llGetPos(); 2959 LSL_Vector from = llGetPos();
@@ -2803,10 +2973,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2803 // the angles of rotation in radians into rotation value 2973 // the angles of rotation in radians into rotation value
2804 2974
2805 LSL_Types.Quaternion rot = llEuler2Rot(angle); 2975 LSL_Types.Quaternion rot = llEuler2Rot(angle);
2806 Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s); 2976
2807 m_host.startLookAt(rotation, (float)damping, (float)strength); 2977 // This would only work if your physics system contains an APID controller:
2978 // Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
2979 // m_host.startLookAt(rotation, (float)damping, (float)strength);
2980
2808 // Orient the object to the angle calculated 2981 // Orient the object to the angle calculated
2809 //llSetRot(rot); 2982 llSetRot(rot);
2983 */
2984
2985 //The above code, while nice, doesn't replicate the behaviour of SL and tends to "roll" the object.
2986 //There's probably a smarter way of doing this, my rotation math-fu is weak.
2987 // http://bugs.meta7.com/view.php?id=28
2988 // - Tom
2989
2990 LSL_Rotation newrot = llGetRot() * llRotBetween(new LSL_Vector(1.0d, 0.0d, 0.0d) * llGetRot(), new LSL_Vector(0.0d, 0.0d, -1.0d));
2991 llSetRot(newrot * llRotBetween(new LSL_Vector(0.0d,0.0d,1.0d) * newrot, target - llGetPos()));
2992
2993 }
2994
2995 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
2996 {
2997 m_host.AddScriptLPS(1);
2998// NotImplemented("llRotLookAt");
2999 m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping);
3000
2810 } 3001 }
2811 3002
2812 public void llStopLookAt() 3003 public void llStopLookAt()
@@ -2855,13 +3046,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2855 { 3046 {
2856 TaskInventoryItem item; 3047 TaskInventoryItem item;
2857 3048
2858 lock (m_host.TaskInventory) 3049 m_host.TaskInventory.LockItemsForRead(true);
3050 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2859 { 3051 {
2860 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3052 m_host.TaskInventory.LockItemsForRead(false);
2861 return; 3053 return;
2862 else
2863 item = m_host.TaskInventory[InventorySelf()];
2864 } 3054 }
3055 else
3056 {
3057 item = m_host.TaskInventory[InventorySelf()];
3058 }
3059 m_host.TaskInventory.LockItemsForRead(false);
2865 3060
2866 if (item.PermsGranter != UUID.Zero) 3061 if (item.PermsGranter != UUID.Zero)
2867 { 3062 {
@@ -2883,13 +3078,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2883 { 3078 {
2884 TaskInventoryItem item; 3079 TaskInventoryItem item;
2885 3080
3081 m_host.TaskInventory.LockItemsForRead(true);
2886 lock (m_host.TaskInventory) 3082 lock (m_host.TaskInventory)
2887 { 3083 {
3084
2888 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3085 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3086 {
3087 m_host.TaskInventory.LockItemsForRead(false);
2889 return; 3088 return;
3089 }
2890 else 3090 else
3091 {
2891 item = m_host.TaskInventory[InventorySelf()]; 3092 item = m_host.TaskInventory[InventorySelf()];
3093 }
2892 } 3094 }
3095 m_host.TaskInventory.LockItemsForRead(false);
2893 3096
2894 m_host.AddScriptLPS(1); 3097 m_host.AddScriptLPS(1);
2895 3098
@@ -2921,19 +3124,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2921 { 3124 {
2922 m_host.AddScriptLPS(1); 3125 m_host.AddScriptLPS(1);
2923 3126
2924 if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
2925 return;
2926
2927 TaskInventoryItem item; 3127 TaskInventoryItem item;
2928 3128
2929 lock (m_host.TaskInventory) 3129 m_host.TaskInventory.LockItemsForRead(true);
3130
3131 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2930 { 3132 {
2931 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3133 m_host.TaskInventory.LockItemsForRead(false);
2932 return; 3134 return;
2933 else 3135 }
2934 item = m_host.TaskInventory[InventorySelf()]; 3136 else
3137 {
3138 item = m_host.TaskInventory[InventorySelf()];
2935 } 3139 }
2936 3140
3141 m_host.TaskInventory.LockItemsForRead(false);
3142
2937 if (item.PermsGranter != m_host.OwnerID) 3143 if (item.PermsGranter != m_host.OwnerID)
2938 return; 3144 return;
2939 3145
@@ -2943,11 +3149,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2943 3149
2944 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 3150 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
2945 3151
3152 /*
2946 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3153 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
2947 if (attachmentsModule != null) 3154 if (attachmentsModule != null)
3155 {
2948 attachmentsModule.AttachObject( 3156 attachmentsModule.AttachObject(
2949 presence.ControllingClient, grp.LocalId, 3157 presence.ControllingClient, grp.LocalId,
2950 (uint)attachment, Quaternion.Identity, Vector3.Zero, false); 3158 (uint)attachment, Quaternion.Identity, Vector3.Zero, false);
3159 }
3160 */
3161 grp.AttachToAgent(m_host.OwnerID, (uint)attachment, Vector3.Zero, false);
2951 } 3162 }
2952 } 3163 }
2953 3164
@@ -2960,13 +3171,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2960 3171
2961 TaskInventoryItem item; 3172 TaskInventoryItem item;
2962 3173
2963 lock (m_host.TaskInventory) 3174 m_host.TaskInventory.LockItemsForRead(true);
3175
3176 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2964 { 3177 {
2965 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3178 m_host.TaskInventory.LockItemsForRead(false);
2966 return; 3179 return;
2967 else 3180 }
2968 item = m_host.TaskInventory[InventorySelf()]; 3181 else
3182 {
3183 item = m_host.TaskInventory[InventorySelf()];
2969 } 3184 }
3185 m_host.TaskInventory.LockItemsForRead(false);
3186
2970 3187
2971 if (item.PermsGranter != m_host.OwnerID) 3188 if (item.PermsGranter != m_host.OwnerID)
2972 return; 3189 return;
@@ -3003,8 +3220,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3003 return m_host.OwnerID.ToString(); 3220 return m_host.OwnerID.ToString();
3004 } 3221 }
3005 3222
3223 [DebuggerNonUserCode]
3006 public void llInstantMessage(string user, string message) 3224 public void llInstantMessage(string user, string message)
3007 { 3225 {
3226 UUID result;
3227 if (!UUID.TryParse(user, out result))
3228 {
3229 throw new Exception(String.Format("An invalid key of '{0} was passed to llInstantMessage", user));
3230 return;
3231 }
3232
3233
3008 m_host.AddScriptLPS(1); 3234 m_host.AddScriptLPS(1);
3009 3235
3010 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. 3236 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
@@ -3019,7 +3245,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3019 UUID friendTransactionID = UUID.Random(); 3245 UUID friendTransactionID = UUID.Random();
3020 3246
3021 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 3247 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
3022 3248
3023 GridInstantMessage msg = new GridInstantMessage(); 3249 GridInstantMessage msg = new GridInstantMessage();
3024 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; 3250 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
3025 msg.toAgentID = new Guid(user); // toAgentID.Guid; 3251 msg.toAgentID = new Guid(user); // toAgentID.Guid;
@@ -3040,13 +3266,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3040 msg.message = message.Substring(0, 1024); 3266 msg.message = message.Substring(0, 1024);
3041 else 3267 else
3042 msg.message = message; 3268 msg.message = message;
3043 msg.dialog = (byte)19; // messgage from script ??? // dialog; 3269 msg.dialog = (byte)19; // MessageFromObject
3044 msg.fromGroup = false;// fromGroup; 3270 msg.fromGroup = false;// fromGroup;
3045 msg.offline = (byte)0; //offline; 3271 msg.offline = (byte)0; //offline;
3046 msg.ParentEstateID = 0; //ParentEstateID; 3272 msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
3047 msg.Position = Vector3.Zero;// new Vector3(m_host.AbsolutePosition); 3273 msg.Position = new Vector3(m_host.AbsolutePosition);
3048 msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; 3274 msg.RegionID = World.RegionInfo.RegionID.Guid;
3049 msg.binaryBucket = new byte[0];// binaryBucket; 3275 msg.binaryBucket = Util.StringToBytes256(m_host.OwnerID.ToString());
3050 3276
3051 if (m_TransferModule != null) 3277 if (m_TransferModule != null)
3052 { 3278 {
@@ -3168,13 +3394,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3168 m_host.AddScriptLPS(1); 3394 m_host.AddScriptLPS(1);
3169 } 3395 }
3170 3396
3171 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3172 {
3173 m_host.AddScriptLPS(1);
3174 Quaternion rot = new Quaternion((float)target.x, (float)target.y, (float)target.z, (float)target.s);
3175 m_host.RotLookAt(rot, (float)strength, (float)damping);
3176 }
3177
3178 public LSL_Integer llStringLength(string str) 3397 public LSL_Integer llStringLength(string str)
3179 { 3398 {
3180 m_host.AddScriptLPS(1); 3399 m_host.AddScriptLPS(1);
@@ -3198,14 +3417,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3198 3417
3199 TaskInventoryItem item; 3418 TaskInventoryItem item;
3200 3419
3201 lock (m_host.TaskInventory) 3420 m_host.TaskInventory.LockItemsForRead(true);
3421 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3202 { 3422 {
3203 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3423 m_host.TaskInventory.LockItemsForRead(false);
3204 return; 3424 return;
3205 else
3206 item = m_host.TaskInventory[InventorySelf()];
3207 } 3425 }
3208 3426 else
3427 {
3428 item = m_host.TaskInventory[InventorySelf()];
3429 }
3430 m_host.TaskInventory.LockItemsForRead(false);
3209 if (item.PermsGranter == UUID.Zero) 3431 if (item.PermsGranter == UUID.Zero)
3210 return; 3432 return;
3211 3433
@@ -3235,13 +3457,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3235 3457
3236 TaskInventoryItem item; 3458 TaskInventoryItem item;
3237 3459
3238 lock (m_host.TaskInventory) 3460 m_host.TaskInventory.LockItemsForRead(true);
3461 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3239 { 3462 {
3240 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3463 m_host.TaskInventory.LockItemsForRead(false);
3241 return; 3464 return;
3242 else
3243 item = m_host.TaskInventory[InventorySelf()];
3244 } 3465 }
3466 else
3467 {
3468 item = m_host.TaskInventory[InventorySelf()];
3469 }
3470 m_host.TaskInventory.LockItemsForRead(false);
3471
3245 3472
3246 if (item.PermsGranter == UUID.Zero) 3473 if (item.PermsGranter == UUID.Zero)
3247 return; 3474 return;
@@ -3318,10 +3545,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3318 3545
3319 TaskInventoryItem item; 3546 TaskInventoryItem item;
3320 3547
3321 lock (m_host.TaskInventory) 3548
3549 m_host.TaskInventory.LockItemsForRead(true);
3550 if (!m_host.TaskInventory.ContainsKey(invItemID))
3551 {
3552 m_host.TaskInventory.LockItemsForRead(false);
3553 return;
3554 }
3555 else
3322 { 3556 {
3323 item = m_host.TaskInventory[invItemID]; 3557 item = m_host.TaskInventory[invItemID];
3324 } 3558 }
3559 m_host.TaskInventory.LockItemsForRead(false);
3325 3560
3326 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3561 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3327 { 3562 {
@@ -3353,11 +3588,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3353 3588
3354 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3589 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3355 { 3590 {
3356 lock (m_host.TaskInventory) 3591 m_host.TaskInventory.LockItemsForWrite(true);
3357 { 3592 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3358 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3593 m_host.TaskInventory[invItemID].PermsMask = perm;
3359 m_host.TaskInventory[invItemID].PermsMask = perm; 3594 m_host.TaskInventory.LockItemsForWrite(false);
3360 }
3361 3595
3362 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3596 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3363 "run_time_permissions", new Object[] { 3597 "run_time_permissions", new Object[] {
@@ -3377,11 +3611,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3377 3611
3378 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3612 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3379 { 3613 {
3380 lock (m_host.TaskInventory) 3614 m_host.TaskInventory.LockItemsForWrite(true);
3381 { 3615 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3382 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3616 m_host.TaskInventory[invItemID].PermsMask = perm;
3383 m_host.TaskInventory[invItemID].PermsMask = perm; 3617 m_host.TaskInventory.LockItemsForWrite(false);
3384 }
3385 3618
3386 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3619 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3387 "run_time_permissions", new Object[] { 3620 "run_time_permissions", new Object[] {
@@ -3402,11 +3635,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3402 3635
3403 if (!m_waitingForScriptAnswer) 3636 if (!m_waitingForScriptAnswer)
3404 { 3637 {
3405 lock (m_host.TaskInventory) 3638 m_host.TaskInventory.LockItemsForWrite(true);
3406 { 3639 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3407 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3640 m_host.TaskInventory[invItemID].PermsMask = 0;
3408 m_host.TaskInventory[invItemID].PermsMask = 0; 3641 m_host.TaskInventory.LockItemsForWrite(false);
3409 }
3410 3642
3411 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3643 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3412 m_waitingForScriptAnswer=true; 3644 m_waitingForScriptAnswer=true;
@@ -3441,10 +3673,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3441 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3673 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3442 llReleaseControls(); 3674 llReleaseControls();
3443 3675
3444 lock (m_host.TaskInventory) 3676
3445 { 3677 m_host.TaskInventory.LockItemsForWrite(true);
3446 m_host.TaskInventory[invItemID].PermsMask = answer; 3678 m_host.TaskInventory[invItemID].PermsMask = answer;
3447 } 3679 m_host.TaskInventory.LockItemsForWrite(false);
3680
3448 3681
3449 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3682 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3450 "run_time_permissions", new Object[] { 3683 "run_time_permissions", new Object[] {
@@ -3456,16 +3689,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3456 { 3689 {
3457 m_host.AddScriptLPS(1); 3690 m_host.AddScriptLPS(1);
3458 3691
3459 lock (m_host.TaskInventory) 3692 m_host.TaskInventory.LockItemsForRead(true);
3693
3694 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3460 { 3695 {
3461 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3696 if (item.Type == 10 && item.ItemID == m_itemID)
3462 { 3697 {
3463 if (item.Type == 10 && item.ItemID == m_itemID) 3698 m_host.TaskInventory.LockItemsForRead(false);
3464 { 3699 return item.PermsGranter.ToString();
3465 return item.PermsGranter.ToString();
3466 }
3467 } 3700 }
3468 } 3701 }
3702 m_host.TaskInventory.LockItemsForRead(false);
3469 3703
3470 return UUID.Zero.ToString(); 3704 return UUID.Zero.ToString();
3471 } 3705 }
@@ -3474,19 +3708,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3474 { 3708 {
3475 m_host.AddScriptLPS(1); 3709 m_host.AddScriptLPS(1);
3476 3710
3477 lock (m_host.TaskInventory) 3711 m_host.TaskInventory.LockItemsForRead(true);
3712
3713 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3478 { 3714 {
3479 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3715 if (item.Type == 10 && item.ItemID == m_itemID)
3480 { 3716 {
3481 if (item.Type == 10 && item.ItemID == m_itemID) 3717 int perms = item.PermsMask;
3482 { 3718 if (m_automaticLinkPermission)
3483 int perms = item.PermsMask; 3719 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3484 if (m_automaticLinkPermission) 3720 m_host.TaskInventory.LockItemsForRead(false);
3485 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; 3721 return perms;
3486 return perms;
3487 }
3488 } 3722 }
3489 } 3723 }
3724 m_host.TaskInventory.LockItemsForRead(false);
3490 3725
3491 return 0; 3726 return 0;
3492 } 3727 }
@@ -3508,9 +3743,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3508 public void llSetLinkColor(int linknumber, LSL_Vector color, int face) 3743 public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
3509 { 3744 {
3510 List<SceneObjectPart> parts = GetLinkParts(linknumber); 3745 List<SceneObjectPart> parts = GetLinkParts(linknumber);
3511 3746 if (parts.Count > 0)
3512 foreach (SceneObjectPart part in parts) 3747 {
3513 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); 3748 try
3749 {
3750 parts[0].ParentGroup.areUpdatesSuspended = true;
3751 foreach (SceneObjectPart part in parts)
3752 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
3753 }
3754 finally
3755 {
3756 parts[0].ParentGroup.areUpdatesSuspended = false;
3757 }
3758 }
3514 } 3759 }
3515 3760
3516 public void llCreateLink(string target, int parent) 3761 public void llCreateLink(string target, int parent)
@@ -3519,11 +3764,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3519 UUID invItemID = InventorySelf(); 3764 UUID invItemID = InventorySelf();
3520 3765
3521 TaskInventoryItem item; 3766 TaskInventoryItem item;
3522 lock (m_host.TaskInventory) 3767 m_host.TaskInventory.LockItemsForRead(true);
3523 { 3768 item = m_host.TaskInventory[invItemID];
3524 item = m_host.TaskInventory[invItemID]; 3769 m_host.TaskInventory.LockItemsForRead(false);
3525 } 3770
3526
3527 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3771 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3528 && !m_automaticLinkPermission) 3772 && !m_automaticLinkPermission)
3529 { 3773 {
@@ -3576,16 +3820,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3576 m_host.AddScriptLPS(1); 3820 m_host.AddScriptLPS(1);
3577 UUID invItemID = InventorySelf(); 3821 UUID invItemID = InventorySelf();
3578 3822
3579 lock (m_host.TaskInventory) 3823 m_host.TaskInventory.LockItemsForRead(true);
3580 {
3581 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3824 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3582 && !m_automaticLinkPermission) 3825 && !m_automaticLinkPermission)
3583 { 3826 {
3584 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3827 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
3828 m_host.TaskInventory.LockItemsForRead(false);
3585 return; 3829 return;
3586 } 3830 }
3587 } 3831 m_host.TaskInventory.LockItemsForRead(false);
3588 3832
3589 if (linknum < ScriptBaseClass.LINK_THIS) 3833 if (linknum < ScriptBaseClass.LINK_THIS)
3590 return; 3834 return;
3591 3835
@@ -3624,10 +3868,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3624 // Restructuring Multiple Prims. 3868 // Restructuring Multiple Prims.
3625 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values); 3869 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values);
3626 parts.Remove(parentPrim.RootPart); 3870 parts.Remove(parentPrim.RootPart);
3627 foreach (SceneObjectPart part in parts) 3871 if (parts.Count > 0)
3628 { 3872 {
3629 parentPrim.DelinkFromGroup(part.LocalId, true); 3873 try
3874 {
3875 parts[0].ParentGroup.areUpdatesSuspended = true;
3876 foreach (SceneObjectPart part in parts)
3877 {
3878 parentPrim.DelinkFromGroup(part.LocalId, true);
3879 }
3880 }
3881 finally
3882 {
3883 parts[0].ParentGroup.areUpdatesSuspended = false;
3884 }
3630 } 3885 }
3886
3631 parentPrim.HasGroupChanged = true; 3887 parentPrim.HasGroupChanged = true;
3632 parentPrim.ScheduleGroupForFullUpdate(); 3888 parentPrim.ScheduleGroupForFullUpdate();
3633 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 3889 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
@@ -3636,11 +3892,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3636 { 3892 {
3637 SceneObjectPart newRoot = parts[0]; 3893 SceneObjectPart newRoot = parts[0];
3638 parts.Remove(newRoot); 3894 parts.Remove(newRoot);
3639 foreach (SceneObjectPart part in parts) 3895
3896 try
3640 { 3897 {
3641 part.UpdateFlag = 0; 3898 parts[0].ParentGroup.areUpdatesSuspended = true;
3642 newRoot.ParentGroup.LinkToGroup(part.ParentGroup); 3899 foreach (SceneObjectPart part in parts)
3900 {
3901 part.UpdateFlag = 0;
3902 newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
3903 }
3643 } 3904 }
3905 finally
3906 {
3907 parts[0].ParentGroup.areUpdatesSuspended = false;
3908 }
3909
3910
3644 newRoot.ParentGroup.HasGroupChanged = true; 3911 newRoot.ParentGroup.HasGroupChanged = true;
3645 newRoot.ParentGroup.ScheduleGroupForFullUpdate(); 3912 newRoot.ParentGroup.ScheduleGroupForFullUpdate();
3646 } 3913 }
@@ -3666,11 +3933,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3666 3933
3667 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values); 3934 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values);
3668 parts.Remove(parentPrim.RootPart); 3935 parts.Remove(parentPrim.RootPart);
3669 3936 if (parts.Count > 0)
3670 foreach (SceneObjectPart part in parts)
3671 { 3937 {
3672 parentPrim.DelinkFromGroup(part.LocalId, true); 3938 try
3673 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 3939 {
3940 parts[0].ParentGroup.areUpdatesSuspended = true;
3941 foreach (SceneObjectPart part in parts)
3942 {
3943 parentPrim.DelinkFromGroup(part.LocalId, true);
3944 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
3945 }
3946 }
3947 finally
3948 {
3949 parts[0].ParentGroup.areUpdatesSuspended = false;
3950 }
3674 } 3951 }
3675 parentPrim.HasGroupChanged = true; 3952 parentPrim.HasGroupChanged = true;
3676 parentPrim.ScheduleGroupForFullUpdate(); 3953 parentPrim.ScheduleGroupForFullUpdate();
@@ -3762,17 +4039,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3762 m_host.AddScriptLPS(1); 4039 m_host.AddScriptLPS(1);
3763 int count = 0; 4040 int count = 0;
3764 4041
3765 lock (m_host.TaskInventory) 4042 m_host.TaskInventory.LockItemsForRead(true);
4043 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3766 { 4044 {
3767 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4045 if (inv.Value.Type == type || type == -1)
3768 { 4046 {
3769 if (inv.Value.Type == type || type == -1) 4047 count = count + 1;
3770 {
3771 count = count + 1;
3772 }
3773 } 4048 }
3774 } 4049 }
3775 4050
4051 m_host.TaskInventory.LockItemsForRead(false);
3776 return count; 4052 return count;
3777 } 4053 }
3778 4054
@@ -3781,16 +4057,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3781 m_host.AddScriptLPS(1); 4057 m_host.AddScriptLPS(1);
3782 ArrayList keys = new ArrayList(); 4058 ArrayList keys = new ArrayList();
3783 4059
3784 lock (m_host.TaskInventory) 4060 m_host.TaskInventory.LockItemsForRead(true);
4061 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3785 { 4062 {
3786 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4063 if (inv.Value.Type == type || type == -1)
3787 { 4064 {
3788 if (inv.Value.Type == type || type == -1) 4065 keys.Add(inv.Value.Name);
3789 {
3790 keys.Add(inv.Value.Name);
3791 }
3792 } 4066 }
3793 } 4067 }
4068 m_host.TaskInventory.LockItemsForRead(false);
3794 4069
3795 if (keys.Count == 0) 4070 if (keys.Count == 0)
3796 { 4071 {
@@ -3827,20 +4102,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3827 } 4102 }
3828 4103
3829 // move the first object found with this inventory name 4104 // move the first object found with this inventory name
3830 lock (m_host.TaskInventory) 4105 m_host.TaskInventory.LockItemsForRead(true);
4106 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3831 { 4107 {
3832 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4108 if (inv.Value.Name == inventory)
3833 { 4109 {
3834 if (inv.Value.Name == inventory) 4110 found = true;
3835 { 4111 objId = inv.Key;
3836 found = true; 4112 assetType = inv.Value.Type;
3837 objId = inv.Key; 4113 objName = inv.Value.Name;
3838 assetType = inv.Value.Type; 4114 break;
3839 objName = inv.Value.Name;
3840 break;
3841 }
3842 } 4115 }
3843 } 4116 }
4117 m_host.TaskInventory.LockItemsForRead(false);
3844 4118
3845 if (!found) 4119 if (!found)
3846 { 4120 {
@@ -3848,9 +4122,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3848 throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); 4122 throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
3849 } 4123 }
3850 4124
3851 // check if destination is an avatar 4125 // check if destination is an object
3852 if (World.GetScenePresence(destId) != null) 4126 if (World.GetSceneObjectPart(destId) != null)
3853 { 4127 {
4128 // destination is an object
4129 World.MoveTaskInventoryItem(destId, m_host, objId);
4130 }
4131 else
4132 {
4133 ScenePresence presence = World.GetScenePresence(destId);
4134
4135 if (presence == null)
4136 {
4137 UserAccount account =
4138 World.UserAccountService.GetUserAccount(
4139 World.RegionInfo.ScopeID,
4140 destId);
4141
4142 if (account == null)
4143 {
4144 llSay(0, "Can't find destination "+destId.ToString());
4145 return;
4146 }
4147 }
4148
3854 // destination is an avatar 4149 // destination is an avatar
3855 InventoryItemBase agentItem = 4150 InventoryItemBase agentItem =
3856 World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId); 4151 World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId);
@@ -3876,33 +4171,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3876 4171
3877 if (m_TransferModule != null) 4172 if (m_TransferModule != null)
3878 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); 4173 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
4174
4175 //This delay should only occur when giving inventory to avatars.
4176 ScriptSleep(3000);
3879 } 4177 }
3880 else
3881 {
3882 // destination is an object
3883 World.MoveTaskInventoryItem(destId, m_host, objId);
3884 }
3885 ScriptSleep(3000);
3886 } 4178 }
3887 4179
4180 [DebuggerNonUserCode]
3888 public void llRemoveInventory(string name) 4181 public void llRemoveInventory(string name)
3889 { 4182 {
3890 m_host.AddScriptLPS(1); 4183 m_host.AddScriptLPS(1);
3891 4184
3892 lock (m_host.TaskInventory) 4185 m_host.TaskInventory.LockItemsForRead(true);
4186 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3893 { 4187 {
3894 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4188 if (item.Name == name)
3895 { 4189 {
3896 if (item.Name == name) 4190 if (item.ItemID == m_itemID)
3897 { 4191 throw new ScriptDeleteException();
3898 if (item.ItemID == m_itemID) 4192 else
3899 throw new ScriptDeleteException(); 4193 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3900 else 4194
3901 m_host.Inventory.RemoveInventoryItem(item.ItemID); 4195 m_host.TaskInventory.LockItemsForRead(false);
3902 return; 4196 return;
3903 }
3904 } 4197 }
3905 } 4198 }
4199 m_host.TaskInventory.LockItemsForRead(false);
3906 } 4200 }
3907 4201
3908 public void llSetText(string text, LSL_Vector color, double alpha) 4202 public void llSetText(string text, LSL_Vector color, double alpha)
@@ -3938,22 +4232,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3938 UUID uuid = (UUID)id; 4232 UUID uuid = (UUID)id;
3939 4233
3940 UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); 4234 UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
4235 if (account == null)
4236 return UUID.Zero.ToString();
4237
3941 4238
3942 PresenceInfo pinfo = null; 4239 PresenceInfo pinfo = null;
3943 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); 4240 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
3944 if (pinfos != null && pinfos.Length > 0) 4241 if (pinfos != null && pinfos.Length > 0)
3945 pinfo = pinfos[0]; 4242 pinfo = pinfos[0];
3946 4243
3947 if (pinfo == null)
3948 return UUID.Zero.ToString();
3949
3950 string reply = String.Empty; 4244 string reply = String.Empty;
3951 4245
3952 switch (data) 4246 switch (data)
3953 { 4247 {
3954 case 1: // DATA_ONLINE (0|1) 4248 case 1: // DATA_ONLINE (0|1)
3955 // TODO: implement fetching of this information 4249 if (pinfo != null && pinfo.RegionID != UUID.Zero)
3956 if (pinfo != null)
3957 reply = "1"; 4250 reply = "1";
3958 else 4251 else
3959 reply = "0"; 4252 reply = "0";
@@ -3993,6 +4286,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3993 { 4286 {
3994 m_host.AddScriptLPS(1); 4287 m_host.AddScriptLPS(1);
3995 4288
4289 //Clone is thread safe
3996 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 4290 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
3997 4291
3998 foreach (TaskInventoryItem item in itemDictionary.Values) 4292 foreach (TaskInventoryItem item in itemDictionary.Values)
@@ -4046,6 +4340,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4046 ScenePresence presence = World.GetScenePresence(agentId); 4340 ScenePresence presence = World.GetScenePresence(agentId);
4047 if (presence != null) 4341 if (presence != null)
4048 { 4342 {
4343 // agent must not be a god
4344 if (presence.GodLevel >= 200) return;
4345
4049 // agent must be over the owners land 4346 // agent must be over the owners land
4050 if (m_host.OwnerID == World.LandChannel.GetLandObject( 4347 if (m_host.OwnerID == World.LandChannel.GetLandObject(
4051 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) 4348 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
@@ -4106,17 +4403,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4106 UUID soundId = UUID.Zero; 4403 UUID soundId = UUID.Zero;
4107 if (!UUID.TryParse(impact_sound, out soundId)) 4404 if (!UUID.TryParse(impact_sound, out soundId))
4108 { 4405 {
4109 lock (m_host.TaskInventory) 4406 m_host.TaskInventory.LockItemsForRead(true);
4407 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4110 { 4408 {
4111 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4409 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
4112 { 4410 {
4113 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 4411 soundId = item.AssetID;
4114 { 4412 break;
4115 soundId = item.AssetID;
4116 break;
4117 }
4118 } 4413 }
4119 } 4414 }
4415 m_host.TaskInventory.LockItemsForRead(false);
4120 } 4416 }
4121 m_host.CollisionSound = soundId; 4417 m_host.CollisionSound = soundId;
4122 m_host.CollisionSoundVolume = (float)impact_volume; 4418 m_host.CollisionSoundVolume = (float)impact_volume;
@@ -4162,6 +4458,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4162 UUID partItemID; 4458 UUID partItemID;
4163 foreach (SceneObjectPart part in parts) 4459 foreach (SceneObjectPart part in parts)
4164 { 4460 {
4461 //Clone is thread safe
4165 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); 4462 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
4166 4463
4167 foreach (TaskInventoryItem item in itemsDictionary.Values) 4464 foreach (TaskInventoryItem item in itemsDictionary.Values)
@@ -4376,17 +4673,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4376 4673
4377 m_host.AddScriptLPS(1); 4674 m_host.AddScriptLPS(1);
4378 4675
4379 lock (m_host.TaskInventory) 4676 m_host.TaskInventory.LockItemsForRead(true);
4677 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4380 { 4678 {
4381 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4679 if (item.Type == 10 && item.ItemID == m_itemID)
4382 { 4680 {
4383 if (item.Type == 10 && item.ItemID == m_itemID) 4681 result = item.Name!=null?item.Name:String.Empty;
4384 { 4682 break;
4385 result = item.Name != null ? item.Name : String.Empty;
4386 break;
4387 }
4388 } 4683 }
4389 } 4684 }
4685 m_host.TaskInventory.LockItemsForRead(false);
4390 4686
4391 return result; 4687 return result;
4392 } 4688 }
@@ -4539,23 +4835,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4539 { 4835 {
4540 m_host.AddScriptLPS(1); 4836 m_host.AddScriptLPS(1);
4541 4837
4542 lock (m_host.TaskInventory) 4838 m_host.TaskInventory.LockItemsForRead(true);
4839 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4543 { 4840 {
4544 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4841 if (inv.Value.Name == name)
4545 { 4842 {
4546 if (inv.Value.Name == name) 4843 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
4547 { 4844 {
4548 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) 4845 m_host.TaskInventory.LockItemsForRead(false);
4549 { 4846 return inv.Value.AssetID.ToString();
4550 return inv.Value.AssetID.ToString(); 4847 }
4551 } 4848 else
4552 else 4849 {
4553 { 4850 m_host.TaskInventory.LockItemsForRead(false);
4554 return UUID.Zero.ToString(); 4851 return UUID.Zero.ToString();
4555 }
4556 } 4852 }
4557 } 4853 }
4558 } 4854 }
4855 m_host.TaskInventory.LockItemsForRead(false);
4559 4856
4560 return UUID.Zero.ToString(); 4857 return UUID.Zero.ToString();
4561 } 4858 }
@@ -5491,10 +5788,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5491 m_host.AddScriptLPS(1); 5788 m_host.AddScriptLPS(1);
5492 5789
5493 List<SceneObjectPart> parts = GetLinkParts(linknumber); 5790 List<SceneObjectPart> parts = GetLinkParts(linknumber);
5494 5791 if (parts.Count > 0)
5495 foreach (var part in parts)
5496 { 5792 {
5497 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate); 5793 try
5794 {
5795 parts[0].ParentGroup.areUpdatesSuspended = true;
5796 foreach (var part in parts)
5797 {
5798 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
5799 }
5800 }
5801 finally
5802 {
5803 parts[0].ParentGroup.areUpdatesSuspended = false;
5804 }
5498 } 5805 }
5499 } 5806 }
5500 5807
@@ -6073,6 +6380,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6073 tempf = (float)rules.GetLSLFloatItem(i + 1); 6380 tempf = (float)rules.GetLSLFloatItem(i + 1);
6074 prules.OuterAngle = (float)tempf; 6381 prules.OuterAngle = (float)tempf;
6075 break; 6382 break;
6383
6384 case (int)ScriptBaseClass.PSYS_SRC_INNERANGLE:
6385 tempf = (float)rules.GetLSLFloatItem(i + 1);
6386 prules.InnerAngle = (float)tempf;
6387 break;
6388
6389 case (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE:
6390 tempf = (float)rules.GetLSLFloatItem(i + 1);
6391 prules.OuterAngle = (float)tempf;
6392 break;
6076 } 6393 }
6077 6394
6078 } 6395 }
@@ -6111,14 +6428,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6111 6428
6112 protected UUID GetTaskInventoryItem(string name) 6429 protected UUID GetTaskInventoryItem(string name)
6113 { 6430 {
6114 lock (m_host.TaskInventory) 6431 m_host.TaskInventory.LockItemsForRead(true);
6432 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6115 { 6433 {
6116 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6434 if (inv.Value.Name == name)
6117 { 6435 {
6118 if (inv.Value.Name == name) 6436 m_host.TaskInventory.LockItemsForRead(false);
6119 return inv.Key; 6437 return inv.Key;
6120 } 6438 }
6121 } 6439 }
6440 m_host.TaskInventory.LockItemsForRead(false);
6122 6441
6123 return UUID.Zero; 6442 return UUID.Zero;
6124 } 6443 }
@@ -6446,22 +6765,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6446 } 6765 }
6447 6766
6448 // copy the first script found with this inventory name 6767 // copy the first script found with this inventory name
6449 lock (m_host.TaskInventory) 6768 m_host.TaskInventory.LockItemsForRead(true);
6769 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6450 { 6770 {
6451 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6771 if (inv.Value.Name == name)
6452 { 6772 {
6453 if (inv.Value.Name == name) 6773 // make sure the object is a script
6774 if (10 == inv.Value.Type)
6454 { 6775 {
6455 // make sure the object is a script 6776 found = true;
6456 if (10 == inv.Value.Type) 6777 srcId = inv.Key;
6457 { 6778 break;
6458 found = true;
6459 srcId = inv.Key;
6460 break;
6461 }
6462 } 6779 }
6463 } 6780 }
6464 } 6781 }
6782 m_host.TaskInventory.LockItemsForRead(false);
6465 6783
6466 if (!found) 6784 if (!found)
6467 { 6785 {
@@ -6545,6 +6863,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6545 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist) 6863 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist)
6546 { 6864 {
6547 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 6865 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6866 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6867 return shapeBlock;
6548 6868
6549 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && 6869 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
6550 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && 6870 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
@@ -6620,6 +6940,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6620 6940
6621 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge) 6941 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge)
6622 { 6942 {
6943 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6944 return;
6945
6623 ObjectShapePacket.ObjectDataBlock shapeBlock; 6946 ObjectShapePacket.ObjectDataBlock shapeBlock;
6624 6947
6625 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 6948 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6669,6 +6992,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6669 6992
6670 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge) 6993 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge)
6671 { 6994 {
6995 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6996 return;
6997
6672 ObjectShapePacket.ObjectDataBlock shapeBlock; 6998 ObjectShapePacket.ObjectDataBlock shapeBlock;
6673 6999
6674 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7000 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6711,6 +7037,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6711 7037
6712 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) 7038 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)
6713 { 7039 {
7040 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7041 return;
7042
6714 ObjectShapePacket.ObjectDataBlock shapeBlock; 7043 ObjectShapePacket.ObjectDataBlock shapeBlock;
6715 7044
6716 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7045 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6837,6 +7166,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6837 7166
6838 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type) 7167 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type)
6839 { 7168 {
7169 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7170 return;
7171
6840 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7172 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6841 UUID sculptId; 7173 UUID sculptId;
6842 7174
@@ -6852,13 +7184,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6852 shapeBlock.PathScaleX = 100; 7184 shapeBlock.PathScaleX = 100;
6853 shapeBlock.PathScaleY = 150; 7185 shapeBlock.PathScaleY = 150;
6854 7186
6855 if (type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER && 7187 if ((type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER) == 0 &&
6856 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE && 7188 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE) == 0 &&
6857 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE && 7189 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE) == 0 &&
6858 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) 7190 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) == 0)
6859 { 7191 {
6860 // default 7192 // default
6861 type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; 7193 type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
6862 } 7194 }
6863 7195
6864 // retain pathcurve 7196 // retain pathcurve
@@ -6877,12 +7209,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6877 7209
6878 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) 7210 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
6879 { 7211 {
6880 m_host.AddScriptLPS(1); 7212 m_host.AddScriptLPS(1);
6881 7213
6882 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7214 List<SceneObjectPart> parts = GetLinkParts(linknumber);
6883 7215 List<ScenePresence> avatars = GetLinkAvatars(linknumber);
6884 foreach (SceneObjectPart part in parts) 7216 if (parts.Count>0)
6885 SetPrimParams(part, rules); 7217 {
7218 try
7219 {
7220 parts[0].ParentGroup.areUpdatesSuspended = true;
7221 foreach (SceneObjectPart part in parts)
7222 SetPrimParams(part, rules);
7223 }
7224 finally
7225 {
7226 parts[0].ParentGroup.areUpdatesSuspended = false;
7227 }
7228 }
7229 if (avatars.Count > 0)
7230 {
7231 foreach (ScenePresence avatar in avatars)
7232 SetPrimParams(avatar, rules);
7233 }
6886 } 7234 }
6887 7235
6888 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) 7236 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
@@ -6890,8 +7238,51 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6890 llSetLinkPrimitiveParams(linknumber, rules); 7238 llSetLinkPrimitiveParams(linknumber, rules);
6891 } 7239 }
6892 7240
7241 protected void SetPrimParams(ScenePresence av, LSL_List rules)
7242 {
7243 //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
7244 //We only support PRIM_POSITION and PRIM_ROTATION
7245
7246 int idx = 0;
7247
7248 while (idx < rules.Length)
7249 {
7250 int code = rules.GetLSLIntegerItem(idx++);
7251
7252 int remain = rules.Length - idx;
7253
7254
7255
7256 switch (code)
7257 {
7258 case (int)ScriptBaseClass.PRIM_POSITION:
7259 if (remain < 1)
7260 return;
7261 LSL_Vector v;
7262 v = rules.GetVector3Item(idx++);
7263 av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
7264 av.SendFullUpdateToAllClients();
7265
7266 break;
7267
7268 case (int)ScriptBaseClass.PRIM_ROTATION:
7269 if (remain < 1)
7270 return;
7271 LSL_Rotation r;
7272 r = rules.GetQuaternionItem(idx++);
7273 av.OffsetRotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
7274 av.SendFullUpdateToAllClients();
7275 break;
7276 }
7277 }
7278
7279 }
7280
6893 protected void SetPrimParams(SceneObjectPart part, LSL_List rules) 7281 protected void SetPrimParams(SceneObjectPart part, LSL_List rules)
6894 { 7282 {
7283 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7284 return;
7285
6895 int idx = 0; 7286 int idx = 0;
6896 7287
6897 while (idx < rules.Length) 7288 while (idx < rules.Length)
@@ -7723,24 +8114,95 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7723 break; 8114 break;
7724 8115
7725 case (int)ScriptBaseClass.PRIM_BUMP_SHINY: 8116 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
7726 // TODO--------------
7727 if (remain < 1) 8117 if (remain < 1)
7728 return res; 8118 return res;
8119 face = (int)rules.GetLSLIntegerItem(idx++);
7729 8120
7730 face=(int)rules.GetLSLIntegerItem(idx++); 8121 tex = part.Shape.Textures;
7731 8122 int shiny;
7732 res.Add(new LSL_Integer(0)); 8123 if (face == ScriptBaseClass.ALL_SIDES)
7733 res.Add(new LSL_Integer(0)); 8124 {
8125 for (face = 0; face < GetNumberOfSides(part); face++)
8126 {
8127 Shininess shinyness = tex.GetFace((uint)face).Shiny;
8128 if (shinyness == Shininess.High)
8129 {
8130 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
8131 }
8132 else if (shinyness == Shininess.Medium)
8133 {
8134 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8135 }
8136 else if (shinyness == Shininess.Low)
8137 {
8138 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8139 }
8140 else
8141 {
8142 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8143 }
8144 res.Add(new LSL_Integer(shiny));
8145 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
8146 }
8147 }
8148 else
8149 {
8150 Shininess shinyness = tex.GetFace((uint)face).Shiny;
8151 if (shinyness == Shininess.High)
8152 {
8153 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
8154 }
8155 else if (shinyness == Shininess.Medium)
8156 {
8157 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8158 }
8159 else if (shinyness == Shininess.Low)
8160 {
8161 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8162 }
8163 else
8164 {
8165 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8166 }
8167 res.Add(new LSL_Integer(shiny));
8168 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
8169 }
7734 break; 8170 break;
7735 8171
7736 case (int)ScriptBaseClass.PRIM_FULLBRIGHT: 8172 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
7737 // TODO--------------
7738 if (remain < 1) 8173 if (remain < 1)
7739 return res; 8174 return res;
8175 face = (int)rules.GetLSLIntegerItem(idx++);
7740 8176
7741 face=(int)rules.GetLSLIntegerItem(idx++); 8177 tex = part.Shape.Textures;
7742 8178 int fullbright;
7743 res.Add(new LSL_Integer(0)); 8179 if (face == ScriptBaseClass.ALL_SIDES)
8180 {
8181 for (face = 0; face < GetNumberOfSides(part); face++)
8182 {
8183 if (tex.GetFace((uint)face).Fullbright == true)
8184 {
8185 fullbright = ScriptBaseClass.TRUE;
8186 }
8187 else
8188 {
8189 fullbright = ScriptBaseClass.FALSE;
8190 }
8191 res.Add(new LSL_Integer(fullbright));
8192 }
8193 }
8194 else
8195 {
8196 if (tex.GetFace((uint)face).Fullbright == true)
8197 {
8198 fullbright = ScriptBaseClass.TRUE;
8199 }
8200 else
8201 {
8202 fullbright = ScriptBaseClass.FALSE;
8203 }
8204 res.Add(new LSL_Integer(fullbright));
8205 }
7744 break; 8206 break;
7745 8207
7746 case (int)ScriptBaseClass.PRIM_FLEXIBLE: 8208 case (int)ScriptBaseClass.PRIM_FLEXIBLE:
@@ -7761,14 +8223,37 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7761 break; 8223 break;
7762 8224
7763 case (int)ScriptBaseClass.PRIM_TEXGEN: 8225 case (int)ScriptBaseClass.PRIM_TEXGEN:
7764 // TODO--------------
7765 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR) 8226 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
7766 if (remain < 1) 8227 if (remain < 1)
7767 return res; 8228 return res;
8229 face = (int)rules.GetLSLIntegerItem(idx++);
7768 8230
7769 face=(int)rules.GetLSLIntegerItem(idx++); 8231 tex = part.Shape.Textures;
7770 8232 if (face == ScriptBaseClass.ALL_SIDES)
7771 res.Add(new LSL_Integer(0)); 8233 {
8234 for (face = 0; face < GetNumberOfSides(part); face++)
8235 {
8236 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8237 {
8238 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8239 }
8240 else
8241 {
8242 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8243 }
8244 }
8245 }
8246 else
8247 {
8248 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8249 {
8250 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8251 }
8252 else
8253 {
8254 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8255 }
8256 }
7772 break; 8257 break;
7773 8258
7774 case (int)ScriptBaseClass.PRIM_POINT_LIGHT: 8259 case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
@@ -7787,13 +8272,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7787 break; 8272 break;
7788 8273
7789 case (int)ScriptBaseClass.PRIM_GLOW: 8274 case (int)ScriptBaseClass.PRIM_GLOW:
7790 // TODO--------------
7791 if (remain < 1) 8275 if (remain < 1)
7792 return res; 8276 return res;
8277 face = (int)rules.GetLSLIntegerItem(idx++);
7793 8278
7794 face=(int)rules.GetLSLIntegerItem(idx++); 8279 tex = part.Shape.Textures;
7795 8280 float primglow;
7796 res.Add(new LSL_Float(0)); 8281 if (face == ScriptBaseClass.ALL_SIDES)
8282 {
8283 for (face = 0; face < GetNumberOfSides(part); face++)
8284 {
8285 primglow = tex.GetFace((uint)face).Glow;
8286 res.Add(new LSL_Float(primglow));
8287 }
8288 }
8289 else
8290 {
8291 primglow = tex.GetFace((uint)face).Glow;
8292 res.Add(new LSL_Float(primglow));
8293 }
7797 break; 8294 break;
7798 case (int)ScriptBaseClass.PRIM_TEXT: 8295 case (int)ScriptBaseClass.PRIM_TEXT:
7799 Color4 textColor = part.GetTextColor(); 8296 Color4 textColor = part.GetTextColor();
@@ -8330,28 +8827,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8330 { 8827 {
8331 m_host.AddScriptLPS(1); 8828 m_host.AddScriptLPS(1);
8332 8829
8333 lock (m_host.TaskInventory) 8830 m_host.TaskInventory.LockItemsForRead(true);
8831 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8334 { 8832 {
8335 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 8833 if (inv.Value.Name == item)
8336 { 8834 {
8337 if (inv.Value.Name == item) 8835 m_host.TaskInventory.LockItemsForRead(false);
8836 switch (mask)
8338 { 8837 {
8339 switch (mask) 8838 case 0:
8340 { 8839 return (int)inv.Value.BasePermissions;
8341 case 0: 8840 case 1:
8342 return (int)inv.Value.BasePermissions; 8841 return (int)inv.Value.CurrentPermissions;
8343 case 1: 8842 case 2:
8344 return (int)inv.Value.CurrentPermissions; 8843 return (int)inv.Value.GroupPermissions;
8345 case 2: 8844 case 3:
8346 return (int)inv.Value.GroupPermissions; 8845 return (int)inv.Value.EveryonePermissions;
8347 case 3: 8846 case 4:
8348 return (int)inv.Value.EveryonePermissions; 8847 return (int)inv.Value.NextPermissions;
8349 case 4:
8350 return (int)inv.Value.NextPermissions;
8351 }
8352 } 8848 }
8353 } 8849 }
8354 } 8850 }
8851 m_host.TaskInventory.LockItemsForRead(false);
8355 8852
8356 return -1; 8853 return -1;
8357 } 8854 }
@@ -8398,16 +8895,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8398 { 8895 {
8399 m_host.AddScriptLPS(1); 8896 m_host.AddScriptLPS(1);
8400 8897
8401 lock (m_host.TaskInventory) 8898 m_host.TaskInventory.LockItemsForRead(true);
8899 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8402 { 8900 {
8403 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 8901 if (inv.Value.Name == item)
8404 { 8902 {
8405 if (inv.Value.Name == item) 8903 m_host.TaskInventory.LockItemsForRead(false);
8406 { 8904 return inv.Value.CreatorID.ToString();
8407 return inv.Value.CreatorID.ToString();
8408 }
8409 } 8905 }
8410 } 8906 }
8907 m_host.TaskInventory.LockItemsForRead(false);
8411 8908
8412 llSay(0, "No item name '" + item + "'"); 8909 llSay(0, "No item name '" + item + "'");
8413 8910
@@ -8667,17 +9164,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8667 int width = 0; 9164 int width = 0;
8668 int height = 0; 9165 int height = 0;
8669 9166
8670 ParcelMediaCommandEnum? commandToSend = null; 9167 uint commandToSend = 0;
8671 float time = 0.0f; // default is from start 9168 float time = 0.0f; // default is from start
8672 9169
8673 ScenePresence presence = null; 9170 ScenePresence presence = null;
8674 9171
8675 for (int i = 0; i < commandList.Data.Length; i++) 9172 for (int i = 0; i < commandList.Data.Length; i++)
8676 { 9173 {
8677 ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i]; 9174 uint command = (uint)(commandList.GetLSLIntegerItem(i));
8678 switch (command) 9175 switch (command)
8679 { 9176 {
8680 case ParcelMediaCommandEnum.Agent: 9177 case (uint)ParcelMediaCommandEnum.Agent:
8681 // we send only to one agent 9178 // we send only to one agent
8682 if ((i + 1) < commandList.Length) 9179 if ((i + 1) < commandList.Length)
8683 { 9180 {
@@ -8694,25 +9191,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8694 } 9191 }
8695 break; 9192 break;
8696 9193
8697 case ParcelMediaCommandEnum.Loop: 9194 case (uint)ParcelMediaCommandEnum.Loop:
8698 loop = 1; 9195 loop = 1;
8699 commandToSend = command; 9196 commandToSend = command;
8700 update = true; //need to send the media update packet to set looping 9197 update = true; //need to send the media update packet to set looping
8701 break; 9198 break;
8702 9199
8703 case ParcelMediaCommandEnum.Play: 9200 case (uint)ParcelMediaCommandEnum.Play:
8704 loop = 0; 9201 loop = 0;
8705 commandToSend = command; 9202 commandToSend = command;
8706 update = true; //need to send the media update packet to make sure it doesn't loop 9203 update = true; //need to send the media update packet to make sure it doesn't loop
8707 break; 9204 break;
8708 9205
8709 case ParcelMediaCommandEnum.Pause: 9206 case (uint)ParcelMediaCommandEnum.Pause:
8710 case ParcelMediaCommandEnum.Stop: 9207 case (uint)ParcelMediaCommandEnum.Stop:
8711 case ParcelMediaCommandEnum.Unload: 9208 case (uint)ParcelMediaCommandEnum.Unload:
8712 commandToSend = command; 9209 commandToSend = command;
8713 break; 9210 break;
8714 9211
8715 case ParcelMediaCommandEnum.Url: 9212 case (uint)ParcelMediaCommandEnum.Url:
8716 if ((i + 1) < commandList.Length) 9213 if ((i + 1) < commandList.Length)
8717 { 9214 {
8718 if (commandList.Data[i + 1] is LSL_String) 9215 if (commandList.Data[i + 1] is LSL_String)
@@ -8725,7 +9222,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8725 } 9222 }
8726 break; 9223 break;
8727 9224
8728 case ParcelMediaCommandEnum.Texture: 9225 case (uint)ParcelMediaCommandEnum.Texture:
8729 if ((i + 1) < commandList.Length) 9226 if ((i + 1) < commandList.Length)
8730 { 9227 {
8731 if (commandList.Data[i + 1] is LSL_String) 9228 if (commandList.Data[i + 1] is LSL_String)
@@ -8738,7 +9235,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8738 } 9235 }
8739 break; 9236 break;
8740 9237
8741 case ParcelMediaCommandEnum.Time: 9238 case (uint)ParcelMediaCommandEnum.Time:
8742 if ((i + 1) < commandList.Length) 9239 if ((i + 1) < commandList.Length)
8743 { 9240 {
8744 if (commandList.Data[i + 1] is LSL_Float) 9241 if (commandList.Data[i + 1] is LSL_Float)
@@ -8750,7 +9247,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8750 } 9247 }
8751 break; 9248 break;
8752 9249
8753 case ParcelMediaCommandEnum.AutoAlign: 9250 case (uint)ParcelMediaCommandEnum.AutoAlign:
8754 if ((i + 1) < commandList.Length) 9251 if ((i + 1) < commandList.Length)
8755 { 9252 {
8756 if (commandList.Data[i + 1] is LSL_Integer) 9253 if (commandList.Data[i + 1] is LSL_Integer)
@@ -8764,7 +9261,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8764 } 9261 }
8765 break; 9262 break;
8766 9263
8767 case ParcelMediaCommandEnum.Type: 9264 case (uint)ParcelMediaCommandEnum.Type:
8768 if ((i + 1) < commandList.Length) 9265 if ((i + 1) < commandList.Length)
8769 { 9266 {
8770 if (commandList.Data[i + 1] is LSL_String) 9267 if (commandList.Data[i + 1] is LSL_String)
@@ -8777,7 +9274,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8777 } 9274 }
8778 break; 9275 break;
8779 9276
8780 case ParcelMediaCommandEnum.Desc: 9277 case (uint)ParcelMediaCommandEnum.Desc:
8781 if ((i + 1) < commandList.Length) 9278 if ((i + 1) < commandList.Length)
8782 { 9279 {
8783 if (commandList.Data[i + 1] is LSL_String) 9280 if (commandList.Data[i + 1] is LSL_String)
@@ -8790,7 +9287,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8790 } 9287 }
8791 break; 9288 break;
8792 9289
8793 case ParcelMediaCommandEnum.Size: 9290 case (uint)ParcelMediaCommandEnum.Size:
8794 if ((i + 2) < commandList.Length) 9291 if ((i + 2) < commandList.Length)
8795 { 9292 {
8796 if (commandList.Data[i + 1] is LSL_Integer) 9293 if (commandList.Data[i + 1] is LSL_Integer)
@@ -8860,7 +9357,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8860 } 9357 }
8861 } 9358 }
8862 9359
8863 if (commandToSend != null) 9360 if (commandToSend != 0)
8864 { 9361 {
8865 // the commandList contained a start/stop/... command, too 9362 // the commandList contained a start/stop/... command, too
8866 if (presence == null) 9363 if (presence == null)
@@ -8940,16 +9437,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8940 { 9437 {
8941 m_host.AddScriptLPS(1); 9438 m_host.AddScriptLPS(1);
8942 9439
8943 lock (m_host.TaskInventory) 9440 m_host.TaskInventory.LockItemsForRead(true);
9441 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8944 { 9442 {
8945 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9443 if (inv.Value.Name == name)
8946 { 9444 {
8947 if (inv.Value.Name == name) 9445 m_host.TaskInventory.LockItemsForRead(false);
8948 { 9446 return inv.Value.Type;
8949 return inv.Value.Type;
8950 }
8951 } 9447 }
8952 } 9448 }
9449 m_host.TaskInventory.LockItemsForRead(false);
8953 9450
8954 return -1; 9451 return -1;
8955 } 9452 }
@@ -8960,15 +9457,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8960 9457
8961 if (quick_pay_buttons.Data.Length < 4) 9458 if (quick_pay_buttons.Data.Length < 4)
8962 { 9459 {
8963 LSLError("List must have at least 4 elements"); 9460 int x;
8964 return; 9461 for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
9462 {
9463 quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
9464 }
8965 } 9465 }
8966 m_host.ParentGroup.RootPart.PayPrice[0]=price; 9466 int[] nPrice = new int[5];
8967 9467 nPrice[0]=price;
8968 m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0]; 9468 nPrice[1] = (LSL_Integer)quick_pay_buttons.Data[0];
8969 m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1]; 9469 nPrice[2] = (LSL_Integer)quick_pay_buttons.Data[1];
8970 m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2]; 9470 nPrice[3] = (LSL_Integer)quick_pay_buttons.Data[2];
8971 m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3]; 9471 nPrice[4] = (LSL_Integer)quick_pay_buttons.Data[3];
9472 m_host.ParentGroup.RootPart.PayPrice = nPrice;
8972 m_host.ParentGroup.HasGroupChanged = true; 9473 m_host.ParentGroup.HasGroupChanged = true;
8973 } 9474 }
8974 9475
@@ -8980,17 +9481,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8980 if (invItemID == UUID.Zero) 9481 if (invItemID == UUID.Zero)
8981 return new LSL_Vector(); 9482 return new LSL_Vector();
8982 9483
8983 lock (m_host.TaskInventory) 9484 m_host.TaskInventory.LockItemsForRead(true);
9485 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
8984 { 9486 {
8985 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 9487 m_host.TaskInventory.LockItemsForRead(false);
8986 return new LSL_Vector(); 9488 return new LSL_Vector();
9489 }
8987 9490
8988 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 9491 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
8989 { 9492 {
8990 ShoutError("No permissions to track the camera"); 9493 ShoutError("No permissions to track the camera");
8991 return new LSL_Vector(); 9494 m_host.TaskInventory.LockItemsForRead(false);
8992 } 9495 return new LSL_Vector();
8993 } 9496 }
9497 m_host.TaskInventory.LockItemsForRead(false);
8994 9498
8995 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 9499 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
8996 if (presence != null) 9500 if (presence != null)
@@ -9008,17 +9512,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9008 if (invItemID == UUID.Zero) 9512 if (invItemID == UUID.Zero)
9009 return new LSL_Rotation(); 9513 return new LSL_Rotation();
9010 9514
9011 lock (m_host.TaskInventory) 9515 m_host.TaskInventory.LockItemsForRead(true);
9516 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
9012 { 9517 {
9013 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 9518 m_host.TaskInventory.LockItemsForRead(false);
9014 return new LSL_Rotation(); 9519 return new LSL_Rotation();
9015 9520 }
9016 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 9521 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9017 { 9522 {
9018 ShoutError("No permissions to track the camera"); 9523 ShoutError("No permissions to track the camera");
9019 return new LSL_Rotation(); 9524 m_host.TaskInventory.LockItemsForRead(false);
9020 } 9525 return new LSL_Rotation();
9021 } 9526 }
9527 m_host.TaskInventory.LockItemsForRead(false);
9022 9528
9023 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 9529 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
9024 if (presence != null) 9530 if (presence != null)
@@ -9080,8 +9586,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9080 { 9586 {
9081 m_host.AddScriptLPS(1); 9587 m_host.AddScriptLPS(1);
9082 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 9588 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0);
9083 if (detectedParams == null) return; // only works on the first detected avatar 9589 if (detectedParams == null)
9084 9590 {
9591 if (m_host.IsAttachment == true)
9592 {
9593 detectedParams = new DetectParams();
9594 detectedParams.Key = m_host.OwnerID;
9595 }
9596 else
9597 {
9598 return;
9599 }
9600 }
9601
9085 ScenePresence avatar = World.GetScenePresence(detectedParams.Key); 9602 ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
9086 if (avatar != null) 9603 if (avatar != null)
9087 { 9604 {
@@ -9089,6 +9606,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9089 new Vector3((float)pos.x, (float)pos.y, (float)pos.z), 9606 new Vector3((float)pos.x, (float)pos.y, (float)pos.z),
9090 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z)); 9607 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z));
9091 } 9608 }
9609
9092 ScriptSleep(1000); 9610 ScriptSleep(1000);
9093 } 9611 }
9094 9612
@@ -9168,14 +9686,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9168 if (objectID == UUID.Zero) return; 9686 if (objectID == UUID.Zero) return;
9169 9687
9170 UUID agentID; 9688 UUID agentID;
9171 lock (m_host.TaskInventory) 9689 m_host.TaskInventory.LockItemsForRead(true);
9172 { 9690 // we need the permission first, to know which avatar we want to set the camera for
9173 // we need the permission first, to know which avatar we want to set the camera for 9691 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9174 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9175 9692
9176 if (agentID == UUID.Zero) return; 9693 if (agentID == UUID.Zero)
9177 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 9694 {
9695 m_host.TaskInventory.LockItemsForRead(false);
9696 return;
9697 }
9698 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
9699 {
9700 m_host.TaskInventory.LockItemsForRead(false);
9701 return;
9178 } 9702 }
9703 m_host.TaskInventory.LockItemsForRead(false);
9179 9704
9180 ScenePresence presence = World.GetScenePresence(agentID); 9705 ScenePresence presence = World.GetScenePresence(agentID);
9181 9706
@@ -9225,12 +9750,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9225 9750
9226 // we need the permission first, to know which avatar we want to clear the camera for 9751 // we need the permission first, to know which avatar we want to clear the camera for
9227 UUID agentID; 9752 UUID agentID;
9228 lock (m_host.TaskInventory) 9753 m_host.TaskInventory.LockItemsForRead(true);
9754 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9755 if (agentID == UUID.Zero)
9229 { 9756 {
9230 agentID = m_host.TaskInventory[invItemID].PermsGranter; 9757 m_host.TaskInventory.LockItemsForRead(false);
9231 if (agentID == UUID.Zero) return; 9758 return;
9232 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 9759 }
9760 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
9761 {
9762 m_host.TaskInventory.LockItemsForRead(false);
9763 return;
9233 } 9764 }
9765 m_host.TaskInventory.LockItemsForRead(false);
9234 9766
9235 ScenePresence presence = World.GetScenePresence(agentID); 9767 ScenePresence presence = World.GetScenePresence(agentID);
9236 9768
@@ -9687,15 +10219,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9687 10219
9688 internal UUID ScriptByName(string name) 10220 internal UUID ScriptByName(string name)
9689 { 10221 {
9690 lock (m_host.TaskInventory) 10222 m_host.TaskInventory.LockItemsForRead(true);
10223
10224 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
9691 { 10225 {
9692 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 10226 if (item.Type == 10 && item.Name == name)
9693 { 10227 {
9694 if (item.Type == 10 && item.Name == name) 10228 m_host.TaskInventory.LockItemsForRead(false);
9695 return item.ItemID; 10229 return item.ItemID;
9696 } 10230 }
9697 } 10231 }
9698 10232
10233 m_host.TaskInventory.LockItemsForRead(false);
10234
9699 return UUID.Zero; 10235 return UUID.Zero;
9700 } 10236 }
9701 10237
@@ -9736,6 +10272,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9736 { 10272 {
9737 m_host.AddScriptLPS(1); 10273 m_host.AddScriptLPS(1);
9738 10274
10275 //Clone is thread safe
9739 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 10276 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
9740 10277
9741 UUID assetID = UUID.Zero; 10278 UUID assetID = UUID.Zero;
@@ -9798,6 +10335,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9798 { 10335 {
9799 m_host.AddScriptLPS(1); 10336 m_host.AddScriptLPS(1);
9800 10337
10338 //Clone is thread safe
9801 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 10339 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
9802 10340
9803 UUID assetID = UUID.Zero; 10341 UUID assetID = UUID.Zero;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
index fe71ed5..1fa8c30 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
@@ -73,6 +73,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
73 if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false)) 73 if (m_ScriptEngine.Config.GetBoolean("AllowLightShareFunctions", false))
74 m_LSFunctionsEnabled = true; 74 m_LSFunctionsEnabled = true;
75 75
76 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false))
77 m_LSFunctionsEnabled = true;
78
76 m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>(); 79 m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
77 if (m_comms == null) 80 if (m_comms == null)
78 m_LSFunctionsEnabled = false; 81 m_LSFunctionsEnabled = false;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 01b64eb..db43902 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -769,18 +769,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
769 if (target != null) 769 if (target != null)
770 { 770 {
771 UUID animID=UUID.Zero; 771 UUID animID=UUID.Zero;
772 lock (m_host.TaskInventory) 772 m_host.TaskInventory.LockItemsForRead(true);
773 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
773 { 774 {
774 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 775 if (inv.Value.Name == animation)
775 { 776 {
776 if (inv.Value.Name == animation) 777 if (inv.Value.Type == (int)AssetType.Animation)
777 { 778 animID = inv.Value.AssetID;
778 if (inv.Value.Type == (int)AssetType.Animation) 779 continue;
779 animID = inv.Value.AssetID;
780 continue;
781 }
782 } 780 }
783 } 781 }
782 m_host.TaskInventory.LockItemsForRead(false);
784 if (animID == UUID.Zero) 783 if (animID == UUID.Zero)
785 target.Animator.AddAnimation(animation, m_host.UUID); 784 target.Animator.AddAnimation(animation, m_host.UUID);
786 else 785 else
@@ -802,18 +801,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
802 if (target != null) 801 if (target != null)
803 { 802 {
804 UUID animID=UUID.Zero; 803 UUID animID=UUID.Zero;
805 lock (m_host.TaskInventory) 804 m_host.TaskInventory.LockItemsForRead(true);
805 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
806 { 806 {
807 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 807 if (inv.Value.Name == animation)
808 { 808 {
809 if (inv.Value.Name == animation) 809 if (inv.Value.Type == (int)AssetType.Animation)
810 { 810 animID = inv.Value.AssetID;
811 if (inv.Value.Type == (int)AssetType.Animation) 811 continue;
812 animID = inv.Value.AssetID;
813 continue;
814 }
815 } 812 }
816 } 813 }
814 m_host.TaskInventory.LockItemsForRead(false);
817 815
818 if (animID == UUID.Zero) 816 if (animID == UUID.Zero)
819 target.Animator.RemoveAnimation(animation); 817 target.Animator.RemoveAnimation(animation);
@@ -1664,6 +1662,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1664 1662
1665 if (!UUID.TryParse(name, out assetID)) 1663 if (!UUID.TryParse(name, out assetID))
1666 { 1664 {
1665 m_host.TaskInventory.LockItemsForRead(true);
1667 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1666 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1668 { 1667 {
1669 if (item.Type == 7 && item.Name == name) 1668 if (item.Type == 7 && item.Name == name)
@@ -1671,6 +1670,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1671 assetID = item.AssetID; 1670 assetID = item.AssetID;
1672 } 1671 }
1673 } 1672 }
1673 m_host.TaskInventory.LockItemsForRead(false);
1674 } 1674 }
1675 1675
1676 if (assetID == UUID.Zero) 1676 if (assetID == UUID.Zero)
@@ -1717,6 +1717,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1717 1717
1718 if (!UUID.TryParse(name, out assetID)) 1718 if (!UUID.TryParse(name, out assetID))
1719 { 1719 {
1720 m_host.TaskInventory.LockItemsForRead(true);
1720 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1721 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1721 { 1722 {
1722 if (item.Type == 7 && item.Name == name) 1723 if (item.Type == 7 && item.Name == name)
@@ -1724,6 +1725,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1724 assetID = item.AssetID; 1725 assetID = item.AssetID;
1725 } 1726 }
1726 } 1727 }
1728 m_host.TaskInventory.LockItemsForRead(false);
1727 } 1729 }
1728 1730
1729 if (assetID == UUID.Zero) 1731 if (assetID == UUID.Zero)
@@ -1774,6 +1776,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1774 1776
1775 if (!UUID.TryParse(name, out assetID)) 1777 if (!UUID.TryParse(name, out assetID))
1776 { 1778 {
1779 m_host.TaskInventory.LockItemsForRead(true);
1777 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1780 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1778 { 1781 {
1779 if (item.Type == 7 && item.Name == name) 1782 if (item.Type == 7 && item.Name == name)
@@ -1781,6 +1784,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1781 assetID = item.AssetID; 1784 assetID = item.AssetID;
1782 } 1785 }
1783 } 1786 }
1787 m_host.TaskInventory.LockItemsForRead(false);
1784 } 1788 }
1785 1789
1786 if (assetID == UUID.Zero) 1790 if (assetID == UUID.Zero)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index 5c2abd5..a5b1124 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -204,7 +204,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
204 // Is the sensor type is AGENT and not SCRIPTED then include agents 204 // Is the sensor type is AGENT and not SCRIPTED then include agents
205 if ((ts.type & AGENT) != 0 && (ts.type & SCRIPTED) == 0) 205 if ((ts.type & AGENT) != 0 && (ts.type & SCRIPTED) == 0)
206 { 206 {
207 sensedEntities.AddRange(doAgentSensor(ts)); 207 sensedEntities.AddRange(doAgentSensor(ts));
208 } 208 }
209 209
210 // If SCRIPTED or PASSIVE or ACTIVE check objects 210 // If SCRIPTED or PASSIVE or ACTIVE check objects
@@ -309,6 +309,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
309 // in mouselook. 309 // in mouselook.
310 310
311 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar); 311 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar);
312 fromRegionPos = avatar.AbsolutePosition;
312 q = avatar.Rotation; 313 q = avatar.Rotation;
313 } 314 }
314 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 315 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
@@ -422,6 +423,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
422 SceneObjectPart SensePoint = ts.host; 423 SceneObjectPart SensePoint = ts.host;
423 Vector3 fromRegionPos = SensePoint.AbsolutePosition; 424 Vector3 fromRegionPos = SensePoint.AbsolutePosition;
424 Quaternion q = SensePoint.RotationOffset; 425 Quaternion q = SensePoint.RotationOffset;
426 if (SensePoint.ParentGroup.RootPart.IsAttachment)
427 {
428 // In attachments, the sensor cone always orients with the
429 // avatar rotation. This may include a nonzero elevation if
430 // in mouselook.
431
432 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar);
433 fromRegionPos = avatar.AbsolutePosition;
434 q = avatar.Rotation;
435 }
425 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 436 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
426 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); 437 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
427 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); 438 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
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/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 78ee43c..c8f3623 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -81,7 +81,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
81 // Avatar Info Commands 81 // Avatar Info Commands
82 string osGetAgentIP(string agent); 82 string osGetAgentIP(string agent);
83 LSL_List osGetAgents(); 83 LSL_List osGetAgents();
84 84
85 // Teleport commands 85 // Teleport commands
86 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 86 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
87 void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 87 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/Executor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
index 9615315..943d7a2 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;
@@ -132,6 +133,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
132 return (eventFlags); 133 return (eventFlags);
133 } 134 }
134 135
136 [DebuggerNonUserCode]
135 public void ExecuteEvent(string state, string FunctionName, object[] args) 137 public void ExecuteEvent(string state, string FunctionName, object[] args)
136 { 138 {
137 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. 139 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index dba6502..96f6486 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -274,6 +274,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
274 public const int CHANGED_ALLOWED_DROP = 64; 274 public const int CHANGED_ALLOWED_DROP = 64;
275 public const int CHANGED_OWNER = 128; 275 public const int CHANGED_OWNER = 128;
276 public const int CHANGED_REGION_RESTART = 256; 276 public const int CHANGED_REGION_RESTART = 256;
277 public const int CHANGED_REGION_START = 256; //LL Changed the constant from CHANGED_REGION_RESTART
277 public const int CHANGED_REGION = 512; 278 public const int CHANGED_REGION = 512;
278 public const int CHANGED_TELEPORT = 1024; 279 public const int CHANGED_TELEPORT = 1024;
279 public const int CHANGED_ANIMATION = 16384; 280 public const int CHANGED_ANIMATION = 16384;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 3339995..e86d08c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Diagnostics; //for [DebuggerNonUserCode]
29using System.Runtime.Remoting.Lifetime; 30using System.Runtime.Remoting.Lifetime;
30using System.Threading; 31using System.Threading;
31using System.Reflection; 32using System.Reflection;
@@ -309,6 +310,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
309 m_LSL_Functions.llDialog(avatar, message, buttons, chat_channel); 310 m_LSL_Functions.llDialog(avatar, message, buttons, chat_channel);
310 } 311 }
311 312
313 [DebuggerNonUserCode]
312 public void llDie() 314 public void llDie()
313 { 315 {
314 m_LSL_Functions.llDie(); 316 m_LSL_Functions.llDie();
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
index f8dbe03..8280ca5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
@@ -72,5 +72,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
72 { 72 {
73 return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target); 73 return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target);
74 } 74 }
75
76 public LSL_List cmGetWindlightScene(LSL_List rules)
77 {
78 return m_LS_Functions.lsGetWindlightScene(rules);
79 }
80
81 public int cmSetWindlightScene(LSL_List rules)
82 {
83 return m_LS_Functions.lsSetWindlightScene(rules);
84 }
85
86 public int cmSetWindlightSceneTargeted(LSL_List rules, key target)
87 {
88 return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target);
89 }
75 } 90 }
76} 91}
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 3dd381d..b348403 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;
@@ -238,13 +239,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
238 239
239 if (part != null) 240 if (part != null)
240 { 241 {
241 lock (part.TaskInventory) 242 part.TaskInventory.LockItemsForRead(true);
243 if (part.TaskInventory.ContainsKey(m_ItemID))
242 { 244 {
243 if (part.TaskInventory.ContainsKey(m_ItemID)) 245 m_thisScriptTask = part.TaskInventory[m_ItemID];
244 {
245 m_thisScriptTask = part.TaskInventory[m_ItemID];
246 }
247 } 246 }
247 part.TaskInventory.LockItemsForRead(false);
248 } 248 }
249 249
250 ApiManager am = new ApiManager(); 250 ApiManager am = new ApiManager();
@@ -429,14 +429,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
429 { 429 {
430 int permsMask; 430 int permsMask;
431 UUID permsGranter; 431 UUID permsGranter;
432 lock (part.TaskInventory) 432 part.TaskInventory.LockItemsForRead(true);
433 if (!part.TaskInventory.ContainsKey(m_ItemID))
433 { 434 {
434 if (!part.TaskInventory.ContainsKey(m_ItemID)) 435 part.TaskInventory.LockItemsForRead(false);
435 return; 436 return;
436
437 permsGranter = part.TaskInventory[m_ItemID].PermsGranter;
438 permsMask = part.TaskInventory[m_ItemID].PermsMask;
439 } 437 }
438 permsGranter = part.TaskInventory[m_ItemID].PermsGranter;
439 permsMask = part.TaskInventory[m_ItemID].PermsMask;
440 part.TaskInventory.LockItemsForRead(false);
440 441
441 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 442 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
442 { 443 {
@@ -545,6 +546,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
545 return true; 546 return true;
546 } 547 }
547 548
549 [DebuggerNonUserCode] //Prevents the debugger from farting in this function
548 public void SetState(string state) 550 public void SetState(string state)
549 { 551 {
550 if (state == State) 552 if (state == State)
@@ -556,7 +558,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
556 new DetectParams[0])); 558 new DetectParams[0]));
557 PostEvent(new EventParams("state_entry", new Object[0], 559 PostEvent(new EventParams("state_entry", new Object[0],
558 new DetectParams[0])); 560 new DetectParams[0]));
559 561
560 throw new EventAbortException(); 562 throw new EventAbortException();
561 } 563 }
562 564
@@ -639,14 +641,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
639 /// <returns></returns> 641 /// <returns></returns>
640 public object EventProcessor() 642 public object EventProcessor()
641 { 643 {
642 if (m_Suspended) 644 EventParams data = null;
643 return 0;
644 645
645 lock (m_Script) 646 lock (m_EventQueue)
646 { 647 {
647 EventParams data = null; 648 if (m_Suspended)
649 return 0;
648 650
649 lock (m_EventQueue) 651 lock (m_Script)
650 { 652 {
651 data = (EventParams) m_EventQueue.Dequeue(); 653 data = (EventParams) m_EventQueue.Dequeue();
652 if (data == null) // Shouldn't happen 654 if (data == null) // Shouldn't happen
@@ -672,6 +674,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
672 if (data.EventName == "collision") 674 if (data.EventName == "collision")
673 m_CollisionInQueue = false; 675 m_CollisionInQueue = false;
674 } 676 }
677 }
678 lock(m_Script)
679 {
675 680
676 //m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this); 681 //m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this);
677 682
@@ -828,6 +833,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
828 new Object[0], new DetectParams[0])); 833 new Object[0], new DetectParams[0]));
829 } 834 }
830 835
836 [DebuggerNonUserCode] //Stops the VS debugger from farting in this function
831 public void ApiResetScript() 837 public void ApiResetScript()
832 { 838 {
833 // bool running = Running; 839 // bool running = Running;
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 1ea52c5..212dbe3 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -83,19 +83,19 @@ namespace OpenSim.Region.ScriptEngine.Shared
83 83
84 public override string ToString() 84 public override string ToString()
85 { 85 {
86 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z); 86 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}>", x, y, z);
87 return s; 87 return s;
88 } 88 }
89 89
90 public static explicit operator LSLString(Vector3 vec) 90 public static explicit operator LSLString(Vector3 vec)
91 { 91 {
92 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); 92 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}>", vec.x, vec.y, vec.z);
93 return new LSLString(s); 93 return new LSLString(s);
94 } 94 }
95 95
96 public static explicit operator string(Vector3 vec) 96 public static explicit operator string(Vector3 vec)
97 { 97 {
98 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); 98 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}>", vec.x, vec.y, vec.z);
99 return s; 99 return s;
100 } 100 }
101 101
@@ -337,19 +337,19 @@ namespace OpenSim.Region.ScriptEngine.Shared
337 337
338 public override string ToString() 338 public override string ToString()
339 { 339 {
340 string st=String.Format(Culture.FormatProvider, "<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s); 340 string st=String.Format(Culture.FormatProvider, "<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", x, y, z, s);
341 return st; 341 return st;
342 } 342 }
343 343
344 public static explicit operator string(Quaternion r) 344 public static explicit operator string(Quaternion r)
345 { 345 {
346 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); 346 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", r.x, r.y, r.z, r.s);
347 return s; 347 return s;
348 } 348 }
349 349
350 public static explicit operator LSLString(Quaternion r) 350 public static explicit operator LSLString(Quaternion r)
351 { 351 {
352 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); 352 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", r.x, r.y, r.z, r.s);
353 return new LSLString(s); 353 return new LSLString(s);
354 } 354 }
355 355
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 808cf82..bbaf923 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 =
@@ -124,6 +127,71 @@ namespace OpenSim.Region.ScriptEngine.XEngine
124 IWorkItemResult m_CurrentCompile = null; 127 IWorkItemResult m_CurrentCompile = null;
125 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>(); 128 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>();
126 129
130 private void lockScriptsForRead(bool locked)
131 {
132 if (locked)
133 {
134 if (m_scriptsLock.RecursiveReadCount > 0)
135 {
136 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.");
137 m_scriptsLock.ExitReadLock();
138 }
139 if (m_scriptsLock.RecursiveWriteCount > 0)
140 {
141 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
142 m_scriptsLock.ExitWriteLock();
143 }
144
145 while (!m_scriptsLock.TryEnterReadLock(60000))
146 {
147 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.");
148 if (m_scriptsLock.IsWriteLockHeld)
149 {
150 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
151 }
152 }
153 }
154 else
155 {
156 if (m_scriptsLock.RecursiveReadCount > 0)
157 {
158 m_scriptsLock.ExitReadLock();
159 }
160 }
161 }
162 private void lockScriptsForWrite(bool locked)
163 {
164 if (locked)
165 {
166 if (m_scriptsLock.RecursiveReadCount > 0)
167 {
168 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.");
169 m_scriptsLock.ExitReadLock();
170 }
171 if (m_scriptsLock.RecursiveWriteCount > 0)
172 {
173 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
174 m_scriptsLock.ExitWriteLock();
175 }
176
177 while (!m_scriptsLock.TryEnterWriteLock(60000))
178 {
179 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.");
180 if (m_scriptsLock.IsWriteLockHeld)
181 {
182 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
183 }
184 }
185 }
186 else
187 {
188 if (m_scriptsLock.RecursiveWriteCount > 0)
189 {
190 m_scriptsLock.ExitWriteLock();
191 }
192 }
193 }
194
127 public string ScriptEngineName 195 public string ScriptEngineName
128 { 196 {
129 get { return "XEngine"; } 197 get { return "XEngine"; }
@@ -263,43 +331,45 @@ namespace OpenSim.Region.ScriptEngine.XEngine
263 331
264 public void RemoveRegion(Scene scene) 332 public void RemoveRegion(Scene scene)
265 { 333 {
266 lock (m_Scripts) 334 lockScriptsForRead(true);
335 foreach (IScriptInstance instance in m_Scripts.Values)
267 { 336 {
268 foreach (IScriptInstance instance in m_Scripts.Values) 337 // Force a final state save
338 //
339 if (m_Assemblies.ContainsKey(instance.AssetID))
269 { 340 {
270 // Force a final state save 341 string assembly = m_Assemblies[instance.AssetID];
271 // 342 instance.SaveState(assembly);
272 if (m_Assemblies.ContainsKey(instance.AssetID)) 343 }
273 {
274 string assembly = m_Assemblies[instance.AssetID];
275 instance.SaveState(assembly);
276 }
277 344
278 // Clear the event queue and abort the instance thread 345 // Clear the event queue and abort the instance thread
279 // 346 //
280 instance.ClearQueue(); 347 instance.ClearQueue();
281 instance.Stop(0); 348 instance.Stop(0);
282 349
283 // Release events, timer, etc 350 // Release events, timer, etc
284 // 351 //
285 instance.DestroyScriptInstance(); 352 instance.DestroyScriptInstance();
286 353
287 // Unload scripts and app domains 354 // Unload scripts and app domains
288 // Must be done explicitly because they have infinite 355 // Must be done explicitly because they have infinite
289 // lifetime 356 // lifetime
290 // 357 //
291 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 358 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
292 if (m_DomainScripts[instance.AppDomain].Count == 0) 359 if (m_DomainScripts[instance.AppDomain].Count == 0)
293 { 360 {
294 m_DomainScripts.Remove(instance.AppDomain); 361 m_DomainScripts.Remove(instance.AppDomain);
295 UnloadAppDomain(instance.AppDomain); 362 UnloadAppDomain(instance.AppDomain);
296 }
297 } 363 }
298 m_Scripts.Clear();
299 m_PrimObjects.Clear();
300 m_Assemblies.Clear();
301 m_DomainScripts.Clear();
302 } 364 }
365 lockScriptsForRead(false);
366 lockScriptsForWrite(true);
367 m_Scripts.Clear();
368 lockScriptsForWrite(false);
369 m_PrimObjects.Clear();
370 m_Assemblies.Clear();
371 m_DomainScripts.Clear();
372
303 lock (m_ScriptEngines) 373 lock (m_ScriptEngines)
304 { 374 {
305 m_ScriptEngines.Remove(this); 375 m_ScriptEngines.Remove(this);
@@ -358,22 +428,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine
358 428
359 List<IScriptInstance> instances = new List<IScriptInstance>(); 429 List<IScriptInstance> instances = new List<IScriptInstance>();
360 430
361 lock (m_Scripts) 431 lockScriptsForRead(true);
362 { 432 foreach (IScriptInstance instance in m_Scripts.Values)
363 foreach (IScriptInstance instance in m_Scripts.Values)
364 instances.Add(instance); 433 instances.Add(instance);
365 } 434 lockScriptsForRead(false);
366 435
367 foreach (IScriptInstance i in instances) 436 foreach (IScriptInstance i in instances)
368 { 437 {
369 string assembly = String.Empty; 438 string assembly = String.Empty;
370 439
371 lock (m_Scripts) 440
372 {
373 if (!m_Assemblies.ContainsKey(i.AssetID)) 441 if (!m_Assemblies.ContainsKey(i.AssetID))
374 continue; 442 continue;
375 assembly = m_Assemblies[i.AssetID]; 443 assembly = m_Assemblies[i.AssetID];
376 } 444
377 445
378 i.SaveState(assembly); 446 i.SaveState(assembly);
379 } 447 }
@@ -701,111 +769,117 @@ namespace OpenSim.Region.ScriptEngine.XEngine
701 } 769 }
702 } 770 }
703 771
704 lock (m_Scripts) 772
773
774 ScriptInstance instance = null;
775 // Create the object record
776 lockScriptsForRead(true);
777 if ((!m_Scripts.ContainsKey(itemID)) ||
778 (m_Scripts[itemID].AssetID != assetID))
705 { 779 {
706 ScriptInstance instance = null; 780 lockScriptsForRead(false);
707 // Create the object record
708 781
709 if ((!m_Scripts.ContainsKey(itemID)) || 782 UUID appDomain = assetID;
710 (m_Scripts[itemID].AssetID != assetID))
711 {
712 UUID appDomain = assetID;
713 783
714 if (part.ParentGroup.IsAttachment) 784 if (part.ParentGroup.IsAttachment)
715 appDomain = part.ParentGroup.RootPart.UUID; 785 appDomain = part.ParentGroup.RootPart.UUID;
716 786
717 if (!m_AppDomains.ContainsKey(appDomain)) 787 if (!m_AppDomains.ContainsKey(appDomain))
788 {
789 try
718 { 790 {
719 try 791 AppDomainSetup appSetup = new AppDomainSetup();
720 { 792 // appSetup.ApplicationBase = Path.Combine(
721 AppDomainSetup appSetup = new AppDomainSetup(); 793 // "ScriptEngines",
722// appSetup.ApplicationBase = Path.Combine( 794 // m_Scene.RegionInfo.RegionID.ToString());
723// "ScriptEngines", 795
724// m_Scene.RegionInfo.RegionID.ToString()); 796 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
725 797 Evidence evidence = new Evidence(baseEvidence);
726 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; 798
727 Evidence evidence = new Evidence(baseEvidence); 799 AppDomain sandbox;
728 800 if (m_AppDomainLoading)
729 AppDomain sandbox; 801 sandbox = AppDomain.CreateDomain(
730 if (m_AppDomainLoading) 802 m_Scene.RegionInfo.RegionID.ToString(),
731 sandbox = AppDomain.CreateDomain( 803 evidence, appSetup);
732 m_Scene.RegionInfo.RegionID.ToString(), 804 else
733 evidence, appSetup); 805 sandbox = AppDomain.CurrentDomain;
734 else 806
735 sandbox = AppDomain.CurrentDomain; 807 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
736 808 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
737 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); 809 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet");
738 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); 810 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet);
739 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); 811 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement);
740 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); 812 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup;
741 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); 813 //sandbox.SetAppDomainPolicy(sandboxPolicy);
742 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup; 814
743 //sandbox.SetAppDomainPolicy(sandboxPolicy); 815 m_AppDomains[appDomain] = sandbox;
744 816
745 m_AppDomains[appDomain] = sandbox; 817 m_AppDomains[appDomain].AssemblyResolve +=
746 818 new ResolveEventHandler(
747 m_AppDomains[appDomain].AssemblyResolve += 819 AssemblyResolver.OnAssemblyResolve);
748 new ResolveEventHandler( 820 m_DomainScripts[appDomain] = new List<UUID>();
749 AssemblyResolver.OnAssemblyResolve);
750 m_DomainScripts[appDomain] = new List<UUID>();
751 }
752 catch (Exception e)
753 {
754 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
755 m_ScriptErrorMessage += "Exception creating app domain:\n";
756 m_ScriptFailCount++;
757 lock (m_AddingAssemblies)
758 {
759 m_AddingAssemblies[assembly]--;
760 }
761 return false;
762 }
763 } 821 }
764 m_DomainScripts[appDomain].Add(itemID); 822 catch (Exception e)
765
766 instance = new ScriptInstance(this, part,
767 itemID, assetID, assembly,
768 m_AppDomains[appDomain],
769 part.ParentGroup.RootPart.Name,
770 item.Name, startParam, postOnRez,
771 stateSource, m_MaxScriptQueue);
772
773 m_log.DebugFormat("[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}",
774 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, part.ParentGroup.RootPart.AbsolutePosition.ToString());
775
776 if (presence != null)
777 { 823 {
778 ShowScriptSaveResponse(item.OwnerID, 824 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
779 assetID, "Compile successful", true); 825 m_ScriptErrorMessage += "Exception creating app domain:\n";
826 m_ScriptFailCount++;
827 lock (m_AddingAssemblies)
828 {
829 m_AddingAssemblies[assembly]--;
830 }
831 return false;
780 } 832 }
833 }
834 m_DomainScripts[appDomain].Add(itemID);
781 835
782 instance.AppDomain = appDomain; 836 instance = new ScriptInstance(this, part,
783 instance.LineMap = linemap; 837 itemID, assetID, assembly,
838 m_AppDomains[appDomain],
839 part.ParentGroup.RootPart.Name,
840 item.Name, startParam, postOnRez,
841 stateSource, m_MaxScriptQueue);
784 842
785 m_Scripts[itemID] = instance; 843 m_log.DebugFormat("[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}",
786 } 844 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, part.ParentGroup.RootPart.AbsolutePosition.ToString());
787 845
788 lock (m_PrimObjects) 846 if (presence != null)
789 { 847 {
790 if (!m_PrimObjects.ContainsKey(localID)) 848 ShowScriptSaveResponse(item.OwnerID,
791 m_PrimObjects[localID] = new List<UUID>(); 849 assetID, "Compile successful", true);
850 }
792 851
793 if (!m_PrimObjects[localID].Contains(itemID)) 852 instance.AppDomain = appDomain;
794 m_PrimObjects[localID].Add(itemID); 853 instance.LineMap = linemap;
854 lockScriptsForWrite(true);
855 m_Scripts[itemID] = instance;
856 lockScriptsForWrite(false);
857 }
858 else
859 {
860 lockScriptsForRead(false);
861 }
862 lock (m_PrimObjects)
863 {
864 if (!m_PrimObjects.ContainsKey(localID))
865 m_PrimObjects[localID] = new List<UUID>();
795 866
796 } 867 if (!m_PrimObjects[localID].Contains(itemID))
868 m_PrimObjects[localID].Add(itemID);
797 869
798 if (!m_Assemblies.ContainsKey(assetID)) 870 }
799 m_Assemblies[assetID] = assembly;
800 871
801 lock (m_AddingAssemblies) 872 if (!m_Assemblies.ContainsKey(assetID))
802 { 873 m_Assemblies[assetID] = assembly;
803 m_AddingAssemblies[assembly]--;
804 }
805 874
806 if (instance!=null) 875 lock (m_AddingAssemblies)
807 instance.Init(); 876 {
877 m_AddingAssemblies[assembly]--;
808 } 878 }
879
880 if (instance!=null)
881 instance.Init();
882
809 return true; 883 return true;
810 } 884 }
811 885
@@ -818,60 +892,65 @@ namespace OpenSim.Region.ScriptEngine.XEngine
818 m_CompileDict.Remove(itemID); 892 m_CompileDict.Remove(itemID);
819 } 893 }
820 894
821 lock (m_Scripts) 895 lockScriptsForRead(true);
896 // Do we even have it?
897 if (!m_Scripts.ContainsKey(itemID))
822 { 898 {
823 // Do we even have it? 899 lockScriptsForRead(false);
824 if (!m_Scripts.ContainsKey(itemID)) 900 return;
825 return; 901 }
826 902
827 IScriptInstance instance=m_Scripts[itemID];
828 m_Scripts.Remove(itemID);
829 903
830 instance.ClearQueue(); 904 IScriptInstance instance=m_Scripts[itemID];
831 instance.Stop(0); 905 lockScriptsForRead(false);
906 lockScriptsForWrite(true);
907 m_Scripts.Remove(itemID);
908 lockScriptsForWrite(false);
909 instance.ClearQueue();
910 instance.Stop(0);
832 911
833// bool objectRemoved = false; 912// bool objectRemoved = false;
834 913
835 lock (m_PrimObjects) 914 lock (m_PrimObjects)
915 {
916 // Remove the script from it's prim
917 if (m_PrimObjects.ContainsKey(localID))
836 { 918 {
837 // Remove the script from it's prim 919 // Remove inventory item record
838 if (m_PrimObjects.ContainsKey(localID)) 920 if (m_PrimObjects[localID].Contains(itemID))
839 { 921 m_PrimObjects[localID].Remove(itemID);
840 // Remove inventory item record
841 if (m_PrimObjects[localID].Contains(itemID))
842 m_PrimObjects[localID].Remove(itemID);
843 922
844 // If there are no more scripts, remove prim 923 // If there are no more scripts, remove prim
845 if (m_PrimObjects[localID].Count == 0) 924 if (m_PrimObjects[localID].Count == 0)
846 { 925 {
847 m_PrimObjects.Remove(localID); 926 m_PrimObjects.Remove(localID);
848// objectRemoved = true; 927// objectRemoved = true;
849 }
850 } 928 }
851 } 929 }
930 }
852 931
853 instance.RemoveState(); 932 instance.RemoveState();
854 instance.DestroyScriptInstance(); 933 instance.DestroyScriptInstance();
855
856 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
857 if (m_DomainScripts[instance.AppDomain].Count == 0)
858 {
859 m_DomainScripts.Remove(instance.AppDomain);
860 UnloadAppDomain(instance.AppDomain);
861 }
862 934
863 instance = null; 935 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
936 if (m_DomainScripts[instance.AppDomain].Count == 0)
937 {
938 m_DomainScripts.Remove(instance.AppDomain);
939 UnloadAppDomain(instance.AppDomain);
940 }
864 941
865 ObjectRemoved handlerObjectRemoved = OnObjectRemoved; 942 instance = null;
866 if (handlerObjectRemoved != null)
867 {
868 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID);
869 handlerObjectRemoved(part.UUID);
870 }
871 943
872 CleanAssemblies(); 944 ObjectRemoved handlerObjectRemoved = OnObjectRemoved;
945 if (handlerObjectRemoved != null)
946 {
947 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID);
948 handlerObjectRemoved(part.UUID);
873 } 949 }
874 950
951 CleanAssemblies();
952
953
875 ScriptRemoved handlerScriptRemoved = OnScriptRemoved; 954 ScriptRemoved handlerScriptRemoved = OnScriptRemoved;
876 if (handlerScriptRemoved != null) 955 if (handlerScriptRemoved != null)
877 handlerScriptRemoved(itemID); 956 handlerScriptRemoved(itemID);
@@ -1123,12 +1202,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1123 private IScriptInstance GetInstance(UUID itemID) 1202 private IScriptInstance GetInstance(UUID itemID)
1124 { 1203 {
1125 IScriptInstance instance; 1204 IScriptInstance instance;
1126 lock (m_Scripts) 1205 lockScriptsForRead(true);
1206 if (!m_Scripts.ContainsKey(itemID))
1127 { 1207 {
1128 if (!m_Scripts.ContainsKey(itemID)) 1208 lockScriptsForRead(false);
1129 return null; 1209 return null;
1130 instance = m_Scripts[itemID];
1131 } 1210 }
1211 instance = m_Scripts[itemID];
1212 lockScriptsForRead(false);
1132 return instance; 1213 return instance;
1133 } 1214 }
1134 1215
@@ -1152,6 +1233,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1152 return false; 1233 return false;
1153 } 1234 }
1154 1235
1236 [DebuggerNonUserCode]
1155 public void ApiResetScript(UUID itemID) 1237 public void ApiResetScript(UUID itemID)
1156 { 1238 {
1157 IScriptInstance instance = GetInstance(itemID); 1239 IScriptInstance instance = GetInstance(itemID);
@@ -1203,6 +1285,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1203 return UUID.Zero; 1285 return UUID.Zero;
1204 } 1286 }
1205 1287
1288 [DebuggerNonUserCode]
1206 public void SetState(UUID itemID, string newState) 1289 public void SetState(UUID itemID, string newState)
1207 { 1290 {
1208 IScriptInstance instance = GetInstance(itemID); 1291 IScriptInstance instance = GetInstance(itemID);
@@ -1223,11 +1306,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1223 { 1306 {
1224 List<IScriptInstance> instances = new List<IScriptInstance>(); 1307 List<IScriptInstance> instances = new List<IScriptInstance>();
1225 1308
1226 lock (m_Scripts) 1309 lockScriptsForRead(true);
1227 { 1310 foreach (IScriptInstance instance in m_Scripts.Values)
1228 foreach (IScriptInstance instance in m_Scripts.Values)
1229 instances.Add(instance); 1311 instances.Add(instance);
1230 } 1312 lockScriptsForRead(false);
1231 1313
1232 foreach (IScriptInstance i in instances) 1314 foreach (IScriptInstance i in instances)
1233 { 1315 {