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/CM_Api.cs118
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs2088
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs53
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs16
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs32
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs46
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs1
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs71
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs3
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs7
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs21
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Helpers.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs52
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs32
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs353
19 files changed, 1980 insertions, 947 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/CM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
new file mode 100644
index 0000000..489c1c6
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
@@ -0,0 +1,118 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using System.Collections;
31using System.Collections.Generic;
32using System.Runtime.Remoting.Lifetime;
33using OpenMetaverse;
34using Nini.Config;
35using OpenSim;
36using OpenSim.Framework;
37using OpenSim.Region.CoreModules.World.LightShare;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes;
40using OpenSim.Region.ScriptEngine.Shared;
41using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
42using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
43using OpenSim.Region.ScriptEngine.Interfaces;
44using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
45using OpenSim.Services.Interfaces;
46
47using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
48using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
49using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
50using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
51using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
52using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
53using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
54
55namespace OpenSim.Region.ScriptEngine.Shared.Api
56{
57 [Serializable]
58 public class CM_Api : MarshalByRefObject, ICM_Api, IScriptApi
59 {
60 internal IScriptEngine m_ScriptEngine;
61 internal SceneObjectPart m_host;
62 internal uint m_localID;
63 internal UUID m_itemID;
64 internal bool m_CMFunctionsEnabled = false;
65
66 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
67 {
68 m_ScriptEngine = ScriptEngine;
69 m_host = host;
70 m_localID = localID;
71 m_itemID = itemID;
72
73 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false))
74 m_CMFunctionsEnabled = true;
75 }
76
77 public override Object InitializeLifetimeService()
78 {
79 ILease lease = (ILease)base.InitializeLifetimeService();
80
81 if (lease.CurrentState == LeaseState.Initial)
82 {
83 lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
84 // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
85 // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
86 }
87 return lease;
88 }
89
90 public Scene World
91 {
92 get { return m_ScriptEngine.World; }
93 }
94
95 public string cmDetectedCountry(int number)
96 {
97 m_host.AddScriptLPS(1);
98 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, number);
99 if (detectedParams == null)
100 return String.Empty;
101 return detectedParams.Country;
102 }
103
104 public string cmGetAgentCountry(LSL_Key key)
105 {
106 if (!World.Permissions.IsGod(m_host.OwnerID))
107 return String.Empty;
108
109 UUID uuid;
110
111 if (!UUID.TryParse(key, out uuid))
112 return String.Empty;
113
114 UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
115 return account.UserCountry;
116 }
117 }
118}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 72ee495..a62a7b4 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)
@@ -288,40 +346,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
288 protected UUID InventorySelf() 346 protected UUID InventorySelf()
289 { 347 {
290 UUID invItemID = new UUID(); 348 UUID invItemID = new UUID();
291 349 bool unlock = false;
292 lock (m_host.TaskInventory) 350 if (!m_host.TaskInventory.IsReadLockedByMe())
293 { 351 {
294 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 352 m_host.TaskInventory.LockItemsForRead(true);
353 unlock = true;
354 }
355 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
356 {
357 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
295 { 358 {
296 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID) 359 invItemID = inv.Key;
297 { 360 break;
298 invItemID = inv.Key;
299 break;
300 }
301 } 361 }
302 } 362 }
303 363 if (unlock)
364 {
365 m_host.TaskInventory.LockItemsForRead(false);
366 }
304 return invItemID; 367 return invItemID;
305 } 368 }
306 369
307 protected UUID InventoryKey(string name, int type) 370 protected UUID InventoryKey(string name, int type)
308 { 371 {
309 m_host.AddScriptLPS(1); 372 m_host.AddScriptLPS(1);
310 373 m_host.TaskInventory.LockItemsForRead(true);
311 lock (m_host.TaskInventory) 374
375 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
312 { 376 {
313 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 377 if (inv.Value.Name == name)
314 { 378 {
315 if (inv.Value.Name == name) 379 m_host.TaskInventory.LockItemsForRead(false);
380
381 if (inv.Value.Type != type)
316 { 382 {
317 if (inv.Value.Type != type) 383 return UUID.Zero;
318 return UUID.Zero;
319
320 return inv.Value.AssetID;
321 } 384 }
385
386 return inv.Value.AssetID;
322 } 387 }
323 } 388 }
324 389
390 m_host.TaskInventory.LockItemsForRead(false);
325 return UUID.Zero; 391 return UUID.Zero;
326 } 392 }
327 393
@@ -329,17 +395,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
329 { 395 {
330 m_host.AddScriptLPS(1); 396 m_host.AddScriptLPS(1);
331 397
332 lock (m_host.TaskInventory) 398
399 m_host.TaskInventory.LockItemsForRead(true);
400
401 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
333 { 402 {
334 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 403 if (inv.Value.Name == name)
335 { 404 {
336 if (inv.Value.Name == name) 405 m_host.TaskInventory.LockItemsForRead(false);
337 { 406 return inv.Value.AssetID;
338 return inv.Value.AssetID;
339 }
340 } 407 }
341 } 408 }
342 409
410 m_host.TaskInventory.LockItemsForRead(false);
411
412
343 return UUID.Zero; 413 return UUID.Zero;
344 } 414 }
345 415
@@ -481,26 +551,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
481 551
482 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke 552 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
483 553
484 // Old implementation of llRot2Euler. Normalization not required as Atan2 function will 554 // Utility function for llRot2Euler
485 // only return values >= -PI (-180 degrees) and <= PI (180 degrees). 555
556 // normalize an angle between -PI and PI (-180 to +180 degrees)
557 protected double NormalizeAngle(double angle)
558 {
559 if (angle > -Math.PI && angle < Math.PI)
560 return angle;
561
562 int numPis = (int)(Math.PI / angle);
563 double remainder = angle - Math.PI * numPis;
564 if (numPis % 2 == 1)
565 return Math.PI - angle;
566 return remainder;
567 }
486 568
487 public LSL_Vector llRot2Euler(LSL_Rotation r) 569 public LSL_Vector llRot2Euler(LSL_Rotation q1)
488 { 570 {
489 m_host.AddScriptLPS(1); 571 m_host.AddScriptLPS(1);
490 //This implementation is from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions. ckrinke 572 LSL_Vector eul = new LSL_Vector();
491 LSL_Rotation t = new LSL_Rotation(r.x * r.x, r.y * r.y, r.z * r.z, r.s * r.s); 573
492 double m = (t.x + t.y + t.z + t.s); 574 double sqw = q1.s*q1.s;
493 if (m == 0) return new LSL_Vector(); 575 double sqx = q1.x*q1.x;
494 double n = 2 * (r.y * r.s + r.x * r.z); 576 double sqy = q1.z*q1.z;
495 double p = m * m - n * n; 577 double sqz = q1.y*q1.y;
496 if (p > 0) 578 double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
497 return new LSL_Vector(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s)), 579 double test = q1.x*q1.z + q1.y*q1.s;
498 Math.Atan2(n, Math.Sqrt(p)), 580 if (test > 0.4999*unit) { // singularity at north pole
499 Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s))); 581 eul.z = 2 * Math.Atan2(q1.x,q1.s);
500 else if (n > 0) 582 eul.y = Math.PI/2;
501 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)); 583 eul.x = 0;
502 else 584 return eul;
503 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)); 585 }
586 if (test < -0.4999*unit) { // singularity at south pole
587 eul.z = -2 * Math.Atan2(q1.x,q1.s);
588 eul.y = -Math.PI/2;
589 eul.x = 0;
590 return eul;
591 }
592 eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
593 eul.y = Math.Asin(2*test/unit);
594 eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
595 return eul;
504 } 596 }
505 597
506 /* From wiki: 598 /* From wiki:
@@ -702,77 +794,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
702 { 794 {
703 //A and B should both be normalized 795 //A and B should both be normalized
704 m_host.AddScriptLPS(1); 796 m_host.AddScriptLPS(1);
705 LSL_Rotation rotBetween; 797 /* This method is more accurate than the SL one, and thus causes problems
706 // Check for zero vectors. If either is zero, return zero rotation. Otherwise, 798 for scripts that deal with the SL inaccuracy around 180-degrees -.- .._.
707 // continue calculation. 799
708 if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f)) 800 double dotProduct = LSL_Vector.Dot(a, b);
801 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
802 double magProduct = LSL_Vector.Mag(a) * LSL_Vector.Mag(b);
803 double angle = Math.Acos(dotProduct / magProduct);
804 LSL_Vector axis = LSL_Vector.Norm(crossProduct);
805 double s = Math.Sin(angle / 2);
806
807 double x = axis.x * s;
808 double y = axis.y * s;
809 double z = axis.z * s;
810 double w = Math.Cos(angle / 2);
811
812 if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w))
813 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
814
815 return new LSL_Rotation((float)x, (float)y, (float)z, (float)w);
816 */
817
818 // This method mimics the 180 errors found in SL
819 // See www.euclideanspace.com... angleBetween
820 LSL_Vector vec_a = a;
821 LSL_Vector vec_b = b;
822
823 // Eliminate zero length
824 LSL_Float vec_a_mag = LSL_Vector.Mag(vec_a);
825 LSL_Float vec_b_mag = LSL_Vector.Mag(vec_b);
826 if (vec_a_mag < 0.00001 ||
827 vec_b_mag < 0.00001)
709 { 828 {
710 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); 829 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
711 } 830 }
712 else 831
832 // Normalize
833 vec_a = llVecNorm(vec_a);
834 vec_b = llVecNorm(vec_b);
835
836 // Calculate axis and rotation angle
837 LSL_Vector axis = vec_a % vec_b;
838 LSL_Float cos_theta = vec_a * vec_b;
839
840 // Check if parallel
841 if (cos_theta > 0.99999)
713 { 842 {
714 a = LSL_Vector.Norm(a); 843 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
715 b = LSL_Vector.Norm(b); 844 }
716 double dotProduct = LSL_Vector.Dot(a, b); 845
717 // There are two degenerate cases possible. These are for vectors 180 or 846 // Check if anti-parallel
718 // 0 degrees apart. These have to be detected and handled individually. 847 else if (cos_theta < -0.99999)
719 // 848 {
720 // Check for vectors 180 degrees apart. 849 LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (vec_a.x / (vec_a * vec_a) * vec_a);
721 // A dot product of -1 would mean the angle between vectors is 180 degrees. 850 if (LSL_Vector.Mag(orthog_axis) < 0.000001) orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
722 if (dotProduct < -0.9999999f) 851 return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
723 { 852 }
724 // First assume X axis is orthogonal to the vectors. 853 else // other rotation
725 LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f); 854 {
726 orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a)); 855 LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
727 // Check for near zero vector. A very small non-zero number here will create 856 axis = llVecNorm(axis);
728 // a rotation in an undesired direction. 857 double x, y, z, s, t;
729 if (LSL_Vector.Mag(orthoVector) > 0.0001) 858 s = Math.Cos(theta);
730 { 859 t = Math.Sin(theta);
731 rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f); 860 x = axis.x * t;
732 } 861 y = axis.y * t;
733 // If the magnitude of the vector was near zero, then assume the X axis is not 862 z = axis.z * t;
734 // orthogonal and use the Z axis instead. 863 return new LSL_Rotation(x,y,z,s);
735 else
736 {
737 // Set 180 z rotation.
738 rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f);
739 }
740 }
741 // Check for parallel vectors.
742 // A dot product of 1 would mean the angle between vectors is 0 degrees.
743 else if (dotProduct > 0.9999999f)
744 {
745 // Set zero rotation.
746 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
747 }
748 else
749 {
750 // All special checks have been performed so get the axis of rotation.
751 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
752 // Quarternion s value is the length of the unit vector + dot product.
753 double qs = 1.0 + dotProduct;
754 rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs);
755 // Normalize the rotation.
756 double mag = LSL_Rotation.Mag(rotBetween);
757 // We shouldn't have to worry about a divide by zero here. The qs value will be
758 // non-zero because we already know if we're here, then the dotProduct is not -1 so
759 // qs will not be zero. Also, we've already handled the input vectors being zero so the
760 // crossProduct vector should also not be zero.
761 rotBetween.x = rotBetween.x / mag;
762 rotBetween.y = rotBetween.y / mag;
763 rotBetween.z = rotBetween.z / mag;
764 rotBetween.s = rotBetween.s / mag;
765 // Check for undefined values and set zero rotation if any found. This code might not actually be required
766 // any longer since zero vectors are checked for at the top.
767 if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s))
768 {
769 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
770 }
771 }
772 } 864 }
773 return rotBetween;
774 } 865 }
775 866
776 public void llWhisper(int channelID, string text) 867 public void llWhisper(int channelID, string text)
777 { 868 {
778 m_host.AddScriptLPS(1); 869 m_host.AddScriptLPS(1);
@@ -1096,10 +1187,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1096 return detectedParams.TouchUV; 1187 return detectedParams.TouchUV;
1097 } 1188 }
1098 1189
1190 [DebuggerNonUserCode]
1099 public virtual void llDie() 1191 public virtual void llDie()
1100 { 1192 {
1101 m_host.AddScriptLPS(1); 1193 m_host.AddScriptLPS(1);
1102 throw new SelfDeleteException(); 1194 if (!m_host.IsAttachment) throw new SelfDeleteException();
1103 } 1195 }
1104 1196
1105 public LSL_Float llGround(LSL_Vector offset) 1197 public LSL_Float llGround(LSL_Vector offset)
@@ -1172,6 +1264,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1172 1264
1173 public void llSetStatus(int status, int value) 1265 public void llSetStatus(int status, int value)
1174 { 1266 {
1267 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
1268 return;
1175 m_host.AddScriptLPS(1); 1269 m_host.AddScriptLPS(1);
1176 1270
1177 int statusrotationaxis = 0; 1271 int statusrotationaxis = 0;
@@ -1402,6 +1496,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1402 { 1496 {
1403 m_host.AddScriptLPS(1); 1497 m_host.AddScriptLPS(1);
1404 1498
1499 SetColor(m_host, color, face);
1500 }
1501
1502 protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
1503 {
1504 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1505 return;
1506
1507 Primitive.TextureEntry tex = part.Shape.Textures;
1508 Color4 texcolor;
1509 if (face >= 0 && face < GetNumberOfSides(part))
1510 {
1511 texcolor = tex.CreateFace((uint)face).RGBA;
1512 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1513 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1514 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1515 tex.FaceTextures[face].RGBA = texcolor;
1516 part.UpdateTexture(tex);
1517 return;
1518 }
1519 else if (face == ScriptBaseClass.ALL_SIDES)
1520 {
1521 for (uint i = 0; i < GetNumberOfSides(part); i++)
1522 {
1523 if (tex.FaceTextures[i] != null)
1524 {
1525 texcolor = tex.FaceTextures[i].RGBA;
1526 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1527 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1528 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1529 tex.FaceTextures[i].RGBA = texcolor;
1530 }
1531 texcolor = tex.DefaultTexture.RGBA;
1532 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1533 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1534 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1535 tex.DefaultTexture.RGBA = texcolor;
1536 }
1537 part.UpdateTexture(tex);
1538 return;
1539 }
1540
1405 if (face == ScriptBaseClass.ALL_SIDES) 1541 if (face == ScriptBaseClass.ALL_SIDES)
1406 face = SceneObjectPart.ALL_SIDES; 1542 face = SceneObjectPart.ALL_SIDES;
1407 1543
@@ -1410,6 +1546,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1410 1546
1411 public void SetTexGen(SceneObjectPart part, int face,int style) 1547 public void SetTexGen(SceneObjectPart part, int face,int style)
1412 { 1548 {
1549 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1550 return;
1551
1413 Primitive.TextureEntry tex = part.Shape.Textures; 1552 Primitive.TextureEntry tex = part.Shape.Textures;
1414 MappingType textype; 1553 MappingType textype;
1415 textype = MappingType.Default; 1554 textype = MappingType.Default;
@@ -1440,6 +1579,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1440 1579
1441 public void SetGlow(SceneObjectPart part, int face, float glow) 1580 public void SetGlow(SceneObjectPart part, int face, float glow)
1442 { 1581 {
1582 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1583 return;
1584
1443 Primitive.TextureEntry tex = part.Shape.Textures; 1585 Primitive.TextureEntry tex = part.Shape.Textures;
1444 if (face >= 0 && face < GetNumberOfSides(part)) 1586 if (face >= 0 && face < GetNumberOfSides(part))
1445 { 1587 {
@@ -1465,6 +1607,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1465 1607
1466 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump) 1608 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
1467 { 1609 {
1610 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1611 return;
1468 1612
1469 Shininess sval = new Shininess(); 1613 Shininess sval = new Shininess();
1470 1614
@@ -1515,6 +1659,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1515 1659
1516 public void SetFullBright(SceneObjectPart part, int face, bool bright) 1660 public void SetFullBright(SceneObjectPart part, int face, bool bright)
1517 { 1661 {
1662 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1663 return;
1664
1518 Primitive.TextureEntry tex = part.Shape.Textures; 1665 Primitive.TextureEntry tex = part.Shape.Textures;
1519 if (face >= 0 && face < GetNumberOfSides(part)) 1666 if (face >= 0 && face < GetNumberOfSides(part))
1520 { 1667 {
@@ -1575,13 +1722,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1575 m_host.AddScriptLPS(1); 1722 m_host.AddScriptLPS(1);
1576 1723
1577 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1724 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1578 1725 if (parts.Count > 0)
1579 foreach (SceneObjectPart part in parts) 1726 {
1580 SetAlpha(part, alpha, face); 1727 try
1728 {
1729 parts[0].ParentGroup.areUpdatesSuspended = true;
1730 foreach (SceneObjectPart part in parts)
1731 SetAlpha(part, alpha, face);
1732 }
1733 finally
1734 {
1735 parts[0].ParentGroup.areUpdatesSuspended = false;
1736 }
1737 }
1581 } 1738 }
1582 1739
1583 protected void SetAlpha(SceneObjectPart part, double alpha, int face) 1740 protected void SetAlpha(SceneObjectPart part, double alpha, int face)
1584 { 1741 {
1742 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1743 return;
1744
1585 Primitive.TextureEntry tex = part.Shape.Textures; 1745 Primitive.TextureEntry tex = part.Shape.Textures;
1586 Color4 texcolor; 1746 Color4 texcolor;
1587 if (face >= 0 && face < GetNumberOfSides(part)) 1747 if (face >= 0 && face < GetNumberOfSides(part))
@@ -1627,7 +1787,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1627 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction, 1787 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
1628 float wind, float tension, LSL_Vector Force) 1788 float wind, float tension, LSL_Vector Force)
1629 { 1789 {
1630 if (part == null) 1790 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1631 return; 1791 return;
1632 1792
1633 if (flexi) 1793 if (flexi)
@@ -1662,7 +1822,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1662 /// <param name="falloff"></param> 1822 /// <param name="falloff"></param>
1663 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff) 1823 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
1664 { 1824 {
1665 if (part == null) 1825 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1666 return; 1826 return;
1667 1827
1668 if (light) 1828 if (light)
@@ -1739,15 +1899,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1739 m_host.AddScriptLPS(1); 1899 m_host.AddScriptLPS(1);
1740 1900
1741 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1901 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1742 1902 if (parts.Count > 0)
1743 foreach (SceneObjectPart part in parts) 1903 {
1744 SetTexture(part, texture, face); 1904 try
1745 1905 {
1906 parts[0].ParentGroup.areUpdatesSuspended = true;
1907 foreach (SceneObjectPart part in parts)
1908 SetTexture(part, texture, face);
1909 }
1910 finally
1911 {
1912 parts[0].ParentGroup.areUpdatesSuspended = false;
1913 }
1914 }
1746 ScriptSleep(200); 1915 ScriptSleep(200);
1747 } 1916 }
1748 1917
1749 protected void SetTexture(SceneObjectPart part, string texture, int face) 1918 protected void SetTexture(SceneObjectPart part, string texture, int face)
1750 { 1919 {
1920 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1921 return;
1922
1751 UUID textureID = new UUID(); 1923 UUID textureID = new UUID();
1752 1924
1753 textureID = InventoryKey(texture, (int)AssetType.Texture); 1925 textureID = InventoryKey(texture, (int)AssetType.Texture);
@@ -1792,6 +1964,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1792 1964
1793 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) 1965 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
1794 { 1966 {
1967 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1968 return;
1969
1795 Primitive.TextureEntry tex = part.Shape.Textures; 1970 Primitive.TextureEntry tex = part.Shape.Textures;
1796 if (face >= 0 && face < GetNumberOfSides(part)) 1971 if (face >= 0 && face < GetNumberOfSides(part))
1797 { 1972 {
@@ -1828,6 +2003,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1828 2003
1829 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) 2004 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
1830 { 2005 {
2006 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2007 return;
2008
1831 Primitive.TextureEntry tex = part.Shape.Textures; 2009 Primitive.TextureEntry tex = part.Shape.Textures;
1832 if (face >= 0 && face < GetNumberOfSides(part)) 2010 if (face >= 0 && face < GetNumberOfSides(part))
1833 { 2011 {
@@ -1864,6 +2042,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1864 2042
1865 protected void RotateTexture(SceneObjectPart part, double rotation, int face) 2043 protected void RotateTexture(SceneObjectPart part, double rotation, int face)
1866 { 2044 {
2045 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2046 return;
2047
1867 Primitive.TextureEntry tex = part.Shape.Textures; 2048 Primitive.TextureEntry tex = part.Shape.Textures;
1868 if (face >= 0 && face < GetNumberOfSides(part)) 2049 if (face >= 0 && face < GetNumberOfSides(part))
1869 { 2050 {
@@ -1934,6 +2115,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1934 2115
1935 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos) 2116 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos)
1936 { 2117 {
2118 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2119 return;
2120
1937 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos) 2121 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
1938 LSL_Vector currentPos = GetPartLocalPos(part); 2122 LSL_Vector currentPos = GetPartLocalPos(part);
1939 2123
@@ -1950,7 +2134,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1950 } 2134 }
1951 else 2135 else
1952 { 2136 {
1953 LSL_Vector rel_vec = SetPosAdjust(currentPos, targetPos); 2137 LSL_Vector rel_vec = SetPosAdjust(new LSL_Vector(part.OffsetPosition.X, part.OffsetPosition.Y, part.OffsetPosition.Z), targetPos);
1954 part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z); 2138 part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z);
1955 SceneObjectGroup parent = part.ParentGroup; 2139 SceneObjectGroup parent = part.ParentGroup;
1956 parent.HasGroupChanged = true; 2140 parent.HasGroupChanged = true;
@@ -2002,9 +2186,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2002 m_host.AddScriptLPS(1); 2186 m_host.AddScriptLPS(1);
2003 2187
2004 // try to let this work as in SL... 2188 // try to let this work as in SL...
2005 if (m_host.ParentID == 0) 2189 if (m_host.LinkNum < 2)
2006 { 2190 {
2007 // special case: If we are root, rotate complete SOG to new rotation 2191 // Special case: If we are root, rotate complete SOG to new
2192 // rotation.
2193 // We are root if the link number is 0 (single prim) or 1
2194 // (root prim). ParentID may be nonzero in attachments and
2195 // using it would cause attachments and HUDs to rotate
2196 // to the wrong positions.
2008 SetRot(m_host, Rot2Quaternion(rot)); 2197 SetRot(m_host, Rot2Quaternion(rot));
2009 } 2198 }
2010 else 2199 else
@@ -2033,6 +2222,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2033 2222
2034 protected void SetRot(SceneObjectPart part, Quaternion rot) 2223 protected void SetRot(SceneObjectPart part, Quaternion rot)
2035 { 2224 {
2225 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2226 return;
2227
2036 part.UpdateRotation(rot); 2228 part.UpdateRotation(rot);
2037 // Update rotation does not move the object in the physics scene if it's a linkset. 2229 // Update rotation does not move the object in the physics scene if it's a linkset.
2038 2230
@@ -2652,12 +2844,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2652 2844
2653 m_host.AddScriptLPS(1); 2845 m_host.AddScriptLPS(1);
2654 2846
2847 m_host.TaskInventory.LockItemsForRead(true);
2655 TaskInventoryItem item = m_host.TaskInventory[invItemID]; 2848 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2656 2849 m_host.TaskInventory.LockItemsForRead(false);
2657 lock (m_host.TaskInventory)
2658 {
2659 item = m_host.TaskInventory[invItemID];
2660 }
2661 2850
2662 if (item.PermsGranter == UUID.Zero) 2851 if (item.PermsGranter == UUID.Zero)
2663 return 0; 2852 return 0;
@@ -2732,6 +2921,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2732 if (dist > m_ScriptDistanceFactor * 10.0f) 2921 if (dist > m_ScriptDistanceFactor * 10.0f)
2733 return; 2922 return;
2734 2923
2924 //Clone is thread-safe
2735 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 2925 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
2736 2926
2737 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory) 2927 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory)
@@ -2794,6 +2984,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2794 2984
2795 public void llLookAt(LSL_Vector target, double strength, double damping) 2985 public void llLookAt(LSL_Vector target, double strength, double damping)
2796 { 2986 {
2987 /*
2797 m_host.AddScriptLPS(1); 2988 m_host.AddScriptLPS(1);
2798 // Determine where we are looking from 2989 // Determine where we are looking from
2799 LSL_Vector from = llGetPos(); 2990 LSL_Vector from = llGetPos();
@@ -2813,10 +3004,54 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2813 // the angles of rotation in radians into rotation value 3004 // the angles of rotation in radians into rotation value
2814 3005
2815 LSL_Types.Quaternion rot = llEuler2Rot(angle); 3006 LSL_Types.Quaternion rot = llEuler2Rot(angle);
2816 Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s); 3007
2817 m_host.startLookAt(rotation, (float)damping, (float)strength); 3008 // This would only work if your physics system contains an APID controller:
3009 // Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
3010 // m_host.startLookAt(rotation, (float)damping, (float)strength);
3011
2818 // Orient the object to the angle calculated 3012 // Orient the object to the angle calculated
2819 //llSetRot(rot); 3013 llSetRot(rot);
3014 */
3015
3016 //The above code, while nice, doesn't replicate the behaviour of SL and tends to "roll" the object.
3017 //There's probably a smarter way of doing this, my rotation math-fu is weak.
3018 // http://bugs.meta7.com/view.php?id=28
3019 // - Tom
3020
3021 /* And the following does not do the job either. It has to be performed inside the ODE glue-code. -.- .._.
3022 LSL_Rotation newrot = llGetRot() * llRotBetween(new LSL_Vector(1.0d, 0.0d, 0.0d) * llGetRot(), new LSL_Vector(0.0d, 0.0d, -1.0d));
3023 llSetRot(newrot * llRotBetween(new LSL_Vector(0.0d,0.0d,1.0d) * newrot, target - llGetPos()));
3024 */
3025 if (m_host.PhysActor != null && !m_host.PhysActor.IsPhysical)
3026 {
3027 // Part is non-phys, convert this to a llSetRot()
3028 Vector3 tgt = new Vector3((float)target.x, (float)target.y, (float)target.z);
3029 Vector3 dir = tgt - m_host.GroupPosition;
3030 dir.Normalize();
3031 float tzrot = (float)Math.Atan2(dir.Y, dir.X);
3032 float txy = (float)Math.Sqrt((dir.X * dir.X) + (dir.Y * dir.Y));
3033 float terot = (float)Math.Atan2(-dir.Z, txy);
3034 LSL_Vector az = new LSL_Vector(0.0f, 0.0f, tzrot);
3035 LSL_Vector ae = new LSL_Vector(0.0f, terot, 0.0f);
3036 LSL_Types.Quaternion spin = llEuler2Rot(az);
3037 LSL_Types.Quaternion rot = llEuler2Rot(ae) * spin;
3038 llSetRot(rot);
3039 }
3040 else
3041 {
3042 // Physical, send the target vector to RotLookAt method inside a 'rotation', the .w -99.9 value indicates it is really a LookAt.
3043 Quaternion q = new Quaternion((float)target.x, (float)target.y, (float)target.z, -99.9f);
3044 m_host.RotLookAt(q, (float)strength, (float)damping);
3045 }
3046
3047 }
3048
3049 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3050 {
3051 m_host.AddScriptLPS(1);
3052// NotImplemented("llRotLookAt");
3053 m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping);
3054
2820 } 3055 }
2821 3056
2822 public void llStopLookAt() 3057 public void llStopLookAt()
@@ -2865,13 +3100,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2865 { 3100 {
2866 TaskInventoryItem item; 3101 TaskInventoryItem item;
2867 3102
2868 lock (m_host.TaskInventory) 3103 m_host.TaskInventory.LockItemsForRead(true);
3104 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2869 { 3105 {
2870 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3106 m_host.TaskInventory.LockItemsForRead(false);
2871 return; 3107 return;
2872 else
2873 item = m_host.TaskInventory[InventorySelf()];
2874 } 3108 }
3109 else
3110 {
3111 item = m_host.TaskInventory[InventorySelf()];
3112 }
3113 m_host.TaskInventory.LockItemsForRead(false);
2875 3114
2876 if (item.PermsGranter != UUID.Zero) 3115 if (item.PermsGranter != UUID.Zero)
2877 { 3116 {
@@ -2893,13 +3132,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2893 { 3132 {
2894 TaskInventoryItem item; 3133 TaskInventoryItem item;
2895 3134
3135 m_host.TaskInventory.LockItemsForRead(true);
2896 lock (m_host.TaskInventory) 3136 lock (m_host.TaskInventory)
2897 { 3137 {
3138
2898 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3139 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3140 {
3141 m_host.TaskInventory.LockItemsForRead(false);
2899 return; 3142 return;
3143 }
2900 else 3144 else
3145 {
2901 item = m_host.TaskInventory[InventorySelf()]; 3146 item = m_host.TaskInventory[InventorySelf()];
3147 }
2902 } 3148 }
3149 m_host.TaskInventory.LockItemsForRead(false);
2903 3150
2904 m_host.AddScriptLPS(1); 3151 m_host.AddScriptLPS(1);
2905 3152
@@ -2931,19 +3178,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2931 { 3178 {
2932 m_host.AddScriptLPS(1); 3179 m_host.AddScriptLPS(1);
2933 3180
2934 if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
2935 return;
2936
2937 TaskInventoryItem item; 3181 TaskInventoryItem item;
2938 3182
2939 lock (m_host.TaskInventory) 3183 m_host.TaskInventory.LockItemsForRead(true);
3184
3185 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2940 { 3186 {
2941 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3187 m_host.TaskInventory.LockItemsForRead(false);
2942 return; 3188 return;
2943 else 3189 }
2944 item = m_host.TaskInventory[InventorySelf()]; 3190 else
3191 {
3192 item = m_host.TaskInventory[InventorySelf()];
2945 } 3193 }
2946 3194
3195 m_host.TaskInventory.LockItemsForRead(false);
3196
2947 if (item.PermsGranter != m_host.OwnerID) 3197 if (item.PermsGranter != m_host.OwnerID)
2948 return; 3198 return;
2949 3199
@@ -2953,10 +3203,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2953 3203
2954 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 3204 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
2955 3205
2956 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3206 grp.AttachToAgent(m_host.OwnerID, (uint)attachment, Vector3.Zero, false);
2957 if (attachmentsModule != null)
2958 attachmentsModule.AttachObject(presence.ControllingClient,
2959 grp, (uint)attachment, false);
2960 } 3207 }
2961 } 3208 }
2962 3209
@@ -2969,13 +3216,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2969 3216
2970 TaskInventoryItem item; 3217 TaskInventoryItem item;
2971 3218
2972 lock (m_host.TaskInventory) 3219 m_host.TaskInventory.LockItemsForRead(true);
3220
3221 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2973 { 3222 {
2974 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3223 m_host.TaskInventory.LockItemsForRead(false);
2975 return; 3224 return;
2976 else 3225 }
2977 item = m_host.TaskInventory[InventorySelf()]; 3226 else
3227 {
3228 item = m_host.TaskInventory[InventorySelf()];
2978 } 3229 }
3230 m_host.TaskInventory.LockItemsForRead(false);
3231
2979 3232
2980 if (item.PermsGranter != m_host.OwnerID) 3233 if (item.PermsGranter != m_host.OwnerID)
2981 return; 3234 return;
@@ -3022,6 +3275,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3022 3275
3023 public void llInstantMessage(string user, string message) 3276 public void llInstantMessage(string user, string message)
3024 { 3277 {
3278 UUID result;
3279 if (!UUID.TryParse(user, out result))
3280 {
3281 ShoutError("An invalid key was passed to llInstantMessage");
3282 ScriptSleep(2000);
3283 return;
3284 }
3285
3286
3025 m_host.AddScriptLPS(1); 3287 m_host.AddScriptLPS(1);
3026 3288
3027 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. 3289 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
@@ -3036,14 +3298,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3036 UUID friendTransactionID = UUID.Random(); 3298 UUID friendTransactionID = UUID.Random();
3037 3299
3038 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 3300 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
3039 3301
3040 GridInstantMessage msg = new GridInstantMessage(); 3302 GridInstantMessage msg = new GridInstantMessage();
3041 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; 3303 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
3042 msg.toAgentID = new Guid(user); // toAgentID.Guid; 3304 msg.toAgentID = new Guid(user); // toAgentID.Guid;
3043 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here 3305 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
3044// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message); 3306// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
3045// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString()); 3307// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
3046 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp; 3308// DateTime dt = DateTime.UtcNow;
3309//
3310// // Ticks from UtcNow, but make it look like local. Evil, huh?
3311// dt = DateTime.SpecifyKind(dt, DateTimeKind.Local);
3312//
3313// try
3314// {
3315// // Convert that to the PST timezone
3316// TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
3317// dt = TimeZoneInfo.ConvertTime(dt, timeZoneInfo);
3318// }
3319// catch
3320// {
3321// // No logging here, as it could be VERY spammy
3322// }
3323//
3324// // And make it look local again to fool the unix time util
3325// dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
3326
3327 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
3328
3047 //if (client != null) 3329 //if (client != null)
3048 //{ 3330 //{
3049 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName; 3331 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
@@ -3057,12 +3339,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3057 msg.message = message.Substring(0, 1024); 3339 msg.message = message.Substring(0, 1024);
3058 else 3340 else
3059 msg.message = message; 3341 msg.message = message;
3060 msg.dialog = (byte)19; // messgage from script ??? // dialog; 3342 msg.dialog = (byte)19; // MessageFromObject
3061 msg.fromGroup = false;// fromGroup; 3343 msg.fromGroup = false;// fromGroup;
3062 msg.offline = (byte)0; //offline; 3344 msg.offline = (byte)0; //offline;
3063 msg.ParentEstateID = 0; //ParentEstateID; 3345 msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
3064 msg.Position = new Vector3(m_host.AbsolutePosition); 3346 msg.Position = new Vector3(m_host.AbsolutePosition);
3065 msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; 3347 msg.RegionID = World.RegionInfo.RegionID.Guid;
3066 msg.binaryBucket 3348 msg.binaryBucket
3067 = Util.StringToBytes256( 3349 = Util.StringToBytes256(
3068 "{0}/{1}/{2}/{3}", 3350 "{0}/{1}/{2}/{3}",
@@ -3090,7 +3372,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3090 } 3372 }
3091 3373
3092 emailModule.SendEmail(m_host.UUID, address, subject, message); 3374 emailModule.SendEmail(m_host.UUID, address, subject, message);
3093 ScriptSleep(20000); 3375 ScriptSleep(15000);
3094 } 3376 }
3095 3377
3096 public void llGetNextEmail(string address, string subject) 3378 public void llGetNextEmail(string address, string subject)
@@ -3192,13 +3474,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3192 m_host.AddScriptLPS(1); 3474 m_host.AddScriptLPS(1);
3193 } 3475 }
3194 3476
3195 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3196 {
3197 m_host.AddScriptLPS(1);
3198 Quaternion rot = new Quaternion((float)target.x, (float)target.y, (float)target.z, (float)target.s);
3199 m_host.RotLookAt(rot, (float)strength, (float)damping);
3200 }
3201
3202 public LSL_Integer llStringLength(string str) 3477 public LSL_Integer llStringLength(string str)
3203 { 3478 {
3204 m_host.AddScriptLPS(1); 3479 m_host.AddScriptLPS(1);
@@ -3222,14 +3497,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3222 3497
3223 TaskInventoryItem item; 3498 TaskInventoryItem item;
3224 3499
3225 lock (m_host.TaskInventory) 3500 m_host.TaskInventory.LockItemsForRead(true);
3501 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3226 { 3502 {
3227 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3503 m_host.TaskInventory.LockItemsForRead(false);
3228 return; 3504 return;
3229 else
3230 item = m_host.TaskInventory[InventorySelf()];
3231 } 3505 }
3232 3506 else
3507 {
3508 item = m_host.TaskInventory[InventorySelf()];
3509 }
3510 m_host.TaskInventory.LockItemsForRead(false);
3233 if (item.PermsGranter == UUID.Zero) 3511 if (item.PermsGranter == UUID.Zero)
3234 return; 3512 return;
3235 3513
@@ -3259,13 +3537,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3259 3537
3260 TaskInventoryItem item; 3538 TaskInventoryItem item;
3261 3539
3262 lock (m_host.TaskInventory) 3540 m_host.TaskInventory.LockItemsForRead(true);
3541 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3263 { 3542 {
3264 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3543 m_host.TaskInventory.LockItemsForRead(false);
3265 return; 3544 return;
3266 else 3545 }
3267 item = m_host.TaskInventory[InventorySelf()]; 3546 else
3547 {
3548 item = m_host.TaskInventory[InventorySelf()];
3268 } 3549 }
3550 m_host.TaskInventory.LockItemsForRead(false);
3551
3269 3552
3270 if (item.PermsGranter == UUID.Zero) 3553 if (item.PermsGranter == UUID.Zero)
3271 return; 3554 return;
@@ -3336,10 +3619,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3336 3619
3337 TaskInventoryItem item; 3620 TaskInventoryItem item;
3338 3621
3339 lock (m_host.TaskInventory) 3622
3623 m_host.TaskInventory.LockItemsForRead(true);
3624 if (!m_host.TaskInventory.ContainsKey(invItemID))
3625 {
3626 m_host.TaskInventory.LockItemsForRead(false);
3627 return;
3628 }
3629 else
3340 { 3630 {
3341 item = m_host.TaskInventory[invItemID]; 3631 item = m_host.TaskInventory[invItemID];
3342 } 3632 }
3633 m_host.TaskInventory.LockItemsForRead(false);
3343 3634
3344 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3635 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3345 { 3636 {
@@ -3371,11 +3662,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3371 3662
3372 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3663 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3373 { 3664 {
3374 lock (m_host.TaskInventory) 3665 m_host.TaskInventory.LockItemsForWrite(true);
3375 { 3666 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3376 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3667 m_host.TaskInventory[invItemID].PermsMask = perm;
3377 m_host.TaskInventory[invItemID].PermsMask = perm; 3668 m_host.TaskInventory.LockItemsForWrite(false);
3378 }
3379 3669
3380 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3670 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3381 "run_time_permissions", new Object[] { 3671 "run_time_permissions", new Object[] {
@@ -3395,11 +3685,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3395 3685
3396 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3686 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3397 { 3687 {
3398 lock (m_host.TaskInventory) 3688 m_host.TaskInventory.LockItemsForWrite(true);
3399 { 3689 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3400 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3690 m_host.TaskInventory[invItemID].PermsMask = perm;
3401 m_host.TaskInventory[invItemID].PermsMask = perm; 3691 m_host.TaskInventory.LockItemsForWrite(false);
3402 }
3403 3692
3404 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3693 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3405 "run_time_permissions", new Object[] { 3694 "run_time_permissions", new Object[] {
@@ -3420,11 +3709,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3420 3709
3421 if (!m_waitingForScriptAnswer) 3710 if (!m_waitingForScriptAnswer)
3422 { 3711 {
3423 lock (m_host.TaskInventory) 3712 m_host.TaskInventory.LockItemsForWrite(true);
3424 { 3713 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3425 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3714 m_host.TaskInventory[invItemID].PermsMask = 0;
3426 m_host.TaskInventory[invItemID].PermsMask = 0; 3715 m_host.TaskInventory.LockItemsForWrite(false);
3427 }
3428 3716
3429 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3717 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3430 m_waitingForScriptAnswer=true; 3718 m_waitingForScriptAnswer=true;
@@ -3459,10 +3747,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3459 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3747 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3460 llReleaseControls(); 3748 llReleaseControls();
3461 3749
3462 lock (m_host.TaskInventory) 3750
3463 { 3751 m_host.TaskInventory.LockItemsForWrite(true);
3464 m_host.TaskInventory[invItemID].PermsMask = answer; 3752 m_host.TaskInventory[invItemID].PermsMask = answer;
3465 } 3753 m_host.TaskInventory.LockItemsForWrite(false);
3754
3466 3755
3467 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3756 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3468 "run_time_permissions", new Object[] { 3757 "run_time_permissions", new Object[] {
@@ -3474,16 +3763,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3474 { 3763 {
3475 m_host.AddScriptLPS(1); 3764 m_host.AddScriptLPS(1);
3476 3765
3477 lock (m_host.TaskInventory) 3766 m_host.TaskInventory.LockItemsForRead(true);
3767
3768 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3478 { 3769 {
3479 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3770 if (item.Type == 10 && item.ItemID == m_itemID)
3480 { 3771 {
3481 if (item.Type == 10 && item.ItemID == m_itemID) 3772 m_host.TaskInventory.LockItemsForRead(false);
3482 { 3773 return item.PermsGranter.ToString();
3483 return item.PermsGranter.ToString();
3484 }
3485 } 3774 }
3486 } 3775 }
3776 m_host.TaskInventory.LockItemsForRead(false);
3487 3777
3488 return UUID.Zero.ToString(); 3778 return UUID.Zero.ToString();
3489 } 3779 }
@@ -3492,19 +3782,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3492 { 3782 {
3493 m_host.AddScriptLPS(1); 3783 m_host.AddScriptLPS(1);
3494 3784
3495 lock (m_host.TaskInventory) 3785 m_host.TaskInventory.LockItemsForRead(true);
3786
3787 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3496 { 3788 {
3497 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3789 if (item.Type == 10 && item.ItemID == m_itemID)
3498 { 3790 {
3499 if (item.Type == 10 && item.ItemID == m_itemID) 3791 int perms = item.PermsMask;
3500 { 3792 if (m_automaticLinkPermission)
3501 int perms = item.PermsMask; 3793 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3502 if (m_automaticLinkPermission) 3794 m_host.TaskInventory.LockItemsForRead(false);
3503 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; 3795 return perms;
3504 return perms;
3505 }
3506 } 3796 }
3507 } 3797 }
3798 m_host.TaskInventory.LockItemsForRead(false);
3508 3799
3509 return 0; 3800 return 0;
3510 } 3801 }
@@ -3526,9 +3817,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3526 public void llSetLinkColor(int linknumber, LSL_Vector color, int face) 3817 public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
3527 { 3818 {
3528 List<SceneObjectPart> parts = GetLinkParts(linknumber); 3819 List<SceneObjectPart> parts = GetLinkParts(linknumber);
3529 3820 if (parts.Count > 0)
3530 foreach (SceneObjectPart part in parts) 3821 {
3531 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); 3822 try
3823 {
3824 parts[0].ParentGroup.areUpdatesSuspended = true;
3825 foreach (SceneObjectPart part in parts)
3826 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
3827 }
3828 finally
3829 {
3830 parts[0].ParentGroup.areUpdatesSuspended = false;
3831 }
3832 }
3532 } 3833 }
3533 3834
3534 public void llCreateLink(string target, int parent) 3835 public void llCreateLink(string target, int parent)
@@ -3541,11 +3842,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3541 return; 3842 return;
3542 3843
3543 TaskInventoryItem item; 3844 TaskInventoryItem item;
3544 lock (m_host.TaskInventory) 3845 m_host.TaskInventory.LockItemsForRead(true);
3545 { 3846 item = m_host.TaskInventory[invItemID];
3546 item = m_host.TaskInventory[invItemID]; 3847 m_host.TaskInventory.LockItemsForRead(false);
3547 } 3848
3548
3549 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3849 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3550 && !m_automaticLinkPermission) 3850 && !m_automaticLinkPermission)
3551 { 3851 {
@@ -3566,7 +3866,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3566 3866
3567 if (targetPart != null) 3867 if (targetPart != null)
3568 { 3868 {
3569 if (parent != 0) { 3869 if (parent != 0)
3870 {
3570 parentPrim = m_host.ParentGroup; 3871 parentPrim = m_host.ParentGroup;
3571 childPrim = targetPart.ParentGroup; 3872 childPrim = targetPart.ParentGroup;
3572 } 3873 }
@@ -3598,16 +3899,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3598 m_host.AddScriptLPS(1); 3899 m_host.AddScriptLPS(1);
3599 UUID invItemID = InventorySelf(); 3900 UUID invItemID = InventorySelf();
3600 3901
3601 lock (m_host.TaskInventory) 3902 m_host.TaskInventory.LockItemsForRead(true);
3602 {
3603 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3903 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3604 && !m_automaticLinkPermission) 3904 && !m_automaticLinkPermission)
3605 { 3905 {
3606 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3906 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
3907 m_host.TaskInventory.LockItemsForRead(false);
3607 return; 3908 return;
3608 } 3909 }
3609 } 3910 m_host.TaskInventory.LockItemsForRead(false);
3610 3911
3611 if (linknum < ScriptBaseClass.LINK_THIS) 3912 if (linknum < ScriptBaseClass.LINK_THIS)
3612 return; 3913 return;
3613 3914
@@ -3646,10 +3947,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3646 // Restructuring Multiple Prims. 3947 // Restructuring Multiple Prims.
3647 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts); 3948 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
3648 parts.Remove(parentPrim.RootPart); 3949 parts.Remove(parentPrim.RootPart);
3649 foreach (SceneObjectPart part in parts) 3950 if (parts.Count > 0)
3650 { 3951 {
3651 parentPrim.DelinkFromGroup(part.LocalId, true); 3952 try
3953 {
3954 parts[0].ParentGroup.areUpdatesSuspended = true;
3955 foreach (SceneObjectPart part in parts)
3956 {
3957 parentPrim.DelinkFromGroup(part.LocalId, true);
3958 }
3959 }
3960 finally
3961 {
3962 parts[0].ParentGroup.areUpdatesSuspended = false;
3963 }
3652 } 3964 }
3965
3653 parentPrim.HasGroupChanged = true; 3966 parentPrim.HasGroupChanged = true;
3654 parentPrim.ScheduleGroupForFullUpdate(); 3967 parentPrim.ScheduleGroupForFullUpdate();
3655 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 3968 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
@@ -3658,11 +3971,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3658 { 3971 {
3659 SceneObjectPart newRoot = parts[0]; 3972 SceneObjectPart newRoot = parts[0];
3660 parts.Remove(newRoot); 3973 parts.Remove(newRoot);
3661 foreach (SceneObjectPart part in parts) 3974
3975 try
3662 { 3976 {
3663 part.UpdateFlag = 0; 3977 parts[0].ParentGroup.areUpdatesSuspended = true;
3664 newRoot.ParentGroup.LinkToGroup(part.ParentGroup); 3978 foreach (SceneObjectPart part in parts)
3979 {
3980 part.UpdateFlag = 0;
3981 newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
3982 }
3665 } 3983 }
3984 finally
3985 {
3986 parts[0].ParentGroup.areUpdatesSuspended = false;
3987 }
3988
3989
3666 newRoot.ParentGroup.HasGroupChanged = true; 3990 newRoot.ParentGroup.HasGroupChanged = true;
3667 newRoot.ParentGroup.ScheduleGroupForFullUpdate(); 3991 newRoot.ParentGroup.ScheduleGroupForFullUpdate();
3668 } 3992 }
@@ -3708,6 +4032,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3708 } 4032 }
3709 else 4033 else
3710 { 4034 {
4035 if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
4036 {
4037 linknum -= (m_host.ParentGroup.PrimCount) + 1;
4038
4039 if (linknum < 0)
4040 return UUID.Zero.ToString();
4041
4042 List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
4043 if (avatars.Count > linknum)
4044 {
4045 return avatars[linknum].UUID.ToString();
4046 }
4047 }
3711 return UUID.Zero.ToString(); 4048 return UUID.Zero.ToString();
3712 } 4049 }
3713 } 4050 }
@@ -3784,17 +4121,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3784 m_host.AddScriptLPS(1); 4121 m_host.AddScriptLPS(1);
3785 int count = 0; 4122 int count = 0;
3786 4123
3787 lock (m_host.TaskInventory) 4124 m_host.TaskInventory.LockItemsForRead(true);
4125 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3788 { 4126 {
3789 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4127 if (inv.Value.Type == type || type == -1)
3790 { 4128 {
3791 if (inv.Value.Type == type || type == -1) 4129 count = count + 1;
3792 {
3793 count = count + 1;
3794 }
3795 } 4130 }
3796 } 4131 }
3797 4132
4133 m_host.TaskInventory.LockItemsForRead(false);
3798 return count; 4134 return count;
3799 } 4135 }
3800 4136
@@ -3803,16 +4139,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3803 m_host.AddScriptLPS(1); 4139 m_host.AddScriptLPS(1);
3804 ArrayList keys = new ArrayList(); 4140 ArrayList keys = new ArrayList();
3805 4141
3806 lock (m_host.TaskInventory) 4142 m_host.TaskInventory.LockItemsForRead(true);
4143 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3807 { 4144 {
3808 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4145 if (inv.Value.Type == type || type == -1)
3809 { 4146 {
3810 if (inv.Value.Type == type || type == -1) 4147 keys.Add(inv.Value.Name);
3811 {
3812 keys.Add(inv.Value.Name);
3813 }
3814 } 4148 }
3815 } 4149 }
4150 m_host.TaskInventory.LockItemsForRead(false);
3816 4151
3817 if (keys.Count == 0) 4152 if (keys.Count == 0)
3818 { 4153 {
@@ -3849,30 +4184,51 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3849 } 4184 }
3850 4185
3851 // move the first object found with this inventory name 4186 // move the first object found with this inventory name
3852 lock (m_host.TaskInventory) 4187 m_host.TaskInventory.LockItemsForRead(true);
4188 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3853 { 4189 {
3854 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4190 if (inv.Value.Name == inventory)
3855 { 4191 {
3856 if (inv.Value.Name == inventory) 4192 found = true;
3857 { 4193 objId = inv.Key;
3858 found = true; 4194 assetType = inv.Value.Type;
3859 objId = inv.Key; 4195 objName = inv.Value.Name;
3860 assetType = inv.Value.Type; 4196 break;
3861 objName = inv.Value.Name;
3862 break;
3863 }
3864 } 4197 }
3865 } 4198 }
4199 m_host.TaskInventory.LockItemsForRead(false);
3866 4200
3867 if (!found) 4201 if (!found)
3868 { 4202 {
3869 llSay(0, String.Format("Could not find object '{0}'", inventory)); 4203 llSay(0, String.Format("Could not find object '{0}'", inventory));
3870 throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); 4204 return;
4205// throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
3871 } 4206 }
3872 4207
3873 // check if destination is an avatar 4208 // check if destination is an object
3874 if (World.GetScenePresence(destId) != null) 4209 if (World.GetSceneObjectPart(destId) != null)
3875 { 4210 {
4211 // destination is an object
4212 World.MoveTaskInventoryItem(destId, m_host, objId);
4213 }
4214 else
4215 {
4216 ScenePresence presence = World.GetScenePresence(destId);
4217
4218 if (presence == null)
4219 {
4220 UserAccount account =
4221 World.UserAccountService.GetUserAccount(
4222 World.RegionInfo.ScopeID,
4223 destId);
4224
4225 if (account == null)
4226 {
4227 llSay(0, "Can't find destination "+destId.ToString());
4228 return;
4229 }
4230 }
4231
3876 // destination is an avatar 4232 // destination is an avatar
3877 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId); 4233 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId);
3878 4234
@@ -3896,31 +4252,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3896 4252
3897 if (m_TransferModule != null) 4253 if (m_TransferModule != null)
3898 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); 4254 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
4255
4256 //This delay should only occur when giving inventory to avatars.
4257 ScriptSleep(3000);
3899 } 4258 }
3900 else
3901 {
3902 // destination is an object
3903 World.MoveTaskInventoryItem(destId, m_host, objId);
3904 }
3905 ScriptSleep(3000);
3906 } 4259 }
3907 4260
4261 [DebuggerNonUserCode]
3908 public void llRemoveInventory(string name) 4262 public void llRemoveInventory(string name)
3909 { 4263 {
3910 m_host.AddScriptLPS(1); 4264 m_host.AddScriptLPS(1);
3911 4265
3912 lock (m_host.TaskInventory) 4266 List<TaskInventoryItem> inv;
4267 try
3913 { 4268 {
3914 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4269 m_host.TaskInventory.LockItemsForRead(true);
4270 inv = new List<TaskInventoryItem>(m_host.TaskInventory.Values);
4271 }
4272 finally
4273 {
4274 m_host.TaskInventory.LockItemsForRead(false);
4275 }
4276 foreach (TaskInventoryItem item in inv)
4277 {
4278 if (item.Name == name)
3915 { 4279 {
3916 if (item.Name == name) 4280 if (item.ItemID == m_itemID)
3917 { 4281 throw new ScriptDeleteException();
3918 if (item.ItemID == m_itemID) 4282 else
3919 throw new ScriptDeleteException(); 4283 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3920 else 4284 return;
3921 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3922 return;
3923 }
3924 } 4285 }
3925 } 4286 }
3926 } 4287 }
@@ -3955,112 +4316,122 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3955 { 4316 {
3956 m_host.AddScriptLPS(1); 4317 m_host.AddScriptLPS(1);
3957 4318
3958 UUID uuid = (UUID)id; 4319 UUID uuid;
3959 PresenceInfo pinfo = null; 4320 if (UUID.TryParse(id, out uuid))
3960 UserAccount account;
3961
3962 UserInfoCacheEntry ce;
3963 if (!m_userInfoCache.TryGetValue(uuid, out ce))
3964 { 4321 {
3965 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); 4322 PresenceInfo pinfo = null;
3966 if (account == null) 4323 UserAccount account;
4324
4325 UserInfoCacheEntry ce;
4326 if (!m_userInfoCache.TryGetValue(uuid, out ce))
3967 { 4327 {
3968 m_userInfoCache[uuid] = null; // Cache negative 4328 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
3969 return UUID.Zero.ToString(); 4329 if (account == null)
3970 } 4330 {
4331 m_userInfoCache[uuid] = null; // Cache negative
4332 return UUID.Zero.ToString();
4333 }
3971 4334
3972 4335
3973 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); 4336 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
3974 if (pinfos != null && pinfos.Length > 0) 4337 if (pinfos != null && pinfos.Length > 0)
3975 {
3976 foreach (PresenceInfo p in pinfos)
3977 { 4338 {
3978 if (p.RegionID != UUID.Zero) 4339 foreach (PresenceInfo p in pinfos)
3979 { 4340 {
3980 pinfo = p; 4341 if (p.RegionID != UUID.Zero)
4342 {
4343 pinfo = p;
4344 }
3981 } 4345 }
3982 } 4346 }
3983 }
3984 4347
3985 ce = new UserInfoCacheEntry(); 4348 ce = new UserInfoCacheEntry();
3986 ce.time = Util.EnvironmentTickCount(); 4349 ce.time = Util.EnvironmentTickCount();
3987 ce.account = account; 4350 ce.account = account;
3988 ce.pinfo = pinfo; 4351 ce.pinfo = pinfo;
3989 } 4352 m_userInfoCache[uuid] = ce;
3990 else 4353 }
3991 { 4354 else
3992 if (ce == null) 4355 {
3993 return UUID.Zero.ToString(); 4356 if (ce == null)
4357 return UUID.Zero.ToString();
3994 4358
3995 account = ce.account; 4359 account = ce.account;
3996 pinfo = ce.pinfo; 4360 pinfo = ce.pinfo;
3997 } 4361 }
3998 4362
3999 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) 4363 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000)
4000 {
4001 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4002 if (pinfos != null && pinfos.Length > 0)
4003 { 4364 {
4004 foreach (PresenceInfo p in pinfos) 4365 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4366 if (pinfos != null && pinfos.Length > 0)
4005 { 4367 {
4006 if (p.RegionID != UUID.Zero) 4368 foreach (PresenceInfo p in pinfos)
4007 { 4369 {
4008 pinfo = p; 4370 if (p.RegionID != UUID.Zero)
4371 {
4372 pinfo = p;
4373 }
4009 } 4374 }
4010 } 4375 }
4011 } 4376 else
4012 else 4377 pinfo = null;
4013 pinfo = null;
4014 4378
4015 ce.time = Util.EnvironmentTickCount(); 4379 ce.time = Util.EnvironmentTickCount();
4016 ce.pinfo = pinfo; 4380 ce.pinfo = pinfo;
4017 } 4381 }
4018 4382
4019 string reply = String.Empty; 4383 string reply = String.Empty;
4020 4384
4021 switch (data) 4385 switch (data)
4022 { 4386 {
4023 case 1: // DATA_ONLINE (0|1) 4387 case 1: // DATA_ONLINE (0|1)
4024 if (pinfo != null && pinfo.RegionID != UUID.Zero) 4388 if (pinfo != null && pinfo.RegionID != UUID.Zero)
4025 reply = "1"; 4389 reply = "1";
4026 else 4390 else
4027 reply = "0"; 4391 reply = "0";
4028 break; 4392 break;
4029 case 2: // DATA_NAME (First Last) 4393 case 2: // DATA_NAME (First Last)
4030 reply = account.FirstName + " " + account.LastName; 4394 reply = account.FirstName + " " + account.LastName;
4031 break; 4395 break;
4032 case 3: // DATA_BORN (YYYY-MM-DD) 4396 case 3: // DATA_BORN (YYYY-MM-DD)
4033 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); 4397 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
4034 born = born.AddSeconds(account.Created); 4398 born = born.AddSeconds(account.Created);
4035 reply = born.ToString("yyyy-MM-dd"); 4399 reply = born.ToString("yyyy-MM-dd");
4036 break; 4400 break;
4037 case 4: // DATA_RATING (0,0,0,0,0,0) 4401 case 4: // DATA_RATING (0,0,0,0,0,0)
4038 reply = "0,0,0,0,0,0"; 4402 reply = "0,0,0,0,0,0";
4039 break; 4403 break;
4040 case 8: // DATA_PAYINFO (0|1|2|3) 4404 case 8: // DATA_PAYINFO (0|1|2|3)
4041 reply = "0"; 4405 reply = "0";
4042 break; 4406 break;
4043 default: 4407 default:
4044 return UUID.Zero.ToString(); // Raise no event 4408 return UUID.Zero.ToString(); // Raise no event
4045 } 4409 }
4046 4410
4047 UUID rq = UUID.Random(); 4411 UUID rq = UUID.Random();
4048 4412
4049 UUID tid = AsyncCommands. 4413 UUID tid = AsyncCommands.
4050 DataserverPlugin.RegisterRequest(m_localID, 4414 DataserverPlugin.RegisterRequest(m_localID,
4051 m_itemID, rq.ToString()); 4415 m_itemID, rq.ToString());
4052 4416
4053 AsyncCommands. 4417 AsyncCommands.
4054 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4418 DataserverPlugin.DataserverReply(rq.ToString(), reply);
4055 4419
4056 ScriptSleep(100); 4420 ScriptSleep(100);
4057 return tid.ToString(); 4421 return tid.ToString();
4422 }
4423 else
4424 {
4425 ShoutError("Invalid UUID passed to llRequestAgentData.");
4426 }
4427 return "";
4058 } 4428 }
4059 4429
4060 public LSL_String llRequestInventoryData(string name) 4430 public LSL_String llRequestInventoryData(string name)
4061 { 4431 {
4062 m_host.AddScriptLPS(1); 4432 m_host.AddScriptLPS(1);
4063 4433
4434 //Clone is thread safe
4064 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 4435 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
4065 4436
4066 foreach (TaskInventoryItem item in itemDictionary.Values) 4437 foreach (TaskInventoryItem item in itemDictionary.Values)
@@ -4114,6 +4485,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4114 ScenePresence presence = World.GetScenePresence(agentId); 4485 ScenePresence presence = World.GetScenePresence(agentId);
4115 if (presence != null) 4486 if (presence != null)
4116 { 4487 {
4488 // agent must not be a god
4489 if (presence.GodLevel >= 200) return;
4490
4117 // agent must be over the owners land 4491 // agent must be over the owners land
4118 if (m_host.OwnerID == World.LandChannel.GetLandObject( 4492 if (m_host.OwnerID == World.LandChannel.GetLandObject(
4119 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) 4493 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
@@ -4136,7 +4510,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4136 UUID av = new UUID(); 4510 UUID av = new UUID();
4137 if (!UUID.TryParse(agent,out av)) 4511 if (!UUID.TryParse(agent,out av))
4138 { 4512 {
4139 LSLError("First parameter to llDialog needs to be a key"); 4513 //LSLError("First parameter to llDialog needs to be a key");
4140 return; 4514 return;
4141 } 4515 }
4142 4516
@@ -4173,17 +4547,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4173 UUID soundId = UUID.Zero; 4547 UUID soundId = UUID.Zero;
4174 if (!UUID.TryParse(impact_sound, out soundId)) 4548 if (!UUID.TryParse(impact_sound, out soundId))
4175 { 4549 {
4176 lock (m_host.TaskInventory) 4550 m_host.TaskInventory.LockItemsForRead(true);
4551 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4177 { 4552 {
4178 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4553 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
4179 { 4554 {
4180 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 4555 soundId = item.AssetID;
4181 { 4556 break;
4182 soundId = item.AssetID;
4183 break;
4184 }
4185 } 4557 }
4186 } 4558 }
4559 m_host.TaskInventory.LockItemsForRead(false);
4187 } 4560 }
4188 m_host.CollisionSound = soundId; 4561 m_host.CollisionSound = soundId;
4189 m_host.CollisionSoundVolume = (float)impact_volume; 4562 m_host.CollisionSoundVolume = (float)impact_volume;
@@ -4229,6 +4602,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4229 UUID partItemID; 4602 UUID partItemID;
4230 foreach (SceneObjectPart part in parts) 4603 foreach (SceneObjectPart part in parts)
4231 { 4604 {
4605 //Clone is thread safe
4232 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); 4606 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
4233 4607
4234 foreach (TaskInventoryItem item in itemsDictionary.Values) 4608 foreach (TaskInventoryItem item in itemsDictionary.Values)
@@ -4443,17 +4817,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4443 4817
4444 m_host.AddScriptLPS(1); 4818 m_host.AddScriptLPS(1);
4445 4819
4446 lock (m_host.TaskInventory) 4820 m_host.TaskInventory.LockItemsForRead(true);
4821 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4447 { 4822 {
4448 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4823 if (item.Type == 10 && item.ItemID == m_itemID)
4449 { 4824 {
4450 if (item.Type == 10 && item.ItemID == m_itemID) 4825 result = item.Name!=null?item.Name:String.Empty;
4451 { 4826 break;
4452 result = item.Name != null ? item.Name : String.Empty;
4453 break;
4454 }
4455 } 4827 }
4456 } 4828 }
4829 m_host.TaskInventory.LockItemsForRead(false);
4457 4830
4458 return result; 4831 return result;
4459 } 4832 }
@@ -4606,23 +4979,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4606 { 4979 {
4607 m_host.AddScriptLPS(1); 4980 m_host.AddScriptLPS(1);
4608 4981
4609 lock (m_host.TaskInventory) 4982 m_host.TaskInventory.LockItemsForRead(true);
4983 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4610 { 4984 {
4611 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4985 if (inv.Value.Name == name)
4612 { 4986 {
4613 if (inv.Value.Name == name) 4987 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
4614 { 4988 {
4615 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) 4989 m_host.TaskInventory.LockItemsForRead(false);
4616 { 4990 return inv.Value.AssetID.ToString();
4617 return inv.Value.AssetID.ToString(); 4991 }
4618 } 4992 else
4619 else 4993 {
4620 { 4994 m_host.TaskInventory.LockItemsForRead(false);
4621 return UUID.Zero.ToString(); 4995 return UUID.Zero.ToString();
4622 }
4623 } 4996 }
4624 } 4997 }
4625 } 4998 }
4999 m_host.TaskInventory.LockItemsForRead(false);
4626 5000
4627 return UUID.Zero.ToString(); 5001 return UUID.Zero.ToString();
4628 } 5002 }
@@ -4775,14 +5149,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4775 { 5149 {
4776 m_host.AddScriptLPS(1); 5150 m_host.AddScriptLPS(1);
4777 5151
4778 if (src == null) 5152 return src.Length;
4779 {
4780 return 0;
4781 }
4782 else
4783 {
4784 return src.Length;
4785 }
4786 } 5153 }
4787 5154
4788 public LSL_Integer llList2Integer(LSL_List src, int index) 5155 public LSL_Integer llList2Integer(LSL_List src, int index)
@@ -4828,7 +5195,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4828 else if (src.Data[index] is LSL_Float) 5195 else if (src.Data[index] is LSL_Float)
4829 return Convert.ToDouble(((LSL_Float) src.Data[index]).value); 5196 return Convert.ToDouble(((LSL_Float) src.Data[index]).value);
4830 else if (src.Data[index] is LSL_String) 5197 else if (src.Data[index] is LSL_String)
4831 return Convert.ToDouble(((LSL_String) src.Data[index]).m_string); 5198 {
5199 string str = ((LSL_String) src.Data[index]).m_string;
5200 Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
5201 if (m != Match.Empty)
5202 {
5203 str = m.Value;
5204 double d = 0.0;
5205 if (!Double.TryParse(str, out d))
5206 return 0.0;
5207
5208 return d;
5209 }
5210 return 0.0;
5211 }
4832 return Convert.ToDouble(src.Data[index]); 5212 return Convert.ToDouble(src.Data[index]);
4833 } 5213 }
4834 catch (FormatException) 5214 catch (FormatException)
@@ -5101,7 +5481,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5101 } 5481 }
5102 } 5482 }
5103 } 5483 }
5104 else { 5484 else
5485 {
5105 object[] array = new object[src.Length]; 5486 object[] array = new object[src.Length];
5106 Array.Copy(src.Data, 0, array, 0, src.Length); 5487 Array.Copy(src.Data, 0, array, 0, src.Length);
5107 result = new LSL_List(array); 5488 result = new LSL_List(array);
@@ -5513,7 +5894,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5513 public void llSetSoundQueueing(int queue) 5894 public void llSetSoundQueueing(int queue)
5514 { 5895 {
5515 m_host.AddScriptLPS(1); 5896 m_host.AddScriptLPS(1);
5516 NotImplemented("llSetSoundQueueing");
5517 } 5897 }
5518 5898
5519 public void llSetSoundRadius(double radius) 5899 public void llSetSoundRadius(double radius)
@@ -5558,10 +5938,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5558 m_host.AddScriptLPS(1); 5938 m_host.AddScriptLPS(1);
5559 5939
5560 List<SceneObjectPart> parts = GetLinkParts(linknumber); 5940 List<SceneObjectPart> parts = GetLinkParts(linknumber);
5561 5941 if (parts.Count > 0)
5562 foreach (var part in parts)
5563 { 5942 {
5564 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate); 5943 try
5944 {
5945 parts[0].ParentGroup.areUpdatesSuspended = true;
5946 foreach (var part in parts)
5947 {
5948 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
5949 }
5950 }
5951 finally
5952 {
5953 parts[0].ParentGroup.areUpdatesSuspended = false;
5954 }
5565 } 5955 }
5566 } 5956 }
5567 5957
@@ -5615,6 +6005,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5615 ScriptSleep(5000); 6005 ScriptSleep(5000);
5616 } 6006 }
5617 6007
6008 public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
6009 {
6010 return ParseString2List(str, separators, in_spacers, false);
6011 }
6012
5618 public LSL_Integer llOverMyLand(string id) 6013 public LSL_Integer llOverMyLand(string id)
5619 { 6014 {
5620 m_host.AddScriptLPS(1); 6015 m_host.AddScriptLPS(1);
@@ -5815,7 +6210,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5815 return m_host.ParentGroup.RootPart.AttachmentPoint; 6210 return m_host.ParentGroup.RootPart.AttachmentPoint;
5816 } 6211 }
5817 6212
5818 public LSL_Integer llGetFreeMemory() 6213 public virtual LSL_Integer llGetFreeMemory()
5819 { 6214 {
5820 m_host.AddScriptLPS(1); 6215 m_host.AddScriptLPS(1);
5821 // Make scripts designed for LSO happy 6216 // Make scripts designed for LSO happy
@@ -5932,7 +6327,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5932 SetParticleSystem(m_host, rules); 6327 SetParticleSystem(m_host, rules);
5933 } 6328 }
5934 6329
5935 private void SetParticleSystem(SceneObjectPart part, LSL_List rules) { 6330 private void SetParticleSystem(SceneObjectPart part, LSL_List rules)
6331 {
5936 6332
5937 6333
5938 if (rules.Length == 0) 6334 if (rules.Length == 0)
@@ -6126,14 +6522,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6126 6522
6127 protected UUID GetTaskInventoryItem(string name) 6523 protected UUID GetTaskInventoryItem(string name)
6128 { 6524 {
6129 lock (m_host.TaskInventory) 6525 m_host.TaskInventory.LockItemsForRead(true);
6526 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6130 { 6527 {
6131 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6528 if (inv.Value.Name == name)
6132 { 6529 {
6133 if (inv.Value.Name == name) 6530 m_host.TaskInventory.LockItemsForRead(false);
6134 return inv.Key; 6531 return inv.Key;
6135 } 6532 }
6136 } 6533 }
6534 m_host.TaskInventory.LockItemsForRead(false);
6137 6535
6138 return UUID.Zero; 6536 return UUID.Zero;
6139 } 6537 }
@@ -6383,13 +6781,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6383 UUID av = new UUID(); 6781 UUID av = new UUID();
6384 if (!UUID.TryParse(avatar,out av)) 6782 if (!UUID.TryParse(avatar,out av))
6385 { 6783 {
6386 LSLError("First parameter to llDialog needs to be a key"); 6784 //LSLError("First parameter to llDialog needs to be a key");
6387 return; 6785 return;
6388 } 6786 }
6389 if (buttons.Length < 1) 6787 if (buttons.Length < 1)
6390 { 6788 {
6391 LSLError("No less than 1 button can be shown"); 6789 buttons.Add("OK");
6392 return;
6393 } 6790 }
6394 if (buttons.Length > 12) 6791 if (buttons.Length > 12)
6395 { 6792 {
@@ -6406,7 +6803,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6406 } 6803 }
6407 if (buttons.Data[i].ToString().Length > 24) 6804 if (buttons.Data[i].ToString().Length > 24)
6408 { 6805 {
6409 LSLError("button label cannot be longer than 24 characters"); 6806 llWhisper(ScriptBaseClass.DEBUG_CHANNEL, "button label cannot be longer than 24 characters");
6410 return; 6807 return;
6411 } 6808 }
6412 buts[i] = buttons.Data[i].ToString(); 6809 buts[i] = buttons.Data[i].ToString();
@@ -6470,22 +6867,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6470 } 6867 }
6471 6868
6472 // copy the first script found with this inventory name 6869 // copy the first script found with this inventory name
6473 lock (m_host.TaskInventory) 6870 TaskInventoryItem scriptItem = null;
6871 m_host.TaskInventory.LockItemsForRead(true);
6872 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6474 { 6873 {
6475 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6874 if (inv.Value.Name == name)
6476 { 6875 {
6477 if (inv.Value.Name == name) 6876 // make sure the object is a script
6877 if (10 == inv.Value.Type)
6478 { 6878 {
6479 // make sure the object is a script 6879 found = true;
6480 if (10 == inv.Value.Type) 6880 srcId = inv.Key;
6481 { 6881 scriptItem = inv.Value;
6482 found = true; 6882 break;
6483 srcId = inv.Key;
6484 break;
6485 }
6486 } 6883 }
6487 } 6884 }
6488 } 6885 }
6886 m_host.TaskInventory.LockItemsForRead(false);
6489 6887
6490 if (!found) 6888 if (!found)
6491 { 6889 {
@@ -6493,8 +6891,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6493 return; 6891 return;
6494 } 6892 }
6495 6893
6496 // the rest of the permission checks are done in RezScript, so check the pin there as well 6894 SceneObjectPart dest = World.GetSceneObjectPart(destId);
6497 World.RezScript(srcId, m_host, destId, pin, running, start_param); 6895 if (dest != null)
6896 {
6897 if ((scriptItem.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
6898 {
6899 // the rest of the permission checks are done in RezScript, so check the pin there as well
6900 World.RezScript(srcId, m_host, destId, pin, running, start_param);
6901
6902 if ((scriptItem.BasePermissions & (uint)PermissionMask.Copy) == 0)
6903 m_host.Inventory.RemoveInventoryItem(srcId);
6904 }
6905 }
6498 // this will cause the delay even if the script pin or permissions were wrong - seems ok 6906 // this will cause the delay even if the script pin or permissions were wrong - seems ok
6499 ScriptSleep(3000); 6907 ScriptSleep(3000);
6500 } 6908 }
@@ -6557,18 +6965,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6557 public LSL_String llMD5String(string src, int nonce) 6965 public LSL_String llMD5String(string src, int nonce)
6558 { 6966 {
6559 m_host.AddScriptLPS(1); 6967 m_host.AddScriptLPS(1);
6560 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString())); 6968 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
6561 } 6969 }
6562 6970
6563 public LSL_String llSHA1String(string src) 6971 public LSL_String llSHA1String(string src)
6564 { 6972 {
6565 m_host.AddScriptLPS(1); 6973 m_host.AddScriptLPS(1);
6566 return Util.SHA1Hash(src).ToLower(); 6974 return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
6567 } 6975 }
6568 6976
6569 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist) 6977 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist)
6570 { 6978 {
6571 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 6979 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6980 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6981 return shapeBlock;
6572 6982
6573 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && 6983 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
6574 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && 6984 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
@@ -6644,6 +7054,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6644 7054
6645 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge) 7055 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge)
6646 { 7056 {
7057 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7058 return;
7059
6647 ObjectShapePacket.ObjectDataBlock shapeBlock; 7060 ObjectShapePacket.ObjectDataBlock shapeBlock;
6648 7061
6649 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7062 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6693,6 +7106,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6693 7106
6694 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge) 7107 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge)
6695 { 7108 {
7109 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7110 return;
7111
6696 ObjectShapePacket.ObjectDataBlock shapeBlock; 7112 ObjectShapePacket.ObjectDataBlock shapeBlock;
6697 7113
6698 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7114 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6735,6 +7151,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6735 7151
6736 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) 7152 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)
6737 { 7153 {
7154 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7155 return;
7156
6738 ObjectShapePacket.ObjectDataBlock shapeBlock; 7157 ObjectShapePacket.ObjectDataBlock shapeBlock;
6739 7158
6740 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7159 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6861,6 +7280,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6861 7280
6862 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type) 7281 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type)
6863 { 7282 {
7283 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7284 return;
7285
6864 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7286 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6865 UUID sculptId; 7287 UUID sculptId;
6866 7288
@@ -6876,13 +7298,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6876 shapeBlock.PathScaleX = 100; 7298 shapeBlock.PathScaleX = 100;
6877 shapeBlock.PathScaleY = 150; 7299 shapeBlock.PathScaleY = 150;
6878 7300
6879 if (type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER && 7301 if ((type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER) == 0 &&
6880 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE && 7302 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE) == 0 &&
6881 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE && 7303 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE) == 0 &&
6882 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) 7304 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) == 0)
6883 { 7305 {
6884 // default 7306 // default
6885 type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; 7307 type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
6886 } 7308 }
6887 7309
6888 // retain pathcurve 7310 // retain pathcurve
@@ -6901,30 +7323,82 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6901 ScriptSleep(200); 7323 ScriptSleep(200);
6902 } 7324 }
6903 7325
6904 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) 7326 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
6905 { 7327 {
6906 m_host.AddScriptLPS(1); 7328 m_host.AddScriptLPS(1);
6907 7329
6908 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7330 List<SceneObjectPart> parts = GetLinkParts(linknumber);
7331 List<ScenePresence> avatars = GetLinkAvatars(linknumber);
7332 if (parts.Count>0)
7333 {
7334 try
7335 {
7336 parts[0].ParentGroup.areUpdatesSuspended = true;
7337 foreach (SceneObjectPart part in parts)
7338 SetPrimParams(part, rules);
7339 }
7340 finally
7341 {
7342 parts[0].ParentGroup.areUpdatesSuspended = false;
7343 }
7344 }
7345 if (avatars.Count > 0)
7346 {
7347 foreach (ScenePresence avatar in avatars)
7348 SetPrimParams(avatar, rules);
7349 }
7350 }
6909 7351
6910 foreach (SceneObjectPart part in parts) 7352 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
6911 SetPrimParams(part, rules); 7353 {
6912 7354 llSetLinkPrimitiveParamsFast(linknumber, rules);
6913 ScriptSleep(200); 7355 ScriptSleep(200);
6914 } 7356 }
6915 7357
6916 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) 7358 protected void SetPrimParams(ScenePresence av, LSL_List rules)
6917 { 7359 {
6918 m_host.AddScriptLPS(1); 7360 //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
7361 //We only support PRIM_POSITION and PRIM_ROTATION
6919 7362
6920 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7363 int idx = 0;
6921 7364
6922 foreach (SceneObjectPart part in parts) 7365 while (idx < rules.Length)
6923 SetPrimParams(part, rules); 7366 {
7367 int code = rules.GetLSLIntegerItem(idx++);
7368
7369 int remain = rules.Length - idx;
7370
7371
7372
7373 switch (code)
7374 {
7375 case (int)ScriptBaseClass.PRIM_POSITION:
7376 if (remain < 1)
7377 return;
7378 LSL_Vector v;
7379 v = rules.GetVector3Item(idx++);
7380 av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
7381 av.SendAvatarDataToAllAgents();
7382
7383 break;
7384
7385 case (int)ScriptBaseClass.PRIM_ROTATION:
7386 if (remain < 1)
7387 return;
7388 LSL_Rotation r;
7389 r = rules.GetQuaternionItem(idx++);
7390 av.OffsetRotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
7391 av.SendAvatarDataToAllAgents();
7392 break;
7393 }
7394 }
6924 } 7395 }
6925 7396
6926 protected void SetPrimParams(SceneObjectPart part, LSL_List rules) 7397 protected void SetPrimParams(SceneObjectPart part, LSL_List rules)
6927 { 7398 {
7399 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7400 return;
7401
6928 int idx = 0; 7402 int idx = 0;
6929 7403
6930 while (idx < rules.Length) 7404 while (idx < rules.Length)
@@ -7459,13 +7933,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7459 public LSL_Integer llGetNumberOfPrims() 7933 public LSL_Integer llGetNumberOfPrims()
7460 { 7934 {
7461 m_host.AddScriptLPS(1); 7935 m_host.AddScriptLPS(1);
7462 int avatarCount = 0; 7936 int avatarCount = m_host.ParentGroup.GetLinkedAvatars().Count;
7463 World.ForEachScenePresence(delegate(ScenePresence presence) 7937
7464 {
7465 if (!presence.IsChildAgent && presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID))
7466 avatarCount++;
7467 });
7468
7469 return m_host.ParentGroup.PrimCount + avatarCount; 7938 return m_host.ParentGroup.PrimCount + avatarCount;
7470 } 7939 }
7471 7940
@@ -7481,55 +7950,98 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7481 m_host.AddScriptLPS(1); 7950 m_host.AddScriptLPS(1);
7482 UUID objID = UUID.Zero; 7951 UUID objID = UUID.Zero;
7483 LSL_List result = new LSL_List(); 7952 LSL_List result = new LSL_List();
7953
7954 // If the ID is not valid, return null result
7484 if (!UUID.TryParse(obj, out objID)) 7955 if (!UUID.TryParse(obj, out objID))
7485 { 7956 {
7486 result.Add(new LSL_Vector()); 7957 result.Add(new LSL_Vector());
7487 result.Add(new LSL_Vector()); 7958 result.Add(new LSL_Vector());
7488 return result; 7959 return result;
7489 } 7960 }
7961
7962 // Check if this is an attached prim. If so, replace
7963 // the UUID with the avatar UUID and report it's bounding box
7964 SceneObjectPart part = World.GetSceneObjectPart(objID);
7965 if (part != null && part.ParentGroup.IsAttachment)
7966 objID = part.ParentGroup.RootPart.AttachedAvatar;
7967
7968 // Find out if this is an avatar ID. If so, return it's box
7490 ScenePresence presence = World.GetScenePresence(objID); 7969 ScenePresence presence = World.GetScenePresence(objID);
7491 if (presence != null) 7970 if (presence != null)
7492 { 7971 {
7493 if (presence.ParentID == 0) // not sat on an object 7972 // As per LSL Wiki, there is no difference between sitting
7973 // and standing avatar since server 1.36
7974 LSL_Vector lower;
7975 LSL_Vector upper;
7976 if (presence.Animator.Animations.DefaultAnimation.AnimID
7977 == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
7494 { 7978 {
7495 LSL_Vector lower; 7979 // This is for ground sitting avatars
7496 LSL_Vector upper; 7980 float height = presence.Appearance.AvatarHeight / 2.66666667f;
7497 if (presence.Animator.Animations.DefaultAnimation.AnimID 7981 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
7498 == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) 7982 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
7499 {
7500 // This is for ground sitting avatars
7501 float height = presence.Appearance.AvatarHeight / 2.66666667f;
7502 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
7503 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
7504 }
7505 else
7506 {
7507 // This is for standing/flying avatars
7508 float height = presence.Appearance.AvatarHeight / 2.0f;
7509 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
7510 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
7511 }
7512 result.Add(lower);
7513 result.Add(upper);
7514 return result;
7515 } 7983 }
7516 else 7984 else
7517 { 7985 {
7518 // sitting on an object so we need the bounding box of that 7986 // This is for standing/flying avatars
7519 // which should include the avatar so set the UUID to the 7987 float height = presence.Appearance.AvatarHeight / 2.0f;
7520 // UUID of the object the avatar is sat on and allow it to fall through 7988 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
7521 // to processing an object 7989 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
7522 SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
7523 objID = p.UUID;
7524 } 7990 }
7991
7992 // Adjust to the documented error offsets (see LSL Wiki)
7993 lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
7994 upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
7995
7996 if (lower.x > upper.x)
7997 lower.x = upper.x;
7998 if (lower.y > upper.y)
7999 lower.y = upper.y;
8000 if (lower.z > upper.z)
8001 lower.z = upper.z;
8002
8003 result.Add(lower);
8004 result.Add(upper);
8005 return result;
7525 } 8006 }
7526 SceneObjectPart part = World.GetSceneObjectPart(objID); 8007
8008 part = World.GetSceneObjectPart(objID);
7527 // Currently only works for single prims without a sitting avatar 8009 // Currently only works for single prims without a sitting avatar
7528 if (part != null) 8010 if (part != null)
7529 { 8011 {
7530 Vector3 halfSize = part.Scale / 2.0f; 8012 float minX;
7531 LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f); 8013 float maxX;
7532 LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z); 8014 float minY;
8015 float maxY;
8016 float minZ;
8017 float maxZ;
8018
8019 // This BBox is in sim coordinates, with the offset being
8020 // a contained point.
8021 Vector3[] offsets = World.GetCombinedBoundingBox(new List<SceneObjectGroup> { part.ParentGroup },
8022 out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
8023
8024 minX -= offsets[0].X;
8025 maxX -= offsets[0].X;
8026 minY -= offsets[0].Y;
8027 maxY -= offsets[0].Y;
8028 minZ -= offsets[0].Z;
8029 maxZ -= offsets[0].Z;
8030
8031 LSL_Vector lower;
8032 LSL_Vector upper;
8033
8034 // Adjust to the documented error offsets (see LSL Wiki)
8035 lower = new LSL_Vector(minX + 0.05f, minY + 0.05f, minZ + 0.05f);
8036 upper = new LSL_Vector(maxX - 0.05f, maxY - 0.05f, maxZ - 0.05f);
8037
8038 if (lower.x > upper.x)
8039 lower.x = upper.x;
8040 if (lower.y > upper.y)
8041 lower.y = upper.y;
8042 if (lower.z > upper.z)
8043 lower.z = upper.z;
8044
7533 result.Add(lower); 8045 result.Add(lower);
7534 result.Add(upper); 8046 result.Add(upper);
7535 return result; 8047 return result;
@@ -7609,13 +8121,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7609 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X, 8121 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
7610 part.AbsolutePosition.Y, 8122 part.AbsolutePosition.Y,
7611 part.AbsolutePosition.Z); 8123 part.AbsolutePosition.Z);
7612 // For some reason, the part.AbsolutePosition.* values do not change if the
7613 // linkset is rotated; they always reflect the child prim's world position
7614 // as though the linkset is unrotated. This is incompatible behavior with SL's
7615 // implementation, so will break scripts imported from there (not to mention it
7616 // makes it more difficult to determine a child prim's actual inworld position).
7617 if (part.ParentID != 0)
7618 v = ((v - llGetRootPosition()) * llGetRootRotation()) + llGetRootPosition();
7619 res.Add(v); 8124 res.Add(v);
7620 break; 8125 break;
7621 8126
@@ -7776,56 +8281,92 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7776 case (int)ScriptBaseClass.PRIM_BUMP_SHINY: 8281 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
7777 if (remain < 1) 8282 if (remain < 1)
7778 return res; 8283 return res;
7779 8284 face = (int)rules.GetLSLIntegerItem(idx++);
7780 face=(int)rules.GetLSLIntegerItem(idx++);
7781 8285
7782 tex = part.Shape.Textures; 8286 tex = part.Shape.Textures;
8287 int shiny;
7783 if (face == ScriptBaseClass.ALL_SIDES) 8288 if (face == ScriptBaseClass.ALL_SIDES)
7784 { 8289 {
7785 for (face = 0; face < GetNumberOfSides(part); face++) 8290 for (face = 0; face < GetNumberOfSides(part); face++)
7786 { 8291 {
7787 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8292 Shininess shinyness = tex.GetFace((uint)face).Shiny;
7788 // Convert Shininess to PRIM_SHINY_* 8293 if (shinyness == Shininess.High)
7789 res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); 8294 {
7790 // PRIM_BUMP_* 8295 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
7791 res.Add(new LSL_Integer((int)texface.Bump)); 8296 }
8297 else if (shinyness == Shininess.Medium)
8298 {
8299 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8300 }
8301 else if (shinyness == Shininess.Low)
8302 {
8303 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8304 }
8305 else
8306 {
8307 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8308 }
8309 res.Add(new LSL_Integer(shiny));
8310 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
7792 } 8311 }
7793 } 8312 }
7794 else 8313 else
7795 { 8314 {
7796 if (face >= 0 && face < GetNumberOfSides(part)) 8315 Shininess shinyness = tex.GetFace((uint)face).Shiny;
8316 if (shinyness == Shininess.High)
7797 { 8317 {
7798 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8318 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
7799 // Convert Shininess to PRIM_SHINY_* 8319 }
7800 res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); 8320 else if (shinyness == Shininess.Medium)
7801 // PRIM_BUMP_* 8321 {
7802 res.Add(new LSL_Integer((int)texface.Bump)); 8322 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
7803 } 8323 }
8324 else if (shinyness == Shininess.Low)
8325 {
8326 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8327 }
8328 else
8329 {
8330 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8331 }
8332 res.Add(new LSL_Integer(shiny));
8333 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
7804 } 8334 }
7805 break; 8335 break;
7806 8336
7807 case (int)ScriptBaseClass.PRIM_FULLBRIGHT: 8337 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
7808 if (remain < 1) 8338 if (remain < 1)
7809 return res; 8339 return res;
7810 8340 face = (int)rules.GetLSLIntegerItem(idx++);
7811 face=(int)rules.GetLSLIntegerItem(idx++);
7812 8341
7813 tex = part.Shape.Textures; 8342 tex = part.Shape.Textures;
8343 int fullbright;
7814 if (face == ScriptBaseClass.ALL_SIDES) 8344 if (face == ScriptBaseClass.ALL_SIDES)
7815 { 8345 {
7816 for (face = 0; face < GetNumberOfSides(part); face++) 8346 for (face = 0; face < GetNumberOfSides(part); face++)
7817 { 8347 {
7818 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8348 if (tex.GetFace((uint)face).Fullbright == true)
7819 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); 8349 {
8350 fullbright = ScriptBaseClass.TRUE;
8351 }
8352 else
8353 {
8354 fullbright = ScriptBaseClass.FALSE;
8355 }
8356 res.Add(new LSL_Integer(fullbright));
7820 } 8357 }
7821 } 8358 }
7822 else 8359 else
7823 { 8360 {
7824 if (face >= 0 && face < GetNumberOfSides(part)) 8361 if (tex.GetFace((uint)face).Fullbright == true)
7825 { 8362 {
7826 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8363 fullbright = ScriptBaseClass.TRUE;
7827 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
7828 } 8364 }
8365 else
8366 {
8367 fullbright = ScriptBaseClass.FALSE;
8368 }
8369 res.Add(new LSL_Integer(fullbright));
7829 } 8370 }
7830 break; 8371 break;
7831 8372
@@ -7847,27 +8388,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7847 break; 8388 break;
7848 8389
7849 case (int)ScriptBaseClass.PRIM_TEXGEN: 8390 case (int)ScriptBaseClass.PRIM_TEXGEN:
8391 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
7850 if (remain < 1) 8392 if (remain < 1)
7851 return res; 8393 return res;
7852 8394 face = (int)rules.GetLSLIntegerItem(idx++);
7853 face=(int)rules.GetLSLIntegerItem(idx++);
7854 8395
7855 tex = part.Shape.Textures; 8396 tex = part.Shape.Textures;
7856 if (face == ScriptBaseClass.ALL_SIDES) 8397 if (face == ScriptBaseClass.ALL_SIDES)
7857 { 8398 {
7858 for (face = 0; face < GetNumberOfSides(part); face++) 8399 for (face = 0; face < GetNumberOfSides(part); face++)
7859 { 8400 {
7860 MappingType texgen = tex.GetFace((uint)face).TexMapType; 8401 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
7861 // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc. 8402 {
7862 res.Add(new LSL_Integer((uint)texgen >> 1)); 8403 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8404 }
8405 else
8406 {
8407 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8408 }
7863 } 8409 }
7864 } 8410 }
7865 else 8411 else
7866 { 8412 {
7867 if (face >= 0 && face < GetNumberOfSides(part)) 8413 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8414 {
8415 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8416 }
8417 else
7868 { 8418 {
7869 MappingType texgen = tex.GetFace((uint)face).TexMapType; 8419 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
7870 res.Add(new LSL_Integer((uint)texgen >> 1));
7871 } 8420 }
7872 } 8421 }
7873 break; 8422 break;
@@ -7890,28 +8439,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7890 case (int)ScriptBaseClass.PRIM_GLOW: 8439 case (int)ScriptBaseClass.PRIM_GLOW:
7891 if (remain < 1) 8440 if (remain < 1)
7892 return res; 8441 return res;
7893 8442 face = (int)rules.GetLSLIntegerItem(idx++);
7894 face=(int)rules.GetLSLIntegerItem(idx++);
7895 8443
7896 tex = part.Shape.Textures; 8444 tex = part.Shape.Textures;
8445 float primglow;
7897 if (face == ScriptBaseClass.ALL_SIDES) 8446 if (face == ScriptBaseClass.ALL_SIDES)
7898 { 8447 {
7899 for (face = 0; face < GetNumberOfSides(part); face++) 8448 for (face = 0; face < GetNumberOfSides(part); face++)
7900 { 8449 {
7901 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8450 primglow = tex.GetFace((uint)face).Glow;
7902 res.Add(new LSL_Float(texface.Glow)); 8451 res.Add(new LSL_Float(primglow));
7903 } 8452 }
7904 } 8453 }
7905 else 8454 else
7906 { 8455 {
7907 if (face >= 0 && face < GetNumberOfSides(part)) 8456 primglow = tex.GetFace((uint)face).Glow;
7908 { 8457 res.Add(new LSL_Float(primglow));
7909 Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
7910 res.Add(new LSL_Float(texface.Glow));
7911 }
7912 } 8458 }
7913 break; 8459 break;
7914
7915 case (int)ScriptBaseClass.PRIM_TEXT: 8460 case (int)ScriptBaseClass.PRIM_TEXT:
7916 Color4 textColor = part.GetTextColor(); 8461 Color4 textColor = part.GetTextColor();
7917 res.Add(part.Text); 8462 res.Add(part.Text);
@@ -8460,8 +9005,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8460 // The function returns an ordered list 9005 // The function returns an ordered list
8461 // representing the tokens found in the supplied 9006 // representing the tokens found in the supplied
8462 // sources string. If two successive tokenizers 9007 // sources string. If two successive tokenizers
8463 // are encountered, then a NULL entry is added 9008 // are encountered, then a null-string entry is
8464 // to the list. 9009 // added to the list.
8465 // 9010 //
8466 // It is a precondition that the source and 9011 // It is a precondition that the source and
8467 // toekizer lisst are non-null. If they are null, 9012 // toekizer lisst are non-null. If they are null,
@@ -8469,7 +9014,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8469 // while their lengths are being determined. 9014 // while their lengths are being determined.
8470 // 9015 //
8471 // A small amount of working memoryis required 9016 // A small amount of working memoryis required
8472 // of approximately 8*#tokenizers. 9017 // of approximately 8*#tokenizers + 8*srcstrlen.
8473 // 9018 //
8474 // There are many ways in which this function 9019 // There are many ways in which this function
8475 // can be implemented, this implementation is 9020 // can be implemented, this implementation is
@@ -8485,155 +9030,124 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8485 // and eliminates redundant tokenizers as soon 9030 // and eliminates redundant tokenizers as soon
8486 // as is possible. 9031 // as is possible.
8487 // 9032 //
8488 // The implementation tries to avoid any copying 9033 // The implementation tries to minimize temporary
8489 // of arrays or other objects. 9034 // garbage generation.
8490 // </remarks> 9035 // </remarks>
8491 9036
8492 private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls) 9037 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
8493 { 9038 {
8494 int beginning = 0; 9039 return ParseString2List(src, separators, spacers, true);
8495 int srclen = src.Length; 9040 }
8496 int seplen = separators.Length;
8497 object[] separray = separators.Data;
8498 int spclen = spacers.Length;
8499 object[] spcarray = spacers.Data;
8500 int mlen = seplen+spclen;
8501
8502 int[] offset = new int[mlen+1];
8503 bool[] active = new bool[mlen];
8504
8505 int best;
8506 int j;
8507
8508 // Initial capacity reduces resize cost
8509 9041
8510 LSL_List tokens = new LSL_List(); 9042 private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
9043 {
9044 int srclen = src.Length;
9045 int seplen = separators.Length;
9046 object[] separray = separators.Data;
9047 int spclen = spacers.Length;
9048 object[] spcarray = spacers.Data;
9049 int dellen = 0;
9050 string[] delarray = new string[seplen+spclen];
8511 9051
8512 // All entries are initially valid 9052 int outlen = 0;
9053 string[] outarray = new string[srclen*2+1];
8513 9054
8514 for (int i = 0; i < mlen; i++) 9055 int i, j;
8515 active[i] = true; 9056 string d;
8516 9057
8517 offset[mlen] = srclen; 9058 m_host.AddScriptLPS(1);
8518 9059
8519 while (beginning < srclen) 9060 /*
9061 * Convert separator and spacer lists to C# strings.
9062 * Also filter out null strings so we don't hang.
9063 */
9064 for (i = 0; i < seplen; i ++)
8520 { 9065 {
9066 d = separray[i].ToString();
9067 if (d.Length > 0)
9068 {
9069 delarray[dellen++] = d;
9070 }
9071 }
9072 seplen = dellen;
8521 9073
8522 best = mlen; // as bad as it gets 9074 for (i = 0; i < spclen; i ++)
9075 {
9076 d = spcarray[i].ToString();
9077 if (d.Length > 0)
9078 {
9079 delarray[dellen++] = d;
9080 }
9081 }
8523 9082
8524 // Scan for separators 9083 /*
9084 * Scan through source string from beginning to end.
9085 */
9086 for (i = 0;;)
9087 {
8525 9088
8526 for (j = 0; j < seplen; j++) 9089 /*
9090 * Find earliest delimeter in src starting at i (if any).
9091 */
9092 int earliestDel = -1;
9093 int earliestSrc = srclen;
9094 string earliestStr = null;
9095 for (j = 0; j < dellen; j ++)
8527 { 9096 {
8528 if (separray[j].ToString() == String.Empty) 9097 d = delarray[j];
8529 active[j] = false; 9098 if (d != null)
8530
8531 if (active[j])
8532 { 9099 {
8533 // scan all of the markers 9100 int index = src.IndexOf(d, i);
8534 if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1) 9101 if (index < 0)
8535 { 9102 {
8536 // not present at all 9103 delarray[j] = null; // delim nowhere in src, don't check it anymore
8537 active[j] = false;
8538 } 9104 }
8539 else 9105 else if (index < earliestSrc)
8540 { 9106 {
8541 // present and correct 9107 earliestSrc = index; // where delimeter starts in source string
8542 if (offset[j] < offset[best]) 9108 earliestDel = j; // where delimeter is in delarray[]
8543 { 9109 earliestStr = d; // the delimeter string from delarray[]
8544 // closest so far 9110 if (index == i) break; // can't do any better than found at beg of string
8545 best = j;
8546 if (offset[best] == beginning)
8547 break;
8548 }
8549 } 9111 }
8550 } 9112 }
8551 } 9113 }
8552 9114
8553 // Scan for spacers 9115 /*
8554 9116 * Output source string starting at i through start of earliest delimeter.
8555 if (offset[best] != beginning) 9117 */
9118 if (keepNulls || (earliestSrc > i))
8556 { 9119 {
8557 for (j = seplen; (j < mlen) && (offset[best] > beginning); j++) 9120 outarray[outlen++] = src.Substring(i, earliestSrc - i);
8558 {
8559 if (spcarray[j-seplen].ToString() == String.Empty)
8560 active[j] = false;
8561
8562 if (active[j])
8563 {
8564 // scan all of the markers
8565 if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
8566 {
8567 // not present at all
8568 active[j] = false;
8569 }
8570 else
8571 {
8572 // present and correct
8573 if (offset[j] < offset[best])
8574 {
8575 // closest so far
8576 best = j;
8577 }
8578 }
8579 }
8580 }
8581 } 9121 }
8582 9122
8583 // This is the normal exit from the scanning loop 9123 /*
9124 * If no delimeter found at or after i, we're done scanning.
9125 */
9126 if (earliestDel < 0) break;
8584 9127
8585 if (best == mlen) 9128 /*
9129 * If delimeter was a spacer, output the spacer.
9130 */
9131 if (earliestDel >= seplen)
8586 { 9132 {
8587 // no markers were found on this pass 9133 outarray[outlen++] = earliestStr;
8588 // so we're pretty much done
8589 if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0))
8590 tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
8591 break;
8592 } 9134 }
8593 9135
8594 // Otherwise we just add the newly delimited token 9136 /*
8595 // and recalculate where the search should continue. 9137 * Look at rest of src string following delimeter.
8596 if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0)) 9138 */
8597 tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning))); 9139 i = earliestSrc + earliestStr.Length;
8598
8599 if (best < seplen)
8600 {
8601 beginning = offset[best] + (separray[best].ToString()).Length;
8602 }
8603 else
8604 {
8605 beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
8606 string str = spcarray[best - seplen].ToString();
8607 if ((keepNulls) || ((!keepNulls) && (str.Length > 0)))
8608 tokens.Add(new LSL_String(str));
8609 }
8610 } 9140 }
8611 9141
8612 // This an awkward an not very intuitive boundary case. If the 9142 /*
8613 // last substring is a tokenizer, then there is an implied trailing 9143 * Make up an exact-sized output array suitable for an LSL_List object.
8614 // null list entry. Hopefully the single comparison will not be too 9144 */
8615 // arduous. Alternatively the 'break' could be replced with a return 9145 object[] outlist = new object[outlen];
8616 // but that's shabby programming. 9146 for (i = 0; i < outlen; i ++)
8617
8618 if ((beginning == srclen) && (keepNulls))
8619 { 9147 {
8620 if (srclen != 0) 9148 outlist[i] = new LSL_String(outarray[i]);
8621 tokens.Add(new LSL_String(""));
8622 } 9149 }
8623 9150 return new LSL_List(outlist);
8624 return tokens;
8625 }
8626
8627 public LSL_List llParseString2List(string src, LSL_List separators, LSL_List spacers)
8628 {
8629 m_host.AddScriptLPS(1);
8630 return this.ParseString(src, separators, spacers, false);
8631 }
8632
8633 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
8634 {
8635 m_host.AddScriptLPS(1);
8636 return this.ParseString(src, separators, spacers, true);
8637 } 9151 }
8638 9152
8639 public LSL_Integer llGetObjectPermMask(int mask) 9153 public LSL_Integer llGetObjectPermMask(int mask)
@@ -8710,28 +9224,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8710 { 9224 {
8711 m_host.AddScriptLPS(1); 9225 m_host.AddScriptLPS(1);
8712 9226
8713 lock (m_host.TaskInventory) 9227 m_host.TaskInventory.LockItemsForRead(true);
9228 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8714 { 9229 {
8715 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9230 if (inv.Value.Name == item)
8716 { 9231 {
8717 if (inv.Value.Name == item) 9232 m_host.TaskInventory.LockItemsForRead(false);
9233 switch (mask)
8718 { 9234 {
8719 switch (mask) 9235 case 0:
8720 { 9236 return (int)inv.Value.BasePermissions;
8721 case 0: 9237 case 1:
8722 return (int)inv.Value.BasePermissions; 9238 return (int)inv.Value.CurrentPermissions;
8723 case 1: 9239 case 2:
8724 return (int)inv.Value.CurrentPermissions; 9240 return (int)inv.Value.GroupPermissions;
8725 case 2: 9241 case 3:
8726 return (int)inv.Value.GroupPermissions; 9242 return (int)inv.Value.EveryonePermissions;
8727 case 3: 9243 case 4:
8728 return (int)inv.Value.EveryonePermissions; 9244 return (int)inv.Value.NextPermissions;
8729 case 4:
8730 return (int)inv.Value.NextPermissions;
8731 }
8732 } 9245 }
8733 } 9246 }
8734 } 9247 }
9248 m_host.TaskInventory.LockItemsForRead(false);
8735 9249
8736 return -1; 9250 return -1;
8737 } 9251 }
@@ -8778,16 +9292,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8778 { 9292 {
8779 m_host.AddScriptLPS(1); 9293 m_host.AddScriptLPS(1);
8780 9294
8781 lock (m_host.TaskInventory) 9295 m_host.TaskInventory.LockItemsForRead(true);
9296 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8782 { 9297 {
8783 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9298 if (inv.Value.Name == item)
8784 { 9299 {
8785 if (inv.Value.Name == item) 9300 m_host.TaskInventory.LockItemsForRead(false);
8786 { 9301 return inv.Value.CreatorID.ToString();
8787 return inv.Value.CreatorID.ToString();
8788 }
8789 } 9302 }
8790 } 9303 }
9304 m_host.TaskInventory.LockItemsForRead(false);
8791 9305
8792 llSay(0, "No item name '" + item + "'"); 9306 llSay(0, "No item name '" + item + "'");
8793 9307
@@ -8935,7 +9449,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8935 } 9449 }
8936 9450
8937 /// <summary> 9451 /// <summary>
8938 /// illListReplaceList removes the sub-list defined by the inclusive indices 9452 /// llListReplaceList removes the sub-list defined by the inclusive indices
8939 /// start and end and inserts the src list in its place. The inclusive 9453 /// start and end and inserts the src list in its place. The inclusive
8940 /// nature of the indices means that at least one element must be deleted 9454 /// nature of the indices means that at least one element must be deleted
8941 /// if the indices are within the bounds of the existing list. I.e. 2,2 9455 /// if the indices are within the bounds of the existing list. I.e. 2,2
@@ -8992,16 +9506,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8992 // based upon end. Note that if end exceeds the upper 9506 // based upon end. Note that if end exceeds the upper
8993 // bound in this case, the entire destination list 9507 // bound in this case, the entire destination list
8994 // is removed. 9508 // is removed.
8995 else 9509 else if (start == 0)
8996 { 9510 {
8997 if (end + 1 < dest.Length) 9511 if (end + 1 < dest.Length)
8998 {
8999 return src + dest.GetSublist(end + 1, -1); 9512 return src + dest.GetSublist(end + 1, -1);
9000 }
9001 else 9513 else
9002 {
9003 return src; 9514 return src;
9004 } 9515 }
9516 else // Start < 0
9517 {
9518 if (end + 1 < dest.Length)
9519 return dest.GetSublist(end + 1, -1);
9520 else
9521 return new LSL_List();
9005 } 9522 }
9006 } 9523 }
9007 // Finally, if start > end, we strip away a prefix and 9524 // Finally, if start > end, we strip away a prefix and
@@ -9052,17 +9569,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9052 int width = 0; 9569 int width = 0;
9053 int height = 0; 9570 int height = 0;
9054 9571
9055 ParcelMediaCommandEnum? commandToSend = null; 9572 uint commandToSend = 0;
9056 float time = 0.0f; // default is from start 9573 float time = 0.0f; // default is from start
9057 9574
9058 ScenePresence presence = null; 9575 ScenePresence presence = null;
9059 9576
9060 for (int i = 0; i < commandList.Data.Length; i++) 9577 for (int i = 0; i < commandList.Data.Length; i++)
9061 { 9578 {
9062 ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i]; 9579 uint command = (uint)(commandList.GetLSLIntegerItem(i));
9063 switch (command) 9580 switch (command)
9064 { 9581 {
9065 case ParcelMediaCommandEnum.Agent: 9582 case (uint)ParcelMediaCommandEnum.Agent:
9066 // we send only to one agent 9583 // we send only to one agent
9067 if ((i + 1) < commandList.Length) 9584 if ((i + 1) < commandList.Length)
9068 { 9585 {
@@ -9079,25 +9596,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9079 } 9596 }
9080 break; 9597 break;
9081 9598
9082 case ParcelMediaCommandEnum.Loop: 9599 case (uint)ParcelMediaCommandEnum.Loop:
9083 loop = 1; 9600 loop = 1;
9084 commandToSend = command; 9601 commandToSend = command;
9085 update = true; //need to send the media update packet to set looping 9602 update = true; //need to send the media update packet to set looping
9086 break; 9603 break;
9087 9604
9088 case ParcelMediaCommandEnum.Play: 9605 case (uint)ParcelMediaCommandEnum.Play:
9089 loop = 0; 9606 loop = 0;
9090 commandToSend = command; 9607 commandToSend = command;
9091 update = true; //need to send the media update packet to make sure it doesn't loop 9608 update = true; //need to send the media update packet to make sure it doesn't loop
9092 break; 9609 break;
9093 9610
9094 case ParcelMediaCommandEnum.Pause: 9611 case (uint)ParcelMediaCommandEnum.Pause:
9095 case ParcelMediaCommandEnum.Stop: 9612 case (uint)ParcelMediaCommandEnum.Stop:
9096 case ParcelMediaCommandEnum.Unload: 9613 case (uint)ParcelMediaCommandEnum.Unload:
9097 commandToSend = command; 9614 commandToSend = command;
9098 break; 9615 break;
9099 9616
9100 case ParcelMediaCommandEnum.Url: 9617 case (uint)ParcelMediaCommandEnum.Url:
9101 if ((i + 1) < commandList.Length) 9618 if ((i + 1) < commandList.Length)
9102 { 9619 {
9103 if (commandList.Data[i + 1] is LSL_String) 9620 if (commandList.Data[i + 1] is LSL_String)
@@ -9110,7 +9627,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9110 } 9627 }
9111 break; 9628 break;
9112 9629
9113 case ParcelMediaCommandEnum.Texture: 9630 case (uint)ParcelMediaCommandEnum.Texture:
9114 if ((i + 1) < commandList.Length) 9631 if ((i + 1) < commandList.Length)
9115 { 9632 {
9116 if (commandList.Data[i + 1] is LSL_String) 9633 if (commandList.Data[i + 1] is LSL_String)
@@ -9123,7 +9640,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9123 } 9640 }
9124 break; 9641 break;
9125 9642
9126 case ParcelMediaCommandEnum.Time: 9643 case (uint)ParcelMediaCommandEnum.Time:
9127 if ((i + 1) < commandList.Length) 9644 if ((i + 1) < commandList.Length)
9128 { 9645 {
9129 if (commandList.Data[i + 1] is LSL_Float) 9646 if (commandList.Data[i + 1] is LSL_Float)
@@ -9135,7 +9652,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9135 } 9652 }
9136 break; 9653 break;
9137 9654
9138 case ParcelMediaCommandEnum.AutoAlign: 9655 case (uint)ParcelMediaCommandEnum.AutoAlign:
9139 if ((i + 1) < commandList.Length) 9656 if ((i + 1) < commandList.Length)
9140 { 9657 {
9141 if (commandList.Data[i + 1] is LSL_Integer) 9658 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9149,7 +9666,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9149 } 9666 }
9150 break; 9667 break;
9151 9668
9152 case ParcelMediaCommandEnum.Type: 9669 case (uint)ParcelMediaCommandEnum.Type:
9153 if ((i + 1) < commandList.Length) 9670 if ((i + 1) < commandList.Length)
9154 { 9671 {
9155 if (commandList.Data[i + 1] is LSL_String) 9672 if (commandList.Data[i + 1] is LSL_String)
@@ -9162,7 +9679,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9162 } 9679 }
9163 break; 9680 break;
9164 9681
9165 case ParcelMediaCommandEnum.Desc: 9682 case (uint)ParcelMediaCommandEnum.Desc:
9166 if ((i + 1) < commandList.Length) 9683 if ((i + 1) < commandList.Length)
9167 { 9684 {
9168 if (commandList.Data[i + 1] is LSL_String) 9685 if (commandList.Data[i + 1] is LSL_String)
@@ -9175,7 +9692,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9175 } 9692 }
9176 break; 9693 break;
9177 9694
9178 case ParcelMediaCommandEnum.Size: 9695 case (uint)ParcelMediaCommandEnum.Size:
9179 if ((i + 2) < commandList.Length) 9696 if ((i + 2) < commandList.Length)
9180 { 9697 {
9181 if (commandList.Data[i + 1] is LSL_Integer) 9698 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9245,7 +9762,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9245 } 9762 }
9246 } 9763 }
9247 9764
9248 if (commandToSend != null) 9765 if (commandToSend != 0)
9249 { 9766 {
9250 // the commandList contained a start/stop/... command, too 9767 // the commandList contained a start/stop/... command, too
9251 if (presence == null) 9768 if (presence == null)
@@ -9282,7 +9799,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9282 9799
9283 if (aList.Data[i] != null) 9800 if (aList.Data[i] != null)
9284 { 9801 {
9285 switch ((ParcelMediaCommandEnum) aList.Data[i]) 9802 switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
9286 { 9803 {
9287 case ParcelMediaCommandEnum.Url: 9804 case ParcelMediaCommandEnum.Url:
9288 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL)); 9805 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL));
@@ -9325,16 +9842,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9325 { 9842 {
9326 m_host.AddScriptLPS(1); 9843 m_host.AddScriptLPS(1);
9327 9844
9328 lock (m_host.TaskInventory) 9845 m_host.TaskInventory.LockItemsForRead(true);
9846 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
9329 { 9847 {
9330 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9848 if (inv.Value.Name == name)
9331 { 9849 {
9332 if (inv.Value.Name == name) 9850 m_host.TaskInventory.LockItemsForRead(false);
9333 { 9851 return inv.Value.Type;
9334 return inv.Value.Type;
9335 }
9336 } 9852 }
9337 } 9853 }
9854 m_host.TaskInventory.LockItemsForRead(false);
9338 9855
9339 return -1; 9856 return -1;
9340 } 9857 }
@@ -9345,15 +9862,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9345 9862
9346 if (quick_pay_buttons.Data.Length < 4) 9863 if (quick_pay_buttons.Data.Length < 4)
9347 { 9864 {
9348 LSLError("List must have at least 4 elements"); 9865 int x;
9349 return; 9866 for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
9867 {
9868 quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
9869 }
9350 } 9870 }
9351 m_host.ParentGroup.RootPart.PayPrice[0]=price; 9871 int[] nPrice = new int[5];
9352 9872 nPrice[0] = price;
9353 m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0]; 9873 nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
9354 m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1]; 9874 nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
9355 m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2]; 9875 nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
9356 m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3]; 9876 nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
9877 m_host.ParentGroup.RootPart.PayPrice = nPrice;
9357 m_host.ParentGroup.HasGroupChanged = true; 9878 m_host.ParentGroup.HasGroupChanged = true;
9358 } 9879 }
9359 9880
@@ -9365,17 +9886,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9365 if (invItemID == UUID.Zero) 9886 if (invItemID == UUID.Zero)
9366 return new LSL_Vector(); 9887 return new LSL_Vector();
9367 9888
9368 lock (m_host.TaskInventory) 9889 m_host.TaskInventory.LockItemsForRead(true);
9890 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
9369 { 9891 {
9370 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 9892 m_host.TaskInventory.LockItemsForRead(false);
9371 return new LSL_Vector(); 9893 return new LSL_Vector();
9894 }
9372 9895
9373 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 9896 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9374 { 9897 {
9375 ShoutError("No permissions to track the camera"); 9898 ShoutError("No permissions to track the camera");
9376 return new LSL_Vector(); 9899 m_host.TaskInventory.LockItemsForRead(false);
9377 } 9900 return new LSL_Vector();
9378 } 9901 }
9902 m_host.TaskInventory.LockItemsForRead(false);
9379 9903
9380 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 9904 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
9381 if (presence != null) 9905 if (presence != null)
@@ -9393,17 +9917,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9393 if (invItemID == UUID.Zero) 9917 if (invItemID == UUID.Zero)
9394 return new LSL_Rotation(); 9918 return new LSL_Rotation();
9395 9919
9396 lock (m_host.TaskInventory) 9920 m_host.TaskInventory.LockItemsForRead(true);
9921 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
9397 { 9922 {
9398 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 9923 m_host.TaskInventory.LockItemsForRead(false);
9399 return new LSL_Rotation(); 9924 return new LSL_Rotation();
9400
9401 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9402 {
9403 ShoutError("No permissions to track the camera");
9404 return new LSL_Rotation();
9405 }
9406 } 9925 }
9926 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9927 {
9928 ShoutError("No permissions to track the camera");
9929 m_host.TaskInventory.LockItemsForRead(false);
9930 return new LSL_Rotation();
9931 }
9932 m_host.TaskInventory.LockItemsForRead(false);
9407 9933
9408 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 9934 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
9409 if (presence != null) 9935 if (presence != null)
@@ -9465,8 +9991,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9465 { 9991 {
9466 m_host.AddScriptLPS(1); 9992 m_host.AddScriptLPS(1);
9467 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 9993 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0);
9468 if (detectedParams == null) return; // only works on the first detected avatar 9994 if (detectedParams == null)
9469 9995 {
9996 if (m_host.IsAttachment == true)
9997 {
9998 detectedParams = new DetectParams();
9999 detectedParams.Key = m_host.OwnerID;
10000 }
10001 else
10002 {
10003 return;
10004 }
10005 }
10006
9470 ScenePresence avatar = World.GetScenePresence(detectedParams.Key); 10007 ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
9471 if (avatar != null) 10008 if (avatar != null)
9472 { 10009 {
@@ -9474,6 +10011,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9474 new Vector3((float)pos.x, (float)pos.y, (float)pos.z), 10011 new Vector3((float)pos.x, (float)pos.y, (float)pos.z),
9475 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z)); 10012 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z));
9476 } 10013 }
10014
9477 ScriptSleep(1000); 10015 ScriptSleep(1000);
9478 } 10016 }
9479 10017
@@ -9566,14 +10104,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9566 if (objectID == UUID.Zero) return; 10104 if (objectID == UUID.Zero) return;
9567 10105
9568 UUID agentID; 10106 UUID agentID;
9569 lock (m_host.TaskInventory) 10107 m_host.TaskInventory.LockItemsForRead(true);
9570 { 10108 // we need the permission first, to know which avatar we want to set the camera for
9571 // we need the permission first, to know which avatar we want to set the camera for 10109 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9572 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9573 10110
9574 if (agentID == UUID.Zero) return; 10111 if (agentID == UUID.Zero)
9575 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 10112 {
10113 m_host.TaskInventory.LockItemsForRead(false);
10114 return;
10115 }
10116 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
10117 {
10118 m_host.TaskInventory.LockItemsForRead(false);
10119 return;
9576 } 10120 }
10121 m_host.TaskInventory.LockItemsForRead(false);
9577 10122
9578 ScenePresence presence = World.GetScenePresence(agentID); 10123 ScenePresence presence = World.GetScenePresence(agentID);
9579 10124
@@ -9582,12 +10127,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9582 10127
9583 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>(); 10128 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
9584 object[] data = rules.Data; 10129 object[] data = rules.Data;
9585 for (int i = 0; i < data.Length; ++i) { 10130 for (int i = 0; i < data.Length; ++i)
10131 {
9586 int type = Convert.ToInt32(data[i++].ToString()); 10132 int type = Convert.ToInt32(data[i++].ToString());
9587 if (i >= data.Length) break; // odd number of entries => ignore the last 10133 if (i >= data.Length) break; // odd number of entries => ignore the last
9588 10134
9589 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3) 10135 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
9590 switch (type) { 10136 switch (type)
10137 {
9591 case ScriptBaseClass.CAMERA_FOCUS: 10138 case ScriptBaseClass.CAMERA_FOCUS:
9592 case ScriptBaseClass.CAMERA_FOCUS_OFFSET: 10139 case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
9593 case ScriptBaseClass.CAMERA_POSITION: 10140 case ScriptBaseClass.CAMERA_POSITION:
@@ -9623,12 +10170,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9623 10170
9624 // we need the permission first, to know which avatar we want to clear the camera for 10171 // we need the permission first, to know which avatar we want to clear the camera for
9625 UUID agentID; 10172 UUID agentID;
9626 lock (m_host.TaskInventory) 10173 m_host.TaskInventory.LockItemsForRead(true);
10174 agentID = m_host.TaskInventory[invItemID].PermsGranter;
10175 if (agentID == UUID.Zero)
9627 { 10176 {
9628 agentID = m_host.TaskInventory[invItemID].PermsGranter; 10177 m_host.TaskInventory.LockItemsForRead(false);
9629 if (agentID == UUID.Zero) return; 10178 return;
9630 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
9631 } 10179 }
10180 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
10181 {
10182 m_host.TaskInventory.LockItemsForRead(false);
10183 return;
10184 }
10185 m_host.TaskInventory.LockItemsForRead(false);
9632 10186
9633 ScenePresence presence = World.GetScenePresence(agentID); 10187 ScenePresence presence = World.GetScenePresence(agentID);
9634 10188
@@ -9695,19 +10249,65 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9695 public LSL_String llXorBase64StringsCorrect(string str1, string str2) 10249 public LSL_String llXorBase64StringsCorrect(string str1, string str2)
9696 { 10250 {
9697 m_host.AddScriptLPS(1); 10251 m_host.AddScriptLPS(1);
9698 string ret = String.Empty; 10252
9699 string src1 = llBase64ToString(str1); 10253 if (str1 == String.Empty)
9700 string src2 = llBase64ToString(str2); 10254 return String.Empty;
9701 int c = 0; 10255 if (str2 == String.Empty)
9702 for (int i = 0; i < src1.Length; i++) 10256 return str1;
10257
10258 int len = str2.Length;
10259 if ((len % 4) != 0) // LL is EVIL!!!!
9703 { 10260 {
9704 ret += (char) (src1[i] ^ src2[c]); 10261 while (str2.EndsWith("="))
10262 str2 = str2.Substring(0, str2.Length - 1);
10263
10264 len = str2.Length;
10265 int mod = len % 4;
9705 10266
9706 c++; 10267 if (mod == 1)
9707 if (c >= src2.Length) 10268 str2 = str2.Substring(0, str2.Length - 1);
9708 c = 0; 10269 else if (mod == 2)
10270 str2 += "==";
10271 else if (mod == 3)
10272 str2 += "=";
10273 }
10274
10275 byte[] data1;
10276 byte[] data2;
10277 try
10278 {
10279 data1 = Convert.FromBase64String(str1);
10280 data2 = Convert.FromBase64String(str2);
10281 }
10282 catch (Exception)
10283 {
10284 return new LSL_String(String.Empty);
9709 } 10285 }
9710 return llStringToBase64(ret); 10286
10287 byte[] d2 = new Byte[data1.Length];
10288 int pos = 0;
10289
10290 if (data1.Length <= data2.Length)
10291 {
10292 Array.Copy(data2, 0, d2, 0, data1.Length);
10293 }
10294 else
10295 {
10296 while (pos < data1.Length)
10297 {
10298 len = data1.Length - pos;
10299 if (len > data2.Length)
10300 len = data2.Length;
10301
10302 Array.Copy(data2, 0, d2, pos, len);
10303 pos += len;
10304 }
10305 }
10306
10307 for (pos = 0 ; pos < data1.Length ; pos++ )
10308 data1[pos] ^= d2[pos];
10309
10310 return Convert.ToBase64String(data1);
9711 } 10311 }
9712 10312
9713 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body) 10313 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
@@ -9766,12 +10366,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9766 Regex r = new Regex(authregex); 10366 Regex r = new Regex(authregex);
9767 int[] gnums = r.GetGroupNumbers(); 10367 int[] gnums = r.GetGroupNumbers();
9768 Match m = r.Match(url); 10368 Match m = r.Match(url);
9769 if (m.Success) { 10369 if (m.Success)
9770 for (int i = 1; i < gnums.Length; i++) { 10370 {
10371 for (int i = 1; i < gnums.Length; i++)
10372 {
9771 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]]; 10373 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
9772 //CaptureCollection cc = g.Captures; 10374 //CaptureCollection cc = g.Captures;
9773 } 10375 }
9774 if (m.Groups.Count == 5) { 10376 if (m.Groups.Count == 5)
10377 {
9775 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString()))); 10378 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
9776 url = m.Groups[1].ToString() + m.Groups[4].ToString(); 10379 url = m.Groups[1].ToString() + m.Groups[4].ToString();
9777 } 10380 }
@@ -10088,15 +10691,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10088 10691
10089 internal UUID ScriptByName(string name) 10692 internal UUID ScriptByName(string name)
10090 { 10693 {
10091 lock (m_host.TaskInventory) 10694 m_host.TaskInventory.LockItemsForRead(true);
10695
10696 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
10092 { 10697 {
10093 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 10698 if (item.Type == 10 && item.Name == name)
10094 { 10699 {
10095 if (item.Type == 10 && item.Name == name) 10700 m_host.TaskInventory.LockItemsForRead(false);
10096 return item.ItemID; 10701 return item.ItemID;
10097 } 10702 }
10098 } 10703 }
10099 10704
10705 m_host.TaskInventory.LockItemsForRead(false);
10706
10100 return UUID.Zero; 10707 return UUID.Zero;
10101 } 10708 }
10102 10709
@@ -10137,6 +10744,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10137 { 10744 {
10138 m_host.AddScriptLPS(1); 10745 m_host.AddScriptLPS(1);
10139 10746
10747 //Clone is thread safe
10140 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 10748 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10141 10749
10142 UUID assetID = UUID.Zero; 10750 UUID assetID = UUID.Zero;
@@ -10199,6 +10807,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10199 { 10807 {
10200 m_host.AddScriptLPS(1); 10808 m_host.AddScriptLPS(1);
10201 10809
10810 //Clone is thread safe
10202 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 10811 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10203 10812
10204 UUID assetID = UUID.Zero; 10813 UUID assetID = UUID.Zero;
@@ -10278,6 +10887,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10278 10887
10279 return GetLinkPrimitiveParams(obj, rules); 10888 return GetLinkPrimitiveParams(obj, rules);
10280 } 10889 }
10890
10891 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
10892 {
10893 List<SceneObjectPart> parts = GetLinkParts(link);
10894 if (parts.Count < 1)
10895 return 0;
10896
10897 return GetNumberOfSides(parts[0]);
10898 }
10281 } 10899 }
10282 10900
10283 public class NotecardCache 10901 public class NotecardCache
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 64931d0..39e1a27 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()
@@ -831,18 +840,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
831 if (target != null) 840 if (target != null)
832 { 841 {
833 UUID animID=UUID.Zero; 842 UUID animID=UUID.Zero;
834 lock (m_host.TaskInventory) 843 m_host.TaskInventory.LockItemsForRead(true);
844 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
835 { 845 {
836 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 846 if (inv.Value.Name == animation)
837 { 847 {
838 if (inv.Value.Name == animation) 848 if (inv.Value.Type == (int)AssetType.Animation)
839 { 849 animID = inv.Value.AssetID;
840 if (inv.Value.Type == (int)AssetType.Animation) 850 continue;
841 animID = inv.Value.AssetID;
842 continue;
843 }
844 } 851 }
845 } 852 }
853 m_host.TaskInventory.LockItemsForRead(false);
846 if (animID == UUID.Zero) 854 if (animID == UUID.Zero)
847 target.Animator.AddAnimation(animation, m_host.UUID); 855 target.Animator.AddAnimation(animation, m_host.UUID);
848 else 856 else
@@ -864,18 +872,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
864 if (target != null) 872 if (target != null)
865 { 873 {
866 UUID animID=UUID.Zero; 874 UUID animID=UUID.Zero;
867 lock (m_host.TaskInventory) 875 m_host.TaskInventory.LockItemsForRead(true);
876 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
868 { 877 {
869 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 878 if (inv.Value.Name == animation)
870 { 879 {
871 if (inv.Value.Name == animation) 880 if (inv.Value.Type == (int)AssetType.Animation)
872 { 881 animID = inv.Value.AssetID;
873 if (inv.Value.Type == (int)AssetType.Animation) 882 continue;
874 animID = inv.Value.AssetID;
875 continue;
876 }
877 } 883 }
878 } 884 }
885 m_host.TaskInventory.LockItemsForRead(false);
879 886
880 if (animID == UUID.Zero) 887 if (animID == UUID.Zero)
881 target.Animator.RemoveAnimation(animation); 888 target.Animator.RemoveAnimation(animation);
@@ -1768,6 +1775,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1768 1775
1769 if (!UUID.TryParse(name, out assetID)) 1776 if (!UUID.TryParse(name, out assetID))
1770 { 1777 {
1778 m_host.TaskInventory.LockItemsForRead(true);
1771 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1779 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1772 { 1780 {
1773 if (item.Type == 7 && item.Name == name) 1781 if (item.Type == 7 && item.Name == name)
@@ -1775,6 +1783,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1775 assetID = item.AssetID; 1783 assetID = item.AssetID;
1776 } 1784 }
1777 } 1785 }
1786 m_host.TaskInventory.LockItemsForRead(false);
1778 } 1787 }
1779 1788
1780 if (assetID == UUID.Zero) 1789 if (assetID == UUID.Zero)
@@ -1821,6 +1830,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1821 1830
1822 if (!UUID.TryParse(name, out assetID)) 1831 if (!UUID.TryParse(name, out assetID))
1823 { 1832 {
1833 m_host.TaskInventory.LockItemsForRead(true);
1824 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1834 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1825 { 1835 {
1826 if (item.Type == 7 && item.Name == name) 1836 if (item.Type == 7 && item.Name == name)
@@ -1828,6 +1838,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1828 assetID = item.AssetID; 1838 assetID = item.AssetID;
1829 } 1839 }
1830 } 1840 }
1841 m_host.TaskInventory.LockItemsForRead(false);
1831 } 1842 }
1832 1843
1833 if (assetID == UUID.Zero) 1844 if (assetID == UUID.Zero)
@@ -1878,6 +1889,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1878 1889
1879 if (!UUID.TryParse(name, out assetID)) 1890 if (!UUID.TryParse(name, out assetID))
1880 { 1891 {
1892 m_host.TaskInventory.LockItemsForRead(true);
1881 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1893 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1882 { 1894 {
1883 if (item.Type == 7 && item.Name == name) 1895 if (item.Type == 7 && item.Name == name)
@@ -1885,6 +1897,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1885 assetID = item.AssetID; 1897 assetID = item.AssetID;
1886 } 1898 }
1887 } 1899 }
1900 m_host.TaskInventory.LockItemsForRead(false);
1888 } 1901 }
1889 1902
1890 if (assetID == UUID.Zero) 1903 if (assetID == UUID.Zero)
@@ -2364,9 +2377,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2364 { 2377 {
2365 if (avatar.IsChildAgent == false) 2378 if (avatar.IsChildAgent == false)
2366 { 2379 {
2367 result.Add(avatar.UUID); 2380 result.Add(new LSL_Key(avatar.UUID.ToString()));
2368 result.Add(avatar.AbsolutePosition); 2381 result.Add(new LSL_Vector(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, avatar.AbsolutePosition.Z));
2369 result.Add(avatar.Name); 2382 result.Add(new LSL_String(avatar.Name));
2370 } 2383 }
2371 } 2384 }
2372 }); 2385 });
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index fefbb35..c4f90d2 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
@@ -301,7 +301,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
301 float dy; 301 float dy;
302 float dz; 302 float dz;
303 303
304 Quaternion q = SensePoint.RotationOffset; 304// Quaternion q = SensePoint.RotationOffset;
305 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation!
305 if (SensePoint.ParentGroup.RootPart.IsAttachment) 306 if (SensePoint.ParentGroup.RootPart.IsAttachment)
306 { 307 {
307 // In attachments, the sensor cone always orients with the 308 // In attachments, the sensor cone always orients with the
@@ -309,6 +310,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
309 // in mouselook. 310 // in mouselook.
310 311
311 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar); 312 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar);
313 fromRegionPos = avatar.AbsolutePosition;
312 q = avatar.Rotation; 314 q = avatar.Rotation;
313 } 315 }
314 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 316 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
@@ -422,6 +424,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
422 SceneObjectPart SensePoint = ts.host; 424 SceneObjectPart SensePoint = ts.host;
423 Vector3 fromRegionPos = SensePoint.AbsolutePosition; 425 Vector3 fromRegionPos = SensePoint.AbsolutePosition;
424 Quaternion q = SensePoint.RotationOffset; 426 Quaternion q = SensePoint.RotationOffset;
427 if (SensePoint.ParentGroup.RootPart.IsAttachment)
428 {
429 // In attachments, the sensor cone always orients with the
430 // avatar rotation. This may include a nonzero elevation if
431 // in mouselook.
432
433 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar);
434 fromRegionPos = avatar.AbsolutePosition;
435 q = avatar.Rotation;
436 }
425 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 437 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); 438 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
427 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); 439 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/ICM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs
new file mode 100644
index 0000000..ab215f3
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ICM_Api.cs
@@ -0,0 +1,46 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Collections;
29using OpenSim.Region.ScriptEngine.Interfaces;
30
31using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
32using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
33using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
34using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
35using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
36using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
37using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
38
39namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
40{
41 public interface ICM_Api
42 {
43 string cmDetectedCountry(int num);
44 string cmGetAgentCountry(key key);
45 }
46}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
index 561e3b3..bae7d4b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
@@ -398,6 +398,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
398 LSL_Vector llWind(LSL_Vector offset); 398 LSL_Vector llWind(LSL_Vector offset);
399 LSL_String llXorBase64Strings(string str1, string str2); 399 LSL_String llXorBase64Strings(string str1, string str2);
400 LSL_String llXorBase64StringsCorrect(string str1, string str2); 400 LSL_String llXorBase64StringsCorrect(string str1, string str2);
401 LSL_Integer llGetLinkNumberOfSides(LSL_Integer link);
401 402
402 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 403 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
403 LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 404 LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 63007c6..c08ad3b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -83,7 +83,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
83 // Avatar Info Commands 83 // Avatar Info Commands
84 string osGetAgentIP(string agent); 84 string osGetAgentIP(string agent);
85 LSL_List osGetAgents(); 85 LSL_List osGetAgents();
86 86
87 // Teleport commands 87 // Teleport commands
88 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 88 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
89 void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 89 void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs
new file mode 100644
index 0000000..4132dfa
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs
@@ -0,0 +1,71 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Runtime.Remoting.Lifetime;
30using System.Threading;
31using System.Reflection;
32using System.Collections;
33using System.Collections.Generic;
34using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.ScriptEngine.Interfaces;
37using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
38using integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
39using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
40using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
41using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
42using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
43using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
44using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
45using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
46
47namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
48{
49 public partial class ScriptBaseClass : MarshalByRefObject
50 {
51 public ICM_Api m_CM_Functions;
52
53 public void ApiTypeCM(IScriptApi api)
54 {
55 if (!(api is ICM_Api))
56 return;
57
58 m_CM_Functions = (ICM_Api)api;
59 }
60
61 public string cmDetectedCountry(int num)
62 {
63 return m_CM_Functions.cmDetectedCountry(num);
64 }
65
66 public string cmGetAgentCountry(key key)
67 {
68 return m_CM_Functions.cmGetAgentCountry(key);
69 }
70 }
71}
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 b3c4d95..c31e5d3 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;
@@ -372,6 +373,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
372 public const int PRIM_SCULPT_TYPE_TORUS = 2; 373 public const int PRIM_SCULPT_TYPE_TORUS = 2;
373 public const int PRIM_SCULPT_TYPE_PLANE = 3; 374 public const int PRIM_SCULPT_TYPE_PLANE = 3;
374 public const int PRIM_SCULPT_TYPE_CYLINDER = 4; 375 public const int PRIM_SCULPT_TYPE_CYLINDER = 4;
376 public const int PRIM_SCULPT_FLAG_INVERT = 64;
377 public const int PRIM_SCULPT_FLAG_MIRROR = 128;
375 378
376 public const int MASK_BASE = 0; 379 public const int MASK_BASE = 0;
377 public const int MASK_OWNER = 1; 380 public const int MASK_OWNER = 1;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 451163f..7c26824 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();
@@ -1847,5 +1849,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1847 { 1849 {
1848 return m_LSL_Functions.llClearPrimMedia(face); 1850 return m_LSL_Functions.llClearPrimMedia(face);
1849 } 1851 }
1852
1853 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
1854 {
1855 return m_LSL_Functions.llGetLinkNumberOfSides(link);
1856 }
1850 } 1857 }
1851} 1858}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
index 143b497..2e27f16 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
@@ -72,9 +72,30 @@ 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
75 public void lsClearWindlightScene() 76 public void lsClearWindlightScene()
76 { 77 {
77 m_LS_Functions.lsClearWindlightScene(); 78 m_LS_Functions.lsClearWindlightScene();
78 } 79 }
80
81 public LSL_List cmGetWindlightScene(LSL_List rules)
82 {
83 return m_LS_Functions.lsGetWindlightScene(rules);
84 }
85
86 public int cmSetWindlightScene(LSL_List rules)
87 {
88 return m_LS_Functions.lsSetWindlightScene(rules);
89 }
90
91 public int cmSetWindlightSceneTargeted(LSL_List rules, key target)
92 {
93 return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target);
94 }
95
96 public void cmClearWindlightScene()
97 {
98 m_LS_Functions.lsClearWindlightScene();
99 }
79 } 100 }
80} 101}
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/Helpers.cs b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
index 3575889..e9edf6c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
@@ -35,6 +35,7 @@ using OpenMetaverse;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Region.CoreModules; 36using OpenSim.Region.CoreModules;
37using OpenSim.Region.Framework.Scenes; 37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces;
38 39
39namespace OpenSim.Region.ScriptEngine.Shared 40namespace OpenSim.Region.ScriptEngine.Shared
40{ 41{
@@ -95,6 +96,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
95 Type = 0; 96 Type = 0;
96 Velocity = new LSL_Types.Vector3(); 97 Velocity = new LSL_Types.Vector3();
97 initializeSurfaceTouch(); 98 initializeSurfaceTouch();
99 Country = String.Empty;
98 } 100 }
99 101
100 public UUID Key; 102 public UUID Key;
@@ -126,6 +128,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
126 private int touchFace; 128 private int touchFace;
127 public int TouchFace { get { return touchFace; } } 129 public int TouchFace { get { return touchFace; } }
128 130
131 public string Country;
132
129 // This can be done in two places including the constructor 133 // This can be done in two places including the constructor
130 // so be carefull what gets added here 134 // so be carefull what gets added here
131 private void initializeSurfaceTouch() 135 private void initializeSurfaceTouch()
@@ -173,6 +177,10 @@ namespace OpenSim.Region.ScriptEngine.Shared
173 return; 177 return;
174 178
175 Name = presence.Firstname + " " + presence.Lastname; 179 Name = presence.Firstname + " " + presence.Lastname;
180 UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, Key);
181 if (account != null)
182 Country = account.UserCountry;
183
176 Owner = Key; 184 Owner = Key;
177 Position = new LSL_Types.Vector3( 185 Position = new LSL_Types.Vector3(
178 presence.AbsolutePosition.X, 186 presence.AbsolutePosition.X,
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 783791f..9548253 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;
@@ -55,7 +56,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
55{ 56{
56 public class ScriptInstance : MarshalByRefObject, IScriptInstance 57 public class ScriptInstance : MarshalByRefObject, IScriptInstance
57 { 58 {
58 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 59 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
59 60
60 private IScriptEngine m_Engine; 61 private IScriptEngine m_Engine;
61 private IScriptWorkItem m_CurrentResult = null; 62 private IScriptWorkItem m_CurrentResult = null;
@@ -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();
@@ -271,9 +271,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
271 //RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass); 271 //RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass);
272// lease.Register(this); 272// lease.Register(this);
273 } 273 }
274 catch (Exception) 274 catch (Exception e)
275 { 275 {
276 // m_log.ErrorFormat("[Script] Error loading assembly {0}\n"+e.ToString(), assembly); 276 m_log.ErrorFormat("[Script] Error loading assembly {0}\n"+e.ToString(), assembly);
277 throw;
277 } 278 }
278 279
279 try 280 try
@@ -434,14 +435,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
434 { 435 {
435 int permsMask; 436 int permsMask;
436 UUID permsGranter; 437 UUID permsGranter;
437 lock (part.TaskInventory) 438 part.TaskInventory.LockItemsForRead(true);
439 if (!part.TaskInventory.ContainsKey(m_ItemID))
438 { 440 {
439 if (!part.TaskInventory.ContainsKey(m_ItemID)) 441 part.TaskInventory.LockItemsForRead(false);
440 return; 442 return;
441
442 permsGranter = part.TaskInventory[m_ItemID].PermsGranter;
443 permsMask = part.TaskInventory[m_ItemID].PermsMask;
444 } 443 }
444 permsGranter = part.TaskInventory[m_ItemID].PermsGranter;
445 permsMask = part.TaskInventory[m_ItemID].PermsMask;
446 part.TaskInventory.LockItemsForRead(false);
445 447
446 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 448 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
447 { 449 {
@@ -550,6 +552,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
550 return true; 552 return true;
551 } 553 }
552 554
555 [DebuggerNonUserCode] //Prevents the debugger from farting in this function
553 public void SetState(string state) 556 public void SetState(string state)
554 { 557 {
555 if (state == State) 558 if (state == State)
@@ -561,7 +564,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
561 new DetectParams[0])); 564 new DetectParams[0]));
562 PostEvent(new EventParams("state_entry", new Object[0], 565 PostEvent(new EventParams("state_entry", new Object[0],
563 new DetectParams[0])); 566 new DetectParams[0]));
564 567
565 throw new EventAbortException(); 568 throw new EventAbortException();
566 } 569 }
567 570
@@ -644,14 +647,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
644 /// <returns></returns> 647 /// <returns></returns>
645 public object EventProcessor() 648 public object EventProcessor()
646 { 649 {
647 if (m_Suspended) 650 EventParams data = null;
648 return 0;
649 651
650 lock (m_Script) 652 lock (m_EventQueue)
651 { 653 {
652 EventParams data = null; 654 if (m_Suspended)
655 return 0;
653 656
654 lock (m_EventQueue) 657 lock (m_Script)
655 { 658 {
656 data = (EventParams) m_EventQueue.Dequeue(); 659 data = (EventParams) m_EventQueue.Dequeue();
657 if (data == null) // Shouldn't happen 660 if (data == null) // Shouldn't happen
@@ -677,6 +680,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
677 if (data.EventName == "collision") 680 if (data.EventName == "collision")
678 m_CollisionInQueue = false; 681 m_CollisionInQueue = false;
679 } 682 }
683 }
684 lock(m_Script)
685 {
680 686
681 //m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this); 687 //m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this);
682 688
@@ -833,6 +839,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
833 new Object[0], new DetectParams[0])); 839 new Object[0], new DetectParams[0]));
834 } 840 }
835 841
842 [DebuggerNonUserCode] //Stops the VS debugger from farting in this function
836 public void ApiResetScript() 843 public void ApiResetScript()
837 { 844 {
838 // bool running = Running; 845 // bool running = Running;
@@ -864,10 +871,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
864 871
865 public Dictionary<string, object> GetVars() 872 public Dictionary<string, object> GetVars()
866 { 873 {
867 if (m_Script != null) 874 return m_Script.GetVars();
868 return m_Script.GetVars();
869 else
870 return new Dictionary<string, object>();
871 } 875 }
872 876
873 public void SetVars(Dictionary<string, object> vars) 877 public void SetVars(Dictionary<string, object> vars)
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 298d664..665f4a6 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
@@ -459,6 +459,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
459 size += 64; 459 size += 64;
460 else if (o is int) 460 else if (o is int)
461 size += 4; 461 size += 4;
462 else if (o is uint)
463 size += 4;
462 else if (o is string) 464 else if (o is string)
463 size += ((string)o).Length; 465 size += ((string)o).Length;
464 else if (o is float) 466 else if (o is float)
@@ -613,24 +615,16 @@ namespace OpenSim.Region.ScriptEngine.Shared
613 615
614 public static bool operator ==(list a, list b) 616 public static bool operator ==(list a, list b)
615 { 617 {
616 int la = -1; 618 int la = a.Length;
617 int lb = -1; 619 int lb = b.Length;
618 try { la = a.Length; }
619 catch (NullReferenceException) { }
620 try { lb = b.Length; }
621 catch (NullReferenceException) { }
622 620
623 return la == lb; 621 return la == lb;
624 } 622 }
625 623
626 public static bool operator !=(list a, list b) 624 public static bool operator !=(list a, list b)
627 { 625 {
628 int la = -1; 626 int la = a.Length;
629 int lb = -1; 627 int lb = b.Length;
630 try { la = a.Length; }
631 catch (NullReferenceException) { }
632 try {lb = b.Length;}
633 catch (NullReferenceException) { }
634 628
635 return la != lb; 629 return la != lb;
636 } 630 }
@@ -1064,7 +1058,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1064 { 1058 {
1065 list ret = new list(); 1059 list ret = new list();
1066 double entry; 1060 double entry;
1067 for (int i = 0; i < src.Data.Length - 1; i++) 1061 for (int i = 0; i < src.Data.Length; i++)
1068 { 1062 {
1069 if (double.TryParse(src.Data[i].ToString(), NumberStyles.Float, Culture.NumberFormatInfo, out entry)) 1063 if (double.TryParse(src.Data[i].ToString(), NumberStyles.Float, Culture.NumberFormatInfo, out entry))
1070 { 1064 {
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 8629674..6bdd4c8 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;
@@ -103,6 +104,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
103 private Dictionary<UUID, IScriptInstance> m_Scripts = 104 private Dictionary<UUID, IScriptInstance> m_Scripts =
104 new Dictionary<UUID, IScriptInstance>(); 105 new Dictionary<UUID, IScriptInstance>();
105 106
107 private OpenMetaverse.ReaderWriterLockSlim m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
108
106 // Maps the asset ID to the assembly 109 // Maps the asset ID to the assembly
107 110
108 private Dictionary<UUID, string> m_Assemblies = 111 private Dictionary<UUID, string> m_Assemblies =
@@ -125,6 +128,71 @@ namespace OpenSim.Region.ScriptEngine.XEngine
125 IWorkItemResult m_CurrentCompile = null; 128 IWorkItemResult m_CurrentCompile = null;
126 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>(); 129 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>();
127 130
131 private void lockScriptsForRead(bool locked)
132 {
133 if (locked)
134 {
135 if (m_scriptsLock.RecursiveReadCount > 0)
136 {
137 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.");
138 m_scriptsLock.ExitReadLock();
139 }
140 if (m_scriptsLock.RecursiveWriteCount > 0)
141 {
142 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
143 m_scriptsLock.ExitWriteLock();
144 }
145
146 while (!m_scriptsLock.TryEnterReadLock(60000))
147 {
148 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.");
149 if (m_scriptsLock.IsWriteLockHeld)
150 {
151 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
152 }
153 }
154 }
155 else
156 {
157 if (m_scriptsLock.RecursiveReadCount > 0)
158 {
159 m_scriptsLock.ExitReadLock();
160 }
161 }
162 }
163 private void lockScriptsForWrite(bool locked)
164 {
165 if (locked)
166 {
167 if (m_scriptsLock.RecursiveReadCount > 0)
168 {
169 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.");
170 m_scriptsLock.ExitReadLock();
171 }
172 if (m_scriptsLock.RecursiveWriteCount > 0)
173 {
174 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
175 m_scriptsLock.ExitWriteLock();
176 }
177
178 while (!m_scriptsLock.TryEnterWriteLock(60000))
179 {
180 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.");
181 if (m_scriptsLock.IsWriteLockHeld)
182 {
183 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
184 }
185 }
186 }
187 else
188 {
189 if (m_scriptsLock.RecursiveWriteCount > 0)
190 {
191 m_scriptsLock.ExitWriteLock();
192 }
193 }
194 }
195
128 public string ScriptEngineName 196 public string ScriptEngineName
129 { 197 {
130 get { return "XEngine"; } 198 get { return "XEngine"; }
@@ -270,43 +338,45 @@ namespace OpenSim.Region.ScriptEngine.XEngine
270 338
271 public void RemoveRegion(Scene scene) 339 public void RemoveRegion(Scene scene)
272 { 340 {
273 lock (m_Scripts) 341 lockScriptsForRead(true);
342 foreach (IScriptInstance instance in m_Scripts.Values)
274 { 343 {
275 foreach (IScriptInstance instance in m_Scripts.Values) 344 // Force a final state save
345 //
346 if (m_Assemblies.ContainsKey(instance.AssetID))
276 { 347 {
277 // Force a final state save 348 string assembly = m_Assemblies[instance.AssetID];
278 // 349 instance.SaveState(assembly);
279 if (m_Assemblies.ContainsKey(instance.AssetID)) 350 }
280 {
281 string assembly = m_Assemblies[instance.AssetID];
282 instance.SaveState(assembly);
283 }
284 351
285 // Clear the event queue and abort the instance thread 352 // Clear the event queue and abort the instance thread
286 // 353 //
287 instance.ClearQueue(); 354 instance.ClearQueue();
288 instance.Stop(0); 355 instance.Stop(0);
289 356
290 // Release events, timer, etc 357 // Release events, timer, etc
291 // 358 //
292 instance.DestroyScriptInstance(); 359 instance.DestroyScriptInstance();
293 360
294 // Unload scripts and app domains 361 // Unload scripts and app domains
295 // Must be done explicitly because they have infinite 362 // Must be done explicitly because they have infinite
296 // lifetime 363 // lifetime
297 // 364 //
298 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 365 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
299 if (m_DomainScripts[instance.AppDomain].Count == 0) 366 if (m_DomainScripts[instance.AppDomain].Count == 0)
300 { 367 {
301 m_DomainScripts.Remove(instance.AppDomain); 368 m_DomainScripts.Remove(instance.AppDomain);
302 UnloadAppDomain(instance.AppDomain); 369 UnloadAppDomain(instance.AppDomain);
303 }
304 } 370 }
305 m_Scripts.Clear();
306 m_PrimObjects.Clear();
307 m_Assemblies.Clear();
308 m_DomainScripts.Clear();
309 } 371 }
372 lockScriptsForRead(false);
373 lockScriptsForWrite(true);
374 m_Scripts.Clear();
375 lockScriptsForWrite(false);
376 m_PrimObjects.Clear();
377 m_Assemblies.Clear();
378 m_DomainScripts.Clear();
379
310 lock (m_ScriptEngines) 380 lock (m_ScriptEngines)
311 { 381 {
312 m_ScriptEngines.Remove(this); 382 m_ScriptEngines.Remove(this);
@@ -365,22 +435,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine
365 435
366 List<IScriptInstance> instances = new List<IScriptInstance>(); 436 List<IScriptInstance> instances = new List<IScriptInstance>();
367 437
368 lock (m_Scripts) 438 lockScriptsForRead(true);
369 { 439 foreach (IScriptInstance instance in m_Scripts.Values)
370 foreach (IScriptInstance instance in m_Scripts.Values)
371 instances.Add(instance); 440 instances.Add(instance);
372 } 441 lockScriptsForRead(false);
373 442
374 foreach (IScriptInstance i in instances) 443 foreach (IScriptInstance i in instances)
375 { 444 {
376 string assembly = String.Empty; 445 string assembly = String.Empty;
377 446
378 lock (m_Scripts) 447
379 {
380 if (!m_Assemblies.ContainsKey(i.AssetID)) 448 if (!m_Assemblies.ContainsKey(i.AssetID))
381 continue; 449 continue;
382 assembly = m_Assemblies[i.AssetID]; 450 assembly = m_Assemblies[i.AssetID];
383 } 451
384 452
385 i.SaveState(assembly); 453 i.SaveState(assembly);
386 } 454 }
@@ -709,92 +777,95 @@ namespace OpenSim.Region.ScriptEngine.XEngine
709 } 777 }
710 778
711 ScriptInstance instance = null; 779 ScriptInstance instance = null;
712 lock (m_Scripts) 780 // Create the object record
781 lockScriptsForRead(true);
782 if ((!m_Scripts.ContainsKey(itemID)) ||
783 (m_Scripts[itemID].AssetID != assetID))
713 { 784 {
714 // Create the object record 785 lockScriptsForRead(false);
715 786
716 if ((!m_Scripts.ContainsKey(itemID)) || 787 UUID appDomain = assetID;
717 (m_Scripts[itemID].AssetID != assetID))
718 {
719 UUID appDomain = assetID;
720 788
721 if (part.ParentGroup.IsAttachment) 789 if (part.ParentGroup.IsAttachment)
722 appDomain = part.ParentGroup.RootPart.UUID; 790 appDomain = part.ParentGroup.RootPart.UUID;
723 791
724 if (!m_AppDomains.ContainsKey(appDomain)) 792 if (!m_AppDomains.ContainsKey(appDomain))
793 {
794 try
725 { 795 {
726 try 796 AppDomainSetup appSetup = new AppDomainSetup();
727 { 797 appSetup.PrivateBinPath = Path.Combine(
728 AppDomainSetup appSetup = new AppDomainSetup(); 798 m_ScriptEnginesPath,
729 appSetup.PrivateBinPath = Path.Combine( 799 m_Scene.RegionInfo.RegionID.ToString());
730 m_ScriptEnginesPath, 800
731 m_Scene.RegionInfo.RegionID.ToString()); 801 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
732 802 Evidence evidence = new Evidence(baseEvidence);
733 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; 803
734 Evidence evidence = new Evidence(baseEvidence); 804 AppDomain sandbox;
735 805 if (m_AppDomainLoading)
736 AppDomain sandbox; 806 sandbox = AppDomain.CreateDomain(
737 if (m_AppDomainLoading) 807 m_Scene.RegionInfo.RegionID.ToString(),
738 sandbox = AppDomain.CreateDomain( 808 evidence, appSetup);
739 m_Scene.RegionInfo.RegionID.ToString(), 809 else
740 evidence, appSetup); 810 sandbox = AppDomain.CurrentDomain;
741 else 811
742 sandbox = AppDomain.CurrentDomain; 812 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
743 813 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
744 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); 814 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet");
745 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); 815 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet);
746 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); 816 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement);
747 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); 817 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup;
748 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); 818 //sandbox.SetAppDomainPolicy(sandboxPolicy);
749 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup; 819
750 //sandbox.SetAppDomainPolicy(sandboxPolicy); 820 m_AppDomains[appDomain] = sandbox;
751 821
752 m_AppDomains[appDomain] = sandbox; 822 m_AppDomains[appDomain].AssemblyResolve +=
753 823 new ResolveEventHandler(
754 m_AppDomains[appDomain].AssemblyResolve += 824 AssemblyResolver.OnAssemblyResolve);
755 new ResolveEventHandler( 825 m_DomainScripts[appDomain] = new List<UUID>();
756 AssemblyResolver.OnAssemblyResolve); 826 }
757 m_DomainScripts[appDomain] = new List<UUID>(); 827 catch (Exception e)
758 } 828 {
759 catch (Exception e) 829 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
830 m_ScriptErrorMessage += "Exception creating app domain:\n";
831 m_ScriptFailCount++;
832 lock (m_AddingAssemblies)
760 { 833 {
761 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString()); 834 m_AddingAssemblies[assembly]--;
762 m_ScriptErrorMessage += "Exception creating app domain:\n";
763 m_ScriptFailCount++;
764 lock (m_AddingAssemblies)
765 {
766 m_AddingAssemblies[assembly]--;
767 }
768 return false;
769 } 835 }
836 return false;
770 } 837 }
771 m_DomainScripts[appDomain].Add(itemID); 838 }
772 839 m_DomainScripts[appDomain].Add(itemID);
773 instance = new ScriptInstance(this, part, 840
774 itemID, assetID, assembly, 841 instance = new ScriptInstance(this, part,
775 m_AppDomains[appDomain], 842 itemID, assetID, assembly,
776 part.ParentGroup.RootPart.Name, 843 m_AppDomains[appDomain],
777 item.Name, startParam, postOnRez, 844 part.ParentGroup.RootPart.Name,
778 stateSource, m_MaxScriptQueue); 845 item.Name, startParam, postOnRez,
779 846 stateSource, m_MaxScriptQueue);
780 m_log.DebugFormat( 847
848 m_log.DebugFormat(
781 "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}", 849 "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}",
782 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, 850 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID,
783 part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName); 851 part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName);
784 852
785 if (presence != null) 853 if (presence != null)
786 { 854 {
787 ShowScriptSaveResponse(item.OwnerID, 855 ShowScriptSaveResponse(item.OwnerID,
788 assetID, "Compile successful", true); 856 assetID, "Compile successful", true);
789 }
790
791 instance.AppDomain = appDomain;
792 instance.LineMap = linemap;
793
794 m_Scripts[itemID] = instance;
795 } 857 }
796 }
797 858
859 instance.AppDomain = appDomain;
860 instance.LineMap = linemap;
861 lockScriptsForWrite(true);
862 m_Scripts[itemID] = instance;
863 lockScriptsForWrite(false);
864 }
865 else
866 {
867 lockScriptsForRead(false);
868 }
798 lock (m_PrimObjects) 869 lock (m_PrimObjects)
799 { 870 {
800 if (!m_PrimObjects.ContainsKey(localID)) 871 if (!m_PrimObjects.ContainsKey(localID))
@@ -813,9 +884,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
813 m_AddingAssemblies[assembly]--; 884 m_AddingAssemblies[assembly]--;
814 } 885 }
815 886
816 if (instance != null) 887 if (instance!=null)
817 instance.Init(); 888 instance.Init();
818 889
819 return true; 890 return true;
820 } 891 }
821 892
@@ -828,20 +899,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine
828 m_CompileDict.Remove(itemID); 899 m_CompileDict.Remove(itemID);
829 } 900 }
830 901
831 IScriptInstance instance = null; 902 lockScriptsForRead(true);
832 903 // Do we even have it?
833 lock (m_Scripts) 904 if (!m_Scripts.ContainsKey(itemID))
834 { 905 {
835 // Do we even have it? 906 lockScriptsForRead(false);
836 if (!m_Scripts.ContainsKey(itemID)) 907 return;
837 return;
838
839 instance=m_Scripts[itemID];
840 m_Scripts.Remove(itemID);
841 } 908 }
909
842 910
911 IScriptInstance instance=m_Scripts[itemID];
912 lockScriptsForRead(false);
913 lockScriptsForWrite(true);
914 m_Scripts.Remove(itemID);
915 lockScriptsForWrite(false);
843 instance.ClearQueue(); 916 instance.ClearQueue();
844 instance.Stop(0); 917 instance.Stop(0);
918
845// bool objectRemoved = false; 919// bool objectRemoved = false;
846 920
847 lock (m_PrimObjects) 921 lock (m_PrimObjects)
@@ -877,11 +951,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
877 ObjectRemoved handlerObjectRemoved = OnObjectRemoved; 951 ObjectRemoved handlerObjectRemoved = OnObjectRemoved;
878 if (handlerObjectRemoved != null) 952 if (handlerObjectRemoved != null)
879 { 953 {
880 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID); 954 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID);
881 handlerObjectRemoved(part.UUID); 955 handlerObjectRemoved(part.UUID);
882 } 956 }
883 957
884 958 CleanAssemblies();
959
885 ScriptRemoved handlerScriptRemoved = OnScriptRemoved; 960 ScriptRemoved handlerScriptRemoved = OnScriptRemoved;
886 if (handlerScriptRemoved != null) 961 if (handlerScriptRemoved != null)
887 handlerScriptRemoved(itemID); 962 handlerScriptRemoved(itemID);
@@ -1023,7 +1098,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1023 return false; 1098 return false;
1024 1099
1025 uuids = m_PrimObjects[localID]; 1100 uuids = m_PrimObjects[localID];
1026 } 1101
1027 1102
1028 foreach (UUID itemID in uuids) 1103 foreach (UUID itemID in uuids)
1029 { 1104 {
@@ -1041,6 +1116,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1041 result = true; 1116 result = true;
1042 } 1117 }
1043 } 1118 }
1119 }
1044 1120
1045 return result; 1121 return result;
1046 } 1122 }
@@ -1140,12 +1216,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1140 private IScriptInstance GetInstance(UUID itemID) 1216 private IScriptInstance GetInstance(UUID itemID)
1141 { 1217 {
1142 IScriptInstance instance; 1218 IScriptInstance instance;
1143 lock (m_Scripts) 1219 lockScriptsForRead(true);
1220 if (!m_Scripts.ContainsKey(itemID))
1144 { 1221 {
1145 if (!m_Scripts.ContainsKey(itemID)) 1222 lockScriptsForRead(false);
1146 return null; 1223 return null;
1147 instance = m_Scripts[itemID];
1148 } 1224 }
1225 instance = m_Scripts[itemID];
1226 lockScriptsForRead(false);
1149 return instance; 1227 return instance;
1150 } 1228 }
1151 1229
@@ -1169,6 +1247,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1169 return false; 1247 return false;
1170 } 1248 }
1171 1249
1250 [DebuggerNonUserCode]
1172 public void ApiResetScript(UUID itemID) 1251 public void ApiResetScript(UUID itemID)
1173 { 1252 {
1174 IScriptInstance instance = GetInstance(itemID); 1253 IScriptInstance instance = GetInstance(itemID);
@@ -1220,6 +1299,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1220 return UUID.Zero; 1299 return UUID.Zero;
1221 } 1300 }
1222 1301
1302 [DebuggerNonUserCode]
1223 public void SetState(UUID itemID, string newState) 1303 public void SetState(UUID itemID, string newState)
1224 { 1304 {
1225 IScriptInstance instance = GetInstance(itemID); 1305 IScriptInstance instance = GetInstance(itemID);
@@ -1240,11 +1320,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1240 { 1320 {
1241 List<IScriptInstance> instances = new List<IScriptInstance>(); 1321 List<IScriptInstance> instances = new List<IScriptInstance>();
1242 1322
1243 lock (m_Scripts) 1323 lockScriptsForRead(true);
1244 { 1324 foreach (IScriptInstance instance in m_Scripts.Values)
1245 foreach (IScriptInstance instance in m_Scripts.Values)
1246 instances.Add(instance); 1325 instances.Add(instance);
1247 } 1326 lockScriptsForRead(false);
1248 1327
1249 foreach (IScriptInstance i in instances) 1328 foreach (IScriptInstance i in instances)
1250 { 1329 {
@@ -1616,5 +1695,17 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1616 1695
1617 instance.Resume(); 1696 instance.Resume();
1618 } 1697 }
1698
1699 public bool HasScript(UUID itemID, out bool running)
1700 {
1701 running = true;
1702
1703 IScriptInstance instance = GetInstance(itemID);
1704 if (instance == null)
1705 return false;
1706
1707 running = instance.Running;
1708 return true;
1709 }
1619 } 1710 }
1620} 1711}