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/AsyncCommandManager.cs20
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs1876
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs1011
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs53
-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.cs28
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs341
15 files changed, 2067 insertions, 1371 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
index ee32755..61e4934 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
@@ -248,6 +248,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
248 248
249 } 249 }
250 250
251 public static void StateChange(IScriptEngine engine, uint localID, UUID itemID)
252 {
253 // Remove a specific script
254
255 // Remove dataserver events
256 m_Dataserver[engine].RemoveEvents(localID, itemID);
257
258 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>();
259 if (comms != null)
260 comms.DeleteListener(itemID);
261
262 IXMLRPC xmlrpc = engine.World.RequestModuleInterface<IXMLRPC>();
263 xmlrpc.DeleteChannels(itemID);
264 xmlrpc.CancelSRDRequests(itemID);
265
266 // Remove Sensors
267 m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID);
268
269 }
270
251 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID) 271 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID)
252 { 272 {
253 List<Object> data = new List<Object>(); 273 List<Object> data = new List<Object>();
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 21604d0..a407ef3 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;
@@ -81,7 +82,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
81 /// </summary> 82 /// </summary>
82 public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi 83 public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
83 { 84 {
84 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 85// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
85 protected IScriptEngine m_ScriptEngine; 86 protected IScriptEngine m_ScriptEngine;
86 protected SceneObjectPart m_host; 87 protected SceneObjectPart m_host;
87 protected uint m_localID; 88 protected uint m_localID;
@@ -99,6 +100,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
99 protected int m_notecardLineReadCharsMax = 255; 100 protected int m_notecardLineReadCharsMax = 255;
100 protected int m_scriptConsoleChannel = 0; 101 protected int m_scriptConsoleChannel = 0;
101 protected bool m_scriptConsoleChannelEnabled = false; 102 protected bool m_scriptConsoleChannelEnabled = false;
103 protected bool m_debuggerSafe = false;
102 protected IUrlModule m_UrlModule = null; 104 protected IUrlModule m_UrlModule = null;
103 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = 105 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache =
104 new Dictionary<UUID, UserInfoCacheEntry>(); 106 new Dictionary<UUID, UserInfoCacheEntry>();
@@ -109,6 +111,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
109 m_host = host; 111 m_host = host;
110 m_localID = localID; 112 m_localID = localID;
111 m_itemID = itemID; 113 m_itemID = itemID;
114 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
112 115
113 m_ScriptDelayFactor = 116 m_ScriptDelayFactor =
114 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); 117 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
@@ -161,6 +164,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
161 get { return m_ScriptEngine.World; } 164 get { return m_ScriptEngine.World; }
162 } 165 }
163 166
167 [DebuggerNonUserCode]
164 public void state(string newState) 168 public void state(string newState)
165 { 169 {
166 m_ScriptEngine.SetState(m_itemID, newState); 170 m_ScriptEngine.SetState(m_itemID, newState);
@@ -170,6 +174,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
170 /// Reset the named script. The script must be present 174 /// Reset the named script. The script must be present
171 /// in the same prim. 175 /// in the same prim.
172 /// </summary> 176 /// </summary>
177 [DebuggerNonUserCode]
173 public void llResetScript() 178 public void llResetScript()
174 { 179 {
175 m_host.AddScriptLPS(1); 180 m_host.AddScriptLPS(1);
@@ -226,9 +231,62 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
226 } 231 }
227 } 232 }
228 233
234 public List<ScenePresence> GetLinkAvatars(int linkType)
235 {
236 List<ScenePresence> ret = new List<ScenePresence>();
237 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
238 return ret;
239
240 List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
241
242 switch (linkType)
243 {
244 case ScriptBaseClass.LINK_SET:
245 return avs;
246
247 case ScriptBaseClass.LINK_ROOT:
248 return ret;
249
250 case ScriptBaseClass.LINK_ALL_OTHERS:
251 return avs;
252
253 case ScriptBaseClass.LINK_ALL_CHILDREN:
254 return avs;
255
256 case ScriptBaseClass.LINK_THIS:
257 return ret;
258
259 default:
260 if (linkType < 0)
261 return ret;
262
263 int partCount = m_host.ParentGroup.GetPartCount();
264
265 if (linkType <= partCount)
266 {
267 return ret;
268 }
269 else
270 {
271 linkType = linkType - partCount;
272 if (linkType > avs.Count)
273 {
274 return ret;
275 }
276 else
277 {
278 ret.Add(avs[linkType-1]);
279 return ret;
280 }
281 }
282 }
283 }
284
229 public List<SceneObjectPart> GetLinkParts(int linkType) 285 public List<SceneObjectPart> GetLinkParts(int linkType)
230 { 286 {
231 List<SceneObjectPart> ret = new List<SceneObjectPart>(); 287 List<SceneObjectPart> ret = new List<SceneObjectPart>();
288 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
289 return ret;
232 ret.Add(m_host); 290 ret.Add(m_host);
233 291
234 switch (linkType) 292 switch (linkType)
@@ -282,40 +340,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
282 protected UUID InventorySelf() 340 protected UUID InventorySelf()
283 { 341 {
284 UUID invItemID = new UUID(); 342 UUID invItemID = new UUID();
285 343 bool unlock = false;
286 lock (m_host.TaskInventory) 344 if (!m_host.TaskInventory.IsReadLockedByMe())
287 { 345 {
288 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 346 m_host.TaskInventory.LockItemsForRead(true);
347 unlock = true;
348 }
349 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
350 {
351 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
289 { 352 {
290 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID) 353 invItemID = inv.Key;
291 { 354 break;
292 invItemID = inv.Key;
293 break;
294 }
295 } 355 }
296 } 356 }
297 357 if (unlock)
358 {
359 m_host.TaskInventory.LockItemsForRead(false);
360 }
298 return invItemID; 361 return invItemID;
299 } 362 }
300 363
301 protected UUID InventoryKey(string name, int type) 364 protected UUID InventoryKey(string name, int type)
302 { 365 {
303 m_host.AddScriptLPS(1); 366 m_host.AddScriptLPS(1);
304 367 m_host.TaskInventory.LockItemsForRead(true);
305 lock (m_host.TaskInventory) 368
369 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
306 { 370 {
307 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 371 if (inv.Value.Name == name)
308 { 372 {
309 if (inv.Value.Name == name) 373 m_host.TaskInventory.LockItemsForRead(false);
374
375 if (inv.Value.Type != type)
310 { 376 {
311 if (inv.Value.Type != type) 377 return UUID.Zero;
312 return UUID.Zero;
313
314 return inv.Value.AssetID;
315 } 378 }
379
380 return inv.Value.AssetID;
316 } 381 }
317 } 382 }
318 383
384 m_host.TaskInventory.LockItemsForRead(false);
319 return UUID.Zero; 385 return UUID.Zero;
320 } 386 }
321 387
@@ -323,17 +389,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
323 { 389 {
324 m_host.AddScriptLPS(1); 390 m_host.AddScriptLPS(1);
325 391
326 lock (m_host.TaskInventory) 392
393 m_host.TaskInventory.LockItemsForRead(true);
394
395 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
327 { 396 {
328 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 397 if (inv.Value.Name == name)
329 { 398 {
330 if (inv.Value.Name == name) 399 m_host.TaskInventory.LockItemsForRead(false);
331 { 400 return inv.Value.AssetID;
332 return inv.Value.AssetID;
333 }
334 } 401 }
335 } 402 }
336 403
404 m_host.TaskInventory.LockItemsForRead(false);
405
406
337 return UUID.Zero; 407 return UUID.Zero;
338 } 408 }
339 409
@@ -475,26 +545,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
475 545
476 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke 546 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
477 547
478 // Old implementation of llRot2Euler. Normalization not required as Atan2 function will 548 // Utility function for llRot2Euler
479 // only return values >= -PI (-180 degrees) and <= PI (180 degrees).
480 549
481 public LSL_Vector llRot2Euler(LSL_Rotation r) 550 // normalize an angle between -PI and PI (-180 to +180 degrees)
551 protected double NormalizeAngle(double angle)
552 {
553 if (angle > -Math.PI && angle < Math.PI)
554 return angle;
555
556 int numPis = (int)(Math.PI / angle);
557 double remainder = angle - Math.PI * numPis;
558 if (numPis % 2 == 1)
559 return Math.PI - angle;
560 return remainder;
561 }
562
563 public LSL_Vector llRot2Euler(LSL_Rotation q1)
482 { 564 {
483 m_host.AddScriptLPS(1); 565 m_host.AddScriptLPS(1);
484 //This implementation is from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions. ckrinke 566 LSL_Vector eul = new LSL_Vector();
485 LSL_Rotation t = new LSL_Rotation(r.x * r.x, r.y * r.y, r.z * r.z, r.s * r.s); 567
486 double m = (t.x + t.y + t.z + t.s); 568 double sqw = q1.s*q1.s;
487 if (m == 0) return new LSL_Vector(); 569 double sqx = q1.x*q1.x;
488 double n = 2 * (r.y * r.s + r.x * r.z); 570 double sqy = q1.z*q1.z;
489 double p = m * m - n * n; 571 double sqz = q1.y*q1.y;
490 if (p > 0) 572 double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
491 return new LSL_Vector(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s)), 573 double test = q1.x*q1.z + q1.y*q1.s;
492 Math.Atan2(n, Math.Sqrt(p)), 574 if (test > 0.4999*unit) { // singularity at north pole
493 Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s))); 575 eul.z = 2 * Math.Atan2(q1.x,q1.s);
494 else if (n > 0) 576 eul.y = Math.PI/2;
495 return new LSL_Vector(0.0, Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z)); 577 eul.x = 0;
496 else 578 return eul;
497 return new LSL_Vector(0.0, -Math.PI * 0.5, Math.Atan2((r.z * r.s + r.x * r.y), 0.5 - t.x - t.z)); 579 }
580 if (test < -0.4999*unit) { // singularity at south pole
581 eul.z = -2 * Math.Atan2(q1.x,q1.s);
582 eul.y = -Math.PI/2;
583 eul.x = 0;
584 return eul;
585 }
586 eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
587 eul.y = Math.Asin(2*test/unit);
588 eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
589 return eul;
498 } 590 }
499 591
500 /* From wiki: 592 /* From wiki:
@@ -696,77 +788,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
696 { 788 {
697 //A and B should both be normalized 789 //A and B should both be normalized
698 m_host.AddScriptLPS(1); 790 m_host.AddScriptLPS(1);
699 LSL_Rotation rotBetween; 791 /* This method is more accurate than the SL one, and thus causes problems
700 // Check for zero vectors. If either is zero, return zero rotation. Otherwise, 792 for scripts that deal with the SL inaccuracy around 180-degrees -.- .._.
701 // continue calculation. 793
702 if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f)) 794 double dotProduct = LSL_Vector.Dot(a, b);
795 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
796 double magProduct = LSL_Vector.Mag(a) * LSL_Vector.Mag(b);
797 double angle = Math.Acos(dotProduct / magProduct);
798 LSL_Vector axis = LSL_Vector.Norm(crossProduct);
799 double s = Math.Sin(angle / 2);
800
801 double x = axis.x * s;
802 double y = axis.y * s;
803 double z = axis.z * s;
804 double w = Math.Cos(angle / 2);
805
806 if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w))
807 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
808
809 return new LSL_Rotation((float)x, (float)y, (float)z, (float)w);
810 */
811
812 // This method mimics the 180 errors found in SL
813 // See www.euclideanspace.com... angleBetween
814 LSL_Vector vec_a = a;
815 LSL_Vector vec_b = b;
816
817 // Eliminate zero length
818 LSL_Float vec_a_mag = LSL_Vector.Mag(vec_a);
819 LSL_Float vec_b_mag = LSL_Vector.Mag(vec_b);
820 if (vec_a_mag < 0.00001 ||
821 vec_b_mag < 0.00001)
703 { 822 {
704 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); 823 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
705 } 824 }
706 else 825
826 // Normalize
827 vec_a = llVecNorm(vec_a);
828 vec_b = llVecNorm(vec_b);
829
830 // Calculate axis and rotation angle
831 LSL_Vector axis = vec_a % vec_b;
832 LSL_Float cos_theta = vec_a * vec_b;
833
834 // Check if parallel
835 if (cos_theta > 0.99999)
707 { 836 {
708 a = LSL_Vector.Norm(a); 837 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
709 b = LSL_Vector.Norm(b); 838 }
710 double dotProduct = LSL_Vector.Dot(a, b); 839
711 // There are two degenerate cases possible. These are for vectors 180 or 840 // Check if anti-parallel
712 // 0 degrees apart. These have to be detected and handled individually. 841 else if (cos_theta < -0.99999)
713 // 842 {
714 // Check for vectors 180 degrees apart. 843 LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (vec_a.x / (vec_a * vec_a) * vec_a);
715 // A dot product of -1 would mean the angle between vectors is 180 degrees. 844 if (LSL_Vector.Mag(orthog_axis) < 0.000001) orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
716 if (dotProduct < -0.9999999f) 845 return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
717 { 846 }
718 // First assume X axis is orthogonal to the vectors. 847 else // other rotation
719 LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f); 848 {
720 orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a)); 849 LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
721 // Check for near zero vector. A very small non-zero number here will create 850 axis = llVecNorm(axis);
722 // a rotation in an undesired direction. 851 double x, y, z, s, t;
723 if (LSL_Vector.Mag(orthoVector) > 0.0001) 852 s = Math.Cos(theta);
724 { 853 t = Math.Sin(theta);
725 rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f); 854 x = axis.x * t;
726 } 855 y = axis.y * t;
727 // If the magnitude of the vector was near zero, then assume the X axis is not 856 z = axis.z * t;
728 // orthogonal and use the Z axis instead. 857 return new LSL_Rotation(x,y,z,s);
729 else
730 {
731 // Set 180 z rotation.
732 rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f);
733 }
734 }
735 // Check for parallel vectors.
736 // A dot product of 1 would mean the angle between vectors is 0 degrees.
737 else if (dotProduct > 0.9999999f)
738 {
739 // Set zero rotation.
740 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
741 }
742 else
743 {
744 // All special checks have been performed so get the axis of rotation.
745 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
746 // Quarternion s value is the length of the unit vector + dot product.
747 double qs = 1.0 + dotProduct;
748 rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs);
749 // Normalize the rotation.
750 double mag = LSL_Rotation.Mag(rotBetween);
751 // We shouldn't have to worry about a divide by zero here. The qs value will be
752 // non-zero because we already know if we're here, then the dotProduct is not -1 so
753 // qs will not be zero. Also, we've already handled the input vectors being zero so the
754 // crossProduct vector should also not be zero.
755 rotBetween.x = rotBetween.x / mag;
756 rotBetween.y = rotBetween.y / mag;
757 rotBetween.z = rotBetween.z / mag;
758 rotBetween.s = rotBetween.s / mag;
759 // Check for undefined values and set zero rotation if any found. This code might not actually be required
760 // any longer since zero vectors are checked for at the top.
761 if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s))
762 {
763 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
764 }
765 }
766 } 858 }
767 return rotBetween;
768 } 859 }
769 860
770 public void llWhisper(int channelID, string text) 861 public void llWhisper(int channelID, string text)
771 { 862 {
772 m_host.AddScriptLPS(1); 863 m_host.AddScriptLPS(1);
@@ -1090,10 +1181,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1090 return detectedParams.TouchUV; 1181 return detectedParams.TouchUV;
1091 } 1182 }
1092 1183
1184 [DebuggerNonUserCode]
1093 public virtual void llDie() 1185 public virtual void llDie()
1094 { 1186 {
1095 m_host.AddScriptLPS(1); 1187 m_host.AddScriptLPS(1);
1096 throw new SelfDeleteException(); 1188 if (!m_host.IsAttachment) throw new SelfDeleteException();
1097 } 1189 }
1098 1190
1099 public LSL_Float llGround(LSL_Vector offset) 1191 public LSL_Float llGround(LSL_Vector offset)
@@ -1166,6 +1258,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1166 1258
1167 public void llSetStatus(int status, int value) 1259 public void llSetStatus(int status, int value)
1168 { 1260 {
1261 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
1262 return;
1169 m_host.AddScriptLPS(1); 1263 m_host.AddScriptLPS(1);
1170 1264
1171 int statusrotationaxis = 0; 1265 int statusrotationaxis = 0;
@@ -1395,6 +1489,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1395 { 1489 {
1396 m_host.AddScriptLPS(1); 1490 m_host.AddScriptLPS(1);
1397 1491
1492 SetColor(m_host, color, face);
1493 }
1494
1495 protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
1496 {
1497 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1498 return;
1499
1500 Primitive.TextureEntry tex = part.Shape.Textures;
1501 Color4 texcolor;
1502 if (face >= 0 && face < GetNumberOfSides(part))
1503 {
1504 texcolor = tex.CreateFace((uint)face).RGBA;
1505 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1506 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1507 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1508 tex.FaceTextures[face].RGBA = texcolor;
1509 part.UpdateTexture(tex);
1510 return;
1511 }
1512 else if (face == ScriptBaseClass.ALL_SIDES)
1513 {
1514 for (uint i = 0; i < GetNumberOfSides(part); i++)
1515 {
1516 if (tex.FaceTextures[i] != null)
1517 {
1518 texcolor = tex.FaceTextures[i].RGBA;
1519 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1520 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1521 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1522 tex.FaceTextures[i].RGBA = texcolor;
1523 }
1524 texcolor = tex.DefaultTexture.RGBA;
1525 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1526 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1527 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1528 tex.DefaultTexture.RGBA = texcolor;
1529 }
1530 part.UpdateTexture(tex);
1531 return;
1532 }
1533
1398 if (face == ScriptBaseClass.ALL_SIDES) 1534 if (face == ScriptBaseClass.ALL_SIDES)
1399 face = SceneObjectPart.ALL_SIDES; 1535 face = SceneObjectPart.ALL_SIDES;
1400 1536
@@ -1403,6 +1539,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1403 1539
1404 public void SetTexGen(SceneObjectPart part, int face,int style) 1540 public void SetTexGen(SceneObjectPart part, int face,int style)
1405 { 1541 {
1542 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1543 return;
1544
1406 Primitive.TextureEntry tex = part.Shape.Textures; 1545 Primitive.TextureEntry tex = part.Shape.Textures;
1407 MappingType textype; 1546 MappingType textype;
1408 textype = MappingType.Default; 1547 textype = MappingType.Default;
@@ -1433,6 +1572,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1433 1572
1434 public void SetGlow(SceneObjectPart part, int face, float glow) 1573 public void SetGlow(SceneObjectPart part, int face, float glow)
1435 { 1574 {
1575 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1576 return;
1577
1436 Primitive.TextureEntry tex = part.Shape.Textures; 1578 Primitive.TextureEntry tex = part.Shape.Textures;
1437 if (face >= 0 && face < GetNumberOfSides(part)) 1579 if (face >= 0 && face < GetNumberOfSides(part))
1438 { 1580 {
@@ -1458,6 +1600,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1458 1600
1459 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump) 1601 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
1460 { 1602 {
1603 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1604 return;
1461 1605
1462 Shininess sval = new Shininess(); 1606 Shininess sval = new Shininess();
1463 1607
@@ -1508,6 +1652,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1508 1652
1509 public void SetFullBright(SceneObjectPart part, int face, bool bright) 1653 public void SetFullBright(SceneObjectPart part, int face, bool bright)
1510 { 1654 {
1655 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1656 return;
1657
1511 Primitive.TextureEntry tex = part.Shape.Textures; 1658 Primitive.TextureEntry tex = part.Shape.Textures;
1512 if (face >= 0 && face < GetNumberOfSides(part)) 1659 if (face >= 0 && face < GetNumberOfSides(part))
1513 { 1660 {
@@ -1568,13 +1715,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1568 m_host.AddScriptLPS(1); 1715 m_host.AddScriptLPS(1);
1569 1716
1570 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1717 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1571 1718 if (parts.Count > 0)
1572 foreach (SceneObjectPart part in parts) 1719 {
1573 SetAlpha(part, alpha, face); 1720 try
1721 {
1722 parts[0].ParentGroup.areUpdatesSuspended = true;
1723 foreach (SceneObjectPart part in parts)
1724 SetAlpha(part, alpha, face);
1725 }
1726 finally
1727 {
1728 parts[0].ParentGroup.areUpdatesSuspended = false;
1729 }
1730 }
1574 } 1731 }
1575 1732
1576 protected void SetAlpha(SceneObjectPart part, double alpha, int face) 1733 protected void SetAlpha(SceneObjectPart part, double alpha, int face)
1577 { 1734 {
1735 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1736 return;
1737
1578 Primitive.TextureEntry tex = part.Shape.Textures; 1738 Primitive.TextureEntry tex = part.Shape.Textures;
1579 Color4 texcolor; 1739 Color4 texcolor;
1580 if (face >= 0 && face < GetNumberOfSides(part)) 1740 if (face >= 0 && face < GetNumberOfSides(part))
@@ -1620,7 +1780,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1620 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction, 1780 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
1621 float wind, float tension, LSL_Vector Force) 1781 float wind, float tension, LSL_Vector Force)
1622 { 1782 {
1623 if (part == null) 1783 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1624 return; 1784 return;
1625 1785
1626 if (flexi) 1786 if (flexi)
@@ -1655,7 +1815,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1655 /// <param name="falloff"></param> 1815 /// <param name="falloff"></param>
1656 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff) 1816 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
1657 { 1817 {
1658 if (part == null) 1818 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1659 return; 1819 return;
1660 1820
1661 if (light) 1821 if (light)
@@ -1732,15 +1892,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1732 m_host.AddScriptLPS(1); 1892 m_host.AddScriptLPS(1);
1733 1893
1734 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1894 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1735 1895 if (parts.Count > 0)
1736 foreach (SceneObjectPart part in parts) 1896 {
1737 SetTexture(part, texture, face); 1897 try
1738 1898 {
1899 parts[0].ParentGroup.areUpdatesSuspended = true;
1900 foreach (SceneObjectPart part in parts)
1901 SetTexture(part, texture, face);
1902 }
1903 finally
1904 {
1905 parts[0].ParentGroup.areUpdatesSuspended = false;
1906 }
1907 }
1739 ScriptSleep(200); 1908 ScriptSleep(200);
1740 } 1909 }
1741 1910
1742 protected void SetTexture(SceneObjectPart part, string texture, int face) 1911 protected void SetTexture(SceneObjectPart part, string texture, int face)
1743 { 1912 {
1913 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1914 return;
1915
1744 UUID textureID=new UUID(); 1916 UUID textureID=new UUID();
1745 1917
1746 if (!UUID.TryParse(texture, out textureID)) 1918 if (!UUID.TryParse(texture, out textureID))
@@ -1786,6 +1958,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1786 1958
1787 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) 1959 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
1788 { 1960 {
1961 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1962 return;
1963
1789 Primitive.TextureEntry tex = part.Shape.Textures; 1964 Primitive.TextureEntry tex = part.Shape.Textures;
1790 if (face >= 0 && face < GetNumberOfSides(part)) 1965 if (face >= 0 && face < GetNumberOfSides(part))
1791 { 1966 {
@@ -1822,6 +1997,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1822 1997
1823 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) 1998 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
1824 { 1999 {
2000 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2001 return;
2002
1825 Primitive.TextureEntry tex = part.Shape.Textures; 2003 Primitive.TextureEntry tex = part.Shape.Textures;
1826 if (face >= 0 && face < GetNumberOfSides(part)) 2004 if (face >= 0 && face < GetNumberOfSides(part))
1827 { 2005 {
@@ -1858,6 +2036,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1858 2036
1859 protected void RotateTexture(SceneObjectPart part, double rotation, int face) 2037 protected void RotateTexture(SceneObjectPart part, double rotation, int face)
1860 { 2038 {
2039 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2040 return;
2041
1861 Primitive.TextureEntry tex = part.Shape.Textures; 2042 Primitive.TextureEntry tex = part.Shape.Textures;
1862 if (face >= 0 && face < GetNumberOfSides(part)) 2043 if (face >= 0 && face < GetNumberOfSides(part))
1863 { 2044 {
@@ -1928,6 +2109,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1928 2109
1929 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos) 2110 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos)
1930 { 2111 {
2112 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2113 return;
2114
1931 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos) 2115 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
1932 LSL_Vector currentPos = GetPartLocalPos(part); 2116 LSL_Vector currentPos = GetPartLocalPos(part);
1933 2117
@@ -1944,7 +2128,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1944 } 2128 }
1945 else 2129 else
1946 { 2130 {
1947 LSL_Vector rel_vec = SetPosAdjust(currentPos, targetPos); 2131 LSL_Vector rel_vec = SetPosAdjust(new LSL_Vector(part.OffsetPosition.X, part.OffsetPosition.Y, part.OffsetPosition.Z), targetPos);
1948 part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z); 2132 part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z);
1949 SceneObjectGroup parent = part.ParentGroup; 2133 SceneObjectGroup parent = part.ParentGroup;
1950 parent.HasGroupChanged = true; 2134 parent.HasGroupChanged = true;
@@ -2027,6 +2211,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2027 2211
2028 protected void SetRot(SceneObjectPart part, Quaternion rot) 2212 protected void SetRot(SceneObjectPart part, Quaternion rot)
2029 { 2213 {
2214 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2215 return;
2216
2030 part.UpdateRotation(rot); 2217 part.UpdateRotation(rot);
2031 // Update rotation does not move the object in the physics scene if it's a linkset. 2218 // Update rotation does not move the object in the physics scene if it's a linkset.
2032 2219
@@ -2646,12 +2833,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2646 2833
2647 m_host.AddScriptLPS(1); 2834 m_host.AddScriptLPS(1);
2648 2835
2836 m_host.TaskInventory.LockItemsForRead(true);
2649 TaskInventoryItem item = m_host.TaskInventory[invItemID]; 2837 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2650 2838 m_host.TaskInventory.LockItemsForRead(false);
2651 lock (m_host.TaskInventory)
2652 {
2653 item = m_host.TaskInventory[invItemID];
2654 }
2655 2839
2656 if (item.PermsGranter == UUID.Zero) 2840 if (item.PermsGranter == UUID.Zero)
2657 return 0; 2841 return 0;
@@ -2726,6 +2910,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2726 if (dist > m_ScriptDistanceFactor * 10.0f) 2910 if (dist > m_ScriptDistanceFactor * 10.0f)
2727 return; 2911 return;
2728 2912
2913 //Clone is thread-safe
2729 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 2914 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
2730 2915
2731 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory) 2916 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory)
@@ -2788,6 +2973,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2788 2973
2789 public void llLookAt(LSL_Vector target, double strength, double damping) 2974 public void llLookAt(LSL_Vector target, double strength, double damping)
2790 { 2975 {
2976 /*
2791 m_host.AddScriptLPS(1); 2977 m_host.AddScriptLPS(1);
2792 // Determine where we are looking from 2978 // Determine where we are looking from
2793 LSL_Vector from = llGetPos(); 2979 LSL_Vector from = llGetPos();
@@ -2807,10 +2993,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2807 // the angles of rotation in radians into rotation value 2993 // the angles of rotation in radians into rotation value
2808 2994
2809 LSL_Types.Quaternion rot = llEuler2Rot(angle); 2995 LSL_Types.Quaternion rot = llEuler2Rot(angle);
2810 Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s); 2996
2811 m_host.startLookAt(rotation, (float)damping, (float)strength); 2997 // This would only work if your physics system contains an APID controller:
2998 // Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
2999 // m_host.startLookAt(rotation, (float)damping, (float)strength);
3000
2812 // Orient the object to the angle calculated 3001 // Orient the object to the angle calculated
2813 //llSetRot(rot); 3002 llSetRot(rot);
3003 */
3004
3005 //The above code, while nice, doesn't replicate the behaviour of SL and tends to "roll" the object.
3006 //There's probably a smarter way of doing this, my rotation math-fu is weak.
3007 // http://bugs.meta7.com/view.php?id=28
3008 // - Tom
3009
3010 LSL_Rotation newrot = llGetRot() * llRotBetween(new LSL_Vector(1.0d, 0.0d, 0.0d) * llGetRot(), new LSL_Vector(0.0d, 0.0d, -1.0d));
3011 llSetRot(newrot * llRotBetween(new LSL_Vector(0.0d,0.0d,1.0d) * newrot, target - llGetPos()));
3012
3013 }
3014
3015 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3016 {
3017 m_host.AddScriptLPS(1);
3018// NotImplemented("llRotLookAt");
3019 m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping);
3020
2814 } 3021 }
2815 3022
2816 public void llStopLookAt() 3023 public void llStopLookAt()
@@ -2859,13 +3066,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2859 { 3066 {
2860 TaskInventoryItem item; 3067 TaskInventoryItem item;
2861 3068
2862 lock (m_host.TaskInventory) 3069 m_host.TaskInventory.LockItemsForRead(true);
3070 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2863 { 3071 {
2864 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3072 m_host.TaskInventory.LockItemsForRead(false);
2865 return; 3073 return;
2866 else 3074 }
2867 item = m_host.TaskInventory[InventorySelf()]; 3075 else
3076 {
3077 item = m_host.TaskInventory[InventorySelf()];
2868 } 3078 }
3079 m_host.TaskInventory.LockItemsForRead(false);
2869 3080
2870 if (item.PermsGranter != UUID.Zero) 3081 if (item.PermsGranter != UUID.Zero)
2871 { 3082 {
@@ -2887,13 +3098,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2887 { 3098 {
2888 TaskInventoryItem item; 3099 TaskInventoryItem item;
2889 3100
3101 m_host.TaskInventory.LockItemsForRead(true);
2890 lock (m_host.TaskInventory) 3102 lock (m_host.TaskInventory)
2891 { 3103 {
3104
2892 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3105 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3106 {
3107 m_host.TaskInventory.LockItemsForRead(false);
2893 return; 3108 return;
3109 }
2894 else 3110 else
3111 {
2895 item = m_host.TaskInventory[InventorySelf()]; 3112 item = m_host.TaskInventory[InventorySelf()];
3113 }
2896 } 3114 }
3115 m_host.TaskInventory.LockItemsForRead(false);
2897 3116
2898 m_host.AddScriptLPS(1); 3117 m_host.AddScriptLPS(1);
2899 3118
@@ -2925,19 +3144,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2925 { 3144 {
2926 m_host.AddScriptLPS(1); 3145 m_host.AddScriptLPS(1);
2927 3146
2928 if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
2929 return;
2930
2931 TaskInventoryItem item; 3147 TaskInventoryItem item;
2932 3148
2933 lock (m_host.TaskInventory) 3149 m_host.TaskInventory.LockItemsForRead(true);
3150
3151 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2934 { 3152 {
2935 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3153 m_host.TaskInventory.LockItemsForRead(false);
2936 return; 3154 return;
2937 else 3155 }
2938 item = m_host.TaskInventory[InventorySelf()]; 3156 else
3157 {
3158 item = m_host.TaskInventory[InventorySelf()];
2939 } 3159 }
2940 3160
3161 m_host.TaskInventory.LockItemsForRead(false);
3162
2941 if (item.PermsGranter != m_host.OwnerID) 3163 if (item.PermsGranter != m_host.OwnerID)
2942 return; 3164 return;
2943 3165
@@ -2947,10 +3169,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2947 3169
2948 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 3170 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
2949 3171
2950 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3172 grp.AttachToAgent(m_host.OwnerID, (uint)attachment, Vector3.Zero, false);
2951 if (attachmentsModule != null)
2952 attachmentsModule.AttachObject(presence.ControllingClient,
2953 grp, (uint)attachment, false);
2954 } 3173 }
2955 } 3174 }
2956 3175
@@ -2963,13 +3182,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2963 3182
2964 TaskInventoryItem item; 3183 TaskInventoryItem item;
2965 3184
2966 lock (m_host.TaskInventory) 3185 m_host.TaskInventory.LockItemsForRead(true);
3186
3187 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2967 { 3188 {
2968 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3189 m_host.TaskInventory.LockItemsForRead(false);
2969 return; 3190 return;
2970 else 3191 }
2971 item = m_host.TaskInventory[InventorySelf()]; 3192 else
3193 {
3194 item = m_host.TaskInventory[InventorySelf()];
2972 } 3195 }
3196 m_host.TaskInventory.LockItemsForRead(false);
3197
2973 3198
2974 if (item.PermsGranter != m_host.OwnerID) 3199 if (item.PermsGranter != m_host.OwnerID)
2975 return; 3200 return;
@@ -3008,6 +3233,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3008 3233
3009 public void llInstantMessage(string user, string message) 3234 public void llInstantMessage(string user, string message)
3010 { 3235 {
3236 UUID result;
3237 if (!UUID.TryParse(user, out result))
3238 {
3239 if (!m_debuggerSafe)
3240 {
3241 throw new Exception(String.Format("An invalid key of '{0} was passed to llInstantMessage", user));
3242 }
3243 return;
3244 }
3245
3246
3011 m_host.AddScriptLPS(1); 3247 m_host.AddScriptLPS(1);
3012 3248
3013 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. 3249 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
@@ -3022,14 +3258,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3022 UUID friendTransactionID = UUID.Random(); 3258 UUID friendTransactionID = UUID.Random();
3023 3259
3024 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 3260 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
3025 3261
3026 GridInstantMessage msg = new GridInstantMessage(); 3262 GridInstantMessage msg = new GridInstantMessage();
3027 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; 3263 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
3028 msg.toAgentID = new Guid(user); // toAgentID.Guid; 3264 msg.toAgentID = new Guid(user); // toAgentID.Guid;
3029 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here 3265 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
3030// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message); 3266// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
3031// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString()); 3267// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
3032 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp; 3268 DateTime dt = DateTime.UtcNow;
3269
3270 // Ticks from UtcNow, but make it look like local. Evil, huh?
3271 dt = DateTime.SpecifyKind(dt, DateTimeKind.Local);
3272
3273 try
3274 {
3275 // Convert that to the PST timezone
3276 TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
3277 dt = TimeZoneInfo.ConvertTime(dt, timeZoneInfo);
3278 }
3279 catch
3280 {
3281 // No logging here, as it could be VERY spammy
3282 }
3283
3284 // And make it look local again to fool the unix time util
3285 dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
3286
3287 msg.timestamp = (uint)Util.ToUnixTime(dt);
3288
3033 //if (client != null) 3289 //if (client != null)
3034 //{ 3290 //{
3035 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName; 3291 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
@@ -3043,13 +3299,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3043 msg.message = message.Substring(0, 1024); 3299 msg.message = message.Substring(0, 1024);
3044 else 3300 else
3045 msg.message = message; 3301 msg.message = message;
3046 msg.dialog = (byte)19; // messgage from script ??? // dialog; 3302 msg.dialog = (byte)19; // MessageFromObject
3047 msg.fromGroup = false;// fromGroup; 3303 msg.fromGroup = false;// fromGroup;
3048 msg.offline = (byte)0; //offline; 3304 msg.offline = (byte)0; //offline;
3049 msg.ParentEstateID = 0; //ParentEstateID; 3305 msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
3050 msg.Position = Vector3.Zero;// new Vector3(m_host.AbsolutePosition); 3306 msg.Position = new Vector3(m_host.AbsolutePosition);
3051 msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; 3307 msg.RegionID = World.RegionInfo.RegionID.Guid;
3052 msg.binaryBucket = new byte[0];// binaryBucket; 3308 msg.binaryBucket = Util.StringToBytes256(m_host.OwnerID.ToString());
3053 3309
3054 if (m_TransferModule != null) 3310 if (m_TransferModule != null)
3055 { 3311 {
@@ -3069,7 +3325,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3069 } 3325 }
3070 3326
3071 emailModule.SendEmail(m_host.UUID, address, subject, message); 3327 emailModule.SendEmail(m_host.UUID, address, subject, message);
3072 ScriptSleep(20000); 3328 ScriptSleep(15000);
3073 } 3329 }
3074 3330
3075 public void llGetNextEmail(string address, string subject) 3331 public void llGetNextEmail(string address, string subject)
@@ -3171,13 +3427,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3171 m_host.AddScriptLPS(1); 3427 m_host.AddScriptLPS(1);
3172 } 3428 }
3173 3429
3174 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3175 {
3176 m_host.AddScriptLPS(1);
3177 Quaternion rot = new Quaternion((float)target.x, (float)target.y, (float)target.z, (float)target.s);
3178 m_host.RotLookAt(rot, (float)strength, (float)damping);
3179 }
3180
3181 public LSL_Integer llStringLength(string str) 3430 public LSL_Integer llStringLength(string str)
3182 { 3431 {
3183 m_host.AddScriptLPS(1); 3432 m_host.AddScriptLPS(1);
@@ -3201,14 +3450,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3201 3450
3202 TaskInventoryItem item; 3451 TaskInventoryItem item;
3203 3452
3204 lock (m_host.TaskInventory) 3453 m_host.TaskInventory.LockItemsForRead(true);
3454 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3205 { 3455 {
3206 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3456 m_host.TaskInventory.LockItemsForRead(false);
3207 return; 3457 return;
3208 else
3209 item = m_host.TaskInventory[InventorySelf()];
3210 } 3458 }
3211 3459 else
3460 {
3461 item = m_host.TaskInventory[InventorySelf()];
3462 }
3463 m_host.TaskInventory.LockItemsForRead(false);
3212 if (item.PermsGranter == UUID.Zero) 3464 if (item.PermsGranter == UUID.Zero)
3213 return; 3465 return;
3214 3466
@@ -3238,13 +3490,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3238 3490
3239 TaskInventoryItem item; 3491 TaskInventoryItem item;
3240 3492
3241 lock (m_host.TaskInventory) 3493 m_host.TaskInventory.LockItemsForRead(true);
3494 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3242 { 3495 {
3243 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3496 m_host.TaskInventory.LockItemsForRead(false);
3244 return; 3497 return;
3245 else 3498 }
3246 item = m_host.TaskInventory[InventorySelf()]; 3499 else
3500 {
3501 item = m_host.TaskInventory[InventorySelf()];
3247 } 3502 }
3503 m_host.TaskInventory.LockItemsForRead(false);
3504
3248 3505
3249 if (item.PermsGranter == UUID.Zero) 3506 if (item.PermsGranter == UUID.Zero)
3250 return; 3507 return;
@@ -3315,10 +3572,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3315 3572
3316 TaskInventoryItem item; 3573 TaskInventoryItem item;
3317 3574
3318 lock (m_host.TaskInventory) 3575
3576 m_host.TaskInventory.LockItemsForRead(true);
3577 if (!m_host.TaskInventory.ContainsKey(invItemID))
3578 {
3579 m_host.TaskInventory.LockItemsForRead(false);
3580 return;
3581 }
3582 else
3319 { 3583 {
3320 item = m_host.TaskInventory[invItemID]; 3584 item = m_host.TaskInventory[invItemID];
3321 } 3585 }
3586 m_host.TaskInventory.LockItemsForRead(false);
3322 3587
3323 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3588 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3324 { 3589 {
@@ -3350,11 +3615,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3350 3615
3351 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3616 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3352 { 3617 {
3353 lock (m_host.TaskInventory) 3618 m_host.TaskInventory.LockItemsForWrite(true);
3354 { 3619 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3355 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3620 m_host.TaskInventory[invItemID].PermsMask = perm;
3356 m_host.TaskInventory[invItemID].PermsMask = perm; 3621 m_host.TaskInventory.LockItemsForWrite(false);
3357 }
3358 3622
3359 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3623 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3360 "run_time_permissions", new Object[] { 3624 "run_time_permissions", new Object[] {
@@ -3374,11 +3638,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3374 3638
3375 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3639 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3376 { 3640 {
3377 lock (m_host.TaskInventory) 3641 m_host.TaskInventory.LockItemsForWrite(true);
3378 { 3642 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3379 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3643 m_host.TaskInventory[invItemID].PermsMask = perm;
3380 m_host.TaskInventory[invItemID].PermsMask = perm; 3644 m_host.TaskInventory.LockItemsForWrite(false);
3381 }
3382 3645
3383 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3646 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3384 "run_time_permissions", new Object[] { 3647 "run_time_permissions", new Object[] {
@@ -3399,11 +3662,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3399 3662
3400 if (!m_waitingForScriptAnswer) 3663 if (!m_waitingForScriptAnswer)
3401 { 3664 {
3402 lock (m_host.TaskInventory) 3665 m_host.TaskInventory.LockItemsForWrite(true);
3403 { 3666 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3404 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3667 m_host.TaskInventory[invItemID].PermsMask = 0;
3405 m_host.TaskInventory[invItemID].PermsMask = 0; 3668 m_host.TaskInventory.LockItemsForWrite(false);
3406 }
3407 3669
3408 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3670 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3409 m_waitingForScriptAnswer=true; 3671 m_waitingForScriptAnswer=true;
@@ -3438,10 +3700,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3438 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3700 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3439 llReleaseControls(); 3701 llReleaseControls();
3440 3702
3441 lock (m_host.TaskInventory) 3703
3442 { 3704 m_host.TaskInventory.LockItemsForWrite(true);
3443 m_host.TaskInventory[invItemID].PermsMask = answer; 3705 m_host.TaskInventory[invItemID].PermsMask = answer;
3444 } 3706 m_host.TaskInventory.LockItemsForWrite(false);
3707
3445 3708
3446 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3709 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3447 "run_time_permissions", new Object[] { 3710 "run_time_permissions", new Object[] {
@@ -3453,16 +3716,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3453 { 3716 {
3454 m_host.AddScriptLPS(1); 3717 m_host.AddScriptLPS(1);
3455 3718
3456 lock (m_host.TaskInventory) 3719 m_host.TaskInventory.LockItemsForRead(true);
3720
3721 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3457 { 3722 {
3458 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3723 if (item.Type == 10 && item.ItemID == m_itemID)
3459 { 3724 {
3460 if (item.Type == 10 && item.ItemID == m_itemID) 3725 m_host.TaskInventory.LockItemsForRead(false);
3461 { 3726 return item.PermsGranter.ToString();
3462 return item.PermsGranter.ToString();
3463 }
3464 } 3727 }
3465 } 3728 }
3729 m_host.TaskInventory.LockItemsForRead(false);
3466 3730
3467 return UUID.Zero.ToString(); 3731 return UUID.Zero.ToString();
3468 } 3732 }
@@ -3471,19 +3735,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3471 { 3735 {
3472 m_host.AddScriptLPS(1); 3736 m_host.AddScriptLPS(1);
3473 3737
3474 lock (m_host.TaskInventory) 3738 m_host.TaskInventory.LockItemsForRead(true);
3739
3740 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3475 { 3741 {
3476 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3742 if (item.Type == 10 && item.ItemID == m_itemID)
3477 { 3743 {
3478 if (item.Type == 10 && item.ItemID == m_itemID) 3744 int perms = item.PermsMask;
3479 { 3745 if (m_automaticLinkPermission)
3480 int perms = item.PermsMask; 3746 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3481 if (m_automaticLinkPermission) 3747 m_host.TaskInventory.LockItemsForRead(false);
3482 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; 3748 return perms;
3483 return perms;
3484 }
3485 } 3749 }
3486 } 3750 }
3751 m_host.TaskInventory.LockItemsForRead(false);
3487 3752
3488 return 0; 3753 return 0;
3489 } 3754 }
@@ -3505,9 +3770,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3505 public void llSetLinkColor(int linknumber, LSL_Vector color, int face) 3770 public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
3506 { 3771 {
3507 List<SceneObjectPart> parts = GetLinkParts(linknumber); 3772 List<SceneObjectPart> parts = GetLinkParts(linknumber);
3508 3773 if (parts.Count > 0)
3509 foreach (SceneObjectPart part in parts) 3774 {
3510 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); 3775 try
3776 {
3777 parts[0].ParentGroup.areUpdatesSuspended = true;
3778 foreach (SceneObjectPart part in parts)
3779 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
3780 }
3781 finally
3782 {
3783 parts[0].ParentGroup.areUpdatesSuspended = false;
3784 }
3785 }
3511 } 3786 }
3512 3787
3513 public void llCreateLink(string target, int parent) 3788 public void llCreateLink(string target, int parent)
@@ -3520,11 +3795,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3520 return; 3795 return;
3521 3796
3522 TaskInventoryItem item; 3797 TaskInventoryItem item;
3523 lock (m_host.TaskInventory) 3798 m_host.TaskInventory.LockItemsForRead(true);
3524 { 3799 item = m_host.TaskInventory[invItemID];
3525 item = m_host.TaskInventory[invItemID]; 3800 m_host.TaskInventory.LockItemsForRead(false);
3526 } 3801
3527
3528 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3802 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3529 && !m_automaticLinkPermission) 3803 && !m_automaticLinkPermission)
3530 { 3804 {
@@ -3577,16 +3851,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3577 m_host.AddScriptLPS(1); 3851 m_host.AddScriptLPS(1);
3578 UUID invItemID = InventorySelf(); 3852 UUID invItemID = InventorySelf();
3579 3853
3580 lock (m_host.TaskInventory) 3854 m_host.TaskInventory.LockItemsForRead(true);
3581 {
3582 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3855 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3583 && !m_automaticLinkPermission) 3856 && !m_automaticLinkPermission)
3584 { 3857 {
3585 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3858 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
3859 m_host.TaskInventory.LockItemsForRead(false);
3586 return; 3860 return;
3587 } 3861 }
3588 } 3862 m_host.TaskInventory.LockItemsForRead(false);
3589 3863
3590 if (linknum < ScriptBaseClass.LINK_THIS) 3864 if (linknum < ScriptBaseClass.LINK_THIS)
3591 return; 3865 return;
3592 3866
@@ -3625,10 +3899,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3625 // Restructuring Multiple Prims. 3899 // Restructuring Multiple Prims.
3626 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values); 3900 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values);
3627 parts.Remove(parentPrim.RootPart); 3901 parts.Remove(parentPrim.RootPart);
3628 foreach (SceneObjectPart part in parts) 3902 if (parts.Count > 0)
3629 { 3903 {
3630 parentPrim.DelinkFromGroup(part.LocalId, true); 3904 try
3905 {
3906 parts[0].ParentGroup.areUpdatesSuspended = true;
3907 foreach (SceneObjectPart part in parts)
3908 {
3909 parentPrim.DelinkFromGroup(part.LocalId, true);
3910 }
3911 }
3912 finally
3913 {
3914 parts[0].ParentGroup.areUpdatesSuspended = false;
3915 }
3631 } 3916 }
3917
3632 parentPrim.HasGroupChanged = true; 3918 parentPrim.HasGroupChanged = true;
3633 parentPrim.ScheduleGroupForFullUpdate(); 3919 parentPrim.ScheduleGroupForFullUpdate();
3634 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 3920 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
@@ -3637,11 +3923,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3637 { 3923 {
3638 SceneObjectPart newRoot = parts[0]; 3924 SceneObjectPart newRoot = parts[0];
3639 parts.Remove(newRoot); 3925 parts.Remove(newRoot);
3640 foreach (SceneObjectPart part in parts) 3926
3927 try
3641 { 3928 {
3642 part.UpdateFlag = 0; 3929 parts[0].ParentGroup.areUpdatesSuspended = true;
3643 newRoot.ParentGroup.LinkToGroup(part.ParentGroup); 3930 foreach (SceneObjectPart part in parts)
3931 {
3932 part.UpdateFlag = 0;
3933 newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
3934 }
3644 } 3935 }
3936 finally
3937 {
3938 parts[0].ParentGroup.areUpdatesSuspended = false;
3939 }
3940
3941
3645 newRoot.ParentGroup.HasGroupChanged = true; 3942 newRoot.ParentGroup.HasGroupChanged = true;
3646 newRoot.ParentGroup.ScheduleGroupForFullUpdate(); 3943 newRoot.ParentGroup.ScheduleGroupForFullUpdate();
3647 } 3944 }
@@ -3667,11 +3964,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3667 3964
3668 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values); 3965 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Children.Values);
3669 parts.Remove(parentPrim.RootPart); 3966 parts.Remove(parentPrim.RootPart);
3670 3967 if (parts.Count > 0)
3671 foreach (SceneObjectPart part in parts)
3672 { 3968 {
3673 parentPrim.DelinkFromGroup(part.LocalId, true); 3969 try
3674 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 3970 {
3971 parts[0].ParentGroup.areUpdatesSuspended = true;
3972 foreach (SceneObjectPart part in parts)
3973 {
3974 parentPrim.DelinkFromGroup(part.LocalId, true);
3975 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
3976 }
3977 }
3978 finally
3979 {
3980 parts[0].ParentGroup.areUpdatesSuspended = false;
3981 }
3675 } 3982 }
3676 parentPrim.HasGroupChanged = true; 3983 parentPrim.HasGroupChanged = true;
3677 parentPrim.ScheduleGroupForFullUpdate(); 3984 parentPrim.ScheduleGroupForFullUpdate();
@@ -3687,6 +3994,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3687 } 3994 }
3688 else 3995 else
3689 { 3996 {
3997 if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
3998 {
3999 linknum -= (m_host.ParentGroup.PrimCount) + 1;
4000
4001 List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
4002 if (avatars.Count > linknum)
4003 {
4004 return avatars[linknum].UUID.ToString();
4005 }
4006 }
3690 return UUID.Zero.ToString(); 4007 return UUID.Zero.ToString();
3691 } 4008 }
3692 } 4009 }
@@ -3763,17 +4080,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3763 m_host.AddScriptLPS(1); 4080 m_host.AddScriptLPS(1);
3764 int count = 0; 4081 int count = 0;
3765 4082
3766 lock (m_host.TaskInventory) 4083 m_host.TaskInventory.LockItemsForRead(true);
4084 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3767 { 4085 {
3768 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4086 if (inv.Value.Type == type || type == -1)
3769 { 4087 {
3770 if (inv.Value.Type == type || type == -1) 4088 count = count + 1;
3771 {
3772 count = count + 1;
3773 }
3774 } 4089 }
3775 } 4090 }
3776 4091
4092 m_host.TaskInventory.LockItemsForRead(false);
3777 return count; 4093 return count;
3778 } 4094 }
3779 4095
@@ -3782,16 +4098,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3782 m_host.AddScriptLPS(1); 4098 m_host.AddScriptLPS(1);
3783 ArrayList keys = new ArrayList(); 4099 ArrayList keys = new ArrayList();
3784 4100
3785 lock (m_host.TaskInventory) 4101 m_host.TaskInventory.LockItemsForRead(true);
4102 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3786 { 4103 {
3787 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4104 if (inv.Value.Type == type || type == -1)
3788 { 4105 {
3789 if (inv.Value.Type == type || type == -1) 4106 keys.Add(inv.Value.Name);
3790 {
3791 keys.Add(inv.Value.Name);
3792 }
3793 } 4107 }
3794 } 4108 }
4109 m_host.TaskInventory.LockItemsForRead(false);
3795 4110
3796 if (keys.Count == 0) 4111 if (keys.Count == 0)
3797 { 4112 {
@@ -3828,20 +4143,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3828 } 4143 }
3829 4144
3830 // move the first object found with this inventory name 4145 // move the first object found with this inventory name
3831 lock (m_host.TaskInventory) 4146 m_host.TaskInventory.LockItemsForRead(true);
4147 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3832 { 4148 {
3833 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4149 if (inv.Value.Name == inventory)
3834 { 4150 {
3835 if (inv.Value.Name == inventory) 4151 found = true;
3836 { 4152 objId = inv.Key;
3837 found = true; 4153 assetType = inv.Value.Type;
3838 objId = inv.Key; 4154 objName = inv.Value.Name;
3839 assetType = inv.Value.Type; 4155 break;
3840 objName = inv.Value.Name;
3841 break;
3842 }
3843 } 4156 }
3844 } 4157 }
4158 m_host.TaskInventory.LockItemsForRead(false);
3845 4159
3846 if (!found) 4160 if (!found)
3847 { 4161 {
@@ -3849,9 +4163,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3849 throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); 4163 throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
3850 } 4164 }
3851 4165
3852 // check if destination is an avatar 4166 // check if destination is an object
3853 if (World.GetScenePresence(destId) != null) 4167 if (World.GetSceneObjectPart(destId) != null)
4168 {
4169 // destination is an object
4170 World.MoveTaskInventoryItem(destId, m_host, objId);
4171 }
4172 else
3854 { 4173 {
4174 ScenePresence presence = World.GetScenePresence(destId);
4175
4176 if (presence == null)
4177 {
4178 UserAccount account =
4179 World.UserAccountService.GetUserAccount(
4180 World.RegionInfo.ScopeID,
4181 destId);
4182
4183 if (account == null)
4184 {
4185 llSay(0, "Can't find destination "+destId.ToString());
4186 return;
4187 }
4188 }
4189
3855 // destination is an avatar 4190 // destination is an avatar
3856 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId); 4191 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId);
3857 4192
@@ -3875,31 +4210,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3875 4210
3876 if (m_TransferModule != null) 4211 if (m_TransferModule != null)
3877 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); 4212 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
4213
4214 //This delay should only occur when giving inventory to avatars.
4215 ScriptSleep(3000);
3878 } 4216 }
3879 else
3880 {
3881 // destination is an object
3882 World.MoveTaskInventoryItem(destId, m_host, objId);
3883 }
3884 ScriptSleep(3000);
3885 } 4217 }
3886 4218
4219 [DebuggerNonUserCode]
3887 public void llRemoveInventory(string name) 4220 public void llRemoveInventory(string name)
3888 { 4221 {
3889 m_host.AddScriptLPS(1); 4222 m_host.AddScriptLPS(1);
3890 4223
3891 lock (m_host.TaskInventory) 4224 List<TaskInventoryItem> inv;
4225 try
3892 { 4226 {
3893 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4227 m_host.TaskInventory.LockItemsForRead(true);
4228 inv = new List<TaskInventoryItem>(m_host.TaskInventory.Values);
4229 }
4230 finally
4231 {
4232 m_host.TaskInventory.LockItemsForRead(false);
4233 }
4234 foreach (TaskInventoryItem item in inv)
4235 {
4236 if (item.Name == name)
3894 { 4237 {
3895 if (item.Name == name) 4238 if (item.ItemID == m_itemID)
3896 { 4239 throw new ScriptDeleteException();
3897 if (item.ItemID == m_itemID) 4240 else
3898 throw new ScriptDeleteException(); 4241 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3899 else 4242 return;
3900 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3901 return;
3902 }
3903 } 4243 }
3904 } 4244 }
3905 } 4245 }
@@ -3957,6 +4297,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3957 ce.time = Util.EnvironmentTickCount(); 4297 ce.time = Util.EnvironmentTickCount();
3958 ce.account = account; 4298 ce.account = account;
3959 ce.pinfo = pinfo; 4299 ce.pinfo = pinfo;
4300 m_userInfoCache[uuid] = ce;
3960 } 4301 }
3961 else 4302 else
3962 { 4303 {
@@ -4024,6 +4365,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4024 { 4365 {
4025 m_host.AddScriptLPS(1); 4366 m_host.AddScriptLPS(1);
4026 4367
4368 //Clone is thread safe
4027 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 4369 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
4028 4370
4029 foreach (TaskInventoryItem item in itemDictionary.Values) 4371 foreach (TaskInventoryItem item in itemDictionary.Values)
@@ -4077,6 +4419,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4077 ScenePresence presence = World.GetScenePresence(agentId); 4419 ScenePresence presence = World.GetScenePresence(agentId);
4078 if (presence != null) 4420 if (presence != null)
4079 { 4421 {
4422 // agent must not be a god
4423 if (presence.GodLevel >= 200) return;
4424
4080 // agent must be over the owners land 4425 // agent must be over the owners land
4081 if (m_host.OwnerID == World.LandChannel.GetLandObject( 4426 if (m_host.OwnerID == World.LandChannel.GetLandObject(
4082 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) 4427 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
@@ -4136,17 +4481,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4136 UUID soundId = UUID.Zero; 4481 UUID soundId = UUID.Zero;
4137 if (!UUID.TryParse(impact_sound, out soundId)) 4482 if (!UUID.TryParse(impact_sound, out soundId))
4138 { 4483 {
4139 lock (m_host.TaskInventory) 4484 m_host.TaskInventory.LockItemsForRead(true);
4485 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4140 { 4486 {
4141 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4487 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
4142 { 4488 {
4143 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 4489 soundId = item.AssetID;
4144 { 4490 break;
4145 soundId = item.AssetID;
4146 break;
4147 }
4148 } 4491 }
4149 } 4492 }
4493 m_host.TaskInventory.LockItemsForRead(false);
4150 } 4494 }
4151 m_host.CollisionSound = soundId; 4495 m_host.CollisionSound = soundId;
4152 m_host.CollisionSoundVolume = (float)impact_volume; 4496 m_host.CollisionSoundVolume = (float)impact_volume;
@@ -4192,6 +4536,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4192 UUID partItemID; 4536 UUID partItemID;
4193 foreach (SceneObjectPart part in parts) 4537 foreach (SceneObjectPart part in parts)
4194 { 4538 {
4539 //Clone is thread safe
4195 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); 4540 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
4196 4541
4197 foreach (TaskInventoryItem item in itemsDictionary.Values) 4542 foreach (TaskInventoryItem item in itemsDictionary.Values)
@@ -4406,17 +4751,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4406 4751
4407 m_host.AddScriptLPS(1); 4752 m_host.AddScriptLPS(1);
4408 4753
4409 lock (m_host.TaskInventory) 4754 m_host.TaskInventory.LockItemsForRead(true);
4755 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4410 { 4756 {
4411 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4757 if (item.Type == 10 && item.ItemID == m_itemID)
4412 { 4758 {
4413 if (item.Type == 10 && item.ItemID == m_itemID) 4759 result = item.Name!=null?item.Name:String.Empty;
4414 { 4760 break;
4415 result = item.Name != null ? item.Name : String.Empty;
4416 break;
4417 }
4418 } 4761 }
4419 } 4762 }
4763 m_host.TaskInventory.LockItemsForRead(false);
4420 4764
4421 return result; 4765 return result;
4422 } 4766 }
@@ -4569,23 +4913,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4569 { 4913 {
4570 m_host.AddScriptLPS(1); 4914 m_host.AddScriptLPS(1);
4571 4915
4572 lock (m_host.TaskInventory) 4916 m_host.TaskInventory.LockItemsForRead(true);
4917 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4573 { 4918 {
4574 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4919 if (inv.Value.Name == name)
4575 { 4920 {
4576 if (inv.Value.Name == name) 4921 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
4577 { 4922 {
4578 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) 4923 m_host.TaskInventory.LockItemsForRead(false);
4579 { 4924 return inv.Value.AssetID.ToString();
4580 return inv.Value.AssetID.ToString(); 4925 }
4581 } 4926 else
4582 else 4927 {
4583 { 4928 m_host.TaskInventory.LockItemsForRead(false);
4584 return UUID.Zero.ToString(); 4929 return UUID.Zero.ToString();
4585 }
4586 } 4930 }
4587 } 4931 }
4588 } 4932 }
4933 m_host.TaskInventory.LockItemsForRead(false);
4589 4934
4590 return UUID.Zero.ToString(); 4935 return UUID.Zero.ToString();
4591 } 4936 }
@@ -4738,14 +5083,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4738 { 5083 {
4739 m_host.AddScriptLPS(1); 5084 m_host.AddScriptLPS(1);
4740 5085
4741 if (src == null) 5086 return src.Length;
4742 {
4743 return 0;
4744 }
4745 else
4746 {
4747 return src.Length;
4748 }
4749 } 5087 }
4750 5088
4751 public LSL_Integer llList2Integer(LSL_List src, int index) 5089 public LSL_Integer llList2Integer(LSL_List src, int index)
@@ -4791,7 +5129,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4791 else if (src.Data[index] is LSL_Float) 5129 else if (src.Data[index] is LSL_Float)
4792 return Convert.ToDouble(((LSL_Float) src.Data[index]).value); 5130 return Convert.ToDouble(((LSL_Float) src.Data[index]).value);
4793 else if (src.Data[index] is LSL_String) 5131 else if (src.Data[index] is LSL_String)
4794 return Convert.ToDouble(((LSL_String) src.Data[index]).m_string); 5132 {
5133 string str = ((LSL_String) src.Data[index]).m_string;
5134 Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
5135 if (m != Match.Empty)
5136 {
5137 str = m.Value;
5138 double d = 0.0;
5139 if (!Double.TryParse(str, out d))
5140 return 0.0;
5141
5142 return d;
5143 }
5144 return 0.0;
5145 }
4795 return Convert.ToDouble(src.Data[index]); 5146 return Convert.ToDouble(src.Data[index]);
4796 } 5147 }
4797 catch (FormatException) 5148 catch (FormatException)
@@ -5476,7 +5827,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5476 public void llSetSoundQueueing(int queue) 5827 public void llSetSoundQueueing(int queue)
5477 { 5828 {
5478 m_host.AddScriptLPS(1); 5829 m_host.AddScriptLPS(1);
5479 NotImplemented("llSetSoundQueueing");
5480 } 5830 }
5481 5831
5482 public void llSetSoundRadius(double radius) 5832 public void llSetSoundRadius(double radius)
@@ -5521,10 +5871,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5521 m_host.AddScriptLPS(1); 5871 m_host.AddScriptLPS(1);
5522 5872
5523 List<SceneObjectPart> parts = GetLinkParts(linknumber); 5873 List<SceneObjectPart> parts = GetLinkParts(linknumber);
5524 5874 if (parts.Count > 0)
5525 foreach (var part in parts)
5526 { 5875 {
5527 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate); 5876 try
5877 {
5878 parts[0].ParentGroup.areUpdatesSuspended = true;
5879 foreach (var part in parts)
5880 {
5881 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
5882 }
5883 }
5884 finally
5885 {
5886 parts[0].ParentGroup.areUpdatesSuspended = false;
5887 }
5528 } 5888 }
5529 } 5889 }
5530 5890
@@ -5580,74 +5940,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5580 5940
5581 public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers) 5941 public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
5582 { 5942 {
5583 m_host.AddScriptLPS(1); 5943 return ParseString2List(str, separators, in_spacers, false);
5584 LSL_List ret = new LSL_List();
5585 LSL_List spacers = new LSL_List();
5586 if (in_spacers.Length > 0 && separators.Length > 0)
5587 {
5588 for (int i = 0; i < in_spacers.Length; i++)
5589 {
5590 object s = in_spacers.Data[i];
5591 for (int j = 0; j < separators.Length; j++)
5592 {
5593 if (separators.Data[j].ToString() == s.ToString())
5594 {
5595 s = null;
5596 break;
5597 }
5598 }
5599 if (s != null)
5600 {
5601 spacers.Add(s);
5602 }
5603 }
5604 }
5605 object[] delimiters = new object[separators.Length + spacers.Length];
5606 separators.Data.CopyTo(delimiters, 0);
5607 spacers.Data.CopyTo(delimiters, separators.Length);
5608 bool dfound = false;
5609 do
5610 {
5611 dfound = false;
5612 int cindex = -1;
5613 string cdeli = "";
5614 for (int i = 0; i < delimiters.Length; i++)
5615 {
5616 int index = str.IndexOf(delimiters[i].ToString());
5617 bool found = index != -1;
5618 if (found && String.Empty != delimiters[i].ToString())
5619 {
5620 if ((cindex > index) || (cindex == -1))
5621 {
5622 cindex = index;
5623 cdeli = delimiters[i].ToString();
5624 }
5625 dfound = dfound || found;
5626 }
5627 }
5628 if (cindex != -1)
5629 {
5630 if (cindex > 0)
5631 {
5632 ret.Add(new LSL_String(str.Substring(0, cindex)));
5633 }
5634 // Cannot use spacers.Contains() because spacers may be either type String or LSLString
5635 for (int j = 0; j < spacers.Length; j++)
5636 {
5637 if (spacers.Data[j].ToString() == cdeli)
5638 {
5639 ret.Add(new LSL_String(cdeli));
5640 break;
5641 }
5642 }
5643 str = str.Substring(cindex + cdeli.Length);
5644 }
5645 } while (dfound);
5646 if (str != "")
5647 {
5648 ret.Add(new LSL_String(str));
5649 }
5650 return ret;
5651 } 5944 }
5652 5945
5653 public LSL_Integer llOverMyLand(string id) 5946 public LSL_Integer llOverMyLand(string id)
@@ -5850,7 +6143,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5850 return m_host.ParentGroup.RootPart.AttachmentPoint; 6143 return m_host.ParentGroup.RootPart.AttachmentPoint;
5851 } 6144 }
5852 6145
5853 public LSL_Integer llGetFreeMemory() 6146 public virtual LSL_Integer llGetFreeMemory()
5854 { 6147 {
5855 m_host.AddScriptLPS(1); 6148 m_host.AddScriptLPS(1);
5856 // Make scripts designed for LSO happy 6149 // Make scripts designed for LSO happy
@@ -6161,14 +6454,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6161 6454
6162 protected UUID GetTaskInventoryItem(string name) 6455 protected UUID GetTaskInventoryItem(string name)
6163 { 6456 {
6164 lock (m_host.TaskInventory) 6457 m_host.TaskInventory.LockItemsForRead(true);
6458 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6165 { 6459 {
6166 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6460 if (inv.Value.Name == name)
6167 { 6461 {
6168 if (inv.Value.Name == name) 6462 m_host.TaskInventory.LockItemsForRead(false);
6169 return inv.Key; 6463 return inv.Key;
6170 } 6464 }
6171 } 6465 }
6466 m_host.TaskInventory.LockItemsForRead(false);
6172 6467
6173 return UUID.Zero; 6468 return UUID.Zero;
6174 } 6469 }
@@ -6496,22 +6791,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6496 } 6791 }
6497 6792
6498 // copy the first script found with this inventory name 6793 // copy the first script found with this inventory name
6499 lock (m_host.TaskInventory) 6794 m_host.TaskInventory.LockItemsForRead(true);
6795 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6500 { 6796 {
6501 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6797 if (inv.Value.Name == name)
6502 { 6798 {
6503 if (inv.Value.Name == name) 6799 // make sure the object is a script
6800 if (10 == inv.Value.Type)
6504 { 6801 {
6505 // make sure the object is a script 6802 found = true;
6506 if (10 == inv.Value.Type) 6803 srcId = inv.Key;
6507 { 6804 break;
6508 found = true;
6509 srcId = inv.Key;
6510 break;
6511 }
6512 } 6805 }
6513 } 6806 }
6514 } 6807 }
6808 m_host.TaskInventory.LockItemsForRead(false);
6515 6809
6516 if (!found) 6810 if (!found)
6517 { 6811 {
@@ -6595,6 +6889,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6595 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist) 6889 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist)
6596 { 6890 {
6597 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 6891 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6892 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6893 return shapeBlock;
6598 6894
6599 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && 6895 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
6600 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && 6896 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
@@ -6670,6 +6966,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6670 6966
6671 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge) 6967 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge)
6672 { 6968 {
6969 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6970 return;
6971
6673 ObjectShapePacket.ObjectDataBlock shapeBlock; 6972 ObjectShapePacket.ObjectDataBlock shapeBlock;
6674 6973
6675 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 6974 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6719,6 +7018,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6719 7018
6720 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge) 7019 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge)
6721 { 7020 {
7021 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7022 return;
7023
6722 ObjectShapePacket.ObjectDataBlock shapeBlock; 7024 ObjectShapePacket.ObjectDataBlock shapeBlock;
6723 7025
6724 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7026 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6761,6 +7063,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6761 7063
6762 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) 7064 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)
6763 { 7065 {
7066 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7067 return;
7068
6764 ObjectShapePacket.ObjectDataBlock shapeBlock; 7069 ObjectShapePacket.ObjectDataBlock shapeBlock;
6765 7070
6766 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7071 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6887,6 +7192,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6887 7192
6888 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type) 7193 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type)
6889 { 7194 {
7195 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7196 return;
7197
6890 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7198 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6891 UUID sculptId; 7199 UUID sculptId;
6892 7200
@@ -6902,13 +7210,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6902 shapeBlock.PathScaleX = 100; 7210 shapeBlock.PathScaleX = 100;
6903 shapeBlock.PathScaleY = 150; 7211 shapeBlock.PathScaleY = 150;
6904 7212
6905 if (type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER && 7213 if ((type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER) == 0 &&
6906 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE && 7214 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE) == 0 &&
6907 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE && 7215 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE) == 0 &&
6908 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) 7216 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) == 0)
6909 { 7217 {
6910 // default 7218 // default
6911 type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; 7219 type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
6912 } 7220 }
6913 7221
6914 // retain pathcurve 7222 // retain pathcurve
@@ -6925,23 +7233,83 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6925 SetPrimParams(m_host, rules); 7233 SetPrimParams(m_host, rules);
6926 } 7234 }
6927 7235
6928 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) 7236 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
6929 { 7237 {
6930 m_host.AddScriptLPS(1); 7238 m_host.AddScriptLPS(1);
6931 7239
6932 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7240 List<SceneObjectPart> parts = GetLinkParts(linknumber);
7241 List<ScenePresence> avatars = GetLinkAvatars(linknumber);
7242 if (parts.Count>0)
7243 {
7244 try
7245 {
7246 parts[0].ParentGroup.areUpdatesSuspended = true;
7247 foreach (SceneObjectPart part in parts)
7248 SetPrimParams(part, rules);
7249 }
7250 finally
7251 {
7252 parts[0].ParentGroup.areUpdatesSuspended = false;
7253 }
7254 }
7255 if (avatars.Count > 0)
7256 {
7257 foreach (ScenePresence avatar in avatars)
7258 SetPrimParams(avatar, rules);
7259 }
7260 }
6933 7261
6934 foreach (SceneObjectPart part in parts) 7262 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
6935 SetPrimParams(part, rules); 7263 {
7264 llSetLinkPrimitiveParamsFast(linknumber, rules);
7265 ScriptSleep(200);
6936 } 7266 }
6937 7267
6938 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) 7268 protected void SetPrimParams(ScenePresence av, LSL_List rules)
6939 { 7269 {
6940 llSetLinkPrimitiveParams(linknumber, rules); 7270 //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
7271 //We only support PRIM_POSITION and PRIM_ROTATION
7272
7273 int idx = 0;
7274
7275 while (idx < rules.Length)
7276 {
7277 int code = rules.GetLSLIntegerItem(idx++);
7278
7279 int remain = rules.Length - idx;
7280
7281
7282
7283 switch (code)
7284 {
7285 case (int)ScriptBaseClass.PRIM_POSITION:
7286 if (remain < 1)
7287 return;
7288 LSL_Vector v;
7289 v = rules.GetVector3Item(idx++);
7290 av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
7291 av.SendFullUpdateToAllClients();
7292
7293 break;
7294
7295 case (int)ScriptBaseClass.PRIM_ROTATION:
7296 if (remain < 1)
7297 return;
7298 LSL_Rotation r;
7299 r = rules.GetQuaternionItem(idx++);
7300 av.OffsetRotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
7301 av.SendFullUpdateToAllClients();
7302 break;
7303 }
7304 }
7305
6941 } 7306 }
6942 7307
6943 protected void SetPrimParams(SceneObjectPart part, LSL_List rules) 7308 protected void SetPrimParams(SceneObjectPart part, LSL_List rules)
6944 { 7309 {
7310 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7311 return;
7312
6945 int idx = 0; 7313 int idx = 0;
6946 7314
6947 while (idx < rules.Length) 7315 while (idx < rules.Length)
@@ -7458,13 +7826,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7458 public LSL_Integer llGetNumberOfPrims() 7826 public LSL_Integer llGetNumberOfPrims()
7459 { 7827 {
7460 m_host.AddScriptLPS(1); 7828 m_host.AddScriptLPS(1);
7461 int avatarCount = 0; 7829 int avatarCount = m_host.ParentGroup.GetLinkedAvatars().Count;
7462 World.ForEachScenePresence(delegate(ScenePresence presence) 7830
7463 {
7464 if (!presence.IsChildAgent && presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID))
7465 avatarCount++;
7466 });
7467
7468 return m_host.ParentGroup.PrimCount + avatarCount; 7831 return m_host.ParentGroup.PrimCount + avatarCount;
7469 } 7832 }
7470 7833
@@ -7480,55 +7843,98 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7480 m_host.AddScriptLPS(1); 7843 m_host.AddScriptLPS(1);
7481 UUID objID = UUID.Zero; 7844 UUID objID = UUID.Zero;
7482 LSL_List result = new LSL_List(); 7845 LSL_List result = new LSL_List();
7846
7847 // If the ID is not valid, return null result
7483 if (!UUID.TryParse(obj, out objID)) 7848 if (!UUID.TryParse(obj, out objID))
7484 { 7849 {
7485 result.Add(new LSL_Vector()); 7850 result.Add(new LSL_Vector());
7486 result.Add(new LSL_Vector()); 7851 result.Add(new LSL_Vector());
7487 return result; 7852 return result;
7488 } 7853 }
7854
7855 // Check if this is an attached prim. If so, replace
7856 // the UUID with the avatar UUID and report it's bounding box
7857 SceneObjectPart part = World.GetSceneObjectPart(objID);
7858 if (part != null && part.ParentGroup.IsAttachment)
7859 objID = part.ParentGroup.RootPart.AttachedAvatar;
7860
7861 // Find out if this is an avatar ID. If so, return it's box
7489 ScenePresence presence = World.GetScenePresence(objID); 7862 ScenePresence presence = World.GetScenePresence(objID);
7490 if (presence != null) 7863 if (presence != null)
7491 { 7864 {
7492 if (presence.ParentID == 0) // not sat on an object 7865 // As per LSL Wiki, there is no difference between sitting
7866 // and standing avatar since server 1.36
7867 LSL_Vector lower;
7868 LSL_Vector upper;
7869 if (presence.Animator.Animations.DefaultAnimation.AnimID
7870 == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
7493 { 7871 {
7494 LSL_Vector lower; 7872 // This is for ground sitting avatars
7495 LSL_Vector upper; 7873 float height = presence.Appearance.AvatarHeight / 2.66666667f;
7496 if (presence.Animator.Animations.DefaultAnimation.AnimID 7874 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
7497 == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) 7875 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
7498 {
7499 // This is for ground sitting avatars
7500 float height = presence.Appearance.AvatarHeight / 2.66666667f;
7501 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
7502 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
7503 }
7504 else
7505 {
7506 // This is for standing/flying avatars
7507 float height = presence.Appearance.AvatarHeight / 2.0f;
7508 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
7509 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
7510 }
7511 result.Add(lower);
7512 result.Add(upper);
7513 return result;
7514 } 7876 }
7515 else 7877 else
7516 { 7878 {
7517 // sitting on an object so we need the bounding box of that 7879 // This is for standing/flying avatars
7518 // which should include the avatar so set the UUID to the 7880 float height = presence.Appearance.AvatarHeight / 2.0f;
7519 // UUID of the object the avatar is sat on and allow it to fall through 7881 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
7520 // to processing an object 7882 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
7521 SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
7522 objID = p.UUID;
7523 } 7883 }
7884
7885 // Adjust to the documented error offsets (see LSL Wiki)
7886 lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
7887 upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
7888
7889 if (lower.x > upper.x)
7890 lower.x = upper.x;
7891 if (lower.y > upper.y)
7892 lower.y = upper.y;
7893 if (lower.z > upper.z)
7894 lower.z = upper.z;
7895
7896 result.Add(lower);
7897 result.Add(upper);
7898 return result;
7524 } 7899 }
7525 SceneObjectPart part = World.GetSceneObjectPart(objID); 7900
7901 part = World.GetSceneObjectPart(objID);
7526 // Currently only works for single prims without a sitting avatar 7902 // Currently only works for single prims without a sitting avatar
7527 if (part != null) 7903 if (part != null)
7528 { 7904 {
7529 Vector3 halfSize = part.Scale / 2.0f; 7905 float minX;
7530 LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f); 7906 float maxX;
7531 LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z); 7907 float minY;
7908 float maxY;
7909 float minZ;
7910 float maxZ;
7911
7912 // This BBox is in sim coordinates, with the offset being
7913 // a contained point.
7914 Vector3[] offsets = World.GetCombinedBoundingBox(new List<SceneObjectGroup> { part.ParentGroup },
7915 out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
7916
7917 minX -= offsets[0].X;
7918 maxX -= offsets[0].X;
7919 minY -= offsets[0].Y;
7920 maxY -= offsets[0].Y;
7921 minZ -= offsets[0].Z;
7922 maxZ -= offsets[0].Z;
7923
7924 LSL_Vector lower;
7925 LSL_Vector upper;
7926
7927 // Adjust to the documented error offsets (see LSL Wiki)
7928 lower = new LSL_Vector(minX + 0.05f, minY + 0.05f, minZ + 0.05f);
7929 upper = new LSL_Vector(maxX - 0.05f, maxY - 0.05f, maxZ - 0.05f);
7930
7931 if (lower.x > upper.x)
7932 lower.x = upper.x;
7933 if (lower.y > upper.y)
7934 lower.y = upper.y;
7935 if (lower.z > upper.z)
7936 lower.z = upper.z;
7937
7532 result.Add(lower); 7938 result.Add(lower);
7533 result.Add(upper); 7939 result.Add(upper);
7534 return result; 7940 return result;
@@ -7773,24 +8179,95 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7773 break; 8179 break;
7774 8180
7775 case (int)ScriptBaseClass.PRIM_BUMP_SHINY: 8181 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
7776 // TODO--------------
7777 if (remain < 1) 8182 if (remain < 1)
7778 return res; 8183 return res;
8184 face = (int)rules.GetLSLIntegerItem(idx++);
7779 8185
7780 face=(int)rules.GetLSLIntegerItem(idx++); 8186 tex = part.Shape.Textures;
7781 8187 int shiny;
7782 res.Add(new LSL_Integer(0)); 8188 if (face == ScriptBaseClass.ALL_SIDES)
7783 res.Add(new LSL_Integer(0)); 8189 {
8190 for (face = 0; face < GetNumberOfSides(part); face++)
8191 {
8192 Shininess shinyness = tex.GetFace((uint)face).Shiny;
8193 if (shinyness == Shininess.High)
8194 {
8195 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
8196 }
8197 else if (shinyness == Shininess.Medium)
8198 {
8199 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8200 }
8201 else if (shinyness == Shininess.Low)
8202 {
8203 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8204 }
8205 else
8206 {
8207 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8208 }
8209 res.Add(new LSL_Integer(shiny));
8210 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
8211 }
8212 }
8213 else
8214 {
8215 Shininess shinyness = tex.GetFace((uint)face).Shiny;
8216 if (shinyness == Shininess.High)
8217 {
8218 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
8219 }
8220 else if (shinyness == Shininess.Medium)
8221 {
8222 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8223 }
8224 else if (shinyness == Shininess.Low)
8225 {
8226 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8227 }
8228 else
8229 {
8230 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8231 }
8232 res.Add(new LSL_Integer(shiny));
8233 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
8234 }
7784 break; 8235 break;
7785 8236
7786 case (int)ScriptBaseClass.PRIM_FULLBRIGHT: 8237 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
7787 // TODO--------------
7788 if (remain < 1) 8238 if (remain < 1)
7789 return res; 8239 return res;
8240 face = (int)rules.GetLSLIntegerItem(idx++);
7790 8241
7791 face=(int)rules.GetLSLIntegerItem(idx++); 8242 tex = part.Shape.Textures;
7792 8243 int fullbright;
7793 res.Add(new LSL_Integer(0)); 8244 if (face == ScriptBaseClass.ALL_SIDES)
8245 {
8246 for (face = 0; face < GetNumberOfSides(part); face++)
8247 {
8248 if (tex.GetFace((uint)face).Fullbright == true)
8249 {
8250 fullbright = ScriptBaseClass.TRUE;
8251 }
8252 else
8253 {
8254 fullbright = ScriptBaseClass.FALSE;
8255 }
8256 res.Add(new LSL_Integer(fullbright));
8257 }
8258 }
8259 else
8260 {
8261 if (tex.GetFace((uint)face).Fullbright == true)
8262 {
8263 fullbright = ScriptBaseClass.TRUE;
8264 }
8265 else
8266 {
8267 fullbright = ScriptBaseClass.FALSE;
8268 }
8269 res.Add(new LSL_Integer(fullbright));
8270 }
7794 break; 8271 break;
7795 8272
7796 case (int)ScriptBaseClass.PRIM_FLEXIBLE: 8273 case (int)ScriptBaseClass.PRIM_FLEXIBLE:
@@ -7811,14 +8288,37 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7811 break; 8288 break;
7812 8289
7813 case (int)ScriptBaseClass.PRIM_TEXGEN: 8290 case (int)ScriptBaseClass.PRIM_TEXGEN:
7814 // TODO--------------
7815 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR) 8291 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
7816 if (remain < 1) 8292 if (remain < 1)
7817 return res; 8293 return res;
8294 face = (int)rules.GetLSLIntegerItem(idx++);
7818 8295
7819 face=(int)rules.GetLSLIntegerItem(idx++); 8296 tex = part.Shape.Textures;
7820 8297 if (face == ScriptBaseClass.ALL_SIDES)
7821 res.Add(new LSL_Integer(0)); 8298 {
8299 for (face = 0; face < GetNumberOfSides(part); face++)
8300 {
8301 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8302 {
8303 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8304 }
8305 else
8306 {
8307 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8308 }
8309 }
8310 }
8311 else
8312 {
8313 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8314 {
8315 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8316 }
8317 else
8318 {
8319 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8320 }
8321 }
7822 break; 8322 break;
7823 8323
7824 case (int)ScriptBaseClass.PRIM_POINT_LIGHT: 8324 case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
@@ -7837,13 +8337,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7837 break; 8337 break;
7838 8338
7839 case (int)ScriptBaseClass.PRIM_GLOW: 8339 case (int)ScriptBaseClass.PRIM_GLOW:
7840 // TODO--------------
7841 if (remain < 1) 8340 if (remain < 1)
7842 return res; 8341 return res;
8342 face = (int)rules.GetLSLIntegerItem(idx++);
7843 8343
7844 face=(int)rules.GetLSLIntegerItem(idx++); 8344 tex = part.Shape.Textures;
7845 8345 float primglow;
7846 res.Add(new LSL_Float(0)); 8346 if (face == ScriptBaseClass.ALL_SIDES)
8347 {
8348 for (face = 0; face < GetNumberOfSides(part); face++)
8349 {
8350 primglow = tex.GetFace((uint)face).Glow;
8351 res.Add(new LSL_Float(primglow));
8352 }
8353 }
8354 else
8355 {
8356 primglow = tex.GetFace((uint)face).Glow;
8357 res.Add(new LSL_Float(primglow));
8358 }
7847 break; 8359 break;
7848 case (int)ScriptBaseClass.PRIM_TEXT: 8360 case (int)ScriptBaseClass.PRIM_TEXT:
7849 Color4 textColor = part.GetTextColor(); 8361 Color4 textColor = part.GetTextColor();
@@ -8384,8 +8896,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8384 // The function returns an ordered list 8896 // The function returns an ordered list
8385 // representing the tokens found in the supplied 8897 // representing the tokens found in the supplied
8386 // sources string. If two successive tokenizers 8898 // sources string. If two successive tokenizers
8387 // are encountered, then a NULL entry is added 8899 // are encountered, then a null-string entry is
8388 // to the list. 8900 // added to the list.
8389 // 8901 //
8390 // It is a precondition that the source and 8902 // It is a precondition that the source and
8391 // toekizer lisst are non-null. If they are null, 8903 // toekizer lisst are non-null. If they are null,
@@ -8393,7 +8905,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8393 // while their lengths are being determined. 8905 // while their lengths are being determined.
8394 // 8906 //
8395 // A small amount of working memoryis required 8907 // A small amount of working memoryis required
8396 // of approximately 8*#tokenizers. 8908 // of approximately 8*#tokenizers + 8*srcstrlen.
8397 // 8909 //
8398 // There are many ways in which this function 8910 // There are many ways in which this function
8399 // can be implemented, this implementation is 8911 // can be implemented, this implementation is
@@ -8409,136 +8921,111 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8409 // and eliminates redundant tokenizers as soon 8921 // and eliminates redundant tokenizers as soon
8410 // as is possible. 8922 // as is possible.
8411 // 8923 //
8412 // The implementation tries to avoid any copying 8924 // The implementation tries to minimize temporary
8413 // of arrays or other objects. 8925 // garbage generation.
8414 // </remarks> 8926 // </remarks>
8415 8927
8416 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers) 8928 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
8417 { 8929 {
8418 int beginning = 0; 8930 return ParseString2List(src, separators, spacers, true);
8419 int srclen = src.Length; 8931 }
8420 int seplen = separators.Length;
8421 object[] separray = separators.Data;
8422 int spclen = spacers.Length;
8423 object[] spcarray = spacers.Data;
8424 int mlen = seplen+spclen;
8425
8426 int[] offset = new int[mlen+1];
8427 bool[] active = new bool[mlen];
8428 8932
8429 int best; 8933 private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
8430 int j; 8934 {
8935 int srclen = src.Length;
8936 int seplen = separators.Length;
8937 object[] separray = separators.Data;
8938 int spclen = spacers.Length;
8939 object[] spcarray = spacers.Data;
8940 int dellen = 0;
8941 string[] delarray = new string[seplen+spclen];
8431 8942
8432 // Initial capacity reduces resize cost 8943 int outlen = 0;
8944 string[] outarray = new string[srclen*2+1];
8433 8945
8434 LSL_List tokens = new LSL_List(); 8946 int i, j;
8947 string d;
8435 8948
8436 m_host.AddScriptLPS(1); 8949 m_host.AddScriptLPS(1);
8437 8950
8438 // All entries are initially valid 8951 /*
8439 8952 * Convert separator and spacer lists to C# strings.
8440 for (int i = 0; i < mlen; i++) 8953 * Also filter out null strings so we don't hang.
8441 active[i] = true; 8954 */
8442 8955 for (i = 0; i < seplen; i ++) {
8443 offset[mlen] = srclen; 8956 d = separray[i].ToString();
8444 8957 if (d.Length > 0) {
8445 while (beginning < srclen) 8958 delarray[dellen++] = d;
8446 { 8959 }
8447 8960 }
8448 best = mlen; // as bad as it gets 8961 seplen = dellen;
8449
8450 // Scan for separators
8451 8962
8452 for (j = 0; j < seplen; j++) 8963 for (i = 0; i < spclen; i ++) {
8453 { 8964 d = spcarray[i].ToString();
8454 if (active[j]) 8965 if (d.Length > 0) {
8455 { 8966 delarray[dellen++] = d;
8456 // scan all of the markers
8457 if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1)
8458 {
8459 // not present at all
8460 active[j] = false;
8461 }
8462 else
8463 {
8464 // present and correct
8465 if (offset[j] < offset[best])
8466 {
8467 // closest so far
8468 best = j;
8469 if (offset[best] == beginning)
8470 break;
8471 }
8472 }
8473 }
8474 } 8967 }
8968 }
8475 8969
8476 // Scan for spacers 8970 /*
8971 * Scan through source string from beginning to end.
8972 */
8973 for (i = 0;;) {
8477 8974
8478 if (offset[best] != beginning) 8975 /*
8479 { 8976 * Find earliest delimeter in src starting at i (if any).
8480 for (j = seplen; (j < mlen) && (offset[best] > beginning); j++) 8977 */
8481 { 8978 int earliestDel = -1;
8482 if (active[j]) 8979 int earliestSrc = srclen;
8483 { 8980 string earliestStr = null;
8484 // scan all of the markers 8981 for (j = 0; j < dellen; j ++) {
8485 if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1) 8982 d = delarray[j];
8486 { 8983 if (d != null) {
8487 // not present at all 8984 int index = src.IndexOf(d, i);
8488 active[j] = false; 8985 if (index < 0) {
8489 } 8986 delarray[j] = null; // delim nowhere in src, don't check it anymore
8490 else 8987 } else if (index < earliestSrc) {
8491 { 8988 earliestSrc = index; // where delimeter starts in source string
8492 // present and correct 8989 earliestDel = j; // where delimeter is in delarray[]
8493 if (offset[j] < offset[best]) 8990 earliestStr = d; // the delimeter string from delarray[]
8494 { 8991 if (index == i) break; // can't do any better than found at beg of string
8495 // closest so far
8496 best = j;
8497 }
8498 }
8499 } 8992 }
8500 } 8993 }
8501 } 8994 }
8502 8995
8503 // This is the normal exit from the scanning loop 8996 /*
8504 8997 * Output source string starting at i through start of earliest delimeter.
8505 if (best == mlen) 8998 */
8506 { 8999 if (keepNulls || (earliestSrc > i)) {
8507 // no markers were found on this pass 9000 outarray[outlen++] = src.Substring(i, earliestSrc - i);
8508 // so we're pretty much done
8509 tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
8510 break;
8511 } 9001 }
8512 9002
8513 // Otherwise we just add the newly delimited token 9003 /*
8514 // and recalculate where the search should continue. 9004 * If no delimeter found at or after i, we're done scanning.
8515 9005 */
8516 tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning))); 9006 if (earliestDel < 0) break;
8517 9007
8518 if (best < seplen) 9008 /*
8519 { 9009 * If delimeter was a spacer, output the spacer.
8520 beginning = offset[best] + (separray[best].ToString()).Length; 9010 */
8521 } 9011 if (earliestDel >= seplen) {
8522 else 9012 outarray[outlen++] = earliestStr;
8523 {
8524 beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
8525 tokens.Add(new LSL_String(spcarray[best - seplen].ToString()));
8526 } 9013 }
8527 }
8528
8529 // This an awkward an not very intuitive boundary case. If the
8530 // last substring is a tokenizer, then there is an implied trailing
8531 // null list entry. Hopefully the single comparison will not be too
8532 // arduous. Alternatively the 'break' could be replced with a return
8533 // but that's shabby programming.
8534 9014
8535 if (beginning == srclen) 9015 /*
8536 { 9016 * Look at rest of src string following delimeter.
8537 if (srclen != 0) 9017 */
8538 tokens.Add(new LSL_String("")); 9018 i = earliestSrc + earliestStr.Length;
8539 } 9019 }
8540 9020
8541 return tokens; 9021 /*
9022 * Make up an exact-sized output array suitable for an LSL_List object.
9023 */
9024 object[] outlist = new object[outlen];
9025 for (i = 0; i < outlen; i ++) {
9026 outlist[i] = new LSL_String(outarray[i]);
9027 }
9028 return new LSL_List(outlist);
8542 } 9029 }
8543 9030
8544 public LSL_Integer llGetObjectPermMask(int mask) 9031 public LSL_Integer llGetObjectPermMask(int mask)
@@ -8615,28 +9102,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8615 { 9102 {
8616 m_host.AddScriptLPS(1); 9103 m_host.AddScriptLPS(1);
8617 9104
8618 lock (m_host.TaskInventory) 9105 m_host.TaskInventory.LockItemsForRead(true);
9106 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8619 { 9107 {
8620 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9108 if (inv.Value.Name == item)
8621 { 9109 {
8622 if (inv.Value.Name == item) 9110 m_host.TaskInventory.LockItemsForRead(false);
9111 switch (mask)
8623 { 9112 {
8624 switch (mask) 9113 case 0:
8625 { 9114 return (int)inv.Value.BasePermissions;
8626 case 0: 9115 case 1:
8627 return (int)inv.Value.BasePermissions; 9116 return (int)inv.Value.CurrentPermissions;
8628 case 1: 9117 case 2:
8629 return (int)inv.Value.CurrentPermissions; 9118 return (int)inv.Value.GroupPermissions;
8630 case 2: 9119 case 3:
8631 return (int)inv.Value.GroupPermissions; 9120 return (int)inv.Value.EveryonePermissions;
8632 case 3: 9121 case 4:
8633 return (int)inv.Value.EveryonePermissions; 9122 return (int)inv.Value.NextPermissions;
8634 case 4:
8635 return (int)inv.Value.NextPermissions;
8636 }
8637 } 9123 }
8638 } 9124 }
8639 } 9125 }
9126 m_host.TaskInventory.LockItemsForRead(false);
8640 9127
8641 return -1; 9128 return -1;
8642 } 9129 }
@@ -8683,16 +9170,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8683 { 9170 {
8684 m_host.AddScriptLPS(1); 9171 m_host.AddScriptLPS(1);
8685 9172
8686 lock (m_host.TaskInventory) 9173 m_host.TaskInventory.LockItemsForRead(true);
9174 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8687 { 9175 {
8688 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9176 if (inv.Value.Name == item)
8689 { 9177 {
8690 if (inv.Value.Name == item) 9178 m_host.TaskInventory.LockItemsForRead(false);
8691 { 9179 return inv.Value.CreatorID.ToString();
8692 return inv.Value.CreatorID.ToString();
8693 }
8694 } 9180 }
8695 } 9181 }
9182 m_host.TaskInventory.LockItemsForRead(false);
8696 9183
8697 llSay(0, "No item name '" + item + "'"); 9184 llSay(0, "No item name '" + item + "'");
8698 9185
@@ -8743,8 +9230,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8743 return UUID.Zero.ToString(); 9230 return UUID.Zero.ToString();
8744 } 9231 }
8745 reply = new LSL_Vector( 9232 reply = new LSL_Vector(
8746 info.RegionLocX * Constants.RegionSize, 9233 info.RegionLocX,
8747 info.RegionLocY * Constants.RegionSize, 9234 info.RegionLocY,
8748 0).ToString(); 9235 0).ToString();
8749 break; 9236 break;
8750 case 6: // DATA_SIM_STATUS 9237 case 6: // DATA_SIM_STATUS
@@ -8957,17 +9444,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8957 int width = 0; 9444 int width = 0;
8958 int height = 0; 9445 int height = 0;
8959 9446
8960 ParcelMediaCommandEnum? commandToSend = null; 9447 uint commandToSend = 0;
8961 float time = 0.0f; // default is from start 9448 float time = 0.0f; // default is from start
8962 9449
8963 ScenePresence presence = null; 9450 ScenePresence presence = null;
8964 9451
8965 for (int i = 0; i < commandList.Data.Length; i++) 9452 for (int i = 0; i < commandList.Data.Length; i++)
8966 { 9453 {
8967 ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i]; 9454 uint command = (uint)(commandList.GetLSLIntegerItem(i));
8968 switch (command) 9455 switch (command)
8969 { 9456 {
8970 case ParcelMediaCommandEnum.Agent: 9457 case (uint)ParcelMediaCommandEnum.Agent:
8971 // we send only to one agent 9458 // we send only to one agent
8972 if ((i + 1) < commandList.Length) 9459 if ((i + 1) < commandList.Length)
8973 { 9460 {
@@ -8984,25 +9471,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8984 } 9471 }
8985 break; 9472 break;
8986 9473
8987 case ParcelMediaCommandEnum.Loop: 9474 case (uint)ParcelMediaCommandEnum.Loop:
8988 loop = 1; 9475 loop = 1;
8989 commandToSend = command; 9476 commandToSend = command;
8990 update = true; //need to send the media update packet to set looping 9477 update = true; //need to send the media update packet to set looping
8991 break; 9478 break;
8992 9479
8993 case ParcelMediaCommandEnum.Play: 9480 case (uint)ParcelMediaCommandEnum.Play:
8994 loop = 0; 9481 loop = 0;
8995 commandToSend = command; 9482 commandToSend = command;
8996 update = true; //need to send the media update packet to make sure it doesn't loop 9483 update = true; //need to send the media update packet to make sure it doesn't loop
8997 break; 9484 break;
8998 9485
8999 case ParcelMediaCommandEnum.Pause: 9486 case (uint)ParcelMediaCommandEnum.Pause:
9000 case ParcelMediaCommandEnum.Stop: 9487 case (uint)ParcelMediaCommandEnum.Stop:
9001 case ParcelMediaCommandEnum.Unload: 9488 case (uint)ParcelMediaCommandEnum.Unload:
9002 commandToSend = command; 9489 commandToSend = command;
9003 break; 9490 break;
9004 9491
9005 case ParcelMediaCommandEnum.Url: 9492 case (uint)ParcelMediaCommandEnum.Url:
9006 if ((i + 1) < commandList.Length) 9493 if ((i + 1) < commandList.Length)
9007 { 9494 {
9008 if (commandList.Data[i + 1] is LSL_String) 9495 if (commandList.Data[i + 1] is LSL_String)
@@ -9015,7 +9502,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9015 } 9502 }
9016 break; 9503 break;
9017 9504
9018 case ParcelMediaCommandEnum.Texture: 9505 case (uint)ParcelMediaCommandEnum.Texture:
9019 if ((i + 1) < commandList.Length) 9506 if ((i + 1) < commandList.Length)
9020 { 9507 {
9021 if (commandList.Data[i + 1] is LSL_String) 9508 if (commandList.Data[i + 1] is LSL_String)
@@ -9028,7 +9515,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9028 } 9515 }
9029 break; 9516 break;
9030 9517
9031 case ParcelMediaCommandEnum.Time: 9518 case (uint)ParcelMediaCommandEnum.Time:
9032 if ((i + 1) < commandList.Length) 9519 if ((i + 1) < commandList.Length)
9033 { 9520 {
9034 if (commandList.Data[i + 1] is LSL_Float) 9521 if (commandList.Data[i + 1] is LSL_Float)
@@ -9040,7 +9527,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9040 } 9527 }
9041 break; 9528 break;
9042 9529
9043 case ParcelMediaCommandEnum.AutoAlign: 9530 case (uint)ParcelMediaCommandEnum.AutoAlign:
9044 if ((i + 1) < commandList.Length) 9531 if ((i + 1) < commandList.Length)
9045 { 9532 {
9046 if (commandList.Data[i + 1] is LSL_Integer) 9533 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9054,7 +9541,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9054 } 9541 }
9055 break; 9542 break;
9056 9543
9057 case ParcelMediaCommandEnum.Type: 9544 case (uint)ParcelMediaCommandEnum.Type:
9058 if ((i + 1) < commandList.Length) 9545 if ((i + 1) < commandList.Length)
9059 { 9546 {
9060 if (commandList.Data[i + 1] is LSL_String) 9547 if (commandList.Data[i + 1] is LSL_String)
@@ -9067,7 +9554,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9067 } 9554 }
9068 break; 9555 break;
9069 9556
9070 case ParcelMediaCommandEnum.Desc: 9557 case (uint)ParcelMediaCommandEnum.Desc:
9071 if ((i + 1) < commandList.Length) 9558 if ((i + 1) < commandList.Length)
9072 { 9559 {
9073 if (commandList.Data[i + 1] is LSL_String) 9560 if (commandList.Data[i + 1] is LSL_String)
@@ -9080,7 +9567,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9080 } 9567 }
9081 break; 9568 break;
9082 9569
9083 case ParcelMediaCommandEnum.Size: 9570 case (uint)ParcelMediaCommandEnum.Size:
9084 if ((i + 2) < commandList.Length) 9571 if ((i + 2) < commandList.Length)
9085 { 9572 {
9086 if (commandList.Data[i + 1] is LSL_Integer) 9573 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9150,7 +9637,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9150 } 9637 }
9151 } 9638 }
9152 9639
9153 if (commandToSend != null) 9640 if (commandToSend != 0)
9154 { 9641 {
9155 // the commandList contained a start/stop/... command, too 9642 // the commandList contained a start/stop/... command, too
9156 if (presence == null) 9643 if (presence == null)
@@ -9187,7 +9674,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9187 9674
9188 if (aList.Data[i] != null) 9675 if (aList.Data[i] != null)
9189 { 9676 {
9190 switch ((ParcelMediaCommandEnum) aList.Data[i]) 9677 switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
9191 { 9678 {
9192 case ParcelMediaCommandEnum.Url: 9679 case ParcelMediaCommandEnum.Url:
9193 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL)); 9680 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL));
@@ -9230,16 +9717,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9230 { 9717 {
9231 m_host.AddScriptLPS(1); 9718 m_host.AddScriptLPS(1);
9232 9719
9233 lock (m_host.TaskInventory) 9720 m_host.TaskInventory.LockItemsForRead(true);
9721 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
9234 { 9722 {
9235 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9723 if (inv.Value.Name == name)
9236 { 9724 {
9237 if (inv.Value.Name == name) 9725 m_host.TaskInventory.LockItemsForRead(false);
9238 { 9726 return inv.Value.Type;
9239 return inv.Value.Type;
9240 }
9241 } 9727 }
9242 } 9728 }
9729 m_host.TaskInventory.LockItemsForRead(false);
9243 9730
9244 return -1; 9731 return -1;
9245 } 9732 }
@@ -9250,15 +9737,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9250 9737
9251 if (quick_pay_buttons.Data.Length < 4) 9738 if (quick_pay_buttons.Data.Length < 4)
9252 { 9739 {
9253 LSLError("List must have at least 4 elements"); 9740 int x;
9254 return; 9741 for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
9742 {
9743 quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
9744 }
9255 } 9745 }
9256 m_host.ParentGroup.RootPart.PayPrice[0]=price; 9746 int[] nPrice = new int[5];
9257 9747 nPrice[0]=price;
9258 m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0]; 9748 nPrice[1] = (LSL_Integer)quick_pay_buttons.Data[0];
9259 m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1]; 9749 nPrice[2] = (LSL_Integer)quick_pay_buttons.Data[1];
9260 m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2]; 9750 nPrice[3] = (LSL_Integer)quick_pay_buttons.Data[2];
9261 m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3]; 9751 nPrice[4] = (LSL_Integer)quick_pay_buttons.Data[3];
9752 m_host.ParentGroup.RootPart.PayPrice = nPrice;
9262 m_host.ParentGroup.HasGroupChanged = true; 9753 m_host.ParentGroup.HasGroupChanged = true;
9263 } 9754 }
9264 9755
@@ -9270,17 +9761,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9270 if (invItemID == UUID.Zero) 9761 if (invItemID == UUID.Zero)
9271 return new LSL_Vector(); 9762 return new LSL_Vector();
9272 9763
9273 lock (m_host.TaskInventory) 9764 m_host.TaskInventory.LockItemsForRead(true);
9765 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
9274 { 9766 {
9275 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 9767 m_host.TaskInventory.LockItemsForRead(false);
9276 return new LSL_Vector(); 9768 return new LSL_Vector();
9769 }
9277 9770
9278 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 9771 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9279 { 9772 {
9280 ShoutError("No permissions to track the camera"); 9773 ShoutError("No permissions to track the camera");
9281 return new LSL_Vector(); 9774 m_host.TaskInventory.LockItemsForRead(false);
9282 } 9775 return new LSL_Vector();
9283 } 9776 }
9777 m_host.TaskInventory.LockItemsForRead(false);
9284 9778
9285 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 9779 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
9286 if (presence != null) 9780 if (presence != null)
@@ -9298,17 +9792,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9298 if (invItemID == UUID.Zero) 9792 if (invItemID == UUID.Zero)
9299 return new LSL_Rotation(); 9793 return new LSL_Rotation();
9300 9794
9301 lock (m_host.TaskInventory) 9795 m_host.TaskInventory.LockItemsForRead(true);
9796 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
9302 { 9797 {
9303 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 9798 m_host.TaskInventory.LockItemsForRead(false);
9304 return new LSL_Rotation(); 9799 return new LSL_Rotation();
9305 9800 }
9306 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 9801 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9307 { 9802 {
9308 ShoutError("No permissions to track the camera"); 9803 ShoutError("No permissions to track the camera");
9309 return new LSL_Rotation(); 9804 m_host.TaskInventory.LockItemsForRead(false);
9310 } 9805 return new LSL_Rotation();
9311 } 9806 }
9807 m_host.TaskInventory.LockItemsForRead(false);
9312 9808
9313 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 9809 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
9314 if (presence != null) 9810 if (presence != null)
@@ -9370,8 +9866,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9370 { 9866 {
9371 m_host.AddScriptLPS(1); 9867 m_host.AddScriptLPS(1);
9372 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 9868 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0);
9373 if (detectedParams == null) return; // only works on the first detected avatar 9869 if (detectedParams == null)
9374 9870 {
9871 if (m_host.IsAttachment == true)
9872 {
9873 detectedParams = new DetectParams();
9874 detectedParams.Key = m_host.OwnerID;
9875 }
9876 else
9877 {
9878 return;
9879 }
9880 }
9881
9375 ScenePresence avatar = World.GetScenePresence(detectedParams.Key); 9882 ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
9376 if (avatar != null) 9883 if (avatar != null)
9377 { 9884 {
@@ -9379,6 +9886,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9379 new Vector3((float)pos.x, (float)pos.y, (float)pos.z), 9886 new Vector3((float)pos.x, (float)pos.y, (float)pos.z),
9380 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z)); 9887 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z));
9381 } 9888 }
9889
9382 ScriptSleep(1000); 9890 ScriptSleep(1000);
9383 } 9891 }
9384 9892
@@ -9458,14 +9966,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9458 if (objectID == UUID.Zero) return; 9966 if (objectID == UUID.Zero) return;
9459 9967
9460 UUID agentID; 9968 UUID agentID;
9461 lock (m_host.TaskInventory) 9969 m_host.TaskInventory.LockItemsForRead(true);
9462 { 9970 // we need the permission first, to know which avatar we want to set the camera for
9463 // we need the permission first, to know which avatar we want to set the camera for 9971 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9464 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9465 9972
9466 if (agentID == UUID.Zero) return; 9973 if (agentID == UUID.Zero)
9467 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 9974 {
9975 m_host.TaskInventory.LockItemsForRead(false);
9976 return;
9977 }
9978 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
9979 {
9980 m_host.TaskInventory.LockItemsForRead(false);
9981 return;
9468 } 9982 }
9983 m_host.TaskInventory.LockItemsForRead(false);
9469 9984
9470 ScenePresence presence = World.GetScenePresence(agentID); 9985 ScenePresence presence = World.GetScenePresence(agentID);
9471 9986
@@ -9515,12 +10030,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9515 10030
9516 // we need the permission first, to know which avatar we want to clear the camera for 10031 // we need the permission first, to know which avatar we want to clear the camera for
9517 UUID agentID; 10032 UUID agentID;
9518 lock (m_host.TaskInventory) 10033 m_host.TaskInventory.LockItemsForRead(true);
10034 agentID = m_host.TaskInventory[invItemID].PermsGranter;
10035 if (agentID == UUID.Zero)
10036 {
10037 m_host.TaskInventory.LockItemsForRead(false);
10038 return;
10039 }
10040 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
9519 { 10041 {
9520 agentID = m_host.TaskInventory[invItemID].PermsGranter; 10042 m_host.TaskInventory.LockItemsForRead(false);
9521 if (agentID == UUID.Zero) return; 10043 return;
9522 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
9523 } 10044 }
10045 m_host.TaskInventory.LockItemsForRead(false);
9524 10046
9525 ScenePresence presence = World.GetScenePresence(agentID); 10047 ScenePresence presence = World.GetScenePresence(agentID);
9526 10048
@@ -9587,19 +10109,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9587 public LSL_String llXorBase64StringsCorrect(string str1, string str2) 10109 public LSL_String llXorBase64StringsCorrect(string str1, string str2)
9588 { 10110 {
9589 m_host.AddScriptLPS(1); 10111 m_host.AddScriptLPS(1);
9590 string ret = String.Empty; 10112
9591 string src1 = llBase64ToString(str1); 10113 if (str1 == String.Empty)
9592 string src2 = llBase64ToString(str2); 10114 return String.Empty;
9593 int c = 0; 10115 if (str2 == String.Empty)
9594 for (int i = 0; i < src1.Length; i++) 10116 return str1;
10117
10118 byte[] data1 = Convert.FromBase64String(str1);
10119 byte[] data2 = Convert.FromBase64String(str2);
10120
10121 byte[] d2 = new Byte[data1.Length];
10122 int pos = 0;
10123
10124 if (data1.Length <= data2.Length)
10125 {
10126 Array.Copy(data2, 0, d2, 0, data1.Length);
10127 }
10128 else
9595 { 10129 {
9596 ret += (char) (src1[i] ^ src2[c]); 10130 while (pos < data1.Length)
10131 {
10132 int len = data1.Length - pos;
10133 if (len > data2.Length)
10134 len = data2.Length;
9597 10135
9598 c++; 10136 Array.Copy(data2, 0, d2, pos, len);
9599 if (c >= src2.Length) 10137 pos += len;
9600 c = 0; 10138 }
9601 } 10139 }
9602 return llStringToBase64(ret); 10140
10141 for (pos = 0 ; pos < data1.Length ; pos++ )
10142 data1[pos] ^= d2[pos];
10143
10144 return Convert.ToBase64String(data1);
9603 } 10145 }
9604 10146
9605 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body) 10147 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
@@ -9977,15 +10519,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9977 10519
9978 internal UUID ScriptByName(string name) 10520 internal UUID ScriptByName(string name)
9979 { 10521 {
9980 lock (m_host.TaskInventory) 10522 m_host.TaskInventory.LockItemsForRead(true);
10523
10524 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
9981 { 10525 {
9982 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 10526 if (item.Type == 10 && item.Name == name)
9983 { 10527 {
9984 if (item.Type == 10 && item.Name == name) 10528 m_host.TaskInventory.LockItemsForRead(false);
9985 return item.ItemID; 10529 return item.ItemID;
9986 } 10530 }
9987 } 10531 }
9988 10532
10533 m_host.TaskInventory.LockItemsForRead(false);
10534
9989 return UUID.Zero; 10535 return UUID.Zero;
9990 } 10536 }
9991 10537
@@ -10026,6 +10572,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10026 { 10572 {
10027 m_host.AddScriptLPS(1); 10573 m_host.AddScriptLPS(1);
10028 10574
10575 //Clone is thread safe
10029 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 10576 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10030 10577
10031 UUID assetID = UUID.Zero; 10578 UUID assetID = UUID.Zero;
@@ -10088,6 +10635,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10088 { 10635 {
10089 m_host.AddScriptLPS(1); 10636 m_host.AddScriptLPS(1);
10090 10637
10638 //Clone is thread safe
10091 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 10639 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10092 10640
10093 UUID assetID = UUID.Zero; 10641 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 5ae6439..f0384f8 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
@@ -1,504 +1,507 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the 12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Reflection; 29using System.Reflection;
30using System.Collections; 30using System.Collections;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Runtime.Remoting.Lifetime; 32using System.Runtime.Remoting.Lifetime;
33using OpenMetaverse; 33using OpenMetaverse;
34using Nini.Config; 34using Nini.Config;
35using OpenSim; 35using OpenSim;
36using OpenSim.Framework; 36using OpenSim.Framework;
37using OpenSim.Region.CoreModules.World.LightShare; 37using OpenSim.Region.CoreModules.World.LightShare;
38using OpenSim.Region.Framework.Interfaces; 38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes; 39using OpenSim.Region.Framework.Scenes;
40using OpenSim.Region.ScriptEngine.Shared; 40using OpenSim.Region.ScriptEngine.Shared;
41using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; 41using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
42using OpenSim.Region.ScriptEngine.Shared.ScriptBase; 42using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
43using OpenSim.Region.ScriptEngine.Interfaces; 43using OpenSim.Region.ScriptEngine.Interfaces;
44using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces; 44using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
45 45
46using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; 46using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
47using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; 47using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
48using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; 48using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
49using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; 49using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
50using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; 50using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
51using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; 51using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
52using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; 52using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
53 53
54namespace OpenSim.Region.ScriptEngine.Shared.Api 54namespace OpenSim.Region.ScriptEngine.Shared.Api
55{ 55{
56 [Serializable] 56 [Serializable]
57 public class LS_Api : MarshalByRefObject, ILS_Api, IScriptApi 57 public class LS_Api : MarshalByRefObject, ILS_Api, IScriptApi
58 { 58 {
59 internal IScriptEngine m_ScriptEngine; 59 internal IScriptEngine m_ScriptEngine;
60 internal SceneObjectPart m_host; 60 internal SceneObjectPart m_host;
61 internal uint m_localID; 61 internal uint m_localID;
62 internal UUID m_itemID; 62 internal UUID m_itemID;
63 internal bool m_LSFunctionsEnabled = false; 63 internal bool m_LSFunctionsEnabled = false;
64 internal IScriptModuleComms m_comms = null; 64 internal IScriptModuleComms m_comms = null;
65 65
66 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 66 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
67 { 67 {
68 m_ScriptEngine = ScriptEngine; 68 m_ScriptEngine = ScriptEngine;
69 m_host = host; 69 m_host = host;
70 m_localID = localID; 70 m_localID = localID;
71 m_itemID = itemID; 71 m_itemID = itemID;
72 72
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 m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>(); 76 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false))
77 if (m_comms == null) 77 m_LSFunctionsEnabled = true;
78 m_LSFunctionsEnabled = false; 78
79 } 79 m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
80 80 if (m_comms == null)
81 public override Object InitializeLifetimeService() 81 m_LSFunctionsEnabled = false;
82 { 82 }
83 ILease lease = (ILease)base.InitializeLifetimeService(); 83
84 84 public override Object InitializeLifetimeService()
85 if (lease.CurrentState == LeaseState.Initial) 85 {
86 { 86 ILease lease = (ILease)base.InitializeLifetimeService();
87 lease.InitialLeaseTime = TimeSpan.FromMinutes(0); 87
88 // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0); 88 if (lease.CurrentState == LeaseState.Initial)
89 // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0); 89 {
90 } 90 lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
91 return lease; 91 // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
92 } 92 // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
93 93 }
94 public Scene World 94 return lease;
95 { 95 }
96 get { return m_ScriptEngine.World; } 96
97 } 97 public Scene World
98 98 {
99 // 99 get { return m_ScriptEngine.World; }
100 //Dumps an error message on the debug console. 100 }
101 // 101
102 102 //
103 internal void LSShoutError(string message) 103 //Dumps an error message on the debug console.
104 { 104 //
105 if (message.Length > 1023) 105
106 message = message.Substring(0, 1023); 106 internal void LSShoutError(string message)
107 107 {
108 World.SimChat(Utils.StringToBytes(message), 108 if (message.Length > 1023)
109 ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true); 109 message = message.Substring(0, 1023);
110 110
111 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 111 World.SimChat(Utils.StringToBytes(message),
112 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); 112 ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
113 } 113
114 114 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
115 /// <summary> 115 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
116 /// Get the current Windlight scene 116 }
117 /// </summary> 117
118 /// <returns>List of windlight parameters</returns> 118 /// <summary>
119 public LSL_List lsGetWindlightScene(LSL_List rules) 119 /// Get the current Windlight scene
120 { 120 /// </summary>
121 if (!m_LSFunctionsEnabled) 121 /// <returns>List of windlight parameters</returns>
122 { 122 public LSL_List lsGetWindlightScene(LSL_List rules)
123 LSShoutError("LightShare functions are not enabled."); 123 {
124 return new LSL_List(); 124 if (!m_LSFunctionsEnabled)
125 } 125 {
126 m_host.AddScriptLPS(1); 126 LSShoutError("LightShare functions are not enabled.");
127 RegionLightShareData wl = m_host.ParentGroup.Scene.RegionInfo.WindlightSettings; 127 return new LSL_List();
128 128 }
129 LSL_List values = new LSL_List(); 129 m_host.AddScriptLPS(1);
130 int idx = 0; 130 RegionLightShareData wl = m_host.ParentGroup.Scene.RegionInfo.WindlightSettings;
131 while (idx < rules.Length) 131
132 { 132 LSL_List values = new LSL_List();
133 uint rule = (uint)rules.GetLSLIntegerItem(idx); 133 int idx = 0;
134 LSL_List toadd = new LSL_List(); 134 while (idx < rules.Length)
135 135 {
136 switch (rule) 136 uint rule = (uint)rules.GetLSLIntegerItem(idx);
137 { 137 LSL_List toadd = new LSL_List();
138 case (int)ScriptBaseClass.WL_AMBIENT: 138
139 toadd.Add(new LSL_Rotation(wl.ambient.X, wl.ambient.Y, wl.ambient.Z, wl.ambient.W)); 139 switch (rule)
140 break; 140 {
141 case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION: 141 case (int)ScriptBaseClass.WL_AMBIENT:
142 toadd.Add(new LSL_Vector(wl.bigWaveDirection.X, wl.bigWaveDirection.Y, 0.0f)); 142 toadd.Add(new LSL_Rotation(wl.ambient.X, wl.ambient.Y, wl.ambient.Z, wl.ambient.W));
143 break; 143 break;
144 case (int)ScriptBaseClass.WL_BLUE_DENSITY: 144 case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
145 toadd.Add(new LSL_Rotation(wl.blueDensity.X, wl.blueDensity.Y, wl.blueDensity.Z, wl.blueDensity.W)); 145 toadd.Add(new LSL_Vector(wl.bigWaveDirection.X, wl.bigWaveDirection.Y, 0.0f));
146 break; 146 break;
147 case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER: 147 case (int)ScriptBaseClass.WL_BLUE_DENSITY:
148 toadd.Add(new LSL_Float(wl.blurMultiplier)); 148 toadd.Add(new LSL_Rotation(wl.blueDensity.X, wl.blueDensity.Y, wl.blueDensity.Z, wl.blueDensity.W));
149 break; 149 break;
150 case (int)ScriptBaseClass.WL_CLOUD_COLOR: 150 case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
151 toadd.Add(new LSL_Rotation(wl.cloudColor.X, wl.cloudColor.Y, wl.cloudColor.Z, wl.cloudColor.W)); 151 toadd.Add(new LSL_Float(wl.blurMultiplier));
152 break; 152 break;
153 case (int)ScriptBaseClass.WL_CLOUD_COVERAGE: 153 case (int)ScriptBaseClass.WL_CLOUD_COLOR:
154 toadd.Add(new LSL_Float(wl.cloudCoverage)); 154 toadd.Add(new LSL_Rotation(wl.cloudColor.X, wl.cloudColor.Y, wl.cloudColor.Z, wl.cloudColor.W));
155 break; 155 break;
156 case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY: 156 case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
157 toadd.Add(new LSL_Vector(wl.cloudDetailXYDensity.X, wl.cloudDetailXYDensity.Y, wl.cloudDetailXYDensity.Z)); 157 toadd.Add(new LSL_Float(wl.cloudCoverage));
158 break; 158 break;
159 case (int)ScriptBaseClass.WL_CLOUD_SCALE: 159 case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
160 toadd.Add(new LSL_Float(wl.cloudScale)); 160 toadd.Add(new LSL_Vector(wl.cloudDetailXYDensity.X, wl.cloudDetailXYDensity.Y, wl.cloudDetailXYDensity.Z));
161 break; 161 break;
162 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X: 162 case (int)ScriptBaseClass.WL_CLOUD_SCALE:
163 toadd.Add(new LSL_Float(wl.cloudScrollX)); 163 toadd.Add(new LSL_Float(wl.cloudScale));
164 break; 164 break;
165 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK: 165 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
166 toadd.Add(new LSL_Integer(wl.cloudScrollXLock ? 1 : 0)); 166 toadd.Add(new LSL_Float(wl.cloudScrollX));
167 break; 167 break;
168 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y: 168 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
169 toadd.Add(new LSL_Float(wl.cloudScrollY)); 169 toadd.Add(new LSL_Integer(wl.cloudScrollXLock ? 1 : 0));
170 break; 170 break;
171 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK: 171 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
172 toadd.Add(new LSL_Integer(wl.cloudScrollYLock ? 1 : 0)); 172 toadd.Add(new LSL_Float(wl.cloudScrollY));
173 break; 173 break;
174 case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY: 174 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
175 toadd.Add(new LSL_Vector(wl.cloudXYDensity.X, wl.cloudXYDensity.Y, wl.cloudXYDensity.Z)); 175 toadd.Add(new LSL_Integer(wl.cloudScrollYLock ? 1 : 0));
176 break; 176 break;
177 case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER: 177 case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
178 toadd.Add(new LSL_Float(wl.densityMultiplier)); 178 toadd.Add(new LSL_Vector(wl.cloudXYDensity.X, wl.cloudXYDensity.Y, wl.cloudXYDensity.Z));
179 break; 179 break;
180 case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER: 180 case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
181 toadd.Add(new LSL_Float(wl.distanceMultiplier)); 181 toadd.Add(new LSL_Float(wl.densityMultiplier));
182 break; 182 break;
183 case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS: 183 case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
184 toadd.Add(new LSL_Integer(wl.drawClassicClouds ? 1 : 0)); 184 toadd.Add(new LSL_Float(wl.distanceMultiplier));
185 break; 185 break;
186 case (int)ScriptBaseClass.WL_EAST_ANGLE: 186 case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
187 toadd.Add(new LSL_Float(wl.eastAngle)); 187 toadd.Add(new LSL_Integer(wl.drawClassicClouds ? 1 : 0));
188 break; 188 break;
189 case (int)ScriptBaseClass.WL_FRESNEL_OFFSET: 189 case (int)ScriptBaseClass.WL_EAST_ANGLE:
190 toadd.Add(new LSL_Float(wl.fresnelOffset)); 190 toadd.Add(new LSL_Float(wl.eastAngle));
191 break; 191 break;
192 case (int)ScriptBaseClass.WL_FRESNEL_SCALE: 192 case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
193 toadd.Add(new LSL_Float(wl.fresnelScale)); 193 toadd.Add(new LSL_Float(wl.fresnelOffset));
194 break; 194 break;
195 case (int)ScriptBaseClass.WL_HAZE_DENSITY: 195 case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
196 toadd.Add(new LSL_Float(wl.hazeDensity)); 196 toadd.Add(new LSL_Float(wl.fresnelScale));
197 break; 197 break;
198 case (int)ScriptBaseClass.WL_HAZE_HORIZON: 198 case (int)ScriptBaseClass.WL_HAZE_DENSITY:
199 toadd.Add(new LSL_Float(wl.hazeHorizon)); 199 toadd.Add(new LSL_Float(wl.hazeDensity));
200 break; 200 break;
201 case (int)ScriptBaseClass.WL_HORIZON: 201 case (int)ScriptBaseClass.WL_HAZE_HORIZON:
202 toadd.Add(new LSL_Rotation(wl.horizon.X, wl.horizon.Y, wl.horizon.Z, wl.horizon.W)); 202 toadd.Add(new LSL_Float(wl.hazeHorizon));
203 break; 203 break;
204 case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION: 204 case (int)ScriptBaseClass.WL_HORIZON:
205 toadd.Add(new LSL_Vector(wl.littleWaveDirection.X, wl.littleWaveDirection.Y, 0.0f)); 205 toadd.Add(new LSL_Rotation(wl.horizon.X, wl.horizon.Y, wl.horizon.Z, wl.horizon.W));
206 break; 206 break;
207 case (int)ScriptBaseClass.WL_MAX_ALTITUDE: 207 case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
208 toadd.Add(new LSL_Integer(wl.maxAltitude)); 208 toadd.Add(new LSL_Vector(wl.littleWaveDirection.X, wl.littleWaveDirection.Y, 0.0f));
209 break; 209 break;
210 case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE: 210 case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
211 toadd.Add(new LSL_Key(wl.normalMapTexture.ToString())); 211 toadd.Add(new LSL_Integer(wl.maxAltitude));
212 break; 212 break;
213 case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE: 213 case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
214 toadd.Add(new LSL_Vector(wl.reflectionWaveletScale.X, wl.reflectionWaveletScale.Y, wl.reflectionWaveletScale.Z)); 214 toadd.Add(new LSL_Key(wl.normalMapTexture.ToString()));
215 break; 215 break;
216 case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE: 216 case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
217 toadd.Add(new LSL_Float(wl.refractScaleAbove)); 217 toadd.Add(new LSL_Vector(wl.reflectionWaveletScale.X, wl.reflectionWaveletScale.Y, wl.reflectionWaveletScale.Z));
218 break; 218 break;
219 case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW: 219 case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
220 toadd.Add(new LSL_Float(wl.refractScaleBelow)); 220 toadd.Add(new LSL_Float(wl.refractScaleAbove));
221 break; 221 break;
222 case (int)ScriptBaseClass.WL_SCENE_GAMMA: 222 case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
223 toadd.Add(new LSL_Float(wl.sceneGamma)); 223 toadd.Add(new LSL_Float(wl.refractScaleBelow));
224 break; 224 break;
225 case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS: 225 case (int)ScriptBaseClass.WL_SCENE_GAMMA:
226 toadd.Add(new LSL_Float(wl.starBrightness)); 226 toadd.Add(new LSL_Float(wl.sceneGamma));
227 break; 227 break;
228 case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS: 228 case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
229 toadd.Add(new LSL_Float(wl.sunGlowFocus)); 229 toadd.Add(new LSL_Float(wl.starBrightness));
230 break; 230 break;
231 case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE: 231 case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
232 toadd.Add(new LSL_Float(wl.sunGlowSize)); 232 toadd.Add(new LSL_Float(wl.sunGlowFocus));
233 break; 233 break;
234 case (int)ScriptBaseClass.WL_SUN_MOON_COLOR: 234 case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
235 toadd.Add(new LSL_Rotation(wl.sunMoonColor.X, wl.sunMoonColor.Y, wl.sunMoonColor.Z, wl.sunMoonColor.W)); 235 toadd.Add(new LSL_Float(wl.sunGlowSize));
236 break; 236 break;
237 case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER: 237 case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
238 toadd.Add(new LSL_Float(wl.underwaterFogModifier)); 238 toadd.Add(new LSL_Rotation(wl.sunMoonColor.X, wl.sunMoonColor.Y, wl.sunMoonColor.Z, wl.sunMoonColor.W));
239 break; 239 break;
240 case (int)ScriptBaseClass.WL_WATER_COLOR: 240 case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
241 toadd.Add(new LSL_Vector(wl.waterColor.X, wl.waterColor.Y, wl.waterColor.Z)); 241 toadd.Add(new LSL_Float(wl.underwaterFogModifier));
242 break; 242 break;
243 case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT: 243 case (int)ScriptBaseClass.WL_WATER_COLOR:
244 toadd.Add(new LSL_Float(wl.waterFogDensityExponent)); 244 toadd.Add(new LSL_Vector(wl.waterColor.X, wl.waterColor.Y, wl.waterColor.Z));
245 break; 245 break;
246 } 246 case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
247 247 toadd.Add(new LSL_Float(wl.waterFogDensityExponent));
248 if (toadd.Length > 0) 248 break;
249 { 249 }
250 values.Add(rule); 250
251 values.Add(toadd.Data[0]); 251 if (toadd.Length > 0)
252 } 252 {
253 idx++; 253 values.Add(new LSL_Integer(rule));
254 } 254 values.Add(toadd.Data[0]);
255 255 }
256 256 idx++;
257 return values; 257 }
258 258
259 } 259
260 260 return values;
261 private RegionLightShareData getWindlightProfileFromRules(LSL_List rules) 261
262 { 262 }
263 RegionLightShareData wl = (RegionLightShareData)m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.Clone(); 263
264 264 private RegionLightShareData getWindlightProfileFromRules(LSL_List rules)
265 LSL_List values = new LSL_List(); 265 {
266 int idx = 0; 266 RegionLightShareData wl = (RegionLightShareData)m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.Clone();
267 while (idx < rules.Length) 267
268 { 268 LSL_List values = new LSL_List();
269 uint rule = (uint)rules.GetLSLIntegerItem(idx); 269 int idx = 0;
270 LSL_Types.Quaternion iQ; 270 while (idx < rules.Length)
271 LSL_Types.Vector3 iV; 271 {
272 switch (rule) 272 uint rule = (uint)rules.GetLSLIntegerItem(idx);
273 { 273 LSL_Types.Quaternion iQ;
274 case (int)ScriptBaseClass.WL_SUN_MOON_POSITION: 274 LSL_Types.Vector3 iV;
275 idx++; 275 switch (rule)
276 wl.sunMoonPosition = (float)rules.GetLSLFloatItem(idx); 276 {
277 break; 277 case (int)ScriptBaseClass.WL_SUN_MOON_POSITION:
278 case (int)ScriptBaseClass.WL_AMBIENT: 278 idx++;
279 idx++; 279 wl.sunMoonPosition = (float)rules.GetLSLFloatItem(idx);
280 iQ = rules.GetQuaternionItem(idx); 280 break;
281 wl.ambient = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); 281 case (int)ScriptBaseClass.WL_AMBIENT:
282 break; 282 idx++;
283 case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION: 283 iQ = rules.GetQuaternionItem(idx);
284 idx++; 284 wl.ambient = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
285 iV = rules.GetVector3Item(idx); 285 break;
286 wl.bigWaveDirection = new Vector2((float)iV.x, (float)iV.y); 286 case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
287 break; 287 idx++;
288 case (int)ScriptBaseClass.WL_BLUE_DENSITY: 288 iV = rules.GetVector3Item(idx);
289 idx++; 289 wl.bigWaveDirection = new Vector2((float)iV.x, (float)iV.y);
290 iQ = rules.GetQuaternionItem(idx); 290 break;
291 wl.blueDensity = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); 291 case (int)ScriptBaseClass.WL_BLUE_DENSITY:
292 break; 292 idx++;
293 case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER: 293 iQ = rules.GetQuaternionItem(idx);
294 idx++; 294 wl.blueDensity = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
295 wl.blurMultiplier = (float)rules.GetLSLFloatItem(idx); 295 break;
296 break; 296 case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
297 case (int)ScriptBaseClass.WL_CLOUD_COLOR: 297 idx++;
298 idx++; 298 wl.blurMultiplier = (float)rules.GetLSLFloatItem(idx);
299 iQ = rules.GetQuaternionItem(idx); 299 break;
300 wl.cloudColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); 300 case (int)ScriptBaseClass.WL_CLOUD_COLOR:
301 break; 301 idx++;
302 case (int)ScriptBaseClass.WL_CLOUD_COVERAGE: 302 iQ = rules.GetQuaternionItem(idx);
303 idx++; 303 wl.cloudColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
304 wl.cloudCoverage = (float)rules.GetLSLFloatItem(idx); 304 break;
305 break; 305 case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
306 case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY: 306 idx++;
307 idx++; 307 wl.cloudCoverage = (float)rules.GetLSLFloatItem(idx);
308 iV = rules.GetVector3Item(idx); 308 break;
309 wl.cloudDetailXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); 309 case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
310 break; 310 idx++;
311 case (int)ScriptBaseClass.WL_CLOUD_SCALE: 311 iV = rules.GetVector3Item(idx);
312 idx++; 312 wl.cloudDetailXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
313 wl.cloudScale = (float)rules.GetLSLFloatItem(idx); 313 break;
314 break; 314 case (int)ScriptBaseClass.WL_CLOUD_SCALE:
315 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X: 315 idx++;
316 idx++; 316 wl.cloudScale = (float)rules.GetLSLFloatItem(idx);
317 wl.cloudScrollX = (float)rules.GetLSLFloatItem(idx); 317 break;
318 break; 318 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
319 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK: 319 idx++;
320 idx++; 320 wl.cloudScrollX = (float)rules.GetLSLFloatItem(idx);
321 wl.cloudScrollXLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; 321 break;
322 break; 322 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
323 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y: 323 idx++;
324 idx++; 324 wl.cloudScrollXLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
325 wl.cloudScrollY = (float)rules.GetLSLFloatItem(idx); 325 break;
326 break; 326 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
327 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK: 327 idx++;
328 idx++; 328 wl.cloudScrollY = (float)rules.GetLSLFloatItem(idx);
329 wl.cloudScrollYLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; 329 break;
330 break; 330 case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
331 case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY: 331 idx++;
332 idx++; 332 wl.cloudScrollYLock = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
333 iV = rules.GetVector3Item(idx); 333 break;
334 wl.cloudXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); 334 case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
335 break; 335 idx++;
336 case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER: 336 iV = rules.GetVector3Item(idx);
337 idx++; 337 wl.cloudXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
338 wl.densityMultiplier = (float)rules.GetLSLFloatItem(idx); 338 break;
339 break; 339 case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
340 case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER: 340 idx++;
341 idx++; 341 wl.densityMultiplier = (float)rules.GetLSLFloatItem(idx);
342 wl.distanceMultiplier = (float)rules.GetLSLFloatItem(idx); 342 break;
343 break; 343 case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
344 case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS: 344 idx++;
345 idx++; 345 wl.distanceMultiplier = (float)rules.GetLSLFloatItem(idx);
346 wl.drawClassicClouds = rules.GetLSLIntegerItem(idx).value == 1 ? true : false; 346 break;
347 break; 347 case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
348 case (int)ScriptBaseClass.WL_EAST_ANGLE: 348 idx++;
349 idx++; 349 wl.drawClassicClouds = rules.GetLSLIntegerItem(idx).value == 1 ? true : false;
350 wl.eastAngle = (float)rules.GetLSLFloatItem(idx); 350 break;
351 break; 351 case (int)ScriptBaseClass.WL_EAST_ANGLE:
352 case (int)ScriptBaseClass.WL_FRESNEL_OFFSET: 352 idx++;
353 idx++; 353 wl.eastAngle = (float)rules.GetLSLFloatItem(idx);
354 wl.fresnelOffset = (float)rules.GetLSLFloatItem(idx); 354 break;
355 break; 355 case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
356 case (int)ScriptBaseClass.WL_FRESNEL_SCALE: 356 idx++;
357 idx++; 357 wl.fresnelOffset = (float)rules.GetLSLFloatItem(idx);
358 wl.fresnelScale = (float)rules.GetLSLFloatItem(idx); 358 break;
359 break; 359 case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
360 case (int)ScriptBaseClass.WL_HAZE_DENSITY: 360 idx++;
361 idx++; 361 wl.fresnelScale = (float)rules.GetLSLFloatItem(idx);
362 wl.hazeDensity = (float)rules.GetLSLFloatItem(idx); 362 break;
363 break; 363 case (int)ScriptBaseClass.WL_HAZE_DENSITY:
364 case (int)ScriptBaseClass.WL_HAZE_HORIZON: 364 idx++;
365 idx++; 365 wl.hazeDensity = (float)rules.GetLSLFloatItem(idx);
366 wl.hazeHorizon = (float)rules.GetLSLFloatItem(idx); 366 break;
367 break; 367 case (int)ScriptBaseClass.WL_HAZE_HORIZON:
368 case (int)ScriptBaseClass.WL_HORIZON: 368 idx++;
369 idx++; 369 wl.hazeHorizon = (float)rules.GetLSLFloatItem(idx);
370 iQ = rules.GetQuaternionItem(idx); 370 break;
371 wl.horizon = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); 371 case (int)ScriptBaseClass.WL_HORIZON:
372 break; 372 idx++;
373 case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION: 373 iQ = rules.GetQuaternionItem(idx);
374 idx++; 374 wl.horizon = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
375 iV = rules.GetVector3Item(idx); 375 break;
376 wl.littleWaveDirection = new Vector2((float)iV.x, (float)iV.y); 376 case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
377 break; 377 idx++;
378 case (int)ScriptBaseClass.WL_MAX_ALTITUDE: 378 iV = rules.GetVector3Item(idx);
379 idx++; 379 wl.littleWaveDirection = new Vector2((float)iV.x, (float)iV.y);
380 wl.maxAltitude = (ushort)rules.GetLSLIntegerItem(idx).value; 380 break;
381 break; 381 case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
382 case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE: 382 idx++;
383 idx++; 383 wl.maxAltitude = (ushort)rules.GetLSLIntegerItem(idx).value;
384 wl.normalMapTexture = new UUID(rules.GetLSLStringItem(idx).m_string); 384 break;
385 break; 385 case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
386 case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE: 386 idx++;
387 idx++; 387 wl.normalMapTexture = new UUID(rules.GetLSLStringItem(idx).m_string);
388 iV = rules.GetVector3Item(idx); 388 break;
389 wl.reflectionWaveletScale = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); 389 case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
390 break; 390 idx++;
391 case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE: 391 iV = rules.GetVector3Item(idx);
392 idx++; 392 wl.reflectionWaveletScale = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
393 wl.refractScaleAbove = (float)rules.GetLSLFloatItem(idx); 393 break;
394 break; 394 case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
395 case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW: 395 idx++;
396 idx++; 396 wl.refractScaleAbove = (float)rules.GetLSLFloatItem(idx);
397 wl.refractScaleBelow = (float)rules.GetLSLFloatItem(idx); 397 break;
398 break; 398 case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
399 case (int)ScriptBaseClass.WL_SCENE_GAMMA: 399 idx++;
400 idx++; 400 wl.refractScaleBelow = (float)rules.GetLSLFloatItem(idx);
401 wl.sceneGamma = (float)rules.GetLSLFloatItem(idx); 401 break;
402 break; 402 case (int)ScriptBaseClass.WL_SCENE_GAMMA:
403 case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS: 403 idx++;
404 idx++; 404 wl.sceneGamma = (float)rules.GetLSLFloatItem(idx);
405 wl.starBrightness = (float)rules.GetLSLFloatItem(idx); 405 break;
406 break; 406 case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
407 case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS: 407 idx++;
408 idx++; 408 wl.starBrightness = (float)rules.GetLSLFloatItem(idx);
409 wl.sunGlowFocus = (float)rules.GetLSLFloatItem(idx); 409 break;
410 break; 410 case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
411 case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE: 411 idx++;
412 idx++; 412 wl.sunGlowFocus = (float)rules.GetLSLFloatItem(idx);
413 wl.sunGlowSize = (float)rules.GetLSLFloatItem(idx); 413 break;
414 break; 414 case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
415 case (int)ScriptBaseClass.WL_SUN_MOON_COLOR: 415 idx++;
416 idx++; 416 wl.sunGlowSize = (float)rules.GetLSLFloatItem(idx);
417 iQ = rules.GetQuaternionItem(idx); 417 break;
418 wl.sunMoonColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s); 418 case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
419 break; 419 idx++;
420 case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER: 420 iQ = rules.GetQuaternionItem(idx);
421 idx++; 421 wl.sunMoonColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
422 wl.underwaterFogModifier = (float)rules.GetLSLFloatItem(idx); 422 break;
423 break; 423 case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
424 case (int)ScriptBaseClass.WL_WATER_COLOR: 424 idx++;
425 idx++; 425 wl.underwaterFogModifier = (float)rules.GetLSLFloatItem(idx);
426 iV = rules.GetVector3Item(idx); 426 break;
427 wl.waterColor = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); 427 case (int)ScriptBaseClass.WL_WATER_COLOR:
428 break; 428 idx++;
429 case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT: 429 iV = rules.GetVector3Item(idx);
430 idx++; 430 wl.waterColor = new Vector3((float)iV.x, (float)iV.y, (float)iV.z);
431 wl.waterFogDensityExponent = (float)rules.GetLSLFloatItem(idx); 431 break;
432 break; 432 case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
433 } 433 idx++;
434 idx++; 434 wl.waterFogDensityExponent = (float)rules.GetLSLFloatItem(idx);
435 } 435 break;
436 return wl; 436 }
437 } 437 idx++;
438 /// <summary> 438 }
439 /// Set the current Windlight scene 439 return wl;
440 /// </summary> 440 }
441 /// <param name="rules"></param> 441 /// <summary>
442 /// <returns>success: true or false</returns> 442 /// Set the current Windlight scene
443 public int lsSetWindlightScene(LSL_List rules) 443 /// </summary>
444 { 444 /// <param name="rules"></param>
445 if (!m_LSFunctionsEnabled) 445 /// <returns>success: true or false</returns>
446 { 446 public int lsSetWindlightScene(LSL_List rules)
447 LSShoutError("LightShare functions are not enabled."); 447 {
448 return 0; 448 if (!m_LSFunctionsEnabled)
449 } 449 {
450 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) 450 LSShoutError("LightShare functions are not enabled.");
451 { 451 return 0;
452 LSShoutError("lsSetWindlightScene can only be used by estate managers or owners."); 452 }
453 return 0; 453 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200)
454 } 454 {
455 int success = 0; 455 LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
456 m_host.AddScriptLPS(1); 456 return 0;
457 if (LightShareModule.EnableWindlight) 457 }
458 { 458 int success = 0;
459 RegionLightShareData wl = getWindlightProfileFromRules(rules); 459 m_host.AddScriptLPS(1);
460 m_host.ParentGroup.Scene.StoreWindlightProfile(wl); 460 if (LightShareModule.EnableWindlight)
461 success = 1; 461 {
462 } 462 RegionLightShareData wl = getWindlightProfileFromRules(rules);
463 else 463 m_host.ParentGroup.Scene.StoreWindlightProfile(wl);
464 { 464 success = 1;
465 LSShoutError("Windlight module is disabled"); 465 }
466 return 0; 466 else
467 } 467 {
468 return success; 468 LSShoutError("Windlight module is disabled");
469 } 469 return 0;
470 /// <summary> 470 }
471 /// Set the current Windlight scene to a target avatar 471 return success;
472 /// </summary> 472 }
473 /// <param name="rules"></param> 473 /// <summary>
474 /// <returns>success: true or false</returns> 474 /// Set the current Windlight scene to a target avatar
475 public int lsSetWindlightSceneTargeted(LSL_List rules, LSL_Key target) 475 /// </summary>
476 { 476 /// <param name="rules"></param>
477 if (!m_LSFunctionsEnabled) 477 /// <returns>success: true or false</returns>
478 { 478 public int lsSetWindlightSceneTargeted(LSL_List rules, LSL_Key target)
479 LSShoutError("LightShare functions are not enabled."); 479 {
480 return 0; 480 if (!m_LSFunctionsEnabled)
481 } 481 {
482 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200) 482 LSShoutError("LightShare functions are not enabled.");
483 { 483 return 0;
484 LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners."); 484 }
485 return 0; 485 if (!World.RegionInfo.EstateSettings.IsEstateManager(m_host.OwnerID) && World.GetScenePresence(m_host.OwnerID).GodLevel < 200)
486 } 486 {
487 int success = 0; 487 LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners.");
488 m_host.AddScriptLPS(1); 488 return 0;
489 if (LightShareModule.EnableWindlight) 489 }
490 { 490 int success = 0;
491 RegionLightShareData wl = getWindlightProfileFromRules(rules); 491 m_host.AddScriptLPS(1);
492 World.EventManager.TriggerOnSendNewWindlightProfileTargeted(wl, new UUID(target.m_string)); 492 if (LightShareModule.EnableWindlight)
493 success = 1; 493 {
494 } 494 RegionLightShareData wl = getWindlightProfileFromRules(rules);
495 else 495 World.EventManager.TriggerOnSendNewWindlightProfileTargeted(wl, new UUID(target.m_string));
496 { 496 success = 1;
497 LSShoutError("Windlight module is disabled"); 497 }
498 return 0; 498 else
499 } 499 {
500 return success; 500 LSShoutError("Windlight module is disabled");
501 } 501 return 0;
502 502 }
503 } 503 return success;
504} 504 }
505
506 }
507}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index a529a94..a08b135 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -129,6 +129,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
129 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; 129 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
130 internal float m_ScriptDelayFactor = 1.0f; 130 internal float m_ScriptDelayFactor = 1.0f;
131 internal float m_ScriptDistanceFactor = 1.0f; 131 internal float m_ScriptDistanceFactor = 1.0f;
132 internal bool m_debuggerSafe = false;
132 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); 133 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
133 134
134 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 135 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
@@ -137,6 +138,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
137 m_host = host; 138 m_host = host;
138 m_localID = localID; 139 m_localID = localID;
139 m_itemID = itemID; 140 m_itemID = itemID;
141 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
140 142
141 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) 143 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
142 m_OSFunctionsEnabled = true; 144 m_OSFunctionsEnabled = true;
@@ -195,7 +197,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
195 197
196 internal void OSSLError(string msg) 198 internal void OSSLError(string msg)
197 { 199 {
198 throw new Exception("OSSL Runtime Error: " + msg); 200 if (m_debuggerSafe)
201 {
202 OSSLShoutError(msg);
203 }
204 else
205 {
206 throw new Exception("OSSL Runtime Error: " + msg);
207 }
199 } 208 }
200 209
201 private void InitLSL() 210 private void InitLSL()
@@ -767,18 +776,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
767 if (target != null) 776 if (target != null)
768 { 777 {
769 UUID animID=UUID.Zero; 778 UUID animID=UUID.Zero;
770 lock (m_host.TaskInventory) 779 m_host.TaskInventory.LockItemsForRead(true);
780 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
771 { 781 {
772 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 782 if (inv.Value.Name == animation)
773 { 783 {
774 if (inv.Value.Name == animation) 784 if (inv.Value.Type == (int)AssetType.Animation)
775 { 785 animID = inv.Value.AssetID;
776 if (inv.Value.Type == (int)AssetType.Animation) 786 continue;
777 animID = inv.Value.AssetID;
778 continue;
779 }
780 } 787 }
781 } 788 }
789 m_host.TaskInventory.LockItemsForRead(false);
782 if (animID == UUID.Zero) 790 if (animID == UUID.Zero)
783 target.Animator.AddAnimation(animation, m_host.UUID); 791 target.Animator.AddAnimation(animation, m_host.UUID);
784 else 792 else
@@ -800,18 +808,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
800 if (target != null) 808 if (target != null)
801 { 809 {
802 UUID animID=UUID.Zero; 810 UUID animID=UUID.Zero;
803 lock (m_host.TaskInventory) 811 m_host.TaskInventory.LockItemsForRead(true);
812 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
804 { 813 {
805 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 814 if (inv.Value.Name == animation)
806 { 815 {
807 if (inv.Value.Name == animation) 816 if (inv.Value.Type == (int)AssetType.Animation)
808 { 817 animID = inv.Value.AssetID;
809 if (inv.Value.Type == (int)AssetType.Animation) 818 continue;
810 animID = inv.Value.AssetID;
811 continue;
812 }
813 } 819 }
814 } 820 }
821 m_host.TaskInventory.LockItemsForRead(false);
815 822
816 if (animID == UUID.Zero) 823 if (animID == UUID.Zero)
817 target.Animator.RemoveAnimation(animation); 824 target.Animator.RemoveAnimation(animation);
@@ -1662,6 +1669,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1662 1669
1663 if (!UUID.TryParse(name, out assetID)) 1670 if (!UUID.TryParse(name, out assetID))
1664 { 1671 {
1672 m_host.TaskInventory.LockItemsForRead(true);
1665 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1673 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1666 { 1674 {
1667 if (item.Type == 7 && item.Name == name) 1675 if (item.Type == 7 && item.Name == name)
@@ -1669,6 +1677,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1669 assetID = item.AssetID; 1677 assetID = item.AssetID;
1670 } 1678 }
1671 } 1679 }
1680 m_host.TaskInventory.LockItemsForRead(false);
1672 } 1681 }
1673 1682
1674 if (assetID == UUID.Zero) 1683 if (assetID == UUID.Zero)
@@ -1715,6 +1724,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1715 1724
1716 if (!UUID.TryParse(name, out assetID)) 1725 if (!UUID.TryParse(name, out assetID))
1717 { 1726 {
1727 m_host.TaskInventory.LockItemsForRead(true);
1718 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1728 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1719 { 1729 {
1720 if (item.Type == 7 && item.Name == name) 1730 if (item.Type == 7 && item.Name == name)
@@ -1722,6 +1732,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1722 assetID = item.AssetID; 1732 assetID = item.AssetID;
1723 } 1733 }
1724 } 1734 }
1735 m_host.TaskInventory.LockItemsForRead(false);
1725 } 1736 }
1726 1737
1727 if (assetID == UUID.Zero) 1738 if (assetID == UUID.Zero)
@@ -1772,6 +1783,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1772 1783
1773 if (!UUID.TryParse(name, out assetID)) 1784 if (!UUID.TryParse(name, out assetID))
1774 { 1785 {
1786 m_host.TaskInventory.LockItemsForRead(true);
1775 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1787 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1776 { 1788 {
1777 if (item.Type == 7 && item.Name == name) 1789 if (item.Type == 7 && item.Name == name)
@@ -1779,6 +1791,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1779 assetID = item.AssetID; 1791 assetID = item.AssetID;
1780 } 1792 }
1781 } 1793 }
1794 m_host.TaskInventory.LockItemsForRead(false);
1782 } 1795 }
1783 1796
1784 if (assetID == UUID.Zero) 1797 if (assetID == UUID.Zero)
@@ -2216,9 +2229,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2216 { 2229 {
2217 if (avatar.IsChildAgent == false) 2230 if (avatar.IsChildAgent == false)
2218 { 2231 {
2219 result.Add(avatar.UUID); 2232 result.Add(new LSL_Key(avatar.UUID.ToString()));
2220 result.Add(avatar.AbsolutePosition); 2233 result.Add(new LSL_Vector(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, avatar.AbsolutePosition.Z));
2221 result.Add(avatar.Name); 2234 result.Add(new LSL_String(avatar.Name));
2222 } 2235 }
2223 } 2236 }
2224 }); 2237 });
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 5da6bb9..6e8435d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -279,6 +279,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
279 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART 279 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART
280 public const int CHANGED_MEDIA = 2048; 280 public const int CHANGED_MEDIA = 2048;
281 public const int CHANGED_ANIMATION = 16384; 281 public const int CHANGED_ANIMATION = 16384;
282 public const int CHANGED_POSITION = 32768;
282 public const int TYPE_INVALID = 0; 283 public const int TYPE_INVALID = 0;
283 public const int TYPE_INTEGER = 1; 284 public const int TYPE_INTEGER = 1;
284 public const int TYPE_FLOAT = 2; 285 public const int TYPE_FLOAT = 2;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 451163f..f14967e 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 6663aa5..b4da246 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 91e03ac..a3a2fdf 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
@@ -342,19 +342,19 @@ namespace OpenSim.Region.ScriptEngine.Shared
342 342
343 public override string ToString() 343 public override string ToString()
344 { 344 {
345 string st=String.Format(Culture.FormatProvider, "<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s); 345 string st=String.Format(Culture.FormatProvider, "<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", x, y, z, s);
346 return st; 346 return st;
347 } 347 }
348 348
349 public static explicit operator string(Quaternion r) 349 public static explicit operator string(Quaternion r)
350 { 350 {
351 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); 351 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 return s; 352 return s;
353 } 353 }
354 354
355 public static explicit operator LSLString(Quaternion r) 355 public static explicit operator LSLString(Quaternion r)
356 { 356 {
357 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); 357 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", r.x, r.y, r.z, r.s);
358 return new LSLString(s); 358 return new LSLString(s);
359 } 359 }
360 360
@@ -613,24 +613,16 @@ namespace OpenSim.Region.ScriptEngine.Shared
613 613
614 public static bool operator ==(list a, list b) 614 public static bool operator ==(list a, list b)
615 { 615 {
616 int la = -1; 616 int la = a.Length;
617 int lb = -1; 617 int lb = b.Length;
618 try { la = a.Length; }
619 catch (NullReferenceException) { }
620 try { lb = b.Length; }
621 catch (NullReferenceException) { }
622 618
623 return la == lb; 619 return la == lb;
624 } 620 }
625 621
626 public static bool operator !=(list a, list b) 622 public static bool operator !=(list a, list b)
627 { 623 {
628 int la = -1; 624 int la = a.Length;
629 int lb = -1; 625 int lb = b.Length;
630 try { la = a.Length; }
631 catch (NullReferenceException) { }
632 try {lb = b.Length;}
633 catch (NullReferenceException) { }
634 626
635 return la != lb; 627 return la != lb;
636 } 628 }
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 8102acd..e5e8a56 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 }
@@ -702,92 +770,95 @@ namespace OpenSim.Region.ScriptEngine.XEngine
702 } 770 }
703 771
704 ScriptInstance instance = null; 772 ScriptInstance instance = null;
705 lock (m_Scripts) 773 // Create the object record
774 lockScriptsForRead(true);
775 if ((!m_Scripts.ContainsKey(itemID)) ||
776 (m_Scripts[itemID].AssetID != assetID))
706 { 777 {
707 // Create the object record 778 lockScriptsForRead(false);
708 779
709 if ((!m_Scripts.ContainsKey(itemID)) || 780 UUID appDomain = assetID;
710 (m_Scripts[itemID].AssetID != assetID))
711 {
712 UUID appDomain = assetID;
713 781
714 if (part.ParentGroup.IsAttachment) 782 if (part.ParentGroup.IsAttachment)
715 appDomain = part.ParentGroup.RootPart.UUID; 783 appDomain = part.ParentGroup.RootPart.UUID;
716 784
717 if (!m_AppDomains.ContainsKey(appDomain)) 785 if (!m_AppDomains.ContainsKey(appDomain))
786 {
787 try
718 { 788 {
719 try 789 AppDomainSetup appSetup = new AppDomainSetup();
720 { 790 // appSetup.ApplicationBase = Path.Combine(
721 AppDomainSetup appSetup = new AppDomainSetup(); 791 // "ScriptEngines",
722// appSetup.ApplicationBase = Path.Combine( 792 // m_Scene.RegionInfo.RegionID.ToString());
723// "ScriptEngines", 793
724// m_Scene.RegionInfo.RegionID.ToString()); 794 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
725 795 Evidence evidence = new Evidence(baseEvidence);
726 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; 796
727 Evidence evidence = new Evidence(baseEvidence); 797 AppDomain sandbox;
728 798 if (m_AppDomainLoading)
729 AppDomain sandbox; 799 sandbox = AppDomain.CreateDomain(
730 if (m_AppDomainLoading) 800 m_Scene.RegionInfo.RegionID.ToString(),
731 sandbox = AppDomain.CreateDomain( 801 evidence, appSetup);
732 m_Scene.RegionInfo.RegionID.ToString(), 802 else
733 evidence, appSetup); 803 sandbox = AppDomain.CurrentDomain;
734 else 804
735 sandbox = AppDomain.CurrentDomain; 805 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
736 806 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
737 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); 807 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet");
738 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); 808 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet);
739 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); 809 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement);
740 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); 810 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup;
741 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); 811 //sandbox.SetAppDomainPolicy(sandboxPolicy);
742 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup; 812
743 //sandbox.SetAppDomainPolicy(sandboxPolicy); 813 m_AppDomains[appDomain] = sandbox;
744 814
745 m_AppDomains[appDomain] = sandbox; 815 m_AppDomains[appDomain].AssemblyResolve +=
746 816 new ResolveEventHandler(
747 m_AppDomains[appDomain].AssemblyResolve += 817 AssemblyResolver.OnAssemblyResolve);
748 new ResolveEventHandler( 818 m_DomainScripts[appDomain] = new List<UUID>();
749 AssemblyResolver.OnAssemblyResolve); 819 }
750 m_DomainScripts[appDomain] = new List<UUID>(); 820 catch (Exception e)
751 } 821 {
752 catch (Exception e) 822 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
823 m_ScriptErrorMessage += "Exception creating app domain:\n";
824 m_ScriptFailCount++;
825 lock (m_AddingAssemblies)
753 { 826 {
754 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString()); 827 m_AddingAssemblies[assembly]--;
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 } 828 }
829 return false;
763 } 830 }
764 m_DomainScripts[appDomain].Add(itemID); 831 }
765 832 m_DomainScripts[appDomain].Add(itemID);
766 instance = new ScriptInstance(this, part, 833
767 itemID, assetID, assembly, 834 instance = new ScriptInstance(this, part,
768 m_AppDomains[appDomain], 835 itemID, assetID, assembly,
769 part.ParentGroup.RootPart.Name, 836 m_AppDomains[appDomain],
770 item.Name, startParam, postOnRez, 837 part.ParentGroup.RootPart.Name,
771 stateSource, m_MaxScriptQueue); 838 item.Name, startParam, postOnRez,
772 839 stateSource, m_MaxScriptQueue);
773 m_log.DebugFormat( 840
841 m_log.DebugFormat(
774 "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}", 842 "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}",
775 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, 843 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID,
776 part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName); 844 part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName);
777 845
778 if (presence != null) 846 if (presence != null)
779 { 847 {
780 ShowScriptSaveResponse(item.OwnerID, 848 ShowScriptSaveResponse(item.OwnerID,
781 assetID, "Compile successful", true); 849 assetID, "Compile successful", true);
782 }
783
784 instance.AppDomain = appDomain;
785 instance.LineMap = linemap;
786
787 m_Scripts[itemID] = instance;
788 } 850 }
789 }
790 851
852 instance.AppDomain = appDomain;
853 instance.LineMap = linemap;
854 lockScriptsForWrite(true);
855 m_Scripts[itemID] = instance;
856 lockScriptsForWrite(false);
857 }
858 else
859 {
860 lockScriptsForRead(false);
861 }
791 lock (m_PrimObjects) 862 lock (m_PrimObjects)
792 { 863 {
793 if (!m_PrimObjects.ContainsKey(localID)) 864 if (!m_PrimObjects.ContainsKey(localID))
@@ -806,9 +877,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
806 m_AddingAssemblies[assembly]--; 877 m_AddingAssemblies[assembly]--;
807 } 878 }
808 879
809 if (instance != null) 880 if (instance!=null)
810 instance.Init(); 881 instance.Init();
811 882
812 return true; 883 return true;
813 } 884 }
814 885
@@ -821,20 +892,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine
821 m_CompileDict.Remove(itemID); 892 m_CompileDict.Remove(itemID);
822 } 893 }
823 894
824 IScriptInstance instance = null; 895 lockScriptsForRead(true);
825 896 // Do we even have it?
826 lock (m_Scripts) 897 if (!m_Scripts.ContainsKey(itemID))
827 { 898 {
828 // Do we even have it? 899 lockScriptsForRead(false);
829 if (!m_Scripts.ContainsKey(itemID)) 900 return;
830 return;
831
832 instance=m_Scripts[itemID];
833 m_Scripts.Remove(itemID);
834 } 901 }
902
835 903
904 IScriptInstance instance=m_Scripts[itemID];
905 lockScriptsForRead(false);
906 lockScriptsForWrite(true);
907 m_Scripts.Remove(itemID);
908 lockScriptsForWrite(false);
836 instance.ClearQueue(); 909 instance.ClearQueue();
837 instance.Stop(0); 910 instance.Stop(0);
911
838// bool objectRemoved = false; 912// bool objectRemoved = false;
839 913
840 lock (m_PrimObjects) 914 lock (m_PrimObjects)
@@ -870,11 +944,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
870 ObjectRemoved handlerObjectRemoved = OnObjectRemoved; 944 ObjectRemoved handlerObjectRemoved = OnObjectRemoved;
871 if (handlerObjectRemoved != null) 945 if (handlerObjectRemoved != null)
872 { 946 {
873 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID); 947 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID);
874 handlerObjectRemoved(part.UUID); 948 handlerObjectRemoved(part.UUID);
875 } 949 }
876 950
877 951 CleanAssemblies();
952
878 ScriptRemoved handlerScriptRemoved = OnScriptRemoved; 953 ScriptRemoved handlerScriptRemoved = OnScriptRemoved;
879 if (handlerScriptRemoved != null) 954 if (handlerScriptRemoved != null)
880 handlerScriptRemoved(itemID); 955 handlerScriptRemoved(itemID);
@@ -1016,7 +1091,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1016 return false; 1091 return false;
1017 1092
1018 uuids = m_PrimObjects[localID]; 1093 uuids = m_PrimObjects[localID];
1019 } 1094
1020 1095
1021 foreach (UUID itemID in uuids) 1096 foreach (UUID itemID in uuids)
1022 { 1097 {
@@ -1034,6 +1109,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1034 result = true; 1109 result = true;
1035 } 1110 }
1036 } 1111 }
1112 }
1037 1113
1038 return result; 1114 return result;
1039 } 1115 }
@@ -1133,12 +1209,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1133 private IScriptInstance GetInstance(UUID itemID) 1209 private IScriptInstance GetInstance(UUID itemID)
1134 { 1210 {
1135 IScriptInstance instance; 1211 IScriptInstance instance;
1136 lock (m_Scripts) 1212 lockScriptsForRead(true);
1213 if (!m_Scripts.ContainsKey(itemID))
1137 { 1214 {
1138 if (!m_Scripts.ContainsKey(itemID)) 1215 lockScriptsForRead(false);
1139 return null; 1216 return null;
1140 instance = m_Scripts[itemID];
1141 } 1217 }
1218 instance = m_Scripts[itemID];
1219 lockScriptsForRead(false);
1142 return instance; 1220 return instance;
1143 } 1221 }
1144 1222
@@ -1162,6 +1240,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1162 return false; 1240 return false;
1163 } 1241 }
1164 1242
1243 [DebuggerNonUserCode]
1165 public void ApiResetScript(UUID itemID) 1244 public void ApiResetScript(UUID itemID)
1166 { 1245 {
1167 IScriptInstance instance = GetInstance(itemID); 1246 IScriptInstance instance = GetInstance(itemID);
@@ -1213,6 +1292,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1213 return UUID.Zero; 1292 return UUID.Zero;
1214 } 1293 }
1215 1294
1295 [DebuggerNonUserCode]
1216 public void SetState(UUID itemID, string newState) 1296 public void SetState(UUID itemID, string newState)
1217 { 1297 {
1218 IScriptInstance instance = GetInstance(itemID); 1298 IScriptInstance instance = GetInstance(itemID);
@@ -1233,11 +1313,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1233 { 1313 {
1234 List<IScriptInstance> instances = new List<IScriptInstance>(); 1314 List<IScriptInstance> instances = new List<IScriptInstance>();
1235 1315
1236 lock (m_Scripts) 1316 lockScriptsForRead(true);
1237 { 1317 foreach (IScriptInstance instance in m_Scripts.Values)
1238 foreach (IScriptInstance instance in m_Scripts.Values)
1239 instances.Add(instance); 1318 instances.Add(instance);
1240 } 1319 lockScriptsForRead(false);
1241 1320
1242 foreach (IScriptInstance i in instances) 1321 foreach (IScriptInstance i in instances)
1243 { 1322 {