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