aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs32
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs117
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs3502
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs6
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs157
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs22
-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.cs14
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs3
-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.cs11
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs70
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs21
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Helpers.cs45
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs172
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs39
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs363
21 files changed, 3311 insertions, 1421 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
index 998f40b..1e19032 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
@@ -28,9 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection;
32using System.Threading; 31using System.Threading;
33using log4net;
34using OpenMetaverse; 32using OpenMetaverse;
35using OpenSim.Framework; 33using OpenSim.Framework;
36using OpenSim.Framework.Monitoring; 34using OpenSim.Framework.Monitoring;
@@ -39,6 +37,8 @@ using OpenSim.Region.ScriptEngine.Interfaces;
39using OpenSim.Region.ScriptEngine.Shared; 37using OpenSim.Region.ScriptEngine.Shared;
40using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; 38using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
41using Timer=OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer; 39using Timer=OpenSim.Region.ScriptEngine.Shared.Api.Plugins.Timer;
40using System.Reflection;
41using log4net;
42 42
43namespace OpenSim.Region.ScriptEngine.Shared.Api 43namespace OpenSim.Region.ScriptEngine.Shared.Api
44{ 44{
@@ -269,6 +269,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
269 /// <param name="itemID"></param> 269 /// <param name="itemID"></param>
270 public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID) 270 public static void RemoveScript(IScriptEngine engine, uint localID, UUID itemID)
271 { 271 {
272 // Remove a specific script
272// m_log.DebugFormat("[ASYNC COMMAND MANAGER]: Removing facilities for script {0}", itemID); 273// m_log.DebugFormat("[ASYNC COMMAND MANAGER]: Removing facilities for script {0}", itemID);
273 274
274 lock (staticLock) 275 lock (staticLock)
@@ -282,7 +283,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
282 // Remove from: HttpRequest 283 // Remove from: HttpRequest
283 IHttpRequestModule iHttpReq = engine.World.RequestModuleInterface<IHttpRequestModule>(); 284 IHttpRequestModule iHttpReq = engine.World.RequestModuleInterface<IHttpRequestModule>();
284 if (iHttpReq != null) 285 if (iHttpReq != null)
285 iHttpReq.StopHttpRequestsForScript(itemID); 286 iHttpReq.StopHttpRequest(localID, itemID);
286 287
287 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>(); 288 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>();
288 if (comms != null) 289 if (comms != null)
@@ -364,6 +365,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
364 } 365 }
365 } 366 }
366 367
368 public static void StateChange(IScriptEngine engine, uint localID, UUID itemID)
369 {
370 // Remove a specific script
371
372 // Remove dataserver events
373 m_Dataserver[engine].RemoveEvents(localID, itemID);
374
375 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>();
376 if (comms != null)
377 comms.DeleteListener(itemID);
378
379 IXMLRPC xmlrpc = engine.World.RequestModuleInterface<IXMLRPC>();
380 if (xmlrpc != null)
381 {
382 xmlrpc.DeleteChannels(itemID);
383 xmlrpc.CancelSRDRequests(itemID);
384 }
385
386 // Remove Sensors
387 m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID);
388
389 }
390
367 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID) 391 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID)
368 { 392 {
369 List<Object> data = new List<Object>(); 393 List<Object> data = new List<Object>();
@@ -439,4 +463,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
439 } 463 }
440 } 464 }
441 } 465 }
442} \ No newline at end of file 466}
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..fce8ff8
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
@@ -0,0 +1,117 @@
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.Threading;
30using System.Reflection;
31using System.Collections;
32using System.Collections.Generic;
33using System.Runtime.Remoting.Lifetime;
34using OpenMetaverse;
35using Nini.Config;
36using OpenSim;
37using OpenSim.Framework;
38using OpenSim.Region.CoreModules.World.LightShare;
39using OpenSim.Region.Framework.Interfaces;
40using OpenSim.Region.Framework.Scenes;
41using OpenSim.Region.ScriptEngine.Shared;
42using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
43using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
44using OpenSim.Region.ScriptEngine.Interfaces;
45using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
46using OpenSim.Services.Interfaces;
47
48using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
49using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
50using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
51using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
52using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
53using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
54using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
55
56namespace OpenSim.Region.ScriptEngine.Shared.Api
57{
58 [Serializable]
59 public class CM_Api : MarshalByRefObject, ICM_Api, IScriptApi
60 {
61 internal IScriptEngine m_ScriptEngine;
62 internal SceneObjectPart m_host;
63 internal TaskInventoryItem m_item;
64 internal bool m_CMFunctionsEnabled = false;
65
66 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
67 {
68 m_ScriptEngine = ScriptEngine;
69 m_host = host;
70 m_item = item;
71
72 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false))
73 m_CMFunctionsEnabled = true;
74 }
75
76 public override Object InitializeLifetimeService()
77 {
78 ILease lease = (ILease)base.InitializeLifetimeService();
79
80 if (lease.CurrentState == LeaseState.Initial)
81 {
82 lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
83 // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
84 // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
85 }
86 return lease;
87 }
88
89 public Scene World
90 {
91 get { return m_ScriptEngine.World; }
92 }
93
94 public string cmDetectedCountry(int number)
95 {
96 m_host.AddScriptLPS(1);
97 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
98 if (detectedParams == null)
99 return String.Empty;
100 return detectedParams.Country;
101 }
102
103 public string cmGetAgentCountry(LSL_Key key)
104 {
105 if (!World.Permissions.IsGod(m_host.OwnerID))
106 return String.Empty;
107
108 UUID uuid;
109
110 if (!UUID.TryParse(key, out uuid))
111 return String.Empty;
112
113 UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
114 return account.UserCountry;
115 }
116 }
117}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index e1630b3..9744526 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -24,14 +24,16 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
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.Framework.Scenes.Scripting; 51using OpenSim.Region.Framework.Scenes.Scripting;
49using OpenSim.Region.Physics.Manager; 52using OpenSim.Region.Physics.Manager;
@@ -67,6 +70,7 @@ using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
67using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; 70using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
68using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; 71using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
69using System.Reflection; 72using System.Reflection;
73using Timer = System.Timers.Timer;
70using System.Linq; 74using System.Linq;
71using PermissionMask = OpenSim.Framework.PermissionMask; 75using PermissionMask = OpenSim.Framework.PermissionMask;
72 76
@@ -115,11 +119,38 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
115 protected int m_notecardLineReadCharsMax = 255; 119 protected int m_notecardLineReadCharsMax = 255;
116 protected int m_scriptConsoleChannel = 0; 120 protected int m_scriptConsoleChannel = 0;
117 protected bool m_scriptConsoleChannelEnabled = false; 121 protected bool m_scriptConsoleChannelEnabled = false;
122 protected bool m_debuggerSafe = false;
118 protected IUrlModule m_UrlModule = null; 123 protected IUrlModule m_UrlModule = null;
119 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>(); 124 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache =
120 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp. 125 new Dictionary<UUID, UserInfoCacheEntry>();
126 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
121 protected ISoundModule m_SoundModule = null; 127 protected ISoundModule m_SoundModule = null;
122 128
129// protected Timer m_ShoutSayTimer;
130 protected int m_SayShoutCount = 0;
131 DateTime m_lastSayShoutCheck;
132
133 private Dictionary<string, string> MovementAnimationsForLSL =
134 new Dictionary<string, string> {
135 {"FLY", "Flying"},
136 {"FLYSLOW", "FlyingSlow"},
137 {"HOVER_UP", "Hovering Up"},
138 {"HOVER_DOWN", "Hovering Down"},
139 {"HOVER", "Hovering"},
140 {"LAND", "Landing"},
141 {"FALLDOWN", "Falling Down"},
142 {"PREJUMP", "PreJumping"},
143 {"JUMP", "Jumping"},
144 {"STANDUP", "Standing Up"},
145 {"SOFT_LAND", "Soft Landing"},
146 {"STAND", "Standing"},
147 {"CROUCHWALK", "CrouchWalking"},
148 {"RUN", "Running"},
149 {"WALK", "Walking"},
150 {"CROUCH", "Crouching"},
151 {"TURNLEFT", "Turning Left"},
152 {"TURNRIGHT", "Turning Right"}
153 };
123 //An array of HTTP/1.1 headers that are not allowed to be used 154 //An array of HTTP/1.1 headers that are not allowed to be used
124 //as custom headers by llHTTPRequest. 155 //as custom headers by llHTTPRequest.
125 private string[] HttpStandardHeaders = 156 private string[] HttpStandardHeaders =
@@ -140,9 +171,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
140 public void Initialize( 171 public void Initialize(
141 IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle) 172 IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item, WaitHandle coopSleepHandle)
142 { 173 {
174 m_lastSayShoutCheck = DateTime.UtcNow;
175
143 m_ScriptEngine = scriptEngine; 176 m_ScriptEngine = scriptEngine;
144 m_host = host; 177 m_host = host;
145 m_item = item; 178 m_item = item;
179 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
146 m_coopSleepHandle = coopSleepHandle; 180 m_coopSleepHandle = coopSleepHandle;
147 181
148 LoadConfig(); 182 LoadConfig();
@@ -231,6 +265,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
231 get { return m_ScriptEngine.World; } 265 get { return m_ScriptEngine.World; }
232 } 266 }
233 267
268 [DebuggerNonUserCode]
234 public void state(string newState) 269 public void state(string newState)
235 { 270 {
236 m_ScriptEngine.SetState(m_item.ItemID, newState); 271 m_ScriptEngine.SetState(m_item.ItemID, newState);
@@ -240,6 +275,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
240 /// Reset the named script. The script must be present 275 /// Reset the named script. The script must be present
241 /// in the same prim. 276 /// in the same prim.
242 /// </summary> 277 /// </summary>
278 [DebuggerNonUserCode]
243 public void llResetScript() 279 public void llResetScript()
244 { 280 {
245 m_host.AddScriptLPS(1); 281 m_host.AddScriptLPS(1);
@@ -302,6 +338,57 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
302 } 338 }
303 } 339 }
304 340
341 public List<ScenePresence> GetLinkAvatars(int linkType)
342 {
343 List<ScenePresence> ret = new List<ScenePresence>();
344 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
345 return ret;
346
347 List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
348
349 switch (linkType)
350 {
351 case ScriptBaseClass.LINK_SET:
352 return avs;
353
354 case ScriptBaseClass.LINK_ROOT:
355 return ret;
356
357 case ScriptBaseClass.LINK_ALL_OTHERS:
358 return avs;
359
360 case ScriptBaseClass.LINK_ALL_CHILDREN:
361 return avs;
362
363 case ScriptBaseClass.LINK_THIS:
364 return ret;
365
366 default:
367 if (linkType < 0)
368 return ret;
369
370 int partCount = m_host.ParentGroup.GetPartCount();
371
372 if (linkType <= partCount)
373 {
374 return ret;
375 }
376 else
377 {
378 linkType = linkType - partCount;
379 if (linkType > avs.Count)
380 {
381 return ret;
382 }
383 else
384 {
385 ret.Add(avs[linkType-1]);
386 return ret;
387 }
388 }
389 }
390 }
391
305 /// <summary> 392 /// <summary>
306 /// Get a given link entity from a linkset (linked objects and any sitting avatars). 393 /// Get a given link entity from a linkset (linked objects and any sitting avatars).
307 /// </summary> 394 /// </summary>
@@ -384,6 +471,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
384 public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType) 471 public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
385 { 472 {
386 List<SceneObjectPart> ret = new List<SceneObjectPart>(); 473 List<SceneObjectPart> ret = new List<SceneObjectPart>();
474 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
475 return ret;
387 ret.Add(part); 476 ret.Add(part);
388 477
389 switch (linkType) 478 switch (linkType)
@@ -537,31 +626,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
537 626
538 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke 627 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
539 628
540 /// <summary> 629 // Utility function for llRot2Euler
541 /// Convert an LSL rotation to a Euler vector. 630
542 /// </summary> 631 // normalize an angle between -PI and PI (-180 to +180 degrees)
543 /// <remarks> 632 protected double NormalizeAngle(double angle)
544 /// Using algorithm based off http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/quat_2_euler_paper_ver2-1.pdf
545 /// to avoid issues with singularity and rounding with Y rotation of +/- PI/2
546 /// </remarks>
547 /// <param name="r"></param>
548 /// <returns></returns>
549 public LSL_Vector llRot2Euler(LSL_Rotation r)
550 { 633 {
551 m_host.AddScriptLPS(1); 634 if (angle > -Math.PI && angle < Math.PI)
635 return angle;
552 636
553 LSL_Vector v = new LSL_Vector(0.0, 0.0, 1.0) * r; // Z axis unit vector unaffected by Z rotation component of r. 637 int numPis = (int)(Math.PI / angle);
554 double m = LSL_Vector.Mag(v); // Just in case v isn't normalized, need magnitude for Asin() operation later. 638 double remainder = angle - Math.PI * numPis;
555 if (m == 0.0) return new LSL_Vector(); 639 if (numPis % 2 == 1)
556 double x = Math.Atan2(-v.y, v.z); 640 return Math.PI - angle;
557 double sin = v.x / m; 641 return remainder;
558 if (sin < -0.999999 || sin > 0.999999) x = 0.0; // Force X rotation to 0 at the singularities. 642 }
559 double y = Math.Asin(sin);
560 // Rotate X axis unit vector by r and unwind the X and Y rotations leaving only the Z rotation
561 v = new LSL_Vector(1.0, 0.0, 0.0) * ((r * new LSL_Rotation(Math.Sin(-x / 2.0), 0.0, 0.0, Math.Cos(-x / 2.0))) * new LSL_Rotation(0.0, Math.Sin(-y / 2.0), 0.0, Math.Cos(-y / 2.0)));
562 double z = Math.Atan2(v.y, v.x);
563 643
564 return new LSL_Vector(x, y, z); 644 public LSL_Vector llRot2Euler(LSL_Rotation q1)
645 {
646 m_host.AddScriptLPS(1);
647 LSL_Vector eul = new LSL_Vector();
648
649 double sqw = q1.s*q1.s;
650 double sqx = q1.x*q1.x;
651 double sqy = q1.z*q1.z;
652 double sqz = q1.y*q1.y;
653 double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
654 double test = q1.x*q1.z + q1.y*q1.s;
655 if (test > 0.4999*unit) { // singularity at north pole
656 eul.z = 2 * Math.Atan2(q1.x,q1.s);
657 eul.y = Math.PI/2;
658 eul.x = 0;
659 return eul;
660 }
661 if (test < -0.4999*unit) { // singularity at south pole
662 eul.z = -2 * Math.Atan2(q1.x,q1.s);
663 eul.y = -Math.PI/2;
664 eul.x = 0;
665 return eul;
666 }
667 eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
668 eul.y = Math.Asin(2*test/unit);
669 eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
670 return eul;
565 } 671 }
566 672
567 /* From wiki: 673 /* From wiki:
@@ -614,18 +720,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
614 m_host.AddScriptLPS(1); 720 m_host.AddScriptLPS(1);
615 721
616 double x,y,z,s; 722 double x,y,z,s;
617 723 v.x *= 0.5;
618 double c1 = Math.Cos(v.x * 0.5); 724 v.y *= 0.5;
619 double c2 = Math.Cos(v.y * 0.5); 725 v.z *= 0.5;
620 double c3 = Math.Cos(v.z * 0.5); 726 double c1 = Math.Cos(v.x);
621 double s1 = Math.Sin(v.x * 0.5); 727 double c2 = Math.Cos(v.y);
622 double s2 = Math.Sin(v.y * 0.5); 728 double c1c2 = c1 * c2;
623 double s3 = Math.Sin(v.z * 0.5); 729 double s1 = Math.Sin(v.x);
624 730 double s2 = Math.Sin(v.y);
625 x = s1 * c2 * c3 + c1 * s2 * s3; 731 double s1s2 = s1 * s2;
626 y = c1 * s2 * c3 - s1 * c2 * s3; 732 double c1s2 = c1 * s2;
627 z = s1 * s2 * c3 + c1 * c2 * s3; 733 double s1c2 = s1 * c2;
628 s = c1 * c2 * c3 - s1 * s2 * s3; 734 double c3 = Math.Cos(v.z);
735 double s3 = Math.Sin(v.z);
736
737 x = s1c2 * c3 + c1s2 * s3;
738 y = c1s2 * c3 - s1c2 * s3;
739 z = s1s2 * c3 + c1c2 * s3;
740 s = c1c2 * c3 - s1s2 * s3;
629 741
630 return new LSL_Rotation(x, y, z, s); 742 return new LSL_Rotation(x, y, z, s);
631 } 743 }
@@ -763,77 +875,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
763 { 875 {
764 //A and B should both be normalized 876 //A and B should both be normalized
765 m_host.AddScriptLPS(1); 877 m_host.AddScriptLPS(1);
766 LSL_Rotation rotBetween; 878 /* This method is more accurate than the SL one, and thus causes problems
767 // Check for zero vectors. If either is zero, return zero rotation. Otherwise, 879 for scripts that deal with the SL inaccuracy around 180-degrees -.- .._.
768 // continue calculation. 880
769 if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f)) 881 double dotProduct = LSL_Vector.Dot(a, b);
770 { 882 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
771 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); 883 double magProduct = LSL_Vector.Mag(a) * LSL_Vector.Mag(b);
772 } 884 double angle = Math.Acos(dotProduct / magProduct);
773 else 885 LSL_Vector axis = LSL_Vector.Norm(crossProduct);
774 { 886 double s = Math.Sin(angle / 2);
775 a = LSL_Vector.Norm(a); 887
776 b = LSL_Vector.Norm(b); 888 double x = axis.x * s;
777 double dotProduct = LSL_Vector.Dot(a, b); 889 double y = axis.y * s;
778 // There are two degenerate cases possible. These are for vectors 180 or 890 double z = axis.z * s;
779 // 0 degrees apart. These have to be detected and handled individually. 891 double w = Math.Cos(angle / 2);
780 // 892
781 // Check for vectors 180 degrees apart. 893 if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w))
782 // A dot product of -1 would mean the angle between vectors is 180 degrees. 894 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
783 if (dotProduct < -0.9999999f) 895
784 { 896 return new LSL_Rotation((float)x, (float)y, (float)z, (float)w);
785 // First assume X axis is orthogonal to the vectors. 897 */
786 LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f); 898
787 orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a)); 899 // This method mimics the 180 errors found in SL
788 // Check for near zero vector. A very small non-zero number here will create 900 // See www.euclideanspace.com... angleBetween
789 // a rotation in an undesired direction. 901 LSL_Vector vec_a = a;
790 if (LSL_Vector.Mag(orthoVector) > 0.0001) 902 LSL_Vector vec_b = b;
791 { 903
792 rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f); 904 // Eliminate zero length
793 } 905 LSL_Float vec_a_mag = LSL_Vector.Mag(vec_a);
794 // If the magnitude of the vector was near zero, then assume the X axis is not 906 LSL_Float vec_b_mag = LSL_Vector.Mag(vec_b);
795 // orthogonal and use the Z axis instead. 907 if (vec_a_mag < 0.00001 ||
796 else 908 vec_b_mag < 0.00001)
797 { 909 {
798 // Set 180 z rotation. 910 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
799 rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f); 911 }
800 } 912
801 } 913 // Normalize
802 // Check for parallel vectors. 914 vec_a = llVecNorm(vec_a);
803 // A dot product of 1 would mean the angle between vectors is 0 degrees. 915 vec_b = llVecNorm(vec_b);
804 else if (dotProduct > 0.9999999f) 916
805 { 917 // Calculate axis and rotation angle
806 // Set zero rotation. 918 LSL_Vector axis = vec_a % vec_b;
807 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); 919 LSL_Float cos_theta = vec_a * vec_b;
808 } 920
809 else 921 // Check if parallel
810 { 922 if (cos_theta > 0.99999)
811 // All special checks have been performed so get the axis of rotation. 923 {
812 LSL_Vector crossProduct = LSL_Vector.Cross(a, b); 924 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
813 // Quarternion s value is the length of the unit vector + dot product. 925 }
814 double qs = 1.0 + dotProduct; 926
815 rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs); 927 // Check if anti-parallel
816 // Normalize the rotation. 928 else if (cos_theta < -0.99999)
817 double mag = LSL_Rotation.Mag(rotBetween); 929 {
818 // We shouldn't have to worry about a divide by zero here. The qs value will be 930 LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (vec_a.x / (vec_a * vec_a) * vec_a);
819 // non-zero because we already know if we're here, then the dotProduct is not -1 so 931 if (LSL_Vector.Mag(orthog_axis) < 0.000001) orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
820 // qs will not be zero. Also, we've already handled the input vectors being zero so the 932 return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
821 // crossProduct vector should also not be zero. 933 }
822 rotBetween.x = rotBetween.x / mag; 934 else // other rotation
823 rotBetween.y = rotBetween.y / mag; 935 {
824 rotBetween.z = rotBetween.z / mag; 936 LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
825 rotBetween.s = rotBetween.s / mag; 937 axis = llVecNorm(axis);
826 // Check for undefined values and set zero rotation if any found. This code might not actually be required 938 double x, y, z, s, t;
827 // any longer since zero vectors are checked for at the top. 939 s = Math.Cos(theta);
828 if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s)) 940 t = Math.Sin(theta);
829 { 941 x = axis.x * t;
830 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); 942 y = axis.y * t;
831 } 943 z = axis.z * t;
832 } 944 return new LSL_Rotation(x,y,z,s);
833 } 945 }
834 return rotBetween; 946 }
835 } 947
836
837 public void llWhisper(int channelID, string text) 948 public void llWhisper(int channelID, string text)
838 { 949 {
839 m_host.AddScriptLPS(1); 950 m_host.AddScriptLPS(1);
@@ -849,10 +960,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
849 wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text); 960 wComm.DeliverMessage(ChatTypeEnum.Whisper, channelID, m_host.Name, m_host.UUID, text);
850 } 961 }
851 962
963 private void CheckSayShoutTime()
964 {
965 DateTime now = DateTime.UtcNow;
966 if ((now - m_lastSayShoutCheck).Ticks > 10000000) // 1sec
967 {
968 m_lastSayShoutCheck = now;
969 m_SayShoutCount = 0;
970 }
971 else
972 m_SayShoutCount++;
973 }
974
852 public void llSay(int channelID, string text) 975 public void llSay(int channelID, string text)
853 { 976 {
854 m_host.AddScriptLPS(1); 977 m_host.AddScriptLPS(1);
855 978
979 if (channelID == 0)
980// m_SayShoutCount++;
981 CheckSayShoutTime();
982
983 if (m_SayShoutCount >= 11)
984 ScriptSleep(2000);
985
856 if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel)) 986 if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
857 { 987 {
858 Console.WriteLine(text); 988 Console.WriteLine(text);
@@ -875,6 +1005,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
875 { 1005 {
876 m_host.AddScriptLPS(1); 1006 m_host.AddScriptLPS(1);
877 1007
1008 if (channelID == 0)
1009// m_SayShoutCount++;
1010 CheckSayShoutTime();
1011
1012 if (m_SayShoutCount >= 11)
1013 ScriptSleep(2000);
1014
878 if (text.Length > 1023) 1015 if (text.Length > 1023)
879 text = text.Substring(0, 1023); 1016 text = text.Substring(0, 1023);
880 1017
@@ -906,22 +1043,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
906 1043
907 public void llRegionSayTo(string target, int channel, string msg) 1044 public void llRegionSayTo(string target, int channel, string msg)
908 { 1045 {
1046 string error = String.Empty;
1047
909 if (msg.Length > 1023) 1048 if (msg.Length > 1023)
910 msg = msg.Substring(0, 1023); 1049 msg = msg.Substring(0, 1023);
911 1050
912 m_host.AddScriptLPS(1); 1051 m_host.AddScriptLPS(1);
913 1052
914 if (channel == ScriptBaseClass.DEBUG_CHANNEL)
915 {
916 return;
917 }
918
919 UUID TargetID; 1053 UUID TargetID;
920 UUID.TryParse(target, out TargetID); 1054 UUID.TryParse(target, out TargetID);
921 1055
922 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); 1056 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
923 if (wComm != null) 1057 if (wComm != null)
924 wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg); 1058 if (!wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg, out error))
1059 LSLError(error);
925 } 1060 }
926 1061
927 public LSL_Integer llListen(int channelID, string name, string ID, string msg) 1062 public LSL_Integer llListen(int channelID, string name, string ID, string msg)
@@ -1177,10 +1312,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1177 return detectedParams.TouchUV; 1312 return detectedParams.TouchUV;
1178 } 1313 }
1179 1314
1315 [DebuggerNonUserCode]
1180 public virtual void llDie() 1316 public virtual void llDie()
1181 { 1317 {
1182 m_host.AddScriptLPS(1); 1318 m_host.AddScriptLPS(1);
1183 throw new SelfDeleteException(); 1319 if (!m_host.ParentGroup.IsAttachment) throw new SelfDeleteException();
1184 } 1320 }
1185 1321
1186 public LSL_Float llGround(LSL_Vector offset) 1322 public LSL_Float llGround(LSL_Vector offset)
@@ -1251,6 +1387,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1251 1387
1252 public void llSetStatus(int status, int value) 1388 public void llSetStatus(int status, int value)
1253 { 1389 {
1390 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
1391 return;
1254 m_host.AddScriptLPS(1); 1392 m_host.AddScriptLPS(1);
1255 1393
1256 int statusrotationaxis = 0; 1394 int statusrotationaxis = 0;
@@ -1274,6 +1412,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1274 if (!allow) 1412 if (!allow)
1275 return; 1413 return;
1276 1414
1415 if (m_host.ParentGroup.RootPart.PhysActor != null &&
1416 m_host.ParentGroup.RootPart.PhysActor.IsPhysical)
1417 return;
1418
1277 m_host.ScriptSetPhysicsStatus(true); 1419 m_host.ScriptSetPhysicsStatus(true);
1278 } 1420 }
1279 else 1421 else
@@ -1474,6 +1616,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1474 { 1616 {
1475 m_host.AddScriptLPS(1); 1617 m_host.AddScriptLPS(1);
1476 1618
1619 SetColor(m_host, color, face);
1620 }
1621
1622 protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
1623 {
1624 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1625 return;
1626
1627 Primitive.TextureEntry tex = part.Shape.Textures;
1628 Color4 texcolor;
1629 if (face >= 0 && face < GetNumberOfSides(part))
1630 {
1631 texcolor = tex.CreateFace((uint)face).RGBA;
1632 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1633 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1634 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1635 tex.FaceTextures[face].RGBA = texcolor;
1636 part.UpdateTextureEntry(tex.GetBytes());
1637 return;
1638 }
1639 else if (face == ScriptBaseClass.ALL_SIDES)
1640 {
1641 for (uint i = 0; i < GetNumberOfSides(part); i++)
1642 {
1643 if (tex.FaceTextures[i] != null)
1644 {
1645 texcolor = tex.FaceTextures[i].RGBA;
1646 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1647 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1648 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1649 tex.FaceTextures[i].RGBA = texcolor;
1650 }
1651 texcolor = tex.DefaultTexture.RGBA;
1652 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1653 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1654 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1655 tex.DefaultTexture.RGBA = texcolor;
1656 }
1657 part.UpdateTextureEntry(tex.GetBytes());
1658 return;
1659 }
1660
1477 if (face == ScriptBaseClass.ALL_SIDES) 1661 if (face == ScriptBaseClass.ALL_SIDES)
1478 face = SceneObjectPart.ALL_SIDES; 1662 face = SceneObjectPart.ALL_SIDES;
1479 1663
@@ -1482,6 +1666,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1482 1666
1483 public void SetTexGen(SceneObjectPart part, int face,int style) 1667 public void SetTexGen(SceneObjectPart part, int face,int style)
1484 { 1668 {
1669 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1670 return;
1671
1485 Primitive.TextureEntry tex = part.Shape.Textures; 1672 Primitive.TextureEntry tex = part.Shape.Textures;
1486 MappingType textype; 1673 MappingType textype;
1487 textype = MappingType.Default; 1674 textype = MappingType.Default;
@@ -1512,6 +1699,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1512 1699
1513 public void SetGlow(SceneObjectPart part, int face, float glow) 1700 public void SetGlow(SceneObjectPart part, int face, float glow)
1514 { 1701 {
1702 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1703 return;
1704
1515 Primitive.TextureEntry tex = part.Shape.Textures; 1705 Primitive.TextureEntry tex = part.Shape.Textures;
1516 if (face >= 0 && face < GetNumberOfSides(part)) 1706 if (face >= 0 && face < GetNumberOfSides(part))
1517 { 1707 {
@@ -1537,6 +1727,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1537 1727
1538 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump) 1728 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
1539 { 1729 {
1730 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1731 return;
1540 1732
1541 Shininess sval = new Shininess(); 1733 Shininess sval = new Shininess();
1542 1734
@@ -1587,6 +1779,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1587 1779
1588 public void SetFullBright(SceneObjectPart part, int face, bool bright) 1780 public void SetFullBright(SceneObjectPart part, int face, bool bright)
1589 { 1781 {
1782 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1783 return;
1784
1590 Primitive.TextureEntry tex = part.Shape.Textures; 1785 Primitive.TextureEntry tex = part.Shape.Textures;
1591 if (face >= 0 && face < GetNumberOfSides(part)) 1786 if (face >= 0 && face < GetNumberOfSides(part))
1592 { 1787 {
@@ -1647,13 +1842,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1647 m_host.AddScriptLPS(1); 1842 m_host.AddScriptLPS(1);
1648 1843
1649 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1844 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1650 1845 if (parts.Count > 0)
1651 foreach (SceneObjectPart part in parts) 1846 {
1652 SetAlpha(part, alpha, face); 1847 try
1848 {
1849 foreach (SceneObjectPart part in parts)
1850 SetAlpha(part, alpha, face);
1851 }
1852 finally
1853 {
1854 }
1855 }
1653 } 1856 }
1654 1857
1655 protected void SetAlpha(SceneObjectPart part, double alpha, int face) 1858 protected void SetAlpha(SceneObjectPart part, double alpha, int face)
1656 { 1859 {
1860 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1861 return;
1862
1657 Primitive.TextureEntry tex = part.Shape.Textures; 1863 Primitive.TextureEntry tex = part.Shape.Textures;
1658 Color4 texcolor; 1864 Color4 texcolor;
1659 if (face >= 0 && face < GetNumberOfSides(part)) 1865 if (face >= 0 && face < GetNumberOfSides(part))
@@ -1706,7 +1912,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1706 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction, 1912 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
1707 float wind, float tension, LSL_Vector Force) 1913 float wind, float tension, LSL_Vector Force)
1708 { 1914 {
1709 if (part == null) 1915 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1710 return; 1916 return;
1711 1917
1712 if (flexi) 1918 if (flexi)
@@ -1747,7 +1953,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1747 /// <param name="falloff"></param> 1953 /// <param name="falloff"></param>
1748 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff) 1954 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
1749 { 1955 {
1750 if (part == null) 1956 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1751 return; 1957 return;
1752 1958
1753 if (light) 1959 if (light)
@@ -1780,11 +1986,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1780 Primitive.TextureEntry tex = part.Shape.Textures; 1986 Primitive.TextureEntry tex = part.Shape.Textures;
1781 Color4 texcolor; 1987 Color4 texcolor;
1782 LSL_Vector rgb = new LSL_Vector(); 1988 LSL_Vector rgb = new LSL_Vector();
1989 int nsides = GetNumberOfSides(part);
1990
1783 if (face == ScriptBaseClass.ALL_SIDES) 1991 if (face == ScriptBaseClass.ALL_SIDES)
1784 { 1992 {
1785 int i; 1993 int i;
1786 1994 for (i = 0; i < nsides; i++)
1787 for (i = 0 ; i < GetNumberOfSides(part); i++)
1788 { 1995 {
1789 texcolor = tex.GetFace((uint)i).RGBA; 1996 texcolor = tex.GetFace((uint)i).RGBA;
1790 rgb.x += texcolor.R; 1997 rgb.x += texcolor.R;
@@ -1792,14 +1999,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1792 rgb.z += texcolor.B; 1999 rgb.z += texcolor.B;
1793 } 2000 }
1794 2001
1795 rgb.x /= (float)GetNumberOfSides(part); 2002 float invnsides = 1.0f / (float)nsides;
1796 rgb.y /= (float)GetNumberOfSides(part); 2003
1797 rgb.z /= (float)GetNumberOfSides(part); 2004 rgb.x *= invnsides;
2005 rgb.y *= invnsides;
2006 rgb.z *= invnsides;
1798 2007
1799 return rgb; 2008 return rgb;
1800 } 2009 }
1801 2010 if (face >= 0 && face < nsides)
1802 if (face >= 0 && face < GetNumberOfSides(part))
1803 { 2011 {
1804 texcolor = tex.GetFace((uint)face).RGBA; 2012 texcolor = tex.GetFace((uint)face).RGBA;
1805 rgb.x = texcolor.R; 2013 rgb.x = texcolor.R;
@@ -1826,15 +2034,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1826 m_host.AddScriptLPS(1); 2034 m_host.AddScriptLPS(1);
1827 2035
1828 List<SceneObjectPart> parts = GetLinkParts(linknumber); 2036 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1829 2037 if (parts.Count > 0)
1830 foreach (SceneObjectPart part in parts) 2038 {
1831 SetTexture(part, texture, face); 2039 try
1832 2040 {
2041 foreach (SceneObjectPart part in parts)
2042 SetTexture(part, texture, face);
2043 }
2044 finally
2045 {
2046 }
2047 }
1833 ScriptSleep(200); 2048 ScriptSleep(200);
1834 } 2049 }
1835 2050
1836 protected void SetTexture(SceneObjectPart part, string texture, int face) 2051 protected void SetTexture(SceneObjectPart part, string texture, int face)
1837 { 2052 {
2053 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2054 return;
2055
1838 UUID textureID = new UUID(); 2056 UUID textureID = new UUID();
1839 2057
1840 textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture); 2058 textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture);
@@ -1879,6 +2097,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1879 2097
1880 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) 2098 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
1881 { 2099 {
2100 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2101 return;
2102
1882 Primitive.TextureEntry tex = part.Shape.Textures; 2103 Primitive.TextureEntry tex = part.Shape.Textures;
1883 if (face >= 0 && face < GetNumberOfSides(part)) 2104 if (face >= 0 && face < GetNumberOfSides(part))
1884 { 2105 {
@@ -1915,6 +2136,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1915 2136
1916 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) 2137 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
1917 { 2138 {
2139 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2140 return;
2141
1918 Primitive.TextureEntry tex = part.Shape.Textures; 2142 Primitive.TextureEntry tex = part.Shape.Textures;
1919 if (face >= 0 && face < GetNumberOfSides(part)) 2143 if (face >= 0 && face < GetNumberOfSides(part))
1920 { 2144 {
@@ -1951,6 +2175,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1951 2175
1952 protected void RotateTexture(SceneObjectPart part, double rotation, int face) 2176 protected void RotateTexture(SceneObjectPart part, double rotation, int face)
1953 { 2177 {
2178 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2179 return;
2180
1954 Primitive.TextureEntry tex = part.Shape.Textures; 2181 Primitive.TextureEntry tex = part.Shape.Textures;
1955 if (face >= 0 && face < GetNumberOfSides(part)) 2182 if (face >= 0 && face < GetNumberOfSides(part))
1956 { 2183 {
@@ -2092,7 +2319,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2092 return end; 2319 return end;
2093 } 2320 }
2094 2321
2095 protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos) 2322 protected LSL_Vector GetSetPosTarget(SceneObjectPart part, LSL_Vector targetPos, LSL_Vector fromPos, bool adjust)
2096 { 2323 {
2097 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) 2324 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2098 return fromPos; 2325 return fromPos;
@@ -2108,9 +2335,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2108 if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0) 2335 if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
2109 targetPos.z = ground; 2336 targetPos.z = ground;
2110 } 2337 }
2111 LSL_Vector real_vec = SetPosAdjust(fromPos, targetPos); 2338 if (adjust)
2339 return SetPosAdjust(fromPos, targetPos);
2112 2340
2113 return real_vec; 2341 return targetPos;
2114 } 2342 }
2115 2343
2116 /// <summary> 2344 /// <summary>
@@ -2121,27 +2349,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2121 /// <param name="adjust">if TRUE, will cap the distance to 10m.</param> 2349 /// <param name="adjust">if TRUE, will cap the distance to 10m.</param>
2122 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust) 2350 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos, bool adjust)
2123 { 2351 {
2124 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos) 2352 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2353 return;
2354
2125 LSL_Vector currentPos = GetPartLocalPos(part); 2355 LSL_Vector currentPos = GetPartLocalPos(part);
2356 LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos, adjust);
2126 2357
2127 float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
2128 bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
2129 2358
2130 if (part.ParentGroup.RootPart == part) 2359 if (part.ParentGroup.RootPart == part)
2131 { 2360 {
2132 if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
2133 targetPos.z = ground;
2134 SceneObjectGroup parent = part.ParentGroup; 2361 SceneObjectGroup parent = part.ParentGroup;
2135 parent.UpdateGroupPosition(!adjust ? targetPos : 2362 if (!World.Permissions.CanObjectEntry(parent.UUID, false, (Vector3)toPos))
2136 SetPosAdjust(currentPos, targetPos)); 2363 return;
2364 Util.FireAndForget(delegate(object x) {
2365 parent.UpdateGroupPosition((Vector3)toPos);
2366 });
2137 } 2367 }
2138 else 2368 else
2139 { 2369 {
2140 part.OffsetPosition = !adjust ? targetPos : 2370 part.OffsetPosition = (Vector3)toPos;
2141 SetPosAdjust(currentPos, targetPos); 2371// SceneObjectGroup parent = part.ParentGroup;
2142 SceneObjectGroup parent = part.ParentGroup; 2372// parent.HasGroupChanged = true;
2143 parent.HasGroupChanged = true; 2373// parent.ScheduleGroupForTerseUpdate();
2144 parent.ScheduleGroupForTerseUpdate(); 2374 part.ScheduleTerseUpdate();
2145 } 2375 }
2146 } 2376 }
2147 2377
@@ -2170,13 +2400,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2170 else 2400 else
2171 { 2401 {
2172 if (part.ParentGroup.IsAttachment) 2402 if (part.ParentGroup.IsAttachment)
2173 {
2174 pos = part.AttachedPos; 2403 pos = part.AttachedPos;
2175 }
2176 else 2404 else
2177 {
2178 pos = part.AbsolutePosition; 2405 pos = part.AbsolutePosition;
2179 }
2180 } 2406 }
2181 2407
2182// m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos); 2408// m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
@@ -2188,8 +2414,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2188 { 2414 {
2189 m_host.AddScriptLPS(1); 2415 m_host.AddScriptLPS(1);
2190 2416
2417
2418 // Teravus: if (m_host.ParentID == 0) is bug code because the ParentID for the Avatar will cause this to be nonzero for root prim attachments
2419 // which is then treated like a child prim rotation and it's offset gets cumulatively multiplied against.
2420 // to fix the scripted rotations we also have to check to see if the root part localid is the same as the host's localid.
2421 // RootPart != null should shortcircuit
2422
2191 // try to let this work as in SL... 2423 // try to let this work as in SL...
2192 if (m_host.ParentID == 0) 2424 if (m_host.ParentID == 0 || (m_host.ParentGroup != null && m_host == m_host.ParentGroup.RootPart))
2193 { 2425 {
2194 // special case: If we are root, rotate complete SOG to new rotation 2426 // special case: If we are root, rotate complete SOG to new rotation
2195 SetRot(m_host, rot); 2427 SetRot(m_host, rot);
@@ -2216,25 +2448,46 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2216 2448
2217 protected void SetRot(SceneObjectPart part, Quaternion rot) 2449 protected void SetRot(SceneObjectPart part, Quaternion rot)
2218 { 2450 {
2219 part.UpdateRotation(rot); 2451 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2220 // Update rotation does not move the object in the physics scene if it's a linkset. 2452 return;
2221 2453
2222//KF: Do NOT use this next line if using ODE physics engine. This need a switch based on .ini Phys Engine type 2454 bool isroot = (part == part.ParentGroup.RootPart);
2223// part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition; 2455 bool isphys;
2224 2456
2225 // So, after thinking about this for a bit, the issue with the part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition line
2226 // is it isn't compatible with vehicles because it causes the vehicle body to have to be broken down and rebuilt
2227 // It's perfectly okay when the object is not an active physical body though.
2228 // So, part.ParentGroup.ResetChildPrimPhysicsPositions(); does the thing that Kitto is warning against
2229 // but only if the object is not physial and active. This is important for rotating doors.
2230 // without the absoluteposition = absoluteposition happening, the doors do not move in the physics
2231 // scene
2232 PhysicsActor pa = part.PhysActor; 2457 PhysicsActor pa = part.PhysActor;
2233 2458
2234 if (pa != null && !pa.IsPhysical) 2459 // keep using physactor ideia of isphysical
2460 // it should be SOP ideia of that
2461 // not much of a issue with ubitODE
2462 if (pa != null && pa.IsPhysical)
2463 isphys = true;
2464 else
2465 isphys = false;
2466
2467 // SL doesn't let scripts rotate root of physical linksets
2468 if (isroot && isphys)
2469 return;
2470
2471 part.UpdateRotation(rot);
2472
2473 // Update rotation does not move the object in the physics engine if it's a non physical linkset
2474 // so do a nasty update of parts positions if is a root part rotation
2475 if (isroot && pa != null) // with if above implies non physical root part
2235 { 2476 {
2236 part.ParentGroup.ResetChildPrimPhysicsPositions(); 2477 part.ParentGroup.ResetChildPrimPhysicsPositions();
2237 } 2478 }
2479 else // fix sitting avatars. This is only needed bc of how we link avas to child parts, not root part
2480 {
2481 List<ScenePresence> sittingavas = part.ParentGroup.GetLinkedAvatars();
2482 if (sittingavas.Count > 0)
2483 {
2484 foreach (ScenePresence av in sittingavas)
2485 {
2486 if (isroot || part.LocalId == av.ParentID)
2487 av.SendTerseUpdateToAllClients();
2488 }
2489 }
2490 }
2238 } 2491 }
2239 2492
2240 /// <summary> 2493 /// <summary>
@@ -2251,6 +2504,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2251 2504
2252 m_host.AddScriptLPS(1); 2505 m_host.AddScriptLPS(1);
2253 Quaternion q = m_host.GetWorldRotation(); 2506 Quaternion q = m_host.GetWorldRotation();
2507
2508 if (m_host.ParentGroup != null && m_host.ParentGroup.AttachmentPoint != 0)
2509 {
2510 ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
2511 if (avatar != null)
2512 {
2513 if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
2514 q = avatar.CameraRotation * q; // Mouselook
2515 else
2516 q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
2517 }
2518 }
2519
2254 return new LSL_Rotation(q.X, q.Y, q.Z, q.W); 2520 return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
2255 } 2521 }
2256 2522
@@ -2278,14 +2544,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2278 return new LSL_Rotation(q); 2544 return new LSL_Rotation(q);
2279 } 2545 }
2280 2546
2281 return new LSL_Rotation(part.GetWorldRotation()); 2547 q = part.GetWorldRotation();
2548 if (part.ParentGroup.AttachmentPoint != 0)
2549 {
2550 ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
2551 if (avatar != null)
2552 {
2553 if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
2554 q = avatar.CameraRotation * q; // Mouselook
2555 else
2556 q = avatar.Rotation * q; // Currently infrequently updated so may be inaccurate
2557 }
2558 }
2559
2560 return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
2282 } 2561 }
2283 2562
2284 public LSL_Rotation llGetLocalRot() 2563 public LSL_Rotation llGetLocalRot()
2285 { 2564 {
2286 m_host.AddScriptLPS(1); 2565 return GetPartLocalRot(m_host);
2566 }
2287 2567
2288 return new LSL_Rotation(m_host.RotationOffset); 2568 private LSL_Rotation GetPartLocalRot(SceneObjectPart part)
2569 {
2570 m_host.AddScriptLPS(1);
2571 Quaternion rot = part.RotationOffset;
2572 return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W);
2289 } 2573 }
2290 2574
2291 public void llSetForce(LSL_Vector force, int local) 2575 public void llSetForce(LSL_Vector force, int local)
@@ -2365,16 +2649,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2365 m_host.ApplyImpulse(v, local != 0); 2649 m_host.ApplyImpulse(v, local != 0);
2366 } 2650 }
2367 2651
2652
2368 public void llApplyRotationalImpulse(LSL_Vector force, int local) 2653 public void llApplyRotationalImpulse(LSL_Vector force, int local)
2369 { 2654 {
2370 m_host.AddScriptLPS(1); 2655 m_host.AddScriptLPS(1);
2371 m_host.ApplyAngularImpulse(force, local != 0); 2656 m_host.ParentGroup.RootPart.ApplyAngularImpulse(force, local != 0);
2372 } 2657 }
2373 2658
2374 public void llSetTorque(LSL_Vector torque, int local) 2659 public void llSetTorque(LSL_Vector torque, int local)
2375 { 2660 {
2376 m_host.AddScriptLPS(1); 2661 m_host.AddScriptLPS(1);
2377 m_host.SetAngularImpulse(torque, local != 0); 2662 m_host.ParentGroup.RootPart.SetAngularImpulse(torque, local != 0);
2378 } 2663 }
2379 2664
2380 public LSL_Vector llGetTorque() 2665 public LSL_Vector llGetTorque()
@@ -2391,20 +2676,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2391 llSetTorque(torque, local); 2676 llSetTorque(torque, local);
2392 } 2677 }
2393 2678
2679 public void llSetVelocity(LSL_Vector vel, int local)
2680 {
2681 m_host.AddScriptLPS(1);
2682 m_host.SetVelocity(new Vector3((float)vel.x, (float)vel.y, (float)vel.z), local != 0);
2683 }
2684
2394 public LSL_Vector llGetVel() 2685 public LSL_Vector llGetVel()
2395 { 2686 {
2396 m_host.AddScriptLPS(1); 2687 m_host.AddScriptLPS(1);
2397 2688
2398 Vector3 vel; 2689 Vector3 vel = Vector3.Zero;
2399 2690
2400 if (m_host.ParentGroup.IsAttachment) 2691 if (m_host.ParentGroup.IsAttachment)
2401 { 2692 {
2402 ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar); 2693 ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
2403 vel = avatar.Velocity; 2694 if (avatar != null)
2695 vel = avatar.Velocity;
2404 } 2696 }
2405 else 2697 else
2406 { 2698 {
2407 vel = m_host.Velocity; 2699 vel = m_host.ParentGroup.RootPart.Velocity;
2408 } 2700 }
2409 2701
2410 return new LSL_Vector(vel); 2702 return new LSL_Vector(vel);
@@ -2417,11 +2709,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2417 return new LSL_Vector(m_host.Acceleration); 2709 return new LSL_Vector(m_host.Acceleration);
2418 } 2710 }
2419 2711
2420 public LSL_Vector llGetOmega() 2712 public void llSetAngularVelocity(LSL_Vector avel, int local)
2421 { 2713 {
2422 m_host.AddScriptLPS(1); 2714 m_host.AddScriptLPS(1);
2715 m_host.SetAngularVelocity(new Vector3((float)avel.x, (float)avel.y, (float)avel.z), local != 0);
2716 }
2423 2717
2424 return new LSL_Vector(m_host.AngularVelocity); 2718 public LSL_Vector llGetOmega()
2719 {
2720 m_host.AddScriptLPS(1);
2721 Vector3 avel = m_host.AngularVelocity;
2722 return new LSL_Vector(avel.X, avel.Y, avel.Z);
2425 } 2723 }
2426 2724
2427 public LSL_Float llGetTimeOfDay() 2725 public LSL_Float llGetTimeOfDay()
@@ -2782,7 +3080,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2782 return src.ToLower(); 3080 return src.ToLower();
2783 } 3081 }
2784 3082
2785 public void llGiveMoney(string destination, int amount) 3083 public LSL_Integer llGiveMoney(string destination, int amount)
2786 { 3084 {
2787 Util.FireAndForget(x => 3085 Util.FireAndForget(x =>
2788 { 3086 {
@@ -2814,8 +3112,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2814 } 3112 }
2815 3113
2816 money.ObjectGiveMoney( 3114 money.ObjectGiveMoney(
2817 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount); 3115 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount,UUID.Zero);
2818 }); 3116 });
3117
3118 return 0;
2819 } 3119 }
2820 3120
2821 public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset) 3121 public void llMakeExplosion(int particles, double scale, double vel, double lifetime, double arc, string texture, LSL_Vector offset)
@@ -2894,13 +3194,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2894 new_group.RootPart.UUID.ToString()) }, 3194 new_group.RootPart.UUID.ToString()) },
2895 new DetectParams[0])); 3195 new DetectParams[0]));
2896 3196
2897 float groupmass = new_group.GetMass(); 3197 // do recoil
3198 SceneObjectGroup hostgrp = m_host.ParentGroup;
3199 if (hostgrp == null)
3200 return;
3201
3202 if (hostgrp.IsAttachment) // don't recoil avatars
3203 return;
2898 3204
2899 PhysicsActor pa = new_group.RootPart.PhysActor; 3205 PhysicsActor pa = new_group.RootPart.PhysActor;
2900 3206
2901 //Recoil. 3207 //Recoil.
2902 if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero) 3208 if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
2903 { 3209 {
3210 float groupmass = new_group.GetMass();
2904 Vector3 recoil = -vel * groupmass * m_recoilScaleFactor; 3211 Vector3 recoil = -vel * groupmass * m_recoilScaleFactor;
2905 if (recoil != Vector3.Zero) 3212 if (recoil != Vector3.Zero)
2906 { 3213 {
@@ -2908,6 +3215,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2908 } 3215 }
2909 } 3216 }
2910 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) 3217 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
3218 return;
3219
2911 }); 3220 });
2912 3221
2913 //ScriptSleep((int)((groupmass * velmag) / 10)); 3222 //ScriptSleep((int)((groupmass * velmag) / 10));
@@ -2922,35 +3231,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2922 public void llLookAt(LSL_Vector target, double strength, double damping) 3231 public void llLookAt(LSL_Vector target, double strength, double damping)
2923 { 3232 {
2924 m_host.AddScriptLPS(1); 3233 m_host.AddScriptLPS(1);
2925 // Determine where we are looking from
2926 LSL_Vector from = llGetPos();
2927 3234
2928 // Work out the normalised vector from the source to the target 3235 // Get the normalized vector to the target
2929 LSL_Vector delta = llVecNorm(target - from); 3236 LSL_Vector d1 = llVecNorm(target - llGetPos());
2930 LSL_Vector angle = new LSL_Vector(0,0,0);
2931 3237
2932 // Calculate the yaw 3238 // Get the bearing (yaw)
2933 // subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system 3239 LSL_Vector a1 = new LSL_Vector(0,0,0);
2934 angle.x = llAtan2(delta.z, delta.y) - ScriptBaseClass.PI_BY_TWO; 3240 a1.z = llAtan2(d1.y, d1.x);
2935 3241
2936 // Calculate pitch 3242 // Get the elevation (pitch)
2937 angle.y = llAtan2(delta.x, llSqrt((delta.y * delta.y) + (delta.z * delta.z))); 3243 LSL_Vector a2 = new LSL_Vector(0,0,0);
3244 a2.y= -llAtan2(d1.z, llSqrt((d1.x * d1.x) + (d1.y * d1.y)));
2938 3245
2939 // we need to convert from a vector describing 3246 LSL_Rotation r1 = llEuler2Rot(a1);
2940 // the angles of rotation in radians into rotation value 3247 LSL_Rotation r2 = llEuler2Rot(a2);
2941 LSL_Rotation rot = llEuler2Rot(angle); 3248 LSL_Rotation r3 = new LSL_Rotation(0.000000, 0.707107, 0.000000, 0.707107);
2942
2943 // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
2944 // set the rotation of the object, copy that behavior
2945 PhysicsActor pa = m_host.PhysActor;
2946 3249
2947 if (strength == 0 || pa == null || !pa.IsPhysical) 3250 if (m_host.PhysActor == null || !m_host.PhysActor.IsPhysical)
2948 { 3251 {
2949 llSetRot(rot); 3252 // Do nothing if either value is 0 (this has been checked in SL)
3253 if (strength <= 0.0 || damping <= 0.0)
3254 return;
3255
3256 llSetRot(r3 * r2 * r1);
2950 } 3257 }
2951 else 3258 else
2952 { 3259 {
2953 m_host.StartLookAt(rot, (float)strength, (float)damping); 3260 if (strength == 0)
3261 {
3262 llSetRot(r3 * r2 * r1);
3263 return;
3264 }
3265
3266 m_host.StartLookAt((Quaternion)(r3 * r2 * r1), (float)strength, (float)damping);
2954 } 3267 }
2955 } 3268 }
2956 3269
@@ -2997,17 +3310,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2997 } 3310 }
2998 else 3311 else
2999 { 3312 {
3000 if (m_host.IsRoot) 3313 // new SL always returns object mass
3001 { 3314// if (m_host.IsRoot)
3315// {
3002 return m_host.ParentGroup.GetMass(); 3316 return m_host.ParentGroup.GetMass();
3003 } 3317// }
3004 else 3318// else
3005 { 3319// {
3006 return m_host.GetMass(); 3320// return m_host.GetMass();
3007 } 3321// }
3008 } 3322 }
3009 } 3323 }
3010 3324
3325
3326 public LSL_Float llGetMassMKS()
3327 {
3328 return 100f * llGetMass();
3329 }
3330
3011 public void llCollisionFilter(string name, string id, int accept) 3331 public void llCollisionFilter(string name, string id, int accept)
3012 { 3332 {
3013 m_host.AddScriptLPS(1); 3333 m_host.AddScriptLPS(1);
@@ -3055,8 +3375,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3055 { 3375 {
3056 // Unregister controls from Presence 3376 // Unregister controls from Presence
3057 presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID); 3377 presence.UnRegisterControlEventsToScript(m_host.LocalId, m_item.ItemID);
3058 // Remove Take Control permission.
3059 m_item.PermsMask &= ~ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3060 } 3378 }
3061 } 3379 }
3062 } 3380 }
@@ -3084,7 +3402,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3084 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3402 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3085 3403
3086 if (attachmentsModule != null) 3404 if (attachmentsModule != null)
3087 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, true); 3405 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true, false, true);
3088 else 3406 else
3089 return false; 3407 return false;
3090 } 3408 }
@@ -3114,9 +3432,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3114 { 3432 {
3115 m_host.AddScriptLPS(1); 3433 m_host.AddScriptLPS(1);
3116 3434
3117// if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
3118// return;
3119
3120 if (m_item.PermsGranter != m_host.OwnerID) 3435 if (m_item.PermsGranter != m_host.OwnerID)
3121 return; 3436 return;
3122 3437
@@ -3159,6 +3474,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3159 3474
3160 public void llInstantMessage(string user, string message) 3475 public void llInstantMessage(string user, string message)
3161 { 3476 {
3477 UUID result;
3478 if (!UUID.TryParse(user, out result) || result == UUID.Zero)
3479 {
3480 ShoutError("An invalid key was passed to llInstantMessage");
3481 ScriptSleep(2000);
3482 return;
3483 }
3484
3485
3162 m_host.AddScriptLPS(1); 3486 m_host.AddScriptLPS(1);
3163 3487
3164 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. 3488 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
@@ -3173,14 +3497,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3173 UUID friendTransactionID = UUID.Random(); 3497 UUID friendTransactionID = UUID.Random();
3174 3498
3175 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 3499 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
3176 3500
3177 GridInstantMessage msg = new GridInstantMessage(); 3501 GridInstantMessage msg = new GridInstantMessage();
3178 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; 3502 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
3179 msg.toAgentID = new Guid(user); // toAgentID.Guid; 3503 msg.toAgentID = new Guid(user); // toAgentID.Guid;
3180 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here 3504 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
3181// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message); 3505// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
3182// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString()); 3506// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
3183 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp; 3507// DateTime dt = DateTime.UtcNow;
3508//
3509// // Ticks from UtcNow, but make it look like local. Evil, huh?
3510// dt = DateTime.SpecifyKind(dt, DateTimeKind.Local);
3511//
3512// try
3513// {
3514// // Convert that to the PST timezone
3515// TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
3516// dt = TimeZoneInfo.ConvertTime(dt, timeZoneInfo);
3517// }
3518// catch
3519// {
3520// // No logging here, as it could be VERY spammy
3521// }
3522//
3523// // And make it look local again to fool the unix time util
3524// dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
3525
3526 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
3527
3184 //if (client != null) 3528 //if (client != null)
3185 //{ 3529 //{
3186 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName; 3530 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
@@ -3194,10 +3538,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3194 msg.message = message.Substring(0, 1024); 3538 msg.message = message.Substring(0, 1024);
3195 else 3539 else
3196 msg.message = message; 3540 msg.message = message;
3197 msg.dialog = (byte)19; // messgage from script ??? // dialog; 3541 msg.dialog = (byte)19; // MessageFromObject
3198 msg.fromGroup = false;// fromGroup; 3542 msg.fromGroup = false;// fromGroup;
3199 msg.offline = (byte)0; //offline; 3543 msg.offline = (byte)0; //offline;
3200 msg.ParentEstateID = 0; //ParentEstateID; 3544 msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
3201 msg.Position = new Vector3(m_host.AbsolutePosition); 3545 msg.Position = new Vector3(m_host.AbsolutePosition);
3202 msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; 3546 msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid;
3203 3547
@@ -3229,7 +3573,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3229 } 3573 }
3230 3574
3231 emailModule.SendEmail(m_host.UUID, address, subject, message); 3575 emailModule.SendEmail(m_host.UUID, address, subject, message);
3232 llSleep(EMAIL_PAUSE_TIME); 3576 ScriptSleep(EMAIL_PAUSE_TIME * 1000);
3233 } 3577 }
3234 3578
3235 public void llGetNextEmail(string address, string subject) 3579 public void llGetNextEmail(string address, string subject)
@@ -3475,7 +3819,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3475 implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS | 3819 implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
3476 ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | 3820 ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
3477 ScriptBaseClass.PERMISSION_CONTROL_CAMERA | 3821 ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
3822 ScriptBaseClass.PERMISSION_TRACK_CAMERA |
3478 ScriptBaseClass.PERMISSION_ATTACH; 3823 ScriptBaseClass.PERMISSION_ATTACH;
3824
3479 } 3825 }
3480 else 3826 else
3481 { 3827 {
@@ -3492,15 +3838,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3492 if (World.GetExtraSetting("auto_grant_attach_perms") == "true") 3838 if (World.GetExtraSetting("auto_grant_attach_perms") == "true")
3493 implicitPerms = ScriptBaseClass.PERMISSION_ATTACH; 3839 implicitPerms = ScriptBaseClass.PERMISSION_ATTACH;
3494 } 3840 }
3841 if (World.GetExtraSetting("auto_grant_all_perms") == "true")
3842 {
3843 implicitPerms = perm;
3844 }
3495 } 3845 }
3496 3846
3497 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3847 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3498 { 3848 {
3499 lock (m_host.TaskInventory) 3849 m_host.TaskInventory.LockItemsForWrite(true);
3500 { 3850 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3501 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID; 3851 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3502 m_host.TaskInventory[m_item.ItemID].PermsMask = perm; 3852 m_host.TaskInventory.LockItemsForWrite(false);
3503 }
3504 3853
3505 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams( 3854 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3506 "run_time_permissions", new Object[] { 3855 "run_time_permissions", new Object[] {
@@ -3543,11 +3892,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3543 3892
3544 if (!m_waitingForScriptAnswer) 3893 if (!m_waitingForScriptAnswer)
3545 { 3894 {
3546 lock (m_host.TaskInventory) 3895 m_host.TaskInventory.LockItemsForWrite(true);
3547 { 3896 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3548 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID; 3897 m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
3549 m_host.TaskInventory[m_item.ItemID].PermsMask = 0; 3898 m_host.TaskInventory.LockItemsForWrite(false);
3550 }
3551 3899
3552 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3900 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3553 m_waitingForScriptAnswer=true; 3901 m_waitingForScriptAnswer=true;
@@ -3576,14 +3924,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3576 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3924 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3577 llReleaseControls(); 3925 llReleaseControls();
3578 3926
3579 lock (m_host.TaskInventory) 3927 m_host.TaskInventory.LockItemsForWrite(true);
3580 { 3928 m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
3581 m_host.TaskInventory[m_item.ItemID].PermsMask = answer; 3929 m_host.TaskInventory.LockItemsForWrite(false);
3582 } 3930
3583 3931 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3584 m_ScriptEngine.PostScriptEvent( 3932 "run_time_permissions", new Object[] {
3585 m_item.ItemID, 3933 new LSL_Integer(answer) },
3586 new EventParams("run_time_permissions", new Object[] { new LSL_Integer(answer) }, new DetectParams[0])); 3934 new DetectParams[0]));
3587 } 3935 }
3588 3936
3589 public LSL_String llGetPermissionsKey() 3937 public LSL_String llGetPermissionsKey()
@@ -3622,14 +3970,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3622 public void llSetLinkColor(int linknumber, LSL_Vector color, int face) 3970 public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
3623 { 3971 {
3624 List<SceneObjectPart> parts = GetLinkParts(linknumber); 3972 List<SceneObjectPart> parts = GetLinkParts(linknumber);
3625 3973 if (parts.Count > 0)
3626 foreach (SceneObjectPart part in parts) 3974 {
3627 part.SetFaceColorAlpha(face, color, null); 3975 try
3976 {
3977 foreach (SceneObjectPart part in parts)
3978 part.SetFaceColorAlpha(face, color, null);
3979 }
3980 finally
3981 {
3982 }
3983 }
3628 } 3984 }
3629 3985
3630 public void llCreateLink(string target, int parent) 3986 public void llCreateLink(string target, int parent)
3631 { 3987 {
3632 m_host.AddScriptLPS(1); 3988 m_host.AddScriptLPS(1);
3989
3633 UUID targetID; 3990 UUID targetID;
3634 3991
3635 if (!UUID.TryParse(target, out targetID)) 3992 if (!UUID.TryParse(target, out targetID))
@@ -3735,10 +4092,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3735 // Restructuring Multiple Prims. 4092 // Restructuring Multiple Prims.
3736 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts); 4093 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
3737 parts.Remove(parentPrim.RootPart); 4094 parts.Remove(parentPrim.RootPart);
3738 foreach (SceneObjectPart part in parts) 4095 if (parts.Count > 0)
3739 { 4096 {
3740 parentPrim.DelinkFromGroup(part.LocalId, true); 4097 try
4098 {
4099 foreach (SceneObjectPart part in parts)
4100 {
4101 parentPrim.DelinkFromGroup(part.LocalId, true);
4102 }
4103 }
4104 finally
4105 {
4106 }
3741 } 4107 }
4108
3742 parentPrim.HasGroupChanged = true; 4109 parentPrim.HasGroupChanged = true;
3743 parentPrim.ScheduleGroupForFullUpdate(); 4110 parentPrim.ScheduleGroupForFullUpdate();
3744 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 4111 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
@@ -3747,12 +4114,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3747 { 4114 {
3748 SceneObjectPart newRoot = parts[0]; 4115 SceneObjectPart newRoot = parts[0];
3749 parts.Remove(newRoot); 4116 parts.Remove(newRoot);
3750 foreach (SceneObjectPart part in parts) 4117
4118 try
3751 { 4119 {
3752 // Required for linking 4120 foreach (SceneObjectPart part in parts)
3753 part.ClearUpdateSchedule(); 4121 {
3754 newRoot.ParentGroup.LinkToGroup(part.ParentGroup); 4122 part.ClearUpdateSchedule();
4123 newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
4124 }
3755 } 4125 }
4126 finally
4127 {
4128 }
4129
4130
3756 newRoot.ParentGroup.HasGroupChanged = true; 4131 newRoot.ParentGroup.HasGroupChanged = true;
3757 newRoot.ParentGroup.ScheduleGroupForFullUpdate(); 4132 newRoot.ParentGroup.ScheduleGroupForFullUpdate();
3758 } 4133 }
@@ -3772,6 +4147,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3772 public void llBreakAllLinks() 4147 public void llBreakAllLinks()
3773 { 4148 {
3774 m_host.AddScriptLPS(1); 4149 m_host.AddScriptLPS(1);
4150
4151 TaskInventoryItem item = m_item;
4152
4153 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4154 && !m_automaticLinkPermission)
4155 {
4156 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
4157 return;
4158 }
4159
3775 SceneObjectGroup parentPrim = m_host.ParentGroup; 4160 SceneObjectGroup parentPrim = m_host.ParentGroup;
3776 if (parentPrim.AttachmentPoint != 0) 4161 if (parentPrim.AttachmentPoint != 0)
3777 return; // Fail silently if attached 4162 return; // Fail silently if attached
@@ -3791,13 +4176,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3791 public LSL_String llGetLinkKey(int linknum) 4176 public LSL_String llGetLinkKey(int linknum)
3792 { 4177 {
3793 m_host.AddScriptLPS(1); 4178 m_host.AddScriptLPS(1);
4179 SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
4180 if (part != null)
4181 {
4182 return part.UUID.ToString();
4183 }
4184 else
4185 {
4186 if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
4187 {
4188 linknum -= (m_host.ParentGroup.PrimCount) + 1;
3794 4189
3795 ISceneEntity entity = GetLinkEntity(linknum); 4190 if (linknum < 0)
4191 return UUID.Zero.ToString();
3796 4192
3797 if (entity != null) 4193 List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
3798 return entity.UUID.ToString(); 4194 if (avatars.Count > linknum)
3799 else 4195 {
3800 return ScriptBaseClass.NULL_KEY; 4196 return avatars[linknum].UUID.ToString();
4197 }
4198 }
4199 return UUID.Zero.ToString();
4200 }
3801 } 4201 }
3802 4202
3803 /// <summary> 4203 /// <summary>
@@ -3856,17 +4256,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3856 m_host.AddScriptLPS(1); 4256 m_host.AddScriptLPS(1);
3857 int count = 0; 4257 int count = 0;
3858 4258
3859 lock (m_host.TaskInventory) 4259 m_host.TaskInventory.LockItemsForRead(true);
4260 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3860 { 4261 {
3861 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4262 if (inv.Value.Type == type || type == -1)
3862 { 4263 {
3863 if (inv.Value.Type == type || type == -1) 4264 count = count + 1;
3864 {
3865 count = count + 1;
3866 }
3867 } 4265 }
3868 } 4266 }
3869 4267
4268 m_host.TaskInventory.LockItemsForRead(false);
3870 return count; 4269 return count;
3871 } 4270 }
3872 4271
@@ -3875,16 +4274,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3875 m_host.AddScriptLPS(1); 4274 m_host.AddScriptLPS(1);
3876 ArrayList keys = new ArrayList(); 4275 ArrayList keys = new ArrayList();
3877 4276
3878 lock (m_host.TaskInventory) 4277 m_host.TaskInventory.LockItemsForRead(true);
4278 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3879 { 4279 {
3880 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4280 if (inv.Value.Type == type || type == -1)
3881 { 4281 {
3882 if (inv.Value.Type == type || type == -1) 4282 keys.Add(inv.Value.Name);
3883 {
3884 keys.Add(inv.Value.Name);
3885 }
3886 } 4283 }
3887 } 4284 }
4285 m_host.TaskInventory.LockItemsForRead(false);
3888 4286
3889 if (keys.Count == 0) 4287 if (keys.Count == 0)
3890 { 4288 {
@@ -3922,7 +4320,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3922 if (item == null) 4320 if (item == null)
3923 { 4321 {
3924 llSay(0, String.Format("Could not find object '{0}'", inventory)); 4322 llSay(0, String.Format("Could not find object '{0}'", inventory));
3925 throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); 4323 return;
4324// throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
3926 } 4325 }
3927 4326
3928 UUID objId = item.ItemID; 4327 UUID objId = item.ItemID;
@@ -3950,33 +4349,45 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3950 return; 4349 return;
3951 } 4350 }
3952 } 4351 }
4352
3953 // destination is an avatar 4353 // destination is an avatar
3954 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId); 4354 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId);
3955 4355
3956 if (agentItem == null) 4356 if (agentItem == null)
3957 return; 4357 return;
3958 4358
3959 if (m_TransferModule != null) 4359 byte[] bucket = new byte[1];
3960 { 4360 bucket[0] = (byte)item.Type;
3961 byte[] bucket = new byte[1]; 4361 //byte[] objBytes = agentItem.ID.GetBytes();
3962 bucket[0] = (byte)item.Type; 4362 //Array.Copy(objBytes, 0, bucket, 1, 16);
3963 4363
3964 GridInstantMessage msg = new GridInstantMessage(World, 4364 GridInstantMessage msg = new GridInstantMessage(World,
3965 m_host.OwnerID, m_host.Name, destId, 4365 m_host.OwnerID, m_host.Name, destId,
3966 (byte)InstantMessageDialog.TaskInventoryOffered, 4366 (byte)InstantMessageDialog.TaskInventoryOffered,
3967 false, item.Name+". "+m_host.Name+" is located at "+ 4367 false, item.Name+". "+m_host.Name+" is located at "+
3968 World.RegionInfo.RegionName+" "+ 4368 World.RegionInfo.RegionName+" "+
3969 m_host.AbsolutePosition.ToString(), 4369 m_host.AbsolutePosition.ToString(),
3970 agentItem.ID, true, m_host.AbsolutePosition, 4370 agentItem.ID, true, m_host.AbsolutePosition,
3971 bucket, true); 4371 bucket, true);
3972 4372
3973 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); 4373 ScenePresence sp;
3974 }
3975 4374
4375 if (World.TryGetScenePresence(destId, out sp))
4376 {
4377 sp.ControllingClient.SendInstantMessage(msg);
4378 }
4379 else
4380 {
4381 if (m_TransferModule != null)
4382 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
4383 }
4384
4385 //This delay should only occur when giving inventory to avatars.
3976 ScriptSleep(3000); 4386 ScriptSleep(3000);
3977 } 4387 }
3978 } 4388 }
3979 4389
4390 [DebuggerNonUserCode]
3980 public void llRemoveInventory(string name) 4391 public void llRemoveInventory(string name)
3981 { 4392 {
3982 m_host.AddScriptLPS(1); 4393 m_host.AddScriptLPS(1);
@@ -4031,109 +4442,115 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4031 { 4442 {
4032 m_host.AddScriptLPS(1); 4443 m_host.AddScriptLPS(1);
4033 4444
4034 UUID uuid = (UUID)id; 4445 UUID uuid;
4035 PresenceInfo pinfo = null; 4446 if (UUID.TryParse(id, out uuid))
4036 UserAccount account;
4037
4038 UserInfoCacheEntry ce;
4039 if (!m_userInfoCache.TryGetValue(uuid, out ce))
4040 { 4447 {
4041 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); 4448 PresenceInfo pinfo = null;
4042 if (account == null) 4449 UserAccount account;
4450
4451 UserInfoCacheEntry ce;
4452 if (!m_userInfoCache.TryGetValue(uuid, out ce))
4043 { 4453 {
4044 m_userInfoCache[uuid] = null; // Cache negative 4454 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
4045 return UUID.Zero.ToString(); 4455 if (account == null)
4046 } 4456 {
4457 m_userInfoCache[uuid] = null; // Cache negative
4458 return UUID.Zero.ToString();
4459 }
4047 4460
4048 4461
4049 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); 4462 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4050 if (pinfos != null && pinfos.Length > 0) 4463 if (pinfos != null && pinfos.Length > 0)
4051 {
4052 foreach (PresenceInfo p in pinfos)
4053 { 4464 {
4054 if (p.RegionID != UUID.Zero) 4465 foreach (PresenceInfo p in pinfos)
4055 { 4466 {
4056 pinfo = p; 4467 if (p.RegionID != UUID.Zero)
4468 {
4469 pinfo = p;
4470 }
4057 } 4471 }
4058 } 4472 }
4059 }
4060 4473
4061 ce = new UserInfoCacheEntry(); 4474 ce = new UserInfoCacheEntry();
4062 ce.time = Util.EnvironmentTickCount(); 4475 ce.time = Util.EnvironmentTickCount();
4063 ce.account = account; 4476 ce.account = account;
4064 ce.pinfo = pinfo; 4477 ce.pinfo = pinfo;
4065 } 4478 m_userInfoCache[uuid] = ce;
4066 else 4479 }
4067 { 4480 else
4068 if (ce == null) 4481 {
4069 return UUID.Zero.ToString(); 4482 if (ce == null)
4483 return UUID.Zero.ToString();
4070 4484
4071 account = ce.account; 4485 account = ce.account;
4072 pinfo = ce.pinfo; 4486 pinfo = ce.pinfo;
4073 } 4487 }
4074 4488
4075 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) 4489 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000)
4076 {
4077 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4078 if (pinfos != null && pinfos.Length > 0)
4079 { 4490 {
4080 foreach (PresenceInfo p in pinfos) 4491 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4492 if (pinfos != null && pinfos.Length > 0)
4081 { 4493 {
4082 if (p.RegionID != UUID.Zero) 4494 foreach (PresenceInfo p in pinfos)
4083 { 4495 {
4084 pinfo = p; 4496 if (p.RegionID != UUID.Zero)
4497 {
4498 pinfo = p;
4499 }
4085 } 4500 }
4086 } 4501 }
4087 } 4502 else
4088 else 4503 pinfo = null;
4089 pinfo = null;
4090 4504
4091 ce.time = Util.EnvironmentTickCount(); 4505 ce.time = Util.EnvironmentTickCount();
4092 ce.pinfo = pinfo; 4506 ce.pinfo = pinfo;
4093 } 4507 }
4094 4508
4095 string reply = String.Empty; 4509 string reply = String.Empty;
4096 4510
4097 switch (data) 4511 switch (data)
4098 { 4512 {
4099 case 1: // DATA_ONLINE (0|1) 4513 case 1: // DATA_ONLINE (0|1)
4100 if (pinfo != null && pinfo.RegionID != UUID.Zero) 4514 if (pinfo != null && pinfo.RegionID != UUID.Zero)
4101 reply = "1"; 4515 reply = "1";
4102 else 4516 else
4103 reply = "0"; 4517 reply = "0";
4104 break; 4518 break;
4105 case 2: // DATA_NAME (First Last) 4519 case 2: // DATA_NAME (First Last)
4106 reply = account.FirstName + " " + account.LastName; 4520 reply = account.FirstName + " " + account.LastName;
4107 break; 4521 break;
4108 case 3: // DATA_BORN (YYYY-MM-DD) 4522 case 3: // DATA_BORN (YYYY-MM-DD)
4109 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); 4523 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
4110 born = born.AddSeconds(account.Created); 4524 born = born.AddSeconds(account.Created);
4111 reply = born.ToString("yyyy-MM-dd"); 4525 reply = born.ToString("yyyy-MM-dd");
4112 break; 4526 break;
4113 case 4: // DATA_RATING (0,0,0,0,0,0) 4527 case 4: // DATA_RATING (0,0,0,0,0,0)
4114 reply = "0,0,0,0,0,0"; 4528 reply = "0,0,0,0,0,0";
4115 break; 4529 break;
4116 case 7: // DATA_USERLEVEL (integer) 4530 case 8: // DATA_PAYINFO (0|1|2|3)
4117 reply = account.UserLevel.ToString(); 4531 reply = "0";
4118 break; 4532 break;
4119 case 8: // DATA_PAYINFO (0|1|2|3) 4533 default:
4120 reply = "0"; 4534 return UUID.Zero.ToString(); // Raise no event
4121 break; 4535 }
4122 default:
4123 return UUID.Zero.ToString(); // Raise no event
4124 }
4125 4536
4126 UUID rq = UUID.Random(); 4537 UUID rq = UUID.Random();
4127 4538
4128 UUID tid = AsyncCommands. 4539 UUID tid = AsyncCommands.
4129 DataserverPlugin.RegisterRequest(m_host.LocalId, 4540 DataserverPlugin.RegisterRequest(m_host.LocalId,
4130 m_item.ItemID, rq.ToString()); 4541 m_item.ItemID, rq.ToString());
4131 4542
4132 AsyncCommands. 4543 AsyncCommands.
4133 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4544 DataserverPlugin.DataserverReply(rq.ToString(), reply);
4134 4545
4135 ScriptSleep(100); 4546 ScriptSleep(100);
4136 return tid.ToString(); 4547 return tid.ToString();
4548 }
4549 else
4550 {
4551 ShoutError("Invalid UUID passed to llRequestAgentData.");
4552 }
4553 return "";
4137 } 4554 }
4138 4555
4139 public LSL_String llRequestInventoryData(string name) 4556 public LSL_String llRequestInventoryData(string name)
@@ -4190,12 +4607,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4190 if (UUID.TryParse(agent, out agentId)) 4607 if (UUID.TryParse(agent, out agentId))
4191 { 4608 {
4192 ScenePresence presence = World.GetScenePresence(agentId); 4609 ScenePresence presence = World.GetScenePresence(agentId);
4193 if (presence != null) 4610 if (presence != null && presence.PresenceType != PresenceType.Npc)
4194 { 4611 {
4612 // agent must not be a god
4613 if (presence.UserLevel >= 200) return;
4614
4195 // agent must be over the owners land 4615 // agent must be over the owners land
4196 if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID) 4616 if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
4197 { 4617 {
4198 World.TeleportClientHome(agentId, presence.ControllingClient); 4618 if (!World.TeleportClientHome(agentId, presence.ControllingClient))
4619 {
4620 // They can't be teleported home for some reason
4621 GridRegion regionInfo = World.GridService.GetRegionByUUID(UUID.Zero, new UUID("2b02daac-e298-42fa-9a75-f488d37896e6"));
4622 if (regionInfo != null)
4623 {
4624 World.RequestTeleportLocation(
4625 presence.ControllingClient, regionInfo.RegionHandle, new Vector3(128, 128, 23), Vector3.Zero,
4626 (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
4627 }
4628 }
4199 } 4629 }
4200 } 4630 }
4201 } 4631 }
@@ -4213,20 +4643,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4213 ScenePresence presence = World.GetScenePresence(agentId); 4643 ScenePresence presence = World.GetScenePresence(agentId);
4214 if (presence != null && presence.PresenceType != PresenceType.Npc) 4644 if (presence != null && presence.PresenceType != PresenceType.Npc)
4215 { 4645 {
4216 // agent must not be a god
4217 if (presence.GodLevel >= 200) return;
4218
4219 if (destination == String.Empty) 4646 if (destination == String.Empty)
4220 destination = World.RegionInfo.RegionName; 4647 destination = World.RegionInfo.RegionName;
4221 4648
4222 // agent must be over the owners land 4649 if (m_item.PermsGranter == agentId)
4223 if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID) 4650 {
4651 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
4652 {
4653 DoLLTeleport(presence, destination, targetPos, targetLookAt);
4654 }
4655 }
4656
4657 // agent must be wearing the object
4658 if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
4224 { 4659 {
4225 DoLLTeleport(presence, destination, targetPos, targetLookAt); 4660 DoLLTeleport(presence, destination, targetPos, targetLookAt);
4226 } 4661 }
4227 else // or must be wearing the prim 4662 else
4228 { 4663 {
4229 if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID) 4664 // agent must not be a god
4665 if (presence.GodLevel >= 200) return;
4666
4667 // agent must be over the owners land
4668 ILandObject agentLand = World.LandChannel.GetLandObject(presence.AbsolutePosition);
4669 ILandObject objectLand = World.LandChannel.GetLandObject(m_host.AbsolutePosition);
4670 if (m_host.OwnerID == objectLand.LandData.OwnerID && m_host.OwnerID == agentLand.LandData.OwnerID)
4230 { 4671 {
4231 DoLLTeleport(presence, destination, targetPos, targetLookAt); 4672 DoLLTeleport(presence, destination, targetPos, targetLookAt);
4232 } 4673 }
@@ -4240,24 +4681,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4240 m_host.AddScriptLPS(1); 4681 m_host.AddScriptLPS(1);
4241 UUID agentId = new UUID(); 4682 UUID agentId = new UUID();
4242 4683
4243 ulong regionHandle = Utils.UIntsToLong((uint)global_coords.x, (uint)global_coords.y); 4684 ulong regionHandle = Utils.UIntsToLong((uint)(global_coords.x / 256) * 256, (uint)(global_coords.y / 256) * 256);
4244 4685
4245 if (UUID.TryParse(agent, out agentId)) 4686 if (UUID.TryParse(agent, out agentId))
4246 { 4687 {
4688 // This function is owner only!
4689 if (m_host.OwnerID != agentId)
4690 return;
4691
4247 ScenePresence presence = World.GetScenePresence(agentId); 4692 ScenePresence presence = World.GetScenePresence(agentId);
4693
4694 // Can't TP sitting avatars
4695 if (presence.ParentID != 0) // Sitting
4696 return;
4697
4248 if (presence != null && presence.PresenceType != PresenceType.Npc) 4698 if (presence != null && presence.PresenceType != PresenceType.Npc)
4249 { 4699 {
4250 // agent must not be a god 4700 if (m_item.PermsGranter == agentId)
4251 if (presence.GodLevel >= 200) return;
4252
4253 // agent must be over the owners land
4254 if (m_host.OwnerID == World.LandChannel.GetLandObject(presence.AbsolutePosition).LandData.OwnerID)
4255 { 4701 {
4256 World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation); 4702 // If attached using llAttachToAvatarTemp, cowardly refuse
4257 } 4703 if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.ParentGroup.FromItemID == UUID.Zero)
4258 else // or must be wearing the prim 4704 return;
4259 { 4705
4260 if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID) 4706 if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_TELEPORT) != 0)
4261 { 4707 {
4262 World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation); 4708 World.RequestTeleportLocation(presence.ControllingClient, regionHandle, targetPos, targetLookAt, (uint)TeleportFlags.ViaLocation);
4263 } 4709 }
@@ -4301,7 +4747,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4301 UUID av = new UUID(); 4747 UUID av = new UUID();
4302 if (!UUID.TryParse(agent,out av)) 4748 if (!UUID.TryParse(agent,out av))
4303 { 4749 {
4304 LSLError("First parameter to llDialog needs to be a key");
4305 return; 4750 return;
4306 } 4751 }
4307 4752
@@ -4334,9 +4779,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4334 { 4779 {
4335 m_host.AddScriptLPS(1); 4780 m_host.AddScriptLPS(1);
4336 4781
4782 if(impact_sound == "")
4783 {
4784 m_host.CollisionSoundVolume = (float)impact_volume;
4785 m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
4786 m_host.CollisionSoundType = 0;
4787 return;
4788 }
4337 // TODO: Parameter check logic required. 4789 // TODO: Parameter check logic required.
4338 m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound); 4790 m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound);
4339 m_host.CollisionSoundVolume = (float)impact_volume; 4791 m_host.CollisionSoundVolume = (float)impact_volume;
4792 m_host.CollisionSoundType = 1;
4340 } 4793 }
4341 4794
4342 public LSL_String llGetAnimation(string id) 4795 public LSL_String llGetAnimation(string id)
@@ -4350,14 +4803,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4350 4803
4351 if (m_host.RegionHandle == presence.RegionHandle) 4804 if (m_host.RegionHandle == presence.RegionHandle)
4352 { 4805 {
4353 Dictionary<UUID, string> animationstateNames = DefaultAvatarAnimations.AnimStateNames;
4354
4355 if (presence != null) 4806 if (presence != null)
4356 { 4807 {
4357 AnimationSet currentAnims = presence.Animator.Animations; 4808 if (presence.SitGround)
4358 string currentAnimationState = String.Empty; 4809 return "Sitting on Ground";
4359 if (animationstateNames.TryGetValue(currentAnims.ImplicitDefaultAnimation.AnimID, out currentAnimationState)) 4810 if (presence.ParentID != 0 || presence.ParentUUID != UUID.Zero)
4360 return currentAnimationState; 4811 return "Sitting";
4812
4813 string movementAnimation = presence.Animator.CurrentMovementAnimation;
4814 string lslMovementAnimation;
4815
4816 if (MovementAnimationsForLSL.TryGetValue(movementAnimation, out lslMovementAnimation))
4817 return lslMovementAnimation;
4361 } 4818 }
4362 } 4819 }
4363 4820
@@ -4505,7 +4962,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4505 { 4962 {
4506 float distance = (PusheePos - m_host.AbsolutePosition).Length(); 4963 float distance = (PusheePos - m_host.AbsolutePosition).Length();
4507 float distance_term = distance * distance * distance; // Script Energy 4964 float distance_term = distance * distance * distance; // Script Energy
4508 float pusher_mass = m_host.GetMass(); 4965 // use total object mass and not part
4966 float pusher_mass = m_host.ParentGroup.GetMass();
4509 4967
4510 float PUSH_ATTENUATION_DISTANCE = 17f; 4968 float PUSH_ATTENUATION_DISTANCE = 17f;
4511 float PUSH_ATTENUATION_SCALE = 5f; 4969 float PUSH_ATTENUATION_SCALE = 5f;
@@ -4741,6 +5199,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4741 { 5199 {
4742 return item.AssetID.ToString(); 5200 return item.AssetID.ToString();
4743 } 5201 }
5202 m_host.TaskInventory.LockItemsForRead(false);
4744 5203
4745 return UUID.Zero.ToString(); 5204 return UUID.Zero.ToString();
4746 } 5205 }
@@ -4893,14 +5352,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4893 { 5352 {
4894 m_host.AddScriptLPS(1); 5353 m_host.AddScriptLPS(1);
4895 5354
4896 if (src == null) 5355 return src.Length;
4897 {
4898 return 0;
4899 }
4900 else
4901 {
4902 return src.Length;
4903 }
4904 } 5356 }
4905 5357
4906 public LSL_Integer llList2Integer(LSL_List src, int index) 5358 public LSL_Integer llList2Integer(LSL_List src, int index)
@@ -4971,7 +5423,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4971 else if (src.Data[index] is LSL_Float) 5423 else if (src.Data[index] is LSL_Float)
4972 return Convert.ToDouble(((LSL_Float)src.Data[index]).value); 5424 return Convert.ToDouble(((LSL_Float)src.Data[index]).value);
4973 else if (src.Data[index] is LSL_String) 5425 else if (src.Data[index] is LSL_String)
4974 return Convert.ToDouble(((LSL_String)src.Data[index]).m_string); 5426 {
5427 string str = ((LSL_String) src.Data[index]).m_string;
5428 Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
5429 if (m != Match.Empty)
5430 {
5431 str = m.Value;
5432 double d = 0.0;
5433 if (!Double.TryParse(str, out d))
5434 return 0.0;
5435
5436 return d;
5437 }
5438 return 0.0;
5439 }
4975 return Convert.ToDouble(src.Data[index]); 5440 return Convert.ToDouble(src.Data[index]);
4976 } 5441 }
4977 catch (FormatException) 5442 catch (FormatException)
@@ -5013,7 +5478,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5013 // for completion and should LSL_Key ever be implemented 5478 // for completion and should LSL_Key ever be implemented
5014 // as it's own struct 5479 // as it's own struct
5015 else if (!(src.Data[index] is LSL_String || 5480 else if (!(src.Data[index] is LSL_String ||
5016 src.Data[index] is LSL_Key)) 5481 src.Data[index] is LSL_Key ||
5482 src.Data[index] is String))
5017 { 5483 {
5018 return ""; 5484 return "";
5019 } 5485 }
@@ -5271,7 +5737,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5271 } 5737 }
5272 } 5738 }
5273 } 5739 }
5274 else { 5740 else
5741 {
5275 object[] array = new object[src.Length]; 5742 object[] array = new object[src.Length];
5276 Array.Copy(src.Data, 0, array, 0, src.Length); 5743 Array.Copy(src.Data, 0, array, 0, src.Length);
5277 result = new LSL_List(array); 5744 result = new LSL_List(array);
@@ -5378,7 +5845,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5378 public LSL_Integer llGetRegionAgentCount() 5845 public LSL_Integer llGetRegionAgentCount()
5379 { 5846 {
5380 m_host.AddScriptLPS(1); 5847 m_host.AddScriptLPS(1);
5381 return new LSL_Integer(World.GetRootAgentCount()); 5848
5849 int count = 0;
5850 World.ForEachRootScenePresence(delegate(ScenePresence sp) {
5851 count++;
5852 });
5853
5854 return new LSL_Integer(count);
5382 } 5855 }
5383 5856
5384 public LSL_Vector llGetRegionCorner() 5857 public LSL_Vector llGetRegionCorner()
@@ -5619,6 +6092,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5619 flags |= ScriptBaseClass.AGENT_AWAY; 6092 flags |= ScriptBaseClass.AGENT_AWAY;
5620 } 6093 }
5621 6094
6095 UUID busy = new UUID("efcf670c-2d18-8128-973a-034ebc806b67");
6096 UUID[] anims = agent.Animator.GetAnimationArray();
6097 if (Array.Exists<UUID>(anims, a => { return a == busy; }))
6098 {
6099 flags |= ScriptBaseClass.AGENT_BUSY;
6100 }
6101
5622 // seems to get unset, even if in mouselook, when avatar is sitting on a prim??? 6102 // seems to get unset, even if in mouselook, when avatar is sitting on a prim???
5623 if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0) 6103 if ((agent.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
5624 { 6104 {
@@ -5666,6 +6146,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5666 flags |= ScriptBaseClass.AGENT_SITTING; 6146 flags |= ScriptBaseClass.AGENT_SITTING;
5667 } 6147 }
5668 6148
6149 if (agent.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] > 0)
6150 {
6151 flags |= ScriptBaseClass.AGENT_MALE;
6152 }
6153
5669 return flags; 6154 return flags;
5670 } 6155 }
5671 6156
@@ -5811,9 +6296,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5811 6296
5812 List<SceneObjectPart> parts = GetLinkParts(linknumber); 6297 List<SceneObjectPart> parts = GetLinkParts(linknumber);
5813 6298
5814 foreach (SceneObjectPart part in parts) 6299 try
6300 {
6301 foreach (SceneObjectPart part in parts)
6302 {
6303 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
6304 }
6305 }
6306 finally
5815 { 6307 {
5816 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
5817 } 6308 }
5818 } 6309 }
5819 6310
@@ -5867,13 +6358,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5867 6358
5868 if (m_host.OwnerID == land.LandData.OwnerID) 6359 if (m_host.OwnerID == land.LandData.OwnerID)
5869 { 6360 {
5870 World.TeleportClientHome(agentID, presence.ControllingClient); 6361 Vector3 p = World.GetNearestAllowedPosition(presence, land);
6362 presence.TeleportWithMomentum(p, null);
6363 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
5871 } 6364 }
5872 } 6365 }
5873 } 6366 }
5874 ScriptSleep(5000); 6367 ScriptSleep(5000);
5875 } 6368 }
5876 6369
6370 public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
6371 {
6372 return ParseString2List(str, separators, in_spacers, false);
6373 }
6374
5877 public LSL_Integer llOverMyLand(string id) 6375 public LSL_Integer llOverMyLand(string id)
5878 { 6376 {
5879 m_host.AddScriptLPS(1); 6377 m_host.AddScriptLPS(1);
@@ -5926,26 +6424,55 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5926 } 6424 }
5927 else 6425 else
5928 { 6426 {
5929 agentSize = GetAgentSize(avatar); 6427// agentSize = new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight);
6428 Vector3 s = avatar.Appearance.AvatarSize;
6429 agentSize = new LSL_Vector(s.X, s.Y, s.Z);
5930 } 6430 }
5931
5932 return agentSize; 6431 return agentSize;
5933 } 6432 }
5934 6433
5935 public LSL_Integer llSameGroup(string agent) 6434 public LSL_Integer llSameGroup(string id)
5936 { 6435 {
5937 m_host.AddScriptLPS(1); 6436 m_host.AddScriptLPS(1);
5938 UUID agentId = new UUID(); 6437 UUID uuid = new UUID();
5939 if (!UUID.TryParse(agent, out agentId)) 6438 if (!UUID.TryParse(id, out uuid))
5940 return new LSL_Integer(0); 6439 return new LSL_Integer(0);
5941 ScenePresence presence = World.GetScenePresence(agentId); 6440
5942 if (presence == null || presence.IsChildAgent) // Return flase for child agents 6441 // Check if it's a group key
5943 return new LSL_Integer(0); 6442 if (uuid == m_host.ParentGroup.RootPart.GroupID)
5944 IClientAPI client = presence.ControllingClient;
5945 if (m_host.GroupID == client.ActiveGroupId)
5946 return new LSL_Integer(1); 6443 return new LSL_Integer(1);
5947 else 6444
6445 // We got passed a UUID.Zero
6446 if (uuid == UUID.Zero)
6447 return new LSL_Integer(0);
6448
6449 // Handle the case where id names an avatar
6450 ScenePresence presence = World.GetScenePresence(uuid);
6451 if (presence != null)
6452 {
6453 if (presence.IsChildAgent)
6454 return new LSL_Integer(0);
6455
6456 IClientAPI client = presence.ControllingClient;
6457 if (m_host.ParentGroup.RootPart.GroupID == client.ActiveGroupId)
6458 return new LSL_Integer(1);
6459
6460 return new LSL_Integer(0);
6461 }
6462
6463 // Handle object case
6464 SceneObjectPart part = World.GetSceneObjectPart(uuid);
6465 if (part != null)
6466 {
6467 // This will handle both deed and non-deed and also the no
6468 // group case
6469 if (part.ParentGroup.RootPart.GroupID == m_host.ParentGroup.RootPart.GroupID)
6470 return new LSL_Integer(1);
6471
5948 return new LSL_Integer(0); 6472 return new LSL_Integer(0);
6473 }
6474
6475 return new LSL_Integer(0);
5949 } 6476 }
5950 6477
5951 public void llUnSit(string id) 6478 public void llUnSit(string id)
@@ -6504,6 +7031,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6504 7031
6505 protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot) 7032 protected void SitTarget(SceneObjectPart part, LSL_Vector offset, LSL_Rotation rot)
6506 { 7033 {
7034 // LSL quaternions can normalize to 0, normal Quaternions can't.
7035 if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
7036 rot.s = 1; // ZERO_ROTATION = 0,0,0,1
7037
6507 part.SitTargetPosition = offset; 7038 part.SitTargetPosition = offset;
6508 part.SitTargetOrientation = rot; 7039 part.SitTargetOrientation = rot;
6509 part.ParentGroup.HasGroupChanged = true; 7040 part.ParentGroup.HasGroupChanged = true;
@@ -6690,30 +7221,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6690 UUID av = new UUID(); 7221 UUID av = new UUID();
6691 if (!UUID.TryParse(avatar,out av)) 7222 if (!UUID.TryParse(avatar,out av))
6692 { 7223 {
6693 LSLError("First parameter to llDialog needs to be a key"); 7224 //LSLError("First parameter to llDialog needs to be a key");
6694 return; 7225 return;
6695 } 7226 }
6696 if (buttons.Length < 1) 7227 if (buttons.Length < 1)
6697 { 7228 {
6698 LSLError("No less than 1 button can be shown"); 7229 buttons.Add("OK");
6699 return;
6700 } 7230 }
6701 if (buttons.Length > 12) 7231 if (buttons.Length > 12)
6702 { 7232 {
6703 LSLError("No more than 12 buttons can be shown"); 7233 ShoutError("button list too long, must be 12 or fewer entries");
6704 return;
6705 } 7234 }
6706 string[] buts = new string[buttons.Length]; 7235 int length = buttons.Length;
6707 for (int i = 0; i < buttons.Length; i++) 7236 if (length > 12)
7237 length = 12;
7238
7239 string[] buts = new string[length];
7240 for (int i = 0; i < length; i++)
6708 { 7241 {
6709 if (buttons.Data[i].ToString() == String.Empty) 7242 if (buttons.Data[i].ToString() == String.Empty)
6710 { 7243 {
6711 LSLError("button label cannot be blank"); 7244 ShoutError("button label cannot be blank");
6712 return; 7245 return;
6713 } 7246 }
6714 if (buttons.Data[i].ToString().Length > 24) 7247 if (buttons.Data[i].ToString().Length > 24)
6715 { 7248 {
6716 LSLError("button label cannot be longer than 24 characters"); 7249 ShoutError("button label cannot be longer than 24 characters");
6717 return; 7250 return;
6718 } 7251 }
6719 buts[i] = buttons.Data[i].ToString(); 7252 buts[i] = buttons.Data[i].ToString();
@@ -6780,9 +7313,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6780 return; 7313 return;
6781 } 7314 }
6782 7315
6783 // the rest of the permission checks are done in RezScript, so check the pin there as well 7316 SceneObjectPart dest = World.GetSceneObjectPart(destId);
6784 World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param); 7317 if (dest != null)
7318 {
7319 if ((item.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
7320 {
7321 // the rest of the permission checks are done in RezScript, so check the pin there as well
7322 World.RezScriptFromPrim(item.ItemID, m_host, destId, pin, running, start_param);
6785 7323
7324 if ((item.BasePermissions & (uint)PermissionMask.Copy) == 0)
7325 m_host.Inventory.RemoveInventoryItem(item.ItemID);
7326 }
7327 }
6786 // this will cause the delay even if the script pin or permissions were wrong - seems ok 7328 // this will cause the delay even if the script pin or permissions were wrong - seems ok
6787 ScriptSleep(3000); 7329 ScriptSleep(3000);
6788 } 7330 }
@@ -6856,19 +7398,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6856 public LSL_String llMD5String(string src, int nonce) 7398 public LSL_String llMD5String(string src, int nonce)
6857 { 7399 {
6858 m_host.AddScriptLPS(1); 7400 m_host.AddScriptLPS(1);
6859 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString())); 7401 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
6860 } 7402 }
6861 7403
6862 public LSL_String llSHA1String(string src) 7404 public LSL_String llSHA1String(string src)
6863 { 7405 {
6864 m_host.AddScriptLPS(1); 7406 m_host.AddScriptLPS(1);
6865 return Util.SHA1Hash(src).ToLower(); 7407 return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
6866 } 7408 }
6867 7409
6868 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve) 7410 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
6869 { 7411 {
6870 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7412 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
6871 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7413 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
7414 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7415 return shapeBlock;
6872 7416
6873 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && 7417 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
6874 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && 7418 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
@@ -6973,6 +7517,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6973 // Prim type box, cylinder and prism. 7517 // Prim type box, cylinder and prism.
6974 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) 7518 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)
6975 { 7519 {
7520 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7521 return;
7522
6976 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7523 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
6977 ObjectShapePacket.ObjectDataBlock shapeBlock; 7524 ObjectShapePacket.ObjectDataBlock shapeBlock;
6978 7525
@@ -7026,6 +7573,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7026 // Prim type sphere. 7573 // Prim type sphere.
7027 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve) 7574 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
7028 { 7575 {
7576 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7577 return;
7578
7029 ObjectShapePacket.ObjectDataBlock shapeBlock; 7579 ObjectShapePacket.ObjectDataBlock shapeBlock;
7030 7580
7031 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve); 7581 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
@@ -7067,6 +7617,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7067 // Prim type torus, tube and ring. 7617 // Prim type torus, tube and ring.
7068 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) 7618 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)
7069 { 7619 {
7620 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7621 return;
7622
7070 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7623 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
7071 ObjectShapePacket.ObjectDataBlock shapeBlock; 7624 ObjectShapePacket.ObjectDataBlock shapeBlock;
7072 7625
@@ -7202,6 +7755,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7202 // Prim type sculpt. 7755 // Prim type sculpt.
7203 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve) 7756 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
7204 { 7757 {
7758 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7759 return;
7760
7205 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7761 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
7206 UUID sculptId; 7762 UUID sculptId;
7207 7763
@@ -7224,7 +7780,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7224 type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag)) 7780 type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
7225 { 7781 {
7226 // default 7782 // default
7227 type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; 7783 type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
7228 } 7784 }
7229 7785
7230 part.Shape.SetSculptProperties((byte)type, sculptId); 7786 part.Shape.SetSculptProperties((byte)type, sculptId);
@@ -7241,15 +7797,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7241 ScriptSleep(200); 7797 ScriptSleep(200);
7242 } 7798 }
7243 7799
7244 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
7245 {
7246 m_host.AddScriptLPS(1);
7247
7248 setLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
7249
7250 ScriptSleep(200);
7251 }
7252
7253 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) 7800 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
7254 { 7801 {
7255 m_host.AddScriptLPS(1); 7802 m_host.AddScriptLPS(1);
@@ -7257,172 +7804,135 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7257 setLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast"); 7804 setLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
7258 } 7805 }
7259 7806
7260 protected void setLinkPrimParams(int linknumber, LSL_List rules, string originFunc) 7807 private void setLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
7261 { 7808 {
7262 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7809 List<object> parts = new List<object>();
7810 List<SceneObjectPart> prims = GetLinkParts(linknumber);
7811 List<ScenePresence> avatars = GetLinkAvatars(linknumber);
7812 foreach (SceneObjectPart p in prims)
7813 parts.Add(p);
7814 foreach (ScenePresence p in avatars)
7815 parts.Add(p);
7263 7816
7264 LSL_List remaining = null; 7817 LSL_List remaining = null;
7265 uint rulesParsed = 0; 7818 uint rulesParsed = 0;
7266 7819
7267 foreach (SceneObjectPart part in parts) 7820 if (parts.Count > 0)
7268 remaining = SetPrimParams(part, rules, originFunc, ref rulesParsed);
7269
7270 while (remaining != null && remaining.Length > 2)
7271 {
7272 linknumber = remaining.GetLSLIntegerItem(0);
7273 rules = remaining.GetSublist(1, -1);
7274 parts = GetLinkParts(linknumber);
7275
7276 foreach (SceneObjectPart part in parts)
7277 remaining = SetPrimParams(part, rules, originFunc, ref rulesParsed);
7278 }
7279 }
7280
7281 public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
7282 {
7283 SceneObjectGroup group = m_host.ParentGroup;
7284
7285 if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
7286 return;
7287 if (group.IsAttachment)
7288 return;
7289
7290 if (frames.Data.Length > 0) // We are getting a new motion
7291 { 7821 {
7292 if (group.RootPart.KeyframeMotion != null) 7822 foreach (object part in parts)
7293 group.RootPart.KeyframeMotion.Delete();
7294 group.RootPart.KeyframeMotion = null;
7295
7296 int idx = 0;
7297
7298 KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
7299 KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
7300
7301 while (idx < options.Data.Length)
7302 { 7823 {
7303 int option = (int)options.GetLSLIntegerItem(idx++); 7824 if (part is SceneObjectPart)
7304 int remain = options.Data.Length - idx; 7825 remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
7826 else
7827 remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
7828 }
7305 7829
7306 switch (option) 7830 while ((object)remaining != null && remaining.Length > 2)
7831 {
7832 linknumber = remaining.GetLSLIntegerItem(0);
7833 rules = remaining.GetSublist(1, -1);
7834 parts.Clear();
7835 prims = GetLinkParts(linknumber);
7836 avatars = GetLinkAvatars(linknumber);
7837 foreach (SceneObjectPart p in prims)
7838 parts.Add(p);
7839 foreach (ScenePresence p in avatars)
7840 parts.Add(p);
7841
7842 remaining = null;
7843 foreach (object part in parts)
7307 { 7844 {
7308 case ScriptBaseClass.KFM_MODE: 7845 if (part is SceneObjectPart)
7309 if (remain < 1) 7846 remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
7310 break; 7847 else
7311 int modeval = (int)options.GetLSLIntegerItem(idx++); 7848 remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
7312 switch(modeval)
7313 {
7314 case ScriptBaseClass.KFM_FORWARD:
7315 mode = KeyframeMotion.PlayMode.Forward;
7316 break;
7317 case ScriptBaseClass.KFM_REVERSE:
7318 mode = KeyframeMotion.PlayMode.Reverse;
7319 break;
7320 case ScriptBaseClass.KFM_LOOP:
7321 mode = KeyframeMotion.PlayMode.Loop;
7322 break;
7323 case ScriptBaseClass.KFM_PING_PONG:
7324 mode = KeyframeMotion.PlayMode.PingPong;
7325 break;
7326 }
7327 break;
7328 case ScriptBaseClass.KFM_DATA:
7329 if (remain < 1)
7330 break;
7331 int dataval = (int)options.GetLSLIntegerItem(idx++);
7332 data = (KeyframeMotion.DataFormat)dataval;
7333 break;
7334 } 7849 }
7335 } 7850 }
7851 }
7852 }
7336 7853
7337 group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data); 7854 public LSL_List llGetPhysicsMaterial()
7855 {
7856 LSL_List result = new LSL_List();
7338 7857
7339 idx = 0; 7858 result.Add(new LSL_Float(m_host.GravityModifier));
7859 result.Add(new LSL_Float(m_host.Restitution));
7860 result.Add(new LSL_Float(m_host.Friction));
7861 result.Add(new LSL_Float(m_host.Density));
7340 7862
7341 int elemLength = 2; 7863 return result;
7342 if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation)) 7864 }
7343 elemLength = 3;
7344 7865
7345 List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>(); 7866 private void SetPhysicsMaterial(SceneObjectPart part, int material_bits,
7346 while (idx < frames.Data.Length) 7867 float material_density, float material_friction,
7347 { 7868 float material_restitution, float material_gravity_modifier)
7348 int remain = frames.Data.Length - idx; 7869 {
7870 ExtraPhysicsData physdata = new ExtraPhysicsData();
7871 physdata.PhysShapeType = (PhysShapeType)part.PhysicsShapeType;
7872 physdata.Density = part.Density;
7873 physdata.Friction = part.Friction;
7874 physdata.Bounce = part.Restitution;
7875 physdata.GravitationModifier = part.GravityModifier;
7349 7876
7350 if (remain < elemLength) 7877 if ((material_bits & (int)ScriptBaseClass.DENSITY) != 0)
7351 break; 7878 physdata.Density = material_density;
7879 if ((material_bits & (int)ScriptBaseClass.FRICTION) != 0)
7880 physdata.Friction = material_friction;
7881 if ((material_bits & (int)ScriptBaseClass.RESTITUTION) != 0)
7882 physdata.Bounce = material_restitution;
7883 if ((material_bits & (int)ScriptBaseClass.GRAVITY_MULTIPLIER) != 0)
7884 physdata.GravitationModifier = material_gravity_modifier;
7352 7885
7353 KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe(); 7886 part.UpdateExtraPhysics(physdata);
7354 frame.Position = null; 7887 }
7355 frame.Rotation = null;
7356 7888
7357 if ((data & KeyframeMotion.DataFormat.Translation) != 0) 7889 public void llSetPhysicsMaterial(int material_bits,
7358 { 7890 float material_gravity_modifier, float material_restitution,
7359 LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++); 7891 float material_friction, float material_density)
7360 frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z); 7892 {
7361 } 7893 SetPhysicsMaterial(m_host, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
7362 if ((data & KeyframeMotion.DataFormat.Rotation) != 0) 7894 }
7363 {
7364 LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
7365 Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
7366 q.Normalize();
7367 frame.Rotation = q;
7368 }
7369 7895
7370 float tempf = (float)frames.GetLSLFloatItem(idx++); 7896 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
7371 frame.TimeMS = (int)(tempf * 1000.0f); 7897 {
7898 setLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
7899 llSetLinkPrimitiveParamsFast(linknumber, rules);
7900 ScriptSleep(200);
7901 }
7372 7902
7373 keyframes.Add(frame); 7903 // vector up using libomv (c&p from sop )
7374 } 7904 // vector up rotated by r
7905 private Vector3 Zrot(Quaternion r)
7906 {
7907 double x, y, z, m;
7375 7908
7376 group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray()); 7909 m = r.X * r.X + r.Y * r.Y + r.Z * r.Z + r.W * r.W;
7377 group.RootPart.KeyframeMotion.Start(); 7910 if (Math.Abs(1.0 - m) > 0.000001)
7378 }
7379 else
7380 { 7911 {
7381 if (group.RootPart.KeyframeMotion == null) 7912 m = 1.0 / Math.Sqrt(m);
7382 return; 7913 r.X *= (float)m;
7383 7914 r.Y *= (float)m;
7384 if (options.Data.Length == 0) 7915 r.Z *= (float)m;
7385 { 7916 r.W *= (float)m;
7386 group.RootPart.KeyframeMotion.Stop(); 7917 }
7387 return;
7388 }
7389
7390 int code = (int)options.GetLSLIntegerItem(0);
7391
7392 int idx = 0;
7393 7918
7394 while (idx < options.Data.Length) 7919 x = 2 * (r.X * r.Z + r.Y * r.W);
7395 { 7920 y = 2 * (-r.X * r.W + r.Y * r.Z);
7396 int option = (int)options.GetLSLIntegerItem(idx++); 7921 z = -r.X * r.X - r.Y * r.Y + r.Z * r.Z + r.W * r.W;
7397 int remain = options.Data.Length - idx;
7398 7922
7399 switch (option) 7923 return new Vector3((float)x, (float)y, (float)z);
7400 {
7401 case ScriptBaseClass.KFM_COMMAND:
7402 int cmd = (int)options.GetLSLIntegerItem(idx++);
7403 switch (cmd)
7404 {
7405 case ScriptBaseClass.KFM_CMD_PLAY:
7406 group.RootPart.KeyframeMotion.Start();
7407 break;
7408 case ScriptBaseClass.KFM_CMD_STOP:
7409 group.RootPart.KeyframeMotion.Stop();
7410 break;
7411 case ScriptBaseClass.KFM_CMD_PAUSE:
7412 group.RootPart.KeyframeMotion.Pause();
7413 break;
7414 }
7415 break;
7416 }
7417 }
7418 }
7419 } 7924 }
7420 7925
7421 protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed) 7926 protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
7422 { 7927 {
7928 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7929 return null;
7930
7423 int idx = 0; 7931 int idx = 0;
7424 int idxStart = 0; 7932 int idxStart = 0;
7425 7933
7934 SceneObjectGroup parentgrp = part.ParentGroup;
7935
7426 bool positionChanged = false; 7936 bool positionChanged = false;
7427 LSL_Vector currentPosition = GetPartLocalPos(part); 7937 LSL_Vector currentPosition = GetPartLocalPos(part);
7428 7938
@@ -7447,8 +7957,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7447 return null; 7957 return null;
7448 7958
7449 v=rules.GetVector3Item(idx++); 7959 v=rules.GetVector3Item(idx++);
7960 if (part.IsRoot && !part.ParentGroup.IsAttachment)
7961 currentPosition = GetSetPosTarget(part, v, currentPosition, true);
7962 else
7963 currentPosition = GetSetPosTarget(part, v, currentPosition, false);
7450 positionChanged = true; 7964 positionChanged = true;
7451 currentPosition = GetSetPosTarget(part, v, currentPosition);
7452 7965
7453 break; 7966 break;
7454 case (int)ScriptBaseClass.PRIM_SIZE: 7967 case (int)ScriptBaseClass.PRIM_SIZE:
@@ -7465,7 +7978,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7465 7978
7466 LSL_Rotation q = rules.GetQuaternionItem(idx++); 7979 LSL_Rotation q = rules.GetQuaternionItem(idx++);
7467 // try to let this work as in SL... 7980 // try to let this work as in SL...
7468 if (part.ParentID == 0) 7981 if (part.ParentID == 0 || (part.ParentGroup != null && part == part.ParentGroup.RootPart))
7469 { 7982 {
7470 // special case: If we are root, rotate complete SOG to new rotation 7983 // special case: If we are root, rotate complete SOG to new rotation
7471 SetRot(part, q); 7984 SetRot(part, q);
@@ -7725,7 +8238,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7725 return null; 8238 return null;
7726 8239
7727 string ph = rules.Data[idx++].ToString(); 8240 string ph = rules.Data[idx++].ToString();
7728 m_host.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1")); 8241 parentgrp.ScriptSetPhantomStatus(ph.Equals("1"));
7729 8242
7730 break; 8243 break;
7731 8244
@@ -7759,12 +8272,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7759 8272
7760 break; 8273 break;
7761 8274
8275 case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
8276 if (remain < 5)
8277 return null;
8278
8279 int material_bits = rules.GetLSLIntegerItem(idx++);
8280 float material_density = (float)rules.GetLSLFloatItem(idx++);
8281 float material_friction = (float)rules.GetLSLFloatItem(idx++);
8282 float material_restitution = (float)rules.GetLSLFloatItem(idx++);
8283 float material_gravity_modifier = (float)rules.GetLSLFloatItem(idx++);
8284
8285 SetPhysicsMaterial(part, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
8286
8287 break;
8288
7762 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ: 8289 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
7763 if (remain < 1) 8290 if (remain < 1)
7764 return null; 8291 return null;
7765 string temp = rules.Data[idx++].ToString(); 8292 string temp = rules.Data[idx++].ToString();
7766 8293
7767 m_host.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1")); 8294 parentgrp.ScriptSetTemporaryStatus(temp.Equals("1"));
7768 8295
7769 break; 8296 break;
7770 8297
@@ -7838,14 +8365,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7838 if (part.ParentGroup.RootPart == part) 8365 if (part.ParentGroup.RootPart == part)
7839 { 8366 {
7840 SceneObjectGroup parent = part.ParentGroup; 8367 SceneObjectGroup parent = part.ParentGroup;
7841 parent.UpdateGroupPosition(currentPosition); 8368 Util.FireAndForget(delegate(object x) {
8369 parent.UpdateGroupPosition(currentPosition);
8370 });
7842 } 8371 }
7843 else 8372 else
7844 { 8373 {
7845 part.OffsetPosition = currentPosition; 8374 part.OffsetPosition = currentPosition;
7846 SceneObjectGroup parent = part.ParentGroup; 8375// SceneObjectGroup parent = part.ParentGroup;
7847 parent.HasGroupChanged = true; 8376// parent.HasGroupChanged = true;
7848 parent.ScheduleGroupForTerseUpdate(); 8377// parent.ScheduleGroupForTerseUpdate();
8378 part.ScheduleTerseUpdate();
7849 } 8379 }
7850 } 8380 }
7851 } 8381 }
@@ -7883,10 +8413,91 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7883 8413
7884 public LSL_String llXorBase64Strings(string str1, string str2) 8414 public LSL_String llXorBase64Strings(string str1, string str2)
7885 { 8415 {
7886 m_host.AddScriptLPS(1); 8416 string b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
7887 Deprecated("llXorBase64Strings"); 8417
7888 ScriptSleep(300); 8418 ScriptSleep(300);
7889 return String.Empty; 8419 m_host.AddScriptLPS(1);
8420
8421 if (str1 == String.Empty)
8422 return String.Empty;
8423 if (str2 == String.Empty)
8424 return str1;
8425
8426 int len = str2.Length;
8427 if ((len % 4) != 0) // LL is EVIL!!!!
8428 {
8429 while (str2.EndsWith("="))
8430 str2 = str2.Substring(0, str2.Length - 1);
8431
8432 len = str2.Length;
8433 int mod = len % 4;
8434
8435 if (mod == 1)
8436 str2 = str2.Substring(0, str2.Length - 1);
8437 else if (mod == 2)
8438 str2 += "==";
8439 else if (mod == 3)
8440 str2 += "=";
8441 }
8442
8443 byte[] data1;
8444 byte[] data2;
8445 try
8446 {
8447 data1 = Convert.FromBase64String(str1);
8448 data2 = Convert.FromBase64String(str2);
8449 }
8450 catch (Exception)
8451 {
8452 return new LSL_String(String.Empty);
8453 }
8454
8455 // For cases where the decoded length of s2 is greater
8456 // than the decoded length of s1, simply perform a normal
8457 // decode and XOR
8458 //
8459 if (data2.Length >= data1.Length)
8460 {
8461 for (int pos = 0 ; pos < data1.Length ; pos++ )
8462 data1[pos] ^= data2[pos];
8463
8464 return Convert.ToBase64String(data1);
8465 }
8466
8467 // Remove padding
8468 while (str1.EndsWith("="))
8469 str1 = str1.Substring(0, str1.Length - 1);
8470 while (str2.EndsWith("="))
8471 str2 = str2.Substring(0, str2.Length - 1);
8472
8473 byte[] d1 = new byte[str1.Length];
8474 byte[] d2 = new byte[str2.Length];
8475
8476 for (int i = 0 ; i < str1.Length ; i++)
8477 {
8478 int idx = b64.IndexOf(str1.Substring(i, 1));
8479 if (idx == -1)
8480 idx = 0;
8481 d1[i] = (byte)idx;
8482 }
8483
8484 for (int i = 0 ; i < str2.Length ; i++)
8485 {
8486 int idx = b64.IndexOf(str2.Substring(i, 1));
8487 if (idx == -1)
8488 idx = 0;
8489 d2[i] = (byte)idx;
8490 }
8491
8492 string output = String.Empty;
8493
8494 for (int pos = 0 ; pos < d1.Length ; pos++)
8495 output += b64[d1[pos] ^ d2[pos % d2.Length]];
8496
8497 while (output.Length % 3 > 0)
8498 output += "=";
8499
8500 return output;
7890 } 8501 }
7891 8502
7892 public void llRemoteDataSetRegion() 8503 public void llRemoteDataSetRegion()
@@ -8011,8 +8622,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8011 public LSL_Integer llGetNumberOfPrims() 8622 public LSL_Integer llGetNumberOfPrims()
8012 { 8623 {
8013 m_host.AddScriptLPS(1); 8624 m_host.AddScriptLPS(1);
8014 8625 int avatarCount = m_host.ParentGroup.GetLinkedAvatars().Count;
8015 return m_host.ParentGroup.PrimCount + m_host.ParentGroup.GetSittingAvatarsCount(); 8626
8627 return m_host.ParentGroup.PrimCount + avatarCount;
8016 } 8628 }
8017 8629
8018 /// <summary> 8630 /// <summary>
@@ -8027,55 +8639,114 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8027 m_host.AddScriptLPS(1); 8639 m_host.AddScriptLPS(1);
8028 UUID objID = UUID.Zero; 8640 UUID objID = UUID.Zero;
8029 LSL_List result = new LSL_List(); 8641 LSL_List result = new LSL_List();
8642
8643 // If the ID is not valid, return null result
8030 if (!UUID.TryParse(obj, out objID)) 8644 if (!UUID.TryParse(obj, out objID))
8031 { 8645 {
8032 result.Add(new LSL_Vector()); 8646 result.Add(new LSL_Vector());
8033 result.Add(new LSL_Vector()); 8647 result.Add(new LSL_Vector());
8034 return result; 8648 return result;
8035 } 8649 }
8650
8651 // Check if this is an attached prim. If so, replace
8652 // the UUID with the avatar UUID and report it's bounding box
8653 SceneObjectPart part = World.GetSceneObjectPart(objID);
8654 if (part != null && part.ParentGroup.IsAttachment)
8655 objID = part.ParentGroup.AttachedAvatar;
8656
8657 // Find out if this is an avatar ID. If so, return it's box
8036 ScenePresence presence = World.GetScenePresence(objID); 8658 ScenePresence presence = World.GetScenePresence(objID);
8037 if (presence != null) 8659 if (presence != null)
8038 { 8660 {
8039 if (presence.ParentID == 0) // not sat on an object 8661 // As per LSL Wiki, there is no difference between sitting
8662 // and standing avatar since server 1.36
8663 LSL_Vector lower;
8664 LSL_Vector upper;
8665
8666 Vector3 box = presence.Appearance.AvatarBoxSize * 0.5f;
8667
8668 if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
8669 == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
8670/*
8040 { 8671 {
8041 LSL_Vector lower; 8672 // This is for ground sitting avatars
8042 LSL_Vector upper; 8673 float height = presence.Appearance.AvatarHeight / 2.66666667f;
8043 if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID 8674 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
8044 == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) 8675 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
8045 { 8676 }
8046 // This is for ground sitting avatars 8677 else
8047 float height = presence.Appearance.AvatarHeight / 2.66666667f; 8678 {
8048 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f); 8679 // This is for standing/flying avatars
8049 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f); 8680 float height = presence.Appearance.AvatarHeight / 2.0f;
8050 } 8681 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
8051 else 8682 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
8052 { 8683 }
8053 // This is for standing/flying avatars 8684
8054 float height = presence.Appearance.AvatarHeight / 2.0f; 8685 // Adjust to the documented error offsets (see LSL Wiki)
8055 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f); 8686 lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
8056 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f); 8687 upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
8057 } 8688*/
8058 result.Add(lower); 8689 {
8059 result.Add(upper); 8690 // This is for ground sitting avatars TODO!
8060 return result; 8691 lower = new LSL_Vector(-box.X - 0.1125, -box.Y, box.Z * -1.0f);
8692 upper = new LSL_Vector(box.X + 0.1125, box.Y, box.Z * -1.0f);
8061 } 8693 }
8062 else 8694 else
8063 { 8695 {
8064 // sitting on an object so we need the bounding box of that 8696 // This is for standing/flying avatars
8065 // which should include the avatar so set the UUID to the 8697 lower = new LSL_Vector(-box.X, -box.Y, -box.Z);
8066 // UUID of the object the avatar is sat on and allow it to fall through 8698 upper = new LSL_Vector(box.X, box.Y, box.Z);
8067 // to processing an object
8068 SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
8069 objID = p.UUID;
8070 } 8699 }
8700
8701 if (lower.x > upper.x)
8702 lower.x = upper.x;
8703 if (lower.y > upper.y)
8704 lower.y = upper.y;
8705 if (lower.z > upper.z)
8706 lower.z = upper.z;
8707
8708 result.Add(lower);
8709 result.Add(upper);
8710 return result;
8071 } 8711 }
8072 SceneObjectPart part = World.GetSceneObjectPart(objID); 8712
8713 part = World.GetSceneObjectPart(objID);
8073 // Currently only works for single prims without a sitting avatar 8714 // Currently only works for single prims without a sitting avatar
8074 if (part != null) 8715 if (part != null)
8075 { 8716 {
8076 Vector3 halfSize = part.Scale / 2.0f; 8717 float minX;
8077 LSL_Vector lower = (new LSL_Vector(halfSize)) * -1.0f; 8718 float maxX;
8078 LSL_Vector upper = new LSL_Vector(halfSize); 8719 float minY;
8720 float maxY;
8721 float minZ;
8722 float maxZ;
8723
8724 // This BBox is in sim coordinates, with the offset being
8725 // a contained point.
8726 Vector3[] offsets = Scene.GetCombinedBoundingBox(new List<SceneObjectGroup> { part.ParentGroup },
8727 out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
8728
8729 minX -= offsets[0].X;
8730 maxX -= offsets[0].X;
8731 minY -= offsets[0].Y;
8732 maxY -= offsets[0].Y;
8733 minZ -= offsets[0].Z;
8734 maxZ -= offsets[0].Z;
8735
8736 LSL_Vector lower;
8737 LSL_Vector upper;
8738
8739 // Adjust to the documented error offsets (see LSL Wiki)
8740 lower = new LSL_Vector(minX + 0.05f, minY + 0.05f, minZ + 0.05f);
8741 upper = new LSL_Vector(maxX - 0.05f, maxY - 0.05f, maxZ - 0.05f);
8742
8743 if (lower.x > upper.x)
8744 lower.x = upper.x;
8745 if (lower.y > upper.y)
8746 lower.y = upper.y;
8747 if (lower.z > upper.z)
8748 lower.z = upper.z;
8749
8079 result.Add(lower); 8750 result.Add(lower);
8080 result.Add(upper); 8751 result.Add(upper);
8081 return result; 8752 return result;
@@ -8092,224 +8763,74 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8092 return new LSL_Vector(m_host.GetGeometricCenter()); 8763 return new LSL_Vector(m_host.GetGeometricCenter());
8093 } 8764 }
8094 8765
8095 public LSL_List GetEntityParams(ISceneEntity entity, LSL_List rules) 8766 public LSL_List llGetPrimitiveParams(LSL_List rules)
8096 { 8767 {
8097 LSL_List result = new LSL_List(); 8768 m_host.AddScriptLPS(1);
8098 LSL_List remaining = null;
8099 8769
8100 while (true) 8770 LSL_List result = new LSL_List();
8101 {
8102 if (entity is SceneObjectPart)
8103 remaining = GetPrimParams((SceneObjectPart)entity, rules, ref result);
8104 else
8105 remaining = GetAgentParams((ScenePresence)entity, rules, ref result);
8106 8771
8107 if (remaining == null || remaining.Length <= 2) 8772 LSL_List remaining = GetPrimParams(m_host, rules, ref result);
8108 return result;
8109 8773
8774 while ((object)remaining != null && remaining.Length > 2)
8775 {
8110 int linknumber = remaining.GetLSLIntegerItem(0); 8776 int linknumber = remaining.GetLSLIntegerItem(0);
8111 rules = remaining.GetSublist(1, -1); 8777 rules = remaining.GetSublist(1, -1);
8112 entity = GetLinkEntity(linknumber); 8778 List<SceneObjectPart> parts = GetLinkParts(linknumber);
8113 }
8114 }
8115 8779
8116 public LSL_List llGetPrimitiveParams(LSL_List rules) 8780 foreach (SceneObjectPart part in parts)
8117 { 8781 remaining = GetPrimParams(part, rules, ref result);
8118 m_host.AddScriptLPS(1); 8782 }
8119 8783
8120 return GetEntityParams(m_host, rules); 8784 return result;
8121 } 8785 }
8122 8786
8123 public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules) 8787 public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
8124 { 8788 {
8125 m_host.AddScriptLPS(1); 8789 m_host.AddScriptLPS(1);
8126 8790
8127 return GetEntityParams(GetLinkEntity(linknumber), rules); 8791 // acording to SL wiki this must indicate a single link number or link_root or link_this.
8128 } 8792 // keep other options as before
8129 8793
8130 public LSL_Vector GetAgentSize(ScenePresence sp) 8794 List<SceneObjectPart> parts;
8131 { 8795 List<ScenePresence> avatars;
8132 return new LSL_Vector(0.45, 0.6, sp.Appearance.AvatarHeight); 8796
8133 } 8797 LSL_List res = new LSL_List();
8798 LSL_List remaining = null;
8134 8799
8135 /// <summary> 8800 while (rules.Length > 0)
8136 /// Gets params for a seated avatar in a linkset.
8137 /// </summary>
8138 /// <returns></returns>
8139 /// <param name='sp'></param>
8140 /// <param name='rules'></param>
8141 /// <param name='res'></param>
8142 public LSL_List GetAgentParams(ScenePresence sp, LSL_List rules, ref LSL_List res)
8143 {
8144 int idx = 0;
8145 while (idx < rules.Length)
8146 { 8801 {
8147 int code = (int)rules.GetLSLIntegerItem(idx++); 8802 parts = GetLinkParts(linknumber);
8148 int remain = rules.Length-idx; 8803 avatars = GetLinkAvatars(linknumber);
8149 8804
8150 switch (code) 8805 remaining = null;
8806 foreach (SceneObjectPart part in parts)
8151 { 8807 {
8152 case (int)ScriptBaseClass.PRIM_MATERIAL: 8808 remaining = GetPrimParams(part, rules, ref res);
8153 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MATERIAL_FLESH)); 8809 }
8154 break; 8810 foreach (ScenePresence avatar in avatars)
8155 8811 {
8156 case (int)ScriptBaseClass.PRIM_PHYSICS: 8812 remaining = GetPrimParams(avatar, rules, ref res);
8157 res.Add(ScriptBaseClass.FALSE); 8813 }
8158 break;
8159
8160 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
8161 res.Add(ScriptBaseClass.FALSE);
8162 break;
8163
8164 case (int)ScriptBaseClass.PRIM_PHANTOM:
8165 res.Add(ScriptBaseClass.FALSE);
8166 break;
8167
8168 case (int)ScriptBaseClass.PRIM_POSITION:
8169 res.Add(new LSL_Vector(sp.AbsolutePosition));
8170 break;
8171
8172 case (int)ScriptBaseClass.PRIM_SIZE:
8173 res.Add(GetAgentSize(sp));
8174 break;
8175
8176 case (int)ScriptBaseClass.PRIM_ROTATION:
8177 res.Add(sp.GetWorldRotation());
8178 break;
8179
8180 case (int)ScriptBaseClass.PRIM_TYPE:
8181 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
8182 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
8183 res.Add(new LSL_Vector(0, 1, 0));
8184 res.Add(new LSL_Float(0));
8185 res.Add(new LSL_Vector(0, 0, 0));
8186 res.Add(new LSL_Vector(1, 1, 0));
8187 res.Add(new LSL_Vector(0, 0, 0));
8188 break;
8189
8190 case (int)ScriptBaseClass.PRIM_TEXTURE:
8191 if (remain < 1)
8192 return null;
8193
8194 int face = (int)rules.GetLSLIntegerItem(idx++);
8195 if (face > 21)
8196 break;
8197
8198 res.Add(new LSL_String(""));
8199 res.Add(ScriptBaseClass.ZERO_VECTOR);
8200 res.Add(ScriptBaseClass.ZERO_VECTOR);
8201 res.Add(new LSL_Float(0));
8202 break;
8203
8204 case (int)ScriptBaseClass.PRIM_COLOR:
8205 if (remain < 1)
8206 return null;
8207
8208 face = (int)rules.GetLSLIntegerItem(idx++);
8209 if (face > 21)
8210 break;
8211
8212 res.Add(ScriptBaseClass.ZERO_VECTOR);
8213 res.Add(new LSL_Float(0));
8214 break;
8215
8216 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
8217 if (remain < 1)
8218 return null;
8219
8220 face = (int)rules.GetLSLIntegerItem(idx++);
8221 if (face > 21)
8222 break;
8223
8224 res.Add(ScriptBaseClass.PRIM_SHINY_NONE);
8225 res.Add(ScriptBaseClass.PRIM_BUMP_NONE);
8226 break;
8227
8228 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
8229 if (remain < 1)
8230 return null;
8231
8232 face = (int)rules.GetLSLIntegerItem(idx++);
8233 if (face > 21)
8234 break;
8235
8236 res.Add(ScriptBaseClass.FALSE);
8237 break;
8238
8239 case (int)ScriptBaseClass.PRIM_FLEXIBLE:
8240 res.Add(ScriptBaseClass.FALSE);
8241 res.Add(new LSL_Integer(0));
8242 res.Add(new LSL_Float(0));
8243 res.Add(new LSL_Float(0));
8244 res.Add(new LSL_Float(0));
8245 res.Add(new LSL_Float(0));
8246 res.Add(ScriptBaseClass.ZERO_VECTOR);
8247 break;
8248
8249 case (int)ScriptBaseClass.PRIM_TEXGEN:
8250 if (remain < 1)
8251 return null;
8252
8253 face = (int)rules.GetLSLIntegerItem(idx++);
8254 if (face > 21)
8255 break;
8256
8257 res.Add(ScriptBaseClass.PRIM_TEXGEN_DEFAULT);
8258 break;
8259
8260 case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
8261 res.Add(ScriptBaseClass.FALSE);
8262 res.Add(ScriptBaseClass.ZERO_VECTOR);
8263 res.Add(ScriptBaseClass.ZERO_VECTOR);
8264 break;
8265
8266 case (int)ScriptBaseClass.PRIM_GLOW:
8267 if (remain < 1)
8268 return null;
8269
8270 face = (int)rules.GetLSLIntegerItem(idx++);
8271 if (face > 21)
8272 break;
8273
8274 res.Add(new LSL_Float(0));
8275 break;
8276
8277 case (int)ScriptBaseClass.PRIM_TEXT:
8278 res.Add(new LSL_String(""));
8279 res.Add(ScriptBaseClass.ZERO_VECTOR);
8280 res.Add(new LSL_Float(1));
8281 break;
8282
8283 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
8284 res.Add(new LSL_Rotation(sp.Rotation));
8285 break;
8286
8287 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
8288 res.Add(new LSL_Vector(sp.OffsetPosition));
8289 break;
8290
8291 case (int)ScriptBaseClass.PRIM_SLICE:
8292 res.Add(new LSL_Vector(0, 1, 0));
8293 break;
8294
8295 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
8296 if(remain < 3)
8297 return null;
8298 8814
8299 return rules.GetSublist(idx, -1); 8815 if ((object)remaining != null && remaining.Length > 0)
8816 {
8817 linknumber = remaining.GetLSLIntegerItem(0);
8818 rules = remaining.GetSublist(1, -1);
8300 } 8819 }
8820 else
8821 break;
8301 } 8822 }
8302 8823
8303 return null; 8824 return res;
8304 } 8825 }
8305 8826
8306 public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res) 8827 public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
8307 { 8828 {
8308 int idx = 0; 8829 int idx=0;
8309 while (idx < rules.Length) 8830 while (idx < rules.Length)
8310 { 8831 {
8311 int code = (int)rules.GetLSLIntegerItem(idx++); 8832 int code=(int)rules.GetLSLIntegerItem(idx++);
8312 int remain = rules.Length-idx; 8833 int remain=rules.Length-idx;
8313 8834
8314 switch (code) 8835 switch (code)
8315 { 8836 {
@@ -8339,19 +8860,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8339 break; 8860 break;
8340 8861
8341 case (int)ScriptBaseClass.PRIM_POSITION: 8862 case (int)ScriptBaseClass.PRIM_POSITION:
8342 LSL_Vector v = new LSL_Vector(part.AbsolutePosition); 8863 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
8343 8864 part.AbsolutePosition.Y,
8344 // For some reason, the part.AbsolutePosition.* values do not change if the 8865 part.AbsolutePosition.Z);
8345 // linkset is rotated; they always reflect the child prim's world position
8346 // as though the linkset is unrotated. This is incompatible behavior with SL's
8347 // implementation, so will break scripts imported from there (not to mention it
8348 // makes it more difficult to determine a child prim's actual inworld position).
8349 if (!part.IsRoot)
8350 {
8351 LSL_Vector rootPos = new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
8352 v = ((v - rootPos) * llGetRootRotation()) + rootPos;
8353 }
8354
8355 res.Add(v); 8866 res.Add(v);
8356 break; 8867 break;
8357 8868
@@ -8521,30 +9032,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8521 if (remain < 1) 9032 if (remain < 1)
8522 return null; 9033 return null;
8523 9034
8524 face=(int)rules.GetLSLIntegerItem(idx++); 9035 face = (int)rules.GetLSLIntegerItem(idx++);
8525 9036
8526 tex = part.Shape.Textures; 9037 tex = part.Shape.Textures;
9038 int shiny;
8527 if (face == ScriptBaseClass.ALL_SIDES) 9039 if (face == ScriptBaseClass.ALL_SIDES)
8528 { 9040 {
8529 for (face = 0; face < GetNumberOfSides(part); face++) 9041 for (face = 0; face < GetNumberOfSides(part); face++)
8530 { 9042 {
8531 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 9043 Shininess shinyness = tex.GetFace((uint)face).Shiny;
8532 // Convert Shininess to PRIM_SHINY_* 9044 if (shinyness == Shininess.High)
8533 res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); 9045 {
8534 // PRIM_BUMP_* 9046 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
8535 res.Add(new LSL_Integer((int)texface.Bump)); 9047 }
9048 else if (shinyness == Shininess.Medium)
9049 {
9050 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
9051 }
9052 else if (shinyness == Shininess.Low)
9053 {
9054 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
9055 }
9056 else
9057 {
9058 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
9059 }
9060 res.Add(new LSL_Integer(shiny));
9061 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
8536 } 9062 }
8537 } 9063 }
8538 else 9064 else
8539 { 9065 {
8540 if (face >= 0 && face < GetNumberOfSides(part)) 9066 Shininess shinyness = tex.GetFace((uint)face).Shiny;
9067 if (shinyness == Shininess.High)
8541 { 9068 {
8542 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 9069 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
8543 // Convert Shininess to PRIM_SHINY_* 9070 }
8544 res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); 9071 else if (shinyness == Shininess.Medium)
8545 // PRIM_BUMP_* 9072 {
8546 res.Add(new LSL_Integer((int)texface.Bump)); 9073 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8547 } 9074 }
9075 else if (shinyness == Shininess.Low)
9076 {
9077 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
9078 }
9079 else
9080 {
9081 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
9082 }
9083 res.Add(new LSL_Integer(shiny));
9084 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
8548 } 9085 }
8549 break; 9086 break;
8550 9087
@@ -8555,21 +9092,33 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8555 face = (int)rules.GetLSLIntegerItem(idx++); 9092 face = (int)rules.GetLSLIntegerItem(idx++);
8556 9093
8557 tex = part.Shape.Textures; 9094 tex = part.Shape.Textures;
9095 int fullbright;
8558 if (face == ScriptBaseClass.ALL_SIDES) 9096 if (face == ScriptBaseClass.ALL_SIDES)
8559 { 9097 {
8560 for (face = 0; face < GetNumberOfSides(part); face++) 9098 for (face = 0; face < GetNumberOfSides(part); face++)
8561 { 9099 {
8562 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 9100 if (tex.GetFace((uint)face).Fullbright == true)
8563 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); 9101 {
9102 fullbright = ScriptBaseClass.TRUE;
9103 }
9104 else
9105 {
9106 fullbright = ScriptBaseClass.FALSE;
9107 }
9108 res.Add(new LSL_Integer(fullbright));
8564 } 9109 }
8565 } 9110 }
8566 else 9111 else
8567 { 9112 {
8568 if (face >= 0 && face < GetNumberOfSides(part)) 9113 if (tex.GetFace((uint)face).Fullbright == true)
8569 { 9114 {
8570 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 9115 fullbright = ScriptBaseClass.TRUE;
8571 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
8572 } 9116 }
9117 else
9118 {
9119 fullbright = ScriptBaseClass.FALSE;
9120 }
9121 res.Add(new LSL_Integer(fullbright));
8573 } 9122 }
8574 break; 9123 break;
8575 9124
@@ -8591,27 +9140,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8591 break; 9140 break;
8592 9141
8593 case (int)ScriptBaseClass.PRIM_TEXGEN: 9142 case (int)ScriptBaseClass.PRIM_TEXGEN:
9143 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
8594 if (remain < 1) 9144 if (remain < 1)
8595 return null; 9145 return null;
8596 9146
8597 face=(int)rules.GetLSLIntegerItem(idx++); 9147 face = (int)rules.GetLSLIntegerItem(idx++);
8598 9148
8599 tex = part.Shape.Textures; 9149 tex = part.Shape.Textures;
8600 if (face == ScriptBaseClass.ALL_SIDES) 9150 if (face == ScriptBaseClass.ALL_SIDES)
8601 { 9151 {
8602 for (face = 0; face < GetNumberOfSides(part); face++) 9152 for (face = 0; face < GetNumberOfSides(part); face++)
8603 { 9153 {
8604 MappingType texgen = tex.GetFace((uint)face).TexMapType; 9154 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8605 // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc. 9155 {
8606 res.Add(new LSL_Integer((uint)texgen >> 1)); 9156 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
9157 }
9158 else
9159 {
9160 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
9161 }
8607 } 9162 }
8608 } 9163 }
8609 else 9164 else
8610 { 9165 {
8611 if (face >= 0 && face < GetNumberOfSides(part)) 9166 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8612 { 9167 {
8613 MappingType texgen = tex.GetFace((uint)face).TexMapType; 9168 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8614 res.Add(new LSL_Integer((uint)texgen >> 1)); 9169 }
9170 else
9171 {
9172 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8615 } 9173 }
8616 } 9174 }
8617 break; 9175 break;
@@ -8635,24 +9193,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8635 if (remain < 1) 9193 if (remain < 1)
8636 return null; 9194 return null;
8637 9195
8638 face=(int)rules.GetLSLIntegerItem(idx++); 9196 face = (int)rules.GetLSLIntegerItem(idx++);
8639 9197
8640 tex = part.Shape.Textures; 9198 tex = part.Shape.Textures;
9199 float primglow;
8641 if (face == ScriptBaseClass.ALL_SIDES) 9200 if (face == ScriptBaseClass.ALL_SIDES)
8642 { 9201 {
8643 for (face = 0; face < GetNumberOfSides(part); face++) 9202 for (face = 0; face < GetNumberOfSides(part); face++)
8644 { 9203 {
8645 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 9204 primglow = tex.GetFace((uint)face).Glow;
8646 res.Add(new LSL_Float(texface.Glow)); 9205 res.Add(new LSL_Float(primglow));
8647 } 9206 }
8648 } 9207 }
8649 else 9208 else
8650 { 9209 {
8651 if (face >= 0 && face < GetNumberOfSides(part)) 9210 primglow = tex.GetFace((uint)face).Glow;
8652 { 9211 res.Add(new LSL_Float(primglow));
8653 Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
8654 res.Add(new LSL_Float(texface.Glow));
8655 }
8656 } 9212 }
8657 break; 9213 break;
8658 9214
@@ -8664,15 +9220,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8664 textColor.B)); 9220 textColor.B));
8665 res.Add(new LSL_Float(textColor.A)); 9221 res.Add(new LSL_Float(textColor.A));
8666 break; 9222 break;
9223
8667 case (int)ScriptBaseClass.PRIM_NAME: 9224 case (int)ScriptBaseClass.PRIM_NAME:
8668 res.Add(new LSL_String(part.Name)); 9225 res.Add(new LSL_String(part.Name));
8669 break; 9226 break;
9227
8670 case (int)ScriptBaseClass.PRIM_DESC: 9228 case (int)ScriptBaseClass.PRIM_DESC:
8671 res.Add(new LSL_String(part.Description)); 9229 res.Add(new LSL_String(part.Description));
8672 break; 9230 break;
8673 case (int)ScriptBaseClass.PRIM_ROT_LOCAL: 9231 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
8674 res.Add(new LSL_Rotation(part.RotationOffset)); 9232 res.Add(new LSL_Rotation(part.RotationOffset));
8675 break; 9233 break;
9234
8676 case (int)ScriptBaseClass.PRIM_POS_LOCAL: 9235 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
8677 res.Add(new LSL_Vector(GetPartLocalPos(part))); 9236 res.Add(new LSL_Vector(GetPartLocalPos(part)));
8678 break; 9237 break;
@@ -9283,8 +9842,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9283 // The function returns an ordered list 9842 // The function returns an ordered list
9284 // representing the tokens found in the supplied 9843 // representing the tokens found in the supplied
9285 // sources string. If two successive tokenizers 9844 // sources string. If two successive tokenizers
9286 // are encountered, then a NULL entry is added 9845 // are encountered, then a null-string entry is
9287 // to the list. 9846 // added to the list.
9288 // 9847 //
9289 // It is a precondition that the source and 9848 // It is a precondition that the source and
9290 // toekizer lisst are non-null. If they are null, 9849 // toekizer lisst are non-null. If they are null,
@@ -9292,7 +9851,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9292 // while their lengths are being determined. 9851 // while their lengths are being determined.
9293 // 9852 //
9294 // A small amount of working memoryis required 9853 // A small amount of working memoryis required
9295 // of approximately 8*#tokenizers. 9854 // of approximately 8*#tokenizers + 8*srcstrlen.
9296 // 9855 //
9297 // There are many ways in which this function 9856 // There are many ways in which this function
9298 // can be implemented, this implementation is 9857 // can be implemented, this implementation is
@@ -9308,155 +9867,124 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9308 // and eliminates redundant tokenizers as soon 9867 // and eliminates redundant tokenizers as soon
9309 // as is possible. 9868 // as is possible.
9310 // 9869 //
9311 // The implementation tries to avoid any copying 9870 // The implementation tries to minimize temporary
9312 // of arrays or other objects. 9871 // garbage generation.
9313 // </remarks> 9872 // </remarks>
9314 9873
9315 private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls) 9874 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
9316 { 9875 {
9317 int beginning = 0; 9876 return ParseString2List(src, separators, spacers, true);
9318 int srclen = src.Length; 9877 }
9319 int seplen = separators.Length;
9320 object[] separray = separators.Data;
9321 int spclen = spacers.Length;
9322 object[] spcarray = spacers.Data;
9323 int mlen = seplen+spclen;
9324
9325 int[] offset = new int[mlen+1];
9326 bool[] active = new bool[mlen];
9327
9328 int best;
9329 int j;
9330
9331 // Initial capacity reduces resize cost
9332 9878
9333 LSL_List tokens = new LSL_List(); 9879 private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
9880 {
9881 int srclen = src.Length;
9882 int seplen = separators.Length;
9883 object[] separray = separators.Data;
9884 int spclen = spacers.Length;
9885 object[] spcarray = spacers.Data;
9886 int dellen = 0;
9887 string[] delarray = new string[seplen+spclen];
9334 9888
9335 // All entries are initially valid 9889 int outlen = 0;
9890 string[] outarray = new string[srclen*2+1];
9336 9891
9337 for (int i = 0; i < mlen; i++) 9892 int i, j;
9338 active[i] = true; 9893 string d;
9339 9894
9340 offset[mlen] = srclen; 9895 m_host.AddScriptLPS(1);
9341 9896
9342 while (beginning < srclen) 9897 /*
9898 * Convert separator and spacer lists to C# strings.
9899 * Also filter out null strings so we don't hang.
9900 */
9901 for (i = 0; i < seplen; i ++)
9343 { 9902 {
9903 d = separray[i].ToString();
9904 if (d.Length > 0)
9905 {
9906 delarray[dellen++] = d;
9907 }
9908 }
9909 seplen = dellen;
9344 9910
9345 best = mlen; // as bad as it gets 9911 for (i = 0; i < spclen; i ++)
9912 {
9913 d = spcarray[i].ToString();
9914 if (d.Length > 0)
9915 {
9916 delarray[dellen++] = d;
9917 }
9918 }
9346 9919
9347 // Scan for separators 9920 /*
9921 * Scan through source string from beginning to end.
9922 */
9923 for (i = 0;;)
9924 {
9348 9925
9349 for (j = 0; j < seplen; j++) 9926 /*
9927 * Find earliest delimeter in src starting at i (if any).
9928 */
9929 int earliestDel = -1;
9930 int earliestSrc = srclen;
9931 string earliestStr = null;
9932 for (j = 0; j < dellen; j ++)
9350 { 9933 {
9351 if (separray[j].ToString() == String.Empty) 9934 d = delarray[j];
9352 active[j] = false; 9935 if (d != null)
9353
9354 if (active[j])
9355 { 9936 {
9356 // scan all of the markers 9937 int index = src.IndexOf(d, i);
9357 if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1) 9938 if (index < 0)
9358 { 9939 {
9359 // not present at all 9940 delarray[j] = null; // delim nowhere in src, don't check it anymore
9360 active[j] = false;
9361 } 9941 }
9362 else 9942 else if (index < earliestSrc)
9363 { 9943 {
9364 // present and correct 9944 earliestSrc = index; // where delimeter starts in source string
9365 if (offset[j] < offset[best]) 9945 earliestDel = j; // where delimeter is in delarray[]
9366 { 9946 earliestStr = d; // the delimeter string from delarray[]
9367 // closest so far 9947 if (index == i) break; // can't do any better than found at beg of string
9368 best = j;
9369 if (offset[best] == beginning)
9370 break;
9371 }
9372 } 9948 }
9373 } 9949 }
9374 } 9950 }
9375 9951
9376 // Scan for spacers 9952 /*
9377 9953 * Output source string starting at i through start of earliest delimeter.
9378 if (offset[best] != beginning) 9954 */
9955 if (keepNulls || (earliestSrc > i))
9379 { 9956 {
9380 for (j = seplen; (j < mlen) && (offset[best] > beginning); j++) 9957 outarray[outlen++] = src.Substring(i, earliestSrc - i);
9381 {
9382 if (spcarray[j-seplen].ToString() == String.Empty)
9383 active[j] = false;
9384
9385 if (active[j])
9386 {
9387 // scan all of the markers
9388 if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
9389 {
9390 // not present at all
9391 active[j] = false;
9392 }
9393 else
9394 {
9395 // present and correct
9396 if (offset[j] < offset[best])
9397 {
9398 // closest so far
9399 best = j;
9400 }
9401 }
9402 }
9403 }
9404 } 9958 }
9405 9959
9406 // This is the normal exit from the scanning loop 9960 /*
9961 * If no delimeter found at or after i, we're done scanning.
9962 */
9963 if (earliestDel < 0) break;
9407 9964
9408 if (best == mlen) 9965 /*
9966 * If delimeter was a spacer, output the spacer.
9967 */
9968 if (earliestDel >= seplen)
9409 { 9969 {
9410 // no markers were found on this pass 9970 outarray[outlen++] = earliestStr;
9411 // so we're pretty much done
9412 if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0))
9413 tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
9414 break;
9415 } 9971 }
9416 9972
9417 // Otherwise we just add the newly delimited token 9973 /*
9418 // and recalculate where the search should continue. 9974 * Look at rest of src string following delimeter.
9419 if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0)) 9975 */
9420 tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning))); 9976 i = earliestSrc + earliestStr.Length;
9421
9422 if (best < seplen)
9423 {
9424 beginning = offset[best] + (separray[best].ToString()).Length;
9425 }
9426 else
9427 {
9428 beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
9429 string str = spcarray[best - seplen].ToString();
9430 if ((keepNulls) || ((!keepNulls) && (str.Length > 0)))
9431 tokens.Add(new LSL_String(str));
9432 }
9433 } 9977 }
9434 9978
9435 // This an awkward an not very intuitive boundary case. If the 9979 /*
9436 // last substring is a tokenizer, then there is an implied trailing 9980 * Make up an exact-sized output array suitable for an LSL_List object.
9437 // null list entry. Hopefully the single comparison will not be too 9981 */
9438 // arduous. Alternatively the 'break' could be replced with a return 9982 object[] outlist = new object[outlen];
9439 // but that's shabby programming. 9983 for (i = 0; i < outlen; i ++)
9440
9441 if ((beginning == srclen) && (keepNulls))
9442 { 9984 {
9443 if (srclen != 0) 9985 outlist[i] = new LSL_String(outarray[i]);
9444 tokens.Add(new LSL_String(""));
9445 } 9986 }
9446 9987 return new LSL_List(outlist);
9447 return tokens;
9448 }
9449
9450 public LSL_List llParseString2List(string src, LSL_List separators, LSL_List spacers)
9451 {
9452 m_host.AddScriptLPS(1);
9453 return this.ParseString(src, separators, spacers, false);
9454 }
9455
9456 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
9457 {
9458 m_host.AddScriptLPS(1);
9459 return this.ParseString(src, separators, spacers, true);
9460 } 9988 }
9461 9989
9462 public LSL_Integer llGetObjectPermMask(int mask) 9990 public LSL_Integer llGetObjectPermMask(int mask)
@@ -9551,6 +10079,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9551 case 4: 10079 case 4:
9552 return (int)item.NextPermissions; 10080 return (int)item.NextPermissions;
9553 } 10081 }
10082 m_host.TaskInventory.LockItemsForRead(false);
9554 10083
9555 return -1; 10084 return -1;
9556 } 10085 }
@@ -9754,31 +10283,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9754 UUID key = new UUID(); 10283 UUID key = new UUID();
9755 if (UUID.TryParse(id, out key)) 10284 if (UUID.TryParse(id, out key))
9756 { 10285 {
9757 try 10286 // return total object mass
9758 { 10287 SceneObjectPart part = World.GetSceneObjectPart(key);
9759 SceneObjectPart obj = World.GetSceneObjectPart(World.Entities[key].LocalId); 10288 if (part != null)
9760 if (obj != null) 10289 return part.ParentGroup.GetMass();
9761 return (double)obj.GetMass(); 10290
9762 // the object is null so the key is for an avatar 10291 // the object is null so the key is for an avatar
9763 ScenePresence avatar = World.GetScenePresence(key); 10292 ScenePresence avatar = World.GetScenePresence(key);
9764 if (avatar != null) 10293 if (avatar != null)
9765 if (avatar.IsChildAgent)
9766 // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
9767 // child agents have a mass of 1.0
9768 return 1;
9769 else
9770 return (double)avatar.GetMass();
9771 }
9772 catch (KeyNotFoundException)
9773 { 10294 {
9774 return 0; // The Object/Agent not in the region so just return zero 10295 if (avatar.IsChildAgent)
10296 {
10297 // reference http://www.lslwiki.net/lslwiki/wakka.php?wakka=llGetObjectMass
10298 // child agents have a mass of 1.0
10299 return 1;
10300 }
10301 else
10302 {
10303 return (double)avatar.GetMass();
10304 }
9775 } 10305 }
9776 } 10306 }
9777 return 0; 10307 return 0;
9778 } 10308 }
9779 10309
9780 /// <summary> 10310 /// <summary>
9781 /// illListReplaceList removes the sub-list defined by the inclusive indices 10311 /// llListReplaceList removes the sub-list defined by the inclusive indices
9782 /// start and end and inserts the src list in its place. The inclusive 10312 /// start and end and inserts the src list in its place. The inclusive
9783 /// nature of the indices means that at least one element must be deleted 10313 /// nature of the indices means that at least one element must be deleted
9784 /// if the indices are within the bounds of the existing list. I.e. 2,2 10314 /// if the indices are within the bounds of the existing list. I.e. 2,2
@@ -9835,16 +10365,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9835 // based upon end. Note that if end exceeds the upper 10365 // based upon end. Note that if end exceeds the upper
9836 // bound in this case, the entire destination list 10366 // bound in this case, the entire destination list
9837 // is removed. 10367 // is removed.
9838 else 10368 else if (start == 0)
9839 { 10369 {
9840 if (end + 1 < dest.Length) 10370 if (end + 1 < dest.Length)
9841 {
9842 return src + dest.GetSublist(end + 1, -1); 10371 return src + dest.GetSublist(end + 1, -1);
9843 }
9844 else 10372 else
9845 {
9846 return src; 10373 return src;
9847 } 10374 }
10375 else // Start < 0
10376 {
10377 if (end + 1 < dest.Length)
10378 return dest.GetSublist(end + 1, -1);
10379 else
10380 return new LSL_List();
9848 } 10381 }
9849 } 10382 }
9850 // Finally, if start > end, we strip away a prefix and 10383 // Finally, if start > end, we strip away a prefix and
@@ -9895,17 +10428,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9895 int width = 0; 10428 int width = 0;
9896 int height = 0; 10429 int height = 0;
9897 10430
9898 ParcelMediaCommandEnum? commandToSend = null; 10431 uint commandToSend = 0;
9899 float time = 0.0f; // default is from start 10432 float time = 0.0f; // default is from start
9900 10433
9901 ScenePresence presence = null; 10434 ScenePresence presence = null;
9902 10435
9903 for (int i = 0; i < commandList.Data.Length; i++) 10436 for (int i = 0; i < commandList.Data.Length; i++)
9904 { 10437 {
9905 ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i]; 10438 uint command = (uint)(commandList.GetLSLIntegerItem(i));
9906 switch (command) 10439 switch (command)
9907 { 10440 {
9908 case ParcelMediaCommandEnum.Agent: 10441 case (uint)ParcelMediaCommandEnum.Agent:
9909 // we send only to one agent 10442 // we send only to one agent
9910 if ((i + 1) < commandList.Length) 10443 if ((i + 1) < commandList.Length)
9911 { 10444 {
@@ -9922,25 +10455,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9922 } 10455 }
9923 break; 10456 break;
9924 10457
9925 case ParcelMediaCommandEnum.Loop: 10458 case (uint)ParcelMediaCommandEnum.Loop:
9926 loop = 1; 10459 loop = 1;
9927 commandToSend = command; 10460 commandToSend = command;
9928 update = true; //need to send the media update packet to set looping 10461 update = true; //need to send the media update packet to set looping
9929 break; 10462 break;
9930 10463
9931 case ParcelMediaCommandEnum.Play: 10464 case (uint)ParcelMediaCommandEnum.Play:
9932 loop = 0; 10465 loop = 0;
9933 commandToSend = command; 10466 commandToSend = command;
9934 update = true; //need to send the media update packet to make sure it doesn't loop 10467 update = true; //need to send the media update packet to make sure it doesn't loop
9935 break; 10468 break;
9936 10469
9937 case ParcelMediaCommandEnum.Pause: 10470 case (uint)ParcelMediaCommandEnum.Pause:
9938 case ParcelMediaCommandEnum.Stop: 10471 case (uint)ParcelMediaCommandEnum.Stop:
9939 case ParcelMediaCommandEnum.Unload: 10472 case (uint)ParcelMediaCommandEnum.Unload:
9940 commandToSend = command; 10473 commandToSend = command;
9941 break; 10474 break;
9942 10475
9943 case ParcelMediaCommandEnum.Url: 10476 case (uint)ParcelMediaCommandEnum.Url:
9944 if ((i + 1) < commandList.Length) 10477 if ((i + 1) < commandList.Length)
9945 { 10478 {
9946 if (commandList.Data[i + 1] is LSL_String) 10479 if (commandList.Data[i + 1] is LSL_String)
@@ -9953,7 +10486,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9953 } 10486 }
9954 break; 10487 break;
9955 10488
9956 case ParcelMediaCommandEnum.Texture: 10489 case (uint)ParcelMediaCommandEnum.Texture:
9957 if ((i + 1) < commandList.Length) 10490 if ((i + 1) < commandList.Length)
9958 { 10491 {
9959 if (commandList.Data[i + 1] is LSL_String) 10492 if (commandList.Data[i + 1] is LSL_String)
@@ -9966,7 +10499,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9966 } 10499 }
9967 break; 10500 break;
9968 10501
9969 case ParcelMediaCommandEnum.Time: 10502 case (uint)ParcelMediaCommandEnum.Time:
9970 if ((i + 1) < commandList.Length) 10503 if ((i + 1) < commandList.Length)
9971 { 10504 {
9972 if (commandList.Data[i + 1] is LSL_Float) 10505 if (commandList.Data[i + 1] is LSL_Float)
@@ -9978,7 +10511,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9978 } 10511 }
9979 break; 10512 break;
9980 10513
9981 case ParcelMediaCommandEnum.AutoAlign: 10514 case (uint)ParcelMediaCommandEnum.AutoAlign:
9982 if ((i + 1) < commandList.Length) 10515 if ((i + 1) < commandList.Length)
9983 { 10516 {
9984 if (commandList.Data[i + 1] is LSL_Integer) 10517 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9992,7 +10525,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9992 } 10525 }
9993 break; 10526 break;
9994 10527
9995 case ParcelMediaCommandEnum.Type: 10528 case (uint)ParcelMediaCommandEnum.Type:
9996 if ((i + 1) < commandList.Length) 10529 if ((i + 1) < commandList.Length)
9997 { 10530 {
9998 if (commandList.Data[i + 1] is LSL_String) 10531 if (commandList.Data[i + 1] is LSL_String)
@@ -10005,7 +10538,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10005 } 10538 }
10006 break; 10539 break;
10007 10540
10008 case ParcelMediaCommandEnum.Desc: 10541 case (uint)ParcelMediaCommandEnum.Desc:
10009 if ((i + 1) < commandList.Length) 10542 if ((i + 1) < commandList.Length)
10010 { 10543 {
10011 if (commandList.Data[i + 1] is LSL_String) 10544 if (commandList.Data[i + 1] is LSL_String)
@@ -10018,7 +10551,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10018 } 10551 }
10019 break; 10552 break;
10020 10553
10021 case ParcelMediaCommandEnum.Size: 10554 case (uint)ParcelMediaCommandEnum.Size:
10022 if ((i + 2) < commandList.Length) 10555 if ((i + 2) < commandList.Length)
10023 { 10556 {
10024 if (commandList.Data[i + 1] is LSL_Integer) 10557 if (commandList.Data[i + 1] is LSL_Integer)
@@ -10088,7 +10621,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10088 } 10621 }
10089 } 10622 }
10090 10623
10091 if (commandToSend != null) 10624 if (commandToSend != 0)
10092 { 10625 {
10093 // the commandList contained a start/stop/... command, too 10626 // the commandList contained a start/stop/... command, too
10094 if (presence == null) 10627 if (presence == null)
@@ -10125,7 +10658,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10125 10658
10126 if (aList.Data[i] != null) 10659 if (aList.Data[i] != null)
10127 { 10660 {
10128 switch ((ParcelMediaCommandEnum) aList.Data[i]) 10661 switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
10129 { 10662 {
10130 case ParcelMediaCommandEnum.Url: 10663 case ParcelMediaCommandEnum.Url:
10131 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaURL)); 10664 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaURL));
@@ -10182,15 +10715,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10182 10715
10183 if (quick_pay_buttons.Data.Length < 4) 10716 if (quick_pay_buttons.Data.Length < 4)
10184 { 10717 {
10185 LSLError("List must have at least 4 elements"); 10718 int x;
10186 return; 10719 for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
10720 {
10721 quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
10722 }
10187 } 10723 }
10188 m_host.ParentGroup.RootPart.PayPrice[0]=price; 10724 int[] nPrice = new int[5];
10189 10725 nPrice[0] = price;
10190 m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0]; 10726 nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
10191 m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1]; 10727 nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
10192 m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2]; 10728 nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
10193 m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3]; 10729 nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
10730 m_host.ParentGroup.RootPart.PayPrice = nPrice;
10194 m_host.ParentGroup.HasGroupChanged = true; 10731 m_host.ParentGroup.HasGroupChanged = true;
10195 } 10732 }
10196 10733
@@ -10207,7 +10744,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10207 return Vector3.Zero; 10744 return Vector3.Zero;
10208 } 10745 }
10209 10746
10210 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10747// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
10748 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
10211 if (presence != null) 10749 if (presence != null)
10212 { 10750 {
10213 LSL_Vector pos = new LSL_Vector(presence.CameraPosition); 10751 LSL_Vector pos = new LSL_Vector(presence.CameraPosition);
@@ -10230,7 +10768,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10230 return Quaternion.Identity; 10768 return Quaternion.Identity;
10231 } 10769 }
10232 10770
10233 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10771// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
10772 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
10234 if (presence != null) 10773 if (presence != null)
10235 { 10774 {
10236 return new LSL_Rotation(presence.CameraRotation); 10775 return new LSL_Rotation(presence.CameraRotation);
@@ -10290,14 +10829,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10290 { 10829 {
10291 m_host.AddScriptLPS(1); 10830 m_host.AddScriptLPS(1);
10292 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0); 10831 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
10293 if (detectedParams == null) return; // only works on the first detected avatar 10832 if (detectedParams == null)
10294 10833 {
10834 if (m_host.ParentGroup.IsAttachment == true)
10835 {
10836 detectedParams = new DetectParams();
10837 detectedParams.Key = m_host.OwnerID;
10838 }
10839 else
10840 {
10841 return;
10842 }
10843 }
10844
10295 ScenePresence avatar = World.GetScenePresence(detectedParams.Key); 10845 ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
10296 if (avatar != null) 10846 if (avatar != null)
10297 { 10847 {
10298 avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name, 10848 avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
10299 simname, pos, lookAt); 10849 simname, pos, lookAt);
10300 } 10850 }
10851
10301 ScriptSleep(1000); 10852 ScriptSleep(1000);
10302 } 10853 }
10303 10854
@@ -10421,12 +10972,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10421 10972
10422 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>(); 10973 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
10423 object[] data = rules.Data; 10974 object[] data = rules.Data;
10424 for (int i = 0; i < data.Length; ++i) { 10975 for (int i = 0; i < data.Length; ++i)
10976 {
10425 int type = Convert.ToInt32(data[i++].ToString()); 10977 int type = Convert.ToInt32(data[i++].ToString());
10426 if (i >= data.Length) break; // odd number of entries => ignore the last 10978 if (i >= data.Length) break; // odd number of entries => ignore the last
10427 10979
10428 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3) 10980 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
10429 switch (type) { 10981 switch (type)
10982 {
10430 case ScriptBaseClass.CAMERA_FOCUS: 10983 case ScriptBaseClass.CAMERA_FOCUS:
10431 case ScriptBaseClass.CAMERA_FOCUS_OFFSET: 10984 case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
10432 case ScriptBaseClass.CAMERA_POSITION: 10985 case ScriptBaseClass.CAMERA_POSITION:
@@ -10531,19 +11084,65 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10531 public LSL_String llXorBase64StringsCorrect(string str1, string str2) 11084 public LSL_String llXorBase64StringsCorrect(string str1, string str2)
10532 { 11085 {
10533 m_host.AddScriptLPS(1); 11086 m_host.AddScriptLPS(1);
10534 string ret = String.Empty; 11087
10535 string src1 = llBase64ToString(str1); 11088 if (str1 == String.Empty)
10536 string src2 = llBase64ToString(str2); 11089 return String.Empty;
10537 int c = 0; 11090 if (str2 == String.Empty)
10538 for (int i = 0; i < src1.Length; i++) 11091 return str1;
11092
11093 int len = str2.Length;
11094 if ((len % 4) != 0) // LL is EVIL!!!!
10539 { 11095 {
10540 ret += (char) (src1[i] ^ src2[c]); 11096 while (str2.EndsWith("="))
11097 str2 = str2.Substring(0, str2.Length - 1);
10541 11098
10542 c++; 11099 len = str2.Length;
10543 if (c >= src2.Length) 11100 int mod = len % 4;
10544 c = 0; 11101
11102 if (mod == 1)
11103 str2 = str2.Substring(0, str2.Length - 1);
11104 else if (mod == 2)
11105 str2 += "==";
11106 else if (mod == 3)
11107 str2 += "=";
11108 }
11109
11110 byte[] data1;
11111 byte[] data2;
11112 try
11113 {
11114 data1 = Convert.FromBase64String(str1);
11115 data2 = Convert.FromBase64String(str2);
11116 }
11117 catch (Exception)
11118 {
11119 return new LSL_String(String.Empty);
11120 }
11121
11122 byte[] d2 = new Byte[data1.Length];
11123 int pos = 0;
11124
11125 if (data1.Length <= data2.Length)
11126 {
11127 Array.Copy(data2, 0, d2, 0, data1.Length);
11128 }
11129 else
11130 {
11131 while (pos < data1.Length)
11132 {
11133 len = data1.Length - pos;
11134 if (len > data2.Length)
11135 len = data2.Length;
11136
11137 Array.Copy(data2, 0, d2, pos, len);
11138 pos += len;
11139 }
10545 } 11140 }
10546 return llStringToBase64(ret); 11141
11142 for (pos = 0 ; pos < data1.Length ; pos++ )
11143 data1[pos] ^= d2[pos];
11144
11145 return Convert.ToBase64String(data1);
10547 } 11146 }
10548 11147
10549 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body) 11148 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
@@ -10647,16 +11246,72 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10647 if (userAgent != null) 11246 if (userAgent != null)
10648 httpHeaders["User-Agent"] = userAgent; 11247 httpHeaders["User-Agent"] = userAgent;
10649 11248
11249 // See if the URL contains any header hacks
11250 string[] urlParts = url.Split(new char[] {'\n'});
11251 if (urlParts.Length > 1)
11252 {
11253 // Iterate the passed headers and parse them
11254 for (int i = 1 ; i < urlParts.Length ; i++ )
11255 {
11256 // The rest of those would be added to the body in SL.
11257 // Let's not do that.
11258 if (urlParts[i] == String.Empty)
11259 break;
11260
11261 // See if this could be a valid header
11262 string[] headerParts = urlParts[i].Split(new char[] {':'}, 2);
11263 if (headerParts.Length != 2)
11264 continue;
11265
11266 string headerName = headerParts[0].Trim();
11267 string headerValue = headerParts[1].Trim();
11268
11269 // Filter out headers that could be used to abuse
11270 // another system or cloak the request
11271 if (headerName.ToLower() == "x-secondlife-shard" ||
11272 headerName.ToLower() == "x-secondlife-object-name" ||
11273 headerName.ToLower() == "x-secondlife-object-key" ||
11274 headerName.ToLower() == "x-secondlife-region" ||
11275 headerName.ToLower() == "x-secondlife-local-position" ||
11276 headerName.ToLower() == "x-secondlife-local-velocity" ||
11277 headerName.ToLower() == "x-secondlife-local-rotation" ||
11278 headerName.ToLower() == "x-secondlife-owner-name" ||
11279 headerName.ToLower() == "x-secondlife-owner-key" ||
11280 headerName.ToLower() == "connection" ||
11281 headerName.ToLower() == "content-length" ||
11282 headerName.ToLower() == "from" ||
11283 headerName.ToLower() == "host" ||
11284 headerName.ToLower() == "proxy-authorization" ||
11285 headerName.ToLower() == "referer" ||
11286 headerName.ToLower() == "trailer" ||
11287 headerName.ToLower() == "transfer-encoding" ||
11288 headerName.ToLower() == "via" ||
11289 headerName.ToLower() == "authorization")
11290 continue;
11291
11292 httpHeaders[headerName] = headerValue;
11293 }
11294
11295 // Finally, strip any protocol specifier from the URL
11296 url = urlParts[0].Trim();
11297 int idx = url.IndexOf(" HTTP/");
11298 if (idx != -1)
11299 url = url.Substring(0, idx);
11300 }
11301
10650 string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$"; 11302 string authregex = @"^(https?:\/\/)(\w+):(\w+)@(.*)$";
10651 Regex r = new Regex(authregex); 11303 Regex r = new Regex(authregex);
10652 int[] gnums = r.GetGroupNumbers(); 11304 int[] gnums = r.GetGroupNumbers();
10653 Match m = r.Match(url); 11305 Match m = r.Match(url);
10654 if (m.Success) { 11306 if (m.Success)
10655 for (int i = 1; i < gnums.Length; i++) { 11307 {
11308 for (int i = 1; i < gnums.Length; i++)
11309 {
10656 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]]; 11310 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
10657 //CaptureCollection cc = g.Captures; 11311 //CaptureCollection cc = g.Captures;
10658 } 11312 }
10659 if (m.Groups.Count == 5) { 11313 if (m.Groups.Count == 5)
11314 {
10660 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString()))); 11315 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
10661 url = m.Groups[1].ToString() + m.Groups[4].ToString(); 11316 url = m.Groups[1].ToString() + m.Groups[4].ToString();
10662 } 11317 }
@@ -10859,6 +11514,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10859 11514
10860 LSL_List ret = new LSL_List(); 11515 LSL_List ret = new LSL_List();
10861 UUID key = new UUID(); 11516 UUID key = new UUID();
11517
11518
10862 if (UUID.TryParse(id, out key)) 11519 if (UUID.TryParse(id, out key))
10863 { 11520 {
10864 ScenePresence av = World.GetScenePresence(key); 11521 ScenePresence av = World.GetScenePresence(key);
@@ -10876,13 +11533,33 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10876 ret.Add(new LSL_String("")); 11533 ret.Add(new LSL_String(""));
10877 break; 11534 break;
10878 case ScriptBaseClass.OBJECT_POS: 11535 case ScriptBaseClass.OBJECT_POS:
10879 ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z)); 11536 Vector3 avpos;
11537
11538 if (av.ParentID != 0 && av.ParentPart != null)
11539 {
11540 avpos = av.OffsetPosition;
11541
11542 Vector3 sitOffset = (Zrot(av.Rotation)) * (av.Appearance.AvatarHeight * 0.02638f *2.0f);
11543 avpos -= sitOffset;
11544
11545 avpos = av.ParentPart.GetWorldPosition() + avpos * av.ParentPart.GetWorldRotation();
11546 }
11547 else
11548 avpos = av.AbsolutePosition;
11549
11550 ret.Add(new LSL_Vector((double)avpos.X, (double)avpos.Y, (double)avpos.Z));
10880 break; 11551 break;
10881 case ScriptBaseClass.OBJECT_ROT: 11552 case ScriptBaseClass.OBJECT_ROT:
10882 ret.Add(new LSL_Rotation(av.GetWorldRotation())); 11553 Quaternion avrot = av.Rotation;
11554 if (av.ParentID != 0 && av.ParentPart != null)
11555 {
11556 avrot = av.ParentPart.GetWorldRotation() * avrot;
11557 }
11558 ret.Add(new LSL_Rotation((double)avrot.X, (double)avrot.Y, (double)avrot.Z, (double)avrot.W));
10883 break; 11559 break;
10884 case ScriptBaseClass.OBJECT_VELOCITY: 11560 case ScriptBaseClass.OBJECT_VELOCITY:
10885 ret.Add(new LSL_Vector(av.Velocity.X, av.Velocity.Y, av.Velocity.Z)); 11561 Vector3 avvel = av.Velocity;
11562 ret.Add(new LSL_Vector((double)avvel.X, (double)avvel.Y, (double)avvel.Z));
10886 break; 11563 break;
10887 case ScriptBaseClass.OBJECT_OWNER: 11564 case ScriptBaseClass.OBJECT_OWNER:
10888 ret.Add(new LSL_String(id)); 11565 ret.Add(new LSL_String(id));
@@ -10967,11 +11644,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10967 case ScriptBaseClass.OBJECT_NAME: 11644 case ScriptBaseClass.OBJECT_NAME:
10968 ret.Add(new LSL_String(obj.Name)); 11645 ret.Add(new LSL_String(obj.Name));
10969 break; 11646 break;
10970 case ScriptBaseClass.OBJECT_DESC: 11647 case ScriptBaseClass.OBJECT_DESC:
10971 ret.Add(new LSL_String(obj.Description)); 11648 ret.Add(new LSL_String(obj.Description));
10972 break; 11649 break;
10973 case ScriptBaseClass.OBJECT_POS: 11650 case ScriptBaseClass.OBJECT_POS:
10974 ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z)); 11651 Vector3 opos = obj.AbsolutePosition;
11652 ret.Add(new LSL_Vector(opos.X, opos.Y, opos.Z));
10975 break; 11653 break;
10976 case ScriptBaseClass.OBJECT_ROT: 11654 case ScriptBaseClass.OBJECT_ROT:
10977 { 11655 {
@@ -11021,9 +11699,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11021 // The value returned in SL for normal prims is prim count 11699 // The value returned in SL for normal prims is prim count
11022 ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount)); 11700 ret.Add(new LSL_Integer(obj.ParentGroup.PrimCount));
11023 break; 11701 break;
11024 // The following 3 costs I have intentionaly coded to return zero. They are part of 11702
11025 // "Land Impact" calculations. These calculations are probably not applicable 11703 // costs below may need to be diferent for root parts, need to check
11026 // to OpenSim and are not yet complete in SL
11027 case ScriptBaseClass.OBJECT_SERVER_COST: 11704 case ScriptBaseClass.OBJECT_SERVER_COST:
11028 // The linden calculation is here 11705 // The linden calculation is here
11029 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight 11706 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Server_Weight
@@ -11031,16 +11708,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11031 ret.Add(new LSL_Float(0)); 11708 ret.Add(new LSL_Float(0));
11032 break; 11709 break;
11033 case ScriptBaseClass.OBJECT_STREAMING_COST: 11710 case ScriptBaseClass.OBJECT_STREAMING_COST:
11034 // The linden calculation is here 11711 // The value returned in SL for normal prims is prim count * 0.06
11035 // http://wiki.secondlife.com/wiki/Mesh/Mesh_Streaming_Cost 11712 ret.Add(new LSL_Float(obj.StreamingCost));
11036 // The value returned in SL for normal prims looks like the prim count * 0.06
11037 ret.Add(new LSL_Float(0));
11038 break; 11713 break;
11039 case ScriptBaseClass.OBJECT_PHYSICS_COST: 11714 case ScriptBaseClass.OBJECT_PHYSICS_COST:
11040 // The linden calculation is here 11715 // The value returned in SL for normal prims is prim count
11041 // http://wiki.secondlife.com/wiki/Mesh/Mesh_physics 11716 ret.Add(new LSL_Float(obj.PhysicsCost));
11042 // The value returned in SL for normal prims looks like the prim count
11043 ret.Add(new LSL_Float(0));
11044 break; 11717 break;
11045 case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding 11718 case ScriptBaseClass.OBJECT_CHARACTER_TIME: // Pathfinding
11046 ret.Add(new LSL_Float(0)); 11719 ret.Add(new LSL_Float(0));
@@ -11299,15 +11972,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11299 return result; 11972 return result;
11300 } 11973 }
11301 11974
11302 public void print(string str) 11975 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
11303 { 11976 {
11304 // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print 11977 List<SceneObjectPart> parts = GetLinkParts(link);
11305 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL"); 11978 if (parts.Count < 1)
11306 if (ossl != null) 11979 return 0;
11307 { 11980
11308 ossl.CheckThreatLevel(ThreatLevel.High, "print"); 11981 return GetNumberOfSides(parts[0]);
11309 m_log.Info("LSL print():" + str);
11310 }
11311 } 11982 }
11312 11983
11313 private string Name2Username(string name) 11984 private string Name2Username(string name)
@@ -11352,7 +12023,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11352 12023
11353 return rq.ToString(); 12024 return rq.ToString();
11354 } 12025 }
11355 12026/*
12027 private void SayShoutTimerElapsed(Object sender, ElapsedEventArgs args)
12028 {
12029 m_SayShoutCount = 0;
12030 }
12031*/
11356 private struct Tri 12032 private struct Tri
11357 { 12033 {
11358 public Vector3 p1; 12034 public Vector3 p1;
@@ -11501,9 +12177,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11501 12177
11502 ContactResult result = new ContactResult (); 12178 ContactResult result = new ContactResult ();
11503 result.ConsumerID = group.LocalId; 12179 result.ConsumerID = group.LocalId;
11504 result.Depth = intersection.distance; 12180// result.Depth = intersection.distance;
11505 result.Normal = intersection.normal; 12181 result.Normal = intersection.normal;
11506 result.Pos = intersection.ipoint; 12182 result.Pos = intersection.ipoint;
12183 result.Depth = Vector3.Mag(rayStart - result.Pos);
11507 12184
11508 contacts.Add(result); 12185 contacts.Add(result);
11509 }); 12186 });
@@ -11636,6 +12313,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11636 12313
11637 return contacts[0]; 12314 return contacts[0];
11638 } 12315 }
12316/*
12317 // not done:
12318 private ContactResult[] testRay2NonPhysicalPhantom(Vector3 rayStart, Vector3 raydir, float raylenght)
12319 {
12320 ContactResult[] contacts = null;
12321 World.ForEachSOG(delegate(SceneObjectGroup group)
12322 {
12323 if (m_host.ParentGroup == group)
12324 return;
12325
12326 if (group.IsAttachment)
12327 return;
12328
12329 if(group.RootPart.PhysActor != null)
12330 return;
12331
12332 contacts = group.RayCastGroupPartsOBBNonPhysicalPhantom(rayStart, raydir, raylenght);
12333 });
12334 return contacts;
12335 }
12336*/
11639 12337
11640 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options) 12338 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
11641 { 12339 {
@@ -11759,18 +12457,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11759 } 12457 }
11760 } 12458 }
11761 12459
12460 // Double check this
11762 if (checkTerrain) 12461 if (checkTerrain)
11763 { 12462 {
11764 ContactResult? groundContact = GroundIntersection(rayStart, rayEnd); 12463 bool skipGroundCheck = false;
11765 if (groundContact != null) 12464
11766 results.Add((ContactResult)groundContact); 12465 foreach (ContactResult c in results)
12466 {
12467 if (c.ConsumerID == 0) // Physics gave us a ground collision
12468 skipGroundCheck = true;
12469 }
12470
12471 if (!skipGroundCheck)
12472 {
12473 ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
12474 if (groundContact != null)
12475 results.Add((ContactResult)groundContact);
12476 }
11767 } 12477 }
11768 12478
11769 results.Sort(delegate(ContactResult a, ContactResult b) 12479 results.Sort(delegate(ContactResult a, ContactResult b)
11770 { 12480 {
11771 return a.Depth.CompareTo(b.Depth); 12481 return a.Depth.CompareTo(b.Depth);
11772 }); 12482 });
11773 12483
11774 int values = 0; 12484 int values = 0;
11775 SceneObjectGroup thisgrp = m_host.ParentGroup; 12485 SceneObjectGroup thisgrp = m_host.ParentGroup;
11776 12486
@@ -11863,7 +12573,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11863 case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD: 12573 case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
11864 if (!isAccount) return 0; 12574 if (!isAccount) return 0;
11865 if (estate.HasAccess(id)) return 1; 12575 if (estate.HasAccess(id)) return 1;
11866 if (estate.IsBanned(id)) 12576 if (estate.IsBanned(id, World.GetUserFlags(id)))
11867 estate.RemoveBan(id); 12577 estate.RemoveBan(id);
11868 estate.AddEstateUser(id); 12578 estate.AddEstateUser(id);
11869 break; 12579 break;
@@ -11882,14 +12592,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11882 break; 12592 break;
11883 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD: 12593 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
11884 if (!isAccount) return 0; 12594 if (!isAccount) return 0;
11885 if (estate.IsBanned(id)) return 1; 12595 if (estate.IsBanned(id, World.GetUserFlags(id))) return 1;
11886 EstateBan ban = new EstateBan(); 12596 EstateBan ban = new EstateBan();
11887 ban.EstateID = estate.EstateID; 12597 ban.EstateID = estate.EstateID;
11888 ban.BannedUserID = id; 12598 ban.BannedUserID = id;
11889 estate.AddBan(ban); 12599 estate.AddBan(ban);
11890 break; 12600 break;
11891 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE: 12601 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
11892 if (!isAccount || !estate.IsBanned(id)) return 0; 12602 if (!isAccount || !estate.IsBanned(id, World.GetUserFlags(id))) return 0;
11893 estate.RemoveBan(id); 12603 estate.RemoveBan(id);
11894 break; 12604 break;
11895 default: return 0; 12605 default: return 0;
@@ -11954,13 +12664,63 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11954 public void llCollisionSprite(string impact_sprite) 12664 public void llCollisionSprite(string impact_sprite)
11955 { 12665 {
11956 m_host.AddScriptLPS(1); 12666 m_host.AddScriptLPS(1);
11957 NotImplemented("llCollisionSprite"); 12667 // Viewer 2.0 broke this and it's likely LL has no intention
12668 // of fixing it. Therefore, letting this be a NOP seems appropriate.
11958 } 12669 }
11959 12670
11960 public void llGodLikeRezObject(string inventory, LSL_Vector pos) 12671 public void llGodLikeRezObject(string inventory, LSL_Vector pos)
11961 { 12672 {
11962 m_host.AddScriptLPS(1); 12673 m_host.AddScriptLPS(1);
11963 NotImplemented("llGodLikeRezObject"); 12674
12675 if (!World.Permissions.IsGod(m_host.OwnerID))
12676 NotImplemented("llGodLikeRezObject");
12677
12678 AssetBase rezAsset = World.AssetService.Get(inventory);
12679 if (rezAsset == null)
12680 {
12681 llSay(0, "Asset not found");
12682 return;
12683 }
12684
12685 SceneObjectGroup group = null;
12686
12687 try
12688 {
12689 string xmlData = Utils.BytesToString(rezAsset.Data);
12690 group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
12691 }
12692 catch
12693 {
12694 llSay(0, "Asset not found");
12695 return;
12696 }
12697
12698 if (group == null)
12699 {
12700 llSay(0, "Asset not found");
12701 return;
12702 }
12703
12704 group.RootPart.AttachPoint = group.RootPart.Shape.State;
12705 group.RootPart.AttachOffset = group.AbsolutePosition;
12706
12707 group.ResetIDs();
12708
12709 Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
12710 World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero);
12711 group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3);
12712 group.ScheduleGroupForFullUpdate();
12713
12714 // objects rezzed with this method are die_at_edge by default.
12715 group.RootPart.SetDieAtEdge(true);
12716
12717 group.ResumeScripts();
12718
12719 m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
12720 "object_rez", new Object[] {
12721 new LSL_String(
12722 group.RootPart.UUID.ToString()) },
12723 new DetectParams[0]));
11964 } 12724 }
11965 12725
11966 public LSL_String llTransferLindenDollars(string destination, int amount) 12726 public LSL_String llTransferLindenDollars(string destination, int amount)
@@ -12012,7 +12772,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12012 } 12772 }
12013 12773
12014 bool result = money.ObjectGiveMoney( 12774 bool result = money.ObjectGiveMoney(
12015 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount); 12775 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount, txn);
12016 12776
12017 if (result) 12777 if (result)
12018 { 12778 {
@@ -12037,6 +12797,610 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12037 } 12797 }
12038 12798
12039 #endregion 12799 #endregion
12800
12801 public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
12802 {
12803 SceneObjectGroup group = m_host.ParentGroup;
12804
12805 if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
12806 return;
12807 if (group.IsAttachment)
12808 return;
12809
12810 if (frames.Data.Length > 0) // We are getting a new motion
12811 {
12812 if (group.RootPart.KeyframeMotion != null)
12813 group.RootPart.KeyframeMotion.Delete();
12814 group.RootPart.KeyframeMotion = null;
12815
12816 int idx = 0;
12817
12818 KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
12819 KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
12820
12821 while (idx < options.Data.Length)
12822 {
12823 int option = (int)options.GetLSLIntegerItem(idx++);
12824 int remain = options.Data.Length - idx;
12825
12826 switch (option)
12827 {
12828 case ScriptBaseClass.KFM_MODE:
12829 if (remain < 1)
12830 break;
12831 int modeval = (int)options.GetLSLIntegerItem(idx++);
12832 switch(modeval)
12833 {
12834 case ScriptBaseClass.KFM_FORWARD:
12835 mode = KeyframeMotion.PlayMode.Forward;
12836 break;
12837 case ScriptBaseClass.KFM_REVERSE:
12838 mode = KeyframeMotion.PlayMode.Reverse;
12839 break;
12840 case ScriptBaseClass.KFM_LOOP:
12841 mode = KeyframeMotion.PlayMode.Loop;
12842 break;
12843 case ScriptBaseClass.KFM_PING_PONG:
12844 mode = KeyframeMotion.PlayMode.PingPong;
12845 break;
12846 }
12847 break;
12848 case ScriptBaseClass.KFM_DATA:
12849 if (remain < 1)
12850 break;
12851 int dataval = (int)options.GetLSLIntegerItem(idx++);
12852 data = (KeyframeMotion.DataFormat)dataval;
12853 break;
12854 }
12855 }
12856
12857 group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
12858
12859 idx = 0;
12860
12861 int elemLength = 2;
12862 if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
12863 elemLength = 3;
12864
12865 List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
12866 while (idx < frames.Data.Length)
12867 {
12868 int remain = frames.Data.Length - idx;
12869
12870 if (remain < elemLength)
12871 break;
12872
12873 KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe();
12874 frame.Position = null;
12875 frame.Rotation = null;
12876
12877 if ((data & KeyframeMotion.DataFormat.Translation) != 0)
12878 {
12879 LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
12880 frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
12881 }
12882 if ((data & KeyframeMotion.DataFormat.Rotation) != 0)
12883 {
12884 LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
12885 Quaternion q = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
12886 q.Normalize();
12887 frame.Rotation = q;
12888 }
12889
12890 float tempf = (float)frames.GetLSLFloatItem(idx++);
12891 frame.TimeMS = (int)(tempf * 1000.0f);
12892
12893 keyframes.Add(frame);
12894 }
12895
12896 group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
12897 group.RootPart.KeyframeMotion.Start();
12898 }
12899 else
12900 {
12901 if (group.RootPart.KeyframeMotion == null)
12902 return;
12903
12904 if (options.Data.Length == 0)
12905 {
12906 group.RootPart.KeyframeMotion.Stop();
12907 return;
12908 }
12909
12910 int code = (int)options.GetLSLIntegerItem(0);
12911
12912 int idx = 0;
12913
12914 while (idx < options.Data.Length)
12915 {
12916 int option = (int)options.GetLSLIntegerItem(idx++);
12917 int remain = options.Data.Length - idx;
12918
12919 switch (option)
12920 {
12921 case ScriptBaseClass.KFM_COMMAND:
12922 int cmd = (int)options.GetLSLIntegerItem(idx++);
12923 switch (cmd)
12924 {
12925 case ScriptBaseClass.KFM_CMD_PLAY:
12926 group.RootPart.KeyframeMotion.Start();
12927 break;
12928 case ScriptBaseClass.KFM_CMD_STOP:
12929 group.RootPart.KeyframeMotion.Stop();
12930 break;
12931 case ScriptBaseClass.KFM_CMD_PAUSE:
12932 group.RootPart.KeyframeMotion.Pause();
12933 break;
12934 }
12935 break;
12936 }
12937 }
12938 }
12939 }
12940
12941 protected LSL_List SetPrimParams(ScenePresence av, LSL_List rules, string originFunc, ref uint rulesParsed)
12942 {
12943 //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
12944
12945 int idx = 0;
12946 int idxStart = 0;
12947
12948 bool positionChanged = false;
12949 Vector3 finalPos = Vector3.Zero;
12950
12951 try
12952 {
12953 while (idx < rules.Length)
12954 {
12955 ++rulesParsed;
12956 int code = rules.GetLSLIntegerItem(idx++);
12957
12958 int remain = rules.Length - idx;
12959 idxStart = idx;
12960
12961 switch (code)
12962 {
12963 case (int)ScriptBaseClass.PRIM_POSITION:
12964 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
12965 {
12966 if (remain < 1)
12967 return null;
12968
12969 LSL_Vector v;
12970 v = rules.GetVector3Item(idx++);
12971
12972 SceneObjectPart part = World.GetSceneObjectPart(av.ParentID);
12973 if (part == null)
12974 break;
12975
12976 LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION;
12977 LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR;
12978 if (part.LinkNum > 1)
12979 {
12980 localRot = GetPartLocalRot(part);
12981 localPos = GetPartLocalPos(part);
12982 }
12983
12984 v -= localPos;
12985 v /= localRot;
12986
12987 LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
12988
12989 v = v + 2 * sitOffset;
12990
12991 av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
12992 av.SendAvatarDataToAllAgents();
12993
12994 }
12995 break;
12996
12997 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
12998 case (int)ScriptBaseClass.PRIM_ROTATION:
12999 {
13000 if (remain < 1)
13001 return null;
13002
13003 LSL_Rotation r;
13004 r = rules.GetQuaternionItem(idx++);
13005
13006 SceneObjectPart part = World.GetSceneObjectPart(av.ParentID);
13007 if (part == null)
13008 break;
13009
13010 LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION;
13011 LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR;
13012
13013 if (part.LinkNum > 1)
13014 localRot = GetPartLocalRot(part);
13015
13016 r = r * llGetRootRotation() / localRot;
13017 av.Rotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
13018 av.SendAvatarDataToAllAgents();
13019 }
13020 break;
13021
13022 // parse rest doing nothing but number of parameters error check
13023 case (int)ScriptBaseClass.PRIM_SIZE:
13024 case (int)ScriptBaseClass.PRIM_MATERIAL:
13025 case (int)ScriptBaseClass.PRIM_PHANTOM:
13026 case (int)ScriptBaseClass.PRIM_PHYSICS:
13027 case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
13028 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
13029 case (int)ScriptBaseClass.PRIM_NAME:
13030 case (int)ScriptBaseClass.PRIM_DESC:
13031 if (remain < 1)
13032 return null;
13033 idx++;
13034 break;
13035
13036 case (int)ScriptBaseClass.PRIM_GLOW:
13037 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
13038 case (int)ScriptBaseClass.PRIM_TEXGEN:
13039 if (remain < 2)
13040 return null;
13041 idx += 2;
13042 break;
13043
13044 case (int)ScriptBaseClass.PRIM_TYPE:
13045 if (remain < 3)
13046 return null;
13047 code = (int)rules.GetLSLIntegerItem(idx++);
13048 remain = rules.Length - idx;
13049 switch (code)
13050 {
13051 case (int)ScriptBaseClass.PRIM_TYPE_BOX:
13052 case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
13053 case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
13054 if (remain < 6)
13055 return null;
13056 idx += 6;
13057 break;
13058
13059 case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
13060 if (remain < 5)
13061 return null;
13062 idx += 5;
13063 break;
13064
13065 case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
13066 case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
13067 case (int)ScriptBaseClass.PRIM_TYPE_RING:
13068 if (remain < 11)
13069 return null;
13070 idx += 11;
13071 break;
13072
13073 case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
13074 if (remain < 2)
13075 return null;
13076 idx += 2;
13077 break;
13078 }
13079 break;
13080
13081 case (int)ScriptBaseClass.PRIM_COLOR:
13082 case (int)ScriptBaseClass.PRIM_TEXT:
13083 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
13084 case (int)ScriptBaseClass.PRIM_OMEGA:
13085 if (remain < 3)
13086 return null;
13087 idx += 3;
13088 break;
13089
13090 case (int)ScriptBaseClass.PRIM_TEXTURE:
13091 case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
13092 case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
13093 if (remain < 5)
13094 return null;
13095 idx += 5;
13096 break;
13097
13098 case (int)ScriptBaseClass.PRIM_FLEXIBLE:
13099 if (remain < 7)
13100 return null;
13101
13102 idx += 7;
13103 break;
13104
13105 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
13106 if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
13107 return null;
13108
13109 return rules.GetSublist(idx, -1);
13110 }
13111 }
13112 }
13113 catch (InvalidCastException e)
13114 {
13115 ShoutError(string.Format(
13116 "{0} error running rule #{1}: arg #{2} ",
13117 originFunc, rulesParsed, idx - idxStart) + e.Message);
13118 }
13119 finally
13120 {
13121 if (positionChanged)
13122 {
13123 av.OffsetPosition = finalPos;
13124// av.SendAvatarDataToAllAgents();
13125 av.SendTerseUpdateToAllClients();
13126 positionChanged = false;
13127 }
13128 }
13129 return null;
13130 }
13131
13132 public LSL_List GetPrimParams(ScenePresence avatar, LSL_List rules, ref LSL_List res)
13133 {
13134 // avatars case
13135 // replies as SL wiki
13136
13137// SceneObjectPart sitPart = avatar.ParentPart; // most likelly it will be needed
13138 SceneObjectPart sitPart = World.GetSceneObjectPart(avatar.ParentID); // maybe better do this expensive search for it in case it's gone??
13139
13140 int idx = 0;
13141 while (idx < rules.Length)
13142 {
13143 int code = (int)rules.GetLSLIntegerItem(idx++);
13144 int remain = rules.Length - idx;
13145
13146 switch (code)
13147 {
13148 case (int)ScriptBaseClass.PRIM_MATERIAL:
13149 res.Add(new LSL_Integer((int)SOPMaterialData.SopMaterial.Flesh));
13150 break;
13151
13152 case (int)ScriptBaseClass.PRIM_PHYSICS:
13153 res.Add(new LSL_Integer(0));
13154 break;
13155
13156 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
13157 res.Add(new LSL_Integer(0));
13158 break;
13159
13160 case (int)ScriptBaseClass.PRIM_PHANTOM:
13161 res.Add(new LSL_Integer(0));
13162 break;
13163
13164 case (int)ScriptBaseClass.PRIM_POSITION:
13165
13166 Vector3 pos = avatar.OffsetPosition;
13167
13168 Vector3 sitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f *2.0f);
13169 pos -= sitOffset;
13170
13171 if( sitPart != null)
13172 pos = sitPart.GetWorldPosition() + pos * sitPart.GetWorldRotation();
13173
13174 res.Add(new LSL_Vector(pos.X,pos.Y,pos.Z));
13175 break;
13176
13177 case (int)ScriptBaseClass.PRIM_SIZE:
13178 // as in llGetAgentSize above
13179// res.Add(new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight));
13180 Vector3 s = avatar.Appearance.AvatarSize;
13181 res.Add(new LSL_Vector(s.X, s.Y, s.Z));
13182
13183 break;
13184
13185 case (int)ScriptBaseClass.PRIM_ROTATION:
13186 Quaternion rot = avatar.Rotation;
13187 if (sitPart != null)
13188 {
13189 rot = sitPart.GetWorldRotation() * rot; // apply sit part world rotation
13190 }
13191
13192 res.Add(new LSL_Rotation (rot.X, rot.Y, rot.Z, rot.W));
13193 break;
13194
13195 case (int)ScriptBaseClass.PRIM_TYPE:
13196 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
13197 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
13198 res.Add(new LSL_Vector(0f,1.0f,0f));
13199 res.Add(new LSL_Float(0.0f));
13200 res.Add(new LSL_Vector(0, 0, 0));
13201 res.Add(new LSL_Vector(1.0f,1.0f,0f));
13202 res.Add(new LSL_Vector(0, 0, 0));
13203 break;
13204
13205 case (int)ScriptBaseClass.PRIM_TEXTURE:
13206 if (remain < 1)
13207 return null;
13208
13209 int face = (int)rules.GetLSLIntegerItem(idx++);
13210 if (face == ScriptBaseClass.ALL_SIDES)
13211 {
13212 for (face = 0; face < 21; face++)
13213 {
13214 res.Add(new LSL_String(""));
13215 res.Add(new LSL_Vector(0,0,0));
13216 res.Add(new LSL_Vector(0,0,0));
13217 res.Add(new LSL_Float(0.0));
13218 }
13219 }
13220 else
13221 {
13222 if (face >= 0 && face < 21)
13223 {
13224 res.Add(new LSL_String(""));
13225 res.Add(new LSL_Vector(0,0,0));
13226 res.Add(new LSL_Vector(0,0,0));
13227 res.Add(new LSL_Float(0.0));
13228 }
13229 }
13230 break;
13231
13232 case (int)ScriptBaseClass.PRIM_COLOR:
13233 if (remain < 1)
13234 return null;
13235
13236 face = (int)rules.GetLSLIntegerItem(idx++);
13237
13238 if (face == ScriptBaseClass.ALL_SIDES)
13239 {
13240 for (face = 0; face < 21; face++)
13241 {
13242 res.Add(new LSL_Vector(0,0,0));
13243 res.Add(new LSL_Float(0));
13244 }
13245 }
13246 else
13247 {
13248 res.Add(new LSL_Vector(0,0,0));
13249 res.Add(new LSL_Float(0));
13250 }
13251 break;
13252
13253 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
13254 if (remain < 1)
13255 return null;
13256 face = (int)rules.GetLSLIntegerItem(idx++);
13257
13258 if (face == ScriptBaseClass.ALL_SIDES)
13259 {
13260 for (face = 0; face < 21; face++)
13261 {
13262 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
13263 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
13264 }
13265 }
13266 else
13267 {
13268 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
13269 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
13270 }
13271 break;
13272
13273 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
13274 if (remain < 1)
13275 return null;
13276 face = (int)rules.GetLSLIntegerItem(idx++);
13277
13278 if (face == ScriptBaseClass.ALL_SIDES)
13279 {
13280 for (face = 0; face < 21; face++)
13281 {
13282 res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
13283 }
13284 }
13285 else
13286 {
13287 res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
13288 }
13289 break;
13290
13291 case (int)ScriptBaseClass.PRIM_FLEXIBLE:
13292 res.Add(new LSL_Integer(0));
13293 res.Add(new LSL_Integer(0));// softness
13294 res.Add(new LSL_Float(0.0f)); // gravity
13295 res.Add(new LSL_Float(0.0f)); // friction
13296 res.Add(new LSL_Float(0.0f)); // wind
13297 res.Add(new LSL_Float(0.0f)); // tension
13298 res.Add(new LSL_Vector(0f,0f,0f));
13299 break;
13300
13301 case (int)ScriptBaseClass.PRIM_TEXGEN:
13302 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
13303 if (remain < 1)
13304 return null;
13305 face = (int)rules.GetLSLIntegerItem(idx++);
13306
13307 if (face == ScriptBaseClass.ALL_SIDES)
13308 {
13309 for (face = 0; face < 21; face++)
13310 {
13311 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
13312 }
13313 }
13314 else
13315 {
13316 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
13317 }
13318 break;
13319
13320 case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
13321 res.Add(new LSL_Integer(0));
13322 res.Add(new LSL_Vector(0f,0f,0f));
13323 res.Add(new LSL_Float(0f)); // intensity
13324 res.Add(new LSL_Float(0f)); // radius
13325 res.Add(new LSL_Float(0f)); // falloff
13326 break;
13327
13328 case (int)ScriptBaseClass.PRIM_GLOW:
13329 if (remain < 1)
13330 return null;
13331 face = (int)rules.GetLSLIntegerItem(idx++);
13332
13333 if (face == ScriptBaseClass.ALL_SIDES)
13334 {
13335 for (face = 0; face < 21; face++)
13336 {
13337 res.Add(new LSL_Float(0f));
13338 }
13339 }
13340 else
13341 {
13342 res.Add(new LSL_Float(0f));
13343 }
13344 break;
13345
13346 case (int)ScriptBaseClass.PRIM_TEXT:
13347 res.Add(new LSL_String(""));
13348 res.Add(new LSL_Vector(0f,0f,0f));
13349 res.Add(new LSL_Float(1.0f));
13350 break;
13351
13352 case (int)ScriptBaseClass.PRIM_NAME:
13353 res.Add(new LSL_String(avatar.Name));
13354 break;
13355
13356 case (int)ScriptBaseClass.PRIM_DESC:
13357 res.Add(new LSL_String(""));
13358 break;
13359
13360 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
13361 Quaternion lrot = avatar.Rotation;
13362
13363 if (sitPart != null && sitPart != sitPart.ParentGroup.RootPart)
13364 {
13365 lrot = sitPart.RotationOffset * lrot; // apply sit part rotation offset
13366 }
13367 res.Add(new LSL_Rotation(lrot.X, lrot.Y, lrot.Z, lrot.W));
13368 break;
13369
13370 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
13371 Vector3 lpos = avatar.OffsetPosition; // pos relative to sit part
13372 Vector3 lsitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f * 2.0f);
13373 lpos -= lsitOffset;
13374
13375 if (sitPart != null && sitPart != sitPart.ParentGroup.RootPart)
13376 {
13377 lpos = sitPart.OffsetPosition + (lpos * sitPart.RotationOffset); // make it relative to root prim
13378 }
13379 res.Add(new LSL_Vector(lpos.X,lpos.Y,lpos.Z));
13380 break;
13381
13382 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
13383 if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
13384 return null;
13385
13386 return rules.GetSublist(idx, -1);
13387 }
13388 }
13389
13390 return null;
13391 }
13392
13393 public void llSetContentType(LSL_Key id, LSL_Integer content_type)
13394 {
13395 if (m_UrlModule != null)
13396 {
13397 string type = "text.plain";
13398 if (content_type == (int)ScriptBaseClass.CONTENT_TYPE_HTML)
13399 type = "text/html";
13400
13401 m_UrlModule.HttpContentType(new UUID(id),type);
13402 }
13403 }
12040 } 13404 }
12041 13405
12042 public class NotecardCache 13406 public class NotecardCache
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
index 21bae27..bd776b6 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -136,7 +136,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
136// ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType); 136// ((MethodInfo)MethodBase.GetCurrentMethod()).ReturnType);
137 137
138 Type returntype = m_comms.LookupReturnType(fname); 138 Type returntype = m_comms.LookupReturnType(fname);
139 if (returntype != typeof(string)) 139 if (returntype != typeof(void))
140 MODError(String.Format("return type mismatch for {0}",fname)); 140 MODError(String.Format("return type mismatch for {0}",fname));
141 141
142 modInvoke(fname,parms); 142 modInvoke(fname,parms);
@@ -329,6 +329,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
329 if (result != null) 329 if (result != null)
330 return result; 330 return result;
331 331
332 Type returntype = m_comms.LookupReturnType(fname);
333 if (returntype == typeof(void))
334 return null;
335
332 MODError(String.Format("Invocation of {0} failed; null return value",fname)); 336 MODError(String.Format("Invocation of {0} failed; null return value",fname));
333 } 337 }
334 catch (Exception e) 338 catch (Exception e)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 415166a..f4e4f44 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -139,6 +139,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
139 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; 139 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
140 internal float m_ScriptDelayFactor = 1.0f; 140 internal float m_ScriptDelayFactor = 1.0f;
141 internal float m_ScriptDistanceFactor = 1.0f; 141 internal float m_ScriptDistanceFactor = 1.0f;
142 internal bool m_debuggerSafe = false;
142 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); 143 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
143 144
144 protected IUrlModule m_UrlModule = null; 145 protected IUrlModule m_UrlModule = null;
@@ -149,6 +150,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
149 m_ScriptEngine = scriptEngine; 150 m_ScriptEngine = scriptEngine;
150 m_host = host; 151 m_host = host;
151 m_item = item; 152 m_item = item;
153 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
152 154
153 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>(); 155 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
154 156
@@ -212,7 +214,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
212 214
213 internal void OSSLError(string msg) 215 internal void OSSLError(string msg)
214 { 216 {
215 throw new ScriptException("OSSL Runtime Error: " + msg); 217 if (m_debuggerSafe)
218 {
219 OSSLShoutError(msg);
220 }
221 else
222 {
223 throw new ScriptException("OSSL Runtime Error: " + msg);
224 }
216 } 225 }
217 226
218 /// <summary> 227 /// <summary>
@@ -931,18 +940,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
931 if (target != null) 940 if (target != null)
932 { 941 {
933 UUID animID=UUID.Zero; 942 UUID animID=UUID.Zero;
934 lock (m_host.TaskInventory) 943 m_host.TaskInventory.LockItemsForRead(true);
944 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
935 { 945 {
936 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 946 if (inv.Value.Name == animation)
937 { 947 {
938 if (inv.Value.Name == animation) 948 if (inv.Value.Type == (int)AssetType.Animation)
939 { 949 animID = inv.Value.AssetID;
940 if (inv.Value.Type == (int)AssetType.Animation) 950 continue;
941 animID = inv.Value.AssetID;
942 continue;
943 }
944 } 951 }
945 } 952 }
953 m_host.TaskInventory.LockItemsForRead(false);
946 if (animID == UUID.Zero) 954 if (animID == UUID.Zero)
947 target.Animator.AddAnimation(animation, m_host.UUID); 955 target.Animator.AddAnimation(animation, m_host.UUID);
948 else 956 else
@@ -983,6 +991,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
983 else 991 else
984 animID = UUID.Zero; 992 animID = UUID.Zero;
985 } 993 }
994 m_host.TaskInventory.LockItemsForRead(false);
986 995
987 if (animID == UUID.Zero) 996 if (animID == UUID.Zero)
988 target.Animator.RemoveAnimation(animation); 997 target.Animator.RemoveAnimation(animation);
@@ -1645,7 +1654,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1645 } 1654 }
1646 } 1655 }
1647 1656
1648 public Object osParseJSONNew(string JSON) 1657 private Object osParseJSONNew(string JSON)
1649 { 1658 {
1650 CheckThreatLevel(ThreatLevel.None, "osParseJSONNew"); 1659 CheckThreatLevel(ThreatLevel.None, "osParseJSONNew");
1651 1660
@@ -1847,15 +1856,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1847 { 1856 {
1848 UUID assetID = UUID.Zero; 1857 UUID assetID = UUID.Zero;
1849 1858
1850 if (!UUID.TryParse(notecardNameOrUuid, out assetID)) 1859 bool notecardNameIsUUID = UUID.TryParse(notecardNameOrUuid, out assetID);
1860
1861 if (!notecardNameIsUUID)
1851 { 1862 {
1852 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1863 assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
1853 {
1854 if (item.Type == 7 && item.Name == notecardNameOrUuid)
1855 {
1856 assetID = item.AssetID;
1857 }
1858 }
1859 } 1864 }
1860 1865
1861 if (assetID == UUID.Zero) 1866 if (assetID == UUID.Zero)
@@ -1866,7 +1871,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1866 AssetBase a = World.AssetService.Get(assetID.ToString()); 1871 AssetBase a = World.AssetService.Get(assetID.ToString());
1867 1872
1868 if (a == null) 1873 if (a == null)
1869 return UUID.Zero; 1874 {
1875 // Whoops, it's still possible here that the notecard name was properly
1876 // formatted like a UUID but isn't an asset UUID so lets look it up by name after all
1877 assetID = SearchTaskInventoryForAssetId(notecardNameOrUuid);
1878 if (assetID == UUID.Zero)
1879 return UUID.Zero;
1880
1881 if (!NotecardCache.IsCached(assetID))
1882 {
1883 a = World.AssetService.Get(assetID.ToString());
1884
1885 if (a == null)
1886 {
1887 return UUID.Zero;
1888 }
1889 }
1890 }
1870 1891
1871 string data = Encoding.UTF8.GetString(a.Data); 1892 string data = Encoding.UTF8.GetString(a.Data);
1872 NotecardCache.Cache(assetID, data); 1893 NotecardCache.Cache(assetID, data);
@@ -1874,6 +1895,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1874 1895
1875 return assetID; 1896 return assetID;
1876 } 1897 }
1898 protected UUID SearchTaskInventoryForAssetId(string name)
1899 {
1900 UUID assetId = UUID.Zero;
1901 m_host.TaskInventory.LockItemsForRead(true);
1902 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1903 {
1904 if (item.Type == 7 && item.Name == name)
1905 {
1906 assetId = item.AssetID;
1907 }
1908 }
1909 m_host.TaskInventory.LockItemsForRead(false);
1910 return assetId;
1911 }
1877 1912
1878 /// <summary> 1913 /// <summary>
1879 /// Directly get an entire notecard at once. 1914 /// Directly get an entire notecard at once.
@@ -2351,7 +2386,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2351 CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); 2386 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2352 m_host.AddScriptLPS(1); 2387 m_host.AddScriptLPS(1);
2353 2388
2354 return NpcCreate(firstname, lastname, position, notecard, false, false); 2389 return NpcCreate(firstname, lastname, position, notecard, true, false);
2355 } 2390 }
2356 2391
2357 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) 2392 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
@@ -2362,24 +2397,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2362 return NpcCreate( 2397 return NpcCreate(
2363 firstname, lastname, position, notecard, 2398 firstname, lastname, position, notecard,
2364 (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0, 2399 (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0,
2365 (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0); 2400 false);
2401// (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0);
2366 } 2402 }
2367 2403
2368 private LSL_Key NpcCreate( 2404 private LSL_Key NpcCreate(
2369 string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent) 2405 string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent)
2370 { 2406 {
2407 if (!owned)
2408 OSSLError("Unowned NPCs are unsupported");
2409
2410 string groupTitle = String.Empty;
2411
2412 if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z)))
2413 return new LSL_Key(UUID.Zero.ToString());
2414
2415 if (firstname != String.Empty || lastname != String.Empty)
2416 {
2417 if (firstname != "Shown outfit:")
2418 groupTitle = "- NPC -";
2419 }
2420
2371 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2421 INPCModule module = World.RequestModuleInterface<INPCModule>();
2372 if (module != null) 2422 if (module != null)
2373 { 2423 {
2374 AvatarAppearance appearance = null; 2424 AvatarAppearance appearance = null;
2375 2425
2376 UUID id; 2426// UUID id;
2377 if (UUID.TryParse(notecard, out id)) 2427// if (UUID.TryParse(notecard, out id))
2378 { 2428// {
2379 ScenePresence clonePresence = World.GetScenePresence(id); 2429// ScenePresence clonePresence = World.GetScenePresence(id);
2380 if (clonePresence != null) 2430// if (clonePresence != null)
2381 appearance = clonePresence.Appearance; 2431// appearance = clonePresence.Appearance;
2382 } 2432// }
2383 2433
2384 if (appearance == null) 2434 if (appearance == null)
2385 { 2435 {
@@ -2387,9 +2437,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2387 2437
2388 if (appearanceSerialized != null) 2438 if (appearanceSerialized != null)
2389 { 2439 {
2390 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); 2440 try
2391 appearance = new AvatarAppearance(); 2441 {
2392 appearance.Unpack(appearanceOsd); 2442 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
2443 appearance = new AvatarAppearance();
2444 appearance.Unpack(appearanceOsd);
2445 }
2446 catch
2447 {
2448 return UUID.Zero.ToString();
2449 }
2393 } 2450 }
2394 else 2451 else
2395 { 2452 {
@@ -2408,6 +2465,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2408 World, 2465 World,
2409 appearance); 2466 appearance);
2410 2467
2468 ScenePresence sp;
2469 if (World.TryGetScenePresence(x, out sp))
2470 {
2471 sp.Grouptitle = groupTitle;
2472 sp.SendAvatarDataToAllAgents();
2473 }
2411 return new LSL_Key(x.ToString()); 2474 return new LSL_Key(x.ToString());
2412 } 2475 }
2413 2476
@@ -2705,16 +2768,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2705 CheckThreatLevel(ThreatLevel.High, "osNpcRemove"); 2768 CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
2706 m_host.AddScriptLPS(1); 2769 m_host.AddScriptLPS(1);
2707 2770
2708 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2771 ManualResetEvent ev = new ManualResetEvent(false);
2709 if (module != null)
2710 {
2711 UUID npcId = new UUID(npc.m_string);
2712 2772
2713 if (!module.CheckPermissions(npcId, m_host.OwnerID)) 2773 Util.FireAndForget(delegate(object x) {
2714 return; 2774 try
2775 {
2776 INPCModule module = World.RequestModuleInterface<INPCModule>();
2777 if (module != null)
2778 {
2779 UUID npcId = new UUID(npc.m_string);
2715 2780
2716 module.DeleteNPC(npcId, World); 2781 ILandObject l = World.LandChannel.GetLandObject(m_host.GroupPosition.X, m_host.GroupPosition.Y);
2717 } 2782 if (l == null || m_host.OwnerID != l.LandData.OwnerID)
2783 {
2784 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2785 return;
2786 }
2787
2788 module.DeleteNPC(npcId, World);
2789 }
2790 }
2791 finally
2792 {
2793 ev.Set();
2794 }
2795 });
2796 ev.WaitOne();
2718 } 2797 }
2719 2798
2720 public void osNpcPlayAnimation(LSL_Key npc, string animation) 2799 public void osNpcPlayAnimation(LSL_Key npc, string animation)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index 88ab515..a47e452 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -93,7 +93,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
93 private const int AGENT = 1; 93 private const int AGENT = 1;
94 private const int AGENT_BY_USERNAME = 0x10; 94 private const int AGENT_BY_USERNAME = 0x10;
95 private const int NPC = 0x20; 95 private const int NPC = 0x20;
96 private const int OS_NPC = 0x01000000;
97 private const int ACTIVE = 2; 96 private const int ACTIVE = 2;
98 private const int PASSIVE = 4; 97 private const int PASSIVE = 4;
99 private const int SCRIPTED = 8; 98 private const int SCRIPTED = 8;
@@ -240,7 +239,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
240 List<SensedEntity> sensedEntities = new List<SensedEntity>(); 239 List<SensedEntity> sensedEntities = new List<SensedEntity>();
241 240
242 // Is the sensor type is AGENT and not SCRIPTED then include agents 241 // Is the sensor type is AGENT and not SCRIPTED then include agents
243 if ((ts.type & (AGENT | AGENT_BY_USERNAME | NPC | OS_NPC)) != 0 && (ts.type & SCRIPTED) == 0) 242 if ((ts.type & (AGENT | AGENT_BY_USERNAME | NPC)) != 0 && (ts.type & SCRIPTED) == 0)
244 { 243 {
245 sensedEntities.AddRange(doAgentSensor(ts)); 244 sensedEntities.AddRange(doAgentSensor(ts));
246 } 245 }
@@ -339,7 +338,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
339 float dy; 338 float dy;
340 float dz; 339 float dz;
341 340
342 Quaternion q = SensePoint.GetWorldRotation(); 341// Quaternion q = SensePoint.RotationOffset;
342 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation!
343 if (SensePoint.ParentGroup.IsAttachment) 343 if (SensePoint.ParentGroup.IsAttachment)
344 { 344 {
345 // In attachments, rotate the sensor cone with the 345 // In attachments, rotate the sensor cone with the
@@ -353,7 +353,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
353 // Position of a sensor in a child prim attached to an avatar 353 // Position of a sensor in a child prim attached to an avatar
354 // will be still wrong. 354 // will be still wrong.
355 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 355 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
356 q = avatar.GetWorldRotation() * q; 356 fromRegionPos = avatar.AbsolutePosition;
357 q = avatar.Rotation;
357 } 358 }
358 359
359 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q); 360 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q);
@@ -397,7 +398,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
397 objtype = 0; 398 objtype = 0;
398 399
399 part = ((SceneObjectGroup)ent).RootPart; 400 part = ((SceneObjectGroup)ent).RootPart;
400 if (part.ParentGroup.AttachmentPoint != 0) // Attached so ignore 401 if (part.ParentGroup.RootPart.Shape.PCode != (byte)PCode.Tree &&
402 part.ParentGroup.RootPart.Shape.PCode != (byte)PCode.NewTree &&
403 part.ParentGroup.AttachmentPoint != 0) // Attached so ignore
401 continue; 404 continue;
402 405
403 if (part.Inventory.ContainsScripts()) 406 if (part.Inventory.ContainsScripts())
@@ -480,7 +483,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
480 // Position of a sensor in a child prim attached to an avatar 483 // Position of a sensor in a child prim attached to an avatar
481 // will be still wrong. 484 // will be still wrong.
482 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 485 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
483 q = avatar.GetWorldRotation() * q; 486 if (avatar == null)
487 return sensedEntities;
488 fromRegionPos = avatar.AbsolutePosition;
489 q = avatar.Rotation;
484 } 490 }
485 491
486 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q); 492 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q);
@@ -496,7 +502,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
496// "[SENSOR REPEAT]: Inspecting scene presence {0}, type {1} on sensor sweep for {2}, type {3}", 502// "[SENSOR REPEAT]: Inspecting scene presence {0}, type {1} on sensor sweep for {2}, type {3}",
497// presence.Name, presence.PresenceType, ts.name, ts.type); 503// presence.Name, presence.PresenceType, ts.name, ts.type);
498 504
499 if ((ts.type & NPC) == 0 && (ts.type & OS_NPC) == 0 && presence.PresenceType == PresenceType.Npc) 505 if ((ts.type & NPC) == 0 && presence.PresenceType == PresenceType.Npc)
500 { 506 {
501 INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene); 507 INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene);
502 if (npcData == null || !npcData.SenseAsAgent) 508 if (npcData == null || !npcData.SenseAsAgent)
@@ -696,4 +702,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
696 return retList; 702 return retList;
697 } 703 }
698 } 704 }
699} \ No newline at end of file 705}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
index 0b14565..68aacd2 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
@@ -123,25 +123,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
123 if (Timers.Count == 0) 123 if (Timers.Count == 0)
124 return; 124 return;
125 125
126 Dictionary<string, TimerInfo>.ValueCollection tvals;
126 lock (TimerListLock) 127 lock (TimerListLock)
127 { 128 {
128 // Go through all timers 129 // Go through all timers
129 Dictionary<string, TimerInfo>.ValueCollection tvals = Timers.Values; 130 tvals = Timers.Values;
130 foreach (TimerInfo ts in tvals) 131 }
132
133 foreach (TimerInfo ts in tvals)
134 {
135 // Time has passed?
136 if (ts.next < DateTime.Now.Ticks)
131 { 137 {
132 // Time has passed? 138 //m_log.Debug("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next);
133 if (ts.next < DateTime.Now.Ticks) 139 // Add it to queue
134 { 140 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
135 //m_log.Debug("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next); 141 new EventParams("timer", new Object[0],
136 // Add it to queue 142 new DetectParams[0]));
137 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID, 143 // set next interval
138 new EventParams("timer", new Object[0], 144
139 new DetectParams[0])); 145 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
140 // set next interval 146 ts.next = DateTime.Now.Ticks + ts.interval;
141
142 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
143 ts.next = DateTime.Now.Ticks + ts.interval;
144 }
145 } 147 }
146 } 148 }
147 } 149 }
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 a6ea88c..daf89e5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
@@ -126,6 +126,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
126 LSL_Float llGetEnergy(); 126 LSL_Float llGetEnergy();
127 LSL_Vector llGetForce(); 127 LSL_Vector llGetForce();
128 LSL_Integer llGetFreeMemory(); 128 LSL_Integer llGetFreeMemory();
129 LSL_Integer llGetUsedMemory();
129 LSL_Integer llGetFreeURLs(); 130 LSL_Integer llGetFreeURLs();
130 LSL_Vector llGetGeometricCenter(); 131 LSL_Vector llGetGeometricCenter();
131 LSL_Float llGetGMTclock(); 132 LSL_Float llGetGMTclock();
@@ -149,6 +150,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
149 LSL_Vector llGetLocalPos(); 150 LSL_Vector llGetLocalPos();
150 LSL_Rotation llGetLocalRot(); 151 LSL_Rotation llGetLocalRot();
151 LSL_Float llGetMass(); 152 LSL_Float llGetMass();
153 LSL_Float llGetMassMKS();
152 LSL_Integer llGetMemoryLimit(); 154 LSL_Integer llGetMemoryLimit();
153 void llGetNextEmail(string address, string subject); 155 void llGetNextEmail(string address, string subject);
154 LSL_String llGetNotecardLine(string name, int line); 156 LSL_String llGetNotecardLine(string name, int line);
@@ -202,12 +204,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
202 LSL_String llGetTimestamp(); 204 LSL_String llGetTimestamp();
203 LSL_Vector llGetTorque(); 205 LSL_Vector llGetTorque();
204 LSL_Integer llGetUnixTime(); 206 LSL_Integer llGetUnixTime();
205 LSL_Integer llGetUsedMemory();
206 LSL_Vector llGetVel(); 207 LSL_Vector llGetVel();
207 LSL_Float llGetWallclock(); 208 LSL_Float llGetWallclock();
208 void llGiveInventory(string destination, string inventory); 209 void llGiveInventory(string destination, string inventory);
209 void llGiveInventoryList(string destination, string category, LSL_List inventory); 210 void llGiveInventoryList(string destination, string category, LSL_List inventory);
210 void llGiveMoney(string destination, int amount); 211 LSL_Integer llGiveMoney(string destination, int amount);
211 LSL_String llTransferLindenDollars(string destination, int amount); 212 LSL_String llTransferLindenDollars(string destination, int amount);
212 void llGodLikeRezObject(string inventory, LSL_Vector pos); 213 void llGodLikeRezObject(string inventory, LSL_Vector pos);
213 LSL_Float llGround(LSL_Vector offset); 214 LSL_Float llGround(LSL_Vector offset);
@@ -331,6 +332,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
331 void llSensorRemove(); 332 void llSensorRemove();
332 void llSensorRepeat(string name, string id, int type, double range, double arc, double rate); 333 void llSensorRepeat(string name, string id, int type, double range, double arc, double rate);
333 void llSetAlpha(double alpha, int face); 334 void llSetAlpha(double alpha, int face);
335 void llSetAngularVelocity(LSL_Vector angvelocity, int local);
334 void llSetBuoyancy(double buoyancy); 336 void llSetBuoyancy(double buoyancy);
335 void llSetCameraAtOffset(LSL_Vector offset); 337 void llSetCameraAtOffset(LSL_Vector offset);
336 void llSetCameraEyeOffset(LSL_Vector offset); 338 void llSetCameraEyeOffset(LSL_Vector offset);
@@ -357,11 +359,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
357 void llSetParcelMusicURL(string url); 359 void llSetParcelMusicURL(string url);
358 void llSetPayPrice(int price, LSL_List quick_pay_buttons); 360 void llSetPayPrice(int price, LSL_List quick_pay_buttons);
359 void llSetPos(LSL_Vector pos); 361 void llSetPos(LSL_Vector pos);
362 LSL_Integer llSetRegionPos(LSL_Vector pos);
360 LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules); 363 LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules);
361 void llSetPrimitiveParams(LSL_List rules); 364 void llSetPrimitiveParams(LSL_List rules);
362 void llSetLinkPrimitiveParamsFast(int linknum, LSL_List rules); 365 void llSetLinkPrimitiveParamsFast(int linknum, LSL_List rules);
363 void llSetPrimURL(string url); 366 void llSetPrimURL(string url);
364 LSL_Integer llSetRegionPos(LSL_Vector pos);
365 void llSetRemoteScriptAccessPin(int pin); 367 void llSetRemoteScriptAccessPin(int pin);
366 void llSetRot(LSL_Rotation rot); 368 void llSetRot(LSL_Rotation rot);
367 void llSetScale(LSL_Vector scale); 369 void llSetScale(LSL_Vector scale);
@@ -381,6 +383,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
381 void llSetVehicleRotationParam(int param, LSL_Rotation rot); 383 void llSetVehicleRotationParam(int param, LSL_Rotation rot);
382 void llSetVehicleType(int type); 384 void llSetVehicleType(int type);
383 void llSetVehicleVectorParam(int param, LSL_Vector vec); 385 void llSetVehicleVectorParam(int param, LSL_Vector vec);
386 void llSetVelocity(LSL_Vector velocity, int local);
384 void llShout(int channelID, string text); 387 void llShout(int channelID, string text);
385 LSL_Float llSin(double f); 388 LSL_Float llSin(double f);
386 void llSitTarget(LSL_Vector offset, LSL_Rotation rot); 389 void llSitTarget(LSL_Vector offset, LSL_Rotation rot);
@@ -424,10 +427,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
424 LSL_Vector llWind(LSL_Vector offset); 427 LSL_Vector llWind(LSL_Vector offset);
425 LSL_String llXorBase64Strings(string str1, string str2); 428 LSL_String llXorBase64Strings(string str1, string str2);
426 LSL_String llXorBase64StringsCorrect(string str1, string str2); 429 LSL_String llXorBase64StringsCorrect(string str1, string str2);
427 void print(string str); 430 LSL_Integer llGetLinkNumberOfSides(LSL_Integer link);
431 void llSetPhysicsMaterial(int material_bits, float material_gravity_modifier, float material_restitution, float material_friction, float material_density);
428 432
429 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc); 433 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc);
430 void llSetKeyframedMotion(LSL_List frames, LSL_List options); 434 void llSetKeyframedMotion(LSL_List frames, LSL_List options);
431 LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 435 LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
436 LSL_List llGetPhysicsMaterial();
437 void llSetContentType(LSL_Key id, LSL_Integer content_type);
432 } 438 }
433} 439}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 51d0581..a652cb8 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -144,7 +144,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
144 // Avatar Info Commands 144 // Avatar Info Commands
145 string osGetAgentIP(string agent); 145 string osGetAgentIP(string agent);
146 LSL_List osGetAgents(); 146 LSL_List osGetAgents();
147 147
148 // Teleport commands 148 // Teleport commands
149 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 149 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
150 void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 150 void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
@@ -260,7 +260,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
260 string osGetScriptEngineName(); 260 string osGetScriptEngineName();
261 string osGetSimulatorVersion(); 261 string osGetSimulatorVersion();
262 string osGetPhysicsEngineType(); 262 string osGetPhysicsEngineType();
263 Object osParseJSONNew(string JSON);
264 Hashtable osParseJSON(string JSON); 263 Hashtable osParseJSON(string JSON);
265 264
266 void osMessageObject(key objectUUID,string message); 265 void osMessageObject(key objectUUID,string message);
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 559068d..6efa73f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -56,7 +56,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
56 public const int ACTIVE = 2; 56 public const int ACTIVE = 2;
57 public const int PASSIVE = 4; 57 public const int PASSIVE = 4;
58 public const int SCRIPTED = 8; 58 public const int SCRIPTED = 8;
59 public const int OS_NPC = 0x01000000;
60 59
61 public const int CONTROL_FWD = 1; 60 public const int CONTROL_FWD = 1;
62 public const int CONTROL_BACK = 2; 61 public const int CONTROL_BACK = 2;
@@ -81,6 +80,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
81 public const int PERMISSION_CHANGE_PERMISSIONS = 512; 80 public const int PERMISSION_CHANGE_PERMISSIONS = 512;
82 public const int PERMISSION_TRACK_CAMERA = 1024; 81 public const int PERMISSION_TRACK_CAMERA = 1024;
83 public const int PERMISSION_CONTROL_CAMERA = 2048; 82 public const int PERMISSION_CONTROL_CAMERA = 2048;
83 public const int PERMISSION_TELEPORT = 4096;
84 84
85 public const int AGENT_FLYING = 1; 85 public const int AGENT_FLYING = 1;
86 public const int AGENT_ATTACHMENTS = 2; 86 public const int AGENT_ATTACHMENTS = 2;
@@ -95,6 +95,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
95 public const int AGENT_CROUCHING = 1024; 95 public const int AGENT_CROUCHING = 1024;
96 public const int AGENT_BUSY = 2048; 96 public const int AGENT_BUSY = 2048;
97 public const int AGENT_ALWAYS_RUN = 4096; 97 public const int AGENT_ALWAYS_RUN = 4096;
98 public const int AGENT_MALE = 8192;
98 99
99 //Particle Systems 100 //Particle Systems
100 public const int PSYS_PART_INTERP_COLOR_MASK = 1; 101 public const int PSYS_PART_INTERP_COLOR_MASK = 1;
@@ -337,6 +338,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
337 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART 338 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART
338 public const int CHANGED_MEDIA = 2048; 339 public const int CHANGED_MEDIA = 2048;
339 public const int CHANGED_ANIMATION = 16384; 340 public const int CHANGED_ANIMATION = 16384;
341 public const int CHANGED_POSITION = 32768;
340 public const int TYPE_INVALID = 0; 342 public const int TYPE_INVALID = 0;
341 public const int TYPE_INTEGER = 1; 343 public const int TYPE_INTEGER = 1;
342 public const int TYPE_FLOAT = 2; 344 public const int TYPE_FLOAT = 2;
@@ -674,7 +676,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
674 public const int FRICTION = 2; 676 public const int FRICTION = 2;
675 public const int RESTITUTION = 4; 677 public const int RESTITUTION = 4;
676 public const int GRAVITY_MULTIPLIER = 8; 678 public const int GRAVITY_MULTIPLIER = 8;
677 679
678 // extra constants for llSetPrimMediaParams 680 // extra constants for llSetPrimMediaParams
679 public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0); 681 public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0);
680 public static readonly LSLInteger LSL_STATUS_MALFORMED_PARAMS = new LSLInteger(1000); 682 public static readonly LSLInteger LSL_STATUS_MALFORMED_PARAMS = new LSLInteger(1000);
@@ -746,7 +748,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
746 748
747 public static readonly LSLInteger RCERR_UNKNOWN = -1; 749 public static readonly LSLInteger RCERR_UNKNOWN = -1;
748 public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2; 750 public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2;
749 public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3; 751 public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = -3;
750 752
751 public const int KFM_MODE = 1; 753 public const int KFM_MODE = 1;
752 public const int KFM_LOOP = 1; 754 public const int KFM_LOOP = 1;
@@ -770,5 +772,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
770 /// process message parameter as regex 772 /// process message parameter as regex
771 /// </summary> 773 /// </summary>
772 public const int OS_LISTEN_REGEX_MESSAGE = 0x2; 774 public const int OS_LISTEN_REGEX_MESSAGE = 0x2;
775
776 public const int CONTENT_TYPE_TEXT = 0;
777 public const int CONTENT_TYPE_HTML = 1;
773 } 778 }
774} 779}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 398c125..6f3677c 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();
@@ -474,6 +476,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
474 return m_LSL_Functions.llGetFreeMemory(); 476 return m_LSL_Functions.llGetFreeMemory();
475 } 477 }
476 478
479 public LSL_Integer llGetUsedMemory()
480 {
481 return m_LSL_Functions.llGetUsedMemory();
482 }
483
477 public LSL_Integer llGetFreeURLs() 484 public LSL_Integer llGetFreeURLs()
478 { 485 {
479 return m_LSL_Functions.llGetFreeURLs(); 486 return m_LSL_Functions.llGetFreeURLs();
@@ -554,11 +561,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
554 return m_LSL_Functions.llGetLinkNumberOfSides(link); 561 return m_LSL_Functions.llGetLinkNumberOfSides(link);
555 } 562 }
556 563
557 public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
558 {
559 m_LSL_Functions.llSetKeyframedMotion(frames, options);
560 }
561
562 public LSL_Integer llGetListEntryType(LSL_List src, int index) 564 public LSL_Integer llGetListEntryType(LSL_List src, int index)
563 { 565 {
564 return m_LSL_Functions.llGetListEntryType(src, index); 566 return m_LSL_Functions.llGetListEntryType(src, index);
@@ -584,6 +586,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
584 return m_LSL_Functions.llGetMass(); 586 return m_LSL_Functions.llGetMass();
585 } 587 }
586 588
589 public LSL_Float llGetMassMKS()
590 {
591 return m_LSL_Functions.llGetMassMKS();
592 }
593
587 public LSL_Integer llGetMemoryLimit() 594 public LSL_Integer llGetMemoryLimit()
588 { 595 {
589 return m_LSL_Functions.llGetMemoryLimit(); 596 return m_LSL_Functions.llGetMemoryLimit();
@@ -849,11 +856,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
849 return m_LSL_Functions.llGetUnixTime(); 856 return m_LSL_Functions.llGetUnixTime();
850 } 857 }
851 858
852 public LSL_Integer llGetUsedMemory()
853 {
854 return m_LSL_Functions.llGetUsedMemory();
855 }
856
857 public LSL_Vector llGetVel() 859 public LSL_Vector llGetVel()
858 { 860 {
859 return m_LSL_Functions.llGetVel(); 861 return m_LSL_Functions.llGetVel();
@@ -874,9 +876,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
874 m_LSL_Functions.llGiveInventoryList(destination, category, inventory); 876 m_LSL_Functions.llGiveInventoryList(destination, category, inventory);
875 } 877 }
876 878
877 public void llGiveMoney(string destination, int amount) 879 public LSL_Integer llGiveMoney(string destination, int amount)
878 { 880 {
879 m_LSL_Functions.llGiveMoney(destination, amount); 881 return m_LSL_Functions.llGiveMoney(destination, amount);
880 } 882 }
881 883
882 public LSL_String llTransferLindenDollars(string destination, int amount) 884 public LSL_String llTransferLindenDollars(string destination, int amount)
@@ -1493,6 +1495,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1493 m_LSL_Functions.llSetAlpha(alpha, face); 1495 m_LSL_Functions.llSetAlpha(alpha, face);
1494 } 1496 }
1495 1497
1498 public void llSetAngularVelocity(LSL_Vector angvelocity, int local)
1499 {
1500 m_LSL_Functions.llSetAngularVelocity(angvelocity, local);
1501 }
1502
1496 public void llSetBuoyancy(double buoyancy) 1503 public void llSetBuoyancy(double buoyancy)
1497 { 1504 {
1498 m_LSL_Functions.llSetBuoyancy(buoyancy); 1505 m_LSL_Functions.llSetBuoyancy(buoyancy);
@@ -1618,6 +1625,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1618 m_LSL_Functions.llSetPos(pos); 1625 m_LSL_Functions.llSetPos(pos);
1619 } 1626 }
1620 1627
1628 public LSL_Integer llSetRegionPos(LSL_Vector pos)
1629 {
1630 return m_LSL_Functions.llSetRegionPos(pos);
1631 }
1632
1621 public void llSetPrimitiveParams(LSL_List rules) 1633 public void llSetPrimitiveParams(LSL_List rules)
1622 { 1634 {
1623 m_LSL_Functions.llSetPrimitiveParams(rules); 1635 m_LSL_Functions.llSetPrimitiveParams(rules);
@@ -1633,11 +1645,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1633 m_LSL_Functions.llSetPrimURL(url); 1645 m_LSL_Functions.llSetPrimURL(url);
1634 } 1646 }
1635 1647
1636 public LSL_Integer llSetRegionPos(LSL_Vector pos)
1637 {
1638 return m_LSL_Functions.llSetRegionPos(pos);
1639 }
1640
1641 public void llSetRemoteScriptAccessPin(int pin) 1648 public void llSetRemoteScriptAccessPin(int pin)
1642 { 1649 {
1643 m_LSL_Functions.llSetRemoteScriptAccessPin(pin); 1650 m_LSL_Functions.llSetRemoteScriptAccessPin(pin);
@@ -1733,6 +1740,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1733 m_LSL_Functions.llSetVehicleVectorParam(param, vec); 1740 m_LSL_Functions.llSetVehicleVectorParam(param, vec);
1734 } 1741 }
1735 1742
1743 public void llSetVelocity(LSL_Vector velocity, int local)
1744 {
1745 m_LSL_Functions.llSetVelocity(velocity, local);
1746 }
1747
1736 public void llShout(int channelID, string text) 1748 public void llShout(int channelID, string text)
1737 { 1749 {
1738 m_LSL_Functions.llShout(channelID, text); 1750 m_LSL_Functions.llShout(channelID, text);
@@ -1983,9 +1995,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1983 return m_LSL_Functions.llClearLinkMedia(link, face); 1995 return m_LSL_Functions.llClearLinkMedia(link, face);
1984 } 1996 }
1985 1997
1986 public void print(string str) 1998 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
1999 {
2000 return m_LSL_Functions.llGetLinkNumberOfSides(link);
2001 }
2002
2003 public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
2004 {
2005 m_LSL_Functions.llSetKeyframedMotion(frames, options);
2006 }
2007
2008 public void llSetPhysicsMaterial(int material_bits, float material_gravity_modifier, float material_restitution, float material_friction, float material_density)
2009 {
2010 m_LSL_Functions.llSetPhysicsMaterial(material_bits, material_gravity_modifier, material_restitution, material_friction, material_density);
2011 }
2012
2013 public LSL_List llGetPhysicsMaterial()
2014 {
2015 return m_LSL_Functions.llGetPhysicsMaterial();
2016 }
2017
2018 public void llSetContentType(LSL_Key id, LSL_Integer content_type)
1987 { 2019 {
1988 m_LSL_Functions.print(str); 2020 m_LSL_Functions.llSetContentType(id, content_type);
1989 } 2021 }
1990 } 2022 }
1991} 2023}
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/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index c9902e4..b63773b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -435,11 +435,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
435 return m_OSSL_Functions.osParseJSON(JSON); 435 return m_OSSL_Functions.osParseJSON(JSON);
436 } 436 }
437 437
438 public Object osParseJSONNew(string JSON)
439 {
440 return m_OSSL_Functions.osParseJSONNew(JSON);
441 }
442
443 public void osMessageObject(key objectUUID,string message) 438 public void osMessageObject(key objectUUID,string message)
444 { 439 {
445 m_OSSL_Functions.osMessageObject(objectUUID,message); 440 m_OSSL_Functions.osMessageObject(objectUUID,message);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
index edbbc2a..b138da3 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
@@ -33,6 +33,7 @@ using System.Threading;
33using System.Reflection; 33using System.Reflection;
34using System.Collections; 34using System.Collections;
35using System.Collections.Generic; 35using System.Collections.Generic;
36using System.Diagnostics; //for [DebuggerNonUserCode]
36using OpenSim.Region.ScriptEngine.Interfaces; 37using OpenSim.Region.ScriptEngine.Interfaces;
37using OpenSim.Region.ScriptEngine.Shared; 38using OpenSim.Region.ScriptEngine.Shared;
38using OpenSim.Region.ScriptEngine.Shared.Api.Runtime; 39using OpenSim.Region.ScriptEngine.Shared.Api.Runtime;
@@ -90,6 +91,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
90 return (int)m_Executor.GetStateEventFlags(state); 91 return (int)m_Executor.GetStateEventFlags(state);
91 } 92 }
92 93
94 [DebuggerNonUserCode]
93 public void ExecuteEvent(string state, string FunctionName, object[] args) 95 public void ExecuteEvent(string state, string FunctionName, object[] args)
94 { 96 {
95 m_Executor.ExecuteEvent(state, FunctionName, args); 97 m_Executor.ExecuteEvent(state, FunctionName, args);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
index e02d35e..e44a106 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
@@ -35,6 +35,7 @@ using OpenMetaverse;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Region.CoreModules; 36using OpenSim.Region.CoreModules;
37using OpenSim.Region.Framework.Scenes; 37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces;
38using OpenSim.Region.Framework.Interfaces; 39using OpenSim.Region.Framework.Interfaces;
39 40
40namespace OpenSim.Region.ScriptEngine.Shared 41namespace OpenSim.Region.ScriptEngine.Shared
@@ -120,6 +121,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
120 Type = 0; 121 Type = 0;
121 Velocity = new LSL_Types.Vector3(); 122 Velocity = new LSL_Types.Vector3();
122 initializeSurfaceTouch(); 123 initializeSurfaceTouch();
124 Country = String.Empty;
123 } 125 }
124 126
125 public UUID Key; 127 public UUID Key;
@@ -151,6 +153,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
151 private int touchFace; 153 private int touchFace;
152 public int TouchFace { get { return touchFace; } } 154 public int TouchFace { get { return touchFace; } }
153 155
156 public string Country;
157
154 // This can be done in two places including the constructor 158 // This can be done in two places including the constructor
155 // so be carefull what gets added here 159 // so be carefull what gets added here
156 private void initializeSurfaceTouch() 160 private void initializeSurfaceTouch()
@@ -198,6 +202,10 @@ namespace OpenSim.Region.ScriptEngine.Shared
198 return; 202 return;
199 203
200 Name = presence.Firstname + " " + presence.Lastname; 204 Name = presence.Firstname + " " + presence.Lastname;
205 UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, Key);
206 if (account != null)
207 Country = account.UserCountry;
208
201 Owner = Key; 209 Owner = Key;
202 Position = new LSL_Types.Vector3(presence.AbsolutePosition); 210 Position = new LSL_Types.Vector3(presence.AbsolutePosition);
203 Rotation = new LSL_Types.Quaternion( 211 Rotation = new LSL_Types.Quaternion(
@@ -207,22 +215,27 @@ namespace OpenSim.Region.ScriptEngine.Shared
207 presence.Rotation.W); 215 presence.Rotation.W);
208 Velocity = new LSL_Types.Vector3(presence.Velocity); 216 Velocity = new LSL_Types.Vector3(presence.Velocity);
209 217
210 if (presence.PresenceType != PresenceType.Npc) 218 Type = 0x01; // Avatar
211 { 219 if (presence.PresenceType == PresenceType.Npc)
212 Type = AGENT; 220 Type = 0x20;
213 } 221
214 else 222 // Cope Impl. We don't use OS_NPC.
215 { 223 //if (presence.PresenceType != PresenceType.Npc)
216 Type = OS_NPC; 224 //{
217 225 // Type = AGENT;
218 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); 226 //}
219 INPC npcData = npcModule.GetNPC(presence.UUID, presence.Scene); 227 //else
220 228 //{
221 if (npcData.SenseAsAgent) 229 // Type = OS_NPC;
222 { 230
223 Type |= AGENT; 231 // INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
224 } 232 // INPC npcData = npcModule.GetNPC(presence.UUID, presence.Scene);
225 } 233
234 // if (npcData.SenseAsAgent)
235 // {
236 // Type |= AGENT;
237 // }
238 //}
226 239
227 if (presence.Velocity != Vector3.Zero) 240 if (presence.Velocity != Vector3.Zero)
228 Type |= ACTIVE; 241 Type |= ACTIVE;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 887a317..8da06d1 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -30,6 +30,7 @@ using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Globalization; 31using System.Globalization;
32using System.IO; 32using System.IO;
33using System.Diagnostics; //for [DebuggerNonUserCode]
33using System.Reflection; 34using System.Reflection;
34using System.Runtime.Remoting; 35using System.Runtime.Remoting;
35using System.Runtime.Remoting.Lifetime; 36using System.Runtime.Remoting.Lifetime;
@@ -165,13 +166,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
165 166
166 public UUID ItemID { get; private set; } 167 public UUID ItemID { get; private set; }
167 168
168 public UUID ObjectID { get { return Part.UUID; } } 169 public UUID ObjectID { get; private set; }
169 170
170 public uint LocalID { get { return Part.LocalId; } } 171 public uint LocalID { get; private set; }
171 172
172 public UUID RootObjectID { get { return Part.ParentGroup.UUID; } } 173 public UUID RootObjectID { get; private set; }
173 174
174 public uint RootLocalID { get { return Part.ParentGroup.LocalId; } } 175 public uint RootLocalID { get; private set; }
175 176
176 public UUID AssetID { get; private set; } 177 public UUID AssetID { get; private set; }
177 178
@@ -235,8 +236,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
235 StartParam = startParam; 236 StartParam = startParam;
236 m_MaxScriptQueue = maxScriptQueue; 237 m_MaxScriptQueue = maxScriptQueue;
237 m_postOnRez = postOnRez; 238 m_postOnRez = postOnRez;
238 m_AttachedAvatar = Part.ParentGroup.AttachedAvatar; 239 m_AttachedAvatar = part.ParentGroup.AttachedAvatar;
239 m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID; 240 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
240 241
241 if (Engine.Config.GetString("ScriptStopStrategy", "abort") == "co-op") 242 if (Engine.Config.GetString("ScriptStopStrategy", "abort") == "co-op")
242 { 243 {
@@ -481,27 +482,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
481 PostEvent(new EventParams("attach", 482 PostEvent(new EventParams("attach",
482 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0])); 483 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0]));
483 } 484 }
485
484 } 486 }
485 } 487 }
486 488
487 private void ReleaseControls() 489 private void ReleaseControls()
488 { 490 {
489 int permsMask; 491 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
490 UUID permsGranter; 492
491 lock (Part.TaskInventory) 493 if (part != null)
492 { 494 {
493 if (!Part.TaskInventory.ContainsKey(ItemID)) 495 int permsMask;
496 UUID permsGranter;
497 part.TaskInventory.LockItemsForRead(true);
498 if (!part.TaskInventory.ContainsKey(ItemID))
499 {
500 part.TaskInventory.LockItemsForRead(false);
494 return; 501 return;
502 }
503 permsGranter = part.TaskInventory[ItemID].PermsGranter;
504 permsMask = part.TaskInventory[ItemID].PermsMask;
505 part.TaskInventory.LockItemsForRead(false);
495 506
496 permsGranter = Part.TaskInventory[ItemID].PermsGranter; 507 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
497 permsMask = Part.TaskInventory[ItemID].PermsMask; 508 {
498 } 509 ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
499 510 if (presence != null)
500 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 511 presence.UnRegisterControlEventsToScript(LocalID, ItemID);
501 { 512 }
502 ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
503 if (presence != null)
504 presence.UnRegisterControlEventsToScript(LocalID, ItemID);
505 } 513 }
506 } 514 }
507 515
@@ -656,6 +664,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
656 return true; 664 return true;
657 } 665 }
658 666
667 [DebuggerNonUserCode] //Prevents the debugger from farting in this function
659 public void SetState(string state) 668 public void SetState(string state)
660 { 669 {
661 if (state == State) 670 if (state == State)
@@ -667,7 +676,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
667 new DetectParams[0])); 676 new DetectParams[0]));
668 PostEvent(new EventParams("state_entry", new Object[0], 677 PostEvent(new EventParams("state_entry", new Object[0],
669 new DetectParams[0])); 678 new DetectParams[0]));
670 679
671 throw new EventAbortException(); 680 throw new EventAbortException();
672 } 681 }
673 682
@@ -757,57 +766,60 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
757 /// <returns></returns> 766 /// <returns></returns>
758 public object EventProcessor() 767 public object EventProcessor()
759 { 768 {
769 EventParams data = null;
760 // We check here as the thread stopping this instance from running may itself hold the m_Script lock. 770 // We check here as the thread stopping this instance from running may itself hold the m_Script lock.
761 if (!Running) 771 if (!Running)
762 return 0; 772 return 0;
763 773
764 lock (m_Script)
765 {
766// m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); 774// m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName);
767 775
768 if (Suspended) 776 if (Suspended)
769 return 0; 777 return 0;
770
771 EventParams data = null;
772 778
773 lock (EventQueue) 779 lock (EventQueue)
780 {
781 data = (EventParams) EventQueue.Dequeue();
782 if (data == null) // Shouldn't happen
774 { 783 {
775 data = (EventParams)EventQueue.Dequeue(); 784 if (EventQueue.Count > 0 && Running && !ShuttingDown)
776 if (data == null) // Shouldn't happen
777 { 785 {
778 if (EventQueue.Count > 0 && Running && !ShuttingDown) 786 m_CurrentWorkItem = Engine.QueueEventHandler(this);
779 {
780 m_CurrentWorkItem = Engine.QueueEventHandler(this);
781 }
782 else
783 {
784 m_CurrentWorkItem = null;
785 }
786 return 0;
787 } 787 }
788 788 else
789 if (data.EventName == "timer")
790 m_TimerQueued = false;
791 if (data.EventName == "control")
792 { 789 {
793 if (m_ControlEventsInQueue > 0) 790 m_CurrentWorkItem = null;
794 m_ControlEventsInQueue--;
795 } 791 }
796 if (data.EventName == "collision") 792 return 0;
797 m_CollisionInQueue = false;
798 } 793 }
799 794
795 if (data.EventName == "timer")
796 m_TimerQueued = false;
797 if (data.EventName == "control")
798 {
799 if (m_ControlEventsInQueue > 0)
800 m_ControlEventsInQueue--;
801 }
802 if (data.EventName == "collision")
803 m_CollisionInQueue = false;
804 }
805
806 lock(m_Script)
807 {
808
809// m_log.DebugFormat("[XEngine]: Processing event {0} for {1}", data.EventName, this);
810 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
811
800 if (DebugLevel >= 2) 812 if (DebugLevel >= 2)
801 m_log.DebugFormat( 813 m_log.DebugFormat(
802 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", 814 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
803 data.EventName, 815 data.EventName,
804 ScriptName, 816 ScriptName,
805 Part.Name, 817 part.Name,
806 Part.LocalId, 818 part.LocalId,
807 Part.ParentGroup.Name, 819 part.ParentGroup.Name,
808 Part.ParentGroup.UUID, 820 part.ParentGroup.UUID,
809 Part.AbsolutePosition, 821 part.AbsolutePosition,
810 Part.ParentGroup.Scene.Name); 822 part.ParentGroup.Scene.Name);
811 823
812 m_DetectParams = data.DetectParams; 824 m_DetectParams = data.DetectParams;
813 825
@@ -820,17 +832,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
820 "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", 832 "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
821 State, 833 State,
822 ScriptName, 834 ScriptName,
823 Part.Name, 835 part.Name,
824 Part.LocalId, 836 part.LocalId,
825 Part.ParentGroup.Name, 837 part.ParentGroup.Name,
826 Part.ParentGroup.UUID, 838 part.ParentGroup.UUID,
827 Part.AbsolutePosition, 839 part.AbsolutePosition,
828 Part.ParentGroup.Scene.Name); 840 part.ParentGroup.Scene.Name);
829 841
830 AsyncCommandManager.RemoveScript(Engine, 842 AsyncCommandManager.RemoveScript(Engine,
831 LocalID, ItemID); 843 LocalID, ItemID);
832 844
833 Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); 845 if (part != null)
846 {
847 part.SetScriptEvents(ItemID,
848 (int)m_Script.GetStateEventFlags(State));
849 }
834 } 850 }
835 else 851 else
836 { 852 {
@@ -893,17 +909,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
893 text = text.Substring(0, 1000); 909 text = text.Substring(0, 1000);
894 Engine.World.SimChat(Utils.StringToBytes(text), 910 Engine.World.SimChat(Utils.StringToBytes(text),
895 ChatTypeEnum.DebugChannel, 2147483647, 911 ChatTypeEnum.DebugChannel, 2147483647,
896 Part.AbsolutePosition, 912 part.AbsolutePosition,
897 Part.Name, Part.UUID, false); 913 part.Name, part.UUID, false);
898 914
899 915
900 m_log.DebugFormat( 916 m_log.DebugFormat(
901 "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}", 917 "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}",
902 ScriptName, 918 ScriptName,
903 PrimName, 919 PrimName,
904 Part.UUID, 920 part.UUID,
905 Part.AbsolutePosition, 921 part.AbsolutePosition,
906 Part.ParentGroup.Scene.Name, 922 part.ParentGroup.Scene.Name,
907 text.Replace("\n", "\\n"), 923 text.Replace("\n", "\\n"),
908 e.InnerException); 924 e.InnerException);
909 } 925 }
@@ -923,12 +939,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
923 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException)) 939 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
924 { 940 {
925 m_InSelfDelete = true; 941 m_InSelfDelete = true;
926 Engine.World.DeleteSceneObject(Part.ParentGroup, false); 942 if (part != null)
943 Engine.World.DeleteSceneObject(part.ParentGroup, false);
927 } 944 }
928 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) 945 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException))
929 { 946 {
930 m_InSelfDelete = true; 947 m_InSelfDelete = true;
931 Part.Inventory.RemoveInventoryItem(ItemID); 948 if (part != null)
949 part.Inventory.RemoveInventoryItem(ItemID);
932 } 950 }
933 else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException)) 951 else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException))
934 { 952 {
@@ -982,14 +1000,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
982 ReleaseControls(); 1000 ReleaseControls();
983 1001
984 Stop(timeout); 1002 Stop(timeout);
985 Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; 1003 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
986 Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; 1004 part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
1005 part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
1006 part.CollisionSound = UUID.Zero;
987 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); 1007 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
988 EventQueue.Clear(); 1008 EventQueue.Clear();
989 m_Script.ResetVars(); 1009 m_Script.ResetVars();
990 State = "default"; 1010 State = "default";
991 1011
992 Part.SetScriptEvents(ItemID, 1012 part.SetScriptEvents(ItemID,
993 (int)m_Script.GetStateEventFlags(State)); 1013 (int)m_Script.GetStateEventFlags(State));
994 if (running) 1014 if (running)
995 Start(); 1015 Start();
@@ -998,6 +1018,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
998 new Object[0], new DetectParams[0])); 1018 new Object[0], new DetectParams[0]));
999 } 1019 }
1000 1020
1021 [DebuggerNonUserCode] //Stops the VS debugger from farting in this function
1001 public void ApiResetScript() 1022 public void ApiResetScript()
1002 { 1023 {
1003 // bool running = Running; 1024 // bool running = Running;
@@ -1006,15 +1027,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
1006 ReleaseControls(); 1027 ReleaseControls();
1007 1028
1008 m_Script.ResetVars(); 1029 m_Script.ResetVars();
1009 Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; 1030 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
1010 Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; 1031 part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
1032 part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
1033 part.CollisionSound = UUID.Zero;
1011 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); 1034 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
1012 1035
1013 EventQueue.Clear(); 1036 EventQueue.Clear();
1014 m_Script.ResetVars(); 1037 m_Script.ResetVars();
1015 State = "default"; 1038 State = "default";
1016 1039
1017 Part.SetScriptEvents(ItemID, 1040 part.SetScriptEvents(ItemID,
1018 (int)m_Script.GetStateEventFlags(State)); 1041 (int)m_Script.GetStateEventFlags(State));
1019 1042
1020 if (m_CurrentEvent != "state_entry") 1043 if (m_CurrentEvent != "state_entry")
@@ -1028,10 +1051,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
1028 1051
1029 public Dictionary<string, object> GetVars() 1052 public Dictionary<string, object> GetVars()
1030 { 1053 {
1031 if (m_Script != null) 1054 return m_Script.GetVars();
1032 return m_Script.GetVars();
1033 else
1034 return new Dictionary<string, object>();
1035 } 1055 }
1036 1056
1037 public void SetVars(Dictionary<string, object> vars) 1057 public void SetVars(Dictionary<string, object> vars)
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 50f9377..4ba0e64 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -102,19 +102,19 @@ namespace OpenSim.Region.ScriptEngine.Shared
102 102
103 public override string ToString() 103 public override string ToString()
104 { 104 {
105 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z); 105 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}>", x, y, z);
106 return s; 106 return s;
107 } 107 }
108 108
109 public static explicit operator LSLString(Vector3 vec) 109 public static explicit operator LSLString(Vector3 vec)
110 { 110 {
111 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); 111 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}>", vec.x, vec.y, vec.z);
112 return new LSLString(s); 112 return new LSLString(s);
113 } 113 }
114 114
115 public static explicit operator string(Vector3 vec) 115 public static explicit operator string(Vector3 vec)
116 { 116 {
117 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); 117 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}>", vec.x, vec.y, vec.z);
118 return s; 118 return s;
119 } 119 }
120 120
@@ -414,19 +414,19 @@ namespace OpenSim.Region.ScriptEngine.Shared
414 414
415 public override string ToString() 415 public override string ToString()
416 { 416 {
417 string st=String.Format(Culture.FormatProvider, "<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s); 417 string st=String.Format(Culture.FormatProvider, "<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", x, y, z, s);
418 return st; 418 return st;
419 } 419 }
420 420
421 public static explicit operator string(Quaternion r) 421 public static explicit operator string(Quaternion r)
422 { 422 {
423 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); 423 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", r.x, r.y, r.z, r.s);
424 return s; 424 return s;
425 } 425 }
426 426
427 public static explicit operator LSLString(Quaternion r) 427 public static explicit operator LSLString(Quaternion r)
428 { 428 {
429 string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); 429 string s=String.Format("<{0:0.000000}, {1:0.000000}, {2:0.000000}, {3:0.000000}>", r.x, r.y, r.z, r.s);
430 return new LSLString(s); 430 return new LSLString(s);
431 } 431 }
432 432
@@ -537,7 +537,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
537 else if (o is LSL_Types.LSLFloat) 537 else if (o is LSL_Types.LSLFloat)
538 size += 8; 538 size += 8;
539 else if (o is LSL_Types.LSLString) 539 else if (o is LSL_Types.LSLString)
540 size += ((LSL_Types.LSLString)o).m_string.Length; 540 size += ((LSL_Types.LSLString)o).m_string == null ? 0 : ((LSL_Types.LSLString)o).m_string.Length;
541 else if (o is LSL_Types.key) 541 else if (o is LSL_Types.key)
542 size += ((LSL_Types.key)o).value.Length; 542 size += ((LSL_Types.key)o).value.Length;
543 else if (o is LSL_Types.Vector3) 543 else if (o is LSL_Types.Vector3)
@@ -546,6 +546,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
546 size += 64; 546 size += 64;
547 else if (o is int) 547 else if (o is int)
548 size += 4; 548 size += 4;
549 else if (o is uint)
550 size += 4;
549 else if (o is string) 551 else if (o is string)
550 size += ((string)o).Length; 552 size += ((string)o).Length;
551 else if (o is float) 553 else if (o is float)
@@ -736,24 +738,16 @@ namespace OpenSim.Region.ScriptEngine.Shared
736 738
737 public static bool operator ==(list a, list b) 739 public static bool operator ==(list a, list b)
738 { 740 {
739 int la = -1; 741 int la = a.Length;
740 int lb = -1; 742 int lb = b.Length;
741 try { la = a.Length; }
742 catch (NullReferenceException) { }
743 try { lb = b.Length; }
744 catch (NullReferenceException) { }
745 743
746 return la == lb; 744 return la == lb;
747 } 745 }
748 746
749 public static bool operator !=(list a, list b) 747 public static bool operator !=(list a, list b)
750 { 748 {
751 int la = -1; 749 int la = a.Length;
752 int lb = -1; 750 int lb = b.Length;
753 try { la = a.Length; }
754 catch (NullReferenceException) { }
755 try {lb = b.Length;}
756 catch (NullReferenceException) { }
757 751
758 return la != lb; 752 return la != lb;
759 } 753 }
@@ -987,7 +981,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
987 ret = Math.Sign(Quaternion.Mag(l) - Quaternion.Mag(r)); 981 ret = Math.Sign(Quaternion.Mag(l) - Quaternion.Mag(r));
988 } 982 }
989 983
990 if (ascending == 0) 984 if (ascending != 1)
991 { 985 {
992 ret = 0 - ret; 986 ret = 0 - ret;
993 } 987 }
@@ -1020,6 +1014,9 @@ namespace OpenSim.Region.ScriptEngine.Shared
1020 stride = 1; 1014 stride = 1;
1021 } 1015 }
1022 1016
1017 if ((Data.Length % stride) != 0)
1018 return new list(ret);
1019
1023 // we can optimize here in the case where stride == 1 and the list 1020 // we can optimize here in the case where stride == 1 and the list
1024 // consists of homogeneous types 1021 // consists of homogeneous types
1025 1022
@@ -1039,7 +1036,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
1039 if (homogeneous) 1036 if (homogeneous)
1040 { 1037 {
1041 Array.Sort(ret, new HomogeneousComparer()); 1038 Array.Sort(ret, new HomogeneousComparer());
1042 if (ascending == 0) 1039 if (ascending != 1)
1043 { 1040 {
1044 Array.Reverse(ret); 1041 Array.Reverse(ret);
1045 } 1042 }
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 5804aa8..9d1e143 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Diagnostics; //for [DebuggerNonUserCode]
31using System.Globalization; 32using System.Globalization;
32using System.IO; 33using System.IO;
33using System.Linq; 34using System.Linq;
@@ -148,6 +149,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
148 private Dictionary<UUID, IScriptInstance> m_Scripts = 149 private Dictionary<UUID, IScriptInstance> m_Scripts =
149 new Dictionary<UUID, IScriptInstance>(); 150 new Dictionary<UUID, IScriptInstance>();
150 151
152 private OpenMetaverse.ReaderWriterLockSlim m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
153
151 // Maps the asset ID to the assembly 154 // Maps the asset ID to the assembly
152 155
153 private Dictionary<UUID, string> m_Assemblies = 156 private Dictionary<UUID, string> m_Assemblies =
@@ -170,6 +173,71 @@ namespace OpenSim.Region.ScriptEngine.XEngine
170 IWorkItemResult m_CurrentCompile = null; 173 IWorkItemResult m_CurrentCompile = null;
171 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>(); 174 private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>();
172 175
176 private void lockScriptsForRead(bool locked)
177 {
178 if (locked)
179 {
180 if (m_scriptsLock.RecursiveReadCount > 0)
181 {
182 m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
183 m_scriptsLock.ExitReadLock();
184 }
185 if (m_scriptsLock.RecursiveWriteCount > 0)
186 {
187 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
188 m_scriptsLock.ExitWriteLock();
189 }
190
191 while (!m_scriptsLock.TryEnterReadLock(60000))
192 {
193 m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire READ lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
194 if (m_scriptsLock.IsWriteLockHeld)
195 {
196 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
197 }
198 }
199 }
200 else
201 {
202 if (m_scriptsLock.RecursiveReadCount > 0)
203 {
204 m_scriptsLock.ExitReadLock();
205 }
206 }
207 }
208 private void lockScriptsForWrite(bool locked)
209 {
210 if (locked)
211 {
212 if (m_scriptsLock.RecursiveReadCount > 0)
213 {
214 m_log.Error("[XEngine.m_Scripts] Recursive read lock requested. This should not happen and means something needs to be fixed. For now though, it's safe to continue.");
215 m_scriptsLock.ExitReadLock();
216 }
217 if (m_scriptsLock.RecursiveWriteCount > 0)
218 {
219 m_log.Error("[XEngine.m_Scripts] Recursive write lock requested. This should not happen and means something needs to be fixed.");
220 m_scriptsLock.ExitWriteLock();
221 }
222
223 while (!m_scriptsLock.TryEnterWriteLock(60000))
224 {
225 m_log.Error("[XEngine.m_Scripts] Thread lock detected while trying to aquire WRITE lock of m_scripts in XEngine. I'm going to try to solve the thread lock automatically to preserve region stability, but this needs to be fixed.");
226 if (m_scriptsLock.IsWriteLockHeld)
227 {
228 m_scriptsLock = new OpenMetaverse.ReaderWriterLockSlim();
229 }
230 }
231 }
232 else
233 {
234 if (m_scriptsLock.RecursiveWriteCount > 0)
235 {
236 m_scriptsLock.ExitWriteLock();
237 }
238 }
239 }
240
173 private ScriptEngineConsoleCommands m_consoleCommands; 241 private ScriptEngineConsoleCommands m_consoleCommands;
174 242
175 public string ScriptEngineName 243 public string ScriptEngineName
@@ -699,64 +767,69 @@ namespace OpenSim.Region.ScriptEngine.XEngine
699 { 767 {
700 if (!m_Enabled) 768 if (!m_Enabled)
701 return; 769 return;
770 lockScriptsForRead(true);
702 771
703 lock (m_Scripts) 772 List<IScriptInstance> instancesToDel = new List<IScriptInstance>(m_Scripts.Values);
704 {
705 m_log.InfoFormat(
706 "[XEngine]: Shutting down {0} scripts in {1}", m_Scripts.Count, m_Scene.RegionInfo.RegionName);
707 773
708 foreach (IScriptInstance instance in m_Scripts.Values) 774// foreach (IScriptInstance instance in m_Scripts.Values)
775 foreach (IScriptInstance instance in instancesToDel)
776 {
777 // Force a final state save
778 //
779 if (m_Assemblies.ContainsKey(instance.AssetID))
709 { 780 {
710 // Force a final state save 781 string assembly = m_Assemblies[instance.AssetID];
711 //
712 if (m_Assemblies.ContainsKey(instance.AssetID))
713 {
714 string assembly = m_Assemblies[instance.AssetID];
715 782
716 try 783 try
717 { 784 {
718 instance.SaveState(assembly); 785 instance.SaveState(assembly);
719 }
720 catch (Exception e)
721 {
722 m_log.Error(
723 string.Format(
724 "[XEngine]: Failed final state save for script {0}.{1}, item UUID {2}, prim UUID {3} in {4}. Exception ",
725 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name)
726 , e);
727 }
728 } 786 }
787 catch (Exception e)
788 {
789 m_log.Error(
790 string.Format(
791 "[XEngine]: Failed final state save for script {0}.{1}, item UUID {2}, prim UUID {3} in {4}. Exception ",
792 instance.PrimName, instance.ScriptName, instance.ItemID, instance.ObjectID, World.Name)
793 , e);
794 }
795 }
729 796
730 // Clear the event queue and abort the instance thread 797 // Clear the event queue and abort the instance thread
731 // 798 //
732 instance.ClearQueue(); 799 instance.ClearQueue();
733 instance.Stop(0); 800 instance.Stop(0);
734 801
735 // Release events, timer, etc 802 // Release events, timer, etc
736 // 803 //
737 instance.DestroyScriptInstance(); 804 instance.DestroyScriptInstance();
738 805
739 // Unload scripts and app domains. 806 // Unload scripts and app domains
740 // Must be done explicitly because they have infinite 807 // Must be done explicitly because they have infinite
741 // lifetime. 808 // lifetime
742 // However, don't bother to do this if the simulator is shutting 809 //
743 // down since it takes a long time with many scripts. 810// if (!m_SimulatorShuttingDown)
744 if (!m_SimulatorShuttingDown) 811 {
812 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
813 if (m_DomainScripts[instance.AppDomain].Count == 0)
745 { 814 {
746 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 815 m_DomainScripts.Remove(instance.AppDomain);
747 if (m_DomainScripts[instance.AppDomain].Count == 0) 816 UnloadAppDomain(instance.AppDomain);
748 {
749 m_DomainScripts.Remove(instance.AppDomain);
750 UnloadAppDomain(instance.AppDomain);
751 }
752 } 817 }
753 } 818 }
754 819
755 m_Scripts.Clear(); 820// m_Scripts.Clear();
756 m_PrimObjects.Clear(); 821// m_PrimObjects.Clear();
757 m_Assemblies.Clear(); 822// m_Assemblies.Clear();
758 m_DomainScripts.Clear(); 823// m_DomainScripts.Clear();
759 } 824 }
825 lockScriptsForRead(false);
826 lockScriptsForWrite(true);
827 m_Scripts.Clear();
828 lockScriptsForWrite(false);
829 m_PrimObjects.Clear();
830 m_Assemblies.Clear();
831 m_DomainScripts.Clear();
832
760 lock (m_ScriptEngines) 833 lock (m_ScriptEngines)
761 { 834 {
762 m_ScriptEngines.Remove(this); 835 m_ScriptEngines.Remove(this);
@@ -825,22 +898,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine
825 898
826 List<IScriptInstance> instances = new List<IScriptInstance>(); 899 List<IScriptInstance> instances = new List<IScriptInstance>();
827 900
828 lock (m_Scripts) 901 lockScriptsForRead(true);
829 { 902 foreach (IScriptInstance instance in m_Scripts.Values)
830 foreach (IScriptInstance instance in m_Scripts.Values)
831 instances.Add(instance); 903 instances.Add(instance);
832 } 904 lockScriptsForRead(false);
833 905
834 foreach (IScriptInstance i in instances) 906 foreach (IScriptInstance i in instances)
835 { 907 {
836 string assembly = String.Empty; 908 string assembly = String.Empty;
837 909
838 lock (m_Scripts) 910
839 {
840 if (!m_Assemblies.ContainsKey(i.AssetID)) 911 if (!m_Assemblies.ContainsKey(i.AssetID))
841 continue; 912 continue;
842 assembly = m_Assemblies[i.AssetID]; 913 assembly = m_Assemblies[i.AssetID];
843 } 914
844 915
845 try 916 try
846 { 917 {
@@ -1244,97 +1315,93 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1244 } 1315 }
1245 1316
1246 ScriptInstance instance = null; 1317 ScriptInstance instance = null;
1247 lock (m_Scripts) 1318 // Create the object record
1319 lockScriptsForRead(true);
1320 if ((!m_Scripts.ContainsKey(itemID)) ||
1321 (m_Scripts[itemID].AssetID != assetID))
1248 { 1322 {
1249 // Create the object record 1323 lockScriptsForRead(false);
1250 if ((!m_Scripts.ContainsKey(itemID)) ||
1251 (m_Scripts[itemID].AssetID != assetID))
1252 {
1253 UUID appDomain = assetID;
1254 1324
1255 if (part.ParentGroup.IsAttachment) 1325 UUID appDomain = assetID;
1256 appDomain = part.ParentGroup.RootPart.UUID;
1257 1326
1258 if (!m_AppDomains.ContainsKey(appDomain)) 1327 if (part.ParentGroup.IsAttachment)
1259 { 1328 appDomain = part.ParentGroup.RootPart.UUID;
1260 try
1261 {
1262 AppDomainSetup appSetup = new AppDomainSetup();
1263 appSetup.PrivateBinPath = Path.Combine(
1264 m_ScriptEnginesPath,
1265 m_Scene.RegionInfo.RegionID.ToString());
1266 1329
1267 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; 1330 if (!m_AppDomains.ContainsKey(appDomain))
1268 Evidence evidence = new Evidence(baseEvidence); 1331 {
1332 try
1333 {
1334 AppDomainSetup appSetup = new AppDomainSetup();
1335 appSetup.PrivateBinPath = Path.Combine(
1336 m_ScriptEnginesPath,
1337 m_Scene.RegionInfo.RegionID.ToString());
1269 1338
1270 AppDomain sandbox; 1339 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
1271 if (m_AppDomainLoading) 1340 Evidence evidence = new Evidence(baseEvidence);
1272 {
1273 sandbox = AppDomain.CreateDomain(
1274 m_Scene.RegionInfo.RegionID.ToString(),
1275 evidence, appSetup);
1276 sandbox.AssemblyResolve +=
1277 new ResolveEventHandler(
1278 AssemblyResolver.OnAssemblyResolve);
1279 }
1280 else
1281 {
1282 sandbox = AppDomain.CurrentDomain;
1283 }
1284
1285 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
1286 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
1287 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet");
1288 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet);
1289 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement);
1290 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup;
1291 //sandbox.SetAppDomainPolicy(sandboxPolicy);
1292
1293 m_AppDomains[appDomain] = sandbox;
1294 1341
1295 m_DomainScripts[appDomain] = new List<UUID>(); 1342 AppDomain sandbox;
1343 if (m_AppDomainLoading)
1344 {
1345 sandbox = AppDomain.CreateDomain(
1346 m_Scene.RegionInfo.RegionID.ToString(),
1347 evidence, appSetup);
1348 m_AppDomains[appDomain].AssemblyResolve +=
1349 new ResolveEventHandler(
1350 AssemblyResolver.OnAssemblyResolve);
1296 } 1351 }
1297 catch (Exception e) 1352 else
1298 { 1353 {
1299 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString()); 1354 sandbox = AppDomain.CurrentDomain;
1300 m_ScriptErrorMessage += "Exception creating app domain:\n";
1301 m_ScriptFailCount++;
1302 lock (m_AddingAssemblies)
1303 {
1304 m_AddingAssemblies[assembly]--;
1305 }
1306 return false;
1307 } 1355 }
1308 }
1309 m_DomainScripts[appDomain].Add(itemID);
1310
1311 instance = new ScriptInstance(this, part,
1312 item,
1313 startParam, postOnRez,
1314 m_MaxScriptQueue);
1315 1356
1316 if (!instance.Load(m_AppDomains[appDomain], assembly, stateSource)) 1357 if (!instance.Load(m_AppDomains[appDomain], assembly, stateSource))
1317 return false; 1358 return false;
1318 1359
1319// if (DebugLevel >= 1) 1360 m_AppDomains[appDomain] = sandbox;
1320// m_log.DebugFormat(
1321// "[XEngine] Loaded script {0}.{1}, item UUID {2}, prim UUID {3} @ {4}.{5}",
1322// part.ParentGroup.RootPart.Name, item.Name, itemID, part.UUID,
1323// part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName);
1324 1361
1325 if (presence != null) 1362 m_DomainScripts[appDomain] = new List<UUID>();
1363 }
1364 catch (Exception e)
1326 { 1365 {
1327 ShowScriptSaveResponse(item.OwnerID, 1366 m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString());
1328 assetID, "Compile successful", true); 1367 m_ScriptErrorMessage += "Exception creating app domain:\n";
1368 m_ScriptFailCount++;
1369 lock (m_AddingAssemblies)
1370 {
1371 m_AddingAssemblies[assembly]--;
1372 }
1373 return false;
1329 } 1374 }
1375 }
1376 m_DomainScripts[appDomain].Add(itemID);
1377
1378 instance = new ScriptInstance(this, part,
1379 item,
1380 startParam, postOnRez,
1381 m_MaxScriptQueue);
1330 1382
1331 instance.AppDomain = appDomain; 1383 instance.Load(m_AppDomains[appDomain], assembly, stateSource);
1332 instance.LineMap = linemap; 1384// m_log.DebugFormat(
1385// "[XEngine] Loaded script {0}.{1}, script UUID {2}, prim UUID {3} @ {4}.{5}",
1386// part.ParentGroup.RootPart.Name, item.Name, assetID, part.UUID,
1387// part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.RegionInfo.RegionName);
1333 1388
1334 m_Scripts[itemID] = instance; 1389 if (presence != null)
1390 {
1391 ShowScriptSaveResponse(item.OwnerID,
1392 assetID, "Compile successful", true);
1335 } 1393 }
1336 }
1337 1394
1395 instance.AppDomain = appDomain;
1396 instance.LineMap = linemap;
1397 lockScriptsForWrite(true);
1398 m_Scripts[itemID] = instance;
1399 lockScriptsForWrite(false);
1400 }
1401 else
1402 {
1403 lockScriptsForRead(false);
1404 }
1338 lock (m_PrimObjects) 1405 lock (m_PrimObjects)
1339 { 1406 {
1340 if (!m_PrimObjects.ContainsKey(localID)) 1407 if (!m_PrimObjects.ContainsKey(localID))
@@ -1352,7 +1419,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1352 m_AddingAssemblies[assembly]--; 1419 m_AddingAssemblies[assembly]--;
1353 } 1420 }
1354 1421
1355 if (instance != null) 1422 if (instance!=null)
1356 instance.Init(); 1423 instance.Init();
1357 1424
1358 bool runIt; 1425 bool runIt;
@@ -1375,18 +1442,28 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1375 m_CompileDict.Remove(itemID); 1442 m_CompileDict.Remove(itemID);
1376 } 1443 }
1377 1444
1378 IScriptInstance instance = null; 1445 lockScriptsForRead(true);
1379 1446 // Do we even have it?
1380 lock (m_Scripts) 1447 if (!m_Scripts.ContainsKey(itemID))
1381 { 1448 {
1382 // Do we even have it? 1449 // Do we even have it?
1383 if (!m_Scripts.ContainsKey(itemID)) 1450 if (!m_Scripts.ContainsKey(itemID))
1384 return; 1451 return;
1385 1452
1386 instance = m_Scripts[itemID]; 1453 lockScriptsForRead(false);
1454 lockScriptsForWrite(true);
1387 m_Scripts.Remove(itemID); 1455 m_Scripts.Remove(itemID);
1456 lockScriptsForWrite(false);
1457
1458 return;
1388 } 1459 }
1460
1389 1461
1462 IScriptInstance instance=m_Scripts[itemID];
1463 lockScriptsForRead(false);
1464 lockScriptsForWrite(true);
1465 m_Scripts.Remove(itemID);
1466 lockScriptsForWrite(false);
1390 instance.ClearQueue(); 1467 instance.ClearQueue();
1391 1468
1392 instance.Stop(m_WaitForEventCompletionOnScriptStop); 1469 instance.Stop(m_WaitForEventCompletionOnScriptStop);
@@ -1423,8 +1500,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1423 1500
1424 ObjectRemoved handlerObjectRemoved = OnObjectRemoved; 1501 ObjectRemoved handlerObjectRemoved = OnObjectRemoved;
1425 if (handlerObjectRemoved != null) 1502 if (handlerObjectRemoved != null)
1426 handlerObjectRemoved(instance.ObjectID); 1503 {
1504 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID);
1505 handlerObjectRemoved(part.UUID);
1506 }
1427 1507
1508 CleanAssemblies();
1509
1428 ScriptRemoved handlerScriptRemoved = OnScriptRemoved; 1510 ScriptRemoved handlerScriptRemoved = OnScriptRemoved;
1429 if (handlerScriptRemoved != null) 1511 if (handlerScriptRemoved != null)
1430 handlerScriptRemoved(itemID); 1512 handlerScriptRemoved(itemID);
@@ -1685,12 +1767,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1685 private IScriptInstance GetInstance(UUID itemID) 1767 private IScriptInstance GetInstance(UUID itemID)
1686 { 1768 {
1687 IScriptInstance instance; 1769 IScriptInstance instance;
1688 lock (m_Scripts) 1770 lockScriptsForRead(true);
1771 if (!m_Scripts.ContainsKey(itemID))
1689 { 1772 {
1690 if (!m_Scripts.ContainsKey(itemID)) 1773 lockScriptsForRead(false);
1691 return null; 1774 return null;
1692 instance = m_Scripts[itemID];
1693 } 1775 }
1776 instance = m_Scripts[itemID];
1777 lockScriptsForRead(false);
1694 return instance; 1778 return instance;
1695 } 1779 }
1696 1780
@@ -1714,6 +1798,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1714 return false; 1798 return false;
1715 } 1799 }
1716 1800
1801 [DebuggerNonUserCode]
1717 public void ApiResetScript(UUID itemID) 1802 public void ApiResetScript(UUID itemID)
1718 { 1803 {
1719 IScriptInstance instance = GetInstance(itemID); 1804 IScriptInstance instance = GetInstance(itemID);
@@ -1775,6 +1860,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1775 return UUID.Zero; 1860 return UUID.Zero;
1776 } 1861 }
1777 1862
1863 [DebuggerNonUserCode]
1778 public void SetState(UUID itemID, string newState) 1864 public void SetState(UUID itemID, string newState)
1779 { 1865 {
1780 IScriptInstance instance = GetInstance(itemID); 1866 IScriptInstance instance = GetInstance(itemID);
@@ -1797,11 +1883,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1797 1883
1798 List<IScriptInstance> instances = new List<IScriptInstance>(); 1884 List<IScriptInstance> instances = new List<IScriptInstance>();
1799 1885
1800 lock (m_Scripts) 1886 lockScriptsForRead(true);
1801 { 1887 foreach (IScriptInstance instance in m_Scripts.Values)
1802 foreach (IScriptInstance instance in m_Scripts.Values)
1803 instances.Add(instance); 1888 instances.Add(instance);
1804 } 1889 lockScriptsForRead(false);
1805 1890
1806 foreach (IScriptInstance i in instances) 1891 foreach (IScriptInstance i in instances)
1807 { 1892 {