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.cs2143
-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.cs2
-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.cs6
-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, 2016 insertions, 966 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 aa28fa0..cda8adb 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())
351 {
352 m_host.TaskInventory.LockItemsForRead(true);
353 unlock = true;
354 }
355 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
293 { 356 {
294 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 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).
486 555
487 public LSL_Vector llRot2Euler(LSL_Rotation r) 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 }
568
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 {
@@ -1932,10 +2113,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1932 return end; 2113 return end;
1933 } 2114 }
1934 2115
1935 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos) 2116 protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos)
1936 { 2117 {
2118 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2119 return fromPos;
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
1939 2123
1940 float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y); 2124 float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
1941 bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true); 2125 bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
@@ -1944,14 +2128,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1944 { 2128 {
1945 if ((targetPos.z < ground) && disable_underground_movement && m_host.AttachmentPoint == 0) 2129 if ((targetPos.z < ground) && disable_underground_movement && m_host.AttachmentPoint == 0)
1946 targetPos.z = ground; 2130 targetPos.z = ground;
2131 }
2132 LSL_Vector real_vec = SetPosAdjust(fromPos, targetPos);
2133
2134 return real_vec;
2135 }
2136
2137 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos)
2138 {
2139 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2140 return;
2141
2142 LSL_Vector currentPos = GetPartLocalPos(part);
2143 LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos);
2144
2145 if (part.ParentGroup.RootPart == part)
2146 {
1947 SceneObjectGroup parent = part.ParentGroup; 2147 SceneObjectGroup parent = part.ParentGroup;
1948 LSL_Vector real_vec = SetPosAdjust(currentPos, targetPos); 2148 parent.UpdateGroupPosition(new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z));
1949 parent.UpdateGroupPosition(new Vector3((float)real_vec.x, (float)real_vec.y, (float)real_vec.z));
1950 } 2149 }
1951 else 2150 else
1952 { 2151 {
1953 LSL_Vector rel_vec = SetPosAdjust(currentPos, targetPos); 2152 part.OffsetPosition = new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z);
1954 part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z);
1955 SceneObjectGroup parent = part.ParentGroup; 2153 SceneObjectGroup parent = part.ParentGroup;
1956 parent.HasGroupChanged = true; 2154 parent.HasGroupChanged = true;
1957 parent.ScheduleGroupForTerseUpdate(); 2155 parent.ScheduleGroupForTerseUpdate();
@@ -2002,9 +2200,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2002 m_host.AddScriptLPS(1); 2200 m_host.AddScriptLPS(1);
2003 2201
2004 // try to let this work as in SL... 2202 // try to let this work as in SL...
2005 if (m_host.ParentID == 0) 2203 if (m_host.LinkNum < 2)
2006 { 2204 {
2007 // special case: If we are root, rotate complete SOG to new rotation 2205 // Special case: If we are root, rotate complete SOG to new
2206 // rotation.
2207 // We are root if the link number is 0 (single prim) or 1
2208 // (root prim). ParentID may be nonzero in attachments and
2209 // using it would cause attachments and HUDs to rotate
2210 // to the wrong positions.
2008 SetRot(m_host, Rot2Quaternion(rot)); 2211 SetRot(m_host, Rot2Quaternion(rot));
2009 } 2212 }
2010 else 2213 else
@@ -2033,6 +2236,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2033 2236
2034 protected void SetRot(SceneObjectPart part, Quaternion rot) 2237 protected void SetRot(SceneObjectPart part, Quaternion rot)
2035 { 2238 {
2239 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2240 return;
2241
2036 part.UpdateRotation(rot); 2242 part.UpdateRotation(rot);
2037 // Update rotation does not move the object in the physics scene if it's a linkset. 2243 // Update rotation does not move the object in the physics scene if it's a linkset.
2038 2244
@@ -2652,12 +2858,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2652 2858
2653 m_host.AddScriptLPS(1); 2859 m_host.AddScriptLPS(1);
2654 2860
2861 m_host.TaskInventory.LockItemsForRead(true);
2655 TaskInventoryItem item = m_host.TaskInventory[invItemID]; 2862 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2656 2863 m_host.TaskInventory.LockItemsForRead(false);
2657 lock (m_host.TaskInventory)
2658 {
2659 item = m_host.TaskInventory[invItemID];
2660 }
2661 2864
2662 if (item.PermsGranter == UUID.Zero) 2865 if (item.PermsGranter == UUID.Zero)
2663 return 0; 2866 return 0;
@@ -2732,6 +2935,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2732 if (dist > m_ScriptDistanceFactor * 10.0f) 2935 if (dist > m_ScriptDistanceFactor * 10.0f)
2733 return; 2936 return;
2734 2937
2938 //Clone is thread-safe
2735 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 2939 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
2736 2940
2737 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory) 2941 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory)
@@ -2794,6 +2998,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2794 2998
2795 public void llLookAt(LSL_Vector target, double strength, double damping) 2999 public void llLookAt(LSL_Vector target, double strength, double damping)
2796 { 3000 {
3001 /*
2797 m_host.AddScriptLPS(1); 3002 m_host.AddScriptLPS(1);
2798 // Determine where we are looking from 3003 // Determine where we are looking from
2799 LSL_Vector from = llGetPos(); 3004 LSL_Vector from = llGetPos();
@@ -2813,10 +3018,54 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2813 // the angles of rotation in radians into rotation value 3018 // the angles of rotation in radians into rotation value
2814 3019
2815 LSL_Types.Quaternion rot = llEuler2Rot(angle); 3020 LSL_Types.Quaternion rot = llEuler2Rot(angle);
2816 Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s); 3021
2817 m_host.startLookAt(rotation, (float)damping, (float)strength); 3022 // This would only work if your physics system contains an APID controller:
3023 // Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
3024 // m_host.startLookAt(rotation, (float)damping, (float)strength);
3025
2818 // Orient the object to the angle calculated 3026 // Orient the object to the angle calculated
2819 //llSetRot(rot); 3027 llSetRot(rot);
3028 */
3029
3030 //The above code, while nice, doesn't replicate the behaviour of SL and tends to "roll" the object.
3031 //There's probably a smarter way of doing this, my rotation math-fu is weak.
3032 // http://bugs.meta7.com/view.php?id=28
3033 // - Tom
3034
3035 /* And the following does not do the job either. It has to be performed inside the ODE glue-code. -.- .._.
3036 LSL_Rotation newrot = llGetRot() * llRotBetween(new LSL_Vector(1.0d, 0.0d, 0.0d) * llGetRot(), new LSL_Vector(0.0d, 0.0d, -1.0d));
3037 llSetRot(newrot * llRotBetween(new LSL_Vector(0.0d,0.0d,1.0d) * newrot, target - llGetPos()));
3038 */
3039 if (m_host.PhysActor != null && !m_host.PhysActor.IsPhysical)
3040 {
3041 // Part is non-phys, convert this to a llSetRot()
3042 Vector3 tgt = new Vector3((float)target.x, (float)target.y, (float)target.z);
3043 Vector3 dir = tgt - m_host.GroupPosition;
3044 dir.Normalize();
3045 float tzrot = (float)Math.Atan2(dir.Y, dir.X);
3046 float txy = (float)Math.Sqrt((dir.X * dir.X) + (dir.Y * dir.Y));
3047 float terot = (float)Math.Atan2(-dir.Z, txy);
3048 LSL_Vector az = new LSL_Vector(0.0f, 0.0f, tzrot);
3049 LSL_Vector ae = new LSL_Vector(0.0f, terot, 0.0f);
3050 LSL_Types.Quaternion spin = llEuler2Rot(az);
3051 LSL_Types.Quaternion rot = llEuler2Rot(ae) * spin;
3052 llSetRot(rot);
3053 }
3054 else
3055 {
3056 // Physical, send the target vector to RotLookAt method inside a 'rotation', the .w -99.9 value indicates it is really a LookAt.
3057 Quaternion q = new Quaternion((float)target.x, (float)target.y, (float)target.z, -99.9f);
3058 m_host.RotLookAt(q, (float)strength, (float)damping);
3059 }
3060
3061 }
3062
3063 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3064 {
3065 m_host.AddScriptLPS(1);
3066// NotImplemented("llRotLookAt");
3067 m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping);
3068
2820 } 3069 }
2821 3070
2822 public void llStopLookAt() 3071 public void llStopLookAt()
@@ -2865,13 +3114,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2865 { 3114 {
2866 TaskInventoryItem item; 3115 TaskInventoryItem item;
2867 3116
2868 lock (m_host.TaskInventory) 3117 m_host.TaskInventory.LockItemsForRead(true);
3118 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2869 { 3119 {
2870 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3120 m_host.TaskInventory.LockItemsForRead(false);
2871 return; 3121 return;
2872 else 3122 }
2873 item = m_host.TaskInventory[InventorySelf()]; 3123 else
3124 {
3125 item = m_host.TaskInventory[InventorySelf()];
2874 } 3126 }
3127 m_host.TaskInventory.LockItemsForRead(false);
2875 3128
2876 if (item.PermsGranter != UUID.Zero) 3129 if (item.PermsGranter != UUID.Zero)
2877 { 3130 {
@@ -2893,13 +3146,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2893 { 3146 {
2894 TaskInventoryItem item; 3147 TaskInventoryItem item;
2895 3148
3149 m_host.TaskInventory.LockItemsForRead(true);
2896 lock (m_host.TaskInventory) 3150 lock (m_host.TaskInventory)
2897 { 3151 {
3152
2898 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3153 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3154 {
3155 m_host.TaskInventory.LockItemsForRead(false);
2899 return; 3156 return;
3157 }
2900 else 3158 else
3159 {
2901 item = m_host.TaskInventory[InventorySelf()]; 3160 item = m_host.TaskInventory[InventorySelf()];
3161 }
2902 } 3162 }
3163 m_host.TaskInventory.LockItemsForRead(false);
2903 3164
2904 m_host.AddScriptLPS(1); 3165 m_host.AddScriptLPS(1);
2905 3166
@@ -2931,18 +3192,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2931 { 3192 {
2932 m_host.AddScriptLPS(1); 3193 m_host.AddScriptLPS(1);
2933 3194
2934 if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
2935 return;
2936
2937 TaskInventoryItem item; 3195 TaskInventoryItem item;
2938 3196
2939 lock (m_host.TaskInventory) 3197 m_host.TaskInventory.LockItemsForRead(true);
3198
3199 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2940 { 3200 {
2941 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3201 m_host.TaskInventory.LockItemsForRead(false);
2942 return; 3202 return;
2943 else
2944 item = m_host.TaskInventory[InventorySelf()];
2945 } 3203 }
3204 else
3205 {
3206 item = m_host.TaskInventory[InventorySelf()];
3207 }
3208
3209 m_host.TaskInventory.LockItemsForRead(false);
2946 3210
2947 if (item.PermsGranter != m_host.OwnerID) 3211 if (item.PermsGranter != m_host.OwnerID)
2948 return; 3212 return;
@@ -2953,10 +3217,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2953 3217
2954 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 3218 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
2955 3219
2956 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3220 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 } 3221 }
2961 } 3222 }
2962 3223
@@ -2969,13 +3230,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2969 3230
2970 TaskInventoryItem item; 3231 TaskInventoryItem item;
2971 3232
2972 lock (m_host.TaskInventory) 3233 m_host.TaskInventory.LockItemsForRead(true);
3234
3235 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2973 { 3236 {
2974 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3237 m_host.TaskInventory.LockItemsForRead(false);
2975 return; 3238 return;
2976 else 3239 }
2977 item = m_host.TaskInventory[InventorySelf()]; 3240 else
3241 {
3242 item = m_host.TaskInventory[InventorySelf()];
2978 } 3243 }
3244 m_host.TaskInventory.LockItemsForRead(false);
3245
2979 3246
2980 if (item.PermsGranter != m_host.OwnerID) 3247 if (item.PermsGranter != m_host.OwnerID)
2981 return; 3248 return;
@@ -3022,6 +3289,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3022 3289
3023 public void llInstantMessage(string user, string message) 3290 public void llInstantMessage(string user, string message)
3024 { 3291 {
3292 UUID result;
3293 if (!UUID.TryParse(user, out result))
3294 {
3295 ShoutError("An invalid key was passed to llInstantMessage");
3296 ScriptSleep(2000);
3297 return;
3298 }
3299
3300
3025 m_host.AddScriptLPS(1); 3301 m_host.AddScriptLPS(1);
3026 3302
3027 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. 3303 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
@@ -3036,14 +3312,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3036 UUID friendTransactionID = UUID.Random(); 3312 UUID friendTransactionID = UUID.Random();
3037 3313
3038 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 3314 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
3039 3315
3040 GridInstantMessage msg = new GridInstantMessage(); 3316 GridInstantMessage msg = new GridInstantMessage();
3041 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; 3317 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
3042 msg.toAgentID = new Guid(user); // toAgentID.Guid; 3318 msg.toAgentID = new Guid(user); // toAgentID.Guid;
3043 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here 3319 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); 3320// 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()); 3321// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
3046 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp; 3322// DateTime dt = DateTime.UtcNow;
3323//
3324// // Ticks from UtcNow, but make it look like local. Evil, huh?
3325// dt = DateTime.SpecifyKind(dt, DateTimeKind.Local);
3326//
3327// try
3328// {
3329// // Convert that to the PST timezone
3330// TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
3331// dt = TimeZoneInfo.ConvertTime(dt, timeZoneInfo);
3332// }
3333// catch
3334// {
3335// // No logging here, as it could be VERY spammy
3336// }
3337//
3338// // And make it look local again to fool the unix time util
3339// dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
3340
3341 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
3342
3047 //if (client != null) 3343 //if (client != null)
3048 //{ 3344 //{
3049 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName; 3345 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
@@ -3057,12 +3353,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3057 msg.message = message.Substring(0, 1024); 3353 msg.message = message.Substring(0, 1024);
3058 else 3354 else
3059 msg.message = message; 3355 msg.message = message;
3060 msg.dialog = (byte)19; // messgage from script ??? // dialog; 3356 msg.dialog = (byte)19; // MessageFromObject
3061 msg.fromGroup = false;// fromGroup; 3357 msg.fromGroup = false;// fromGroup;
3062 msg.offline = (byte)0; //offline; 3358 msg.offline = (byte)0; //offline;
3063 msg.ParentEstateID = 0; //ParentEstateID; 3359 msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
3064 msg.Position = new Vector3(m_host.AbsolutePosition); 3360 msg.Position = new Vector3(m_host.AbsolutePosition);
3065 msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; 3361 msg.RegionID = World.RegionInfo.RegionID.Guid;
3066 msg.binaryBucket 3362 msg.binaryBucket
3067 = Util.StringToBytes256( 3363 = Util.StringToBytes256(
3068 "{0}/{1}/{2}/{3}", 3364 "{0}/{1}/{2}/{3}",
@@ -3090,7 +3386,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3090 } 3386 }
3091 3387
3092 emailModule.SendEmail(m_host.UUID, address, subject, message); 3388 emailModule.SendEmail(m_host.UUID, address, subject, message);
3093 ScriptSleep(20000); 3389 ScriptSleep(15000);
3094 } 3390 }
3095 3391
3096 public void llGetNextEmail(string address, string subject) 3392 public void llGetNextEmail(string address, string subject)
@@ -3192,13 +3488,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3192 m_host.AddScriptLPS(1); 3488 m_host.AddScriptLPS(1);
3193 } 3489 }
3194 3490
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) 3491 public LSL_Integer llStringLength(string str)
3203 { 3492 {
3204 m_host.AddScriptLPS(1); 3493 m_host.AddScriptLPS(1);
@@ -3222,14 +3511,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3222 3511
3223 TaskInventoryItem item; 3512 TaskInventoryItem item;
3224 3513
3225 lock (m_host.TaskInventory) 3514 m_host.TaskInventory.LockItemsForRead(true);
3515 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3226 { 3516 {
3227 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3517 m_host.TaskInventory.LockItemsForRead(false);
3228 return; 3518 return;
3229 else
3230 item = m_host.TaskInventory[InventorySelf()];
3231 } 3519 }
3232 3520 else
3521 {
3522 item = m_host.TaskInventory[InventorySelf()];
3523 }
3524 m_host.TaskInventory.LockItemsForRead(false);
3233 if (item.PermsGranter == UUID.Zero) 3525 if (item.PermsGranter == UUID.Zero)
3234 return; 3526 return;
3235 3527
@@ -3259,13 +3551,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3259 3551
3260 TaskInventoryItem item; 3552 TaskInventoryItem item;
3261 3553
3262 lock (m_host.TaskInventory) 3554 m_host.TaskInventory.LockItemsForRead(true);
3555 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3263 { 3556 {
3264 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3557 m_host.TaskInventory.LockItemsForRead(false);
3265 return; 3558 return;
3266 else
3267 item = m_host.TaskInventory[InventorySelf()];
3268 } 3559 }
3560 else
3561 {
3562 item = m_host.TaskInventory[InventorySelf()];
3563 }
3564 m_host.TaskInventory.LockItemsForRead(false);
3565
3269 3566
3270 if (item.PermsGranter == UUID.Zero) 3567 if (item.PermsGranter == UUID.Zero)
3271 return; 3568 return;
@@ -3336,10 +3633,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3336 3633
3337 TaskInventoryItem item; 3634 TaskInventoryItem item;
3338 3635
3339 lock (m_host.TaskInventory) 3636
3637 m_host.TaskInventory.LockItemsForRead(true);
3638 if (!m_host.TaskInventory.ContainsKey(invItemID))
3639 {
3640 m_host.TaskInventory.LockItemsForRead(false);
3641 return;
3642 }
3643 else
3340 { 3644 {
3341 item = m_host.TaskInventory[invItemID]; 3645 item = m_host.TaskInventory[invItemID];
3342 } 3646 }
3647 m_host.TaskInventory.LockItemsForRead(false);
3343 3648
3344 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3649 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3345 { 3650 {
@@ -3371,11 +3676,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3371 3676
3372 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3677 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3373 { 3678 {
3374 lock (m_host.TaskInventory) 3679 m_host.TaskInventory.LockItemsForWrite(true);
3375 { 3680 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3376 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3681 m_host.TaskInventory[invItemID].PermsMask = perm;
3377 m_host.TaskInventory[invItemID].PermsMask = perm; 3682 m_host.TaskInventory.LockItemsForWrite(false);
3378 }
3379 3683
3380 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3684 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3381 "run_time_permissions", new Object[] { 3685 "run_time_permissions", new Object[] {
@@ -3395,11 +3699,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3395 3699
3396 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3700 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3397 { 3701 {
3398 lock (m_host.TaskInventory) 3702 m_host.TaskInventory.LockItemsForWrite(true);
3399 { 3703 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3400 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3704 m_host.TaskInventory[invItemID].PermsMask = perm;
3401 m_host.TaskInventory[invItemID].PermsMask = perm; 3705 m_host.TaskInventory.LockItemsForWrite(false);
3402 }
3403 3706
3404 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3707 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3405 "run_time_permissions", new Object[] { 3708 "run_time_permissions", new Object[] {
@@ -3420,11 +3723,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3420 3723
3421 if (!m_waitingForScriptAnswer) 3724 if (!m_waitingForScriptAnswer)
3422 { 3725 {
3423 lock (m_host.TaskInventory) 3726 m_host.TaskInventory.LockItemsForWrite(true);
3424 { 3727 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3425 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3728 m_host.TaskInventory[invItemID].PermsMask = 0;
3426 m_host.TaskInventory[invItemID].PermsMask = 0; 3729 m_host.TaskInventory.LockItemsForWrite(false);
3427 }
3428 3730
3429 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3731 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3430 m_waitingForScriptAnswer=true; 3732 m_waitingForScriptAnswer=true;
@@ -3459,10 +3761,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3459 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3761 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3460 llReleaseControls(); 3762 llReleaseControls();
3461 3763
3462 lock (m_host.TaskInventory) 3764
3463 { 3765 m_host.TaskInventory.LockItemsForWrite(true);
3464 m_host.TaskInventory[invItemID].PermsMask = answer; 3766 m_host.TaskInventory[invItemID].PermsMask = answer;
3465 } 3767 m_host.TaskInventory.LockItemsForWrite(false);
3768
3466 3769
3467 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3770 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3468 "run_time_permissions", new Object[] { 3771 "run_time_permissions", new Object[] {
@@ -3474,16 +3777,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3474 { 3777 {
3475 m_host.AddScriptLPS(1); 3778 m_host.AddScriptLPS(1);
3476 3779
3477 lock (m_host.TaskInventory) 3780 m_host.TaskInventory.LockItemsForRead(true);
3781
3782 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3478 { 3783 {
3479 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3784 if (item.Type == 10 && item.ItemID == m_itemID)
3480 { 3785 {
3481 if (item.Type == 10 && item.ItemID == m_itemID) 3786 m_host.TaskInventory.LockItemsForRead(false);
3482 { 3787 return item.PermsGranter.ToString();
3483 return item.PermsGranter.ToString();
3484 }
3485 } 3788 }
3486 } 3789 }
3790 m_host.TaskInventory.LockItemsForRead(false);
3487 3791
3488 return UUID.Zero.ToString(); 3792 return UUID.Zero.ToString();
3489 } 3793 }
@@ -3492,19 +3796,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3492 { 3796 {
3493 m_host.AddScriptLPS(1); 3797 m_host.AddScriptLPS(1);
3494 3798
3495 lock (m_host.TaskInventory) 3799 m_host.TaskInventory.LockItemsForRead(true);
3800
3801 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3496 { 3802 {
3497 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3803 if (item.Type == 10 && item.ItemID == m_itemID)
3498 { 3804 {
3499 if (item.Type == 10 && item.ItemID == m_itemID) 3805 int perms = item.PermsMask;
3500 { 3806 if (m_automaticLinkPermission)
3501 int perms = item.PermsMask; 3807 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3502 if (m_automaticLinkPermission) 3808 m_host.TaskInventory.LockItemsForRead(false);
3503 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; 3809 return perms;
3504 return perms;
3505 }
3506 } 3810 }
3507 } 3811 }
3812 m_host.TaskInventory.LockItemsForRead(false);
3508 3813
3509 return 0; 3814 return 0;
3510 } 3815 }
@@ -3526,9 +3831,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3526 public void llSetLinkColor(int linknumber, LSL_Vector color, int face) 3831 public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
3527 { 3832 {
3528 List<SceneObjectPart> parts = GetLinkParts(linknumber); 3833 List<SceneObjectPart> parts = GetLinkParts(linknumber);
3529 3834 if (parts.Count > 0)
3530 foreach (SceneObjectPart part in parts) 3835 {
3531 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); 3836 try
3837 {
3838 parts[0].ParentGroup.areUpdatesSuspended = true;
3839 foreach (SceneObjectPart part in parts)
3840 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
3841 }
3842 finally
3843 {
3844 parts[0].ParentGroup.areUpdatesSuspended = false;
3845 }
3846 }
3532 } 3847 }
3533 3848
3534 public void llCreateLink(string target, int parent) 3849 public void llCreateLink(string target, int parent)
@@ -3541,11 +3856,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3541 return; 3856 return;
3542 3857
3543 TaskInventoryItem item; 3858 TaskInventoryItem item;
3544 lock (m_host.TaskInventory) 3859 m_host.TaskInventory.LockItemsForRead(true);
3545 { 3860 item = m_host.TaskInventory[invItemID];
3546 item = m_host.TaskInventory[invItemID]; 3861 m_host.TaskInventory.LockItemsForRead(false);
3547 } 3862
3548
3549 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3863 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3550 && !m_automaticLinkPermission) 3864 && !m_automaticLinkPermission)
3551 { 3865 {
@@ -3566,7 +3880,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3566 3880
3567 if (targetPart != null) 3881 if (targetPart != null)
3568 { 3882 {
3569 if (parent != 0) { 3883 if (parent != 0)
3884 {
3570 parentPrim = m_host.ParentGroup; 3885 parentPrim = m_host.ParentGroup;
3571 childPrim = targetPart.ParentGroup; 3886 childPrim = targetPart.ParentGroup;
3572 } 3887 }
@@ -3598,16 +3913,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3598 m_host.AddScriptLPS(1); 3913 m_host.AddScriptLPS(1);
3599 UUID invItemID = InventorySelf(); 3914 UUID invItemID = InventorySelf();
3600 3915
3601 lock (m_host.TaskInventory) 3916 m_host.TaskInventory.LockItemsForRead(true);
3602 {
3603 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3917 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3604 && !m_automaticLinkPermission) 3918 && !m_automaticLinkPermission)
3605 { 3919 {
3606 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3920 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
3921 m_host.TaskInventory.LockItemsForRead(false);
3607 return; 3922 return;
3608 } 3923 }
3609 } 3924 m_host.TaskInventory.LockItemsForRead(false);
3610 3925
3611 if (linknum < ScriptBaseClass.LINK_THIS) 3926 if (linknum < ScriptBaseClass.LINK_THIS)
3612 return; 3927 return;
3613 3928
@@ -3646,10 +3961,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3646 // Restructuring Multiple Prims. 3961 // Restructuring Multiple Prims.
3647 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts); 3962 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
3648 parts.Remove(parentPrim.RootPart); 3963 parts.Remove(parentPrim.RootPart);
3649 foreach (SceneObjectPart part in parts) 3964 if (parts.Count > 0)
3650 { 3965 {
3651 parentPrim.DelinkFromGroup(part.LocalId, true); 3966 try
3967 {
3968 parts[0].ParentGroup.areUpdatesSuspended = true;
3969 foreach (SceneObjectPart part in parts)
3970 {
3971 parentPrim.DelinkFromGroup(part.LocalId, true);
3972 }
3973 }
3974 finally
3975 {
3976 parts[0].ParentGroup.areUpdatesSuspended = false;
3977 }
3652 } 3978 }
3979
3653 parentPrim.HasGroupChanged = true; 3980 parentPrim.HasGroupChanged = true;
3654 parentPrim.ScheduleGroupForFullUpdate(); 3981 parentPrim.ScheduleGroupForFullUpdate();
3655 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 3982 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
@@ -3658,11 +3985,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3658 { 3985 {
3659 SceneObjectPart newRoot = parts[0]; 3986 SceneObjectPart newRoot = parts[0];
3660 parts.Remove(newRoot); 3987 parts.Remove(newRoot);
3661 foreach (SceneObjectPart part in parts) 3988
3989 try
3662 { 3990 {
3663 part.UpdateFlag = 0; 3991 parts[0].ParentGroup.areUpdatesSuspended = true;
3664 newRoot.ParentGroup.LinkToGroup(part.ParentGroup); 3992 foreach (SceneObjectPart part in parts)
3993 {
3994 part.UpdateFlag = 0;
3995 newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
3996 }
3665 } 3997 }
3998 finally
3999 {
4000 parts[0].ParentGroup.areUpdatesSuspended = false;
4001 }
4002
4003
3666 newRoot.ParentGroup.HasGroupChanged = true; 4004 newRoot.ParentGroup.HasGroupChanged = true;
3667 newRoot.ParentGroup.ScheduleGroupForFullUpdate(); 4005 newRoot.ParentGroup.ScheduleGroupForFullUpdate();
3668 } 4006 }
@@ -3708,6 +4046,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3708 } 4046 }
3709 else 4047 else
3710 { 4048 {
4049 if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
4050 {
4051 linknum -= (m_host.ParentGroup.PrimCount) + 1;
4052
4053 if (linknum < 0)
4054 return UUID.Zero.ToString();
4055
4056 List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
4057 if (avatars.Count > linknum)
4058 {
4059 return avatars[linknum].UUID.ToString();
4060 }
4061 }
3711 return UUID.Zero.ToString(); 4062 return UUID.Zero.ToString();
3712 } 4063 }
3713 } 4064 }
@@ -3784,17 +4135,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3784 m_host.AddScriptLPS(1); 4135 m_host.AddScriptLPS(1);
3785 int count = 0; 4136 int count = 0;
3786 4137
3787 lock (m_host.TaskInventory) 4138 m_host.TaskInventory.LockItemsForRead(true);
4139 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3788 { 4140 {
3789 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4141 if (inv.Value.Type == type || type == -1)
3790 { 4142 {
3791 if (inv.Value.Type == type || type == -1) 4143 count = count + 1;
3792 {
3793 count = count + 1;
3794 }
3795 } 4144 }
3796 } 4145 }
3797 4146
4147 m_host.TaskInventory.LockItemsForRead(false);
3798 return count; 4148 return count;
3799 } 4149 }
3800 4150
@@ -3803,16 +4153,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3803 m_host.AddScriptLPS(1); 4153 m_host.AddScriptLPS(1);
3804 ArrayList keys = new ArrayList(); 4154 ArrayList keys = new ArrayList();
3805 4155
3806 lock (m_host.TaskInventory) 4156 m_host.TaskInventory.LockItemsForRead(true);
4157 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3807 { 4158 {
3808 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4159 if (inv.Value.Type == type || type == -1)
3809 { 4160 {
3810 if (inv.Value.Type == type || type == -1) 4161 keys.Add(inv.Value.Name);
3811 {
3812 keys.Add(inv.Value.Name);
3813 }
3814 } 4162 }
3815 } 4163 }
4164 m_host.TaskInventory.LockItemsForRead(false);
3816 4165
3817 if (keys.Count == 0) 4166 if (keys.Count == 0)
3818 { 4167 {
@@ -3849,30 +4198,51 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3849 } 4198 }
3850 4199
3851 // move the first object found with this inventory name 4200 // move the first object found with this inventory name
3852 lock (m_host.TaskInventory) 4201 m_host.TaskInventory.LockItemsForRead(true);
4202 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3853 { 4203 {
3854 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4204 if (inv.Value.Name == inventory)
3855 { 4205 {
3856 if (inv.Value.Name == inventory) 4206 found = true;
3857 { 4207 objId = inv.Key;
3858 found = true; 4208 assetType = inv.Value.Type;
3859 objId = inv.Key; 4209 objName = inv.Value.Name;
3860 assetType = inv.Value.Type; 4210 break;
3861 objName = inv.Value.Name;
3862 break;
3863 }
3864 } 4211 }
3865 } 4212 }
4213 m_host.TaskInventory.LockItemsForRead(false);
3866 4214
3867 if (!found) 4215 if (!found)
3868 { 4216 {
3869 llSay(0, String.Format("Could not find object '{0}'", inventory)); 4217 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)); 4218 return;
4219// throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
3871 } 4220 }
3872 4221
3873 // check if destination is an avatar 4222 // check if destination is an object
3874 if (World.GetScenePresence(destId) != null) 4223 if (World.GetSceneObjectPart(destId) != null)
3875 { 4224 {
4225 // destination is an object
4226 World.MoveTaskInventoryItem(destId, m_host, objId);
4227 }
4228 else
4229 {
4230 ScenePresence presence = World.GetScenePresence(destId);
4231
4232 if (presence == null)
4233 {
4234 UserAccount account =
4235 World.UserAccountService.GetUserAccount(
4236 World.RegionInfo.ScopeID,
4237 destId);
4238
4239 if (account == null)
4240 {
4241 llSay(0, "Can't find destination "+destId.ToString());
4242 return;
4243 }
4244 }
4245
3876 // destination is an avatar 4246 // destination is an avatar
3877 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId); 4247 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId);
3878 4248
@@ -3896,31 +4266,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3896 4266
3897 if (m_TransferModule != null) 4267 if (m_TransferModule != null)
3898 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); 4268 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
4269
4270 //This delay should only occur when giving inventory to avatars.
4271 ScriptSleep(3000);
3899 } 4272 }
3900 else
3901 {
3902 // destination is an object
3903 World.MoveTaskInventoryItem(destId, m_host, objId);
3904 }
3905 ScriptSleep(3000);
3906 } 4273 }
3907 4274
4275 [DebuggerNonUserCode]
3908 public void llRemoveInventory(string name) 4276 public void llRemoveInventory(string name)
3909 { 4277 {
3910 m_host.AddScriptLPS(1); 4278 m_host.AddScriptLPS(1);
3911 4279
3912 lock (m_host.TaskInventory) 4280 List<TaskInventoryItem> inv;
4281 try
3913 { 4282 {
3914 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4283 m_host.TaskInventory.LockItemsForRead(true);
4284 inv = new List<TaskInventoryItem>(m_host.TaskInventory.Values);
4285 }
4286 finally
4287 {
4288 m_host.TaskInventory.LockItemsForRead(false);
4289 }
4290 foreach (TaskInventoryItem item in inv)
4291 {
4292 if (item.Name == name)
3915 { 4293 {
3916 if (item.Name == name) 4294 if (item.ItemID == m_itemID)
3917 { 4295 throw new ScriptDeleteException();
3918 if (item.ItemID == m_itemID) 4296 else
3919 throw new ScriptDeleteException(); 4297 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3920 else 4298 return;
3921 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3922 return;
3923 }
3924 } 4299 }
3925 } 4300 }
3926 } 4301 }
@@ -3955,112 +4330,122 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3955 { 4330 {
3956 m_host.AddScriptLPS(1); 4331 m_host.AddScriptLPS(1);
3957 4332
3958 UUID uuid = (UUID)id; 4333 UUID uuid;
3959 PresenceInfo pinfo = null; 4334 if (UUID.TryParse(id, out uuid))
3960 UserAccount account;
3961
3962 UserInfoCacheEntry ce;
3963 if (!m_userInfoCache.TryGetValue(uuid, out ce))
3964 { 4335 {
3965 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); 4336 PresenceInfo pinfo = null;
3966 if (account == null) 4337 UserAccount account;
4338
4339 UserInfoCacheEntry ce;
4340 if (!m_userInfoCache.TryGetValue(uuid, out ce))
3967 { 4341 {
3968 m_userInfoCache[uuid] = null; // Cache negative 4342 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
3969 return UUID.Zero.ToString(); 4343 if (account == null)
3970 } 4344 {
4345 m_userInfoCache[uuid] = null; // Cache negative
4346 return UUID.Zero.ToString();
4347 }
3971 4348
3972 4349
3973 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); 4350 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
3974 if (pinfos != null && pinfos.Length > 0) 4351 if (pinfos != null && pinfos.Length > 0)
3975 {
3976 foreach (PresenceInfo p in pinfos)
3977 { 4352 {
3978 if (p.RegionID != UUID.Zero) 4353 foreach (PresenceInfo p in pinfos)
3979 { 4354 {
3980 pinfo = p; 4355 if (p.RegionID != UUID.Zero)
4356 {
4357 pinfo = p;
4358 }
3981 } 4359 }
3982 } 4360 }
3983 }
3984 4361
3985 ce = new UserInfoCacheEntry(); 4362 ce = new UserInfoCacheEntry();
3986 ce.time = Util.EnvironmentTickCount(); 4363 ce.time = Util.EnvironmentTickCount();
3987 ce.account = account; 4364 ce.account = account;
3988 ce.pinfo = pinfo; 4365 ce.pinfo = pinfo;
3989 } 4366 m_userInfoCache[uuid] = ce;
3990 else 4367 }
3991 { 4368 else
3992 if (ce == null) 4369 {
3993 return UUID.Zero.ToString(); 4370 if (ce == null)
4371 return UUID.Zero.ToString();
3994 4372
3995 account = ce.account; 4373 account = ce.account;
3996 pinfo = ce.pinfo; 4374 pinfo = ce.pinfo;
3997 } 4375 }
3998 4376
3999 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) 4377 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 { 4378 {
4004 foreach (PresenceInfo p in pinfos) 4379 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4380 if (pinfos != null && pinfos.Length > 0)
4005 { 4381 {
4006 if (p.RegionID != UUID.Zero) 4382 foreach (PresenceInfo p in pinfos)
4007 { 4383 {
4008 pinfo = p; 4384 if (p.RegionID != UUID.Zero)
4385 {
4386 pinfo = p;
4387 }
4009 } 4388 }
4010 } 4389 }
4011 } 4390 else
4012 else 4391 pinfo = null;
4013 pinfo = null;
4014 4392
4015 ce.time = Util.EnvironmentTickCount(); 4393 ce.time = Util.EnvironmentTickCount();
4016 ce.pinfo = pinfo; 4394 ce.pinfo = pinfo;
4017 } 4395 }
4018 4396
4019 string reply = String.Empty; 4397 string reply = String.Empty;
4020 4398
4021 switch (data) 4399 switch (data)
4022 { 4400 {
4023 case 1: // DATA_ONLINE (0|1) 4401 case 1: // DATA_ONLINE (0|1)
4024 if (pinfo != null && pinfo.RegionID != UUID.Zero) 4402 if (pinfo != null && pinfo.RegionID != UUID.Zero)
4025 reply = "1"; 4403 reply = "1";
4026 else 4404 else
4027 reply = "0"; 4405 reply = "0";
4028 break; 4406 break;
4029 case 2: // DATA_NAME (First Last) 4407 case 2: // DATA_NAME (First Last)
4030 reply = account.FirstName + " " + account.LastName; 4408 reply = account.FirstName + " " + account.LastName;
4031 break; 4409 break;
4032 case 3: // DATA_BORN (YYYY-MM-DD) 4410 case 3: // DATA_BORN (YYYY-MM-DD)
4033 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); 4411 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
4034 born = born.AddSeconds(account.Created); 4412 born = born.AddSeconds(account.Created);
4035 reply = born.ToString("yyyy-MM-dd"); 4413 reply = born.ToString("yyyy-MM-dd");
4036 break; 4414 break;
4037 case 4: // DATA_RATING (0,0,0,0,0,0) 4415 case 4: // DATA_RATING (0,0,0,0,0,0)
4038 reply = "0,0,0,0,0,0"; 4416 reply = "0,0,0,0,0,0";
4039 break; 4417 break;
4040 case 8: // DATA_PAYINFO (0|1|2|3) 4418 case 8: // DATA_PAYINFO (0|1|2|3)
4041 reply = "0"; 4419 reply = "0";
4042 break; 4420 break;
4043 default: 4421 default:
4044 return UUID.Zero.ToString(); // Raise no event 4422 return UUID.Zero.ToString(); // Raise no event
4045 } 4423 }
4046 4424
4047 UUID rq = UUID.Random(); 4425 UUID rq = UUID.Random();
4048 4426
4049 UUID tid = AsyncCommands. 4427 UUID tid = AsyncCommands.
4050 DataserverPlugin.RegisterRequest(m_localID, 4428 DataserverPlugin.RegisterRequest(m_localID,
4051 m_itemID, rq.ToString()); 4429 m_itemID, rq.ToString());
4052 4430
4053 AsyncCommands. 4431 AsyncCommands.
4054 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4432 DataserverPlugin.DataserverReply(rq.ToString(), reply);
4055 4433
4056 ScriptSleep(100); 4434 ScriptSleep(100);
4057 return tid.ToString(); 4435 return tid.ToString();
4436 }
4437 else
4438 {
4439 ShoutError("Invalid UUID passed to llRequestAgentData.");
4440 }
4441 return "";
4058 } 4442 }
4059 4443
4060 public LSL_String llRequestInventoryData(string name) 4444 public LSL_String llRequestInventoryData(string name)
4061 { 4445 {
4062 m_host.AddScriptLPS(1); 4446 m_host.AddScriptLPS(1);
4063 4447
4448 //Clone is thread safe
4064 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 4449 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
4065 4450
4066 foreach (TaskInventoryItem item in itemDictionary.Values) 4451 foreach (TaskInventoryItem item in itemDictionary.Values)
@@ -4114,6 +4499,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4114 ScenePresence presence = World.GetScenePresence(agentId); 4499 ScenePresence presence = World.GetScenePresence(agentId);
4115 if (presence != null) 4500 if (presence != null)
4116 { 4501 {
4502 // agent must not be a god
4503 if (presence.UserLevel >= 200) return;
4504
4117 // agent must be over the owners land 4505 // agent must be over the owners land
4118 if (m_host.OwnerID == World.LandChannel.GetLandObject( 4506 if (m_host.OwnerID == World.LandChannel.GetLandObject(
4119 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) 4507 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
@@ -4136,7 +4524,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4136 UUID av = new UUID(); 4524 UUID av = new UUID();
4137 if (!UUID.TryParse(agent,out av)) 4525 if (!UUID.TryParse(agent,out av))
4138 { 4526 {
4139 LSLError("First parameter to llDialog needs to be a key"); 4527 //LSLError("First parameter to llDialog needs to be a key");
4140 return; 4528 return;
4141 } 4529 }
4142 4530
@@ -4173,17 +4561,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4173 UUID soundId = UUID.Zero; 4561 UUID soundId = UUID.Zero;
4174 if (!UUID.TryParse(impact_sound, out soundId)) 4562 if (!UUID.TryParse(impact_sound, out soundId))
4175 { 4563 {
4176 lock (m_host.TaskInventory) 4564 m_host.TaskInventory.LockItemsForRead(true);
4565 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4177 { 4566 {
4178 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4567 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
4179 { 4568 {
4180 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 4569 soundId = item.AssetID;
4181 { 4570 break;
4182 soundId = item.AssetID;
4183 break;
4184 }
4185 } 4571 }
4186 } 4572 }
4573 m_host.TaskInventory.LockItemsForRead(false);
4187 } 4574 }
4188 m_host.CollisionSound = soundId; 4575 m_host.CollisionSound = soundId;
4189 m_host.CollisionSoundVolume = (float)impact_volume; 4576 m_host.CollisionSoundVolume = (float)impact_volume;
@@ -4229,6 +4616,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4229 UUID partItemID; 4616 UUID partItemID;
4230 foreach (SceneObjectPart part in parts) 4617 foreach (SceneObjectPart part in parts)
4231 { 4618 {
4619 //Clone is thread safe
4232 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); 4620 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
4233 4621
4234 foreach (TaskInventoryItem item in itemsDictionary.Values) 4622 foreach (TaskInventoryItem item in itemsDictionary.Values)
@@ -4443,17 +4831,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4443 4831
4444 m_host.AddScriptLPS(1); 4832 m_host.AddScriptLPS(1);
4445 4833
4446 lock (m_host.TaskInventory) 4834 m_host.TaskInventory.LockItemsForRead(true);
4835 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4447 { 4836 {
4448 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4837 if (item.Type == 10 && item.ItemID == m_itemID)
4449 { 4838 {
4450 if (item.Type == 10 && item.ItemID == m_itemID) 4839 result = item.Name!=null?item.Name:String.Empty;
4451 { 4840 break;
4452 result = item.Name != null ? item.Name : String.Empty;
4453 break;
4454 }
4455 } 4841 }
4456 } 4842 }
4843 m_host.TaskInventory.LockItemsForRead(false);
4457 4844
4458 return result; 4845 return result;
4459 } 4846 }
@@ -4606,23 +4993,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4606 { 4993 {
4607 m_host.AddScriptLPS(1); 4994 m_host.AddScriptLPS(1);
4608 4995
4609 lock (m_host.TaskInventory) 4996 m_host.TaskInventory.LockItemsForRead(true);
4997 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4610 { 4998 {
4611 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4999 if (inv.Value.Name == name)
4612 { 5000 {
4613 if (inv.Value.Name == name) 5001 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
4614 { 5002 {
4615 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) 5003 m_host.TaskInventory.LockItemsForRead(false);
4616 { 5004 return inv.Value.AssetID.ToString();
4617 return inv.Value.AssetID.ToString(); 5005 }
4618 } 5006 else
4619 else 5007 {
4620 { 5008 m_host.TaskInventory.LockItemsForRead(false);
4621 return UUID.Zero.ToString(); 5009 return UUID.Zero.ToString();
4622 }
4623 } 5010 }
4624 } 5011 }
4625 } 5012 }
5013 m_host.TaskInventory.LockItemsForRead(false);
4626 5014
4627 return UUID.Zero.ToString(); 5015 return UUID.Zero.ToString();
4628 } 5016 }
@@ -4775,14 +5163,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4775 { 5163 {
4776 m_host.AddScriptLPS(1); 5164 m_host.AddScriptLPS(1);
4777 5165
4778 if (src == null) 5166 return src.Length;
4779 {
4780 return 0;
4781 }
4782 else
4783 {
4784 return src.Length;
4785 }
4786 } 5167 }
4787 5168
4788 public LSL_Integer llList2Integer(LSL_List src, int index) 5169 public LSL_Integer llList2Integer(LSL_List src, int index)
@@ -4828,7 +5209,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4828 else if (src.Data[index] is LSL_Float) 5209 else if (src.Data[index] is LSL_Float)
4829 return Convert.ToDouble(((LSL_Float) src.Data[index]).value); 5210 return Convert.ToDouble(((LSL_Float) src.Data[index]).value);
4830 else if (src.Data[index] is LSL_String) 5211 else if (src.Data[index] is LSL_String)
4831 return Convert.ToDouble(((LSL_String) src.Data[index]).m_string); 5212 {
5213 string str = ((LSL_String) src.Data[index]).m_string;
5214 Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
5215 if (m != Match.Empty)
5216 {
5217 str = m.Value;
5218 double d = 0.0;
5219 if (!Double.TryParse(str, out d))
5220 return 0.0;
5221
5222 return d;
5223 }
5224 return 0.0;
5225 }
4832 return Convert.ToDouble(src.Data[index]); 5226 return Convert.ToDouble(src.Data[index]);
4833 } 5227 }
4834 catch (FormatException) 5228 catch (FormatException)
@@ -5101,7 +5495,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5101 } 5495 }
5102 } 5496 }
5103 } 5497 }
5104 else { 5498 else
5499 {
5105 object[] array = new object[src.Length]; 5500 object[] array = new object[src.Length];
5106 Array.Copy(src.Data, 0, array, 0, src.Length); 5501 Array.Copy(src.Data, 0, array, 0, src.Length);
5107 result = new LSL_List(array); 5502 result = new LSL_List(array);
@@ -5513,7 +5908,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5513 public void llSetSoundQueueing(int queue) 5908 public void llSetSoundQueueing(int queue)
5514 { 5909 {
5515 m_host.AddScriptLPS(1); 5910 m_host.AddScriptLPS(1);
5516 NotImplemented("llSetSoundQueueing");
5517 } 5911 }
5518 5912
5519 public void llSetSoundRadius(double radius) 5913 public void llSetSoundRadius(double radius)
@@ -5558,10 +5952,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5558 m_host.AddScriptLPS(1); 5952 m_host.AddScriptLPS(1);
5559 5953
5560 List<SceneObjectPart> parts = GetLinkParts(linknumber); 5954 List<SceneObjectPart> parts = GetLinkParts(linknumber);
5561 5955 if (parts.Count > 0)
5562 foreach (var part in parts)
5563 { 5956 {
5564 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate); 5957 try
5958 {
5959 parts[0].ParentGroup.areUpdatesSuspended = true;
5960 foreach (var part in parts)
5961 {
5962 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
5963 }
5964 }
5965 finally
5966 {
5967 parts[0].ParentGroup.areUpdatesSuspended = false;
5968 }
5565 } 5969 }
5566 } 5970 }
5567 5971
@@ -5615,6 +6019,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5615 ScriptSleep(5000); 6019 ScriptSleep(5000);
5616 } 6020 }
5617 6021
6022 public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
6023 {
6024 return ParseString2List(str, separators, in_spacers, false);
6025 }
6026
5618 public LSL_Integer llOverMyLand(string id) 6027 public LSL_Integer llOverMyLand(string id)
5619 { 6028 {
5620 m_host.AddScriptLPS(1); 6029 m_host.AddScriptLPS(1);
@@ -5815,7 +6224,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5815 return m_host.ParentGroup.RootPart.AttachmentPoint; 6224 return m_host.ParentGroup.RootPart.AttachmentPoint;
5816 } 6225 }
5817 6226
5818 public LSL_Integer llGetFreeMemory() 6227 public virtual LSL_Integer llGetFreeMemory()
5819 { 6228 {
5820 m_host.AddScriptLPS(1); 6229 m_host.AddScriptLPS(1);
5821 // Make scripts designed for LSO happy 6230 // Make scripts designed for LSO happy
@@ -5932,7 +6341,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5932 SetParticleSystem(m_host, rules); 6341 SetParticleSystem(m_host, rules);
5933 } 6342 }
5934 6343
5935 private void SetParticleSystem(SceneObjectPart part, LSL_List rules) { 6344 private void SetParticleSystem(SceneObjectPart part, LSL_List rules)
6345 {
5936 6346
5937 6347
5938 if (rules.Length == 0) 6348 if (rules.Length == 0)
@@ -6126,14 +6536,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6126 6536
6127 protected UUID GetTaskInventoryItem(string name) 6537 protected UUID GetTaskInventoryItem(string name)
6128 { 6538 {
6129 lock (m_host.TaskInventory) 6539 m_host.TaskInventory.LockItemsForRead(true);
6540 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6130 { 6541 {
6131 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6542 if (inv.Value.Name == name)
6132 { 6543 {
6133 if (inv.Value.Name == name) 6544 m_host.TaskInventory.LockItemsForRead(false);
6134 return inv.Key; 6545 return inv.Key;
6135 } 6546 }
6136 } 6547 }
6548 m_host.TaskInventory.LockItemsForRead(false);
6137 6549
6138 return UUID.Zero; 6550 return UUID.Zero;
6139 } 6551 }
@@ -6383,13 +6795,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6383 UUID av = new UUID(); 6795 UUID av = new UUID();
6384 if (!UUID.TryParse(avatar,out av)) 6796 if (!UUID.TryParse(avatar,out av))
6385 { 6797 {
6386 LSLError("First parameter to llDialog needs to be a key"); 6798 //LSLError("First parameter to llDialog needs to be a key");
6387 return; 6799 return;
6388 } 6800 }
6389 if (buttons.Length < 1) 6801 if (buttons.Length < 1)
6390 { 6802 {
6391 LSLError("No less than 1 button can be shown"); 6803 buttons.Add("OK");
6392 return;
6393 } 6804 }
6394 if (buttons.Length > 12) 6805 if (buttons.Length > 12)
6395 { 6806 {
@@ -6406,7 +6817,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6406 } 6817 }
6407 if (buttons.Data[i].ToString().Length > 24) 6818 if (buttons.Data[i].ToString().Length > 24)
6408 { 6819 {
6409 LSLError("button label cannot be longer than 24 characters"); 6820 llWhisper(ScriptBaseClass.DEBUG_CHANNEL, "button label cannot be longer than 24 characters");
6410 return; 6821 return;
6411 } 6822 }
6412 buts[i] = buttons.Data[i].ToString(); 6823 buts[i] = buttons.Data[i].ToString();
@@ -6470,22 +6881,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6470 } 6881 }
6471 6882
6472 // copy the first script found with this inventory name 6883 // copy the first script found with this inventory name
6473 lock (m_host.TaskInventory) 6884 TaskInventoryItem scriptItem = null;
6885 m_host.TaskInventory.LockItemsForRead(true);
6886 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6474 { 6887 {
6475 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6888 if (inv.Value.Name == name)
6476 { 6889 {
6477 if (inv.Value.Name == name) 6890 // make sure the object is a script
6891 if (10 == inv.Value.Type)
6478 { 6892 {
6479 // make sure the object is a script 6893 found = true;
6480 if (10 == inv.Value.Type) 6894 srcId = inv.Key;
6481 { 6895 scriptItem = inv.Value;
6482 found = true; 6896 break;
6483 srcId = inv.Key;
6484 break;
6485 }
6486 } 6897 }
6487 } 6898 }
6488 } 6899 }
6900 m_host.TaskInventory.LockItemsForRead(false);
6489 6901
6490 if (!found) 6902 if (!found)
6491 { 6903 {
@@ -6493,8 +6905,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6493 return; 6905 return;
6494 } 6906 }
6495 6907
6496 // the rest of the permission checks are done in RezScript, so check the pin there as well 6908 SceneObjectPart dest = World.GetSceneObjectPart(destId);
6497 World.RezScript(srcId, m_host, destId, pin, running, start_param); 6909 if (dest != null)
6910 {
6911 if ((scriptItem.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
6912 {
6913 // the rest of the permission checks are done in RezScript, so check the pin there as well
6914 World.RezScript(srcId, m_host, destId, pin, running, start_param);
6915
6916 if ((scriptItem.BasePermissions & (uint)PermissionMask.Copy) == 0)
6917 m_host.Inventory.RemoveInventoryItem(srcId);
6918 }
6919 }
6498 // this will cause the delay even if the script pin or permissions were wrong - seems ok 6920 // this will cause the delay even if the script pin or permissions were wrong - seems ok
6499 ScriptSleep(3000); 6921 ScriptSleep(3000);
6500 } 6922 }
@@ -6557,18 +6979,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6557 public LSL_String llMD5String(string src, int nonce) 6979 public LSL_String llMD5String(string src, int nonce)
6558 { 6980 {
6559 m_host.AddScriptLPS(1); 6981 m_host.AddScriptLPS(1);
6560 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString())); 6982 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
6561 } 6983 }
6562 6984
6563 public LSL_String llSHA1String(string src) 6985 public LSL_String llSHA1String(string src)
6564 { 6986 {
6565 m_host.AddScriptLPS(1); 6987 m_host.AddScriptLPS(1);
6566 return Util.SHA1Hash(src).ToLower(); 6988 return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
6567 } 6989 }
6568 6990
6569 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist) 6991 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist)
6570 { 6992 {
6571 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 6993 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6994 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
6995 return shapeBlock;
6572 6996
6573 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && 6997 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
6574 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && 6998 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
@@ -6644,6 +7068,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6644 7068
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) 7069 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 { 7070 {
7071 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7072 return;
7073
6647 ObjectShapePacket.ObjectDataBlock shapeBlock; 7074 ObjectShapePacket.ObjectDataBlock shapeBlock;
6648 7075
6649 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7076 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6693,6 +7120,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6693 7120
6694 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge) 7121 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge)
6695 { 7122 {
7123 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7124 return;
7125
6696 ObjectShapePacket.ObjectDataBlock shapeBlock; 7126 ObjectShapePacket.ObjectDataBlock shapeBlock;
6697 7127
6698 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7128 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6735,6 +7165,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6735 7165
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) 7166 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 { 7167 {
7168 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7169 return;
7170
6738 ObjectShapePacket.ObjectDataBlock shapeBlock; 7171 ObjectShapePacket.ObjectDataBlock shapeBlock;
6739 7172
6740 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7173 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);
@@ -6861,6 +7294,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6861 7294
6862 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type) 7295 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type)
6863 { 7296 {
7297 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7298 return;
7299
6864 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7300 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6865 UUID sculptId; 7301 UUID sculptId;
6866 7302
@@ -6876,13 +7312,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6876 shapeBlock.PathScaleX = 100; 7312 shapeBlock.PathScaleX = 100;
6877 shapeBlock.PathScaleY = 150; 7313 shapeBlock.PathScaleY = 150;
6878 7314
6879 if (type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER && 7315 if ((type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER) == 0 &&
6880 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE && 7316 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE) == 0 &&
6881 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE && 7317 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE) == 0 &&
6882 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) 7318 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) == 0)
6883 { 7319 {
6884 // default 7320 // default
6885 type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; 7321 type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
6886 } 7322 }
6887 7323
6888 // retain pathcurve 7324 // retain pathcurve
@@ -6901,32 +7337,87 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6901 ScriptSleep(200); 7337 ScriptSleep(200);
6902 } 7338 }
6903 7339
6904 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) 7340 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
6905 { 7341 {
6906 m_host.AddScriptLPS(1); 7342 m_host.AddScriptLPS(1);
6907 7343
6908 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7344 List<SceneObjectPart> parts = GetLinkParts(linknumber);
7345 List<ScenePresence> avatars = GetLinkAvatars(linknumber);
7346 if (parts.Count>0)
7347 {
7348 try
7349 {
7350 parts[0].ParentGroup.areUpdatesSuspended = true;
7351 foreach (SceneObjectPart part in parts)
7352 SetPrimParams(part, rules);
7353 }
7354 finally
7355 {
7356 parts[0].ParentGroup.areUpdatesSuspended = false;
7357 }
7358 }
7359 if (avatars.Count > 0)
7360 {
7361 foreach (ScenePresence avatar in avatars)
7362 SetPrimParams(avatar, rules);
7363 }
7364 }
6909 7365
6910 foreach (SceneObjectPart part in parts) 7366 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
6911 SetPrimParams(part, rules); 7367 {
6912 7368 llSetLinkPrimitiveParamsFast(linknumber, rules);
6913 ScriptSleep(200); 7369 ScriptSleep(200);
6914 } 7370 }
6915 7371
6916 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) 7372 protected void SetPrimParams(ScenePresence av, LSL_List rules)
6917 { 7373 {
6918 m_host.AddScriptLPS(1); 7374 //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
7375 //We only support PRIM_POSITION and PRIM_ROTATION
6919 7376
6920 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7377 int idx = 0;
6921 7378
6922 foreach (SceneObjectPart part in parts) 7379 while (idx < rules.Length)
6923 SetPrimParams(part, rules); 7380 {
7381 int code = rules.GetLSLIntegerItem(idx++);
7382
7383 int remain = rules.Length - idx;
7384
7385
7386
7387 switch (code)
7388 {
7389 case (int)ScriptBaseClass.PRIM_POSITION:
7390 if (remain < 1)
7391 return;
7392 LSL_Vector v;
7393 v = rules.GetVector3Item(idx++);
7394 av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
7395 av.SendAvatarDataToAllAgents();
7396
7397 break;
7398
7399 case (int)ScriptBaseClass.PRIM_ROTATION:
7400 if (remain < 1)
7401 return;
7402 LSL_Rotation r;
7403 r = rules.GetQuaternionItem(idx++);
7404 av.OffsetRotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
7405 av.SendAvatarDataToAllAgents();
7406 break;
7407 }
7408 }
6924 } 7409 }
6925 7410
6926 protected void SetPrimParams(SceneObjectPart part, LSL_List rules) 7411 protected void SetPrimParams(SceneObjectPart part, LSL_List rules)
6927 { 7412 {
7413 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7414 return;
7415
6928 int idx = 0; 7416 int idx = 0;
6929 7417
7418 bool positionChanged = false;
7419 LSL_Vector currentPosition = GetPartLocalPos(part);
7420
6930 while (idx < rules.Length) 7421 while (idx < rules.Length)
6931 { 7422 {
6932 int code = rules.GetLSLIntegerItem(idx++); 7423 int code = rules.GetLSLIntegerItem(idx++);
@@ -6935,7 +7426,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6935 7426
6936 int face; 7427 int face;
6937 LSL_Vector v; 7428 LSL_Vector v;
6938 7429
6939 switch (code) 7430 switch (code)
6940 { 7431 {
6941 case (int)ScriptBaseClass.PRIM_POSITION: 7432 case (int)ScriptBaseClass.PRIM_POSITION:
@@ -6943,7 +7434,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6943 return; 7434 return;
6944 7435
6945 v=rules.GetVector3Item(idx++); 7436 v=rules.GetVector3Item(idx++);
6946 SetPos(part, v); 7437 positionChanged = true;
7438 currentPosition = GetSetPosTarget(part, v, currentPosition);
6947 7439
6948 break; 7440 break;
6949 case (int)ScriptBaseClass.PRIM_SIZE: 7441 case (int)ScriptBaseClass.PRIM_SIZE:
@@ -7311,6 +7803,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7311 break; 7803 break;
7312 } 7804 }
7313 } 7805 }
7806
7807 if (positionChanged)
7808 {
7809 if (part.ParentGroup.RootPart == part)
7810 {
7811 SceneObjectGroup parent = part.ParentGroup;
7812 parent.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z));
7813 }
7814 else
7815 {
7816 part.OffsetPosition = new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z);
7817 SceneObjectGroup parent = part.ParentGroup;
7818 parent.HasGroupChanged = true;
7819 parent.ScheduleGroupForTerseUpdate();
7820 }
7821 }
7314 } 7822 }
7315 7823
7316 public LSL_String llStringToBase64(string str) 7824 public LSL_String llStringToBase64(string str)
@@ -7459,13 +7967,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7459 public LSL_Integer llGetNumberOfPrims() 7967 public LSL_Integer llGetNumberOfPrims()
7460 { 7968 {
7461 m_host.AddScriptLPS(1); 7969 m_host.AddScriptLPS(1);
7462 int avatarCount = 0; 7970 int avatarCount = m_host.ParentGroup.GetLinkedAvatars().Count;
7463 World.ForEachScenePresence(delegate(ScenePresence presence) 7971
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; 7972 return m_host.ParentGroup.PrimCount + avatarCount;
7470 } 7973 }
7471 7974
@@ -7481,55 +7984,98 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7481 m_host.AddScriptLPS(1); 7984 m_host.AddScriptLPS(1);
7482 UUID objID = UUID.Zero; 7985 UUID objID = UUID.Zero;
7483 LSL_List result = new LSL_List(); 7986 LSL_List result = new LSL_List();
7987
7988 // If the ID is not valid, return null result
7484 if (!UUID.TryParse(obj, out objID)) 7989 if (!UUID.TryParse(obj, out objID))
7485 { 7990 {
7486 result.Add(new LSL_Vector()); 7991 result.Add(new LSL_Vector());
7487 result.Add(new LSL_Vector()); 7992 result.Add(new LSL_Vector());
7488 return result; 7993 return result;
7489 } 7994 }
7995
7996 // Check if this is an attached prim. If so, replace
7997 // the UUID with the avatar UUID and report it's bounding box
7998 SceneObjectPart part = World.GetSceneObjectPart(objID);
7999 if (part != null && part.ParentGroup.IsAttachment)
8000 objID = part.ParentGroup.RootPart.AttachedAvatar;
8001
8002 // Find out if this is an avatar ID. If so, return it's box
7490 ScenePresence presence = World.GetScenePresence(objID); 8003 ScenePresence presence = World.GetScenePresence(objID);
7491 if (presence != null) 8004 if (presence != null)
7492 { 8005 {
7493 if (presence.ParentID == 0) // not sat on an object 8006 // As per LSL Wiki, there is no difference between sitting
8007 // and standing avatar since server 1.36
8008 LSL_Vector lower;
8009 LSL_Vector upper;
8010 if (presence.Animator.Animations.DefaultAnimation.AnimID
8011 == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
7494 { 8012 {
7495 LSL_Vector lower; 8013 // This is for ground sitting avatars
7496 LSL_Vector upper; 8014 float height = presence.Appearance.AvatarHeight / 2.66666667f;
7497 if (presence.Animator.Animations.DefaultAnimation.AnimID 8015 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
7498 == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) 8016 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 } 8017 }
7516 else 8018 else
7517 { 8019 {
7518 // sitting on an object so we need the bounding box of that 8020 // This is for standing/flying avatars
7519 // which should include the avatar so set the UUID to the 8021 float height = presence.Appearance.AvatarHeight / 2.0f;
7520 // UUID of the object the avatar is sat on and allow it to fall through 8022 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
7521 // to processing an object 8023 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
7522 SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
7523 objID = p.UUID;
7524 } 8024 }
8025
8026 // Adjust to the documented error offsets (see LSL Wiki)
8027 lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
8028 upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
8029
8030 if (lower.x > upper.x)
8031 lower.x = upper.x;
8032 if (lower.y > upper.y)
8033 lower.y = upper.y;
8034 if (lower.z > upper.z)
8035 lower.z = upper.z;
8036
8037 result.Add(lower);
8038 result.Add(upper);
8039 return result;
7525 } 8040 }
7526 SceneObjectPart part = World.GetSceneObjectPart(objID); 8041
8042 part = World.GetSceneObjectPart(objID);
7527 // Currently only works for single prims without a sitting avatar 8043 // Currently only works for single prims without a sitting avatar
7528 if (part != null) 8044 if (part != null)
7529 { 8045 {
7530 Vector3 halfSize = part.Scale / 2.0f; 8046 float minX;
7531 LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f); 8047 float maxX;
7532 LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z); 8048 float minY;
8049 float maxY;
8050 float minZ;
8051 float maxZ;
8052
8053 // This BBox is in sim coordinates, with the offset being
8054 // a contained point.
8055 Vector3[] offsets = World.GetCombinedBoundingBox(new List<SceneObjectGroup> { part.ParentGroup },
8056 out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
8057
8058 minX -= offsets[0].X;
8059 maxX -= offsets[0].X;
8060 minY -= offsets[0].Y;
8061 maxY -= offsets[0].Y;
8062 minZ -= offsets[0].Z;
8063 maxZ -= offsets[0].Z;
8064
8065 LSL_Vector lower;
8066 LSL_Vector upper;
8067
8068 // Adjust to the documented error offsets (see LSL Wiki)
8069 lower = new LSL_Vector(minX + 0.05f, minY + 0.05f, minZ + 0.05f);
8070 upper = new LSL_Vector(maxX - 0.05f, maxY - 0.05f, maxZ - 0.05f);
8071
8072 if (lower.x > upper.x)
8073 lower.x = upper.x;
8074 if (lower.y > upper.y)
8075 lower.y = upper.y;
8076 if (lower.z > upper.z)
8077 lower.z = upper.z;
8078
7533 result.Add(lower); 8079 result.Add(lower);
7534 result.Add(upper); 8080 result.Add(upper);
7535 return result; 8081 return result;
@@ -7609,13 +8155,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7609 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X, 8155 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
7610 part.AbsolutePosition.Y, 8156 part.AbsolutePosition.Y,
7611 part.AbsolutePosition.Z); 8157 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); 8158 res.Add(v);
7620 break; 8159 break;
7621 8160
@@ -7776,56 +8315,92 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7776 case (int)ScriptBaseClass.PRIM_BUMP_SHINY: 8315 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
7777 if (remain < 1) 8316 if (remain < 1)
7778 return res; 8317 return res;
7779 8318 face = (int)rules.GetLSLIntegerItem(idx++);
7780 face=(int)rules.GetLSLIntegerItem(idx++);
7781 8319
7782 tex = part.Shape.Textures; 8320 tex = part.Shape.Textures;
8321 int shiny;
7783 if (face == ScriptBaseClass.ALL_SIDES) 8322 if (face == ScriptBaseClass.ALL_SIDES)
7784 { 8323 {
7785 for (face = 0; face < GetNumberOfSides(part); face++) 8324 for (face = 0; face < GetNumberOfSides(part); face++)
7786 { 8325 {
7787 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8326 Shininess shinyness = tex.GetFace((uint)face).Shiny;
7788 // Convert Shininess to PRIM_SHINY_* 8327 if (shinyness == Shininess.High)
7789 res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); 8328 {
7790 // PRIM_BUMP_* 8329 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
7791 res.Add(new LSL_Integer((int)texface.Bump)); 8330 }
8331 else if (shinyness == Shininess.Medium)
8332 {
8333 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8334 }
8335 else if (shinyness == Shininess.Low)
8336 {
8337 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8338 }
8339 else
8340 {
8341 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8342 }
8343 res.Add(new LSL_Integer(shiny));
8344 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
7792 } 8345 }
7793 } 8346 }
7794 else 8347 else
7795 { 8348 {
7796 if (face >= 0 && face < GetNumberOfSides(part)) 8349 Shininess shinyness = tex.GetFace((uint)face).Shiny;
8350 if (shinyness == Shininess.High)
7797 { 8351 {
7798 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8352 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
7799 // Convert Shininess to PRIM_SHINY_*
7800 res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
7801 // PRIM_BUMP_*
7802 res.Add(new LSL_Integer((int)texface.Bump));
7803 } 8353 }
8354 else if (shinyness == Shininess.Medium)
8355 {
8356 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8357 }
8358 else if (shinyness == Shininess.Low)
8359 {
8360 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8361 }
8362 else
8363 {
8364 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8365 }
8366 res.Add(new LSL_Integer(shiny));
8367 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
7804 } 8368 }
7805 break; 8369 break;
7806 8370
7807 case (int)ScriptBaseClass.PRIM_FULLBRIGHT: 8371 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
7808 if (remain < 1) 8372 if (remain < 1)
7809 return res; 8373 return res;
7810 8374 face = (int)rules.GetLSLIntegerItem(idx++);
7811 face=(int)rules.GetLSLIntegerItem(idx++);
7812 8375
7813 tex = part.Shape.Textures; 8376 tex = part.Shape.Textures;
8377 int fullbright;
7814 if (face == ScriptBaseClass.ALL_SIDES) 8378 if (face == ScriptBaseClass.ALL_SIDES)
7815 { 8379 {
7816 for (face = 0; face < GetNumberOfSides(part); face++) 8380 for (face = 0; face < GetNumberOfSides(part); face++)
7817 { 8381 {
7818 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8382 if (tex.GetFace((uint)face).Fullbright == true)
7819 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); 8383 {
8384 fullbright = ScriptBaseClass.TRUE;
8385 }
8386 else
8387 {
8388 fullbright = ScriptBaseClass.FALSE;
8389 }
8390 res.Add(new LSL_Integer(fullbright));
7820 } 8391 }
7821 } 8392 }
7822 else 8393 else
7823 { 8394 {
7824 if (face >= 0 && face < GetNumberOfSides(part)) 8395 if (tex.GetFace((uint)face).Fullbright == true)
7825 { 8396 {
7826 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8397 fullbright = ScriptBaseClass.TRUE;
7827 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); 8398 }
8399 else
8400 {
8401 fullbright = ScriptBaseClass.FALSE;
7828 } 8402 }
8403 res.Add(new LSL_Integer(fullbright));
7829 } 8404 }
7830 break; 8405 break;
7831 8406
@@ -7847,27 +8422,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7847 break; 8422 break;
7848 8423
7849 case (int)ScriptBaseClass.PRIM_TEXGEN: 8424 case (int)ScriptBaseClass.PRIM_TEXGEN:
8425 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
7850 if (remain < 1) 8426 if (remain < 1)
7851 return res; 8427 return res;
7852 8428 face = (int)rules.GetLSLIntegerItem(idx++);
7853 face=(int)rules.GetLSLIntegerItem(idx++);
7854 8429
7855 tex = part.Shape.Textures; 8430 tex = part.Shape.Textures;
7856 if (face == ScriptBaseClass.ALL_SIDES) 8431 if (face == ScriptBaseClass.ALL_SIDES)
7857 { 8432 {
7858 for (face = 0; face < GetNumberOfSides(part); face++) 8433 for (face = 0; face < GetNumberOfSides(part); face++)
7859 { 8434 {
7860 MappingType texgen = tex.GetFace((uint)face).TexMapType; 8435 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
7861 // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc. 8436 {
7862 res.Add(new LSL_Integer((uint)texgen >> 1)); 8437 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8438 }
8439 else
8440 {
8441 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8442 }
7863 } 8443 }
7864 } 8444 }
7865 else 8445 else
7866 { 8446 {
7867 if (face >= 0 && face < GetNumberOfSides(part)) 8447 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
7868 { 8448 {
7869 MappingType texgen = tex.GetFace((uint)face).TexMapType; 8449 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
7870 res.Add(new LSL_Integer((uint)texgen >> 1)); 8450 }
8451 else
8452 {
8453 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
7871 } 8454 }
7872 } 8455 }
7873 break; 8456 break;
@@ -7890,28 +8473,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7890 case (int)ScriptBaseClass.PRIM_GLOW: 8473 case (int)ScriptBaseClass.PRIM_GLOW:
7891 if (remain < 1) 8474 if (remain < 1)
7892 return res; 8475 return res;
7893 8476 face = (int)rules.GetLSLIntegerItem(idx++);
7894 face=(int)rules.GetLSLIntegerItem(idx++);
7895 8477
7896 tex = part.Shape.Textures; 8478 tex = part.Shape.Textures;
8479 float primglow;
7897 if (face == ScriptBaseClass.ALL_SIDES) 8480 if (face == ScriptBaseClass.ALL_SIDES)
7898 { 8481 {
7899 for (face = 0; face < GetNumberOfSides(part); face++) 8482 for (face = 0; face < GetNumberOfSides(part); face++)
7900 { 8483 {
7901 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8484 primglow = tex.GetFace((uint)face).Glow;
7902 res.Add(new LSL_Float(texface.Glow)); 8485 res.Add(new LSL_Float(primglow));
7903 } 8486 }
7904 } 8487 }
7905 else 8488 else
7906 { 8489 {
7907 if (face >= 0 && face < GetNumberOfSides(part)) 8490 primglow = tex.GetFace((uint)face).Glow;
7908 { 8491 res.Add(new LSL_Float(primglow));
7909 Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
7910 res.Add(new LSL_Float(texface.Glow));
7911 }
7912 } 8492 }
7913 break; 8493 break;
7914
7915 case (int)ScriptBaseClass.PRIM_TEXT: 8494 case (int)ScriptBaseClass.PRIM_TEXT:
7916 Color4 textColor = part.GetTextColor(); 8495 Color4 textColor = part.GetTextColor();
7917 res.Add(part.Text); 8496 res.Add(part.Text);
@@ -8460,8 +9039,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8460 // The function returns an ordered list 9039 // The function returns an ordered list
8461 // representing the tokens found in the supplied 9040 // representing the tokens found in the supplied
8462 // sources string. If two successive tokenizers 9041 // sources string. If two successive tokenizers
8463 // are encountered, then a NULL entry is added 9042 // are encountered, then a null-string entry is
8464 // to the list. 9043 // added to the list.
8465 // 9044 //
8466 // It is a precondition that the source and 9045 // It is a precondition that the source and
8467 // toekizer lisst are non-null. If they are null, 9046 // toekizer lisst are non-null. If they are null,
@@ -8469,7 +9048,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8469 // while their lengths are being determined. 9048 // while their lengths are being determined.
8470 // 9049 //
8471 // A small amount of working memoryis required 9050 // A small amount of working memoryis required
8472 // of approximately 8*#tokenizers. 9051 // of approximately 8*#tokenizers + 8*srcstrlen.
8473 // 9052 //
8474 // There are many ways in which this function 9053 // There are many ways in which this function
8475 // can be implemented, this implementation is 9054 // can be implemented, this implementation is
@@ -8485,155 +9064,124 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8485 // and eliminates redundant tokenizers as soon 9064 // and eliminates redundant tokenizers as soon
8486 // as is possible. 9065 // as is possible.
8487 // 9066 //
8488 // The implementation tries to avoid any copying 9067 // The implementation tries to minimize temporary
8489 // of arrays or other objects. 9068 // garbage generation.
8490 // </remarks> 9069 // </remarks>
8491 9070
8492 private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls) 9071 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
8493 { 9072 {
8494 int beginning = 0; 9073 return ParseString2List(src, separators, spacers, true);
8495 int srclen = src.Length; 9074 }
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 9075
8510 LSL_List tokens = new LSL_List(); 9076 private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
9077 {
9078 int srclen = src.Length;
9079 int seplen = separators.Length;
9080 object[] separray = separators.Data;
9081 int spclen = spacers.Length;
9082 object[] spcarray = spacers.Data;
9083 int dellen = 0;
9084 string[] delarray = new string[seplen+spclen];
8511 9085
8512 // All entries are initially valid 9086 int outlen = 0;
9087 string[] outarray = new string[srclen*2+1];
8513 9088
8514 for (int i = 0; i < mlen; i++) 9089 int i, j;
8515 active[i] = true; 9090 string d;
8516 9091
8517 offset[mlen] = srclen; 9092 m_host.AddScriptLPS(1);
8518 9093
8519 while (beginning < srclen) 9094 /*
9095 * Convert separator and spacer lists to C# strings.
9096 * Also filter out null strings so we don't hang.
9097 */
9098 for (i = 0; i < seplen; i ++)
8520 { 9099 {
9100 d = separray[i].ToString();
9101 if (d.Length > 0)
9102 {
9103 delarray[dellen++] = d;
9104 }
9105 }
9106 seplen = dellen;
8521 9107
8522 best = mlen; // as bad as it gets 9108 for (i = 0; i < spclen; i ++)
9109 {
9110 d = spcarray[i].ToString();
9111 if (d.Length > 0)
9112 {
9113 delarray[dellen++] = d;
9114 }
9115 }
8523 9116
8524 // Scan for separators 9117 /*
9118 * Scan through source string from beginning to end.
9119 */
9120 for (i = 0;;)
9121 {
8525 9122
8526 for (j = 0; j < seplen; j++) 9123 /*
9124 * Find earliest delimeter in src starting at i (if any).
9125 */
9126 int earliestDel = -1;
9127 int earliestSrc = srclen;
9128 string earliestStr = null;
9129 for (j = 0; j < dellen; j ++)
8527 { 9130 {
8528 if (separray[j].ToString() == String.Empty) 9131 d = delarray[j];
8529 active[j] = false; 9132 if (d != null)
8530
8531 if (active[j])
8532 { 9133 {
8533 // scan all of the markers 9134 int index = src.IndexOf(d, i);
8534 if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1) 9135 if (index < 0)
8535 { 9136 {
8536 // not present at all 9137 delarray[j] = null; // delim nowhere in src, don't check it anymore
8537 active[j] = false;
8538 } 9138 }
8539 else 9139 else if (index < earliestSrc)
8540 { 9140 {
8541 // present and correct 9141 earliestSrc = index; // where delimeter starts in source string
8542 if (offset[j] < offset[best]) 9142 earliestDel = j; // where delimeter is in delarray[]
8543 { 9143 earliestStr = d; // the delimeter string from delarray[]
8544 // closest so far 9144 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 } 9145 }
8550 } 9146 }
8551 } 9147 }
8552 9148
8553 // Scan for spacers 9149 /*
8554 9150 * Output source string starting at i through start of earliest delimeter.
8555 if (offset[best] != beginning) 9151 */
9152 if (keepNulls || (earliestSrc > i))
8556 { 9153 {
8557 for (j = seplen; (j < mlen) && (offset[best] > beginning); j++) 9154 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 } 9155 }
8582 9156
8583 // This is the normal exit from the scanning loop 9157 /*
9158 * If no delimeter found at or after i, we're done scanning.
9159 */
9160 if (earliestDel < 0) break;
8584 9161
8585 if (best == mlen) 9162 /*
9163 * If delimeter was a spacer, output the spacer.
9164 */
9165 if (earliestDel >= seplen)
8586 { 9166 {
8587 // no markers were found on this pass 9167 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 } 9168 }
8593 9169
8594 // Otherwise we just add the newly delimited token 9170 /*
8595 // and recalculate where the search should continue. 9171 * Look at rest of src string following delimeter.
8596 if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0)) 9172 */
8597 tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning))); 9173 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 } 9174 }
8611 9175
8612 // This an awkward an not very intuitive boundary case. If the 9176 /*
8613 // last substring is a tokenizer, then there is an implied trailing 9177 * 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 9178 */
8615 // arduous. Alternatively the 'break' could be replced with a return 9179 object[] outlist = new object[outlen];
8616 // but that's shabby programming. 9180 for (i = 0; i < outlen; i ++)
8617
8618 if ((beginning == srclen) && (keepNulls))
8619 { 9181 {
8620 if (srclen != 0) 9182 outlist[i] = new LSL_String(outarray[i]);
8621 tokens.Add(new LSL_String(""));
8622 } 9183 }
8623 9184 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 } 9185 }
8638 9186
8639 public LSL_Integer llGetObjectPermMask(int mask) 9187 public LSL_Integer llGetObjectPermMask(int mask)
@@ -8710,28 +9258,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8710 { 9258 {
8711 m_host.AddScriptLPS(1); 9259 m_host.AddScriptLPS(1);
8712 9260
8713 lock (m_host.TaskInventory) 9261 m_host.TaskInventory.LockItemsForRead(true);
9262 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8714 { 9263 {
8715 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9264 if (inv.Value.Name == item)
8716 { 9265 {
8717 if (inv.Value.Name == item) 9266 m_host.TaskInventory.LockItemsForRead(false);
9267 switch (mask)
8718 { 9268 {
8719 switch (mask) 9269 case 0:
8720 { 9270 return (int)inv.Value.BasePermissions;
8721 case 0: 9271 case 1:
8722 return (int)inv.Value.BasePermissions; 9272 return (int)inv.Value.CurrentPermissions;
8723 case 1: 9273 case 2:
8724 return (int)inv.Value.CurrentPermissions; 9274 return (int)inv.Value.GroupPermissions;
8725 case 2: 9275 case 3:
8726 return (int)inv.Value.GroupPermissions; 9276 return (int)inv.Value.EveryonePermissions;
8727 case 3: 9277 case 4:
8728 return (int)inv.Value.EveryonePermissions; 9278 return (int)inv.Value.NextPermissions;
8729 case 4:
8730 return (int)inv.Value.NextPermissions;
8731 }
8732 } 9279 }
8733 } 9280 }
8734 } 9281 }
9282 m_host.TaskInventory.LockItemsForRead(false);
8735 9283
8736 return -1; 9284 return -1;
8737 } 9285 }
@@ -8778,16 +9326,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8778 { 9326 {
8779 m_host.AddScriptLPS(1); 9327 m_host.AddScriptLPS(1);
8780 9328
8781 lock (m_host.TaskInventory) 9329 m_host.TaskInventory.LockItemsForRead(true);
9330 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8782 { 9331 {
8783 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9332 if (inv.Value.Name == item)
8784 { 9333 {
8785 if (inv.Value.Name == item) 9334 m_host.TaskInventory.LockItemsForRead(false);
8786 { 9335 return inv.Value.CreatorID.ToString();
8787 return inv.Value.CreatorID.ToString();
8788 }
8789 } 9336 }
8790 } 9337 }
9338 m_host.TaskInventory.LockItemsForRead(false);
8791 9339
8792 llSay(0, "No item name '" + item + "'"); 9340 llSay(0, "No item name '" + item + "'");
8793 9341
@@ -8935,7 +9483,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8935 } 9483 }
8936 9484
8937 /// <summary> 9485 /// <summary>
8938 /// illListReplaceList removes the sub-list defined by the inclusive indices 9486 /// llListReplaceList removes the sub-list defined by the inclusive indices
8939 /// start and end and inserts the src list in its place. The inclusive 9487 /// 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 9488 /// 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 9489 /// if the indices are within the bounds of the existing list. I.e. 2,2
@@ -8992,16 +9540,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8992 // based upon end. Note that if end exceeds the upper 9540 // based upon end. Note that if end exceeds the upper
8993 // bound in this case, the entire destination list 9541 // bound in this case, the entire destination list
8994 // is removed. 9542 // is removed.
8995 else 9543 else if (start == 0)
8996 { 9544 {
8997 if (end + 1 < dest.Length) 9545 if (end + 1 < dest.Length)
8998 {
8999 return src + dest.GetSublist(end + 1, -1); 9546 return src + dest.GetSublist(end + 1, -1);
9000 }
9001 else 9547 else
9002 {
9003 return src; 9548 return src;
9004 } 9549 }
9550 else // Start < 0
9551 {
9552 if (end + 1 < dest.Length)
9553 return dest.GetSublist(end + 1, -1);
9554 else
9555 return new LSL_List();
9005 } 9556 }
9006 } 9557 }
9007 // Finally, if start > end, we strip away a prefix and 9558 // Finally, if start > end, we strip away a prefix and
@@ -9052,17 +9603,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9052 int width = 0; 9603 int width = 0;
9053 int height = 0; 9604 int height = 0;
9054 9605
9055 ParcelMediaCommandEnum? commandToSend = null; 9606 uint commandToSend = 0;
9056 float time = 0.0f; // default is from start 9607 float time = 0.0f; // default is from start
9057 9608
9058 ScenePresence presence = null; 9609 ScenePresence presence = null;
9059 9610
9060 for (int i = 0; i < commandList.Data.Length; i++) 9611 for (int i = 0; i < commandList.Data.Length; i++)
9061 { 9612 {
9062 ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i]; 9613 uint command = (uint)(commandList.GetLSLIntegerItem(i));
9063 switch (command) 9614 switch (command)
9064 { 9615 {
9065 case ParcelMediaCommandEnum.Agent: 9616 case (uint)ParcelMediaCommandEnum.Agent:
9066 // we send only to one agent 9617 // we send only to one agent
9067 if ((i + 1) < commandList.Length) 9618 if ((i + 1) < commandList.Length)
9068 { 9619 {
@@ -9079,25 +9630,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9079 } 9630 }
9080 break; 9631 break;
9081 9632
9082 case ParcelMediaCommandEnum.Loop: 9633 case (uint)ParcelMediaCommandEnum.Loop:
9083 loop = 1; 9634 loop = 1;
9084 commandToSend = command; 9635 commandToSend = command;
9085 update = true; //need to send the media update packet to set looping 9636 update = true; //need to send the media update packet to set looping
9086 break; 9637 break;
9087 9638
9088 case ParcelMediaCommandEnum.Play: 9639 case (uint)ParcelMediaCommandEnum.Play:
9089 loop = 0; 9640 loop = 0;
9090 commandToSend = command; 9641 commandToSend = command;
9091 update = true; //need to send the media update packet to make sure it doesn't loop 9642 update = true; //need to send the media update packet to make sure it doesn't loop
9092 break; 9643 break;
9093 9644
9094 case ParcelMediaCommandEnum.Pause: 9645 case (uint)ParcelMediaCommandEnum.Pause:
9095 case ParcelMediaCommandEnum.Stop: 9646 case (uint)ParcelMediaCommandEnum.Stop:
9096 case ParcelMediaCommandEnum.Unload: 9647 case (uint)ParcelMediaCommandEnum.Unload:
9097 commandToSend = command; 9648 commandToSend = command;
9098 break; 9649 break;
9099 9650
9100 case ParcelMediaCommandEnum.Url: 9651 case (uint)ParcelMediaCommandEnum.Url:
9101 if ((i + 1) < commandList.Length) 9652 if ((i + 1) < commandList.Length)
9102 { 9653 {
9103 if (commandList.Data[i + 1] is LSL_String) 9654 if (commandList.Data[i + 1] is LSL_String)
@@ -9110,7 +9661,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9110 } 9661 }
9111 break; 9662 break;
9112 9663
9113 case ParcelMediaCommandEnum.Texture: 9664 case (uint)ParcelMediaCommandEnum.Texture:
9114 if ((i + 1) < commandList.Length) 9665 if ((i + 1) < commandList.Length)
9115 { 9666 {
9116 if (commandList.Data[i + 1] is LSL_String) 9667 if (commandList.Data[i + 1] is LSL_String)
@@ -9123,7 +9674,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9123 } 9674 }
9124 break; 9675 break;
9125 9676
9126 case ParcelMediaCommandEnum.Time: 9677 case (uint)ParcelMediaCommandEnum.Time:
9127 if ((i + 1) < commandList.Length) 9678 if ((i + 1) < commandList.Length)
9128 { 9679 {
9129 if (commandList.Data[i + 1] is LSL_Float) 9680 if (commandList.Data[i + 1] is LSL_Float)
@@ -9135,7 +9686,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9135 } 9686 }
9136 break; 9687 break;
9137 9688
9138 case ParcelMediaCommandEnum.AutoAlign: 9689 case (uint)ParcelMediaCommandEnum.AutoAlign:
9139 if ((i + 1) < commandList.Length) 9690 if ((i + 1) < commandList.Length)
9140 { 9691 {
9141 if (commandList.Data[i + 1] is LSL_Integer) 9692 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9149,7 +9700,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9149 } 9700 }
9150 break; 9701 break;
9151 9702
9152 case ParcelMediaCommandEnum.Type: 9703 case (uint)ParcelMediaCommandEnum.Type:
9153 if ((i + 1) < commandList.Length) 9704 if ((i + 1) < commandList.Length)
9154 { 9705 {
9155 if (commandList.Data[i + 1] is LSL_String) 9706 if (commandList.Data[i + 1] is LSL_String)
@@ -9162,7 +9713,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9162 } 9713 }
9163 break; 9714 break;
9164 9715
9165 case ParcelMediaCommandEnum.Desc: 9716 case (uint)ParcelMediaCommandEnum.Desc:
9166 if ((i + 1) < commandList.Length) 9717 if ((i + 1) < commandList.Length)
9167 { 9718 {
9168 if (commandList.Data[i + 1] is LSL_String) 9719 if (commandList.Data[i + 1] is LSL_String)
@@ -9175,7 +9726,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9175 } 9726 }
9176 break; 9727 break;
9177 9728
9178 case ParcelMediaCommandEnum.Size: 9729 case (uint)ParcelMediaCommandEnum.Size:
9179 if ((i + 2) < commandList.Length) 9730 if ((i + 2) < commandList.Length)
9180 { 9731 {
9181 if (commandList.Data[i + 1] is LSL_Integer) 9732 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9245,7 +9796,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9245 } 9796 }
9246 } 9797 }
9247 9798
9248 if (commandToSend != null) 9799 if (commandToSend != 0)
9249 { 9800 {
9250 // the commandList contained a start/stop/... command, too 9801 // the commandList contained a start/stop/... command, too
9251 if (presence == null) 9802 if (presence == null)
@@ -9282,7 +9833,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9282 9833
9283 if (aList.Data[i] != null) 9834 if (aList.Data[i] != null)
9284 { 9835 {
9285 switch ((ParcelMediaCommandEnum) aList.Data[i]) 9836 switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
9286 { 9837 {
9287 case ParcelMediaCommandEnum.Url: 9838 case ParcelMediaCommandEnum.Url:
9288 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL)); 9839 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL));
@@ -9325,16 +9876,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9325 { 9876 {
9326 m_host.AddScriptLPS(1); 9877 m_host.AddScriptLPS(1);
9327 9878
9328 lock (m_host.TaskInventory) 9879 m_host.TaskInventory.LockItemsForRead(true);
9880 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
9329 { 9881 {
9330 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9882 if (inv.Value.Name == name)
9331 { 9883 {
9332 if (inv.Value.Name == name) 9884 m_host.TaskInventory.LockItemsForRead(false);
9333 { 9885 return inv.Value.Type;
9334 return inv.Value.Type;
9335 }
9336 } 9886 }
9337 } 9887 }
9888 m_host.TaskInventory.LockItemsForRead(false);
9338 9889
9339 return -1; 9890 return -1;
9340 } 9891 }
@@ -9345,15 +9896,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9345 9896
9346 if (quick_pay_buttons.Data.Length < 4) 9897 if (quick_pay_buttons.Data.Length < 4)
9347 { 9898 {
9348 LSLError("List must have at least 4 elements"); 9899 int x;
9349 return; 9900 for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
9901 {
9902 quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
9903 }
9350 } 9904 }
9351 m_host.ParentGroup.RootPart.PayPrice[0]=price; 9905 int[] nPrice = new int[5];
9352 9906 nPrice[0] = price;
9353 m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0]; 9907 nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
9354 m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1]; 9908 nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
9355 m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2]; 9909 nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
9356 m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3]; 9910 nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
9911 m_host.ParentGroup.RootPart.PayPrice = nPrice;
9357 m_host.ParentGroup.HasGroupChanged = true; 9912 m_host.ParentGroup.HasGroupChanged = true;
9358 } 9913 }
9359 9914
@@ -9365,17 +9920,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9365 if (invItemID == UUID.Zero) 9920 if (invItemID == UUID.Zero)
9366 return new LSL_Vector(); 9921 return new LSL_Vector();
9367 9922
9368 lock (m_host.TaskInventory) 9923 m_host.TaskInventory.LockItemsForRead(true);
9924 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
9369 { 9925 {
9370 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 9926 m_host.TaskInventory.LockItemsForRead(false);
9371 return new LSL_Vector(); 9927 return new LSL_Vector();
9928 }
9372 9929
9373 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 9930 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9374 { 9931 {
9375 ShoutError("No permissions to track the camera"); 9932 ShoutError("No permissions to track the camera");
9376 return new LSL_Vector(); 9933 m_host.TaskInventory.LockItemsForRead(false);
9377 } 9934 return new LSL_Vector();
9378 } 9935 }
9936 m_host.TaskInventory.LockItemsForRead(false);
9379 9937
9380 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 9938 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
9381 if (presence != null) 9939 if (presence != null)
@@ -9393,17 +9951,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9393 if (invItemID == UUID.Zero) 9951 if (invItemID == UUID.Zero)
9394 return new LSL_Rotation(); 9952 return new LSL_Rotation();
9395 9953
9396 lock (m_host.TaskInventory) 9954 m_host.TaskInventory.LockItemsForRead(true);
9955 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
9397 { 9956 {
9398 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 9957 m_host.TaskInventory.LockItemsForRead(false);
9399 return new LSL_Rotation(); 9958 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 } 9959 }
9960 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9961 {
9962 ShoutError("No permissions to track the camera");
9963 m_host.TaskInventory.LockItemsForRead(false);
9964 return new LSL_Rotation();
9965 }
9966 m_host.TaskInventory.LockItemsForRead(false);
9407 9967
9408 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 9968 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
9409 if (presence != null) 9969 if (presence != null)
@@ -9465,8 +10025,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9465 { 10025 {
9466 m_host.AddScriptLPS(1); 10026 m_host.AddScriptLPS(1);
9467 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 10027 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0);
9468 if (detectedParams == null) return; // only works on the first detected avatar 10028 if (detectedParams == null)
9469 10029 {
10030 if (m_host.IsAttachment == true)
10031 {
10032 detectedParams = new DetectParams();
10033 detectedParams.Key = m_host.OwnerID;
10034 }
10035 else
10036 {
10037 return;
10038 }
10039 }
10040
9470 ScenePresence avatar = World.GetScenePresence(detectedParams.Key); 10041 ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
9471 if (avatar != null) 10042 if (avatar != null)
9472 { 10043 {
@@ -9474,6 +10045,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9474 new Vector3((float)pos.x, (float)pos.y, (float)pos.z), 10045 new Vector3((float)pos.x, (float)pos.y, (float)pos.z),
9475 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z)); 10046 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z));
9476 } 10047 }
10048
9477 ScriptSleep(1000); 10049 ScriptSleep(1000);
9478 } 10050 }
9479 10051
@@ -9566,14 +10138,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9566 if (objectID == UUID.Zero) return; 10138 if (objectID == UUID.Zero) return;
9567 10139
9568 UUID agentID; 10140 UUID agentID;
9569 lock (m_host.TaskInventory) 10141 m_host.TaskInventory.LockItemsForRead(true);
9570 { 10142 // 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 10143 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9572 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9573 10144
9574 if (agentID == UUID.Zero) return; 10145 if (agentID == UUID.Zero)
9575 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 10146 {
10147 m_host.TaskInventory.LockItemsForRead(false);
10148 return;
9576 } 10149 }
10150 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
10151 {
10152 m_host.TaskInventory.LockItemsForRead(false);
10153 return;
10154 }
10155 m_host.TaskInventory.LockItemsForRead(false);
9577 10156
9578 ScenePresence presence = World.GetScenePresence(agentID); 10157 ScenePresence presence = World.GetScenePresence(agentID);
9579 10158
@@ -9582,12 +10161,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9582 10161
9583 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>(); 10162 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
9584 object[] data = rules.Data; 10163 object[] data = rules.Data;
9585 for (int i = 0; i < data.Length; ++i) { 10164 for (int i = 0; i < data.Length; ++i)
10165 {
9586 int type = Convert.ToInt32(data[i++].ToString()); 10166 int type = Convert.ToInt32(data[i++].ToString());
9587 if (i >= data.Length) break; // odd number of entries => ignore the last 10167 if (i >= data.Length) break; // odd number of entries => ignore the last
9588 10168
9589 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3) 10169 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
9590 switch (type) { 10170 switch (type)
10171 {
9591 case ScriptBaseClass.CAMERA_FOCUS: 10172 case ScriptBaseClass.CAMERA_FOCUS:
9592 case ScriptBaseClass.CAMERA_FOCUS_OFFSET: 10173 case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
9593 case ScriptBaseClass.CAMERA_POSITION: 10174 case ScriptBaseClass.CAMERA_POSITION:
@@ -9623,12 +10204,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9623 10204
9624 // we need the permission first, to know which avatar we want to clear the camera for 10205 // we need the permission first, to know which avatar we want to clear the camera for
9625 UUID agentID; 10206 UUID agentID;
9626 lock (m_host.TaskInventory) 10207 m_host.TaskInventory.LockItemsForRead(true);
10208 agentID = m_host.TaskInventory[invItemID].PermsGranter;
10209 if (agentID == UUID.Zero)
10210 {
10211 m_host.TaskInventory.LockItemsForRead(false);
10212 return;
10213 }
10214 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
9627 { 10215 {
9628 agentID = m_host.TaskInventory[invItemID].PermsGranter; 10216 m_host.TaskInventory.LockItemsForRead(false);
9629 if (agentID == UUID.Zero) return; 10217 return;
9630 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
9631 } 10218 }
10219 m_host.TaskInventory.LockItemsForRead(false);
9632 10220
9633 ScenePresence presence = World.GetScenePresence(agentID); 10221 ScenePresence presence = World.GetScenePresence(agentID);
9634 10222
@@ -9695,19 +10283,65 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9695 public LSL_String llXorBase64StringsCorrect(string str1, string str2) 10283 public LSL_String llXorBase64StringsCorrect(string str1, string str2)
9696 { 10284 {
9697 m_host.AddScriptLPS(1); 10285 m_host.AddScriptLPS(1);
9698 string ret = String.Empty; 10286
9699 string src1 = llBase64ToString(str1); 10287 if (str1 == String.Empty)
9700 string src2 = llBase64ToString(str2); 10288 return String.Empty;
9701 int c = 0; 10289 if (str2 == String.Empty)
9702 for (int i = 0; i < src1.Length; i++) 10290 return str1;
10291
10292 int len = str2.Length;
10293 if ((len % 4) != 0) // LL is EVIL!!!!
9703 { 10294 {
9704 ret += (char) (src1[i] ^ src2[c]); 10295 while (str2.EndsWith("="))
10296 str2 = str2.Substring(0, str2.Length - 1);
9705 10297
9706 c++; 10298 len = str2.Length;
9707 if (c >= src2.Length) 10299 int mod = len % 4;
9708 c = 0; 10300
10301 if (mod == 1)
10302 str2 = str2.Substring(0, str2.Length - 1);
10303 else if (mod == 2)
10304 str2 += "==";
10305 else if (mod == 3)
10306 str2 += "=";
10307 }
10308
10309 byte[] data1;
10310 byte[] data2;
10311 try
10312 {
10313 data1 = Convert.FromBase64String(str1);
10314 data2 = Convert.FromBase64String(str2);
9709 } 10315 }
9710 return llStringToBase64(ret); 10316 catch (Exception)
10317 {
10318 return new LSL_String(String.Empty);
10319 }
10320
10321 byte[] d2 = new Byte[data1.Length];
10322 int pos = 0;
10323
10324 if (data1.Length <= data2.Length)
10325 {
10326 Array.Copy(data2, 0, d2, 0, data1.Length);
10327 }
10328 else
10329 {
10330 while (pos < data1.Length)
10331 {
10332 len = data1.Length - pos;
10333 if (len > data2.Length)
10334 len = data2.Length;
10335
10336 Array.Copy(data2, 0, d2, pos, len);
10337 pos += len;
10338 }
10339 }
10340
10341 for (pos = 0 ; pos < data1.Length ; pos++ )
10342 data1[pos] ^= d2[pos];
10343
10344 return Convert.ToBase64String(data1);
9711 } 10345 }
9712 10346
9713 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body) 10347 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
@@ -9766,12 +10400,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9766 Regex r = new Regex(authregex); 10400 Regex r = new Regex(authregex);
9767 int[] gnums = r.GetGroupNumbers(); 10401 int[] gnums = r.GetGroupNumbers();
9768 Match m = r.Match(url); 10402 Match m = r.Match(url);
9769 if (m.Success) { 10403 if (m.Success)
9770 for (int i = 1; i < gnums.Length; i++) { 10404 {
10405 for (int i = 1; i < gnums.Length; i++)
10406 {
9771 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]]; 10407 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
9772 //CaptureCollection cc = g.Captures; 10408 //CaptureCollection cc = g.Captures;
9773 } 10409 }
9774 if (m.Groups.Count == 5) { 10410 if (m.Groups.Count == 5)
10411 {
9775 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString()))); 10412 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(); 10413 url = m.Groups[1].ToString() + m.Groups[4].ToString();
9777 } 10414 }
@@ -9883,7 +10520,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9883 { 10520 {
9884 foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners()) 10521 foreach (KeyValuePair<UUID, int> detectedParams in land.GetLandObjectOwners())
9885 { 10522 {
9886 ret.Add(detectedParams.Key.ToString()); 10523 ret.Add(new LSL_String(detectedParams.Key.ToString()));
9887 ret.Add(detectedParams.Value); 10524 ret.Add(detectedParams.Value);
9888 } 10525 }
9889 } 10526 }
@@ -10067,15 +10704,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10067 10704
10068 internal UUID ScriptByName(string name) 10705 internal UUID ScriptByName(string name)
10069 { 10706 {
10070 lock (m_host.TaskInventory) 10707 m_host.TaskInventory.LockItemsForRead(true);
10708
10709 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
10071 { 10710 {
10072 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 10711 if (item.Type == 10 && item.Name == name)
10073 { 10712 {
10074 if (item.Type == 10 && item.Name == name) 10713 m_host.TaskInventory.LockItemsForRead(false);
10075 return item.ItemID; 10714 return item.ItemID;
10076 } 10715 }
10077 } 10716 }
10078 10717
10718 m_host.TaskInventory.LockItemsForRead(false);
10719
10079 return UUID.Zero; 10720 return UUID.Zero;
10080 } 10721 }
10081 10722
@@ -10116,6 +10757,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10116 { 10757 {
10117 m_host.AddScriptLPS(1); 10758 m_host.AddScriptLPS(1);
10118 10759
10760 //Clone is thread safe
10119 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 10761 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10120 10762
10121 UUID assetID = UUID.Zero; 10763 UUID assetID = UUID.Zero;
@@ -10178,6 +10820,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10178 { 10820 {
10179 m_host.AddScriptLPS(1); 10821 m_host.AddScriptLPS(1);
10180 10822
10823 //Clone is thread safe
10181 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 10824 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10182 10825
10183 UUID assetID = UUID.Zero; 10826 UUID assetID = UUID.Zero;
@@ -10258,15 +10901,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10258 return GetLinkPrimitiveParams(obj, rules); 10901 return GetLinkPrimitiveParams(obj, rules);
10259 } 10902 }
10260 10903
10261 public void print(string str) 10904 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
10262 { 10905 {
10263 // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print 10906 List<SceneObjectPart> parts = GetLinkParts(link);
10264 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL"); 10907 if (parts.Count < 1)
10265 if (ossl != null) 10908 return 0;
10266 { 10909
10267 ossl.CheckThreatLevel(ThreatLevel.High, "print"); 10910 return GetNumberOfSides(parts[0]);
10268 m_log.Info("LSL print():" + str);
10269 }
10270 } 10911 }
10271 10912
10272 private string Name2Username(string name) 10913 private string Name2Username(string name)
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 47c7915..3afedc7 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -205,7 +205,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
205 // Is the sensor type is AGENT and not SCRIPTED then include agents 205 // Is the sensor type is AGENT and not SCRIPTED then include agents
206 if ((ts.type & (AGENT | AGENT_BY_USERNAME)) != 0 && (ts.type & SCRIPTED) == 0) 206 if ((ts.type & (AGENT | AGENT_BY_USERNAME)) != 0 && (ts.type & SCRIPTED) == 0)
207 { 207 {
208 sensedEntities.AddRange(doAgentSensor(ts)); 208 sensedEntities.AddRange(doAgentSensor(ts));
209 } 209 }
210 210
211 // If SCRIPTED or PASSIVE or ACTIVE check objects 211 // If SCRIPTED or PASSIVE or ACTIVE check objects
@@ -302,7 +302,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
302 float dy; 302 float dy;
303 float dz; 303 float dz;
304 304
305 Quaternion q = SensePoint.RotationOffset; 305// Quaternion q = SensePoint.RotationOffset;
306 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation!
306 if (SensePoint.ParentGroup.RootPart.IsAttachment) 307 if (SensePoint.ParentGroup.RootPart.IsAttachment)
307 { 308 {
308 // In attachments, the sensor cone always orients with the 309 // In attachments, the sensor cone always orients with the
@@ -310,6 +311,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
310 // in mouselook. 311 // in mouselook.
311 312
312 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar); 313 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar);
314 fromRegionPos = avatar.AbsolutePosition;
313 q = avatar.Rotation; 315 q = avatar.Rotation;
314 } 316 }
315 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 317 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
@@ -423,6 +425,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
423 SceneObjectPart SensePoint = ts.host; 425 SceneObjectPart SensePoint = ts.host;
424 Vector3 fromRegionPos = SensePoint.AbsolutePosition; 426 Vector3 fromRegionPos = SensePoint.AbsolutePosition;
425 Quaternion q = SensePoint.RotationOffset; 427 Quaternion q = SensePoint.RotationOffset;
428 if (SensePoint.ParentGroup.RootPart.IsAttachment)
429 {
430 // In attachments, the sensor cone always orients with the
431 // avatar rotation. This may include a nonzero elevation if
432 // in mouselook.
433
434 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar);
435 fromRegionPos = avatar.AbsolutePosition;
436 q = avatar.Rotation;
437 }
426 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 438 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
427 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); 439 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
428 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); 440 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 654ea81..0ae2388 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
@@ -402,7 +402,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
402 LSL_Vector llWind(LSL_Vector offset); 402 LSL_Vector llWind(LSL_Vector offset);
403 LSL_String llXorBase64Strings(string str1, string str2); 403 LSL_String llXorBase64Strings(string str1, string str2);
404 LSL_String llXorBase64StringsCorrect(string str1, string str2); 404 LSL_String llXorBase64StringsCorrect(string str1, string str2);
405 void print(string str); 405 LSL_Integer llGetLinkNumberOfSides(LSL_Integer link);
406 406
407 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 407 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
408 LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 408 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 9377cda..5f94ff5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -281,6 +281,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
281 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART 281 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART
282 public const int CHANGED_MEDIA = 2048; 282 public const int CHANGED_MEDIA = 2048;
283 public const int CHANGED_ANIMATION = 16384; 283 public const int CHANGED_ANIMATION = 16384;
284 public const int CHANGED_POSITION = 32768;
284 public const int TYPE_INVALID = 0; 285 public const int TYPE_INVALID = 0;
285 public const int TYPE_INTEGER = 1; 286 public const int TYPE_INTEGER = 1;
286 public const int TYPE_FLOAT = 2; 287 public const int TYPE_FLOAT = 2;
@@ -374,6 +375,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
374 public const int PRIM_SCULPT_TYPE_TORUS = 2; 375 public const int PRIM_SCULPT_TYPE_TORUS = 2;
375 public const int PRIM_SCULPT_TYPE_PLANE = 3; 376 public const int PRIM_SCULPT_TYPE_PLANE = 3;
376 public const int PRIM_SCULPT_TYPE_CYLINDER = 4; 377 public const int PRIM_SCULPT_TYPE_CYLINDER = 4;
378 public const int PRIM_SCULPT_FLAG_INVERT = 64;
379 public const int PRIM_SCULPT_FLAG_MIRROR = 128;
377 380
378 public const int MASK_BASE = 0; 381 public const int MASK_BASE = 0;
379 public const int MASK_OWNER = 1; 382 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 303d75e..63cac9a 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();
@@ -1868,9 +1870,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1868 return m_LSL_Functions.llClearPrimMedia(face); 1870 return m_LSL_Functions.llClearPrimMedia(face);
1869 } 1871 }
1870 1872
1871 public void print(string str) 1873 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
1872 { 1874 {
1873 m_LSL_Functions.print(str); 1875 return m_LSL_Functions.llGetLinkNumberOfSides(link);
1874 } 1876 }
1875 } 1877 }
1876} 1878}
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}