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.cs2243
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs46
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs7
-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.cs3
-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.cs11
-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.cs357
19 files changed, 2108 insertions, 968 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 53c9297..eadf69c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -28,10 +28,12 @@
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;
34using System.Text.RegularExpressions; 35using System.Text.RegularExpressions;
36using System.Timers;
35using Nini.Config; 37using Nini.Config;
36using log4net; 38using log4net;
37using OpenMetaverse; 39using OpenMetaverse;
@@ -44,6 +46,7 @@ using OpenSim.Region.CoreModules.World.Land;
44using OpenSim.Region.CoreModules.World.Terrain; 46using OpenSim.Region.CoreModules.World.Terrain;
45using OpenSim.Region.Framework.Interfaces; 47using OpenSim.Region.Framework.Interfaces;
46using OpenSim.Region.Framework.Scenes; 48using OpenSim.Region.Framework.Scenes;
49using OpenSim.Region.Framework.Scenes.Serialization;
47using OpenSim.Region.Framework.Scenes.Animation; 50using OpenSim.Region.Framework.Scenes.Animation;
48using OpenSim.Region.Physics.Manager; 51using OpenSim.Region.Physics.Manager;
49using OpenSim.Region.ScriptEngine.Shared; 52using OpenSim.Region.ScriptEngine.Shared;
@@ -65,6 +68,7 @@ using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
65using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; 68using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
66using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; 69using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
67using System.Reflection; 70using System.Reflection;
71using Timer = System.Timers.Timer;
68 72
69namespace OpenSim.Region.ScriptEngine.Shared.Api 73namespace OpenSim.Region.ScriptEngine.Shared.Api
70{ 74{
@@ -81,7 +85,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
81 /// </summary> 85 /// </summary>
82 public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi 86 public class LSL_Api : MarshalByRefObject, ILSL_Api, IScriptApi
83 { 87 {
84 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 88// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
85 protected IScriptEngine m_ScriptEngine; 89 protected IScriptEngine m_ScriptEngine;
86 protected SceneObjectPart m_host; 90 protected SceneObjectPart m_host;
87 protected uint m_localID; 91 protected uint m_localID;
@@ -99,16 +103,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
99 protected int m_notecardLineReadCharsMax = 255; 103 protected int m_notecardLineReadCharsMax = 255;
100 protected int m_scriptConsoleChannel = 0; 104 protected int m_scriptConsoleChannel = 0;
101 protected bool m_scriptConsoleChannelEnabled = false; 105 protected bool m_scriptConsoleChannelEnabled = false;
106 protected bool m_debuggerSafe = false;
102 protected IUrlModule m_UrlModule = null; 107 protected IUrlModule m_UrlModule = null;
103 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = 108 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache =
104 new Dictionary<UUID, UserInfoCacheEntry>(); 109 new Dictionary<UUID, UserInfoCacheEntry>();
105 110
111 protected Timer m_ShoutSayTimer;
112 protected int m_SayShoutCount = 0;
113
106 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 114 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
107 { 115 {
116 m_ShoutSayTimer = new Timer(1000);
117 m_ShoutSayTimer.Elapsed += SayShoutTimerElapsed;
118 m_ShoutSayTimer.AutoReset = true;
119 m_ShoutSayTimer.Start();
120
108 m_ScriptEngine = ScriptEngine; 121 m_ScriptEngine = ScriptEngine;
109 m_host = host; 122 m_host = host;
110 m_localID = localID; 123 m_localID = localID;
111 m_itemID = itemID; 124 m_itemID = itemID;
125 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
112 126
113 m_ScriptDelayFactor = 127 m_ScriptDelayFactor =
114 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); 128 m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f);
@@ -161,6 +175,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
161 get { return m_ScriptEngine.World; } 175 get { return m_ScriptEngine.World; }
162 } 176 }
163 177
178 [DebuggerNonUserCode]
164 public void state(string newState) 179 public void state(string newState)
165 { 180 {
166 m_ScriptEngine.SetState(m_itemID, newState); 181 m_ScriptEngine.SetState(m_itemID, newState);
@@ -170,6 +185,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
170 /// Reset the named script. The script must be present 185 /// Reset the named script. The script must be present
171 /// in the same prim. 186 /// in the same prim.
172 /// </summary> 187 /// </summary>
188 [DebuggerNonUserCode]
173 public void llResetScript() 189 public void llResetScript()
174 { 190 {
175 m_host.AddScriptLPS(1); 191 m_host.AddScriptLPS(1);
@@ -226,9 +242,62 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
226 } 242 }
227 } 243 }
228 244
245 public List<ScenePresence> GetLinkAvatars(int linkType)
246 {
247 List<ScenePresence> ret = new List<ScenePresence>();
248 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
249 return ret;
250
251 List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
252
253 switch (linkType)
254 {
255 case ScriptBaseClass.LINK_SET:
256 return avs;
257
258 case ScriptBaseClass.LINK_ROOT:
259 return ret;
260
261 case ScriptBaseClass.LINK_ALL_OTHERS:
262 return avs;
263
264 case ScriptBaseClass.LINK_ALL_CHILDREN:
265 return avs;
266
267 case ScriptBaseClass.LINK_THIS:
268 return ret;
269
270 default:
271 if (linkType < 0)
272 return ret;
273
274 int partCount = m_host.ParentGroup.GetPartCount();
275
276 if (linkType <= partCount)
277 {
278 return ret;
279 }
280 else
281 {
282 linkType = linkType - partCount;
283 if (linkType > avs.Count)
284 {
285 return ret;
286 }
287 else
288 {
289 ret.Add(avs[linkType-1]);
290 return ret;
291 }
292 }
293 }
294 }
295
229 public List<SceneObjectPart> GetLinkParts(int linkType) 296 public List<SceneObjectPart> GetLinkParts(int linkType)
230 { 297 {
231 List<SceneObjectPart> ret = new List<SceneObjectPart>(); 298 List<SceneObjectPart> ret = new List<SceneObjectPart>();
299 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
300 return ret;
232 ret.Add(m_host); 301 ret.Add(m_host);
233 302
234 switch (linkType) 303 switch (linkType)
@@ -275,40 +344,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
275 protected UUID InventorySelf() 344 protected UUID InventorySelf()
276 { 345 {
277 UUID invItemID = new UUID(); 346 UUID invItemID = new UUID();
278 347 bool unlock = false;
279 lock (m_host.TaskInventory) 348 if (!m_host.TaskInventory.IsReadLockedByMe())
349 {
350 m_host.TaskInventory.LockItemsForRead(true);
351 unlock = true;
352 }
353 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
280 { 354 {
281 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 355 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
282 { 356 {
283 if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID) 357 invItemID = inv.Key;
284 { 358 break;
285 invItemID = inv.Key;
286 break;
287 }
288 } 359 }
289 } 360 }
290 361 if (unlock)
362 {
363 m_host.TaskInventory.LockItemsForRead(false);
364 }
291 return invItemID; 365 return invItemID;
292 } 366 }
293 367
294 protected UUID InventoryKey(string name, int type) 368 protected UUID InventoryKey(string name, int type)
295 { 369 {
296 m_host.AddScriptLPS(1); 370 m_host.AddScriptLPS(1);
297 371 m_host.TaskInventory.LockItemsForRead(true);
298 lock (m_host.TaskInventory) 372
373 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
299 { 374 {
300 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 375 if (inv.Value.Name == name)
301 { 376 {
302 if (inv.Value.Name == name) 377 m_host.TaskInventory.LockItemsForRead(false);
378
379 if (inv.Value.Type != type)
303 { 380 {
304 if (inv.Value.Type != type) 381 return UUID.Zero;
305 return UUID.Zero;
306
307 return inv.Value.AssetID;
308 } 382 }
383
384 return inv.Value.AssetID;
309 } 385 }
310 } 386 }
311 387
388 m_host.TaskInventory.LockItemsForRead(false);
312 return UUID.Zero; 389 return UUID.Zero;
313 } 390 }
314 391
@@ -316,17 +393,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
316 { 393 {
317 m_host.AddScriptLPS(1); 394 m_host.AddScriptLPS(1);
318 395
319 lock (m_host.TaskInventory) 396
397 m_host.TaskInventory.LockItemsForRead(true);
398
399 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
320 { 400 {
321 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 401 if (inv.Value.Name == name)
322 { 402 {
323 if (inv.Value.Name == name) 403 m_host.TaskInventory.LockItemsForRead(false);
324 { 404 return inv.Value.AssetID;
325 return inv.Value.AssetID;
326 }
327 } 405 }
328 } 406 }
329 407
408 m_host.TaskInventory.LockItemsForRead(false);
409
410
330 return UUID.Zero; 411 return UUID.Zero;
331 } 412 }
332 413
@@ -468,26 +549,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
468 549
469 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke 550 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
470 551
471 // Old implementation of llRot2Euler. Normalization not required as Atan2 function will 552 // Utility function for llRot2Euler
472 // only return values >= -PI (-180 degrees) and <= PI (180 degrees). 553
554 // normalize an angle between -PI and PI (-180 to +180 degrees)
555 protected double NormalizeAngle(double angle)
556 {
557 if (angle > -Math.PI && angle < Math.PI)
558 return angle;
559
560 int numPis = (int)(Math.PI / angle);
561 double remainder = angle - Math.PI * numPis;
562 if (numPis % 2 == 1)
563 return Math.PI - angle;
564 return remainder;
565 }
473 566
474 public LSL_Vector llRot2Euler(LSL_Rotation r) 567 public LSL_Vector llRot2Euler(LSL_Rotation q1)
475 { 568 {
476 m_host.AddScriptLPS(1); 569 m_host.AddScriptLPS(1);
477 //This implementation is from http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions. ckrinke 570 LSL_Vector eul = new LSL_Vector();
478 LSL_Rotation t = new LSL_Rotation(r.x * r.x, r.y * r.y, r.z * r.z, r.s * r.s); 571
479 double m = (t.x + t.y + t.z + t.s); 572 double sqw = q1.s*q1.s;
480 if (m == 0) return new LSL_Vector(); 573 double sqx = q1.x*q1.x;
481 double n = 2 * (r.y * r.s + r.x * r.z); 574 double sqy = q1.z*q1.z;
482 double p = m * m - n * n; 575 double sqz = q1.y*q1.y;
483 if (p > 0) 576 double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
484 return new LSL_Vector(Math.Atan2(2.0 * (r.x * r.s - r.y * r.z), (-t.x - t.y + t.z + t.s)), 577 double test = q1.x*q1.z + q1.y*q1.s;
485 Math.Atan2(n, Math.Sqrt(p)), 578 if (test > 0.4999*unit) { // singularity at north pole
486 Math.Atan2(2.0 * (r.z * r.s - r.x * r.y), (t.x - t.y - t.z + t.s))); 579 eul.z = 2 * Math.Atan2(q1.x,q1.s);
487 else if (n > 0) 580 eul.y = Math.PI/2;
488 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)); 581 eul.x = 0;
489 else 582 return eul;
490 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 }
584 if (test < -0.4999*unit) { // singularity at south pole
585 eul.z = -2 * Math.Atan2(q1.x,q1.s);
586 eul.y = -Math.PI/2;
587 eul.x = 0;
588 return eul;
589 }
590 eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
591 eul.y = Math.Asin(2*test/unit);
592 eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
593 return eul;
491 } 594 }
492 595
493 /* From wiki: 596 /* From wiki:
@@ -689,77 +792,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
689 { 792 {
690 //A and B should both be normalized 793 //A and B should both be normalized
691 m_host.AddScriptLPS(1); 794 m_host.AddScriptLPS(1);
692 LSL_Rotation rotBetween; 795 /* This method is more accurate than the SL one, and thus causes problems
693 // Check for zero vectors. If either is zero, return zero rotation. Otherwise, 796 for scripts that deal with the SL inaccuracy around 180-degrees -.- .._.
694 // continue calculation. 797
695 if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f)) 798 double dotProduct = LSL_Vector.Dot(a, b);
799 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
800 double magProduct = LSL_Vector.Mag(a) * LSL_Vector.Mag(b);
801 double angle = Math.Acos(dotProduct / magProduct);
802 LSL_Vector axis = LSL_Vector.Norm(crossProduct);
803 double s = Math.Sin(angle / 2);
804
805 double x = axis.x * s;
806 double y = axis.y * s;
807 double z = axis.z * s;
808 double w = Math.Cos(angle / 2);
809
810 if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w))
811 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
812
813 return new LSL_Rotation((float)x, (float)y, (float)z, (float)w);
814 */
815
816 // This method mimics the 180 errors found in SL
817 // See www.euclideanspace.com... angleBetween
818 LSL_Vector vec_a = a;
819 LSL_Vector vec_b = b;
820
821 // Eliminate zero length
822 LSL_Float vec_a_mag = LSL_Vector.Mag(vec_a);
823 LSL_Float vec_b_mag = LSL_Vector.Mag(vec_b);
824 if (vec_a_mag < 0.00001 ||
825 vec_b_mag < 0.00001)
696 { 826 {
697 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); 827 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
698 } 828 }
699 else 829
830 // Normalize
831 vec_a = llVecNorm(vec_a);
832 vec_b = llVecNorm(vec_b);
833
834 // Calculate axis and rotation angle
835 LSL_Vector axis = vec_a % vec_b;
836 LSL_Float cos_theta = vec_a * vec_b;
837
838 // Check if parallel
839 if (cos_theta > 0.99999)
700 { 840 {
701 a = LSL_Vector.Norm(a); 841 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
702 b = LSL_Vector.Norm(b); 842 }
703 double dotProduct = LSL_Vector.Dot(a, b); 843
704 // There are two degenerate cases possible. These are for vectors 180 or 844 // Check if anti-parallel
705 // 0 degrees apart. These have to be detected and handled individually. 845 else if (cos_theta < -0.99999)
706 // 846 {
707 // Check for vectors 180 degrees apart. 847 LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (vec_a.x / (vec_a * vec_a) * vec_a);
708 // A dot product of -1 would mean the angle between vectors is 180 degrees. 848 if (LSL_Vector.Mag(orthog_axis) < 0.000001) orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
709 if (dotProduct < -0.9999999f) 849 return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
710 { 850 }
711 // First assume X axis is orthogonal to the vectors. 851 else // other rotation
712 LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f); 852 {
713 orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a)); 853 LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
714 // Check for near zero vector. A very small non-zero number here will create 854 axis = llVecNorm(axis);
715 // a rotation in an undesired direction. 855 double x, y, z, s, t;
716 if (LSL_Vector.Mag(orthoVector) > 0.0001) 856 s = Math.Cos(theta);
717 { 857 t = Math.Sin(theta);
718 rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f); 858 x = axis.x * t;
719 } 859 y = axis.y * t;
720 // If the magnitude of the vector was near zero, then assume the X axis is not 860 z = axis.z * t;
721 // orthogonal and use the Z axis instead. 861 return new LSL_Rotation(x,y,z,s);
722 else
723 {
724 // Set 180 z rotation.
725 rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f);
726 }
727 }
728 // Check for parallel vectors.
729 // A dot product of 1 would mean the angle between vectors is 0 degrees.
730 else if (dotProduct > 0.9999999f)
731 {
732 // Set zero rotation.
733 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
734 }
735 else
736 {
737 // All special checks have been performed so get the axis of rotation.
738 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
739 // Quarternion s value is the length of the unit vector + dot product.
740 double qs = 1.0 + dotProduct;
741 rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs);
742 // Normalize the rotation.
743 double mag = LSL_Rotation.Mag(rotBetween);
744 // We shouldn't have to worry about a divide by zero here. The qs value will be
745 // non-zero because we already know if we're here, then the dotProduct is not -1 so
746 // qs will not be zero. Also, we've already handled the input vectors being zero so the
747 // crossProduct vector should also not be zero.
748 rotBetween.x = rotBetween.x / mag;
749 rotBetween.y = rotBetween.y / mag;
750 rotBetween.z = rotBetween.z / mag;
751 rotBetween.s = rotBetween.s / mag;
752 // Check for undefined values and set zero rotation if any found. This code might not actually be required
753 // any longer since zero vectors are checked for at the top.
754 if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s))
755 {
756 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
757 }
758 }
759 } 862 }
760 return rotBetween;
761 } 863 }
762 864
763 public void llWhisper(int channelID, string text) 865 public void llWhisper(int channelID, string text)
764 { 866 {
765 m_host.AddScriptLPS(1); 867 m_host.AddScriptLPS(1);
@@ -779,6 +881,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
779 { 881 {
780 m_host.AddScriptLPS(1); 882 m_host.AddScriptLPS(1);
781 883
884 if (channelID == 0)
885 m_SayShoutCount++;
886
887 if (m_SayShoutCount >= 11)
888 ScriptSleep(2000);
889
782 if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel)) 890 if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
783 { 891 {
784 Console.WriteLine(text); 892 Console.WriteLine(text);
@@ -801,6 +909,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
801 { 909 {
802 m_host.AddScriptLPS(1); 910 m_host.AddScriptLPS(1);
803 911
912 if (channelID == 0)
913 m_SayShoutCount++;
914
915 if (m_SayShoutCount >= 11)
916 ScriptSleep(2000);
917
804 if (text.Length > 1023) 918 if (text.Length > 1023)
805 text = text.Substring(0, 1023); 919 text = text.Substring(0, 1023);
806 920
@@ -1101,10 +1215,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1101 return detectedParams.TouchUV; 1215 return detectedParams.TouchUV;
1102 } 1216 }
1103 1217
1218 [DebuggerNonUserCode]
1104 public virtual void llDie() 1219 public virtual void llDie()
1105 { 1220 {
1106 m_host.AddScriptLPS(1); 1221 m_host.AddScriptLPS(1);
1107 throw new SelfDeleteException(); 1222 if (!m_host.ParentGroup.IsAttachment) throw new SelfDeleteException();
1108 } 1223 }
1109 1224
1110 public LSL_Float llGround(LSL_Vector offset) 1225 public LSL_Float llGround(LSL_Vector offset)
@@ -1177,6 +1292,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1177 1292
1178 public void llSetStatus(int status, int value) 1293 public void llSetStatus(int status, int value)
1179 { 1294 {
1295 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
1296 return;
1180 m_host.AddScriptLPS(1); 1297 m_host.AddScriptLPS(1);
1181 1298
1182 int statusrotationaxis = 0; 1299 int statusrotationaxis = 0;
@@ -1406,6 +1523,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1406 { 1523 {
1407 m_host.AddScriptLPS(1); 1524 m_host.AddScriptLPS(1);
1408 1525
1526 SetColor(m_host, color, face);
1527 }
1528
1529 protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
1530 {
1531 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1532 return;
1533
1534 Primitive.TextureEntry tex = part.Shape.Textures;
1535 Color4 texcolor;
1536 if (face >= 0 && face < GetNumberOfSides(part))
1537 {
1538 texcolor = tex.CreateFace((uint)face).RGBA;
1539 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1540 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1541 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1542 tex.FaceTextures[face].RGBA = texcolor;
1543 part.UpdateTexture(tex);
1544 return;
1545 }
1546 else if (face == ScriptBaseClass.ALL_SIDES)
1547 {
1548 for (uint i = 0; i < GetNumberOfSides(part); i++)
1549 {
1550 if (tex.FaceTextures[i] != null)
1551 {
1552 texcolor = tex.FaceTextures[i].RGBA;
1553 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1554 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1555 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1556 tex.FaceTextures[i].RGBA = texcolor;
1557 }
1558 texcolor = tex.DefaultTexture.RGBA;
1559 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1560 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1561 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1562 tex.DefaultTexture.RGBA = texcolor;
1563 }
1564 part.UpdateTexture(tex);
1565 return;
1566 }
1567
1409 if (face == ScriptBaseClass.ALL_SIDES) 1568 if (face == ScriptBaseClass.ALL_SIDES)
1410 face = SceneObjectPart.ALL_SIDES; 1569 face = SceneObjectPart.ALL_SIDES;
1411 1570
@@ -1414,6 +1573,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1414 1573
1415 public void SetTexGen(SceneObjectPart part, int face,int style) 1574 public void SetTexGen(SceneObjectPart part, int face,int style)
1416 { 1575 {
1576 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1577 return;
1578
1417 Primitive.TextureEntry tex = part.Shape.Textures; 1579 Primitive.TextureEntry tex = part.Shape.Textures;
1418 MappingType textype; 1580 MappingType textype;
1419 textype = MappingType.Default; 1581 textype = MappingType.Default;
@@ -1444,6 +1606,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1444 1606
1445 public void SetGlow(SceneObjectPart part, int face, float glow) 1607 public void SetGlow(SceneObjectPart part, int face, float glow)
1446 { 1608 {
1609 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1610 return;
1611
1447 Primitive.TextureEntry tex = part.Shape.Textures; 1612 Primitive.TextureEntry tex = part.Shape.Textures;
1448 if (face >= 0 && face < GetNumberOfSides(part)) 1613 if (face >= 0 && face < GetNumberOfSides(part))
1449 { 1614 {
@@ -1469,6 +1634,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1469 1634
1470 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump) 1635 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
1471 { 1636 {
1637 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1638 return;
1472 1639
1473 Shininess sval = new Shininess(); 1640 Shininess sval = new Shininess();
1474 1641
@@ -1519,6 +1686,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1519 1686
1520 public void SetFullBright(SceneObjectPart part, int face, bool bright) 1687 public void SetFullBright(SceneObjectPart part, int face, bool bright)
1521 { 1688 {
1689 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1690 return;
1691
1522 Primitive.TextureEntry tex = part.Shape.Textures; 1692 Primitive.TextureEntry tex = part.Shape.Textures;
1523 if (face >= 0 && face < GetNumberOfSides(part)) 1693 if (face >= 0 && face < GetNumberOfSides(part))
1524 { 1694 {
@@ -1579,13 +1749,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1579 m_host.AddScriptLPS(1); 1749 m_host.AddScriptLPS(1);
1580 1750
1581 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1751 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1582 1752 if (parts.Count > 0)
1583 foreach (SceneObjectPart part in parts) 1753 {
1584 SetAlpha(part, alpha, face); 1754 try
1755 {
1756 parts[0].ParentGroup.areUpdatesSuspended = true;
1757 foreach (SceneObjectPart part in parts)
1758 SetAlpha(part, alpha, face);
1759 }
1760 finally
1761 {
1762 parts[0].ParentGroup.areUpdatesSuspended = false;
1763 }
1764 }
1585 } 1765 }
1586 1766
1587 protected void SetAlpha(SceneObjectPart part, double alpha, int face) 1767 protected void SetAlpha(SceneObjectPart part, double alpha, int face)
1588 { 1768 {
1769 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1770 return;
1771
1589 Primitive.TextureEntry tex = part.Shape.Textures; 1772 Primitive.TextureEntry tex = part.Shape.Textures;
1590 Color4 texcolor; 1773 Color4 texcolor;
1591 if (face >= 0 && face < GetNumberOfSides(part)) 1774 if (face >= 0 && face < GetNumberOfSides(part))
@@ -1638,7 +1821,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1638 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction, 1821 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
1639 float wind, float tension, LSL_Vector Force) 1822 float wind, float tension, LSL_Vector Force)
1640 { 1823 {
1641 if (part == null) 1824 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1642 return; 1825 return;
1643 1826
1644 if (flexi) 1827 if (flexi)
@@ -1673,7 +1856,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1673 /// <param name="falloff"></param> 1856 /// <param name="falloff"></param>
1674 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff) 1857 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
1675 { 1858 {
1676 if (part == null) 1859 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1677 return; 1860 return;
1678 1861
1679 if (light) 1862 if (light)
@@ -1750,15 +1933,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1750 m_host.AddScriptLPS(1); 1933 m_host.AddScriptLPS(1);
1751 1934
1752 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1935 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1753 1936 if (parts.Count > 0)
1754 foreach (SceneObjectPart part in parts) 1937 {
1755 SetTexture(part, texture, face); 1938 try
1756 1939 {
1940 parts[0].ParentGroup.areUpdatesSuspended = true;
1941 foreach (SceneObjectPart part in parts)
1942 SetTexture(part, texture, face);
1943 }
1944 finally
1945 {
1946 parts[0].ParentGroup.areUpdatesSuspended = false;
1947 }
1948 }
1757 ScriptSleep(200); 1949 ScriptSleep(200);
1758 } 1950 }
1759 1951
1760 protected void SetTexture(SceneObjectPart part, string texture, int face) 1952 protected void SetTexture(SceneObjectPart part, string texture, int face)
1761 { 1953 {
1954 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1955 return;
1956
1762 UUID textureID = new UUID(); 1957 UUID textureID = new UUID();
1763 1958
1764 textureID = InventoryKey(texture, (int)AssetType.Texture); 1959 textureID = InventoryKey(texture, (int)AssetType.Texture);
@@ -1803,6 +1998,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1803 1998
1804 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) 1999 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
1805 { 2000 {
2001 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2002 return;
2003
1806 Primitive.TextureEntry tex = part.Shape.Textures; 2004 Primitive.TextureEntry tex = part.Shape.Textures;
1807 if (face >= 0 && face < GetNumberOfSides(part)) 2005 if (face >= 0 && face < GetNumberOfSides(part))
1808 { 2006 {
@@ -1839,6 +2037,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1839 2037
1840 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) 2038 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
1841 { 2039 {
2040 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2041 return;
2042
1842 Primitive.TextureEntry tex = part.Shape.Textures; 2043 Primitive.TextureEntry tex = part.Shape.Textures;
1843 if (face >= 0 && face < GetNumberOfSides(part)) 2044 if (face >= 0 && face < GetNumberOfSides(part))
1844 { 2045 {
@@ -1875,6 +2076,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1875 2076
1876 protected void RotateTexture(SceneObjectPart part, double rotation, int face) 2077 protected void RotateTexture(SceneObjectPart part, double rotation, int face)
1877 { 2078 {
2079 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2080 return;
2081
1878 Primitive.TextureEntry tex = part.Shape.Textures; 2082 Primitive.TextureEntry tex = part.Shape.Textures;
1879 if (face >= 0 && face < GetNumberOfSides(part)) 2083 if (face >= 0 && face < GetNumberOfSides(part))
1880 { 2084 {
@@ -1958,10 +2162,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1958 return end; 2162 return end;
1959 } 2163 }
1960 2164
1961 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos) 2165 protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos)
1962 { 2166 {
2167 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2168 return fromPos;
2169
1963 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos) 2170 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos)
1964 LSL_Vector currentPos = GetPartLocalPos(part); 2171
1965 2172
1966 float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y); 2173 float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
1967 bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true); 2174 bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
@@ -1970,14 +2177,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1970 { 2177 {
1971 if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0) 2178 if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
1972 targetPos.z = ground; 2179 targetPos.z = ground;
2180 }
2181 LSL_Vector real_vec = SetPosAdjust(fromPos, targetPos);
2182
2183 return real_vec;
2184 }
2185
2186 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos)
2187 {
2188 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2189 return;
2190
2191 LSL_Vector currentPos = GetPartLocalPos(part);
2192 LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos);
2193
2194 if (part.ParentGroup.RootPart == part)
2195 {
1973 SceneObjectGroup parent = part.ParentGroup; 2196 SceneObjectGroup parent = part.ParentGroup;
1974 LSL_Vector real_vec = SetPosAdjust(currentPos, targetPos); 2197 parent.UpdateGroupPosition(new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z));
1975 parent.UpdateGroupPosition(new Vector3((float)real_vec.x, (float)real_vec.y, (float)real_vec.z));
1976 } 2198 }
1977 else 2199 else
1978 { 2200 {
1979 LSL_Vector rel_vec = SetPosAdjust(currentPos, targetPos); 2201 part.OffsetPosition = new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z);
1980 part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z);
1981 SceneObjectGroup parent = part.ParentGroup; 2202 SceneObjectGroup parent = part.ParentGroup;
1982 parent.HasGroupChanged = true; 2203 parent.HasGroupChanged = true;
1983 parent.ScheduleGroupForTerseUpdate(); 2204 parent.ScheduleGroupForTerseUpdate();
@@ -2028,9 +2249,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2028 m_host.AddScriptLPS(1); 2249 m_host.AddScriptLPS(1);
2029 2250
2030 // try to let this work as in SL... 2251 // try to let this work as in SL...
2031 if (m_host.ParentID == 0) 2252 if (m_host.LinkNum < 2)
2032 { 2253 {
2033 // special case: If we are root, rotate complete SOG to new rotation 2254 // Special case: If we are root, rotate complete SOG to new
2255 // rotation.
2256 // We are root if the link number is 0 (single prim) or 1
2257 // (root prim). ParentID may be nonzero in attachments and
2258 // using it would cause attachments and HUDs to rotate
2259 // to the wrong positions.
2034 SetRot(m_host, Rot2Quaternion(rot)); 2260 SetRot(m_host, Rot2Quaternion(rot));
2035 } 2261 }
2036 else 2262 else
@@ -2055,6 +2281,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2055 2281
2056 protected void SetRot(SceneObjectPart part, Quaternion rot) 2282 protected void SetRot(SceneObjectPart part, Quaternion rot)
2057 { 2283 {
2284 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2285 return;
2286
2058 part.UpdateRotation(rot); 2287 part.UpdateRotation(rot);
2059 // Update rotation does not move the object in the physics scene if it's a linkset. 2288 // Update rotation does not move the object in the physics scene if it's a linkset.
2060 2289
@@ -2680,12 +2909,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2680 2909
2681 m_host.AddScriptLPS(1); 2910 m_host.AddScriptLPS(1);
2682 2911
2912 m_host.TaskInventory.LockItemsForRead(true);
2683 TaskInventoryItem item = m_host.TaskInventory[invItemID]; 2913 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2684 2914 m_host.TaskInventory.LockItemsForRead(false);
2685 lock (m_host.TaskInventory)
2686 {
2687 item = m_host.TaskInventory[invItemID];
2688 }
2689 2915
2690 if (item.PermsGranter == UUID.Zero) 2916 if (item.PermsGranter == UUID.Zero)
2691 return 0; 2917 return 0;
@@ -2760,6 +2986,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2760 if (dist > m_ScriptDistanceFactor * 10.0f) 2986 if (dist > m_ScriptDistanceFactor * 10.0f)
2761 return; 2987 return;
2762 2988
2989 //Clone is thread-safe
2763 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 2990 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
2764 2991
2765 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory) 2992 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory)
@@ -2820,6 +3047,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2820 3047
2821 public void llLookAt(LSL_Vector target, double strength, double damping) 3048 public void llLookAt(LSL_Vector target, double strength, double damping)
2822 { 3049 {
3050 /*
2823 m_host.AddScriptLPS(1); 3051 m_host.AddScriptLPS(1);
2824 // Determine where we are looking from 3052 // Determine where we are looking from
2825 LSL_Vector from = llGetPos(); 3053 LSL_Vector from = llGetPos();
@@ -2839,10 +3067,54 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2839 // the angles of rotation in radians into rotation value 3067 // the angles of rotation in radians into rotation value
2840 3068
2841 LSL_Types.Quaternion rot = llEuler2Rot(angle); 3069 LSL_Types.Quaternion rot = llEuler2Rot(angle);
2842 Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s); 3070
2843 m_host.startLookAt(rotation, (float)damping, (float)strength); 3071 // This would only work if your physics system contains an APID controller:
3072 // Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
3073 // m_host.startLookAt(rotation, (float)damping, (float)strength);
3074
2844 // Orient the object to the angle calculated 3075 // Orient the object to the angle calculated
2845 //llSetRot(rot); 3076 llSetRot(rot);
3077 */
3078
3079 //The above code, while nice, doesn't replicate the behaviour of SL and tends to "roll" the object.
3080 //There's probably a smarter way of doing this, my rotation math-fu is weak.
3081 // http://bugs.meta7.com/view.php?id=28
3082 // - Tom
3083
3084 /* And the following does not do the job either. It has to be performed inside the ODE glue-code. -.- .._.
3085 LSL_Rotation newrot = llGetRot() * llRotBetween(new LSL_Vector(1.0d, 0.0d, 0.0d) * llGetRot(), new LSL_Vector(0.0d, 0.0d, -1.0d));
3086 llSetRot(newrot * llRotBetween(new LSL_Vector(0.0d,0.0d,1.0d) * newrot, target - llGetPos()));
3087 */
3088 if (m_host.PhysActor != null && !m_host.PhysActor.IsPhysical)
3089 {
3090 // Part is non-phys, convert this to a llSetRot()
3091 Vector3 tgt = new Vector3((float)target.x, (float)target.y, (float)target.z);
3092 Vector3 dir = tgt - m_host.GroupPosition;
3093 dir.Normalize();
3094 float tzrot = (float)Math.Atan2(dir.Y, dir.X);
3095 float txy = (float)Math.Sqrt((dir.X * dir.X) + (dir.Y * dir.Y));
3096 float terot = (float)Math.Atan2(-dir.Z, txy);
3097 LSL_Vector az = new LSL_Vector(0.0f, 0.0f, tzrot);
3098 LSL_Vector ae = new LSL_Vector(0.0f, terot, 0.0f);
3099 LSL_Types.Quaternion spin = llEuler2Rot(az);
3100 LSL_Types.Quaternion rot = llEuler2Rot(ae) * spin;
3101 llSetRot(rot);
3102 }
3103 else
3104 {
3105 // Physical, send the target vector to RotLookAt method inside a 'rotation', the .w -99.9 value indicates it is really a LookAt.
3106 Quaternion q = new Quaternion((float)target.x, (float)target.y, (float)target.z, -99.9f);
3107 m_host.RotLookAt(q, (float)strength, (float)damping);
3108 }
3109
3110 }
3111
3112 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3113 {
3114 m_host.AddScriptLPS(1);
3115// NotImplemented("llRotLookAt");
3116 m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping);
3117
2846 } 3118 }
2847 3119
2848 public void llStopLookAt() 3120 public void llStopLookAt()
@@ -2891,13 +3163,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2891 { 3163 {
2892 TaskInventoryItem item; 3164 TaskInventoryItem item;
2893 3165
2894 lock (m_host.TaskInventory) 3166 m_host.TaskInventory.LockItemsForRead(true);
3167 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2895 { 3168 {
2896 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3169 m_host.TaskInventory.LockItemsForRead(false);
2897 return; 3170 return;
2898 else
2899 item = m_host.TaskInventory[InventorySelf()];
2900 } 3171 }
3172 else
3173 {
3174 item = m_host.TaskInventory[InventorySelf()];
3175 }
3176 m_host.TaskInventory.LockItemsForRead(false);
2901 3177
2902 if (item.PermsGranter != UUID.Zero) 3178 if (item.PermsGranter != UUID.Zero)
2903 { 3179 {
@@ -2919,13 +3195,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2919 { 3195 {
2920 TaskInventoryItem item; 3196 TaskInventoryItem item;
2921 3197
3198 m_host.TaskInventory.LockItemsForRead(true);
2922 lock (m_host.TaskInventory) 3199 lock (m_host.TaskInventory)
2923 { 3200 {
3201
2924 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3202 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3203 {
3204 m_host.TaskInventory.LockItemsForRead(false);
2925 return; 3205 return;
3206 }
2926 else 3207 else
3208 {
2927 item = m_host.TaskInventory[InventorySelf()]; 3209 item = m_host.TaskInventory[InventorySelf()];
3210 }
2928 } 3211 }
3212 m_host.TaskInventory.LockItemsForRead(false);
2929 3213
2930 m_host.AddScriptLPS(1); 3214 m_host.AddScriptLPS(1);
2931 3215
@@ -2957,18 +3241,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2957 { 3241 {
2958 m_host.AddScriptLPS(1); 3242 m_host.AddScriptLPS(1);
2959 3243
2960// if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
2961// return;
2962
2963 TaskInventoryItem item; 3244 TaskInventoryItem item;
2964 3245
2965 lock (m_host.TaskInventory) 3246 m_host.TaskInventory.LockItemsForRead(true);
3247
3248 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2966 { 3249 {
2967 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3250 m_host.TaskInventory.LockItemsForRead(false);
2968 return; 3251 return;
2969 else
2970 item = m_host.TaskInventory[InventorySelf()];
2971 } 3252 }
3253 else
3254 {
3255 item = m_host.TaskInventory[InventorySelf()];
3256 }
3257
3258 m_host.TaskInventory.LockItemsForRead(false);
2972 3259
2973 if (item.PermsGranter != m_host.OwnerID) 3260 if (item.PermsGranter != m_host.OwnerID)
2974 return; 3261 return;
@@ -2994,13 +3281,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2994 3281
2995 TaskInventoryItem item; 3282 TaskInventoryItem item;
2996 3283
2997 lock (m_host.TaskInventory) 3284 m_host.TaskInventory.LockItemsForRead(true);
3285
3286 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2998 { 3287 {
2999 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3288 m_host.TaskInventory.LockItemsForRead(false);
3000 return; 3289 return;
3001 else
3002 item = m_host.TaskInventory[InventorySelf()];
3003 } 3290 }
3291 else
3292 {
3293 item = m_host.TaskInventory[InventorySelf()];
3294 }
3295 m_host.TaskInventory.LockItemsForRead(false);
3296
3004 3297
3005 if (item.PermsGranter != m_host.OwnerID) 3298 if (item.PermsGranter != m_host.OwnerID)
3006 return; 3299 return;
@@ -3047,6 +3340,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3047 3340
3048 public void llInstantMessage(string user, string message) 3341 public void llInstantMessage(string user, string message)
3049 { 3342 {
3343 UUID result;
3344 if (!UUID.TryParse(user, out result))
3345 {
3346 ShoutError("An invalid key was passed to llInstantMessage");
3347 ScriptSleep(2000);
3348 return;
3349 }
3350
3351
3050 m_host.AddScriptLPS(1); 3352 m_host.AddScriptLPS(1);
3051 3353
3052 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. 3354 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
@@ -3061,14 +3363,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3061 UUID friendTransactionID = UUID.Random(); 3363 UUID friendTransactionID = UUID.Random();
3062 3364
3063 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 3365 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
3064 3366
3065 GridInstantMessage msg = new GridInstantMessage(); 3367 GridInstantMessage msg = new GridInstantMessage();
3066 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; 3368 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
3067 msg.toAgentID = new Guid(user); // toAgentID.Guid; 3369 msg.toAgentID = new Guid(user); // toAgentID.Guid;
3068 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here 3370 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
3069// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message); 3371// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
3070// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString()); 3372// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
3071 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp; 3373// DateTime dt = DateTime.UtcNow;
3374//
3375// // Ticks from UtcNow, but make it look like local. Evil, huh?
3376// dt = DateTime.SpecifyKind(dt, DateTimeKind.Local);
3377//
3378// try
3379// {
3380// // Convert that to the PST timezone
3381// TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
3382// dt = TimeZoneInfo.ConvertTime(dt, timeZoneInfo);
3383// }
3384// catch
3385// {
3386// // No logging here, as it could be VERY spammy
3387// }
3388//
3389// // And make it look local again to fool the unix time util
3390// dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
3391
3392 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
3393
3072 //if (client != null) 3394 //if (client != null)
3073 //{ 3395 //{
3074 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName; 3396 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
@@ -3082,12 +3404,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3082 msg.message = message.Substring(0, 1024); 3404 msg.message = message.Substring(0, 1024);
3083 else 3405 else
3084 msg.message = message; 3406 msg.message = message;
3085 msg.dialog = (byte)19; // messgage from script ??? // dialog; 3407 msg.dialog = (byte)19; // MessageFromObject
3086 msg.fromGroup = false;// fromGroup; 3408 msg.fromGroup = false;// fromGroup;
3087 msg.offline = (byte)0; //offline; 3409 msg.offline = (byte)0; //offline;
3088 msg.ParentEstateID = 0; //ParentEstateID; 3410 msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
3089 msg.Position = new Vector3(m_host.AbsolutePosition); 3411 msg.Position = new Vector3(m_host.AbsolutePosition);
3090 msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; 3412 msg.RegionID = World.RegionInfo.RegionID.Guid;
3091 msg.binaryBucket 3413 msg.binaryBucket
3092 = Util.StringToBytes256( 3414 = Util.StringToBytes256(
3093 "{0}/{1}/{2}/{3}", 3415 "{0}/{1}/{2}/{3}",
@@ -3115,7 +3437,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3115 } 3437 }
3116 3438
3117 emailModule.SendEmail(m_host.UUID, address, subject, message); 3439 emailModule.SendEmail(m_host.UUID, address, subject, message);
3118 ScriptSleep(20000); 3440 ScriptSleep(15000);
3119 } 3441 }
3120 3442
3121 public void llGetNextEmail(string address, string subject) 3443 public void llGetNextEmail(string address, string subject)
@@ -3215,13 +3537,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3215 m_host.AddScriptLPS(1); 3537 m_host.AddScriptLPS(1);
3216 } 3538 }
3217 3539
3218 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3219 {
3220 m_host.AddScriptLPS(1);
3221 Quaternion rot = new Quaternion((float)target.x, (float)target.y, (float)target.z, (float)target.s);
3222 m_host.RotLookAt(rot, (float)strength, (float)damping);
3223 }
3224
3225 public LSL_Integer llStringLength(string str) 3540 public LSL_Integer llStringLength(string str)
3226 { 3541 {
3227 m_host.AddScriptLPS(1); 3542 m_host.AddScriptLPS(1);
@@ -3245,14 +3560,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3245 3560
3246 TaskInventoryItem item; 3561 TaskInventoryItem item;
3247 3562
3248 lock (m_host.TaskInventory) 3563 m_host.TaskInventory.LockItemsForRead(true);
3564 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3249 { 3565 {
3250 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3566 m_host.TaskInventory.LockItemsForRead(false);
3251 return; 3567 return;
3252 else
3253 item = m_host.TaskInventory[InventorySelf()];
3254 } 3568 }
3255 3569 else
3570 {
3571 item = m_host.TaskInventory[InventorySelf()];
3572 }
3573 m_host.TaskInventory.LockItemsForRead(false);
3256 if (item.PermsGranter == UUID.Zero) 3574 if (item.PermsGranter == UUID.Zero)
3257 return; 3575 return;
3258 3576
@@ -3282,13 +3600,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3282 3600
3283 TaskInventoryItem item; 3601 TaskInventoryItem item;
3284 3602
3285 lock (m_host.TaskInventory) 3603 m_host.TaskInventory.LockItemsForRead(true);
3604 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3286 { 3605 {
3287 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3606 m_host.TaskInventory.LockItemsForRead(false);
3288 return; 3607 return;
3289 else
3290 item = m_host.TaskInventory[InventorySelf()];
3291 } 3608 }
3609 else
3610 {
3611 item = m_host.TaskInventory[InventorySelf()];
3612 }
3613 m_host.TaskInventory.LockItemsForRead(false);
3614
3292 3615
3293 if (item.PermsGranter == UUID.Zero) 3616 if (item.PermsGranter == UUID.Zero)
3294 return; 3617 return;
@@ -3353,10 +3676,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3353 3676
3354 TaskInventoryItem item; 3677 TaskInventoryItem item;
3355 3678
3356 lock (m_host.TaskInventory) 3679
3680 m_host.TaskInventory.LockItemsForRead(true);
3681 if (!m_host.TaskInventory.ContainsKey(invItemID))
3682 {
3683 m_host.TaskInventory.LockItemsForRead(false);
3684 return;
3685 }
3686 else
3357 { 3687 {
3358 item = m_host.TaskInventory[invItemID]; 3688 item = m_host.TaskInventory[invItemID];
3359 } 3689 }
3690 m_host.TaskInventory.LockItemsForRead(false);
3360 3691
3361 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3692 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3362 { 3693 {
@@ -3384,15 +3715,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3384 int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS | 3715 int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
3385 ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | 3716 ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
3386 ScriptBaseClass.PERMISSION_CONTROL_CAMERA | 3717 ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
3718 ScriptBaseClass.PERMISSION_TRACK_CAMERA |
3387 ScriptBaseClass.PERMISSION_ATTACH; 3719 ScriptBaseClass.PERMISSION_ATTACH;
3388 3720
3389 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3721 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3390 { 3722 {
3391 lock (m_host.TaskInventory) 3723 m_host.TaskInventory.LockItemsForWrite(true);
3392 { 3724 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3393 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3725 m_host.TaskInventory[invItemID].PermsMask = perm;
3394 m_host.TaskInventory[invItemID].PermsMask = perm; 3726 m_host.TaskInventory.LockItemsForWrite(false);
3395 }
3396 3727
3397 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3728 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3398 "run_time_permissions", new Object[] { 3729 "run_time_permissions", new Object[] {
@@ -3402,28 +3733,44 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3402 return; 3733 return;
3403 } 3734 }
3404 } 3735 }
3405 else if (m_host.SitTargetAvatar == agentID) // Sitting avatar 3736 else
3406 { 3737 {
3407 // When agent is sitting, certain permissions are implicit if requested from sitting agent 3738 bool sitting = false;
3408 int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | 3739 if (m_host.SitTargetAvatar == agentID)
3409 ScriptBaseClass.PERMISSION_CONTROL_CAMERA | 3740 {
3410 ScriptBaseClass.PERMISSION_TRACK_CAMERA | 3741 sitting = true;
3411 ScriptBaseClass.PERMISSION_TAKE_CONTROLS; 3742 }
3743 else
3744 {
3745 foreach (SceneObjectPart p in m_host.ParentGroup.Parts)
3746 {
3747 if (p.SitTargetAvatar == agentID)
3748 sitting = true;
3749 }
3750 }
3412 3751
3413 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3752 if (sitting)
3414 { 3753 {
3415 lock (m_host.TaskInventory) 3754 // When agent is sitting, certain permissions are implicit if requested from sitting agent
3755 int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
3756 ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
3757 ScriptBaseClass.PERMISSION_TRACK_CAMERA |
3758 ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3759
3760 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3416 { 3761 {
3762 m_host.TaskInventory.LockItemsForWrite(true);
3417 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3763 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3418 m_host.TaskInventory[invItemID].PermsMask = perm; 3764 m_host.TaskInventory[invItemID].PermsMask = perm;
3419 } 3765 m_host.TaskInventory.LockItemsForWrite(false);
3420 3766
3421 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3767 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3422 "run_time_permissions", new Object[] { 3768 "run_time_permissions", new Object[] {
3423 new LSL_Integer(perm) }, 3769 new LSL_Integer(perm) },
3424 new DetectParams[0])); 3770 new DetectParams[0]));
3425 3771
3426 return; 3772 return;
3773 }
3427 } 3774 }
3428 } 3775 }
3429 3776
@@ -3437,11 +3784,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3437 3784
3438 if (!m_waitingForScriptAnswer) 3785 if (!m_waitingForScriptAnswer)
3439 { 3786 {
3440 lock (m_host.TaskInventory) 3787 m_host.TaskInventory.LockItemsForWrite(true);
3441 { 3788 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3442 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3789 m_host.TaskInventory[invItemID].PermsMask = 0;
3443 m_host.TaskInventory[invItemID].PermsMask = 0; 3790 m_host.TaskInventory.LockItemsForWrite(false);
3444 }
3445 3791
3446 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3792 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3447 m_waitingForScriptAnswer=true; 3793 m_waitingForScriptAnswer=true;
@@ -3476,10 +3822,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3476 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3822 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3477 llReleaseControls(); 3823 llReleaseControls();
3478 3824
3479 lock (m_host.TaskInventory) 3825
3480 { 3826 m_host.TaskInventory.LockItemsForWrite(true);
3481 m_host.TaskInventory[invItemID].PermsMask = answer; 3827 m_host.TaskInventory[invItemID].PermsMask = answer;
3482 } 3828 m_host.TaskInventory.LockItemsForWrite(false);
3829
3483 3830
3484 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3831 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3485 "run_time_permissions", new Object[] { 3832 "run_time_permissions", new Object[] {
@@ -3491,16 +3838,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3491 { 3838 {
3492 m_host.AddScriptLPS(1); 3839 m_host.AddScriptLPS(1);
3493 3840
3494 lock (m_host.TaskInventory) 3841 m_host.TaskInventory.LockItemsForRead(true);
3842
3843 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3495 { 3844 {
3496 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3845 if (item.Type == 10 && item.ItemID == m_itemID)
3497 { 3846 {
3498 if (item.Type == 10 && item.ItemID == m_itemID) 3847 m_host.TaskInventory.LockItemsForRead(false);
3499 { 3848 return item.PermsGranter.ToString();
3500 return item.PermsGranter.ToString();
3501 }
3502 } 3849 }
3503 } 3850 }
3851 m_host.TaskInventory.LockItemsForRead(false);
3504 3852
3505 return UUID.Zero.ToString(); 3853 return UUID.Zero.ToString();
3506 } 3854 }
@@ -3509,19 +3857,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3509 { 3857 {
3510 m_host.AddScriptLPS(1); 3858 m_host.AddScriptLPS(1);
3511 3859
3512 lock (m_host.TaskInventory) 3860 m_host.TaskInventory.LockItemsForRead(true);
3861
3862 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3513 { 3863 {
3514 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3864 if (item.Type == 10 && item.ItemID == m_itemID)
3515 { 3865 {
3516 if (item.Type == 10 && item.ItemID == m_itemID) 3866 int perms = item.PermsMask;
3517 { 3867 if (m_automaticLinkPermission)
3518 int perms = item.PermsMask; 3868 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3519 if (m_automaticLinkPermission) 3869 m_host.TaskInventory.LockItemsForRead(false);
3520 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; 3870 return perms;
3521 return perms;
3522 }
3523 } 3871 }
3524 } 3872 }
3873 m_host.TaskInventory.LockItemsForRead(false);
3525 3874
3526 return 0; 3875 return 0;
3527 } 3876 }
@@ -3543,9 +3892,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3543 public void llSetLinkColor(int linknumber, LSL_Vector color, int face) 3892 public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
3544 { 3893 {
3545 List<SceneObjectPart> parts = GetLinkParts(linknumber); 3894 List<SceneObjectPart> parts = GetLinkParts(linknumber);
3546 3895 if (parts.Count > 0)
3547 foreach (SceneObjectPart part in parts) 3896 {
3548 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); 3897 try
3898 {
3899 parts[0].ParentGroup.areUpdatesSuspended = true;
3900 foreach (SceneObjectPart part in parts)
3901 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
3902 }
3903 finally
3904 {
3905 parts[0].ParentGroup.areUpdatesSuspended = false;
3906 }
3907 }
3549 } 3908 }
3550 3909
3551 public void llCreateLink(string target, int parent) 3910 public void llCreateLink(string target, int parent)
@@ -3558,11 +3917,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3558 return; 3917 return;
3559 3918
3560 TaskInventoryItem item; 3919 TaskInventoryItem item;
3561 lock (m_host.TaskInventory) 3920 m_host.TaskInventory.LockItemsForRead(true);
3562 { 3921 item = m_host.TaskInventory[invItemID];
3563 item = m_host.TaskInventory[invItemID]; 3922 m_host.TaskInventory.LockItemsForRead(false);
3564 } 3923
3565
3566 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3924 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3567 && !m_automaticLinkPermission) 3925 && !m_automaticLinkPermission)
3568 { 3926 {
@@ -3579,11 +3937,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3579 3937
3580 if (targetPart.ParentGroup.AttachmentPoint != 0) 3938 if (targetPart.ParentGroup.AttachmentPoint != 0)
3581 return; // Fail silently if attached 3939 return; // Fail silently if attached
3940
3941 if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
3942 return;
3943
3582 SceneObjectGroup parentPrim = null, childPrim = null; 3944 SceneObjectGroup parentPrim = null, childPrim = null;
3583 3945
3584 if (targetPart != null) 3946 if (targetPart != null)
3585 { 3947 {
3586 if (parent != 0) { 3948 if (parent != 0)
3949 {
3587 parentPrim = m_host.ParentGroup; 3950 parentPrim = m_host.ParentGroup;
3588 childPrim = targetPart.ParentGroup; 3951 childPrim = targetPart.ParentGroup;
3589 } 3952 }
@@ -3615,16 +3978,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3615 m_host.AddScriptLPS(1); 3978 m_host.AddScriptLPS(1);
3616 UUID invItemID = InventorySelf(); 3979 UUID invItemID = InventorySelf();
3617 3980
3618 lock (m_host.TaskInventory) 3981 m_host.TaskInventory.LockItemsForRead(true);
3619 {
3620 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3982 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3621 && !m_automaticLinkPermission) 3983 && !m_automaticLinkPermission)
3622 { 3984 {
3623 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3985 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
3986 m_host.TaskInventory.LockItemsForRead(false);
3624 return; 3987 return;
3625 } 3988 }
3626 } 3989 m_host.TaskInventory.LockItemsForRead(false);
3627 3990
3628 if (linknum < ScriptBaseClass.LINK_THIS) 3991 if (linknum < ScriptBaseClass.LINK_THIS)
3629 return; 3992 return;
3630 3993
@@ -3663,10 +4026,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3663 // Restructuring Multiple Prims. 4026 // Restructuring Multiple Prims.
3664 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts); 4027 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
3665 parts.Remove(parentPrim.RootPart); 4028 parts.Remove(parentPrim.RootPart);
3666 foreach (SceneObjectPart part in parts) 4029 if (parts.Count > 0)
3667 { 4030 {
3668 parentPrim.DelinkFromGroup(part.LocalId, true); 4031 try
4032 {
4033 parts[0].ParentGroup.areUpdatesSuspended = true;
4034 foreach (SceneObjectPart part in parts)
4035 {
4036 parentPrim.DelinkFromGroup(part.LocalId, true);
4037 }
4038 }
4039 finally
4040 {
4041 parts[0].ParentGroup.areUpdatesSuspended = false;
4042 }
3669 } 4043 }
4044
3670 parentPrim.HasGroupChanged = true; 4045 parentPrim.HasGroupChanged = true;
3671 parentPrim.ScheduleGroupForFullUpdate(); 4046 parentPrim.ScheduleGroupForFullUpdate();
3672 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 4047 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
@@ -3675,11 +4050,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3675 { 4050 {
3676 SceneObjectPart newRoot = parts[0]; 4051 SceneObjectPart newRoot = parts[0];
3677 parts.Remove(newRoot); 4052 parts.Remove(newRoot);
3678 foreach (SceneObjectPart part in parts) 4053
4054 try
3679 { 4055 {
3680 part.UpdateFlag = 0; 4056 parts[0].ParentGroup.areUpdatesSuspended = true;
3681 newRoot.ParentGroup.LinkToGroup(part.ParentGroup); 4057 foreach (SceneObjectPart part in parts)
4058 {
4059 part.UpdateFlag = 0;
4060 newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
4061 }
3682 } 4062 }
4063 finally
4064 {
4065 parts[0].ParentGroup.areUpdatesSuspended = false;
4066 }
4067
4068
3683 newRoot.ParentGroup.HasGroupChanged = true; 4069 newRoot.ParentGroup.HasGroupChanged = true;
3684 newRoot.ParentGroup.ScheduleGroupForFullUpdate(); 4070 newRoot.ParentGroup.ScheduleGroupForFullUpdate();
3685 } 4071 }
@@ -3699,6 +4085,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3699 public void llBreakAllLinks() 4085 public void llBreakAllLinks()
3700 { 4086 {
3701 m_host.AddScriptLPS(1); 4087 m_host.AddScriptLPS(1);
4088
4089 UUID invItemID = InventorySelf();
4090
4091 TaskInventoryItem item;
4092 m_host.TaskInventory.LockItemsForRead(true);
4093 item = m_host.TaskInventory[invItemID];
4094 m_host.TaskInventory.LockItemsForRead(false);
4095
4096 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4097 && !m_automaticLinkPermission)
4098 {
4099 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
4100 return;
4101 }
4102
3702 SceneObjectGroup parentPrim = m_host.ParentGroup; 4103 SceneObjectGroup parentPrim = m_host.ParentGroup;
3703 if (parentPrim.AttachmentPoint != 0) 4104 if (parentPrim.AttachmentPoint != 0)
3704 return; // Fail silently if attached 4105 return; // Fail silently if attached
@@ -3744,6 +4145,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3744 } 4145 }
3745 else 4146 else
3746 { 4147 {
4148 if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
4149 {
4150 linknum -= (m_host.ParentGroup.PrimCount) + 1;
4151
4152 if (linknum < 0)
4153 return UUID.Zero.ToString();
4154
4155 List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
4156 if (avatars.Count > linknum)
4157 {
4158 return avatars[linknum].UUID.ToString();
4159 }
4160 }
3747 return UUID.Zero.ToString(); 4161 return UUID.Zero.ToString();
3748 } 4162 }
3749 } 4163 }
@@ -3842,17 +4256,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3842 m_host.AddScriptLPS(1); 4256 m_host.AddScriptLPS(1);
3843 int count = 0; 4257 int count = 0;
3844 4258
3845 lock (m_host.TaskInventory) 4259 m_host.TaskInventory.LockItemsForRead(true);
4260 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3846 { 4261 {
3847 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4262 if (inv.Value.Type == type || type == -1)
3848 { 4263 {
3849 if (inv.Value.Type == type || type == -1) 4264 count = count + 1;
3850 {
3851 count = count + 1;
3852 }
3853 } 4265 }
3854 } 4266 }
3855 4267
4268 m_host.TaskInventory.LockItemsForRead(false);
3856 return count; 4269 return count;
3857 } 4270 }
3858 4271
@@ -3861,16 +4274,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3861 m_host.AddScriptLPS(1); 4274 m_host.AddScriptLPS(1);
3862 ArrayList keys = new ArrayList(); 4275 ArrayList keys = new ArrayList();
3863 4276
3864 lock (m_host.TaskInventory) 4277 m_host.TaskInventory.LockItemsForRead(true);
4278 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3865 { 4279 {
3866 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4280 if (inv.Value.Type == type || type == -1)
3867 { 4281 {
3868 if (inv.Value.Type == type || type == -1) 4282 keys.Add(inv.Value.Name);
3869 {
3870 keys.Add(inv.Value.Name);
3871 }
3872 } 4283 }
3873 } 4284 }
4285 m_host.TaskInventory.LockItemsForRead(false);
3874 4286
3875 if (keys.Count == 0) 4287 if (keys.Count == 0)
3876 { 4288 {
@@ -3907,25 +4319,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3907 } 4319 }
3908 4320
3909 // move the first object found with this inventory name 4321 // move the first object found with this inventory name
3910 lock (m_host.TaskInventory) 4322 m_host.TaskInventory.LockItemsForRead(true);
4323 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3911 { 4324 {
3912 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4325 if (inv.Value.Name == inventory)
3913 { 4326 {
3914 if (inv.Value.Name == inventory) 4327 found = true;
3915 { 4328 objId = inv.Key;
3916 found = true; 4329 assetType = inv.Value.Type;
3917 objId = inv.Key; 4330 objName = inv.Value.Name;
3918 assetType = inv.Value.Type; 4331 break;
3919 objName = inv.Value.Name;
3920 break;
3921 }
3922 } 4332 }
3923 } 4333 }
4334 m_host.TaskInventory.LockItemsForRead(false);
3924 4335
3925 if (!found) 4336 if (!found)
3926 { 4337 {
3927 llSay(0, String.Format("Could not find object '{0}'", inventory)); 4338 llSay(0, String.Format("Could not find object '{0}'", inventory));
3928 throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); 4339 return;
4340// throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
3929 } 4341 }
3930 4342
3931 // check if destination is an object 4343 // check if destination is an object
@@ -3951,6 +4363,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3951 return; 4363 return;
3952 } 4364 }
3953 } 4365 }
4366
3954 // destination is an avatar 4367 // destination is an avatar
3955 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId); 4368 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId);
3956 4369
@@ -3973,26 +4386,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3973 bucket); 4386 bucket);
3974 if (m_TransferModule != null) 4387 if (m_TransferModule != null)
3975 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); 4388 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
4389
4390 //This delay should only occur when giving inventory to avatars.
3976 ScriptSleep(3000); 4391 ScriptSleep(3000);
3977 } 4392 }
3978 } 4393 }
3979 4394
4395 [DebuggerNonUserCode]
3980 public void llRemoveInventory(string name) 4396 public void llRemoveInventory(string name)
3981 { 4397 {
3982 m_host.AddScriptLPS(1); 4398 m_host.AddScriptLPS(1);
3983 4399
3984 lock (m_host.TaskInventory) 4400 List<TaskInventoryItem> inv;
4401 try
3985 { 4402 {
3986 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4403 m_host.TaskInventory.LockItemsForRead(true);
4404 inv = new List<TaskInventoryItem>(m_host.TaskInventory.Values);
4405 }
4406 finally
4407 {
4408 m_host.TaskInventory.LockItemsForRead(false);
4409 }
4410 foreach (TaskInventoryItem item in inv)
4411 {
4412 if (item.Name == name)
3987 { 4413 {
3988 if (item.Name == name) 4414 if (item.ItemID == m_itemID)
3989 { 4415 throw new ScriptDeleteException();
3990 if (item.ItemID == m_itemID) 4416 else
3991 throw new ScriptDeleteException(); 4417 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3992 else 4418 return;
3993 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3994 return;
3995 }
3996 } 4419 }
3997 } 4420 }
3998 } 4421 }
@@ -4027,112 +4450,122 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4027 { 4450 {
4028 m_host.AddScriptLPS(1); 4451 m_host.AddScriptLPS(1);
4029 4452
4030 UUID uuid = (UUID)id; 4453 UUID uuid;
4031 PresenceInfo pinfo = null; 4454 if (UUID.TryParse(id, out uuid))
4032 UserAccount account;
4033
4034 UserInfoCacheEntry ce;
4035 if (!m_userInfoCache.TryGetValue(uuid, out ce))
4036 { 4455 {
4037 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); 4456 PresenceInfo pinfo = null;
4038 if (account == null) 4457 UserAccount account;
4458
4459 UserInfoCacheEntry ce;
4460 if (!m_userInfoCache.TryGetValue(uuid, out ce))
4039 { 4461 {
4040 m_userInfoCache[uuid] = null; // Cache negative 4462 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
4041 return UUID.Zero.ToString(); 4463 if (account == null)
4042 } 4464 {
4465 m_userInfoCache[uuid] = null; // Cache negative
4466 return UUID.Zero.ToString();
4467 }
4043 4468
4044 4469
4045 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); 4470 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4046 if (pinfos != null && pinfos.Length > 0) 4471 if (pinfos != null && pinfos.Length > 0)
4047 {
4048 foreach (PresenceInfo p in pinfos)
4049 { 4472 {
4050 if (p.RegionID != UUID.Zero) 4473 foreach (PresenceInfo p in pinfos)
4051 { 4474 {
4052 pinfo = p; 4475 if (p.RegionID != UUID.Zero)
4476 {
4477 pinfo = p;
4478 }
4053 } 4479 }
4054 } 4480 }
4055 }
4056 4481
4057 ce = new UserInfoCacheEntry(); 4482 ce = new UserInfoCacheEntry();
4058 ce.time = Util.EnvironmentTickCount(); 4483 ce.time = Util.EnvironmentTickCount();
4059 ce.account = account; 4484 ce.account = account;
4060 ce.pinfo = pinfo; 4485 ce.pinfo = pinfo;
4061 } 4486 m_userInfoCache[uuid] = ce;
4062 else 4487 }
4063 { 4488 else
4064 if (ce == null) 4489 {
4065 return UUID.Zero.ToString(); 4490 if (ce == null)
4491 return UUID.Zero.ToString();
4066 4492
4067 account = ce.account; 4493 account = ce.account;
4068 pinfo = ce.pinfo; 4494 pinfo = ce.pinfo;
4069 } 4495 }
4070 4496
4071 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) 4497 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000)
4072 {
4073 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4074 if (pinfos != null && pinfos.Length > 0)
4075 { 4498 {
4076 foreach (PresenceInfo p in pinfos) 4499 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4500 if (pinfos != null && pinfos.Length > 0)
4077 { 4501 {
4078 if (p.RegionID != UUID.Zero) 4502 foreach (PresenceInfo p in pinfos)
4079 { 4503 {
4080 pinfo = p; 4504 if (p.RegionID != UUID.Zero)
4505 {
4506 pinfo = p;
4507 }
4081 } 4508 }
4082 } 4509 }
4083 } 4510 else
4084 else 4511 pinfo = null;
4085 pinfo = null;
4086 4512
4087 ce.time = Util.EnvironmentTickCount(); 4513 ce.time = Util.EnvironmentTickCount();
4088 ce.pinfo = pinfo; 4514 ce.pinfo = pinfo;
4089 } 4515 }
4090 4516
4091 string reply = String.Empty; 4517 string reply = String.Empty;
4092 4518
4093 switch (data) 4519 switch (data)
4094 { 4520 {
4095 case 1: // DATA_ONLINE (0|1) 4521 case 1: // DATA_ONLINE (0|1)
4096 if (pinfo != null && pinfo.RegionID != UUID.Zero) 4522 if (pinfo != null && pinfo.RegionID != UUID.Zero)
4097 reply = "1"; 4523 reply = "1";
4098 else 4524 else
4099 reply = "0"; 4525 reply = "0";
4100 break; 4526 break;
4101 case 2: // DATA_NAME (First Last) 4527 case 2: // DATA_NAME (First Last)
4102 reply = account.FirstName + " " + account.LastName; 4528 reply = account.FirstName + " " + account.LastName;
4103 break; 4529 break;
4104 case 3: // DATA_BORN (YYYY-MM-DD) 4530 case 3: // DATA_BORN (YYYY-MM-DD)
4105 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); 4531 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
4106 born = born.AddSeconds(account.Created); 4532 born = born.AddSeconds(account.Created);
4107 reply = born.ToString("yyyy-MM-dd"); 4533 reply = born.ToString("yyyy-MM-dd");
4108 break; 4534 break;
4109 case 4: // DATA_RATING (0,0,0,0,0,0) 4535 case 4: // DATA_RATING (0,0,0,0,0,0)
4110 reply = "0,0,0,0,0,0"; 4536 reply = "0,0,0,0,0,0";
4111 break; 4537 break;
4112 case 8: // DATA_PAYINFO (0|1|2|3) 4538 case 8: // DATA_PAYINFO (0|1|2|3)
4113 reply = "0"; 4539 reply = "0";
4114 break; 4540 break;
4115 default: 4541 default:
4116 return UUID.Zero.ToString(); // Raise no event 4542 return UUID.Zero.ToString(); // Raise no event
4117 } 4543 }
4118 4544
4119 UUID rq = UUID.Random(); 4545 UUID rq = UUID.Random();
4120 4546
4121 UUID tid = AsyncCommands. 4547 UUID tid = AsyncCommands.
4122 DataserverPlugin.RegisterRequest(m_localID, 4548 DataserverPlugin.RegisterRequest(m_localID,
4123 m_itemID, rq.ToString()); 4549 m_itemID, rq.ToString());
4124 4550
4125 AsyncCommands. 4551 AsyncCommands.
4126 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4552 DataserverPlugin.DataserverReply(rq.ToString(), reply);
4127 4553
4128 ScriptSleep(100); 4554 ScriptSleep(100);
4129 return tid.ToString(); 4555 return tid.ToString();
4556 }
4557 else
4558 {
4559 ShoutError("Invalid UUID passed to llRequestAgentData.");
4560 }
4561 return "";
4130 } 4562 }
4131 4563
4132 public LSL_String llRequestInventoryData(string name) 4564 public LSL_String llRequestInventoryData(string name)
4133 { 4565 {
4134 m_host.AddScriptLPS(1); 4566 m_host.AddScriptLPS(1);
4135 4567
4568 //Clone is thread safe
4136 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 4569 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
4137 4570
4138 foreach (TaskInventoryItem item in itemDictionary.Values) 4571 foreach (TaskInventoryItem item in itemDictionary.Values)
@@ -4186,6 +4619,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4186 ScenePresence presence = World.GetScenePresence(agentId); 4619 ScenePresence presence = World.GetScenePresence(agentId);
4187 if (presence != null) 4620 if (presence != null)
4188 { 4621 {
4622 // agent must not be a god
4623 if (presence.UserLevel >= 200) return;
4624
4189 // agent must be over the owners land 4625 // agent must be over the owners land
4190 if (m_host.OwnerID == World.LandChannel.GetLandObject( 4626 if (m_host.OwnerID == World.LandChannel.GetLandObject(
4191 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) 4627 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
@@ -4208,7 +4644,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4208 UUID av = new UUID(); 4644 UUID av = new UUID();
4209 if (!UUID.TryParse(agent,out av)) 4645 if (!UUID.TryParse(agent,out av))
4210 { 4646 {
4211 LSLError("First parameter to llDialog needs to be a key"); 4647 //LSLError("First parameter to llDialog needs to be a key");
4212 return; 4648 return;
4213 } 4649 }
4214 4650
@@ -4245,17 +4681,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4245 UUID soundId = UUID.Zero; 4681 UUID soundId = UUID.Zero;
4246 if (!UUID.TryParse(impact_sound, out soundId)) 4682 if (!UUID.TryParse(impact_sound, out soundId))
4247 { 4683 {
4248 lock (m_host.TaskInventory) 4684 m_host.TaskInventory.LockItemsForRead(true);
4685 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4249 { 4686 {
4250 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4687 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
4251 { 4688 {
4252 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 4689 soundId = item.AssetID;
4253 { 4690 break;
4254 soundId = item.AssetID;
4255 break;
4256 }
4257 } 4691 }
4258 } 4692 }
4693 m_host.TaskInventory.LockItemsForRead(false);
4259 } 4694 }
4260 m_host.CollisionSound = soundId; 4695 m_host.CollisionSound = soundId;
4261 m_host.CollisionSoundVolume = (float)impact_volume; 4696 m_host.CollisionSoundVolume = (float)impact_volume;
@@ -4295,6 +4730,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4295 UUID partItemID; 4730 UUID partItemID;
4296 foreach (SceneObjectPart part in parts) 4731 foreach (SceneObjectPart part in parts)
4297 { 4732 {
4733 //Clone is thread safe
4298 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); 4734 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
4299 4735
4300 foreach (TaskInventoryItem item in itemsDictionary.Values) 4736 foreach (TaskInventoryItem item in itemsDictionary.Values)
@@ -4509,17 +4945,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4509 4945
4510 m_host.AddScriptLPS(1); 4946 m_host.AddScriptLPS(1);
4511 4947
4512 lock (m_host.TaskInventory) 4948 m_host.TaskInventory.LockItemsForRead(true);
4949 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4513 { 4950 {
4514 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4951 if (item.Type == 10 && item.ItemID == m_itemID)
4515 { 4952 {
4516 if (item.Type == 10 && item.ItemID == m_itemID) 4953 result = item.Name!=null?item.Name:String.Empty;
4517 { 4954 break;
4518 result = item.Name != null ? item.Name : String.Empty;
4519 break;
4520 }
4521 } 4955 }
4522 } 4956 }
4957 m_host.TaskInventory.LockItemsForRead(false);
4523 4958
4524 return result; 4959 return result;
4525 } 4960 }
@@ -4688,23 +5123,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4688 { 5123 {
4689 m_host.AddScriptLPS(1); 5124 m_host.AddScriptLPS(1);
4690 5125
4691 lock (m_host.TaskInventory) 5126 m_host.TaskInventory.LockItemsForRead(true);
5127 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4692 { 5128 {
4693 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 5129 if (inv.Value.Name == name)
4694 { 5130 {
4695 if (inv.Value.Name == name) 5131 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
4696 { 5132 {
4697 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) 5133 m_host.TaskInventory.LockItemsForRead(false);
4698 { 5134 return inv.Value.AssetID.ToString();
4699 return inv.Value.AssetID.ToString(); 5135 }
4700 } 5136 else
4701 else 5137 {
4702 { 5138 m_host.TaskInventory.LockItemsForRead(false);
4703 return UUID.Zero.ToString(); 5139 return UUID.Zero.ToString();
4704 }
4705 } 5140 }
4706 } 5141 }
4707 } 5142 }
5143 m_host.TaskInventory.LockItemsForRead(false);
4708 5144
4709 return UUID.Zero.ToString(); 5145 return UUID.Zero.ToString();
4710 } 5146 }
@@ -4857,14 +5293,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4857 { 5293 {
4858 m_host.AddScriptLPS(1); 5294 m_host.AddScriptLPS(1);
4859 5295
4860 if (src == null) 5296 return src.Length;
4861 {
4862 return 0;
4863 }
4864 else
4865 {
4866 return src.Length;
4867 }
4868 } 5297 }
4869 5298
4870 public LSL_Integer llList2Integer(LSL_List src, int index) 5299 public LSL_Integer llList2Integer(LSL_List src, int index)
@@ -4910,7 +5339,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4910 else if (src.Data[index] is LSL_Float) 5339 else if (src.Data[index] is LSL_Float)
4911 return Convert.ToDouble(((LSL_Float) src.Data[index]).value); 5340 return Convert.ToDouble(((LSL_Float) src.Data[index]).value);
4912 else if (src.Data[index] is LSL_String) 5341 else if (src.Data[index] is LSL_String)
4913 return Convert.ToDouble(((LSL_String) src.Data[index]).m_string); 5342 {
5343 string str = ((LSL_String) src.Data[index]).m_string;
5344 Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
5345 if (m != Match.Empty)
5346 {
5347 str = m.Value;
5348 double d = 0.0;
5349 if (!Double.TryParse(str, out d))
5350 return 0.0;
5351
5352 return d;
5353 }
5354 return 0.0;
5355 }
4914 return Convert.ToDouble(src.Data[index]); 5356 return Convert.ToDouble(src.Data[index]);
4915 } 5357 }
4916 catch (FormatException) 5358 catch (FormatException)
@@ -5183,7 +5625,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5183 } 5625 }
5184 } 5626 }
5185 } 5627 }
5186 else { 5628 else
5629 {
5187 object[] array = new object[src.Length]; 5630 object[] array = new object[src.Length];
5188 Array.Copy(src.Data, 0, array, 0, src.Length); 5631 Array.Copy(src.Data, 0, array, 0, src.Length);
5189 result = new LSL_List(array); 5632 result = new LSL_List(array);
@@ -5634,10 +6077,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5634 m_host.AddScriptLPS(1); 6077 m_host.AddScriptLPS(1);
5635 6078
5636 List<SceneObjectPart> parts = GetLinkParts(linknumber); 6079 List<SceneObjectPart> parts = GetLinkParts(linknumber);
5637 6080 if (parts.Count > 0)
5638 foreach (var part in parts)
5639 { 6081 {
5640 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate); 6082 try
6083 {
6084 parts[0].ParentGroup.areUpdatesSuspended = true;
6085 foreach (var part in parts)
6086 {
6087 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
6088 }
6089 }
6090 finally
6091 {
6092 parts[0].ParentGroup.areUpdatesSuspended = false;
6093 }
5641 } 6094 }
5642 } 6095 }
5643 6096
@@ -5691,6 +6144,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5691 ScriptSleep(5000); 6144 ScriptSleep(5000);
5692 } 6145 }
5693 6146
6147 public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
6148 {
6149 return ParseString2List(str, separators, in_spacers, false);
6150 }
6151
5694 public LSL_Integer llOverMyLand(string id) 6152 public LSL_Integer llOverMyLand(string id)
5695 { 6153 {
5696 m_host.AddScriptLPS(1); 6154 m_host.AddScriptLPS(1);
@@ -5891,7 +6349,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5891 return m_host.ParentGroup.AttachmentPoint; 6349 return m_host.ParentGroup.AttachmentPoint;
5892 } 6350 }
5893 6351
5894 public LSL_Integer llGetFreeMemory() 6352 public virtual LSL_Integer llGetFreeMemory()
5895 { 6353 {
5896 m_host.AddScriptLPS(1); 6354 m_host.AddScriptLPS(1);
5897 // Make scripts designed for LSO happy 6355 // Make scripts designed for LSO happy
@@ -6008,7 +6466,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6008 SetParticleSystem(m_host, rules); 6466 SetParticleSystem(m_host, rules);
6009 } 6467 }
6010 6468
6011 private void SetParticleSystem(SceneObjectPart part, LSL_List rules) { 6469 private void SetParticleSystem(SceneObjectPart part, LSL_List rules)
6470 {
6012 6471
6013 6472
6014 if (rules.Length == 0) 6473 if (rules.Length == 0)
@@ -6202,14 +6661,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6202 6661
6203 protected UUID GetTaskInventoryItem(string name) 6662 protected UUID GetTaskInventoryItem(string name)
6204 { 6663 {
6205 lock (m_host.TaskInventory) 6664 m_host.TaskInventory.LockItemsForRead(true);
6665 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6206 { 6666 {
6207 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6667 if (inv.Value.Name == name)
6208 { 6668 {
6209 if (inv.Value.Name == name) 6669 m_host.TaskInventory.LockItemsForRead(false);
6210 return inv.Key; 6670 return inv.Key;
6211 } 6671 }
6212 } 6672 }
6673 m_host.TaskInventory.LockItemsForRead(false);
6213 6674
6214 return UUID.Zero; 6675 return UUID.Zero;
6215 } 6676 }
@@ -6459,13 +6920,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6459 UUID av = new UUID(); 6920 UUID av = new UUID();
6460 if (!UUID.TryParse(avatar,out av)) 6921 if (!UUID.TryParse(avatar,out av))
6461 { 6922 {
6462 LSLError("First parameter to llDialog needs to be a key"); 6923 //LSLError("First parameter to llDialog needs to be a key");
6463 return; 6924 return;
6464 } 6925 }
6465 if (buttons.Length < 1) 6926 if (buttons.Length < 1)
6466 { 6927 {
6467 LSLError("No less than 1 button can be shown"); 6928 buttons.Add("OK");
6468 return;
6469 } 6929 }
6470 if (buttons.Length > 12) 6930 if (buttons.Length > 12)
6471 { 6931 {
@@ -6482,7 +6942,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6482 } 6942 }
6483 if (buttons.Data[i].ToString().Length > 24) 6943 if (buttons.Data[i].ToString().Length > 24)
6484 { 6944 {
6485 LSLError("button label cannot be longer than 24 characters"); 6945 llWhisper(ScriptBaseClass.DEBUG_CHANNEL, "button label cannot be longer than 24 characters");
6486 return; 6946 return;
6487 } 6947 }
6488 buts[i] = buttons.Data[i].ToString(); 6948 buts[i] = buttons.Data[i].ToString();
@@ -6541,22 +7001,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6541 } 7001 }
6542 7002
6543 // copy the first script found with this inventory name 7003 // copy the first script found with this inventory name
6544 lock (m_host.TaskInventory) 7004 TaskInventoryItem scriptItem = null;
7005 m_host.TaskInventory.LockItemsForRead(true);
7006 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6545 { 7007 {
6546 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 7008 if (inv.Value.Name == name)
6547 { 7009 {
6548 if (inv.Value.Name == name) 7010 // make sure the object is a script
7011 if (10 == inv.Value.Type)
6549 { 7012 {
6550 // make sure the object is a script 7013 found = true;
6551 if (10 == inv.Value.Type) 7014 srcId = inv.Key;
6552 { 7015 scriptItem = inv.Value;
6553 found = true; 7016 break;
6554 srcId = inv.Key;
6555 break;
6556 }
6557 } 7017 }
6558 } 7018 }
6559 } 7019 }
7020 m_host.TaskInventory.LockItemsForRead(false);
6560 7021
6561 if (!found) 7022 if (!found)
6562 { 7023 {
@@ -6564,8 +7025,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6564 return; 7025 return;
6565 } 7026 }
6566 7027
6567 // the rest of the permission checks are done in RezScript, so check the pin there as well 7028 SceneObjectPart dest = World.GetSceneObjectPart(destId);
6568 World.RezScript(srcId, m_host, destId, pin, running, start_param); 7029 if (dest != null)
7030 {
7031 if ((scriptItem.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
7032 {
7033 // the rest of the permission checks are done in RezScript, so check the pin there as well
7034 World.RezScript(srcId, m_host, destId, pin, running, start_param);
7035
7036 if ((scriptItem.BasePermissions & (uint)PermissionMask.Copy) == 0)
7037 m_host.Inventory.RemoveInventoryItem(srcId);
7038 }
7039 }
6569 // this will cause the delay even if the script pin or permissions were wrong - seems ok 7040 // this will cause the delay even if the script pin or permissions were wrong - seems ok
6570 ScriptSleep(3000); 7041 ScriptSleep(3000);
6571 } 7042 }
@@ -6628,19 +7099,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6628 public LSL_String llMD5String(string src, int nonce) 7099 public LSL_String llMD5String(string src, int nonce)
6629 { 7100 {
6630 m_host.AddScriptLPS(1); 7101 m_host.AddScriptLPS(1);
6631 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString())); 7102 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
6632 } 7103 }
6633 7104
6634 public LSL_String llSHA1String(string src) 7105 public LSL_String llSHA1String(string src)
6635 { 7106 {
6636 m_host.AddScriptLPS(1); 7107 m_host.AddScriptLPS(1);
6637 return Util.SHA1Hash(src).ToLower(); 7108 return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
6638 } 7109 }
6639 7110
6640 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve) 7111 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
6641 { 7112 {
6642 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7113 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
6643 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7114 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
7115 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7116 return shapeBlock;
6644 7117
6645 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && 7118 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
6646 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && 7119 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
@@ -6745,6 +7218,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6745 // Prim type box, cylinder and prism. 7218 // Prim type box, cylinder and prism.
6746 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte profileshape, byte pathcurve) 7219 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte profileshape, byte pathcurve)
6747 { 7220 {
7221 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7222 return;
7223
6748 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7224 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
6749 ObjectShapePacket.ObjectDataBlock shapeBlock; 7225 ObjectShapePacket.ObjectDataBlock shapeBlock;
6750 7226
@@ -6798,6 +7274,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6798 // Prim type sphere. 7274 // Prim type sphere.
6799 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve) 7275 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
6800 { 7276 {
7277 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7278 return;
7279
6801 ObjectShapePacket.ObjectDataBlock shapeBlock; 7280 ObjectShapePacket.ObjectDataBlock shapeBlock;
6802 7281
6803 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve); 7282 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
@@ -6839,6 +7318,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6839 // Prim type torus, tube and ring. 7318 // Prim type torus, tube and ring.
6840 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 profileshape, byte pathcurve) 7319 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 profileshape, byte pathcurve)
6841 { 7320 {
7321 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7322 return;
7323
6842 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7324 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
6843 ObjectShapePacket.ObjectDataBlock shapeBlock; 7325 ObjectShapePacket.ObjectDataBlock shapeBlock;
6844 7326
@@ -6974,6 +7456,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6974 // Prim type sculpt. 7456 // Prim type sculpt.
6975 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve) 7457 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
6976 { 7458 {
7459 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7460 return;
7461
6977 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7462 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6978 UUID sculptId; 7463 UUID sculptId;
6979 7464
@@ -6990,13 +7475,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6990 shapeBlock.PathScaleX = 100; 7475 shapeBlock.PathScaleX = 100;
6991 shapeBlock.PathScaleY = 150; 7476 shapeBlock.PathScaleY = 150;
6992 7477
6993 if (type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER && 7478 if ((type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER) == 0 &&
6994 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE && 7479 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE) == 0 &&
6995 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE && 7480 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE) == 0 &&
6996 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) 7481 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) == 0)
6997 { 7482 {
6998 // default 7483 // default
6999 type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; 7484 type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
7000 } 7485 }
7001 7486
7002 part.Shape.SetSculptProperties((byte)type, sculptId); 7487 part.Shape.SetSculptProperties((byte)type, sculptId);
@@ -7012,32 +7497,87 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7012 ScriptSleep(200); 7497 ScriptSleep(200);
7013 } 7498 }
7014 7499
7015 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) 7500 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
7016 { 7501 {
7017 m_host.AddScriptLPS(1); 7502 m_host.AddScriptLPS(1);
7018 7503
7019 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7504 List<SceneObjectPart> parts = GetLinkParts(linknumber);
7505 List<ScenePresence> avatars = GetLinkAvatars(linknumber);
7506 if (parts.Count>0)
7507 {
7508 try
7509 {
7510 parts[0].ParentGroup.areUpdatesSuspended = true;
7511 foreach (SceneObjectPart part in parts)
7512 SetPrimParams(part, rules);
7513 }
7514 finally
7515 {
7516 parts[0].ParentGroup.areUpdatesSuspended = false;
7517 }
7518 }
7519 if (avatars.Count > 0)
7520 {
7521 foreach (ScenePresence avatar in avatars)
7522 SetPrimParams(avatar, rules);
7523 }
7524 }
7020 7525
7021 foreach (SceneObjectPart part in parts) 7526 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
7022 SetPrimParams(part, rules); 7527 {
7023 7528 llSetLinkPrimitiveParamsFast(linknumber, rules);
7024 ScriptSleep(200); 7529 ScriptSleep(200);
7025 } 7530 }
7026 7531
7027 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) 7532 protected void SetPrimParams(ScenePresence av, LSL_List rules)
7028 { 7533 {
7029 m_host.AddScriptLPS(1); 7534 //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
7535 //We only support PRIM_POSITION and PRIM_ROTATION
7030 7536
7031 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7537 int idx = 0;
7032 7538
7033 foreach (SceneObjectPart part in parts) 7539 while (idx < rules.Length)
7034 SetPrimParams(part, rules); 7540 {
7541 int code = rules.GetLSLIntegerItem(idx++);
7542
7543 int remain = rules.Length - idx;
7544
7545
7546
7547 switch (code)
7548 {
7549 case (int)ScriptBaseClass.PRIM_POSITION:
7550 if (remain < 1)
7551 return;
7552 LSL_Vector v;
7553 v = rules.GetVector3Item(idx++);
7554 av.AbsolutePosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
7555 av.SendAvatarDataToAllAgents();
7556
7557 break;
7558
7559 case (int)ScriptBaseClass.PRIM_ROTATION:
7560 if (remain < 1)
7561 return;
7562 LSL_Rotation r;
7563 r = rules.GetQuaternionItem(idx++);
7564 av.OffsetRotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
7565 av.SendAvatarDataToAllAgents();
7566 break;
7567 }
7568 }
7035 } 7569 }
7036 7570
7037 protected void SetPrimParams(SceneObjectPart part, LSL_List rules) 7571 protected void SetPrimParams(SceneObjectPart part, LSL_List rules)
7038 { 7572 {
7573 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7574 return;
7575
7039 int idx = 0; 7576 int idx = 0;
7040 7577
7578 bool positionChanged = false;
7579 LSL_Vector currentPosition = GetPartLocalPos(part);
7580
7041 while (idx < rules.Length) 7581 while (idx < rules.Length)
7042 { 7582 {
7043 int code = rules.GetLSLIntegerItem(idx++); 7583 int code = rules.GetLSLIntegerItem(idx++);
@@ -7046,7 +7586,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7046 7586
7047 int face; 7587 int face;
7048 LSL_Vector v; 7588 LSL_Vector v;
7049 7589
7050 switch (code) 7590 switch (code)
7051 { 7591 {
7052 case (int)ScriptBaseClass.PRIM_POSITION: 7592 case (int)ScriptBaseClass.PRIM_POSITION:
@@ -7054,7 +7594,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7054 return; 7594 return;
7055 7595
7056 v=rules.GetVector3Item(idx++); 7596 v=rules.GetVector3Item(idx++);
7057 SetPos(part, v); 7597 positionChanged = true;
7598 currentPosition = GetSetPosTarget(part, v, currentPosition);
7058 7599
7059 break; 7600 break;
7060 case (int)ScriptBaseClass.PRIM_SIZE: 7601 case (int)ScriptBaseClass.PRIM_SIZE:
@@ -7399,6 +7940,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7399 break; 7940 break;
7400 } 7941 }
7401 } 7942 }
7943
7944 if (positionChanged)
7945 {
7946 if (part.ParentGroup.RootPart == part)
7947 {
7948 SceneObjectGroup parent = part.ParentGroup;
7949 parent.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z));
7950 }
7951 else
7952 {
7953 part.OffsetPosition = new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z);
7954 SceneObjectGroup parent = part.ParentGroup;
7955 parent.HasGroupChanged = true;
7956 parent.ScheduleGroupForTerseUpdate();
7957 }
7958 }
7402 } 7959 }
7403 7960
7404 public LSL_String llStringToBase64(string str) 7961 public LSL_String llStringToBase64(string str)
@@ -7547,13 +8104,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7547 public LSL_Integer llGetNumberOfPrims() 8104 public LSL_Integer llGetNumberOfPrims()
7548 { 8105 {
7549 m_host.AddScriptLPS(1); 8106 m_host.AddScriptLPS(1);
7550 int avatarCount = 0; 8107 int avatarCount = m_host.ParentGroup.GetLinkedAvatars().Count;
7551 World.ForEachScenePresence(delegate(ScenePresence presence) 8108
7552 {
7553 if (!presence.IsChildAgent && presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID))
7554 avatarCount++;
7555 });
7556
7557 return m_host.ParentGroup.PrimCount + avatarCount; 8109 return m_host.ParentGroup.PrimCount + avatarCount;
7558 } 8110 }
7559 8111
@@ -7569,55 +8121,98 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7569 m_host.AddScriptLPS(1); 8121 m_host.AddScriptLPS(1);
7570 UUID objID = UUID.Zero; 8122 UUID objID = UUID.Zero;
7571 LSL_List result = new LSL_List(); 8123 LSL_List result = new LSL_List();
8124
8125 // If the ID is not valid, return null result
7572 if (!UUID.TryParse(obj, out objID)) 8126 if (!UUID.TryParse(obj, out objID))
7573 { 8127 {
7574 result.Add(new LSL_Vector()); 8128 result.Add(new LSL_Vector());
7575 result.Add(new LSL_Vector()); 8129 result.Add(new LSL_Vector());
7576 return result; 8130 return result;
7577 } 8131 }
8132
8133 // Check if this is an attached prim. If so, replace
8134 // the UUID with the avatar UUID and report it's bounding box
8135 SceneObjectPart part = World.GetSceneObjectPart(objID);
8136 if (part != null && part.ParentGroup.IsAttachment)
8137 objID = part.ParentGroup.AttachedAvatar;
8138
8139 // Find out if this is an avatar ID. If so, return it's box
7578 ScenePresence presence = World.GetScenePresence(objID); 8140 ScenePresence presence = World.GetScenePresence(objID);
7579 if (presence != null) 8141 if (presence != null)
7580 { 8142 {
7581 if (presence.ParentID == 0) // not sat on an object 8143 // As per LSL Wiki, there is no difference between sitting
8144 // and standing avatar since server 1.36
8145 LSL_Vector lower;
8146 LSL_Vector upper;
8147 if (presence.Animator.Animations.DefaultAnimation.AnimID
8148 == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
7582 { 8149 {
7583 LSL_Vector lower; 8150 // This is for ground sitting avatars
7584 LSL_Vector upper; 8151 float height = presence.Appearance.AvatarHeight / 2.66666667f;
7585 if (presence.Animator.Animations.DefaultAnimation.AnimID 8152 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
7586 == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) 8153 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
7587 {
7588 // This is for ground sitting avatars
7589 float height = presence.Appearance.AvatarHeight / 2.66666667f;
7590 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
7591 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
7592 }
7593 else
7594 {
7595 // This is for standing/flying avatars
7596 float height = presence.Appearance.AvatarHeight / 2.0f;
7597 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
7598 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
7599 }
7600 result.Add(lower);
7601 result.Add(upper);
7602 return result;
7603 } 8154 }
7604 else 8155 else
7605 { 8156 {
7606 // sitting on an object so we need the bounding box of that 8157 // This is for standing/flying avatars
7607 // which should include the avatar so set the UUID to the 8158 float height = presence.Appearance.AvatarHeight / 2.0f;
7608 // UUID of the object the avatar is sat on and allow it to fall through 8159 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
7609 // to processing an object 8160 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
7610 SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
7611 objID = p.UUID;
7612 } 8161 }
8162
8163 // Adjust to the documented error offsets (see LSL Wiki)
8164 lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
8165 upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
8166
8167 if (lower.x > upper.x)
8168 lower.x = upper.x;
8169 if (lower.y > upper.y)
8170 lower.y = upper.y;
8171 if (lower.z > upper.z)
8172 lower.z = upper.z;
8173
8174 result.Add(lower);
8175 result.Add(upper);
8176 return result;
7613 } 8177 }
7614 SceneObjectPart part = World.GetSceneObjectPart(objID); 8178
8179 part = World.GetSceneObjectPart(objID);
7615 // Currently only works for single prims without a sitting avatar 8180 // Currently only works for single prims without a sitting avatar
7616 if (part != null) 8181 if (part != null)
7617 { 8182 {
7618 Vector3 halfSize = part.Scale / 2.0f; 8183 float minX;
7619 LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f); 8184 float maxX;
7620 LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z); 8185 float minY;
8186 float maxY;
8187 float minZ;
8188 float maxZ;
8189
8190 // This BBox is in sim coordinates, with the offset being
8191 // a contained point.
8192 Vector3[] offsets = Scene.GetCombinedBoundingBox(new List<SceneObjectGroup> { part.ParentGroup },
8193 out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
8194
8195 minX -= offsets[0].X;
8196 maxX -= offsets[0].X;
8197 minY -= offsets[0].Y;
8198 maxY -= offsets[0].Y;
8199 minZ -= offsets[0].Z;
8200 maxZ -= offsets[0].Z;
8201
8202 LSL_Vector lower;
8203 LSL_Vector upper;
8204
8205 // Adjust to the documented error offsets (see LSL Wiki)
8206 lower = new LSL_Vector(minX + 0.05f, minY + 0.05f, minZ + 0.05f);
8207 upper = new LSL_Vector(maxX - 0.05f, maxY - 0.05f, maxZ - 0.05f);
8208
8209 if (lower.x > upper.x)
8210 lower.x = upper.x;
8211 if (lower.y > upper.y)
8212 lower.y = upper.y;
8213 if (lower.z > upper.z)
8214 lower.z = upper.z;
8215
7621 result.Add(lower); 8216 result.Add(lower);
7622 result.Add(upper); 8217 result.Add(upper);
7623 return result; 8218 return result;
@@ -7697,13 +8292,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7697 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X, 8292 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
7698 part.AbsolutePosition.Y, 8293 part.AbsolutePosition.Y,
7699 part.AbsolutePosition.Z); 8294 part.AbsolutePosition.Z);
7700 // For some reason, the part.AbsolutePosition.* values do not change if the
7701 // linkset is rotated; they always reflect the child prim's world position
7702 // as though the linkset is unrotated. This is incompatible behavior with SL's
7703 // implementation, so will break scripts imported from there (not to mention it
7704 // makes it more difficult to determine a child prim's actual inworld position).
7705 if (part.ParentID != 0)
7706 v = ((v - llGetRootPosition()) * llGetRootRotation()) + llGetRootPosition();
7707 res.Add(v); 8295 res.Add(v);
7708 break; 8296 break;
7709 8297
@@ -7874,56 +8462,92 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7874 case (int)ScriptBaseClass.PRIM_BUMP_SHINY: 8462 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
7875 if (remain < 1) 8463 if (remain < 1)
7876 return res; 8464 return res;
7877 8465 face = (int)rules.GetLSLIntegerItem(idx++);
7878 face=(int)rules.GetLSLIntegerItem(idx++);
7879 8466
7880 tex = part.Shape.Textures; 8467 tex = part.Shape.Textures;
8468 int shiny;
7881 if (face == ScriptBaseClass.ALL_SIDES) 8469 if (face == ScriptBaseClass.ALL_SIDES)
7882 { 8470 {
7883 for (face = 0; face < GetNumberOfSides(part); face++) 8471 for (face = 0; face < GetNumberOfSides(part); face++)
7884 { 8472 {
7885 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8473 Shininess shinyness = tex.GetFace((uint)face).Shiny;
7886 // Convert Shininess to PRIM_SHINY_* 8474 if (shinyness == Shininess.High)
7887 res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); 8475 {
7888 // PRIM_BUMP_* 8476 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
7889 res.Add(new LSL_Integer((int)texface.Bump)); 8477 }
8478 else if (shinyness == Shininess.Medium)
8479 {
8480 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8481 }
8482 else if (shinyness == Shininess.Low)
8483 {
8484 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8485 }
8486 else
8487 {
8488 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8489 }
8490 res.Add(new LSL_Integer(shiny));
8491 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
7890 } 8492 }
7891 } 8493 }
7892 else 8494 else
7893 { 8495 {
7894 if (face >= 0 && face < GetNumberOfSides(part)) 8496 Shininess shinyness = tex.GetFace((uint)face).Shiny;
8497 if (shinyness == Shininess.High)
7895 { 8498 {
7896 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8499 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
7897 // Convert Shininess to PRIM_SHINY_* 8500 }
7898 res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); 8501 else if (shinyness == Shininess.Medium)
7899 // PRIM_BUMP_* 8502 {
7900 res.Add(new LSL_Integer((int)texface.Bump)); 8503 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
7901 } 8504 }
8505 else if (shinyness == Shininess.Low)
8506 {
8507 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8508 }
8509 else
8510 {
8511 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8512 }
8513 res.Add(new LSL_Integer(shiny));
8514 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
7902 } 8515 }
7903 break; 8516 break;
7904 8517
7905 case (int)ScriptBaseClass.PRIM_FULLBRIGHT: 8518 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
7906 if (remain < 1) 8519 if (remain < 1)
7907 return res; 8520 return res;
7908 8521 face = (int)rules.GetLSLIntegerItem(idx++);
7909 face=(int)rules.GetLSLIntegerItem(idx++);
7910 8522
7911 tex = part.Shape.Textures; 8523 tex = part.Shape.Textures;
8524 int fullbright;
7912 if (face == ScriptBaseClass.ALL_SIDES) 8525 if (face == ScriptBaseClass.ALL_SIDES)
7913 { 8526 {
7914 for (face = 0; face < GetNumberOfSides(part); face++) 8527 for (face = 0; face < GetNumberOfSides(part); face++)
7915 { 8528 {
7916 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8529 if (tex.GetFace((uint)face).Fullbright == true)
7917 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); 8530 {
8531 fullbright = ScriptBaseClass.TRUE;
8532 }
8533 else
8534 {
8535 fullbright = ScriptBaseClass.FALSE;
8536 }
8537 res.Add(new LSL_Integer(fullbright));
7918 } 8538 }
7919 } 8539 }
7920 else 8540 else
7921 { 8541 {
7922 if (face >= 0 && face < GetNumberOfSides(part)) 8542 if (tex.GetFace((uint)face).Fullbright == true)
7923 { 8543 {
7924 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8544 fullbright = ScriptBaseClass.TRUE;
7925 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); 8545 }
8546 else
8547 {
8548 fullbright = ScriptBaseClass.FALSE;
7926 } 8549 }
8550 res.Add(new LSL_Integer(fullbright));
7927 } 8551 }
7928 break; 8552 break;
7929 8553
@@ -7945,27 +8569,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7945 break; 8569 break;
7946 8570
7947 case (int)ScriptBaseClass.PRIM_TEXGEN: 8571 case (int)ScriptBaseClass.PRIM_TEXGEN:
8572 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
7948 if (remain < 1) 8573 if (remain < 1)
7949 return res; 8574 return res;
7950 8575 face = (int)rules.GetLSLIntegerItem(idx++);
7951 face=(int)rules.GetLSLIntegerItem(idx++);
7952 8576
7953 tex = part.Shape.Textures; 8577 tex = part.Shape.Textures;
7954 if (face == ScriptBaseClass.ALL_SIDES) 8578 if (face == ScriptBaseClass.ALL_SIDES)
7955 { 8579 {
7956 for (face = 0; face < GetNumberOfSides(part); face++) 8580 for (face = 0; face < GetNumberOfSides(part); face++)
7957 { 8581 {
7958 MappingType texgen = tex.GetFace((uint)face).TexMapType; 8582 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
7959 // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc. 8583 {
7960 res.Add(new LSL_Integer((uint)texgen >> 1)); 8584 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8585 }
8586 else
8587 {
8588 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8589 }
7961 } 8590 }
7962 } 8591 }
7963 else 8592 else
7964 { 8593 {
7965 if (face >= 0 && face < GetNumberOfSides(part)) 8594 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8595 {
8596 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8597 }
8598 else
7966 { 8599 {
7967 MappingType texgen = tex.GetFace((uint)face).TexMapType; 8600 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
7968 res.Add(new LSL_Integer((uint)texgen >> 1));
7969 } 8601 }
7970 } 8602 }
7971 break; 8603 break;
@@ -7988,28 +8620,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7988 case (int)ScriptBaseClass.PRIM_GLOW: 8620 case (int)ScriptBaseClass.PRIM_GLOW:
7989 if (remain < 1) 8621 if (remain < 1)
7990 return res; 8622 return res;
7991 8623 face = (int)rules.GetLSLIntegerItem(idx++);
7992 face=(int)rules.GetLSLIntegerItem(idx++);
7993 8624
7994 tex = part.Shape.Textures; 8625 tex = part.Shape.Textures;
8626 float primglow;
7995 if (face == ScriptBaseClass.ALL_SIDES) 8627 if (face == ScriptBaseClass.ALL_SIDES)
7996 { 8628 {
7997 for (face = 0; face < GetNumberOfSides(part); face++) 8629 for (face = 0; face < GetNumberOfSides(part); face++)
7998 { 8630 {
7999 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8631 primglow = tex.GetFace((uint)face).Glow;
8000 res.Add(new LSL_Float(texface.Glow)); 8632 res.Add(new LSL_Float(primglow));
8001 } 8633 }
8002 } 8634 }
8003 else 8635 else
8004 { 8636 {
8005 if (face >= 0 && face < GetNumberOfSides(part)) 8637 primglow = tex.GetFace((uint)face).Glow;
8006 { 8638 res.Add(new LSL_Float(primglow));
8007 Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
8008 res.Add(new LSL_Float(texface.Glow));
8009 }
8010 } 8639 }
8011 break; 8640 break;
8012
8013 case (int)ScriptBaseClass.PRIM_TEXT: 8641 case (int)ScriptBaseClass.PRIM_TEXT:
8014 Color4 textColor = part.GetTextColor(); 8642 Color4 textColor = part.GetTextColor();
8015 res.Add(new LSL_String(part.Text)); 8643 res.Add(new LSL_String(part.Text));
@@ -8558,8 +9186,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8558 // The function returns an ordered list 9186 // The function returns an ordered list
8559 // representing the tokens found in the supplied 9187 // representing the tokens found in the supplied
8560 // sources string. If two successive tokenizers 9188 // sources string. If two successive tokenizers
8561 // are encountered, then a NULL entry is added 9189 // are encountered, then a null-string entry is
8562 // to the list. 9190 // added to the list.
8563 // 9191 //
8564 // It is a precondition that the source and 9192 // It is a precondition that the source and
8565 // toekizer lisst are non-null. If they are null, 9193 // toekizer lisst are non-null. If they are null,
@@ -8567,7 +9195,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8567 // while their lengths are being determined. 9195 // while their lengths are being determined.
8568 // 9196 //
8569 // A small amount of working memoryis required 9197 // A small amount of working memoryis required
8570 // of approximately 8*#tokenizers. 9198 // of approximately 8*#tokenizers + 8*srcstrlen.
8571 // 9199 //
8572 // There are many ways in which this function 9200 // There are many ways in which this function
8573 // can be implemented, this implementation is 9201 // can be implemented, this implementation is
@@ -8583,155 +9211,124 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8583 // and eliminates redundant tokenizers as soon 9211 // and eliminates redundant tokenizers as soon
8584 // as is possible. 9212 // as is possible.
8585 // 9213 //
8586 // The implementation tries to avoid any copying 9214 // The implementation tries to minimize temporary
8587 // of arrays or other objects. 9215 // garbage generation.
8588 // </remarks> 9216 // </remarks>
8589 9217
8590 private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls) 9218 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
8591 { 9219 {
8592 int beginning = 0; 9220 return ParseString2List(src, separators, spacers, true);
8593 int srclen = src.Length; 9221 }
8594 int seplen = separators.Length;
8595 object[] separray = separators.Data;
8596 int spclen = spacers.Length;
8597 object[] spcarray = spacers.Data;
8598 int mlen = seplen+spclen;
8599
8600 int[] offset = new int[mlen+1];
8601 bool[] active = new bool[mlen];
8602
8603 int best;
8604 int j;
8605
8606 // Initial capacity reduces resize cost
8607 9222
8608 LSL_List tokens = new LSL_List(); 9223 private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
9224 {
9225 int srclen = src.Length;
9226 int seplen = separators.Length;
9227 object[] separray = separators.Data;
9228 int spclen = spacers.Length;
9229 object[] spcarray = spacers.Data;
9230 int dellen = 0;
9231 string[] delarray = new string[seplen+spclen];
8609 9232
8610 // All entries are initially valid 9233 int outlen = 0;
9234 string[] outarray = new string[srclen*2+1];
8611 9235
8612 for (int i = 0; i < mlen; i++) 9236 int i, j;
8613 active[i] = true; 9237 string d;
8614 9238
8615 offset[mlen] = srclen; 9239 m_host.AddScriptLPS(1);
8616 9240
8617 while (beginning < srclen) 9241 /*
9242 * Convert separator and spacer lists to C# strings.
9243 * Also filter out null strings so we don't hang.
9244 */
9245 for (i = 0; i < seplen; i ++)
8618 { 9246 {
9247 d = separray[i].ToString();
9248 if (d.Length > 0)
9249 {
9250 delarray[dellen++] = d;
9251 }
9252 }
9253 seplen = dellen;
8619 9254
8620 best = mlen; // as bad as it gets 9255 for (i = 0; i < spclen; i ++)
9256 {
9257 d = spcarray[i].ToString();
9258 if (d.Length > 0)
9259 {
9260 delarray[dellen++] = d;
9261 }
9262 }
8621 9263
8622 // Scan for separators 9264 /*
9265 * Scan through source string from beginning to end.
9266 */
9267 for (i = 0;;)
9268 {
8623 9269
8624 for (j = 0; j < seplen; j++) 9270 /*
9271 * Find earliest delimeter in src starting at i (if any).
9272 */
9273 int earliestDel = -1;
9274 int earliestSrc = srclen;
9275 string earliestStr = null;
9276 for (j = 0; j < dellen; j ++)
8625 { 9277 {
8626 if (separray[j].ToString() == String.Empty) 9278 d = delarray[j];
8627 active[j] = false; 9279 if (d != null)
8628
8629 if (active[j])
8630 { 9280 {
8631 // scan all of the markers 9281 int index = src.IndexOf(d, i);
8632 if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1) 9282 if (index < 0)
8633 { 9283 {
8634 // not present at all 9284 delarray[j] = null; // delim nowhere in src, don't check it anymore
8635 active[j] = false;
8636 } 9285 }
8637 else 9286 else if (index < earliestSrc)
8638 { 9287 {
8639 // present and correct 9288 earliestSrc = index; // where delimeter starts in source string
8640 if (offset[j] < offset[best]) 9289 earliestDel = j; // where delimeter is in delarray[]
8641 { 9290 earliestStr = d; // the delimeter string from delarray[]
8642 // closest so far 9291 if (index == i) break; // can't do any better than found at beg of string
8643 best = j;
8644 if (offset[best] == beginning)
8645 break;
8646 }
8647 } 9292 }
8648 } 9293 }
8649 } 9294 }
8650 9295
8651 // Scan for spacers 9296 /*
8652 9297 * Output source string starting at i through start of earliest delimeter.
8653 if (offset[best] != beginning) 9298 */
9299 if (keepNulls || (earliestSrc > i))
8654 { 9300 {
8655 for (j = seplen; (j < mlen) && (offset[best] > beginning); j++) 9301 outarray[outlen++] = src.Substring(i, earliestSrc - i);
8656 {
8657 if (spcarray[j-seplen].ToString() == String.Empty)
8658 active[j] = false;
8659
8660 if (active[j])
8661 {
8662 // scan all of the markers
8663 if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
8664 {
8665 // not present at all
8666 active[j] = false;
8667 }
8668 else
8669 {
8670 // present and correct
8671 if (offset[j] < offset[best])
8672 {
8673 // closest so far
8674 best = j;
8675 }
8676 }
8677 }
8678 }
8679 } 9302 }
8680 9303
8681 // This is the normal exit from the scanning loop 9304 /*
9305 * If no delimeter found at or after i, we're done scanning.
9306 */
9307 if (earliestDel < 0) break;
8682 9308
8683 if (best == mlen) 9309 /*
9310 * If delimeter was a spacer, output the spacer.
9311 */
9312 if (earliestDel >= seplen)
8684 { 9313 {
8685 // no markers were found on this pass 9314 outarray[outlen++] = earliestStr;
8686 // so we're pretty much done
8687 if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0))
8688 tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
8689 break;
8690 } 9315 }
8691 9316
8692 // Otherwise we just add the newly delimited token 9317 /*
8693 // and recalculate where the search should continue. 9318 * Look at rest of src string following delimeter.
8694 if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0)) 9319 */
8695 tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning))); 9320 i = earliestSrc + earliestStr.Length;
8696
8697 if (best < seplen)
8698 {
8699 beginning = offset[best] + (separray[best].ToString()).Length;
8700 }
8701 else
8702 {
8703 beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
8704 string str = spcarray[best - seplen].ToString();
8705 if ((keepNulls) || ((!keepNulls) && (str.Length > 0)))
8706 tokens.Add(new LSL_String(str));
8707 }
8708 } 9321 }
8709 9322
8710 // This an awkward an not very intuitive boundary case. If the 9323 /*
8711 // last substring is a tokenizer, then there is an implied trailing 9324 * Make up an exact-sized output array suitable for an LSL_List object.
8712 // null list entry. Hopefully the single comparison will not be too 9325 */
8713 // arduous. Alternatively the 'break' could be replced with a return 9326 object[] outlist = new object[outlen];
8714 // but that's shabby programming. 9327 for (i = 0; i < outlen; i ++)
8715
8716 if ((beginning == srclen) && (keepNulls))
8717 { 9328 {
8718 if (srclen != 0) 9329 outlist[i] = new LSL_String(outarray[i]);
8719 tokens.Add(new LSL_String(""));
8720 } 9330 }
8721 9331 return new LSL_List(outlist);
8722 return tokens;
8723 }
8724
8725 public LSL_List llParseString2List(string src, LSL_List separators, LSL_List spacers)
8726 {
8727 m_host.AddScriptLPS(1);
8728 return this.ParseString(src, separators, spacers, false);
8729 }
8730
8731 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
8732 {
8733 m_host.AddScriptLPS(1);
8734 return this.ParseString(src, separators, spacers, true);
8735 } 9332 }
8736 9333
8737 public LSL_Integer llGetObjectPermMask(int mask) 9334 public LSL_Integer llGetObjectPermMask(int mask)
@@ -8808,28 +9405,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8808 { 9405 {
8809 m_host.AddScriptLPS(1); 9406 m_host.AddScriptLPS(1);
8810 9407
8811 lock (m_host.TaskInventory) 9408 m_host.TaskInventory.LockItemsForRead(true);
9409 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8812 { 9410 {
8813 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9411 if (inv.Value.Name == item)
8814 { 9412 {
8815 if (inv.Value.Name == item) 9413 m_host.TaskInventory.LockItemsForRead(false);
9414 switch (mask)
8816 { 9415 {
8817 switch (mask) 9416 case 0:
8818 { 9417 return (int)inv.Value.BasePermissions;
8819 case 0: 9418 case 1:
8820 return (int)inv.Value.BasePermissions; 9419 return (int)inv.Value.CurrentPermissions;
8821 case 1: 9420 case 2:
8822 return (int)inv.Value.CurrentPermissions; 9421 return (int)inv.Value.GroupPermissions;
8823 case 2: 9422 case 3:
8824 return (int)inv.Value.GroupPermissions; 9423 return (int)inv.Value.EveryonePermissions;
8825 case 3: 9424 case 4:
8826 return (int)inv.Value.EveryonePermissions; 9425 return (int)inv.Value.NextPermissions;
8827 case 4:
8828 return (int)inv.Value.NextPermissions;
8829 }
8830 } 9426 }
8831 } 9427 }
8832 } 9428 }
9429 m_host.TaskInventory.LockItemsForRead(false);
8833 9430
8834 return -1; 9431 return -1;
8835 } 9432 }
@@ -8876,16 +9473,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8876 { 9473 {
8877 m_host.AddScriptLPS(1); 9474 m_host.AddScriptLPS(1);
8878 9475
8879 lock (m_host.TaskInventory) 9476 m_host.TaskInventory.LockItemsForRead(true);
9477 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8880 { 9478 {
8881 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9479 if (inv.Value.Name == item)
8882 { 9480 {
8883 if (inv.Value.Name == item) 9481 m_host.TaskInventory.LockItemsForRead(false);
8884 { 9482 return inv.Value.CreatorID.ToString();
8885 return inv.Value.CreatorID.ToString();
8886 }
8887 } 9483 }
8888 } 9484 }
9485 m_host.TaskInventory.LockItemsForRead(false);
8889 9486
8890 llSay(0, "No item name '" + item + "'"); 9487 llSay(0, "No item name '" + item + "'");
8891 9488
@@ -9033,7 +9630,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9033 } 9630 }
9034 9631
9035 /// <summary> 9632 /// <summary>
9036 /// illListReplaceList removes the sub-list defined by the inclusive indices 9633 /// llListReplaceList removes the sub-list defined by the inclusive indices
9037 /// start and end and inserts the src list in its place. The inclusive 9634 /// start and end and inserts the src list in its place. The inclusive
9038 /// nature of the indices means that at least one element must be deleted 9635 /// nature of the indices means that at least one element must be deleted
9039 /// if the indices are within the bounds of the existing list. I.e. 2,2 9636 /// if the indices are within the bounds of the existing list. I.e. 2,2
@@ -9090,16 +9687,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9090 // based upon end. Note that if end exceeds the upper 9687 // based upon end. Note that if end exceeds the upper
9091 // bound in this case, the entire destination list 9688 // bound in this case, the entire destination list
9092 // is removed. 9689 // is removed.
9093 else 9690 else if (start == 0)
9094 { 9691 {
9095 if (end + 1 < dest.Length) 9692 if (end + 1 < dest.Length)
9096 {
9097 return src + dest.GetSublist(end + 1, -1); 9693 return src + dest.GetSublist(end + 1, -1);
9098 }
9099 else 9694 else
9100 {
9101 return src; 9695 return src;
9102 } 9696 }
9697 else // Start < 0
9698 {
9699 if (end + 1 < dest.Length)
9700 return dest.GetSublist(end + 1, -1);
9701 else
9702 return new LSL_List();
9103 } 9703 }
9104 } 9704 }
9105 // Finally, if start > end, we strip away a prefix and 9705 // Finally, if start > end, we strip away a prefix and
@@ -9150,17 +9750,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9150 int width = 0; 9750 int width = 0;
9151 int height = 0; 9751 int height = 0;
9152 9752
9153 ParcelMediaCommandEnum? commandToSend = null; 9753 uint commandToSend = 0;
9154 float time = 0.0f; // default is from start 9754 float time = 0.0f; // default is from start
9155 9755
9156 ScenePresence presence = null; 9756 ScenePresence presence = null;
9157 9757
9158 for (int i = 0; i < commandList.Data.Length; i++) 9758 for (int i = 0; i < commandList.Data.Length; i++)
9159 { 9759 {
9160 ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i]; 9760 uint command = (uint)(commandList.GetLSLIntegerItem(i));
9161 switch (command) 9761 switch (command)
9162 { 9762 {
9163 case ParcelMediaCommandEnum.Agent: 9763 case (uint)ParcelMediaCommandEnum.Agent:
9164 // we send only to one agent 9764 // we send only to one agent
9165 if ((i + 1) < commandList.Length) 9765 if ((i + 1) < commandList.Length)
9166 { 9766 {
@@ -9177,25 +9777,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9177 } 9777 }
9178 break; 9778 break;
9179 9779
9180 case ParcelMediaCommandEnum.Loop: 9780 case (uint)ParcelMediaCommandEnum.Loop:
9181 loop = 1; 9781 loop = 1;
9182 commandToSend = command; 9782 commandToSend = command;
9183 update = true; //need to send the media update packet to set looping 9783 update = true; //need to send the media update packet to set looping
9184 break; 9784 break;
9185 9785
9186 case ParcelMediaCommandEnum.Play: 9786 case (uint)ParcelMediaCommandEnum.Play:
9187 loop = 0; 9787 loop = 0;
9188 commandToSend = command; 9788 commandToSend = command;
9189 update = true; //need to send the media update packet to make sure it doesn't loop 9789 update = true; //need to send the media update packet to make sure it doesn't loop
9190 break; 9790 break;
9191 9791
9192 case ParcelMediaCommandEnum.Pause: 9792 case (uint)ParcelMediaCommandEnum.Pause:
9193 case ParcelMediaCommandEnum.Stop: 9793 case (uint)ParcelMediaCommandEnum.Stop:
9194 case ParcelMediaCommandEnum.Unload: 9794 case (uint)ParcelMediaCommandEnum.Unload:
9195 commandToSend = command; 9795 commandToSend = command;
9196 break; 9796 break;
9197 9797
9198 case ParcelMediaCommandEnum.Url: 9798 case (uint)ParcelMediaCommandEnum.Url:
9199 if ((i + 1) < commandList.Length) 9799 if ((i + 1) < commandList.Length)
9200 { 9800 {
9201 if (commandList.Data[i + 1] is LSL_String) 9801 if (commandList.Data[i + 1] is LSL_String)
@@ -9208,7 +9808,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9208 } 9808 }
9209 break; 9809 break;
9210 9810
9211 case ParcelMediaCommandEnum.Texture: 9811 case (uint)ParcelMediaCommandEnum.Texture:
9212 if ((i + 1) < commandList.Length) 9812 if ((i + 1) < commandList.Length)
9213 { 9813 {
9214 if (commandList.Data[i + 1] is LSL_String) 9814 if (commandList.Data[i + 1] is LSL_String)
@@ -9221,7 +9821,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9221 } 9821 }
9222 break; 9822 break;
9223 9823
9224 case ParcelMediaCommandEnum.Time: 9824 case (uint)ParcelMediaCommandEnum.Time:
9225 if ((i + 1) < commandList.Length) 9825 if ((i + 1) < commandList.Length)
9226 { 9826 {
9227 if (commandList.Data[i + 1] is LSL_Float) 9827 if (commandList.Data[i + 1] is LSL_Float)
@@ -9233,7 +9833,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9233 } 9833 }
9234 break; 9834 break;
9235 9835
9236 case ParcelMediaCommandEnum.AutoAlign: 9836 case (uint)ParcelMediaCommandEnum.AutoAlign:
9237 if ((i + 1) < commandList.Length) 9837 if ((i + 1) < commandList.Length)
9238 { 9838 {
9239 if (commandList.Data[i + 1] is LSL_Integer) 9839 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9247,7 +9847,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9247 } 9847 }
9248 break; 9848 break;
9249 9849
9250 case ParcelMediaCommandEnum.Type: 9850 case (uint)ParcelMediaCommandEnum.Type:
9251 if ((i + 1) < commandList.Length) 9851 if ((i + 1) < commandList.Length)
9252 { 9852 {
9253 if (commandList.Data[i + 1] is LSL_String) 9853 if (commandList.Data[i + 1] is LSL_String)
@@ -9260,7 +9860,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9260 } 9860 }
9261 break; 9861 break;
9262 9862
9263 case ParcelMediaCommandEnum.Desc: 9863 case (uint)ParcelMediaCommandEnum.Desc:
9264 if ((i + 1) < commandList.Length) 9864 if ((i + 1) < commandList.Length)
9265 { 9865 {
9266 if (commandList.Data[i + 1] is LSL_String) 9866 if (commandList.Data[i + 1] is LSL_String)
@@ -9273,7 +9873,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9273 } 9873 }
9274 break; 9874 break;
9275 9875
9276 case ParcelMediaCommandEnum.Size: 9876 case (uint)ParcelMediaCommandEnum.Size:
9277 if ((i + 2) < commandList.Length) 9877 if ((i + 2) < commandList.Length)
9278 { 9878 {
9279 if (commandList.Data[i + 1] is LSL_Integer) 9879 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9343,7 +9943,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9343 } 9943 }
9344 } 9944 }
9345 9945
9346 if (commandToSend != null) 9946 if (commandToSend != 0)
9347 { 9947 {
9348 // the commandList contained a start/stop/... command, too 9948 // the commandList contained a start/stop/... command, too
9349 if (presence == null) 9949 if (presence == null)
@@ -9380,7 +9980,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9380 9980
9381 if (aList.Data[i] != null) 9981 if (aList.Data[i] != null)
9382 { 9982 {
9383 switch ((ParcelMediaCommandEnum) aList.Data[i]) 9983 switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
9384 { 9984 {
9385 case ParcelMediaCommandEnum.Url: 9985 case ParcelMediaCommandEnum.Url:
9386 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL)); 9986 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL));
@@ -9423,16 +10023,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9423 { 10023 {
9424 m_host.AddScriptLPS(1); 10024 m_host.AddScriptLPS(1);
9425 10025
9426 lock (m_host.TaskInventory) 10026 m_host.TaskInventory.LockItemsForRead(true);
10027 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
9427 { 10028 {
9428 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 10029 if (inv.Value.Name == name)
9429 { 10030 {
9430 if (inv.Value.Name == name) 10031 m_host.TaskInventory.LockItemsForRead(false);
9431 { 10032 return inv.Value.Type;
9432 return inv.Value.Type;
9433 }
9434 } 10033 }
9435 } 10034 }
10035 m_host.TaskInventory.LockItemsForRead(false);
9436 10036
9437 return -1; 10037 return -1;
9438 } 10038 }
@@ -9443,15 +10043,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9443 10043
9444 if (quick_pay_buttons.Data.Length < 4) 10044 if (quick_pay_buttons.Data.Length < 4)
9445 { 10045 {
9446 LSLError("List must have at least 4 elements"); 10046 int x;
9447 return; 10047 for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
10048 {
10049 quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
10050 }
9448 } 10051 }
9449 m_host.ParentGroup.RootPart.PayPrice[0]=price; 10052 int[] nPrice = new int[5];
9450 10053 nPrice[0] = price;
9451 m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0]; 10054 nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
9452 m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1]; 10055 nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
9453 m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2]; 10056 nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
9454 m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3]; 10057 nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
10058 m_host.ParentGroup.RootPart.PayPrice = nPrice;
9455 m_host.ParentGroup.HasGroupChanged = true; 10059 m_host.ParentGroup.HasGroupChanged = true;
9456 } 10060 }
9457 10061
@@ -9463,17 +10067,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9463 if (invItemID == UUID.Zero) 10067 if (invItemID == UUID.Zero)
9464 return new LSL_Vector(); 10068 return new LSL_Vector();
9465 10069
9466 lock (m_host.TaskInventory) 10070 m_host.TaskInventory.LockItemsForRead(true);
10071 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
9467 { 10072 {
9468 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10073 m_host.TaskInventory.LockItemsForRead(false);
9469 return new LSL_Vector(); 10074 return new LSL_Vector();
10075 }
9470 10076
9471 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 10077 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9472 { 10078 {
9473 ShoutError("No permissions to track the camera"); 10079 ShoutError("No permissions to track the camera");
9474 return new LSL_Vector(); 10080 m_host.TaskInventory.LockItemsForRead(false);
9475 } 10081 return new LSL_Vector();
9476 } 10082 }
10083 m_host.TaskInventory.LockItemsForRead(false);
9477 10084
9478 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10085 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
9479 if (presence != null) 10086 if (presence != null)
@@ -9491,17 +10098,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9491 if (invItemID == UUID.Zero) 10098 if (invItemID == UUID.Zero)
9492 return new LSL_Rotation(); 10099 return new LSL_Rotation();
9493 10100
9494 lock (m_host.TaskInventory) 10101 m_host.TaskInventory.LockItemsForRead(true);
10102 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
9495 { 10103 {
9496 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10104 m_host.TaskInventory.LockItemsForRead(false);
9497 return new LSL_Rotation(); 10105 return new LSL_Rotation();
9498 10106 }
9499 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 10107 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9500 { 10108 {
9501 ShoutError("No permissions to track the camera"); 10109 ShoutError("No permissions to track the camera");
9502 return new LSL_Rotation(); 10110 m_host.TaskInventory.LockItemsForRead(false);
9503 } 10111 return new LSL_Rotation();
9504 } 10112 }
10113 m_host.TaskInventory.LockItemsForRead(false);
9505 10114
9506 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10115 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
9507 if (presence != null) 10116 if (presence != null)
@@ -9563,8 +10172,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9563 { 10172 {
9564 m_host.AddScriptLPS(1); 10173 m_host.AddScriptLPS(1);
9565 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 10174 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0);
9566 if (detectedParams == null) return; // only works on the first detected avatar 10175 if (detectedParams == null)
9567 10176 {
10177 if (m_host.ParentGroup.IsAttachment == true)
10178 {
10179 detectedParams = new DetectParams();
10180 detectedParams.Key = m_host.OwnerID;
10181 }
10182 else
10183 {
10184 return;
10185 }
10186 }
10187
9568 ScenePresence avatar = World.GetScenePresence(detectedParams.Key); 10188 ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
9569 if (avatar != null) 10189 if (avatar != null)
9570 { 10190 {
@@ -9572,6 +10192,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9572 new Vector3((float)pos.x, (float)pos.y, (float)pos.z), 10192 new Vector3((float)pos.x, (float)pos.y, (float)pos.z),
9573 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z)); 10193 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z));
9574 } 10194 }
10195
9575 ScriptSleep(1000); 10196 ScriptSleep(1000);
9576 } 10197 }
9577 10198
@@ -9664,14 +10285,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9664 if (objectID == UUID.Zero) return; 10285 if (objectID == UUID.Zero) return;
9665 10286
9666 UUID agentID; 10287 UUID agentID;
9667 lock (m_host.TaskInventory) 10288 m_host.TaskInventory.LockItemsForRead(true);
9668 { 10289 // we need the permission first, to know which avatar we want to set the camera for
9669 // we need the permission first, to know which avatar we want to set the camera for 10290 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9670 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9671 10291
9672 if (agentID == UUID.Zero) return; 10292 if (agentID == UUID.Zero)
9673 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 10293 {
10294 m_host.TaskInventory.LockItemsForRead(false);
10295 return;
9674 } 10296 }
10297 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
10298 {
10299 m_host.TaskInventory.LockItemsForRead(false);
10300 return;
10301 }
10302 m_host.TaskInventory.LockItemsForRead(false);
9675 10303
9676 ScenePresence presence = World.GetScenePresence(agentID); 10304 ScenePresence presence = World.GetScenePresence(agentID);
9677 10305
@@ -9680,12 +10308,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9680 10308
9681 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>(); 10309 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
9682 object[] data = rules.Data; 10310 object[] data = rules.Data;
9683 for (int i = 0; i < data.Length; ++i) { 10311 for (int i = 0; i < data.Length; ++i)
10312 {
9684 int type = Convert.ToInt32(data[i++].ToString()); 10313 int type = Convert.ToInt32(data[i++].ToString());
9685 if (i >= data.Length) break; // odd number of entries => ignore the last 10314 if (i >= data.Length) break; // odd number of entries => ignore the last
9686 10315
9687 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3) 10316 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
9688 switch (type) { 10317 switch (type)
10318 {
9689 case ScriptBaseClass.CAMERA_FOCUS: 10319 case ScriptBaseClass.CAMERA_FOCUS:
9690 case ScriptBaseClass.CAMERA_FOCUS_OFFSET: 10320 case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
9691 case ScriptBaseClass.CAMERA_POSITION: 10321 case ScriptBaseClass.CAMERA_POSITION:
@@ -9721,12 +10351,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9721 10351
9722 // we need the permission first, to know which avatar we want to clear the camera for 10352 // we need the permission first, to know which avatar we want to clear the camera for
9723 UUID agentID; 10353 UUID agentID;
9724 lock (m_host.TaskInventory) 10354 m_host.TaskInventory.LockItemsForRead(true);
10355 agentID = m_host.TaskInventory[invItemID].PermsGranter;
10356 if (agentID == UUID.Zero)
9725 { 10357 {
9726 agentID = m_host.TaskInventory[invItemID].PermsGranter; 10358 m_host.TaskInventory.LockItemsForRead(false);
9727 if (agentID == UUID.Zero) return; 10359 return;
9728 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 10360 }
10361 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
10362 {
10363 m_host.TaskInventory.LockItemsForRead(false);
10364 return;
9729 } 10365 }
10366 m_host.TaskInventory.LockItemsForRead(false);
9730 10367
9731 ScenePresence presence = World.GetScenePresence(agentID); 10368 ScenePresence presence = World.GetScenePresence(agentID);
9732 10369
@@ -9793,19 +10430,65 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9793 public LSL_String llXorBase64StringsCorrect(string str1, string str2) 10430 public LSL_String llXorBase64StringsCorrect(string str1, string str2)
9794 { 10431 {
9795 m_host.AddScriptLPS(1); 10432 m_host.AddScriptLPS(1);
9796 string ret = String.Empty; 10433
9797 string src1 = llBase64ToString(str1); 10434 if (str1 == String.Empty)
9798 string src2 = llBase64ToString(str2); 10435 return String.Empty;
9799 int c = 0; 10436 if (str2 == String.Empty)
9800 for (int i = 0; i < src1.Length; i++) 10437 return str1;
10438
10439 int len = str2.Length;
10440 if ((len % 4) != 0) // LL is EVIL!!!!
10441 {
10442 while (str2.EndsWith("="))
10443 str2 = str2.Substring(0, str2.Length - 1);
10444
10445 len = str2.Length;
10446 int mod = len % 4;
10447
10448 if (mod == 1)
10449 str2 = str2.Substring(0, str2.Length - 1);
10450 else if (mod == 2)
10451 str2 += "==";
10452 else if (mod == 3)
10453 str2 += "=";
10454 }
10455
10456 byte[] data1;
10457 byte[] data2;
10458 try
10459 {
10460 data1 = Convert.FromBase64String(str1);
10461 data2 = Convert.FromBase64String(str2);
10462 }
10463 catch (Exception)
10464 {
10465 return new LSL_String(String.Empty);
10466 }
10467
10468 byte[] d2 = new Byte[data1.Length];
10469 int pos = 0;
10470
10471 if (data1.Length <= data2.Length)
9801 { 10472 {
9802 ret += (char) (src1[i] ^ src2[c]); 10473 Array.Copy(data2, 0, d2, 0, data1.Length);
10474 }
10475 else
10476 {
10477 while (pos < data1.Length)
10478 {
10479 len = data1.Length - pos;
10480 if (len > data2.Length)
10481 len = data2.Length;
9803 10482
9804 c++; 10483 Array.Copy(data2, 0, d2, pos, len);
9805 if (c >= src2.Length) 10484 pos += len;
9806 c = 0; 10485 }
9807 } 10486 }
9808 return llStringToBase64(ret); 10487
10488 for (pos = 0 ; pos < data1.Length ; pos++ )
10489 data1[pos] ^= d2[pos];
10490
10491 return Convert.ToBase64String(data1);
9809 } 10492 }
9810 10493
9811 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body) 10494 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
@@ -9862,12 +10545,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9862 Regex r = new Regex(authregex); 10545 Regex r = new Regex(authregex);
9863 int[] gnums = r.GetGroupNumbers(); 10546 int[] gnums = r.GetGroupNumbers();
9864 Match m = r.Match(url); 10547 Match m = r.Match(url);
9865 if (m.Success) { 10548 if (m.Success)
9866 for (int i = 1; i < gnums.Length; i++) { 10549 {
10550 for (int i = 1; i < gnums.Length; i++)
10551 {
9867 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]]; 10552 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
9868 //CaptureCollection cc = g.Captures; 10553 //CaptureCollection cc = g.Captures;
9869 } 10554 }
9870 if (m.Groups.Count == 5) { 10555 if (m.Groups.Count == 5)
10556 {
9871 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString()))); 10557 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
9872 url = m.Groups[1].ToString() + m.Groups[4].ToString(); 10558 url = m.Groups[1].ToString() + m.Groups[4].ToString();
9873 } 10559 }
@@ -10153,15 +10839,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10153 10839
10154 internal UUID ScriptByName(string name) 10840 internal UUID ScriptByName(string name)
10155 { 10841 {
10156 lock (m_host.TaskInventory) 10842 m_host.TaskInventory.LockItemsForRead(true);
10843
10844 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
10157 { 10845 {
10158 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 10846 if (item.Type == 10 && item.Name == name)
10159 { 10847 {
10160 if (item.Type == 10 && item.Name == name) 10848 m_host.TaskInventory.LockItemsForRead(false);
10161 return item.ItemID; 10849 return item.ItemID;
10162 } 10850 }
10163 } 10851 }
10164 10852
10853 m_host.TaskInventory.LockItemsForRead(false);
10854
10165 return UUID.Zero; 10855 return UUID.Zero;
10166 } 10856 }
10167 10857
@@ -10202,6 +10892,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10202 { 10892 {
10203 m_host.AddScriptLPS(1); 10893 m_host.AddScriptLPS(1);
10204 10894
10895 //Clone is thread safe
10205 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 10896 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10206 10897
10207 UUID assetID = UUID.Zero; 10898 UUID assetID = UUID.Zero;
@@ -10264,6 +10955,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10264 { 10955 {
10265 m_host.AddScriptLPS(1); 10956 m_host.AddScriptLPS(1);
10266 10957
10958 //Clone is thread safe
10267 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 10959 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10268 10960
10269 UUID assetID = UUID.Zero; 10961 UUID assetID = UUID.Zero;
@@ -10344,15 +11036,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10344 return GetLinkPrimitiveParams(obj, rules); 11036 return GetLinkPrimitiveParams(obj, rules);
10345 } 11037 }
10346 11038
10347 public void print(string str) 11039 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
10348 { 11040 {
10349 // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print 11041 List<SceneObjectPart> parts = GetLinkParts(link);
10350 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL"); 11042 if (parts.Count < 1)
10351 if (ossl != null) 11043 return 0;
10352 { 11044
10353 ossl.CheckThreatLevel(ThreatLevel.High, "print"); 11045 return GetNumberOfSides(parts[0]);
10354 m_log.Info("LSL print():" + str);
10355 }
10356 } 11046 }
10357 11047
10358 private string Name2Username(string name) 11048 private string Name2Username(string name)
@@ -10398,6 +11088,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10398 return rq.ToString(); 11088 return rq.ToString();
10399 } 11089 }
10400 11090
11091 private void SayShoutTimerElapsed(Object sender, ElapsedEventArgs args)
11092 {
11093 m_SayShoutCount = 0;
11094 }
10401 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options) 11095 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
10402 { 11096 {
10403 m_host.AddScriptLPS(1); 11097 m_host.AddScriptLPS(1);
@@ -10567,22 +11261,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10567 NotImplemented("llGetSPMaxMemory"); 11261 NotImplemented("llGetSPMaxMemory");
10568 } 11262 }
10569 11263
10570 public void llGetUsedMemory() 11264 public virtual LSL_Integer llGetUsedMemory()
10571 { 11265 {
10572 m_host.AddScriptLPS(1); 11266 m_host.AddScriptLPS(1);
10573 NotImplemented("llGetUsedMemory"); 11267 NotImplemented("llGetUsedMemory");
11268 return 0;
10574 } 11269 }
10575 11270
10576 public void llScriptProfiler(LSL_Integer flags) 11271 public void llScriptProfiler(LSL_Integer flags)
10577 { 11272 {
10578 m_host.AddScriptLPS(1); 11273 m_host.AddScriptLPS(1);
10579 NotImplemented("llScriptProfiler"); 11274 //NotImplemented("llScriptProfiler");
10580 } 11275 }
10581 11276
10582 public void llSetSoundQueueing(int queue) 11277 public void llSetSoundQueueing(int queue)
10583 { 11278 {
10584 m_host.AddScriptLPS(1); 11279 m_host.AddScriptLPS(1);
10585 NotImplemented("llSetSoundQueueing");
10586 } 11280 }
10587 11281
10588 public void llCollisionSprite(string impact_sprite) 11282 public void llCollisionSprite(string impact_sprite)
@@ -10594,7 +11288,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10594 public void llGodLikeRezObject(string inventory, LSL_Vector pos) 11288 public void llGodLikeRezObject(string inventory, LSL_Vector pos)
10595 { 11289 {
10596 m_host.AddScriptLPS(1); 11290 m_host.AddScriptLPS(1);
10597 NotImplemented("llGodLikeRezObject"); 11291
11292 if (!World.Permissions.IsGod(m_host.OwnerID))
11293 NotImplemented("llGodLikeRezObject");
11294
11295 AssetBase rezAsset = World.AssetService.Get(inventory);
11296 if (rezAsset == null)
11297 {
11298 llSay(0, "Asset not found");
11299 return;
11300 }
11301
11302 SceneObjectGroup group = null;
11303
11304 try
11305 {
11306 string xmlData = Utils.BytesToString(rezAsset.Data);
11307 group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
11308 }
11309 catch
11310 {
11311 llSay(0, "Asset not found");
11312 return;
11313 }
11314
11315 if (group == null)
11316 {
11317 llSay(0, "Asset not found");
11318 return;
11319 }
11320
11321 group.RootPart.AttachPoint = group.RootPart.Shape.State;
11322 group.RootPart.AttachOffset = group.AbsolutePosition;
11323
11324 group.ResetIDs();
11325
11326 Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
11327 World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero);
11328 group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3);
11329 group.ScheduleGroupForFullUpdate();
11330
11331 // objects rezzed with this method are die_at_edge by default.
11332 group.RootPart.SetDieAtEdge(true);
11333
11334 group.ResumeScripts();
11335
11336 m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
11337 "object_rez", new Object[] {
11338 new LSL_String(
11339 group.RootPart.UUID.ToString()) },
11340 new DetectParams[0]));
10598 } 11341 }
10599 11342
10600 #endregion 11343 #endregion
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 268a599..b19f8cf 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -135,6 +135,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
135 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; 135 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
136 internal float m_ScriptDelayFactor = 1.0f; 136 internal float m_ScriptDelayFactor = 1.0f;
137 internal float m_ScriptDistanceFactor = 1.0f; 137 internal float m_ScriptDistanceFactor = 1.0f;
138 internal bool m_debuggerSafe = false;
138 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); 139 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
139 140
140 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 141 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
@@ -143,6 +144,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
143 m_host = host; 144 m_host = host;
144 m_localID = localID; 145 m_localID = localID;
145 m_itemID = itemID; 146 m_itemID = itemID;
147 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
146 148
147 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) 149 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
148 m_OSFunctionsEnabled = true; 150 m_OSFunctionsEnabled = true;
@@ -201,7 +203,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
201 203
202 internal void OSSLError(string msg) 204 internal void OSSLError(string msg)
203 { 205 {
204 throw new Exception("OSSL Runtime Error: " + msg); 206 if (m_debuggerSafe)
207 {
208 OSSLShoutError(msg);
209 }
210 else
211 {
212 throw new Exception("OSSL Runtime Error: " + msg);
213 }
205 } 214 }
206 215
207 private void InitLSL() 216 private void InitLSL()
@@ -840,18 +849,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
840 if (target != null) 849 if (target != null)
841 { 850 {
842 UUID animID=UUID.Zero; 851 UUID animID=UUID.Zero;
843 lock (m_host.TaskInventory) 852 m_host.TaskInventory.LockItemsForRead(true);
853 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
844 { 854 {
845 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 855 if (inv.Value.Name == animation)
846 { 856 {
847 if (inv.Value.Name == animation) 857 if (inv.Value.Type == (int)AssetType.Animation)
848 { 858 animID = inv.Value.AssetID;
849 if (inv.Value.Type == (int)AssetType.Animation) 859 continue;
850 animID = inv.Value.AssetID;
851 continue;
852 }
853 } 860 }
854 } 861 }
862 m_host.TaskInventory.LockItemsForRead(false);
855 if (animID == UUID.Zero) 863 if (animID == UUID.Zero)
856 target.Animator.AddAnimation(animation, m_host.UUID); 864 target.Animator.AddAnimation(animation, m_host.UUID);
857 else 865 else
@@ -873,18 +881,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
873 if (target != null) 881 if (target != null)
874 { 882 {
875 UUID animID = UUID.Zero; 883 UUID animID = UUID.Zero;
876 lock (m_host.TaskInventory) 884 m_host.TaskInventory.LockItemsForRead(true);
885 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
877 { 886 {
878 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 887 if (inv.Value.Name == animation)
879 { 888 {
880 if (inv.Value.Name == animation) 889 if (inv.Value.Type == (int)AssetType.Animation)
881 { 890 animID = inv.Value.AssetID;
882 if (inv.Value.Type == (int)AssetType.Animation) 891 continue;
883 animID = inv.Value.AssetID;
884 continue;
885 }
886 } 892 }
887 } 893 }
894 m_host.TaskInventory.LockItemsForRead(false);
888 895
889 if (animID == UUID.Zero) 896 if (animID == UUID.Zero)
890 target.Animator.RemoveAnimation(animation); 897 target.Animator.RemoveAnimation(animation);
@@ -1841,6 +1848,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1841 1848
1842 if (!UUID.TryParse(notecardNameOrUuid, out assetID)) 1849 if (!UUID.TryParse(notecardNameOrUuid, out assetID))
1843 { 1850 {
1851 m_host.TaskInventory.LockItemsForRead(true);
1844 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1852 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1845 { 1853 {
1846 if (item.Type == 7 && item.Name == notecardNameOrUuid) 1854 if (item.Type == 7 && item.Name == notecardNameOrUuid)
@@ -1848,6 +1856,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1848 assetID = item.AssetID; 1856 assetID = item.AssetID;
1849 } 1857 }
1850 } 1858 }
1859 m_host.TaskInventory.LockItemsForRead(false);
1851 } 1860 }
1852 1861
1853 if (assetID == UUID.Zero) 1862 if (assetID == UUID.Zero)
@@ -2171,8 +2180,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2171 UUID x = module.CreateNPC(firstname, 2180 UUID x = module.CreateNPC(firstname,
2172 lastname, 2181 lastname,
2173 new Vector3((float) position.x, (float) position.y, (float) position.z), 2182 new Vector3((float) position.x, (float) position.y, (float) position.z),
2174 World, 2183 World,appearance);
2175 appearance);
2176 2184
2177 return new LSL_Key(x.ToString()); 2185 return new LSL_Key(x.ToString());
2178 } 2186 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index 4ac7f8b..6de0773 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -205,7 +205,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
205 // Is the sensor type is AGENT and not SCRIPTED then include agents 205 // Is the sensor type is AGENT and not SCRIPTED then include agents
206 if ((ts.type & (AGENT | AGENT_BY_USERNAME)) != 0 && (ts.type & SCRIPTED) == 0) 206 if ((ts.type & (AGENT | AGENT_BY_USERNAME)) != 0 && (ts.type & SCRIPTED) == 0)
207 { 207 {
208 sensedEntities.AddRange(doAgentSensor(ts)); 208 sensedEntities.AddRange(doAgentSensor(ts));
209 } 209 }
210 210
211 // If SCRIPTED or PASSIVE or ACTIVE check objects 211 // If SCRIPTED or PASSIVE or ACTIVE check objects
@@ -302,13 +302,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
302 float dy; 302 float dy;
303 float dz; 303 float dz;
304 304
305 Quaternion q = SensePoint.RotationOffset; 305// Quaternion q = SensePoint.RotationOffset;
306 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation!
306 if (SensePoint.ParentGroup.IsAttachment) 307 if (SensePoint.ParentGroup.IsAttachment)
307 { 308 {
308 // In attachments, the sensor cone always orients with the 309 // In attachments, the sensor cone always orients with the
309 // avatar rotation. This may include a nonzero elevation if 310 // avatar rotation. This may include a nonzero elevation if
310 // in mouselook. 311 // in mouselook.
311 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 312 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.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);
@@ -429,6 +431,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
429 // avatar rotation. This may include a nonzero elevation if 431 // avatar rotation. This may include a nonzero elevation if
430 // in mouselook. 432 // in mouselook.
431 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 433 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
434 fromRegionPos = avatar.AbsolutePosition;
432 q = avatar.Rotation; 435 q = avatar.Rotation;
433 } 436 }
434 437
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 62e2854..4ad4123 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
@@ -123,6 +123,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
123 LSL_Float llGetEnergy(); 123 LSL_Float llGetEnergy();
124 LSL_Vector llGetForce(); 124 LSL_Vector llGetForce();
125 LSL_Integer llGetFreeMemory(); 125 LSL_Integer llGetFreeMemory();
126 LSL_Integer llGetUsedMemory();
126 LSL_Integer llGetFreeURLs(); 127 LSL_Integer llGetFreeURLs();
127 LSL_Vector llGetGeometricCenter(); 128 LSL_Vector llGetGeometricCenter();
128 LSL_Float llGetGMTclock(); 129 LSL_Float llGetGMTclock();
@@ -405,7 +406,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
405 LSL_Vector llWind(LSL_Vector offset); 406 LSL_Vector llWind(LSL_Vector offset);
406 LSL_String llXorBase64Strings(string str1, string str2); 407 LSL_String llXorBase64Strings(string str1, string str2);
407 LSL_String llXorBase64StringsCorrect(string str1, string str2); 408 LSL_String llXorBase64StringsCorrect(string str1, string str2);
408 void print(string str); 409 LSL_Integer llGetLinkNumberOfSides(LSL_Integer link);
409 410
410 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 411 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
411 LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 412 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 87cfe1a..5ddba60 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 36c5f90..864d59c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -281,6 +281,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
281 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART 281 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART
282 public const int CHANGED_MEDIA = 2048; 282 public const int CHANGED_MEDIA = 2048;
283 public const int CHANGED_ANIMATION = 16384; 283 public const int CHANGED_ANIMATION = 16384;
284 public const int CHANGED_POSITION = 32768;
284 public const int TYPE_INVALID = 0; 285 public const int TYPE_INVALID = 0;
285 public const int TYPE_INTEGER = 1; 286 public const int TYPE_INTEGER = 1;
286 public const int TYPE_FLOAT = 2; 287 public const int TYPE_FLOAT = 2;
@@ -374,6 +375,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
374 public const int PRIM_SCULPT_TYPE_TORUS = 2; 375 public const int PRIM_SCULPT_TYPE_TORUS = 2;
375 public const int PRIM_SCULPT_TYPE_PLANE = 3; 376 public const int PRIM_SCULPT_TYPE_PLANE = 3;
376 public const int PRIM_SCULPT_TYPE_CYLINDER = 4; 377 public const int PRIM_SCULPT_TYPE_CYLINDER = 4;
378 public const int PRIM_SCULPT_FLAG_INVERT = 64;
379 public const int PRIM_SCULPT_FLAG_MIRROR = 128;
377 380
378 public const int MASK_BASE = 0; 381 public const int MASK_BASE = 0;
379 public const int MASK_OWNER = 1; 382 public const int MASK_OWNER = 1;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 508f33b..a88a1f4 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;
@@ -314,6 +315,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
314 m_LSL_Functions.llDialog(avatar, message, buttons, chat_channel); 315 m_LSL_Functions.llDialog(avatar, message, buttons, chat_channel);
315 } 316 }
316 317
318 [DebuggerNonUserCode]
317 public void llDie() 319 public void llDie()
318 { 320 {
319 m_LSL_Functions.llDie(); 321 m_LSL_Functions.llDie();
@@ -464,6 +466,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
464 return m_LSL_Functions.llGetFreeMemory(); 466 return m_LSL_Functions.llGetFreeMemory();
465 } 467 }
466 468
469 public LSL_Integer llGetUsedMemory()
470 {
471 return m_LSL_Functions.llGetUsedMemory();
472 }
473
467 public LSL_Integer llGetFreeURLs() 474 public LSL_Integer llGetFreeURLs()
468 { 475 {
469 return m_LSL_Functions.llGetFreeURLs(); 476 return m_LSL_Functions.llGetFreeURLs();
@@ -1878,9 +1885,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1878 return m_LSL_Functions.llClearPrimMedia(face); 1885 return m_LSL_Functions.llClearPrimMedia(face);
1879 } 1886 }
1880 1887
1881 public void print(string str) 1888 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
1882 { 1889 {
1883 m_LSL_Functions.print(str); 1890 return m_LSL_Functions.llGetLinkNumberOfSides(link);
1884 } 1891 }
1885 } 1892 }
1886} 1893}
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 8cebb4a..7e7e278 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 3313b18..5a50714 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 d848b2a..9e6752c 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 2a0ec37..32d1fd3 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -30,6 +30,7 @@ using System.IO;
30using System.Threading; 30using System.Threading;
31using System.Collections; 31using System.Collections;
32using System.Collections.Generic; 32using System.Collections.Generic;
33using System.Diagnostics; //for [DebuggerNonUserCode]
33using System.Security; 34using System.Security;
34using System.Security.Policy; 35using System.Security.Policy;
35using System.Reflection; 36using System.Reflection;
@@ -102,6 +103,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
102 private Dictionary<UUID, IScriptInstance> m_Scripts = 103 private Dictionary<UUID, IScriptInstance> m_Scripts =
103 new Dictionary<UUID, IScriptInstance>(); 104 new Dictionary<UUID, IScriptInstance>();
104 105
106 private OpenMetaverse.ReaderWriterLockSlim m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
107
105 // Maps the asset ID to the assembly 108 // Maps the asset ID to the assembly
106 109
107 private Dictionary<UUID, string> m_Assemblies = 110 private Dictionary<UUID, string> m_Assemblies =
@@ -124,6 +127,71 @@ namespace OpenSim.Region.ScriptEngine.XEngine
124 IWorkItemResult m_CurrentCompile = null; 127 IWorkItemResult m_CurrentCompile = null;
125 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>(); 128 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>();
126 129
130 private void lockScriptsForRead(bool locked)
131 {
132 if (locked)
133 {
134 if (m_scriptsLock.RecursiveReadCount > 0)
135 {
136 m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
137 m_scriptsLock.ExitReadLock();
138 }
139 if (m_scriptsLock.RecursiveWriteCount > 0)
140 {
141 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
142 m_scriptsLock.ExitWriteLock();
143 }
144
145 while (!m_scriptsLock.TryEnterReadLock(60000))
146 {
147 m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire READ lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
148 if (m_scriptsLock.IsWriteLockHeld)
149 {
150 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
151 }
152 }
153 }
154 else
155 {
156 if (m_scriptsLock.RecursiveReadCount > 0)
157 {
158 m_scriptsLock.ExitReadLock();
159 }
160 }
161 }
162 private void lockScriptsForWrite(bool locked)
163 {
164 if (locked)
165 {
166 if (m_scriptsLock.RecursiveReadCount > 0)
167 {
168 m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
169 m_scriptsLock.ExitReadLock();
170 }
171 if (m_scriptsLock.RecursiveWriteCount > 0)
172 {
173 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
174 m_scriptsLock.ExitWriteLock();
175 }
176
177 while (!m_scriptsLock.TryEnterWriteLock(60000))
178 {
179 m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire WRITE lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
180 if (m_scriptsLock.IsWriteLockHeld)
181 {
182 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
183 }
184 }
185 }
186 else
187 {
188 if (m_scriptsLock.RecursiveWriteCount > 0)
189 {
190 m_scriptsLock.ExitWriteLock();
191 }
192 }
193 }
194
127 public string ScriptEngineName 195 public string ScriptEngineName
128 { 196 {
129 get { return "XEngine"; } 197 get { return "XEngine"; }
@@ -271,47 +339,45 @@ namespace OpenSim.Region.ScriptEngine.XEngine
271 { 339 {
272 if (!m_Enabled) 340 if (!m_Enabled)
273 return; 341 return;
274 342 lockScriptsForRead(true);
275 lock (m_Scripts) 343 foreach (IScriptInstance instance in m_Scripts.Values)
276 { 344 {
277 m_log.InfoFormat( 345 // Force a final state save
278 "[XEngine]: Shutting down {0} scripts in {1}", m_Scripts.Count, m_Scene.RegionInfo.RegionName); 346 //
279 347 if (m_Assemblies.ContainsKey(instance.AssetID))
280 foreach (IScriptInstance instance in m_Scripts.Values)
281 { 348 {
282 // Force a final state save 349 string assembly = m_Assemblies[instance.AssetID];
283 // 350 instance.SaveState(assembly);
284 if (m_Assemblies.ContainsKey(instance.AssetID)) 351 }
285 {
286 string assembly = m_Assemblies[instance.AssetID];
287 instance.SaveState(assembly);
288 }
289 352
290 // Clear the event queue and abort the instance thread 353 // Clear the event queue and abort the instance thread
291 // 354 //
292 instance.ClearQueue(); 355 instance.ClearQueue();
293 instance.Stop(0); 356 instance.Stop(0);
294 357
295 // Release events, timer, etc 358 // Release events, timer, etc
296 // 359 //
297 instance.DestroyScriptInstance(); 360 instance.DestroyScriptInstance();
298 361
299 // Unload scripts and app domains 362 // Unload scripts and app domains
300 // Must be done explicitly because they have infinite 363 // Must be done explicitly because they have infinite
301 // lifetime 364 // lifetime
302 // 365 //
303 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 366 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
304 if (m_DomainScripts[instance.AppDomain].Count == 0) 367 if (m_DomainScripts[instance.AppDomain].Count == 0)
305 { 368 {
306 m_DomainScripts.Remove(instance.AppDomain); 369 m_DomainScripts.Remove(instance.AppDomain);
307 UnloadAppDomain(instance.AppDomain); 370 UnloadAppDomain(instance.AppDomain);
308 }
309 } 371 }
310 m_Scripts.Clear();
311 m_PrimObjects.Clear();
312 m_Assemblies.Clear();
313 m_DomainScripts.Clear();
314 } 372 }
373 lockScriptsForRead(false);
374 lockScriptsForWrite(true);
375 m_Scripts.Clear();
376 lockScriptsForWrite(false);
377 m_PrimObjects.Clear();
378 m_Assemblies.Clear();
379 m_DomainScripts.Clear();
380
315 lock (m_ScriptEngines) 381 lock (m_ScriptEngines)
316 { 382 {
317 m_ScriptEngines.Remove(this); 383 m_ScriptEngines.Remove(this);
@@ -376,22 +442,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine
376 442
377 List<IScriptInstance> instances = new List<IScriptInstance>(); 443 List<IScriptInstance> instances = new List<IScriptInstance>();
378 444
379 lock (m_Scripts) 445 lockScriptsForRead(true);
380 { 446 foreach (IScriptInstance instance in m_Scripts.Values)
381 foreach (IScriptInstance instance in m_Scripts.Values)
382 instances.Add(instance); 447 instances.Add(instance);
383 } 448 lockScriptsForRead(false);
384 449
385 foreach (IScriptInstance i in instances) 450 foreach (IScriptInstance i in instances)
386 { 451 {
387 string assembly = String.Empty; 452 string assembly = String.Empty;
388 453
389 lock (m_Scripts) 454
390 {
391 if (!m_Assemblies.ContainsKey(i.AssetID)) 455 if (!m_Assemblies.ContainsKey(i.AssetID))
392 continue; 456 continue;
393 assembly = m_Assemblies[i.AssetID]; 457 assembly = m_Assemblies[i.AssetID];
394 } 458
395 459
396 i.SaveState(assembly); 460 i.SaveState(assembly);
397 } 461 }
@@ -725,92 +789,95 @@ namespace OpenSim.Region.ScriptEngine.XEngine
725 } 789 }
726 790
727 ScriptInstance instance = null; 791 ScriptInstance instance = null;
728 lock (m_Scripts) 792 // Create the object record
793 lockScriptsForRead(true);
794 if ((!m_Scripts.ContainsKey(itemID)) ||
795 (m_Scripts[itemID].AssetID != assetID))
729 { 796 {
730 // Create the object record 797 lockScriptsForRead(false);
731 798
732 if ((!m_Scripts.ContainsKey(itemID)) || 799 UUID appDomain = assetID;
733 (m_Scripts[itemID].AssetID != assetID))
734 {
735 UUID appDomain = assetID;
736 800
737 if (part.ParentGroup.IsAttachment) 801 if (part.ParentGroup.IsAttachment)
738 appDomain = part.ParentGroup.RootPart.UUID; 802 appDomain = part.ParentGroup.RootPart.UUID;
739 803
740 if (!m_AppDomains.ContainsKey(appDomain)) 804 if (!m_AppDomains.ContainsKey(appDomain))
805 {
806 try
741 { 807 {
742 try 808 AppDomainSetup appSetup = new AppDomainSetup();
743 { 809 appSetup.PrivateBinPath = Path.Combine(
744 AppDomainSetup appSetup = new AppDomainSetup(); 810 m_ScriptEnginesPath,
745 appSetup.PrivateBinPath = Path.Combine( 811 m_Scene.RegionInfo.RegionID.ToString());
746 m_ScriptEnginesPath, 812
747 m_Scene.RegionInfo.RegionID.ToString()); 813 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
748 814 Evidence evidence = new Evidence(baseEvidence);
749 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; 815
750 Evidence evidence = new Evidence(baseEvidence); 816 AppDomain sandbox;
751 817 if (m_AppDomainLoading)
752 AppDomain sandbox; 818 sandbox = AppDomain.CreateDomain(
753 if (m_AppDomainLoading) 819 m_Scene.RegionInfo.RegionID.ToString(),
754 sandbox = AppDomain.CreateDomain( 820 evidence, appSetup);
755 m_Scene.RegionInfo.RegionID.ToString(), 821 else
756 evidence, appSetup); 822 sandbox = AppDomain.CurrentDomain;
757 else 823
758 sandbox = AppDomain.CurrentDomain; 824 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
759 825 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
760 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); 826 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet");
761 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); 827 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet);
762 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); 828 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement);
763 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); 829 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup;
764 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); 830 //sandbox.SetAppDomainPolicy(sandboxPolicy);
765 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup; 831
766 //sandbox.SetAppDomainPolicy(sandboxPolicy); 832 m_AppDomains[appDomain] = sandbox;
767 833
768 m_AppDomains[appDomain] = sandbox; 834 m_AppDomains[appDomain].AssemblyResolve +=
769 835 new ResolveEventHandler(
770 m_AppDomains[appDomain].AssemblyResolve += 836 AssemblyResolver.OnAssemblyResolve);
771 new ResolveEventHandler( 837 m_DomainScripts[appDomain] = new List<UUID>();
772 AssemblyResolver.OnAssemblyResolve); 838 }
773 m_DomainScripts[appDomain] = new List<UUID>(); 839 catch (Exception e)
774 } 840 {
775 catch (Exception e) 841 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
842 m_ScriptErrorMessage += "Exception creating app domain:\n";
843 m_ScriptFailCount++;
844 lock (m_AddingAssemblies)
776 { 845 {
777 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString()); 846 m_AddingAssemblies[assembly]--;
778 m_ScriptErrorMessage += "Exception creating app domain:\n";
779 m_ScriptFailCount++;
780 lock (m_AddingAssemblies)
781 {
782 m_AddingAssemblies[assembly]--;
783 }
784 return false;
785 } 847 }
848 return false;
786 } 849 }
787 m_DomainScripts[appDomain].Add(itemID); 850 }
788 851 m_DomainScripts[appDomain].Add(itemID);
789 instance = new ScriptInstance(this, part, 852
790 itemID, assetID, assembly, 853 instance = new ScriptInstance(this, part,
791 m_AppDomains[appDomain], 854 itemID, assetID, assembly,
792 part.ParentGroup.RootPart.Name, 855 m_AppDomains[appDomain],
793 item.Name, startParam, postOnRez, 856 part.ParentGroup.RootPart.Name,
794 stateSource, m_MaxScriptQueue); 857 item.Name, startParam, postOnRez,
795 858 stateSource, m_MaxScriptQueue);
796 m_log.DebugFormat( 859
860 m_log.DebugFormat(
797 "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}", 861 "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}",
798 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID, 862 part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID,
799 part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName); 863 part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName);
800 864
801 if (presence != null) 865 if (presence != null)
802 { 866 {
803 ShowScriptSaveResponse(item.OwnerID, 867 ShowScriptSaveResponse(item.OwnerID,
804 assetID, "Compile successful", true); 868 assetID, "Compile successful", true);
805 }
806
807 instance.AppDomain = appDomain;
808 instance.LineMap = linemap;
809
810 m_Scripts[itemID] = instance;
811 } 869 }
812 }
813 870
871 instance.AppDomain = appDomain;
872 instance.LineMap = linemap;
873 lockScriptsForWrite(true);
874 m_Scripts[itemID] = instance;
875 lockScriptsForWrite(false);
876 }
877 else
878 {
879 lockScriptsForRead(false);
880 }
814 lock (m_PrimObjects) 881 lock (m_PrimObjects)
815 { 882 {
816 if (!m_PrimObjects.ContainsKey(localID)) 883 if (!m_PrimObjects.ContainsKey(localID))
@@ -829,9 +896,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
829 m_AddingAssemblies[assembly]--; 896 m_AddingAssemblies[assembly]--;
830 } 897 }
831 898
832 if (instance != null) 899 if (instance!=null)
833 instance.Init(); 900 instance.Init();
834 901
835 return true; 902 return true;
836 } 903 }
837 904
@@ -844,20 +911,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine
844 m_CompileDict.Remove(itemID); 911 m_CompileDict.Remove(itemID);
845 } 912 }
846 913
847 IScriptInstance instance = null; 914 lockScriptsForRead(true);
848 915 // Do we even have it?
849 lock (m_Scripts) 916 if (!m_Scripts.ContainsKey(itemID))
850 { 917 {
851 // Do we even have it? 918 lockScriptsForRead(false);
852 if (!m_Scripts.ContainsKey(itemID)) 919 return;
853 return;
854
855 instance=m_Scripts[itemID];
856 m_Scripts.Remove(itemID);
857 } 920 }
921
858 922
923 IScriptInstance instance=m_Scripts[itemID];
924 lockScriptsForRead(false);
925 lockScriptsForWrite(true);
926 m_Scripts.Remove(itemID);
927 lockScriptsForWrite(false);
859 instance.ClearQueue(); 928 instance.ClearQueue();
860 instance.Stop(0); 929 instance.Stop(0);
930
861// bool objectRemoved = false; 931// bool objectRemoved = false;
862 932
863 lock (m_PrimObjects) 933 lock (m_PrimObjects)
@@ -893,11 +963,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
893 ObjectRemoved handlerObjectRemoved = OnObjectRemoved; 963 ObjectRemoved handlerObjectRemoved = OnObjectRemoved;
894 if (handlerObjectRemoved != null) 964 if (handlerObjectRemoved != null)
895 { 965 {
896 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID); 966 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID);
897 handlerObjectRemoved(part.UUID); 967 handlerObjectRemoved(part.UUID);
898 } 968 }
899 969
900 970 CleanAssemblies();
971
901 ScriptRemoved handlerScriptRemoved = OnScriptRemoved; 972 ScriptRemoved handlerScriptRemoved = OnScriptRemoved;
902 if (handlerScriptRemoved != null) 973 if (handlerScriptRemoved != null)
903 handlerScriptRemoved(itemID); 974 handlerScriptRemoved(itemID);
@@ -1039,7 +1110,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1039 return false; 1110 return false;
1040 1111
1041 uuids = m_PrimObjects[localID]; 1112 uuids = m_PrimObjects[localID];
1042 } 1113
1043 1114
1044 foreach (UUID itemID in uuids) 1115 foreach (UUID itemID in uuids)
1045 { 1116 {
@@ -1057,6 +1128,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1057 result = true; 1128 result = true;
1058 } 1129 }
1059 } 1130 }
1131 }
1060 1132
1061 return result; 1133 return result;
1062 } 1134 }
@@ -1156,12 +1228,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1156 private IScriptInstance GetInstance(UUID itemID) 1228 private IScriptInstance GetInstance(UUID itemID)
1157 { 1229 {
1158 IScriptInstance instance; 1230 IScriptInstance instance;
1159 lock (m_Scripts) 1231 lockScriptsForRead(true);
1232 if (!m_Scripts.ContainsKey(itemID))
1160 { 1233 {
1161 if (!m_Scripts.ContainsKey(itemID)) 1234 lockScriptsForRead(false);
1162 return null; 1235 return null;
1163 instance = m_Scripts[itemID];
1164 } 1236 }
1237 instance = m_Scripts[itemID];
1238 lockScriptsForRead(false);
1165 return instance; 1239 return instance;
1166 } 1240 }
1167 1241
@@ -1185,6 +1259,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1185 return false; 1259 return false;
1186 } 1260 }
1187 1261
1262 [DebuggerNonUserCode]
1188 public void ApiResetScript(UUID itemID) 1263 public void ApiResetScript(UUID itemID)
1189 { 1264 {
1190 IScriptInstance instance = GetInstance(itemID); 1265 IScriptInstance instance = GetInstance(itemID);
@@ -1236,6 +1311,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1236 return UUID.Zero; 1311 return UUID.Zero;
1237 } 1312 }
1238 1313
1314 [DebuggerNonUserCode]
1239 public void SetState(UUID itemID, string newState) 1315 public void SetState(UUID itemID, string newState)
1240 { 1316 {
1241 IScriptInstance instance = GetInstance(itemID); 1317 IScriptInstance instance = GetInstance(itemID);
@@ -1256,11 +1332,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1256 { 1332 {
1257 List<IScriptInstance> instances = new List<IScriptInstance>(); 1333 List<IScriptInstance> instances = new List<IScriptInstance>();
1258 1334
1259 lock (m_Scripts) 1335 lockScriptsForRead(true);
1260 { 1336 foreach (IScriptInstance instance in m_Scripts.Values)
1261 foreach (IScriptInstance instance in m_Scripts.Values)
1262 instances.Add(instance); 1337 instances.Add(instance);
1263 } 1338 lockScriptsForRead(false);
1264 1339
1265 foreach (IScriptInstance i in instances) 1340 foreach (IScriptInstance i in instances)
1266 { 1341 {
@@ -1641,5 +1716,17 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1641 1716
1642 instance.Resume(); 1717 instance.Resume();
1643 } 1718 }
1719
1720 public bool HasScript(UUID itemID, out bool running)
1721 {
1722 running = true;
1723
1724 IScriptInstance instance = GetInstance(itemID);
1725 if (instance == null)
1726 return false;
1727
1728 running = instance.Running;
1729 return true;
1730 }
1644 } 1731 }
1645} 1732}