aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api')
-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.cs2347
-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.cs4
-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.cs16
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs21
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs2
15 files changed, 1927 insertions, 810 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 6d067b0..7a56f11 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.UpdateTextureEntry(tex.GetBytes());
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.UpdateTextureEntry(tex.GetBytes());
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)
@@ -1672,7 +1855,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1672 /// <param name="falloff"></param> 1855 /// <param name="falloff"></param>
1673 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff) 1856 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
1674 { 1857 {
1675 if (part == null) 1858 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1676 return; 1859 return;
1677 1860
1678 if (light) 1861 if (light)
@@ -1749,15 +1932,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1749 m_host.AddScriptLPS(1); 1932 m_host.AddScriptLPS(1);
1750 1933
1751 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1934 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1752 1935 if (parts.Count > 0)
1753 foreach (SceneObjectPart part in parts) 1936 {
1754 SetTexture(part, texture, face); 1937 try
1755 1938 {
1939 parts[0].ParentGroup.areUpdatesSuspended = true;
1940 foreach (SceneObjectPart part in parts)
1941 SetTexture(part, texture, face);
1942 }
1943 finally
1944 {
1945 parts[0].ParentGroup.areUpdatesSuspended = false;
1946 }
1947 }
1756 ScriptSleep(200); 1948 ScriptSleep(200);
1757 } 1949 }
1758 1950
1759 protected void SetTexture(SceneObjectPart part, string texture, int face) 1951 protected void SetTexture(SceneObjectPart part, string texture, int face)
1760 { 1952 {
1953 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1954 return;
1955
1761 UUID textureID = new UUID(); 1956 UUID textureID = new UUID();
1762 1957
1763 textureID = InventoryKey(texture, (int)AssetType.Texture); 1958 textureID = InventoryKey(texture, (int)AssetType.Texture);
@@ -1802,6 +1997,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1802 1997
1803 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) 1998 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
1804 { 1999 {
2000 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2001 return;
2002
1805 Primitive.TextureEntry tex = part.Shape.Textures; 2003 Primitive.TextureEntry tex = part.Shape.Textures;
1806 if (face >= 0 && face < GetNumberOfSides(part)) 2004 if (face >= 0 && face < GetNumberOfSides(part))
1807 { 2005 {
@@ -1838,6 +2036,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1838 2036
1839 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) 2037 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
1840 { 2038 {
2039 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2040 return;
2041
1841 Primitive.TextureEntry tex = part.Shape.Textures; 2042 Primitive.TextureEntry tex = part.Shape.Textures;
1842 if (face >= 0 && face < GetNumberOfSides(part)) 2043 if (face >= 0 && face < GetNumberOfSides(part))
1843 { 2044 {
@@ -1874,6 +2075,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1874 2075
1875 protected void RotateTexture(SceneObjectPart part, double rotation, int face) 2076 protected void RotateTexture(SceneObjectPart part, double rotation, int face)
1876 { 2077 {
2078 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2079 return;
2080
1877 Primitive.TextureEntry tex = part.Shape.Textures; 2081 Primitive.TextureEntry tex = part.Shape.Textures;
1878 if (face >= 0 && face < GetNumberOfSides(part)) 2082 if (face >= 0 && face < GetNumberOfSides(part))
1879 { 2083 {
@@ -1980,24 +2184,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1980 2184
1981 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos) 2185 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos)
1982 { 2186 {
1983 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos) 2187 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1984 LSL_Vector currentPos = GetPartLocalPos(part); 2188 return;
1985 2189
1986 float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y); 2190 LSL_Vector currentPos = GetPartLocalPos(part);
1987 bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true); 2191 LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos);
1988 2192
1989 if (part.ParentGroup.RootPart == part) 2193 if (part.ParentGroup.RootPart == part)
1990 { 2194 {
1991 if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
1992 targetPos.z = ground;
1993 SceneObjectGroup parent = part.ParentGroup; 2195 SceneObjectGroup parent = part.ParentGroup;
1994 LSL_Vector real_vec = SetPosAdjust(currentPos, targetPos); 2196 parent.UpdateGroupPosition(new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z));
1995 parent.UpdateGroupPosition(new Vector3((float)real_vec.x, (float)real_vec.y, (float)real_vec.z));
1996 } 2197 }
1997 else 2198 else
1998 { 2199 {
1999 LSL_Vector rel_vec = SetPosAdjust(currentPos, targetPos); 2200 part.OffsetPosition = new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z);
2000 part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z);
2001 SceneObjectGroup parent = part.ParentGroup; 2201 SceneObjectGroup parent = part.ParentGroup;
2002 parent.HasGroupChanged = true; 2202 parent.HasGroupChanged = true;
2003 parent.ScheduleGroupForTerseUpdate(); 2203 parent.ScheduleGroupForTerseUpdate();
@@ -2048,9 +2248,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2048 m_host.AddScriptLPS(1); 2248 m_host.AddScriptLPS(1);
2049 2249
2050 // try to let this work as in SL... 2250 // try to let this work as in SL...
2051 if (m_host.ParentID == 0) 2251 if (m_host.LinkNum < 2)
2052 { 2252 {
2053 // special case: If we are root, rotate complete SOG to new rotation 2253 // Special case: If we are root, rotate complete SOG to new
2254 // rotation.
2255 // We are root if the link number is 0 (single prim) or 1
2256 // (root prim). ParentID may be nonzero in attachments and
2257 // using it would cause attachments and HUDs to rotate
2258 // to the wrong positions.
2054 SetRot(m_host, Rot2Quaternion(rot)); 2259 SetRot(m_host, Rot2Quaternion(rot));
2055 } 2260 }
2056 else 2261 else
@@ -2075,6 +2280,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2075 2280
2076 protected void SetRot(SceneObjectPart part, Quaternion rot) 2281 protected void SetRot(SceneObjectPart part, Quaternion rot)
2077 { 2282 {
2283 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2284 return;
2285
2078 part.UpdateRotation(rot); 2286 part.UpdateRotation(rot);
2079 // Update rotation does not move the object in the physics scene if it's a linkset. 2287 // Update rotation does not move the object in the physics scene if it's a linkset.
2080 2288
@@ -2698,12 +2906,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2698 2906
2699 m_host.AddScriptLPS(1); 2907 m_host.AddScriptLPS(1);
2700 2908
2909 m_host.TaskInventory.LockItemsForRead(true);
2701 TaskInventoryItem item = m_host.TaskInventory[invItemID]; 2910 TaskInventoryItem item = m_host.TaskInventory[invItemID];
2702 2911 m_host.TaskInventory.LockItemsForRead(false);
2703 lock (m_host.TaskInventory)
2704 {
2705 item = m_host.TaskInventory[invItemID];
2706 }
2707 2912
2708 if (item.PermsGranter == UUID.Zero) 2913 if (item.PermsGranter == UUID.Zero)
2709 return 0; 2914 return 0;
@@ -2778,6 +2983,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2778 if (dist > m_ScriptDistanceFactor * 10.0f) 2983 if (dist > m_ScriptDistanceFactor * 10.0f)
2779 return; 2984 return;
2780 2985
2986 //Clone is thread-safe
2781 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 2987 TaskInventoryDictionary partInventory = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
2782 2988
2783 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory) 2989 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in partInventory)
@@ -2838,6 +3044,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2838 3044
2839 public void llLookAt(LSL_Vector target, double strength, double damping) 3045 public void llLookAt(LSL_Vector target, double strength, double damping)
2840 { 3046 {
3047 /*
2841 m_host.AddScriptLPS(1); 3048 m_host.AddScriptLPS(1);
2842 // Determine where we are looking from 3049 // Determine where we are looking from
2843 LSL_Vector from = llGetPos(); 3050 LSL_Vector from = llGetPos();
@@ -2857,10 +3064,54 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2857 // the angles of rotation in radians into rotation value 3064 // the angles of rotation in radians into rotation value
2858 3065
2859 LSL_Types.Quaternion rot = llEuler2Rot(angle); 3066 LSL_Types.Quaternion rot = llEuler2Rot(angle);
2860 Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s); 3067
2861 m_host.startLookAt(rotation, (float)damping, (float)strength); 3068 // This would only work if your physics system contains an APID controller:
3069 // Quaternion rotation = new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
3070 // m_host.startLookAt(rotation, (float)damping, (float)strength);
3071
2862 // Orient the object to the angle calculated 3072 // Orient the object to the angle calculated
2863 //llSetRot(rot); 3073 llSetRot(rot);
3074 */
3075
3076 //The above code, while nice, doesn't replicate the behaviour of SL and tends to "roll" the object.
3077 //There's probably a smarter way of doing this, my rotation math-fu is weak.
3078 // http://bugs.meta7.com/view.php?id=28
3079 // - Tom
3080
3081 /* And the following does not do the job either. It has to be performed inside the ODE glue-code. -.- .._.
3082 LSL_Rotation newrot = llGetRot() * llRotBetween(new LSL_Vector(1.0d, 0.0d, 0.0d) * llGetRot(), new LSL_Vector(0.0d, 0.0d, -1.0d));
3083 llSetRot(newrot * llRotBetween(new LSL_Vector(0.0d,0.0d,1.0d) * newrot, target - llGetPos()));
3084 */
3085 if (m_host.PhysActor != null && !m_host.PhysActor.IsPhysical)
3086 {
3087 // Part is non-phys, convert this to a llSetRot()
3088 Vector3 tgt = new Vector3((float)target.x, (float)target.y, (float)target.z);
3089 Vector3 dir = tgt - m_host.GroupPosition;
3090 dir.Normalize();
3091 float tzrot = (float)Math.Atan2(dir.Y, dir.X);
3092 float txy = (float)Math.Sqrt((dir.X * dir.X) + (dir.Y * dir.Y));
3093 float terot = (float)Math.Atan2(-dir.Z, txy);
3094 LSL_Vector az = new LSL_Vector(0.0f, 0.0f, tzrot);
3095 LSL_Vector ae = new LSL_Vector(0.0f, terot, 0.0f);
3096 LSL_Types.Quaternion spin = llEuler2Rot(az);
3097 LSL_Types.Quaternion rot = llEuler2Rot(ae) * spin;
3098 llSetRot(rot);
3099 }
3100 else
3101 {
3102 // Physical, send the target vector to RotLookAt method inside a 'rotation', the .w -99.9 value indicates it is really a LookAt.
3103 Quaternion q = new Quaternion((float)target.x, (float)target.y, (float)target.z, -99.9f);
3104 m_host.RotLookAt(q, (float)strength, (float)damping);
3105 }
3106
3107 }
3108
3109 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3110 {
3111 m_host.AddScriptLPS(1);
3112// NotImplemented("llRotLookAt");
3113 m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping);
3114
2864 } 3115 }
2865 3116
2866 public void llStopLookAt() 3117 public void llStopLookAt()
@@ -2909,13 +3160,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2909 { 3160 {
2910 TaskInventoryItem item; 3161 TaskInventoryItem item;
2911 3162
2912 lock (m_host.TaskInventory) 3163 m_host.TaskInventory.LockItemsForRead(true);
3164 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2913 { 3165 {
2914 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3166 m_host.TaskInventory.LockItemsForRead(false);
2915 return; 3167 return;
2916 else 3168 }
2917 item = m_host.TaskInventory[InventorySelf()]; 3169 else
3170 {
3171 item = m_host.TaskInventory[InventorySelf()];
2918 } 3172 }
3173 m_host.TaskInventory.LockItemsForRead(false);
2919 3174
2920 if (item.PermsGranter != UUID.Zero) 3175 if (item.PermsGranter != UUID.Zero)
2921 { 3176 {
@@ -2937,13 +3192,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2937 { 3192 {
2938 TaskInventoryItem item; 3193 TaskInventoryItem item;
2939 3194
3195 m_host.TaskInventory.LockItemsForRead(true);
2940 lock (m_host.TaskInventory) 3196 lock (m_host.TaskInventory)
2941 { 3197 {
3198
2942 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3199 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3200 {
3201 m_host.TaskInventory.LockItemsForRead(false);
2943 return; 3202 return;
3203 }
2944 else 3204 else
3205 {
2945 item = m_host.TaskInventory[InventorySelf()]; 3206 item = m_host.TaskInventory[InventorySelf()];
3207 }
2946 } 3208 }
3209 m_host.TaskInventory.LockItemsForRead(false);
2947 3210
2948 m_host.AddScriptLPS(1); 3211 m_host.AddScriptLPS(1);
2949 3212
@@ -2975,18 +3238,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2975 { 3238 {
2976 m_host.AddScriptLPS(1); 3239 m_host.AddScriptLPS(1);
2977 3240
2978// if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
2979// return;
2980
2981 TaskInventoryItem item; 3241 TaskInventoryItem item;
2982 3242
2983 lock (m_host.TaskInventory) 3243 m_host.TaskInventory.LockItemsForRead(true);
3244
3245 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
2984 { 3246 {
2985 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3247 m_host.TaskInventory.LockItemsForRead(false);
2986 return; 3248 return;
2987 else
2988 item = m_host.TaskInventory[InventorySelf()];
2989 } 3249 }
3250 else
3251 {
3252 item = m_host.TaskInventory[InventorySelf()];
3253 }
3254
3255 m_host.TaskInventory.LockItemsForRead(false);
2990 3256
2991 if (item.PermsGranter != m_host.OwnerID) 3257 if (item.PermsGranter != m_host.OwnerID)
2992 return; 3258 return;
@@ -3012,13 +3278,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3012 3278
3013 TaskInventoryItem item; 3279 TaskInventoryItem item;
3014 3280
3015 lock (m_host.TaskInventory) 3281 m_host.TaskInventory.LockItemsForRead(true);
3282
3283 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3016 { 3284 {
3017 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3285 m_host.TaskInventory.LockItemsForRead(false);
3018 return; 3286 return;
3019 else
3020 item = m_host.TaskInventory[InventorySelf()];
3021 } 3287 }
3288 else
3289 {
3290 item = m_host.TaskInventory[InventorySelf()];
3291 }
3292 m_host.TaskInventory.LockItemsForRead(false);
3293
3022 3294
3023 if (item.PermsGranter != m_host.OwnerID) 3295 if (item.PermsGranter != m_host.OwnerID)
3024 return; 3296 return;
@@ -3065,6 +3337,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3065 3337
3066 public void llInstantMessage(string user, string message) 3338 public void llInstantMessage(string user, string message)
3067 { 3339 {
3340 UUID result;
3341 if (!UUID.TryParse(user, out result))
3342 {
3343 ShoutError("An invalid key was passed to llInstantMessage");
3344 ScriptSleep(2000);
3345 return;
3346 }
3347
3348
3068 m_host.AddScriptLPS(1); 3349 m_host.AddScriptLPS(1);
3069 3350
3070 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. 3351 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
@@ -3079,14 +3360,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3079 UUID friendTransactionID = UUID.Random(); 3360 UUID friendTransactionID = UUID.Random();
3080 3361
3081 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 3362 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
3082 3363
3083 GridInstantMessage msg = new GridInstantMessage(); 3364 GridInstantMessage msg = new GridInstantMessage();
3084 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; 3365 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
3085 msg.toAgentID = new Guid(user); // toAgentID.Guid; 3366 msg.toAgentID = new Guid(user); // toAgentID.Guid;
3086 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here 3367 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
3087// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message); 3368// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
3088// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString()); 3369// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
3089 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp; 3370// DateTime dt = DateTime.UtcNow;
3371//
3372// // Ticks from UtcNow, but make it look like local. Evil, huh?
3373// dt = DateTime.SpecifyKind(dt, DateTimeKind.Local);
3374//
3375// try
3376// {
3377// // Convert that to the PST timezone
3378// TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
3379// dt = TimeZoneInfo.ConvertTime(dt, timeZoneInfo);
3380// }
3381// catch
3382// {
3383// // No logging here, as it could be VERY spammy
3384// }
3385//
3386// // And make it look local again to fool the unix time util
3387// dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
3388
3389 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
3390
3090 //if (client != null) 3391 //if (client != null)
3091 //{ 3392 //{
3092 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName; 3393 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
@@ -3100,12 +3401,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3100 msg.message = message.Substring(0, 1024); 3401 msg.message = message.Substring(0, 1024);
3101 else 3402 else
3102 msg.message = message; 3403 msg.message = message;
3103 msg.dialog = (byte)19; // messgage from script ??? // dialog; 3404 msg.dialog = (byte)19; // MessageFromObject
3104 msg.fromGroup = false;// fromGroup; 3405 msg.fromGroup = false;// fromGroup;
3105 msg.offline = (byte)0; //offline; 3406 msg.offline = (byte)0; //offline;
3106 msg.ParentEstateID = 0; //ParentEstateID; 3407 msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
3107 msg.Position = new Vector3(m_host.AbsolutePosition); 3408 msg.Position = new Vector3(m_host.AbsolutePosition);
3108 msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; 3409 msg.RegionID = World.RegionInfo.RegionID.Guid;
3109 msg.binaryBucket 3410 msg.binaryBucket
3110 = Util.StringToBytes256( 3411 = Util.StringToBytes256(
3111 "{0}/{1}/{2}/{3}", 3412 "{0}/{1}/{2}/{3}",
@@ -3133,7 +3434,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3133 } 3434 }
3134 3435
3135 emailModule.SendEmail(m_host.UUID, address, subject, message); 3436 emailModule.SendEmail(m_host.UUID, address, subject, message);
3136 ScriptSleep(20000); 3437 ScriptSleep(15000);
3137 } 3438 }
3138 3439
3139 public void llGetNextEmail(string address, string subject) 3440 public void llGetNextEmail(string address, string subject)
@@ -3233,13 +3534,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3233 m_host.AddScriptLPS(1); 3534 m_host.AddScriptLPS(1);
3234 } 3535 }
3235 3536
3236 public void llRotLookAt(LSL_Rotation target, double strength, double damping)
3237 {
3238 m_host.AddScriptLPS(1);
3239 Quaternion rot = new Quaternion((float)target.x, (float)target.y, (float)target.z, (float)target.s);
3240 m_host.RotLookAt(rot, (float)strength, (float)damping);
3241 }
3242
3243 public LSL_Integer llStringLength(string str) 3537 public LSL_Integer llStringLength(string str)
3244 { 3538 {
3245 m_host.AddScriptLPS(1); 3539 m_host.AddScriptLPS(1);
@@ -3263,14 +3557,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3263 3557
3264 TaskInventoryItem item; 3558 TaskInventoryItem item;
3265 3559
3266 lock (m_host.TaskInventory) 3560 m_host.TaskInventory.LockItemsForRead(true);
3561 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3267 { 3562 {
3268 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3563 m_host.TaskInventory.LockItemsForRead(false);
3269 return; 3564 return;
3270 else
3271 item = m_host.TaskInventory[InventorySelf()];
3272 } 3565 }
3273 3566 else
3567 {
3568 item = m_host.TaskInventory[InventorySelf()];
3569 }
3570 m_host.TaskInventory.LockItemsForRead(false);
3274 if (item.PermsGranter == UUID.Zero) 3571 if (item.PermsGranter == UUID.Zero)
3275 return; 3572 return;
3276 3573
@@ -3300,13 +3597,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3300 3597
3301 TaskInventoryItem item; 3598 TaskInventoryItem item;
3302 3599
3303 lock (m_host.TaskInventory) 3600 m_host.TaskInventory.LockItemsForRead(true);
3601 if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
3304 { 3602 {
3305 if (!m_host.TaskInventory.ContainsKey(InventorySelf())) 3603 m_host.TaskInventory.LockItemsForRead(false);
3306 return; 3604 return;
3307 else 3605 }
3308 item = m_host.TaskInventory[InventorySelf()]; 3606 else
3607 {
3608 item = m_host.TaskInventory[InventorySelf()];
3309 } 3609 }
3610 m_host.TaskInventory.LockItemsForRead(false);
3611
3310 3612
3311 if (item.PermsGranter == UUID.Zero) 3613 if (item.PermsGranter == UUID.Zero)
3312 return; 3614 return;
@@ -3373,10 +3675,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3373 3675
3374 TaskInventoryItem item; 3676 TaskInventoryItem item;
3375 3677
3376 lock (m_host.TaskInventory) 3678
3679 m_host.TaskInventory.LockItemsForRead(true);
3680 if (!m_host.TaskInventory.ContainsKey(invItemID))
3681 {
3682 m_host.TaskInventory.LockItemsForRead(false);
3683 return;
3684 }
3685 else
3377 { 3686 {
3378 item = m_host.TaskInventory[invItemID]; 3687 item = m_host.TaskInventory[invItemID];
3379 } 3688 }
3689 m_host.TaskInventory.LockItemsForRead(false);
3380 3690
3381 if (agentID == UUID.Zero || perm == 0) // Releasing permissions 3691 if (agentID == UUID.Zero || perm == 0) // Releasing permissions
3382 { 3692 {
@@ -3404,15 +3714,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3404 int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS | 3714 int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
3405 ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | 3715 ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
3406 ScriptBaseClass.PERMISSION_CONTROL_CAMERA | 3716 ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
3717 ScriptBaseClass.PERMISSION_TRACK_CAMERA |
3407 ScriptBaseClass.PERMISSION_ATTACH; 3718 ScriptBaseClass.PERMISSION_ATTACH;
3408 3719
3409 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3720 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3410 { 3721 {
3411 lock (m_host.TaskInventory) 3722 m_host.TaskInventory.LockItemsForWrite(true);
3412 { 3723 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3413 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3724 m_host.TaskInventory[invItemID].PermsMask = perm;
3414 m_host.TaskInventory[invItemID].PermsMask = perm; 3725 m_host.TaskInventory.LockItemsForWrite(false);
3415 }
3416 3726
3417 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3727 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3418 "run_time_permissions", new Object[] { 3728 "run_time_permissions", new Object[] {
@@ -3422,28 +3732,44 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3422 return; 3732 return;
3423 } 3733 }
3424 } 3734 }
3425 else if (m_host.SitTargetAvatar == agentID) // Sitting avatar 3735 else
3426 { 3736 {
3427 // When agent is sitting, certain permissions are implicit if requested from sitting agent 3737 bool sitting = false;
3428 int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | 3738 if (m_host.SitTargetAvatar == agentID)
3429 ScriptBaseClass.PERMISSION_CONTROL_CAMERA | 3739 {
3430 ScriptBaseClass.PERMISSION_TRACK_CAMERA | 3740 sitting = true;
3431 ScriptBaseClass.PERMISSION_TAKE_CONTROLS; 3741 }
3742 else
3743 {
3744 foreach (SceneObjectPart p in m_host.ParentGroup.Parts)
3745 {
3746 if (p.SitTargetAvatar == agentID)
3747 sitting = true;
3748 }
3749 }
3432 3750
3433 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3751 if (sitting)
3434 { 3752 {
3435 lock (m_host.TaskInventory) 3753 // When agent is sitting, certain permissions are implicit if requested from sitting agent
3754 int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
3755 ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
3756 ScriptBaseClass.PERMISSION_TRACK_CAMERA |
3757 ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3758
3759 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3436 { 3760 {
3761 m_host.TaskInventory.LockItemsForWrite(true);
3437 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3762 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3438 m_host.TaskInventory[invItemID].PermsMask = perm; 3763 m_host.TaskInventory[invItemID].PermsMask = perm;
3439 } 3764 m_host.TaskInventory.LockItemsForWrite(false);
3440 3765
3441 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3766 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3442 "run_time_permissions", new Object[] { 3767 "run_time_permissions", new Object[] {
3443 new LSL_Integer(perm) }, 3768 new LSL_Integer(perm) },
3444 new DetectParams[0])); 3769 new DetectParams[0]));
3445 3770
3446 return; 3771 return;
3772 }
3447 } 3773 }
3448 } 3774 }
3449 3775
@@ -3457,11 +3783,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3457 3783
3458 if (!m_waitingForScriptAnswer) 3784 if (!m_waitingForScriptAnswer)
3459 { 3785 {
3460 lock (m_host.TaskInventory) 3786 m_host.TaskInventory.LockItemsForWrite(true);
3461 { 3787 m_host.TaskInventory[invItemID].PermsGranter = agentID;
3462 m_host.TaskInventory[invItemID].PermsGranter = agentID; 3788 m_host.TaskInventory[invItemID].PermsMask = 0;
3463 m_host.TaskInventory[invItemID].PermsMask = 0; 3789 m_host.TaskInventory.LockItemsForWrite(false);
3464 }
3465 3790
3466 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3791 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3467 m_waitingForScriptAnswer=true; 3792 m_waitingForScriptAnswer=true;
@@ -3496,10 +3821,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3496 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3821 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3497 llReleaseControls(); 3822 llReleaseControls();
3498 3823
3499 lock (m_host.TaskInventory) 3824
3500 { 3825 m_host.TaskInventory.LockItemsForWrite(true);
3501 m_host.TaskInventory[invItemID].PermsMask = answer; 3826 m_host.TaskInventory[invItemID].PermsMask = answer;
3502 } 3827 m_host.TaskInventory.LockItemsForWrite(false);
3828
3503 3829
3504 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams( 3830 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
3505 "run_time_permissions", new Object[] { 3831 "run_time_permissions", new Object[] {
@@ -3511,16 +3837,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3511 { 3837 {
3512 m_host.AddScriptLPS(1); 3838 m_host.AddScriptLPS(1);
3513 3839
3514 lock (m_host.TaskInventory) 3840 m_host.TaskInventory.LockItemsForRead(true);
3841
3842 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3515 { 3843 {
3516 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3844 if (item.Type == 10 && item.ItemID == m_itemID)
3517 { 3845 {
3518 if (item.Type == 10 && item.ItemID == m_itemID) 3846 m_host.TaskInventory.LockItemsForRead(false);
3519 { 3847 return item.PermsGranter.ToString();
3520 return item.PermsGranter.ToString();
3521 }
3522 } 3848 }
3523 } 3849 }
3850 m_host.TaskInventory.LockItemsForRead(false);
3524 3851
3525 return UUID.Zero.ToString(); 3852 return UUID.Zero.ToString();
3526 } 3853 }
@@ -3529,19 +3856,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3529 { 3856 {
3530 m_host.AddScriptLPS(1); 3857 m_host.AddScriptLPS(1);
3531 3858
3532 lock (m_host.TaskInventory) 3859 m_host.TaskInventory.LockItemsForRead(true);
3860
3861 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
3533 { 3862 {
3534 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 3863 if (item.Type == 10 && item.ItemID == m_itemID)
3535 { 3864 {
3536 if (item.Type == 10 && item.ItemID == m_itemID) 3865 int perms = item.PermsMask;
3537 { 3866 if (m_automaticLinkPermission)
3538 int perms = item.PermsMask; 3867 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
3539 if (m_automaticLinkPermission) 3868 m_host.TaskInventory.LockItemsForRead(false);
3540 perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; 3869 return perms;
3541 return perms;
3542 }
3543 } 3870 }
3544 } 3871 }
3872 m_host.TaskInventory.LockItemsForRead(false);
3545 3873
3546 return 0; 3874 return 0;
3547 } 3875 }
@@ -3563,9 +3891,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3563 public void llSetLinkColor(int linknumber, LSL_Vector color, int face) 3891 public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
3564 { 3892 {
3565 List<SceneObjectPart> parts = GetLinkParts(linknumber); 3893 List<SceneObjectPart> parts = GetLinkParts(linknumber);
3566 3894 if (parts.Count > 0)
3567 foreach (SceneObjectPart part in parts) 3895 {
3568 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); 3896 try
3897 {
3898 parts[0].ParentGroup.areUpdatesSuspended = true;
3899 foreach (SceneObjectPart part in parts)
3900 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
3901 }
3902 finally
3903 {
3904 parts[0].ParentGroup.areUpdatesSuspended = false;
3905 }
3906 }
3569 } 3907 }
3570 3908
3571 public void llCreateLink(string target, int parent) 3909 public void llCreateLink(string target, int parent)
@@ -3578,11 +3916,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3578 return; 3916 return;
3579 3917
3580 TaskInventoryItem item; 3918 TaskInventoryItem item;
3581 lock (m_host.TaskInventory) 3919 m_host.TaskInventory.LockItemsForRead(true);
3582 { 3920 item = m_host.TaskInventory[invItemID];
3583 item = m_host.TaskInventory[invItemID]; 3921 m_host.TaskInventory.LockItemsForRead(false);
3584 } 3922
3585
3586 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3923 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3587 && !m_automaticLinkPermission) 3924 && !m_automaticLinkPermission)
3588 { 3925 {
@@ -3599,11 +3936,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3599 3936
3600 if (targetPart.ParentGroup.AttachmentPoint != 0) 3937 if (targetPart.ParentGroup.AttachmentPoint != 0)
3601 return; // Fail silently if attached 3938 return; // Fail silently if attached
3939
3940 if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
3941 return;
3942
3602 SceneObjectGroup parentPrim = null, childPrim = null; 3943 SceneObjectGroup parentPrim = null, childPrim = null;
3603 3944
3604 if (targetPart != null) 3945 if (targetPart != null)
3605 { 3946 {
3606 if (parent != 0) { 3947 if (parent != 0)
3948 {
3607 parentPrim = m_host.ParentGroup; 3949 parentPrim = m_host.ParentGroup;
3608 childPrim = targetPart.ParentGroup; 3950 childPrim = targetPart.ParentGroup;
3609 } 3951 }
@@ -3634,16 +3976,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3634 m_host.AddScriptLPS(1); 3976 m_host.AddScriptLPS(1);
3635 UUID invItemID = InventorySelf(); 3977 UUID invItemID = InventorySelf();
3636 3978
3637 lock (m_host.TaskInventory) 3979 m_host.TaskInventory.LockItemsForRead(true);
3638 {
3639 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 3980 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
3640 && !m_automaticLinkPermission) 3981 && !m_automaticLinkPermission)
3641 { 3982 {
3642 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); 3983 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
3984 m_host.TaskInventory.LockItemsForRead(false);
3643 return; 3985 return;
3644 } 3986 }
3645 } 3987 m_host.TaskInventory.LockItemsForRead(false);
3646 3988
3647 if (linknum < ScriptBaseClass.LINK_THIS) 3989 if (linknum < ScriptBaseClass.LINK_THIS)
3648 return; 3990 return;
3649 3991
@@ -3682,10 +4024,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3682 // Restructuring Multiple Prims. 4024 // Restructuring Multiple Prims.
3683 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts); 4025 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
3684 parts.Remove(parentPrim.RootPart); 4026 parts.Remove(parentPrim.RootPart);
3685 foreach (SceneObjectPart part in parts) 4027 if (parts.Count > 0)
3686 { 4028 {
3687 parentPrim.DelinkFromGroup(part.LocalId, true); 4029 try
4030 {
4031 parts[0].ParentGroup.areUpdatesSuspended = true;
4032 foreach (SceneObjectPart part in parts)
4033 {
4034 parentPrim.DelinkFromGroup(part.LocalId, true);
4035 }
4036 }
4037 finally
4038 {
4039 parts[0].ParentGroup.areUpdatesSuspended = false;
4040 }
3688 } 4041 }
4042
3689 parentPrim.HasGroupChanged = true; 4043 parentPrim.HasGroupChanged = true;
3690 parentPrim.ScheduleGroupForFullUpdate(); 4044 parentPrim.ScheduleGroupForFullUpdate();
3691 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 4045 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
@@ -3694,12 +4048,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3694 { 4048 {
3695 SceneObjectPart newRoot = parts[0]; 4049 SceneObjectPart newRoot = parts[0];
3696 parts.Remove(newRoot); 4050 parts.Remove(newRoot);
3697 foreach (SceneObjectPart part in parts) 4051
4052 try
3698 { 4053 {
3699 // Required for linking 4054 parts[0].ParentGroup.areUpdatesSuspended = true;
3700 part.ClearUpdateSchedule(); 4055 foreach (SceneObjectPart part in parts)
3701 newRoot.ParentGroup.LinkToGroup(part.ParentGroup); 4056 {
4057 part.ClearUpdateSchedule();
4058 newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
4059 }
3702 } 4060 }
4061 finally
4062 {
4063 parts[0].ParentGroup.areUpdatesSuspended = false;
4064 }
4065
4066
3703 newRoot.ParentGroup.HasGroupChanged = true; 4067 newRoot.ParentGroup.HasGroupChanged = true;
3704 newRoot.ParentGroup.ScheduleGroupForFullUpdate(); 4068 newRoot.ParentGroup.ScheduleGroupForFullUpdate();
3705 } 4069 }
@@ -3719,6 +4083,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3719 public void llBreakAllLinks() 4083 public void llBreakAllLinks()
3720 { 4084 {
3721 m_host.AddScriptLPS(1); 4085 m_host.AddScriptLPS(1);
4086
4087 UUID invItemID = InventorySelf();
4088
4089 TaskInventoryItem item;
4090 m_host.TaskInventory.LockItemsForRead(true);
4091 item = m_host.TaskInventory[invItemID];
4092 m_host.TaskInventory.LockItemsForRead(false);
4093
4094 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4095 && !m_automaticLinkPermission)
4096 {
4097 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
4098 return;
4099 }
4100
3722 SceneObjectGroup parentPrim = m_host.ParentGroup; 4101 SceneObjectGroup parentPrim = m_host.ParentGroup;
3723 if (parentPrim.AttachmentPoint != 0) 4102 if (parentPrim.AttachmentPoint != 0)
3724 return; // Fail silently if attached 4103 return; // Fail silently if attached
@@ -3764,6 +4143,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3764 } 4143 }
3765 else 4144 else
3766 { 4145 {
4146 if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
4147 {
4148 linknum -= (m_host.ParentGroup.PrimCount) + 1;
4149
4150 if (linknum < 0)
4151 return UUID.Zero.ToString();
4152
4153 List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
4154 if (avatars.Count > linknum)
4155 {
4156 return avatars[linknum].UUID.ToString();
4157 }
4158 }
3767 return UUID.Zero.ToString(); 4159 return UUID.Zero.ToString();
3768 } 4160 }
3769 } 4161 }
@@ -3862,17 +4254,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3862 m_host.AddScriptLPS(1); 4254 m_host.AddScriptLPS(1);
3863 int count = 0; 4255 int count = 0;
3864 4256
3865 lock (m_host.TaskInventory) 4257 m_host.TaskInventory.LockItemsForRead(true);
4258 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3866 { 4259 {
3867 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4260 if (inv.Value.Type == type || type == -1)
3868 { 4261 {
3869 if (inv.Value.Type == type || type == -1) 4262 count = count + 1;
3870 {
3871 count = count + 1;
3872 }
3873 } 4263 }
3874 } 4264 }
3875 4265
4266 m_host.TaskInventory.LockItemsForRead(false);
3876 return count; 4267 return count;
3877 } 4268 }
3878 4269
@@ -3881,16 +4272,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3881 m_host.AddScriptLPS(1); 4272 m_host.AddScriptLPS(1);
3882 ArrayList keys = new ArrayList(); 4273 ArrayList keys = new ArrayList();
3883 4274
3884 lock (m_host.TaskInventory) 4275 m_host.TaskInventory.LockItemsForRead(true);
4276 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3885 { 4277 {
3886 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4278 if (inv.Value.Type == type || type == -1)
3887 { 4279 {
3888 if (inv.Value.Type == type || type == -1) 4280 keys.Add(inv.Value.Name);
3889 {
3890 keys.Add(inv.Value.Name);
3891 }
3892 } 4281 }
3893 } 4282 }
4283 m_host.TaskInventory.LockItemsForRead(false);
3894 4284
3895 if (keys.Count == 0) 4285 if (keys.Count == 0)
3896 { 4286 {
@@ -3927,25 +4317,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3927 } 4317 }
3928 4318
3929 // move the first object found with this inventory name 4319 // move the first object found with this inventory name
3930 lock (m_host.TaskInventory) 4320 m_host.TaskInventory.LockItemsForRead(true);
4321 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3931 { 4322 {
3932 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4323 if (inv.Value.Name == inventory)
3933 { 4324 {
3934 if (inv.Value.Name == inventory) 4325 found = true;
3935 { 4326 objId = inv.Key;
3936 found = true; 4327 assetType = inv.Value.Type;
3937 objId = inv.Key; 4328 objName = inv.Value.Name;
3938 assetType = inv.Value.Type; 4329 break;
3939 objName = inv.Value.Name;
3940 break;
3941 }
3942 } 4330 }
3943 } 4331 }
4332 m_host.TaskInventory.LockItemsForRead(false);
3944 4333
3945 if (!found) 4334 if (!found)
3946 { 4335 {
3947 llSay(0, String.Format("Could not find object '{0}'", inventory)); 4336 llSay(0, String.Format("Could not find object '{0}'", inventory));
3948 throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); 4337 return;
4338// throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
3949 } 4339 }
3950 4340
3951 // check if destination is an object 4341 // check if destination is an object
@@ -3971,48 +4361,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3971 return; 4361 return;
3972 } 4362 }
3973 } 4363 }
4364
3974 // destination is an avatar 4365 // destination is an avatar
3975 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId); 4366 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId);
3976 4367
3977 if (agentItem == null) 4368 if (agentItem == null)
3978 return; 4369 return;
3979 4370
3980 byte[] bucket = new byte[17]; 4371 byte[] bucket = new byte[1];
3981 bucket[0] = (byte)assetType; 4372 bucket[0] = (byte)assetType;
3982 byte[] objBytes = agentItem.ID.GetBytes(); 4373 //byte[] objBytes = agentItem.ID.GetBytes();
3983 Array.Copy(objBytes, 0, bucket, 1, 16); 4374 //Array.Copy(objBytes, 0, bucket, 1, 16);
3984 4375
3985 GridInstantMessage msg = new GridInstantMessage(World, 4376 GridInstantMessage msg = new GridInstantMessage(World,
3986 m_host.UUID, m_host.Name+", an object owned by "+ 4377 m_host.OwnerID, m_host.Name, destId,
3987 resolveName(m_host.OwnerID)+",", destId,
3988 (byte)InstantMessageDialog.TaskInventoryOffered, 4378 (byte)InstantMessageDialog.TaskInventoryOffered,
3989 false, objName+"\n"+m_host.Name+" is located at "+ 4379 false, objName+". "+m_host.Name+" is located at "+
3990 World.RegionInfo.RegionName+" "+ 4380 World.RegionInfo.RegionName+" "+
3991 m_host.AbsolutePosition.ToString(), 4381 m_host.AbsolutePosition.ToString(),
3992 agentItem.ID, true, m_host.AbsolutePosition, 4382 agentItem.ID, true, m_host.AbsolutePosition,
3993 bucket); 4383 bucket);
3994 if (m_TransferModule != null) 4384
3995 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); 4385 ScenePresence sp;
4386
4387 if (World.TryGetScenePresence(destId, out sp))
4388 {
4389 sp.ControllingClient.SendInstantMessage(msg);
4390 }
4391 else
4392 {
4393 if (m_TransferModule != null)
4394 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
4395 }
4396
4397 //This delay should only occur when giving inventory to avatars.
3996 ScriptSleep(3000); 4398 ScriptSleep(3000);
3997 } 4399 }
3998 } 4400 }
3999 4401
4402 [DebuggerNonUserCode]
4000 public void llRemoveInventory(string name) 4403 public void llRemoveInventory(string name)
4001 { 4404 {
4002 m_host.AddScriptLPS(1); 4405 m_host.AddScriptLPS(1);
4003 4406
4004 lock (m_host.TaskInventory) 4407 List<TaskInventoryItem> inv;
4408 try
4005 { 4409 {
4006 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4410 m_host.TaskInventory.LockItemsForRead(true);
4411 inv = new List<TaskInventoryItem>(m_host.TaskInventory.Values);
4412 }
4413 finally
4414 {
4415 m_host.TaskInventory.LockItemsForRead(false);
4416 }
4417 foreach (TaskInventoryItem item in inv)
4418 {
4419 if (item.Name == name)
4007 { 4420 {
4008 if (item.Name == name) 4421 if (item.ItemID == m_itemID)
4009 { 4422 throw new ScriptDeleteException();
4010 if (item.ItemID == m_itemID) 4423 else
4011 throw new ScriptDeleteException(); 4424 m_host.Inventory.RemoveInventoryItem(item.ItemID);
4012 else 4425 return;
4013 m_host.Inventory.RemoveInventoryItem(item.ItemID);
4014 return;
4015 }
4016 } 4426 }
4017 } 4427 }
4018 } 4428 }
@@ -4047,112 +4457,122 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4047 { 4457 {
4048 m_host.AddScriptLPS(1); 4458 m_host.AddScriptLPS(1);
4049 4459
4050 UUID uuid = (UUID)id; 4460 UUID uuid;
4051 PresenceInfo pinfo = null; 4461 if (UUID.TryParse(id, out uuid))
4052 UserAccount account;
4053
4054 UserInfoCacheEntry ce;
4055 if (!m_userInfoCache.TryGetValue(uuid, out ce))
4056 { 4462 {
4057 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); 4463 PresenceInfo pinfo = null;
4058 if (account == null) 4464 UserAccount account;
4465
4466 UserInfoCacheEntry ce;
4467 if (!m_userInfoCache.TryGetValue(uuid, out ce))
4059 { 4468 {
4060 m_userInfoCache[uuid] = null; // Cache negative 4469 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
4061 return UUID.Zero.ToString(); 4470 if (account == null)
4062 } 4471 {
4472 m_userInfoCache[uuid] = null; // Cache negative
4473 return UUID.Zero.ToString();
4474 }
4063 4475
4064 4476
4065 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); 4477 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4066 if (pinfos != null && pinfos.Length > 0) 4478 if (pinfos != null && pinfos.Length > 0)
4067 {
4068 foreach (PresenceInfo p in pinfos)
4069 { 4479 {
4070 if (p.RegionID != UUID.Zero) 4480 foreach (PresenceInfo p in pinfos)
4071 { 4481 {
4072 pinfo = p; 4482 if (p.RegionID != UUID.Zero)
4483 {
4484 pinfo = p;
4485 }
4073 } 4486 }
4074 } 4487 }
4075 }
4076 4488
4077 ce = new UserInfoCacheEntry(); 4489 ce = new UserInfoCacheEntry();
4078 ce.time = Util.EnvironmentTickCount(); 4490 ce.time = Util.EnvironmentTickCount();
4079 ce.account = account; 4491 ce.account = account;
4080 ce.pinfo = pinfo; 4492 ce.pinfo = pinfo;
4081 } 4493 m_userInfoCache[uuid] = ce;
4082 else 4494 }
4083 { 4495 else
4084 if (ce == null) 4496 {
4085 return UUID.Zero.ToString(); 4497 if (ce == null)
4498 return UUID.Zero.ToString();
4086 4499
4087 account = ce.account; 4500 account = ce.account;
4088 pinfo = ce.pinfo; 4501 pinfo = ce.pinfo;
4089 } 4502 }
4090 4503
4091 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) 4504 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000)
4092 {
4093 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4094 if (pinfos != null && pinfos.Length > 0)
4095 { 4505 {
4096 foreach (PresenceInfo p in pinfos) 4506 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4507 if (pinfos != null && pinfos.Length > 0)
4097 { 4508 {
4098 if (p.RegionID != UUID.Zero) 4509 foreach (PresenceInfo p in pinfos)
4099 { 4510 {
4100 pinfo = p; 4511 if (p.RegionID != UUID.Zero)
4512 {
4513 pinfo = p;
4514 }
4101 } 4515 }
4102 } 4516 }
4103 } 4517 else
4104 else 4518 pinfo = null;
4105 pinfo = null;
4106 4519
4107 ce.time = Util.EnvironmentTickCount(); 4520 ce.time = Util.EnvironmentTickCount();
4108 ce.pinfo = pinfo; 4521 ce.pinfo = pinfo;
4109 } 4522 }
4110 4523
4111 string reply = String.Empty; 4524 string reply = String.Empty;
4112 4525
4113 switch (data) 4526 switch (data)
4114 { 4527 {
4115 case 1: // DATA_ONLINE (0|1) 4528 case 1: // DATA_ONLINE (0|1)
4116 if (pinfo != null && pinfo.RegionID != UUID.Zero) 4529 if (pinfo != null && pinfo.RegionID != UUID.Zero)
4117 reply = "1"; 4530 reply = "1";
4118 else 4531 else
4119 reply = "0"; 4532 reply = "0";
4120 break; 4533 break;
4121 case 2: // DATA_NAME (First Last) 4534 case 2: // DATA_NAME (First Last)
4122 reply = account.FirstName + " " + account.LastName; 4535 reply = account.FirstName + " " + account.LastName;
4123 break; 4536 break;
4124 case 3: // DATA_BORN (YYYY-MM-DD) 4537 case 3: // DATA_BORN (YYYY-MM-DD)
4125 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); 4538 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
4126 born = born.AddSeconds(account.Created); 4539 born = born.AddSeconds(account.Created);
4127 reply = born.ToString("yyyy-MM-dd"); 4540 reply = born.ToString("yyyy-MM-dd");
4128 break; 4541 break;
4129 case 4: // DATA_RATING (0,0,0,0,0,0) 4542 case 4: // DATA_RATING (0,0,0,0,0,0)
4130 reply = "0,0,0,0,0,0"; 4543 reply = "0,0,0,0,0,0";
4131 break; 4544 break;
4132 case 8: // DATA_PAYINFO (0|1|2|3) 4545 case 8: // DATA_PAYINFO (0|1|2|3)
4133 reply = "0"; 4546 reply = "0";
4134 break; 4547 break;
4135 default: 4548 default:
4136 return UUID.Zero.ToString(); // Raise no event 4549 return UUID.Zero.ToString(); // Raise no event
4137 } 4550 }
4138 4551
4139 UUID rq = UUID.Random(); 4552 UUID rq = UUID.Random();
4140 4553
4141 UUID tid = AsyncCommands. 4554 UUID tid = AsyncCommands.
4142 DataserverPlugin.RegisterRequest(m_localID, 4555 DataserverPlugin.RegisterRequest(m_localID,
4143 m_itemID, rq.ToString()); 4556 m_itemID, rq.ToString());
4144 4557
4145 AsyncCommands. 4558 AsyncCommands.
4146 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4559 DataserverPlugin.DataserverReply(rq.ToString(), reply);
4147 4560
4148 ScriptSleep(100); 4561 ScriptSleep(100);
4149 return tid.ToString(); 4562 return tid.ToString();
4563 }
4564 else
4565 {
4566 ShoutError("Invalid UUID passed to llRequestAgentData.");
4567 }
4568 return "";
4150 } 4569 }
4151 4570
4152 public LSL_String llRequestInventoryData(string name) 4571 public LSL_String llRequestInventoryData(string name)
4153 { 4572 {
4154 m_host.AddScriptLPS(1); 4573 m_host.AddScriptLPS(1);
4155 4574
4575 //Clone is thread safe
4156 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 4576 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
4157 4577
4158 foreach (TaskInventoryItem item in itemDictionary.Values) 4578 foreach (TaskInventoryItem item in itemDictionary.Values)
@@ -4206,6 +4626,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4206 ScenePresence presence = World.GetScenePresence(agentId); 4626 ScenePresence presence = World.GetScenePresence(agentId);
4207 if (presence != null) 4627 if (presence != null)
4208 { 4628 {
4629 // agent must not be a god
4630 if (presence.UserLevel >= 200) return;
4631
4209 // agent must be over the owners land 4632 // agent must be over the owners land
4210 if (m_host.OwnerID == World.LandChannel.GetLandObject( 4633 if (m_host.OwnerID == World.LandChannel.GetLandObject(
4211 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) 4634 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
@@ -4228,7 +4651,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4228 UUID av = new UUID(); 4651 UUID av = new UUID();
4229 if (!UUID.TryParse(agent,out av)) 4652 if (!UUID.TryParse(agent,out av))
4230 { 4653 {
4231 LSLError("First parameter to llDialog needs to be a key"); 4654 //LSLError("First parameter to llDialog needs to be a key");
4232 return; 4655 return;
4233 } 4656 }
4234 4657
@@ -4265,17 +4688,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4265 UUID soundId = UUID.Zero; 4688 UUID soundId = UUID.Zero;
4266 if (!UUID.TryParse(impact_sound, out soundId)) 4689 if (!UUID.TryParse(impact_sound, out soundId))
4267 { 4690 {
4268 lock (m_host.TaskInventory) 4691 m_host.TaskInventory.LockItemsForRead(true);
4692 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4269 { 4693 {
4270 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4694 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
4271 { 4695 {
4272 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 4696 soundId = item.AssetID;
4273 { 4697 break;
4274 soundId = item.AssetID;
4275 break;
4276 }
4277 } 4698 }
4278 } 4699 }
4700 m_host.TaskInventory.LockItemsForRead(false);
4279 } 4701 }
4280 m_host.CollisionSound = soundId; 4702 m_host.CollisionSound = soundId;
4281 m_host.CollisionSoundVolume = (float)impact_volume; 4703 m_host.CollisionSoundVolume = (float)impact_volume;
@@ -4315,6 +4737,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4315 UUID partItemID; 4737 UUID partItemID;
4316 foreach (SceneObjectPart part in parts) 4738 foreach (SceneObjectPart part in parts)
4317 { 4739 {
4740 //Clone is thread safe
4318 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); 4741 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
4319 4742
4320 foreach (TaskInventoryItem item in itemsDictionary.Values) 4743 foreach (TaskInventoryItem item in itemsDictionary.Values)
@@ -4529,17 +4952,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4529 4952
4530 m_host.AddScriptLPS(1); 4953 m_host.AddScriptLPS(1);
4531 4954
4532 lock (m_host.TaskInventory) 4955 m_host.TaskInventory.LockItemsForRead(true);
4956 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4533 { 4957 {
4534 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4958 if (item.Type == 10 && item.ItemID == m_itemID)
4535 { 4959 {
4536 if (item.Type == 10 && item.ItemID == m_itemID) 4960 result = item.Name!=null?item.Name:String.Empty;
4537 { 4961 break;
4538 result = item.Name != null ? item.Name : String.Empty;
4539 break;
4540 }
4541 } 4962 }
4542 } 4963 }
4964 m_host.TaskInventory.LockItemsForRead(false);
4543 4965
4544 return result; 4966 return result;
4545 } 4967 }
@@ -4708,23 +5130,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4708 { 5130 {
4709 m_host.AddScriptLPS(1); 5131 m_host.AddScriptLPS(1);
4710 5132
4711 lock (m_host.TaskInventory) 5133 m_host.TaskInventory.LockItemsForRead(true);
5134 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4712 { 5135 {
4713 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 5136 if (inv.Value.Name == name)
4714 { 5137 {
4715 if (inv.Value.Name == name) 5138 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
4716 { 5139 {
4717 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) 5140 m_host.TaskInventory.LockItemsForRead(false);
4718 { 5141 return inv.Value.AssetID.ToString();
4719 return inv.Value.AssetID.ToString(); 5142 }
4720 } 5143 else
4721 else 5144 {
4722 { 5145 m_host.TaskInventory.LockItemsForRead(false);
4723 return UUID.Zero.ToString(); 5146 return UUID.Zero.ToString();
4724 }
4725 } 5147 }
4726 } 5148 }
4727 } 5149 }
5150 m_host.TaskInventory.LockItemsForRead(false);
4728 5151
4729 return UUID.Zero.ToString(); 5152 return UUID.Zero.ToString();
4730 } 5153 }
@@ -4877,14 +5300,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4877 { 5300 {
4878 m_host.AddScriptLPS(1); 5301 m_host.AddScriptLPS(1);
4879 5302
4880 if (src == null) 5303 return src.Length;
4881 {
4882 return 0;
4883 }
4884 else
4885 {
4886 return src.Length;
4887 }
4888 } 5304 }
4889 5305
4890 public LSL_Integer llList2Integer(LSL_List src, int index) 5306 public LSL_Integer llList2Integer(LSL_List src, int index)
@@ -4930,7 +5346,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4930 else if (src.Data[index] is LSL_Float) 5346 else if (src.Data[index] is LSL_Float)
4931 return Convert.ToDouble(((LSL_Float) src.Data[index]).value); 5347 return Convert.ToDouble(((LSL_Float) src.Data[index]).value);
4932 else if (src.Data[index] is LSL_String) 5348 else if (src.Data[index] is LSL_String)
4933 return Convert.ToDouble(((LSL_String) src.Data[index]).m_string); 5349 {
5350 string str = ((LSL_String) src.Data[index]).m_string;
5351 Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
5352 if (m != Match.Empty)
5353 {
5354 str = m.Value;
5355 double d = 0.0;
5356 if (!Double.TryParse(str, out d))
5357 return 0.0;
5358
5359 return d;
5360 }
5361 return 0.0;
5362 }
4934 return Convert.ToDouble(src.Data[index]); 5363 return Convert.ToDouble(src.Data[index]);
4935 } 5364 }
4936 catch (FormatException) 5365 catch (FormatException)
@@ -5203,7 +5632,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5203 } 5632 }
5204 } 5633 }
5205 } 5634 }
5206 else { 5635 else
5636 {
5207 object[] array = new object[src.Length]; 5637 object[] array = new object[src.Length];
5208 Array.Copy(src.Data, 0, array, 0, src.Length); 5638 Array.Copy(src.Data, 0, array, 0, src.Length);
5209 result = new LSL_List(array); 5639 result = new LSL_List(array);
@@ -5654,10 +6084,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5654 m_host.AddScriptLPS(1); 6084 m_host.AddScriptLPS(1);
5655 6085
5656 List<SceneObjectPart> parts = GetLinkParts(linknumber); 6086 List<SceneObjectPart> parts = GetLinkParts(linknumber);
5657 6087 if (parts.Count > 0)
5658 foreach (var part in parts)
5659 { 6088 {
5660 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate); 6089 try
6090 {
6091 parts[0].ParentGroup.areUpdatesSuspended = true;
6092 foreach (var part in parts)
6093 {
6094 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
6095 }
6096 }
6097 finally
6098 {
6099 parts[0].ParentGroup.areUpdatesSuspended = false;
6100 }
5661 } 6101 }
5662 } 6102 }
5663 6103
@@ -5711,6 +6151,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5711 ScriptSleep(5000); 6151 ScriptSleep(5000);
5712 } 6152 }
5713 6153
6154 public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
6155 {
6156 return ParseString2List(str, separators, in_spacers, false);
6157 }
6158
5714 public LSL_Integer llOverMyLand(string id) 6159 public LSL_Integer llOverMyLand(string id)
5715 { 6160 {
5716 m_host.AddScriptLPS(1); 6161 m_host.AddScriptLPS(1);
@@ -5775,8 +6220,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5775 UUID agentId = new UUID(); 6220 UUID agentId = new UUID();
5776 if (!UUID.TryParse(agent, out agentId)) 6221 if (!UUID.TryParse(agent, out agentId))
5777 return new LSL_Integer(0); 6222 return new LSL_Integer(0);
6223 if (agentId == m_host.GroupID)
6224 return new LSL_Integer(1);
5778 ScenePresence presence = World.GetScenePresence(agentId); 6225 ScenePresence presence = World.GetScenePresence(agentId);
5779 if (presence == null || presence.IsChildAgent) // Return flase for child agents 6226 if (presence == null || presence.IsChildAgent) // Return false for child agents
5780 return new LSL_Integer(0); 6227 return new LSL_Integer(0);
5781 IClientAPI client = presence.ControllingClient; 6228 IClientAPI client = presence.ControllingClient;
5782 if (m_host.GroupID == client.ActiveGroupId) 6229 if (m_host.GroupID == client.ActiveGroupId)
@@ -5911,7 +6358,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5911 return m_host.ParentGroup.AttachmentPoint; 6358 return m_host.ParentGroup.AttachmentPoint;
5912 } 6359 }
5913 6360
5914 public LSL_Integer llGetFreeMemory() 6361 public virtual LSL_Integer llGetFreeMemory()
5915 { 6362 {
5916 m_host.AddScriptLPS(1); 6363 m_host.AddScriptLPS(1);
5917 // Make scripts designed for LSO happy 6364 // Make scripts designed for LSO happy
@@ -6028,7 +6475,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6028 SetParticleSystem(m_host, rules); 6475 SetParticleSystem(m_host, rules);
6029 } 6476 }
6030 6477
6031 private void SetParticleSystem(SceneObjectPart part, LSL_List rules) { 6478 private void SetParticleSystem(SceneObjectPart part, LSL_List rules)
6479 {
6032 6480
6033 6481
6034 if (rules.Length == 0) 6482 if (rules.Length == 0)
@@ -6222,14 +6670,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6222 6670
6223 protected UUID GetTaskInventoryItem(string name) 6671 protected UUID GetTaskInventoryItem(string name)
6224 { 6672 {
6225 lock (m_host.TaskInventory) 6673 m_host.TaskInventory.LockItemsForRead(true);
6674 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6226 { 6675 {
6227 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6676 if (inv.Value.Name == name)
6228 { 6677 {
6229 if (inv.Value.Name == name) 6678 m_host.TaskInventory.LockItemsForRead(false);
6230 return inv.Key; 6679 return inv.Key;
6231 } 6680 }
6232 } 6681 }
6682 m_host.TaskInventory.LockItemsForRead(false);
6233 6683
6234 return UUID.Zero; 6684 return UUID.Zero;
6235 } 6685 }
@@ -6267,16 +6717,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6267 if (folderID == UUID.Zero) 6717 if (folderID == UUID.Zero)
6268 return; 6718 return;
6269 6719
6270 byte[] bucket = new byte[17]; 6720 byte[] bucket = new byte[1];
6271 bucket[0] = (byte)AssetType.Folder; 6721 bucket[0] = (byte)AssetType.Folder;
6272 byte[] objBytes = folderID.GetBytes(); 6722 //byte[] objBytes = folderID.GetBytes();
6273 Array.Copy(objBytes, 0, bucket, 1, 16); 6723 //Array.Copy(objBytes, 0, bucket, 1, 16);
6274 6724
6275 GridInstantMessage msg = new GridInstantMessage(World, 6725 GridInstantMessage msg = new GridInstantMessage(World,
6276 m_host.UUID, m_host.Name+", an object owned by "+ 6726 m_host.OwnerID, m_host.Name, destID,
6277 resolveName(m_host.OwnerID)+",", destID, 6727 (byte)InstantMessageDialog.TaskInventoryOffered,
6278 (byte)InstantMessageDialog.InventoryOffered, 6728 false, category+". "+m_host.Name+" is located at "+
6279 false, category+"\n"+m_host.Name+" is located at "+
6280 World.RegionInfo.RegionName+" "+ 6729 World.RegionInfo.RegionName+" "+
6281 m_host.AbsolutePosition.ToString(), 6730 m_host.AbsolutePosition.ToString(),
6282 folderID, true, m_host.AbsolutePosition, 6731 folderID, true, m_host.AbsolutePosition,
@@ -6479,13 +6928,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6479 UUID av = new UUID(); 6928 UUID av = new UUID();
6480 if (!UUID.TryParse(avatar,out av)) 6929 if (!UUID.TryParse(avatar,out av))
6481 { 6930 {
6482 LSLError("First parameter to llDialog needs to be a key"); 6931 //LSLError("First parameter to llDialog needs to be a key");
6483 return; 6932 return;
6484 } 6933 }
6485 if (buttons.Length < 1) 6934 if (buttons.Length < 1)
6486 { 6935 {
6487 LSLError("No less than 1 button can be shown"); 6936 buttons.Add("OK");
6488 return;
6489 } 6937 }
6490 if (buttons.Length > 12) 6938 if (buttons.Length > 12)
6491 { 6939 {
@@ -6502,7 +6950,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6502 } 6950 }
6503 if (buttons.Data[i].ToString().Length > 24) 6951 if (buttons.Data[i].ToString().Length > 24)
6504 { 6952 {
6505 LSLError("button label cannot be longer than 24 characters"); 6953 llWhisper(ScriptBaseClass.DEBUG_CHANNEL, "button label cannot be longer than 24 characters");
6506 return; 6954 return;
6507 } 6955 }
6508 buts[i] = buttons.Data[i].ToString(); 6956 buts[i] = buttons.Data[i].ToString();
@@ -6561,22 +7009,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6561 } 7009 }
6562 7010
6563 // copy the first script found with this inventory name 7011 // copy the first script found with this inventory name
6564 lock (m_host.TaskInventory) 7012 TaskInventoryItem scriptItem = null;
7013 m_host.TaskInventory.LockItemsForRead(true);
7014 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6565 { 7015 {
6566 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 7016 if (inv.Value.Name == name)
6567 { 7017 {
6568 if (inv.Value.Name == name) 7018 // make sure the object is a script
7019 if (10 == inv.Value.Type)
6569 { 7020 {
6570 // make sure the object is a script 7021 found = true;
6571 if (10 == inv.Value.Type) 7022 srcId = inv.Key;
6572 { 7023 scriptItem = inv.Value;
6573 found = true; 7024 break;
6574 srcId = inv.Key;
6575 break;
6576 }
6577 } 7025 }
6578 } 7026 }
6579 } 7027 }
7028 m_host.TaskInventory.LockItemsForRead(false);
6580 7029
6581 if (!found) 7030 if (!found)
6582 { 7031 {
@@ -6584,8 +7033,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6584 return; 7033 return;
6585 } 7034 }
6586 7035
6587 // the rest of the permission checks are done in RezScript, so check the pin there as well 7036 SceneObjectPart dest = World.GetSceneObjectPart(destId);
6588 World.RezScript(srcId, m_host, destId, pin, running, start_param); 7037 if (dest != null)
7038 {
7039 if ((scriptItem.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
7040 {
7041 // the rest of the permission checks are done in RezScript, so check the pin there as well
7042 World.RezScript(srcId, m_host, destId, pin, running, start_param);
7043
7044 if ((scriptItem.BasePermissions & (uint)PermissionMask.Copy) == 0)
7045 m_host.Inventory.RemoveInventoryItem(srcId);
7046 }
7047 }
6589 // this will cause the delay even if the script pin or permissions were wrong - seems ok 7048 // this will cause the delay even if the script pin or permissions were wrong - seems ok
6590 ScriptSleep(3000); 7049 ScriptSleep(3000);
6591 } 7050 }
@@ -6648,19 +7107,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6648 public LSL_String llMD5String(string src, int nonce) 7107 public LSL_String llMD5String(string src, int nonce)
6649 { 7108 {
6650 m_host.AddScriptLPS(1); 7109 m_host.AddScriptLPS(1);
6651 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString())); 7110 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
6652 } 7111 }
6653 7112
6654 public LSL_String llSHA1String(string src) 7113 public LSL_String llSHA1String(string src)
6655 { 7114 {
6656 m_host.AddScriptLPS(1); 7115 m_host.AddScriptLPS(1);
6657 return Util.SHA1Hash(src).ToLower(); 7116 return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
6658 } 7117 }
6659 7118
6660 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve) 7119 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
6661 { 7120 {
6662 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7121 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
6663 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7122 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
7123 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7124 return shapeBlock;
6664 7125
6665 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && 7126 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
6666 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && 7127 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
@@ -6765,6 +7226,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6765 // Prim type box, cylinder and prism. 7226 // Prim type box, cylinder and prism.
6766 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) 7227 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)
6767 { 7228 {
7229 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7230 return;
7231
6768 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7232 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
6769 ObjectShapePacket.ObjectDataBlock shapeBlock; 7233 ObjectShapePacket.ObjectDataBlock shapeBlock;
6770 7234
@@ -6818,6 +7282,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6818 // Prim type sphere. 7282 // Prim type sphere.
6819 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve) 7283 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
6820 { 7284 {
7285 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7286 return;
7287
6821 ObjectShapePacket.ObjectDataBlock shapeBlock; 7288 ObjectShapePacket.ObjectDataBlock shapeBlock;
6822 7289
6823 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve); 7290 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
@@ -6859,6 +7326,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6859 // Prim type torus, tube and ring. 7326 // Prim type torus, tube and ring.
6860 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) 7327 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)
6861 { 7328 {
7329 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7330 return;
7331
6862 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7332 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
6863 ObjectShapePacket.ObjectDataBlock shapeBlock; 7333 ObjectShapePacket.ObjectDataBlock shapeBlock;
6864 7334
@@ -6994,6 +7464,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6994 // Prim type sculpt. 7464 // Prim type sculpt.
6995 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve) 7465 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
6996 { 7466 {
7467 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7468 return;
7469
6997 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7470 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
6998 UUID sculptId; 7471 UUID sculptId;
6999 7472
@@ -7010,13 +7483,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7010 shapeBlock.PathScaleX = 100; 7483 shapeBlock.PathScaleX = 100;
7011 shapeBlock.PathScaleY = 150; 7484 shapeBlock.PathScaleY = 150;
7012 7485
7013 if (type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER && 7486 if ((type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_CYLINDER) == 0 &&
7014 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE && 7487 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_PLANE) == 0 &&
7015 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE && 7488 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE) == 0 &&
7016 type != (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) 7489 (type & (int)ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS) == 0)
7017 { 7490 {
7018 // default 7491 // default
7019 type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; 7492 type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
7020 } 7493 }
7021 7494
7022 part.Shape.SetSculptProperties((byte)type, sculptId); 7495 part.Shape.SetSculptProperties((byte)type, sculptId);
@@ -7032,32 +7505,87 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7032 ScriptSleep(200); 7505 ScriptSleep(200);
7033 } 7506 }
7034 7507
7035 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) 7508 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
7036 { 7509 {
7037 m_host.AddScriptLPS(1); 7510 m_host.AddScriptLPS(1);
7038 7511
7039 setLinkPrimParams(linknumber, rules); 7512 setLinkPrimParams(linknumber, rules);
7040
7041 ScriptSleep(200);
7042 } 7513 }
7043 7514
7044 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) 7515 private void setLinkPrimParams(int linknumber, LSL_List rules)
7045 { 7516 {
7046 m_host.AddScriptLPS(1); 7517 List<SceneObjectPart> parts = GetLinkParts(linknumber);
7518 List<ScenePresence> avatars = GetLinkAvatars(linknumber);
7519 if (parts.Count>0)
7520 {
7521 try
7522 {
7523 parts[0].ParentGroup.areUpdatesSuspended = true;
7524 foreach (SceneObjectPart part in parts)
7525 SetPrimParams(part, rules);
7526 }
7527 finally
7528 {
7529 parts[0].ParentGroup.areUpdatesSuspended = false;
7530 }
7531 }
7532 if (avatars.Count > 0)
7533 {
7534 foreach (ScenePresence avatar in avatars)
7535 SetPrimParams(avatar, rules);
7536 }
7537 }
7047 7538
7048 setLinkPrimParams(linknumber, rules); 7539 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
7540 {
7541 llSetLinkPrimitiveParamsFast(linknumber, rules);
7542 ScriptSleep(200);
7049 } 7543 }
7050 7544
7051 protected void setLinkPrimParams(int linknumber, LSL_List rules) 7545 protected void SetPrimParams(ScenePresence av, LSL_List rules)
7052 { 7546 {
7053 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7547 //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
7548 //We only support PRIM_POSITION and PRIM_ROTATION
7054 7549
7055 foreach (SceneObjectPart part in parts) 7550 int idx = 0;
7056 SetPrimParams(part, rules); 7551
7552 while (idx < rules.Length)
7553 {
7554 int code = rules.GetLSLIntegerItem(idx++);
7555
7556 int remain = rules.Length - idx;
7557
7558
7559
7560 switch (code)
7561 {
7562 case (int)ScriptBaseClass.PRIM_POSITION:
7563 if (remain < 1)
7564 return;
7565 LSL_Vector v;
7566 v = rules.GetVector3Item(idx++);
7567 av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
7568 av.SendAvatarDataToAllAgents();
7569
7570 break;
7571
7572 case (int)ScriptBaseClass.PRIM_ROTATION:
7573 if (remain < 1)
7574 return;
7575 LSL_Rotation r;
7576 r = rules.GetQuaternionItem(idx++);
7577 av.Rotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
7578 av.SendAvatarDataToAllAgents();
7579 break;
7580 }
7581 }
7057 } 7582 }
7058 7583
7059 protected void SetPrimParams(SceneObjectPart part, LSL_List rules) 7584 protected void SetPrimParams(SceneObjectPart part, LSL_List rules)
7060 { 7585 {
7586 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7587 return;
7588
7061 int idx = 0; 7589 int idx = 0;
7062 7590
7063 bool positionChanged = false; 7591 bool positionChanged = false;
@@ -7462,6 +7990,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7462 } 7990 }
7463 } 7991 }
7464 } 7992 }
7993
7994 if (positionChanged)
7995 {
7996 if (part.ParentGroup.RootPart == part)
7997 {
7998 SceneObjectGroup parent = part.ParentGroup;
7999 parent.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z));
8000 }
8001 else
8002 {
8003 part.OffsetPosition = new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z);
8004 SceneObjectGroup parent = part.ParentGroup;
8005 parent.HasGroupChanged = true;
8006 parent.ScheduleGroupForTerseUpdate();
8007 }
8008 }
7465 } 8009 }
7466 8010
7467 public LSL_String llStringToBase64(string str) 8011 public LSL_String llStringToBase64(string str)
@@ -7610,13 +8154,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7610 public LSL_Integer llGetNumberOfPrims() 8154 public LSL_Integer llGetNumberOfPrims()
7611 { 8155 {
7612 m_host.AddScriptLPS(1); 8156 m_host.AddScriptLPS(1);
7613 int avatarCount = 0; 8157 int avatarCount = m_host.ParentGroup.GetLinkedAvatars().Count;
7614 World.ForEachRootScenePresence(delegate(ScenePresence presence) 8158
7615 {
7616 if (presence.ParentID != 0 && m_host.ParentGroup.HasChildPrim(presence.ParentID))
7617 avatarCount++;
7618 });
7619
7620 return m_host.ParentGroup.PrimCount + avatarCount; 8159 return m_host.ParentGroup.PrimCount + avatarCount;
7621 } 8160 }
7622 8161
@@ -7632,55 +8171,98 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7632 m_host.AddScriptLPS(1); 8171 m_host.AddScriptLPS(1);
7633 UUID objID = UUID.Zero; 8172 UUID objID = UUID.Zero;
7634 LSL_List result = new LSL_List(); 8173 LSL_List result = new LSL_List();
8174
8175 // If the ID is not valid, return null result
7635 if (!UUID.TryParse(obj, out objID)) 8176 if (!UUID.TryParse(obj, out objID))
7636 { 8177 {
7637 result.Add(new LSL_Vector()); 8178 result.Add(new LSL_Vector());
7638 result.Add(new LSL_Vector()); 8179 result.Add(new LSL_Vector());
7639 return result; 8180 return result;
7640 } 8181 }
8182
8183 // Check if this is an attached prim. If so, replace
8184 // the UUID with the avatar UUID and report it's bounding box
8185 SceneObjectPart part = World.GetSceneObjectPart(objID);
8186 if (part != null && part.ParentGroup.IsAttachment)
8187 objID = part.ParentGroup.AttachedAvatar;
8188
8189 // Find out if this is an avatar ID. If so, return it's box
7641 ScenePresence presence = World.GetScenePresence(objID); 8190 ScenePresence presence = World.GetScenePresence(objID);
7642 if (presence != null) 8191 if (presence != null)
7643 { 8192 {
7644 if (presence.ParentID == 0) // not sat on an object 8193 // As per LSL Wiki, there is no difference between sitting
8194 // and standing avatar since server 1.36
8195 LSL_Vector lower;
8196 LSL_Vector upper;
8197 if (presence.Animator.Animations.DefaultAnimation.AnimID
8198 == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
7645 { 8199 {
7646 LSL_Vector lower; 8200 // This is for ground sitting avatars
7647 LSL_Vector upper; 8201 float height = presence.Appearance.AvatarHeight / 2.66666667f;
7648 if (presence.Animator.Animations.DefaultAnimation.AnimID 8202 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
7649 == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) 8203 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
7650 {
7651 // This is for ground sitting avatars
7652 float height = presence.Appearance.AvatarHeight / 2.66666667f;
7653 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
7654 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
7655 }
7656 else
7657 {
7658 // This is for standing/flying avatars
7659 float height = presence.Appearance.AvatarHeight / 2.0f;
7660 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
7661 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
7662 }
7663 result.Add(lower);
7664 result.Add(upper);
7665 return result;
7666 } 8204 }
7667 else 8205 else
7668 { 8206 {
7669 // sitting on an object so we need the bounding box of that 8207 // This is for standing/flying avatars
7670 // which should include the avatar so set the UUID to the 8208 float height = presence.Appearance.AvatarHeight / 2.0f;
7671 // UUID of the object the avatar is sat on and allow it to fall through 8209 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
7672 // to processing an object 8210 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
7673 SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
7674 objID = p.UUID;
7675 } 8211 }
8212
8213 // Adjust to the documented error offsets (see LSL Wiki)
8214 lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
8215 upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
8216
8217 if (lower.x > upper.x)
8218 lower.x = upper.x;
8219 if (lower.y > upper.y)
8220 lower.y = upper.y;
8221 if (lower.z > upper.z)
8222 lower.z = upper.z;
8223
8224 result.Add(lower);
8225 result.Add(upper);
8226 return result;
7676 } 8227 }
7677 SceneObjectPart part = World.GetSceneObjectPart(objID); 8228
8229 part = World.GetSceneObjectPart(objID);
7678 // Currently only works for single prims without a sitting avatar 8230 // Currently only works for single prims without a sitting avatar
7679 if (part != null) 8231 if (part != null)
7680 { 8232 {
7681 Vector3 halfSize = part.Scale / 2.0f; 8233 float minX;
7682 LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f); 8234 float maxX;
7683 LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z); 8235 float minY;
8236 float maxY;
8237 float minZ;
8238 float maxZ;
8239
8240 // This BBox is in sim coordinates, with the offset being
8241 // a contained point.
8242 Vector3[] offsets = Scene.GetCombinedBoundingBox(new List<SceneObjectGroup> { part.ParentGroup },
8243 out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
8244
8245 minX -= offsets[0].X;
8246 maxX -= offsets[0].X;
8247 minY -= offsets[0].Y;
8248 maxY -= offsets[0].Y;
8249 minZ -= offsets[0].Z;
8250 maxZ -= offsets[0].Z;
8251
8252 LSL_Vector lower;
8253 LSL_Vector upper;
8254
8255 // Adjust to the documented error offsets (see LSL Wiki)
8256 lower = new LSL_Vector(minX + 0.05f, minY + 0.05f, minZ + 0.05f);
8257 upper = new LSL_Vector(maxX - 0.05f, maxY - 0.05f, maxZ - 0.05f);
8258
8259 if (lower.x > upper.x)
8260 lower.x = upper.x;
8261 if (lower.y > upper.y)
8262 lower.y = upper.y;
8263 if (lower.z > upper.z)
8264 lower.z = upper.z;
8265
7684 result.Add(lower); 8266 result.Add(lower);
7685 result.Add(upper); 8267 result.Add(upper);
7686 return result; 8268 return result;
@@ -7760,13 +8342,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7760 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X, 8342 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
7761 part.AbsolutePosition.Y, 8343 part.AbsolutePosition.Y,
7762 part.AbsolutePosition.Z); 8344 part.AbsolutePosition.Z);
7763 // For some reason, the part.AbsolutePosition.* values do not change if the
7764 // linkset is rotated; they always reflect the child prim's world position
7765 // as though the linkset is unrotated. This is incompatible behavior with SL's
7766 // implementation, so will break scripts imported from there (not to mention it
7767 // makes it more difficult to determine a child prim's actual inworld position).
7768 if (part.ParentID != 0)
7769 v = ((v - llGetRootPosition()) * llGetRootRotation()) + llGetRootPosition();
7770 res.Add(v); 8345 res.Add(v);
7771 break; 8346 break;
7772 8347
@@ -7937,56 +8512,92 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7937 case (int)ScriptBaseClass.PRIM_BUMP_SHINY: 8512 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
7938 if (remain < 1) 8513 if (remain < 1)
7939 return res; 8514 return res;
7940 8515 face = (int)rules.GetLSLIntegerItem(idx++);
7941 face=(int)rules.GetLSLIntegerItem(idx++);
7942 8516
7943 tex = part.Shape.Textures; 8517 tex = part.Shape.Textures;
8518 int shiny;
7944 if (face == ScriptBaseClass.ALL_SIDES) 8519 if (face == ScriptBaseClass.ALL_SIDES)
7945 { 8520 {
7946 for (face = 0; face < GetNumberOfSides(part); face++) 8521 for (face = 0; face < GetNumberOfSides(part); face++)
7947 { 8522 {
7948 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8523 Shininess shinyness = tex.GetFace((uint)face).Shiny;
7949 // Convert Shininess to PRIM_SHINY_* 8524 if (shinyness == Shininess.High)
7950 res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); 8525 {
7951 // PRIM_BUMP_* 8526 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
7952 res.Add(new LSL_Integer((int)texface.Bump)); 8527 }
8528 else if (shinyness == Shininess.Medium)
8529 {
8530 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8531 }
8532 else if (shinyness == Shininess.Low)
8533 {
8534 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8535 }
8536 else
8537 {
8538 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8539 }
8540 res.Add(new LSL_Integer(shiny));
8541 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
7953 } 8542 }
7954 } 8543 }
7955 else 8544 else
7956 { 8545 {
7957 if (face >= 0 && face < GetNumberOfSides(part)) 8546 Shininess shinyness = tex.GetFace((uint)face).Shiny;
8547 if (shinyness == Shininess.High)
7958 { 8548 {
7959 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8549 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
7960 // Convert Shininess to PRIM_SHINY_*
7961 res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
7962 // PRIM_BUMP_*
7963 res.Add(new LSL_Integer((int)texface.Bump));
7964 } 8550 }
8551 else if (shinyness == Shininess.Medium)
8552 {
8553 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8554 }
8555 else if (shinyness == Shininess.Low)
8556 {
8557 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8558 }
8559 else
8560 {
8561 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8562 }
8563 res.Add(new LSL_Integer(shiny));
8564 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
7965 } 8565 }
7966 break; 8566 break;
7967 8567
7968 case (int)ScriptBaseClass.PRIM_FULLBRIGHT: 8568 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
7969 if (remain < 1) 8569 if (remain < 1)
7970 return res; 8570 return res;
7971 8571 face = (int)rules.GetLSLIntegerItem(idx++);
7972 face=(int)rules.GetLSLIntegerItem(idx++);
7973 8572
7974 tex = part.Shape.Textures; 8573 tex = part.Shape.Textures;
8574 int fullbright;
7975 if (face == ScriptBaseClass.ALL_SIDES) 8575 if (face == ScriptBaseClass.ALL_SIDES)
7976 { 8576 {
7977 for (face = 0; face < GetNumberOfSides(part); face++) 8577 for (face = 0; face < GetNumberOfSides(part); face++)
7978 { 8578 {
7979 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8579 if (tex.GetFace((uint)face).Fullbright == true)
7980 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); 8580 {
8581 fullbright = ScriptBaseClass.TRUE;
8582 }
8583 else
8584 {
8585 fullbright = ScriptBaseClass.FALSE;
8586 }
8587 res.Add(new LSL_Integer(fullbright));
7981 } 8588 }
7982 } 8589 }
7983 else 8590 else
7984 { 8591 {
7985 if (face >= 0 && face < GetNumberOfSides(part)) 8592 if (tex.GetFace((uint)face).Fullbright == true)
7986 { 8593 {
7987 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8594 fullbright = ScriptBaseClass.TRUE;
7988 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); 8595 }
8596 else
8597 {
8598 fullbright = ScriptBaseClass.FALSE;
7989 } 8599 }
8600 res.Add(new LSL_Integer(fullbright));
7990 } 8601 }
7991 break; 8602 break;
7992 8603
@@ -8008,27 +8619,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8008 break; 8619 break;
8009 8620
8010 case (int)ScriptBaseClass.PRIM_TEXGEN: 8621 case (int)ScriptBaseClass.PRIM_TEXGEN:
8622 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
8011 if (remain < 1) 8623 if (remain < 1)
8012 return res; 8624 return res;
8013 8625 face = (int)rules.GetLSLIntegerItem(idx++);
8014 face=(int)rules.GetLSLIntegerItem(idx++);
8015 8626
8016 tex = part.Shape.Textures; 8627 tex = part.Shape.Textures;
8017 if (face == ScriptBaseClass.ALL_SIDES) 8628 if (face == ScriptBaseClass.ALL_SIDES)
8018 { 8629 {
8019 for (face = 0; face < GetNumberOfSides(part); face++) 8630 for (face = 0; face < GetNumberOfSides(part); face++)
8020 { 8631 {
8021 MappingType texgen = tex.GetFace((uint)face).TexMapType; 8632 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8022 // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc. 8633 {
8023 res.Add(new LSL_Integer((uint)texgen >> 1)); 8634 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8635 }
8636 else
8637 {
8638 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8639 }
8024 } 8640 }
8025 } 8641 }
8026 else 8642 else
8027 { 8643 {
8028 if (face >= 0 && face < GetNumberOfSides(part)) 8644 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8645 {
8646 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8647 }
8648 else
8029 { 8649 {
8030 MappingType texgen = tex.GetFace((uint)face).TexMapType; 8650 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8031 res.Add(new LSL_Integer((uint)texgen >> 1));
8032 } 8651 }
8033 } 8652 }
8034 break; 8653 break;
@@ -8051,28 +8670,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8051 case (int)ScriptBaseClass.PRIM_GLOW: 8670 case (int)ScriptBaseClass.PRIM_GLOW:
8052 if (remain < 1) 8671 if (remain < 1)
8053 return res; 8672 return res;
8054 8673 face = (int)rules.GetLSLIntegerItem(idx++);
8055 face=(int)rules.GetLSLIntegerItem(idx++);
8056 8674
8057 tex = part.Shape.Textures; 8675 tex = part.Shape.Textures;
8676 float primglow;
8058 if (face == ScriptBaseClass.ALL_SIDES) 8677 if (face == ScriptBaseClass.ALL_SIDES)
8059 { 8678 {
8060 for (face = 0; face < GetNumberOfSides(part); face++) 8679 for (face = 0; face < GetNumberOfSides(part); face++)
8061 { 8680 {
8062 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8681 primglow = tex.GetFace((uint)face).Glow;
8063 res.Add(new LSL_Float(texface.Glow)); 8682 res.Add(new LSL_Float(primglow));
8064 } 8683 }
8065 } 8684 }
8066 else 8685 else
8067 { 8686 {
8068 if (face >= 0 && face < GetNumberOfSides(part)) 8687 primglow = tex.GetFace((uint)face).Glow;
8069 { 8688 res.Add(new LSL_Float(primglow));
8070 Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
8071 res.Add(new LSL_Float(texface.Glow));
8072 }
8073 } 8689 }
8074 break; 8690 break;
8075
8076 case (int)ScriptBaseClass.PRIM_TEXT: 8691 case (int)ScriptBaseClass.PRIM_TEXT:
8077 Color4 textColor = part.GetTextColor(); 8692 Color4 textColor = part.GetTextColor();
8078 res.Add(new LSL_String(part.Text)); 8693 res.Add(new LSL_String(part.Text));
@@ -8624,8 +9239,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8624 // The function returns an ordered list 9239 // The function returns an ordered list
8625 // representing the tokens found in the supplied 9240 // representing the tokens found in the supplied
8626 // sources string. If two successive tokenizers 9241 // sources string. If two successive tokenizers
8627 // are encountered, then a NULL entry is added 9242 // are encountered, then a null-string entry is
8628 // to the list. 9243 // added to the list.
8629 // 9244 //
8630 // It is a precondition that the source and 9245 // It is a precondition that the source and
8631 // toekizer lisst are non-null. If they are null, 9246 // toekizer lisst are non-null. If they are null,
@@ -8633,7 +9248,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8633 // while their lengths are being determined. 9248 // while their lengths are being determined.
8634 // 9249 //
8635 // A small amount of working memoryis required 9250 // A small amount of working memoryis required
8636 // of approximately 8*#tokenizers. 9251 // of approximately 8*#tokenizers + 8*srcstrlen.
8637 // 9252 //
8638 // There are many ways in which this function 9253 // There are many ways in which this function
8639 // can be implemented, this implementation is 9254 // can be implemented, this implementation is
@@ -8649,155 +9264,124 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8649 // and eliminates redundant tokenizers as soon 9264 // and eliminates redundant tokenizers as soon
8650 // as is possible. 9265 // as is possible.
8651 // 9266 //
8652 // The implementation tries to avoid any copying 9267 // The implementation tries to minimize temporary
8653 // of arrays or other objects. 9268 // garbage generation.
8654 // </remarks> 9269 // </remarks>
8655 9270
8656 private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls) 9271 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
8657 { 9272 {
8658 int beginning = 0; 9273 return ParseString2List(src, separators, spacers, true);
8659 int srclen = src.Length; 9274 }
8660 int seplen = separators.Length;
8661 object[] separray = separators.Data;
8662 int spclen = spacers.Length;
8663 object[] spcarray = spacers.Data;
8664 int mlen = seplen+spclen;
8665
8666 int[] offset = new int[mlen+1];
8667 bool[] active = new bool[mlen];
8668
8669 int best;
8670 int j;
8671
8672 // Initial capacity reduces resize cost
8673 9275
8674 LSL_List tokens = new LSL_List(); 9276 private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
9277 {
9278 int srclen = src.Length;
9279 int seplen = separators.Length;
9280 object[] separray = separators.Data;
9281 int spclen = spacers.Length;
9282 object[] spcarray = spacers.Data;
9283 int dellen = 0;
9284 string[] delarray = new string[seplen+spclen];
8675 9285
8676 // All entries are initially valid 9286 int outlen = 0;
9287 string[] outarray = new string[srclen*2+1];
8677 9288
8678 for (int i = 0; i < mlen; i++) 9289 int i, j;
8679 active[i] = true; 9290 string d;
8680 9291
8681 offset[mlen] = srclen; 9292 m_host.AddScriptLPS(1);
8682 9293
8683 while (beginning < srclen) 9294 /*
9295 * Convert separator and spacer lists to C# strings.
9296 * Also filter out null strings so we don't hang.
9297 */
9298 for (i = 0; i < seplen; i ++)
8684 { 9299 {
9300 d = separray[i].ToString();
9301 if (d.Length > 0)
9302 {
9303 delarray[dellen++] = d;
9304 }
9305 }
9306 seplen = dellen;
8685 9307
8686 best = mlen; // as bad as it gets 9308 for (i = 0; i < spclen; i ++)
9309 {
9310 d = spcarray[i].ToString();
9311 if (d.Length > 0)
9312 {
9313 delarray[dellen++] = d;
9314 }
9315 }
8687 9316
8688 // Scan for separators 9317 /*
9318 * Scan through source string from beginning to end.
9319 */
9320 for (i = 0;;)
9321 {
8689 9322
8690 for (j = 0; j < seplen; j++) 9323 /*
9324 * Find earliest delimeter in src starting at i (if any).
9325 */
9326 int earliestDel = -1;
9327 int earliestSrc = srclen;
9328 string earliestStr = null;
9329 for (j = 0; j < dellen; j ++)
8691 { 9330 {
8692 if (separray[j].ToString() == String.Empty) 9331 d = delarray[j];
8693 active[j] = false; 9332 if (d != null)
8694
8695 if (active[j])
8696 { 9333 {
8697 // scan all of the markers 9334 int index = src.IndexOf(d, i);
8698 if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1) 9335 if (index < 0)
8699 { 9336 {
8700 // not present at all 9337 delarray[j] = null; // delim nowhere in src, don't check it anymore
8701 active[j] = false;
8702 } 9338 }
8703 else 9339 else if (index < earliestSrc)
8704 { 9340 {
8705 // present and correct 9341 earliestSrc = index; // where delimeter starts in source string
8706 if (offset[j] < offset[best]) 9342 earliestDel = j; // where delimeter is in delarray[]
8707 { 9343 earliestStr = d; // the delimeter string from delarray[]
8708 // closest so far 9344 if (index == i) break; // can't do any better than found at beg of string
8709 best = j;
8710 if (offset[best] == beginning)
8711 break;
8712 }
8713 } 9345 }
8714 } 9346 }
8715 } 9347 }
8716 9348
8717 // Scan for spacers 9349 /*
8718 9350 * Output source string starting at i through start of earliest delimeter.
8719 if (offset[best] != beginning) 9351 */
9352 if (keepNulls || (earliestSrc > i))
8720 { 9353 {
8721 for (j = seplen; (j < mlen) && (offset[best] > beginning); j++) 9354 outarray[outlen++] = src.Substring(i, earliestSrc - i);
8722 {
8723 if (spcarray[j-seplen].ToString() == String.Empty)
8724 active[j] = false;
8725
8726 if (active[j])
8727 {
8728 // scan all of the markers
8729 if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
8730 {
8731 // not present at all
8732 active[j] = false;
8733 }
8734 else
8735 {
8736 // present and correct
8737 if (offset[j] < offset[best])
8738 {
8739 // closest so far
8740 best = j;
8741 }
8742 }
8743 }
8744 }
8745 } 9355 }
8746 9356
8747 // This is the normal exit from the scanning loop 9357 /*
9358 * If no delimeter found at or after i, we're done scanning.
9359 */
9360 if (earliestDel < 0) break;
8748 9361
8749 if (best == mlen) 9362 /*
9363 * If delimeter was a spacer, output the spacer.
9364 */
9365 if (earliestDel >= seplen)
8750 { 9366 {
8751 // no markers were found on this pass 9367 outarray[outlen++] = earliestStr;
8752 // so we're pretty much done
8753 if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0))
8754 tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
8755 break;
8756 } 9368 }
8757 9369
8758 // Otherwise we just add the newly delimited token 9370 /*
8759 // and recalculate where the search should continue. 9371 * Look at rest of src string following delimeter.
8760 if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0)) 9372 */
8761 tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning))); 9373 i = earliestSrc + earliestStr.Length;
8762
8763 if (best < seplen)
8764 {
8765 beginning = offset[best] + (separray[best].ToString()).Length;
8766 }
8767 else
8768 {
8769 beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
8770 string str = spcarray[best - seplen].ToString();
8771 if ((keepNulls) || ((!keepNulls) && (str.Length > 0)))
8772 tokens.Add(new LSL_String(str));
8773 }
8774 } 9374 }
8775 9375
8776 // This an awkward an not very intuitive boundary case. If the 9376 /*
8777 // last substring is a tokenizer, then there is an implied trailing 9377 * Make up an exact-sized output array suitable for an LSL_List object.
8778 // null list entry. Hopefully the single comparison will not be too 9378 */
8779 // arduous. Alternatively the 'break' could be replced with a return 9379 object[] outlist = new object[outlen];
8780 // but that's shabby programming. 9380 for (i = 0; i < outlen; i ++)
8781
8782 if ((beginning == srclen) && (keepNulls))
8783 { 9381 {
8784 if (srclen != 0) 9382 outlist[i] = new LSL_String(outarray[i]);
8785 tokens.Add(new LSL_String(""));
8786 } 9383 }
8787 9384 return new LSL_List(outlist);
8788 return tokens;
8789 }
8790
8791 public LSL_List llParseString2List(string src, LSL_List separators, LSL_List spacers)
8792 {
8793 m_host.AddScriptLPS(1);
8794 return this.ParseString(src, separators, spacers, false);
8795 }
8796
8797 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
8798 {
8799 m_host.AddScriptLPS(1);
8800 return this.ParseString(src, separators, spacers, true);
8801 } 9385 }
8802 9386
8803 public LSL_Integer llGetObjectPermMask(int mask) 9387 public LSL_Integer llGetObjectPermMask(int mask)
@@ -8874,28 +9458,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8874 { 9458 {
8875 m_host.AddScriptLPS(1); 9459 m_host.AddScriptLPS(1);
8876 9460
8877 lock (m_host.TaskInventory) 9461 m_host.TaskInventory.LockItemsForRead(true);
9462 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8878 { 9463 {
8879 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9464 if (inv.Value.Name == item)
8880 { 9465 {
8881 if (inv.Value.Name == item) 9466 m_host.TaskInventory.LockItemsForRead(false);
9467 switch (mask)
8882 { 9468 {
8883 switch (mask) 9469 case 0:
8884 { 9470 return (int)inv.Value.BasePermissions;
8885 case 0: 9471 case 1:
8886 return (int)inv.Value.BasePermissions; 9472 return (int)inv.Value.CurrentPermissions;
8887 case 1: 9473 case 2:
8888 return (int)inv.Value.CurrentPermissions; 9474 return (int)inv.Value.GroupPermissions;
8889 case 2: 9475 case 3:
8890 return (int)inv.Value.GroupPermissions; 9476 return (int)inv.Value.EveryonePermissions;
8891 case 3: 9477 case 4:
8892 return (int)inv.Value.EveryonePermissions; 9478 return (int)inv.Value.NextPermissions;
8893 case 4:
8894 return (int)inv.Value.NextPermissions;
8895 }
8896 } 9479 }
8897 } 9480 }
8898 } 9481 }
9482 m_host.TaskInventory.LockItemsForRead(false);
8899 9483
8900 return -1; 9484 return -1;
8901 } 9485 }
@@ -8942,16 +9526,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8942 { 9526 {
8943 m_host.AddScriptLPS(1); 9527 m_host.AddScriptLPS(1);
8944 9528
8945 lock (m_host.TaskInventory) 9529 m_host.TaskInventory.LockItemsForRead(true);
9530 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
8946 { 9531 {
8947 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9532 if (inv.Value.Name == item)
8948 { 9533 {
8949 if (inv.Value.Name == item) 9534 m_host.TaskInventory.LockItemsForRead(false);
8950 { 9535 return inv.Value.CreatorID.ToString();
8951 return inv.Value.CreatorID.ToString();
8952 }
8953 } 9536 }
8954 } 9537 }
9538 m_host.TaskInventory.LockItemsForRead(false);
8955 9539
8956 llSay(0, "No item name '" + item + "'"); 9540 llSay(0, "No item name '" + item + "'");
8957 9541
@@ -9099,7 +9683,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9099 } 9683 }
9100 9684
9101 /// <summary> 9685 /// <summary>
9102 /// illListReplaceList removes the sub-list defined by the inclusive indices 9686 /// llListReplaceList removes the sub-list defined by the inclusive indices
9103 /// start and end and inserts the src list in its place. The inclusive 9687 /// start and end and inserts the src list in its place. The inclusive
9104 /// nature of the indices means that at least one element must be deleted 9688 /// nature of the indices means that at least one element must be deleted
9105 /// if the indices are within the bounds of the existing list. I.e. 2,2 9689 /// if the indices are within the bounds of the existing list. I.e. 2,2
@@ -9156,16 +9740,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9156 // based upon end. Note that if end exceeds the upper 9740 // based upon end. Note that if end exceeds the upper
9157 // bound in this case, the entire destination list 9741 // bound in this case, the entire destination list
9158 // is removed. 9742 // is removed.
9159 else 9743 else if (start == 0)
9160 { 9744 {
9161 if (end + 1 < dest.Length) 9745 if (end + 1 < dest.Length)
9162 {
9163 return src + dest.GetSublist(end + 1, -1); 9746 return src + dest.GetSublist(end + 1, -1);
9164 }
9165 else 9747 else
9166 {
9167 return src; 9748 return src;
9168 } 9749 }
9750 else // Start < 0
9751 {
9752 if (end + 1 < dest.Length)
9753 return dest.GetSublist(end + 1, -1);
9754 else
9755 return new LSL_List();
9169 } 9756 }
9170 } 9757 }
9171 // Finally, if start > end, we strip away a prefix and 9758 // Finally, if start > end, we strip away a prefix and
@@ -9216,17 +9803,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9216 int width = 0; 9803 int width = 0;
9217 int height = 0; 9804 int height = 0;
9218 9805
9219 ParcelMediaCommandEnum? commandToSend = null; 9806 uint commandToSend = 0;
9220 float time = 0.0f; // default is from start 9807 float time = 0.0f; // default is from start
9221 9808
9222 ScenePresence presence = null; 9809 ScenePresence presence = null;
9223 9810
9224 for (int i = 0; i < commandList.Data.Length; i++) 9811 for (int i = 0; i < commandList.Data.Length; i++)
9225 { 9812 {
9226 ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i]; 9813 uint command = (uint)(commandList.GetLSLIntegerItem(i));
9227 switch (command) 9814 switch (command)
9228 { 9815 {
9229 case ParcelMediaCommandEnum.Agent: 9816 case (uint)ParcelMediaCommandEnum.Agent:
9230 // we send only to one agent 9817 // we send only to one agent
9231 if ((i + 1) < commandList.Length) 9818 if ((i + 1) < commandList.Length)
9232 { 9819 {
@@ -9243,25 +9830,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9243 } 9830 }
9244 break; 9831 break;
9245 9832
9246 case ParcelMediaCommandEnum.Loop: 9833 case (uint)ParcelMediaCommandEnum.Loop:
9247 loop = 1; 9834 loop = 1;
9248 commandToSend = command; 9835 commandToSend = command;
9249 update = true; //need to send the media update packet to set looping 9836 update = true; //need to send the media update packet to set looping
9250 break; 9837 break;
9251 9838
9252 case ParcelMediaCommandEnum.Play: 9839 case (uint)ParcelMediaCommandEnum.Play:
9253 loop = 0; 9840 loop = 0;
9254 commandToSend = command; 9841 commandToSend = command;
9255 update = true; //need to send the media update packet to make sure it doesn't loop 9842 update = true; //need to send the media update packet to make sure it doesn't loop
9256 break; 9843 break;
9257 9844
9258 case ParcelMediaCommandEnum.Pause: 9845 case (uint)ParcelMediaCommandEnum.Pause:
9259 case ParcelMediaCommandEnum.Stop: 9846 case (uint)ParcelMediaCommandEnum.Stop:
9260 case ParcelMediaCommandEnum.Unload: 9847 case (uint)ParcelMediaCommandEnum.Unload:
9261 commandToSend = command; 9848 commandToSend = command;
9262 break; 9849 break;
9263 9850
9264 case ParcelMediaCommandEnum.Url: 9851 case (uint)ParcelMediaCommandEnum.Url:
9265 if ((i + 1) < commandList.Length) 9852 if ((i + 1) < commandList.Length)
9266 { 9853 {
9267 if (commandList.Data[i + 1] is LSL_String) 9854 if (commandList.Data[i + 1] is LSL_String)
@@ -9274,7 +9861,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9274 } 9861 }
9275 break; 9862 break;
9276 9863
9277 case ParcelMediaCommandEnum.Texture: 9864 case (uint)ParcelMediaCommandEnum.Texture:
9278 if ((i + 1) < commandList.Length) 9865 if ((i + 1) < commandList.Length)
9279 { 9866 {
9280 if (commandList.Data[i + 1] is LSL_String) 9867 if (commandList.Data[i + 1] is LSL_String)
@@ -9287,7 +9874,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9287 } 9874 }
9288 break; 9875 break;
9289 9876
9290 case ParcelMediaCommandEnum.Time: 9877 case (uint)ParcelMediaCommandEnum.Time:
9291 if ((i + 1) < commandList.Length) 9878 if ((i + 1) < commandList.Length)
9292 { 9879 {
9293 if (commandList.Data[i + 1] is LSL_Float) 9880 if (commandList.Data[i + 1] is LSL_Float)
@@ -9299,7 +9886,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9299 } 9886 }
9300 break; 9887 break;
9301 9888
9302 case ParcelMediaCommandEnum.AutoAlign: 9889 case (uint)ParcelMediaCommandEnum.AutoAlign:
9303 if ((i + 1) < commandList.Length) 9890 if ((i + 1) < commandList.Length)
9304 { 9891 {
9305 if (commandList.Data[i + 1] is LSL_Integer) 9892 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9313,7 +9900,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9313 } 9900 }
9314 break; 9901 break;
9315 9902
9316 case ParcelMediaCommandEnum.Type: 9903 case (uint)ParcelMediaCommandEnum.Type:
9317 if ((i + 1) < commandList.Length) 9904 if ((i + 1) < commandList.Length)
9318 { 9905 {
9319 if (commandList.Data[i + 1] is LSL_String) 9906 if (commandList.Data[i + 1] is LSL_String)
@@ -9326,7 +9913,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9326 } 9913 }
9327 break; 9914 break;
9328 9915
9329 case ParcelMediaCommandEnum.Desc: 9916 case (uint)ParcelMediaCommandEnum.Desc:
9330 if ((i + 1) < commandList.Length) 9917 if ((i + 1) < commandList.Length)
9331 { 9918 {
9332 if (commandList.Data[i + 1] is LSL_String) 9919 if (commandList.Data[i + 1] is LSL_String)
@@ -9339,7 +9926,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9339 } 9926 }
9340 break; 9927 break;
9341 9928
9342 case ParcelMediaCommandEnum.Size: 9929 case (uint)ParcelMediaCommandEnum.Size:
9343 if ((i + 2) < commandList.Length) 9930 if ((i + 2) < commandList.Length)
9344 { 9931 {
9345 if (commandList.Data[i + 1] is LSL_Integer) 9932 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9409,7 +9996,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9409 } 9996 }
9410 } 9997 }
9411 9998
9412 if (commandToSend != null) 9999 if (commandToSend != 0)
9413 { 10000 {
9414 // the commandList contained a start/stop/... command, too 10001 // the commandList contained a start/stop/... command, too
9415 if (presence == null) 10002 if (presence == null)
@@ -9446,7 +10033,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9446 10033
9447 if (aList.Data[i] != null) 10034 if (aList.Data[i] != null)
9448 { 10035 {
9449 switch ((ParcelMediaCommandEnum) aList.Data[i]) 10036 switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
9450 { 10037 {
9451 case ParcelMediaCommandEnum.Url: 10038 case ParcelMediaCommandEnum.Url:
9452 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL)); 10039 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL));
@@ -9489,16 +10076,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9489 { 10076 {
9490 m_host.AddScriptLPS(1); 10077 m_host.AddScriptLPS(1);
9491 10078
9492 lock (m_host.TaskInventory) 10079 m_host.TaskInventory.LockItemsForRead(true);
10080 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
9493 { 10081 {
9494 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 10082 if (inv.Value.Name == name)
9495 { 10083 {
9496 if (inv.Value.Name == name) 10084 m_host.TaskInventory.LockItemsForRead(false);
9497 { 10085 return inv.Value.Type;
9498 return inv.Value.Type;
9499 }
9500 } 10086 }
9501 } 10087 }
10088 m_host.TaskInventory.LockItemsForRead(false);
9502 10089
9503 return -1; 10090 return -1;
9504 } 10091 }
@@ -9509,15 +10096,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9509 10096
9510 if (quick_pay_buttons.Data.Length < 4) 10097 if (quick_pay_buttons.Data.Length < 4)
9511 { 10098 {
9512 LSLError("List must have at least 4 elements"); 10099 int x;
9513 return; 10100 for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
10101 {
10102 quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
10103 }
9514 } 10104 }
9515 m_host.ParentGroup.RootPart.PayPrice[0]=price; 10105 int[] nPrice = new int[5];
9516 10106 nPrice[0] = price;
9517 m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0]; 10107 nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
9518 m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1]; 10108 nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
9519 m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2]; 10109 nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
9520 m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3]; 10110 nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
10111 m_host.ParentGroup.RootPart.PayPrice = nPrice;
9521 m_host.ParentGroup.HasGroupChanged = true; 10112 m_host.ParentGroup.HasGroupChanged = true;
9522 } 10113 }
9523 10114
@@ -9529,17 +10120,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9529 if (invItemID == UUID.Zero) 10120 if (invItemID == UUID.Zero)
9530 return new LSL_Vector(); 10121 return new LSL_Vector();
9531 10122
9532 lock (m_host.TaskInventory) 10123 m_host.TaskInventory.LockItemsForRead(true);
10124 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
9533 { 10125 {
9534 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10126 m_host.TaskInventory.LockItemsForRead(false);
9535 return new LSL_Vector(); 10127 return new LSL_Vector();
10128 }
9536 10129
9537 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) 10130 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9538 { 10131 {
9539 ShoutError("No permissions to track the camera"); 10132 ShoutError("No permissions to track the camera");
9540 return new LSL_Vector(); 10133 m_host.TaskInventory.LockItemsForRead(false);
9541 } 10134 return new LSL_Vector();
9542 } 10135 }
10136 m_host.TaskInventory.LockItemsForRead(false);
9543 10137
9544 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10138 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
9545 if (presence != null) 10139 if (presence != null)
@@ -9557,17 +10151,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9557 if (invItemID == UUID.Zero) 10151 if (invItemID == UUID.Zero)
9558 return new LSL_Rotation(); 10152 return new LSL_Rotation();
9559 10153
9560 lock (m_host.TaskInventory) 10154 m_host.TaskInventory.LockItemsForRead(true);
10155 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
9561 { 10156 {
9562 if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero) 10157 m_host.TaskInventory.LockItemsForRead(false);
9563 return new LSL_Rotation(); 10158 return new LSL_Rotation();
9564
9565 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
9566 {
9567 ShoutError("No permissions to track the camera");
9568 return new LSL_Rotation();
9569 }
9570 } 10159 }
10160 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
10161 {
10162 ShoutError("No permissions to track the camera");
10163 m_host.TaskInventory.LockItemsForRead(false);
10164 return new LSL_Rotation();
10165 }
10166 m_host.TaskInventory.LockItemsForRead(false);
9571 10167
9572 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10168 ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
9573 if (presence != null) 10169 if (presence != null)
@@ -9629,8 +10225,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9629 { 10225 {
9630 m_host.AddScriptLPS(1); 10226 m_host.AddScriptLPS(1);
9631 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0); 10227 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_itemID, 0);
9632 if (detectedParams == null) return; // only works on the first detected avatar 10228 if (detectedParams == null)
9633 10229 {
10230 if (m_host.ParentGroup.IsAttachment == true)
10231 {
10232 detectedParams = new DetectParams();
10233 detectedParams.Key = m_host.OwnerID;
10234 }
10235 else
10236 {
10237 return;
10238 }
10239 }
10240
9634 ScenePresence avatar = World.GetScenePresence(detectedParams.Key); 10241 ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
9635 if (avatar != null) 10242 if (avatar != null)
9636 { 10243 {
@@ -9638,6 +10245,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9638 new Vector3((float)pos.x, (float)pos.y, (float)pos.z), 10245 new Vector3((float)pos.x, (float)pos.y, (float)pos.z),
9639 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z)); 10246 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z));
9640 } 10247 }
10248
9641 ScriptSleep(1000); 10249 ScriptSleep(1000);
9642 } 10250 }
9643 10251
@@ -9730,14 +10338,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9730 if (objectID == UUID.Zero) return; 10338 if (objectID == UUID.Zero) return;
9731 10339
9732 UUID agentID; 10340 UUID agentID;
9733 lock (m_host.TaskInventory) 10341 m_host.TaskInventory.LockItemsForRead(true);
9734 { 10342 // we need the permission first, to know which avatar we want to set the camera for
9735 // we need the permission first, to know which avatar we want to set the camera for 10343 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9736 agentID = m_host.TaskInventory[invItemID].PermsGranter;
9737 10344
9738 if (agentID == UUID.Zero) return; 10345 if (agentID == UUID.Zero)
9739 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 10346 {
10347 m_host.TaskInventory.LockItemsForRead(false);
10348 return;
10349 }
10350 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
10351 {
10352 m_host.TaskInventory.LockItemsForRead(false);
10353 return;
9740 } 10354 }
10355 m_host.TaskInventory.LockItemsForRead(false);
9741 10356
9742 ScenePresence presence = World.GetScenePresence(agentID); 10357 ScenePresence presence = World.GetScenePresence(agentID);
9743 10358
@@ -9746,12 +10361,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9746 10361
9747 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>(); 10362 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
9748 object[] data = rules.Data; 10363 object[] data = rules.Data;
9749 for (int i = 0; i < data.Length; ++i) { 10364 for (int i = 0; i < data.Length; ++i)
10365 {
9750 int type = Convert.ToInt32(data[i++].ToString()); 10366 int type = Convert.ToInt32(data[i++].ToString());
9751 if (i >= data.Length) break; // odd number of entries => ignore the last 10367 if (i >= data.Length) break; // odd number of entries => ignore the last
9752 10368
9753 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3) 10369 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
9754 switch (type) { 10370 switch (type)
10371 {
9755 case ScriptBaseClass.CAMERA_FOCUS: 10372 case ScriptBaseClass.CAMERA_FOCUS:
9756 case ScriptBaseClass.CAMERA_FOCUS_OFFSET: 10373 case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
9757 case ScriptBaseClass.CAMERA_POSITION: 10374 case ScriptBaseClass.CAMERA_POSITION:
@@ -9787,12 +10404,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9787 10404
9788 // we need the permission first, to know which avatar we want to clear the camera for 10405 // we need the permission first, to know which avatar we want to clear the camera for
9789 UUID agentID; 10406 UUID agentID;
9790 lock (m_host.TaskInventory) 10407 m_host.TaskInventory.LockItemsForRead(true);
10408 agentID = m_host.TaskInventory[invItemID].PermsGranter;
10409 if (agentID == UUID.Zero)
9791 { 10410 {
9792 agentID = m_host.TaskInventory[invItemID].PermsGranter; 10411 m_host.TaskInventory.LockItemsForRead(false);
9793 if (agentID == UUID.Zero) return; 10412 return;
9794 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; 10413 }
10414 if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
10415 {
10416 m_host.TaskInventory.LockItemsForRead(false);
10417 return;
9795 } 10418 }
10419 m_host.TaskInventory.LockItemsForRead(false);
9796 10420
9797 ScenePresence presence = World.GetScenePresence(agentID); 10421 ScenePresence presence = World.GetScenePresence(agentID);
9798 10422
@@ -9859,19 +10483,65 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9859 public LSL_String llXorBase64StringsCorrect(string str1, string str2) 10483 public LSL_String llXorBase64StringsCorrect(string str1, string str2)
9860 { 10484 {
9861 m_host.AddScriptLPS(1); 10485 m_host.AddScriptLPS(1);
9862 string ret = String.Empty; 10486
9863 string src1 = llBase64ToString(str1); 10487 if (str1 == String.Empty)
9864 string src2 = llBase64ToString(str2); 10488 return String.Empty;
9865 int c = 0; 10489 if (str2 == String.Empty)
9866 for (int i = 0; i < src1.Length; i++) 10490 return str1;
10491
10492 int len = str2.Length;
10493 if ((len % 4) != 0) // LL is EVIL!!!!
9867 { 10494 {
9868 ret += (char) (src1[i] ^ src2[c]); 10495 while (str2.EndsWith("="))
10496 str2 = str2.Substring(0, str2.Length - 1);
10497
10498 len = str2.Length;
10499 int mod = len % 4;
10500
10501 if (mod == 1)
10502 str2 = str2.Substring(0, str2.Length - 1);
10503 else if (mod == 2)
10504 str2 += "==";
10505 else if (mod == 3)
10506 str2 += "=";
10507 }
9869 10508
9870 c++; 10509 byte[] data1;
9871 if (c >= src2.Length) 10510 byte[] data2;
9872 c = 0; 10511 try
10512 {
10513 data1 = Convert.FromBase64String(str1);
10514 data2 = Convert.FromBase64String(str2);
10515 }
10516 catch (Exception)
10517 {
10518 return new LSL_String(String.Empty);
10519 }
10520
10521 byte[] d2 = new Byte[data1.Length];
10522 int pos = 0;
10523
10524 if (data1.Length <= data2.Length)
10525 {
10526 Array.Copy(data2, 0, d2, 0, data1.Length);
10527 }
10528 else
10529 {
10530 while (pos < data1.Length)
10531 {
10532 len = data1.Length - pos;
10533 if (len > data2.Length)
10534 len = data2.Length;
10535
10536 Array.Copy(data2, 0, d2, pos, len);
10537 pos += len;
10538 }
9873 } 10539 }
9874 return llStringToBase64(ret); 10540
10541 for (pos = 0 ; pos < data1.Length ; pos++ )
10542 data1[pos] ^= d2[pos];
10543
10544 return Convert.ToBase64String(data1);
9875 } 10545 }
9876 10546
9877 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body) 10547 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
@@ -9928,12 +10598,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9928 Regex r = new Regex(authregex); 10598 Regex r = new Regex(authregex);
9929 int[] gnums = r.GetGroupNumbers(); 10599 int[] gnums = r.GetGroupNumbers();
9930 Match m = r.Match(url); 10600 Match m = r.Match(url);
9931 if (m.Success) { 10601 if (m.Success)
9932 for (int i = 1; i < gnums.Length; i++) { 10602 {
10603 for (int i = 1; i < gnums.Length; i++)
10604 {
9933 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]]; 10605 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
9934 //CaptureCollection cc = g.Captures; 10606 //CaptureCollection cc = g.Captures;
9935 } 10607 }
9936 if (m.Groups.Count == 5) { 10608 if (m.Groups.Count == 5)
10609 {
9937 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString()))); 10610 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
9938 url = m.Groups[1].ToString() + m.Groups[4].ToString(); 10611 url = m.Groups[1].ToString() + m.Groups[4].ToString();
9939 } 10612 }
@@ -10219,15 +10892,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10219 10892
10220 internal UUID ScriptByName(string name) 10893 internal UUID ScriptByName(string name)
10221 { 10894 {
10222 lock (m_host.TaskInventory) 10895 m_host.TaskInventory.LockItemsForRead(true);
10896
10897 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
10223 { 10898 {
10224 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 10899 if (item.Type == 10 && item.Name == name)
10225 { 10900 {
10226 if (item.Type == 10 && item.Name == name) 10901 m_host.TaskInventory.LockItemsForRead(false);
10227 return item.ItemID; 10902 return item.ItemID;
10228 } 10903 }
10229 } 10904 }
10230 10905
10906 m_host.TaskInventory.LockItemsForRead(false);
10907
10231 return UUID.Zero; 10908 return UUID.Zero;
10232 } 10909 }
10233 10910
@@ -10268,6 +10945,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10268 { 10945 {
10269 m_host.AddScriptLPS(1); 10946 m_host.AddScriptLPS(1);
10270 10947
10948 //Clone is thread safe
10271 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 10949 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10272 10950
10273 UUID assetID = UUID.Zero; 10951 UUID assetID = UUID.Zero;
@@ -10330,6 +11008,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10330 { 11008 {
10331 m_host.AddScriptLPS(1); 11009 m_host.AddScriptLPS(1);
10332 11010
11011 //Clone is thread safe
10333 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 11012 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10334 11013
10335 UUID assetID = UUID.Zero; 11014 UUID assetID = UUID.Zero;
@@ -10410,15 +11089,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10410 return GetLinkPrimitiveParams(obj, rules); 11089 return GetLinkPrimitiveParams(obj, rules);
10411 } 11090 }
10412 11091
10413 public void print(string str) 11092 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
10414 { 11093 {
10415 // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print 11094 List<SceneObjectPart> parts = GetLinkParts(link);
10416 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_itemID, "OSSL"); 11095 if (parts.Count < 1)
10417 if (ossl != null) 11096 return 0;
10418 { 11097
10419 ossl.CheckThreatLevel(ThreatLevel.High, "print"); 11098 return GetNumberOfSides(parts[0]);
10420 m_log.Info("LSL print():" + str);
10421 }
10422 } 11099 }
10423 11100
10424 private string Name2Username(string name) 11101 private string Name2Username(string name)
@@ -10464,6 +11141,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10464 return rq.ToString(); 11141 return rq.ToString();
10465 } 11142 }
10466 11143
11144 private void SayShoutTimerElapsed(Object sender, ElapsedEventArgs args)
11145 {
11146 m_SayShoutCount = 0;
11147 }
10467 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options) 11148 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
10468 { 11149 {
10469 m_host.AddScriptLPS(1); 11150 m_host.AddScriptLPS(1);
@@ -10633,22 +11314,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10633 NotImplemented("llGetSPMaxMemory"); 11314 NotImplemented("llGetSPMaxMemory");
10634 } 11315 }
10635 11316
10636 public void llGetUsedMemory() 11317 public virtual LSL_Integer llGetUsedMemory()
10637 { 11318 {
10638 m_host.AddScriptLPS(1); 11319 m_host.AddScriptLPS(1);
10639 NotImplemented("llGetUsedMemory"); 11320 NotImplemented("llGetUsedMemory");
11321 return 0;
10640 } 11322 }
10641 11323
10642 public void llScriptProfiler(LSL_Integer flags) 11324 public void llScriptProfiler(LSL_Integer flags)
10643 { 11325 {
10644 m_host.AddScriptLPS(1); 11326 m_host.AddScriptLPS(1);
10645 NotImplemented("llScriptProfiler"); 11327 //NotImplemented("llScriptProfiler");
10646 } 11328 }
10647 11329
10648 public void llSetSoundQueueing(int queue) 11330 public void llSetSoundQueueing(int queue)
10649 { 11331 {
10650 m_host.AddScriptLPS(1); 11332 m_host.AddScriptLPS(1);
10651 NotImplemented("llSetSoundQueueing");
10652 } 11333 }
10653 11334
10654 public void llCollisionSprite(string impact_sprite) 11335 public void llCollisionSprite(string impact_sprite)
@@ -10660,7 +11341,133 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10660 public void llGodLikeRezObject(string inventory, LSL_Vector pos) 11341 public void llGodLikeRezObject(string inventory, LSL_Vector pos)
10661 { 11342 {
10662 m_host.AddScriptLPS(1); 11343 m_host.AddScriptLPS(1);
10663 NotImplemented("llGodLikeRezObject"); 11344
11345 if (!World.Permissions.IsGod(m_host.OwnerID))
11346 NotImplemented("llGodLikeRezObject");
11347
11348 AssetBase rezAsset = World.AssetService.Get(inventory);
11349 if (rezAsset == null)
11350 {
11351 llSay(0, "Asset not found");
11352 return;
11353 }
11354
11355 SceneObjectGroup group = null;
11356
11357 try
11358 {
11359 string xmlData = Utils.BytesToString(rezAsset.Data);
11360 group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
11361 }
11362 catch
11363 {
11364 llSay(0, "Asset not found");
11365 return;
11366 }
11367
11368 if (group == null)
11369 {
11370 llSay(0, "Asset not found");
11371 return;
11372 }
11373
11374 group.RootPart.AttachPoint = group.RootPart.Shape.State;
11375 group.RootPart.AttachOffset = group.AbsolutePosition;
11376
11377 group.ResetIDs();
11378
11379 Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
11380 World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero);
11381 group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3);
11382 group.ScheduleGroupForFullUpdate();
11383
11384 // objects rezzed with this method are die_at_edge by default.
11385 group.RootPart.SetDieAtEdge(true);
11386
11387 group.ResumeScripts();
11388
11389 m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
11390 "object_rez", new Object[] {
11391 new LSL_String(
11392 group.RootPart.UUID.ToString()) },
11393 new DetectParams[0]));
11394 }
11395
11396 public LSL_String llTransferLindenDollars(string destination, int amount)
11397 {
11398 UUID txn = UUID.Random();
11399
11400 Util.FireAndForget(delegate(object x)
11401 {
11402 int replycode = 0;
11403 string replydata = destination + "," + amount.ToString();
11404
11405 try
11406 {
11407 UUID invItemID=InventorySelf();
11408 if (invItemID == UUID.Zero)
11409 {
11410 replydata = "SERVICE_ERROR";
11411 return;
11412 }
11413
11414 m_host.AddScriptLPS(1);
11415
11416 m_host.TaskInventory.LockItemsForRead(true);
11417 TaskInventoryItem item = m_host.TaskInventory[invItemID];
11418 m_host.TaskInventory.LockItemsForRead(false);
11419
11420 if (item.PermsGranter == UUID.Zero)
11421 {
11422 replydata = "MISSING_PERMISSION_DEBIT";
11423 return;
11424 }
11425
11426 if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
11427 {
11428 replydata = "MISSING_PERMISSION_DEBIT";
11429 return;
11430 }
11431
11432 UUID toID = new UUID();
11433
11434 if (!UUID.TryParse(destination, out toID))
11435 {
11436 replydata = "INVALID_AGENT";
11437 return;
11438 }
11439
11440 IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
11441
11442 if (money == null)
11443 {
11444 replydata = "TRANSFERS_DISABLED";
11445 return;
11446 }
11447
11448 bool result = money.ObjectGiveMoney(
11449 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
11450
11451 if (result)
11452 {
11453 replycode = 1;
11454 return;
11455 }
11456
11457 replydata = "LINDENDOLLAR_INSUFFICIENTFUNDS";
11458 }
11459 finally
11460 {
11461 m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
11462 "transaction_result", new Object[] {
11463 new LSL_String(txn.ToString()),
11464 new LSL_Integer(replycode),
11465 new LSL_String(replydata) },
11466 new DetectParams[0]));
11467 }
11468 });
11469
11470 return txn.ToString();
10664 } 11471 }
10665 11472
10666 #endregion 11473 #endregion
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index f3206ac..c0d2f38 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -137,6 +137,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
137 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; 137 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
138 internal float m_ScriptDelayFactor = 1.0f; 138 internal float m_ScriptDelayFactor = 1.0f;
139 internal float m_ScriptDistanceFactor = 1.0f; 139 internal float m_ScriptDistanceFactor = 1.0f;
140 internal bool m_debuggerSafe = false;
140 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); 141 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
141 142
142 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) 143 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
@@ -145,6 +146,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
145 m_host = host; 146 m_host = host;
146 m_localID = localID; 147 m_localID = localID;
147 m_itemID = itemID; 148 m_itemID = itemID;
149 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
148 150
149 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) 151 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
150 m_OSFunctionsEnabled = true; 152 m_OSFunctionsEnabled = true;
@@ -203,7 +205,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
203 205
204 internal void OSSLError(string msg) 206 internal void OSSLError(string msg)
205 { 207 {
206 throw new Exception("OSSL Runtime Error: " + msg); 208 if (m_debuggerSafe)
209 {
210 OSSLShoutError(msg);
211 }
212 else
213 {
214 throw new Exception("OSSL Runtime Error: " + msg);
215 }
207 } 216 }
208 217
209 private void InitLSL() 218 private void InitLSL()
@@ -894,18 +903,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
894 if (target != null) 903 if (target != null)
895 { 904 {
896 UUID animID=UUID.Zero; 905 UUID animID=UUID.Zero;
897 lock (m_host.TaskInventory) 906 m_host.TaskInventory.LockItemsForRead(true);
907 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
898 { 908 {
899 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 909 if (inv.Value.Name == animation)
900 { 910 {
901 if (inv.Value.Name == animation) 911 if (inv.Value.Type == (int)AssetType.Animation)
902 { 912 animID = inv.Value.AssetID;
903 if (inv.Value.Type == (int)AssetType.Animation) 913 continue;
904 animID = inv.Value.AssetID;
905 continue;
906 }
907 } 914 }
908 } 915 }
916 m_host.TaskInventory.LockItemsForRead(false);
909 if (animID == UUID.Zero) 917 if (animID == UUID.Zero)
910 target.Animator.AddAnimation(animation, m_host.UUID); 918 target.Animator.AddAnimation(animation, m_host.UUID);
911 else 919 else
@@ -927,18 +935,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
927 if (target != null) 935 if (target != null)
928 { 936 {
929 UUID animID = UUID.Zero; 937 UUID animID = UUID.Zero;
930 lock (m_host.TaskInventory) 938 m_host.TaskInventory.LockItemsForRead(true);
939 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
931 { 940 {
932 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 941 if (inv.Value.Name == animation)
933 { 942 {
934 if (inv.Value.Name == animation) 943 if (inv.Value.Type == (int)AssetType.Animation)
935 { 944 animID = inv.Value.AssetID;
936 if (inv.Value.Type == (int)AssetType.Animation) 945 continue;
937 animID = inv.Value.AssetID;
938 continue;
939 }
940 } 946 }
941 } 947 }
948 m_host.TaskInventory.LockItemsForRead(false);
942 949
943 if (animID == UUID.Zero) 950 if (animID == UUID.Zero)
944 target.Animator.RemoveAnimation(animation); 951 target.Animator.RemoveAnimation(animation);
@@ -1895,6 +1902,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1895 1902
1896 if (!UUID.TryParse(notecardNameOrUuid, out assetID)) 1903 if (!UUID.TryParse(notecardNameOrUuid, out assetID))
1897 { 1904 {
1905 m_host.TaskInventory.LockItemsForRead(true);
1898 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1906 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1899 { 1907 {
1900 if (item.Type == 7 && item.Name == notecardNameOrUuid) 1908 if (item.Type == 7 && item.Name == notecardNameOrUuid)
@@ -1902,6 +1910,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1902 assetID = item.AssetID; 1910 assetID = item.AssetID;
1903 } 1911 }
1904 } 1912 }
1913 m_host.TaskInventory.LockItemsForRead(false);
1905 } 1914 }
1906 1915
1907 if (assetID == UUID.Zero) 1916 if (assetID == UUID.Zero)
@@ -2225,8 +2234,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2225 UUID x = module.CreateNPC(firstname, 2234 UUID x = module.CreateNPC(firstname,
2226 lastname, 2235 lastname,
2227 new Vector3((float) position.x, (float) position.y, (float) position.z), 2236 new Vector3((float) position.x, (float) position.y, (float) position.z),
2228 World, 2237 World,appearance);
2229 appearance);
2230 2238
2231 return new LSL_Key(x.ToString()); 2239 return new LSL_Key(x.ToString());
2232 } 2240 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index 3eeb23d..4da8fe7 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..e0027b2 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();
@@ -199,6 +200,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
199 void llGiveInventory(string destination, string inventory); 200 void llGiveInventory(string destination, string inventory);
200 void llGiveInventoryList(string destination, string category, LSL_List inventory); 201 void llGiveInventoryList(string destination, string category, LSL_List inventory);
201 LSL_Integer llGiveMoney(string destination, int amount); 202 LSL_Integer llGiveMoney(string destination, int amount);
203 LSL_String llTransferLindenDollars(string destination, int amount);
202 void llGodLikeRezObject(string inventory, LSL_Vector pos); 204 void llGodLikeRezObject(string inventory, LSL_Vector pos);
203 LSL_Float llGround(LSL_Vector offset); 205 LSL_Float llGround(LSL_Vector offset);
204 LSL_Vector llGroundContour(LSL_Vector offset); 206 LSL_Vector llGroundContour(LSL_Vector offset);
@@ -405,7 +407,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
405 LSL_Vector llWind(LSL_Vector offset); 407 LSL_Vector llWind(LSL_Vector offset);
406 LSL_String llXorBase64Strings(string str1, string str2); 408 LSL_String llXorBase64Strings(string str1, string str2);
407 LSL_String llXorBase64StringsCorrect(string str1, string str2); 409 LSL_String llXorBase64StringsCorrect(string str1, string str2);
408 void print(string str); 410 LSL_Integer llGetLinkNumberOfSides(LSL_Integer link);
409 411
410 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 412 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
411 LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 413 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 3221833..a61d553 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 fd08373..0ad3f78 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;
@@ -377,6 +378,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
377 public const int PRIM_SCULPT_TYPE_TORUS = 2; 378 public const int PRIM_SCULPT_TYPE_TORUS = 2;
378 public const int PRIM_SCULPT_TYPE_PLANE = 3; 379 public const int PRIM_SCULPT_TYPE_PLANE = 3;
379 public const int PRIM_SCULPT_TYPE_CYLINDER = 4; 380 public const int PRIM_SCULPT_TYPE_CYLINDER = 4;
381 public const int PRIM_SCULPT_FLAG_INVERT = 64;
382 public const int PRIM_SCULPT_FLAG_MIRROR = 128;
380 383
381 public const int MASK_BASE = 0; 384 public const int MASK_BASE = 0;
382 public const int MASK_OWNER = 1; 385 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..c717589 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();
@@ -839,6 +846,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
839 return m_LSL_Functions.llGiveMoney(destination, amount); 846 return m_LSL_Functions.llGiveMoney(destination, amount);
840 } 847 }
841 848
849 public LSL_String llTransferLindenDollars(string destination, int amount)
850 {
851 return m_LSL_Functions.llTransferLindenDollars(destination, amount);
852 }
853
842 public void llGodLikeRezObject(string inventory, LSL_Vector pos) 854 public void llGodLikeRezObject(string inventory, LSL_Vector pos)
843 { 855 {
844 m_LSL_Functions.llGodLikeRezObject(inventory, pos); 856 m_LSL_Functions.llGodLikeRezObject(inventory, pos);
@@ -1878,9 +1890,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1878 return m_LSL_Functions.llClearPrimMedia(face); 1890 return m_LSL_Functions.llClearPrimMedia(face);
1879 } 1891 }
1880 1892
1881 public void print(string str) 1893 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
1882 { 1894 {
1883 m_LSL_Functions.print(str); 1895 return m_LSL_Functions.llGetLinkNumberOfSides(link);
1884 } 1896 }
1885 } 1897 }
1886} 1898}
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);