aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs20
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs116
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs3034
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs102
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs11
-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.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs71
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs26
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs51
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs21
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs2
15 files changed, 2664 insertions, 882 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
index 993d10f..3cbdde5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
@@ -301,6 +301,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
301 return null; 301 return null;
302 } 302 }
303 303
304 public static void StateChange(IScriptEngine engine, uint localID, UUID itemID)
305 {
306 // Remove a specific script
307
308 // Remove dataserver events
309 m_Dataserver[engine].RemoveEvents(localID, itemID);
310
311 IWorldComm comms = engine.World.RequestModuleInterface<IWorldComm>();
312 if (comms != null)
313 comms.DeleteListener(itemID);
314
315 IXMLRPC xmlrpc = engine.World.RequestModuleInterface<IXMLRPC>();
316 xmlrpc.DeleteChannels(itemID);
317 xmlrpc.CancelSRDRequests(itemID);
318
319 // Remove Sensors
320 m_SensorRepeat[engine].UnSetSenseRepeaterEvents(localID, itemID);
321
322 }
323
304 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID) 324 public static Object[] GetSerializationData(IScriptEngine engine, UUID itemID)
305 { 325 {
306 List<Object> data = new List<Object>(); 326 List<Object> data = new List<Object>();
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
new file mode 100644
index 0000000..b5fa6de
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/CM_Api.cs
@@ -0,0 +1,116 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using System.Collections;
31using System.Collections.Generic;
32using System.Runtime.Remoting.Lifetime;
33using OpenMetaverse;
34using Nini.Config;
35using OpenSim;
36using OpenSim.Framework;
37using OpenSim.Region.CoreModules.World.LightShare;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes;
40using OpenSim.Region.ScriptEngine.Shared;
41using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
42using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
43using OpenSim.Region.ScriptEngine.Interfaces;
44using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
45using OpenSim.Services.Interfaces;
46
47using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
48using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
49using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
50using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
51using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
52using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
53using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
54
55namespace OpenSim.Region.ScriptEngine.Shared.Api
56{
57 [Serializable]
58 public class CM_Api : MarshalByRefObject, ICM_Api, IScriptApi
59 {
60 internal IScriptEngine m_ScriptEngine;
61 internal SceneObjectPart m_host;
62 internal TaskInventoryItem m_item;
63 internal bool m_CMFunctionsEnabled = false;
64
65 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
66 {
67 m_ScriptEngine = ScriptEngine;
68 m_host = host;
69 m_item = item;
70
71 if (m_ScriptEngine.Config.GetBoolean("AllowCareminsterFunctions", false))
72 m_CMFunctionsEnabled = true;
73 }
74
75 public override Object InitializeLifetimeService()
76 {
77 ILease lease = (ILease)base.InitializeLifetimeService();
78
79 if (lease.CurrentState == LeaseState.Initial)
80 {
81 lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
82 // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
83 // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
84 }
85 return lease;
86 }
87
88 public Scene World
89 {
90 get { return m_ScriptEngine.World; }
91 }
92
93 public string cmDetectedCountry(int number)
94 {
95 m_host.AddScriptLPS(1);
96 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, number);
97 if (detectedParams == null)
98 return String.Empty;
99 return detectedParams.Country;
100 }
101
102 public string cmGetAgentCountry(LSL_Key key)
103 {
104 if (!World.Permissions.IsGod(m_host.OwnerID))
105 return String.Empty;
106
107 UUID uuid;
108
109 if (!UUID.TryParse(key, out uuid))
110 return String.Empty;
111
112 UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
113 return account.UserCountry;
114 }
115 }
116}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index fb0fdc9..6af3c1e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -28,10 +28,12 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Diagnostics; //for [DebuggerNonUserCode]
31using System.Runtime.Remoting.Lifetime; 32using System.Runtime.Remoting.Lifetime;
32using System.Text; 33using System.Text;
33using System.Threading; 34using System.Threading;
34using System.Text.RegularExpressions; 35using System.Text.RegularExpressions;
36using System.Timers;
35using Nini.Config; 37using Nini.Config;
36using log4net; 38using log4net;
37using OpenMetaverse; 39using OpenMetaverse;
@@ -44,6 +46,7 @@ using OpenSim.Region.CoreModules.World.Land;
44using OpenSim.Region.CoreModules.World.Terrain; 46using OpenSim.Region.CoreModules.World.Terrain;
45using OpenSim.Region.Framework.Interfaces; 47using OpenSim.Region.Framework.Interfaces;
46using OpenSim.Region.Framework.Scenes; 48using OpenSim.Region.Framework.Scenes;
49using OpenSim.Region.Framework.Scenes.Serialization;
47using OpenSim.Region.Framework.Scenes.Animation; 50using OpenSim.Region.Framework.Scenes.Animation;
48using OpenSim.Region.Physics.Manager; 51using OpenSim.Region.Physics.Manager;
49using OpenSim.Region.ScriptEngine.Shared; 52using OpenSim.Region.ScriptEngine.Shared;
@@ -65,6 +68,7 @@ using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
65using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; 68using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
66using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; 69using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
67using System.Reflection; 70using System.Reflection;
71using Timer = System.Timers.Timer;
68 72
69namespace OpenSim.Region.ScriptEngine.Shared.Api 73namespace OpenSim.Region.ScriptEngine.Shared.Api
70{ 74{
@@ -103,15 +107,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
103 protected int m_notecardLineReadCharsMax = 255; 107 protected int m_notecardLineReadCharsMax = 255;
104 protected int m_scriptConsoleChannel = 0; 108 protected int m_scriptConsoleChannel = 0;
105 protected bool m_scriptConsoleChannelEnabled = false; 109 protected bool m_scriptConsoleChannelEnabled = false;
110 protected bool m_debuggerSafe = false;
106 protected IUrlModule m_UrlModule = null; 111 protected IUrlModule m_UrlModule = null;
107 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache = new Dictionary<UUID, UserInfoCacheEntry>(); 112 protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache =
108 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp. 113 new Dictionary<UUID, UserInfoCacheEntry>();
114 protected int EMAIL_PAUSE_TIME = 20; // documented delay value for smtp.
115
116 protected Timer m_ShoutSayTimer;
117 protected int m_SayShoutCount = 0;
118
119 private Dictionary<string, string> MovementAnimationsForLSL =
120 new Dictionary<string, string> {
121 {"FLY", "Flying"},
122 {"FLYSLOW", "FlyingSlow"},
123 {"HOVER_UP", "Hovering Up"},
124 {"HOVER_DOWN", "Hovering Down"},
125 {"HOVER", "Hovering"},
126 {"LAND", "Landing"},
127 {"FALLDOWN", "Falling Down"},
128 {"PREJUMP", "PreJumping"},
129 {"JUMP", "Jumping"},
130 {"STANDUP", "Standing Up"},
131 {"SOFT_LAND", "Soft Landing"},
132 {"STAND", "Standing"},
133 {"CROUCHWALK", "CrouchWalking"},
134 {"RUN", "Running"},
135 {"WALK", "Walking"},
136 {"CROUCH", "Crouching"},
137 {"TURNLEFT", "Turning Left"},
138 {"TURNRIGHT", "Turning Right"}
139 };
109 140
110 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) 141 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
111 { 142 {
143 m_ShoutSayTimer = new Timer(1000);
144 m_ShoutSayTimer.Elapsed += SayShoutTimerElapsed;
145 m_ShoutSayTimer.AutoReset = true;
146 m_ShoutSayTimer.Start();
147
112 m_ScriptEngine = ScriptEngine; 148 m_ScriptEngine = ScriptEngine;
113 m_host = host; 149 m_host = host;
114 m_item = item; 150 m_item = item;
151 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
115 152
116 LoadLimits(); // read script limits from config. 153 LoadLimits(); // read script limits from config.
117 154
@@ -171,6 +208,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
171 get { return m_ScriptEngine.World; } 208 get { return m_ScriptEngine.World; }
172 } 209 }
173 210
211 [DebuggerNonUserCode]
174 public void state(string newState) 212 public void state(string newState)
175 { 213 {
176 m_ScriptEngine.SetState(m_item.ItemID, newState); 214 m_ScriptEngine.SetState(m_item.ItemID, newState);
@@ -180,6 +218,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
180 /// Reset the named script. The script must be present 218 /// Reset the named script. The script must be present
181 /// in the same prim. 219 /// in the same prim.
182 /// </summary> 220 /// </summary>
221 [DebuggerNonUserCode]
183 public void llResetScript() 222 public void llResetScript()
184 { 223 {
185 m_host.AddScriptLPS(1); 224 m_host.AddScriptLPS(1);
@@ -236,9 +275,62 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
236 } 275 }
237 } 276 }
238 277
278 public List<ScenePresence> GetLinkAvatars(int linkType)
279 {
280 List<ScenePresence> ret = new List<ScenePresence>();
281 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
282 return ret;
283
284 List<ScenePresence> avs = m_host.ParentGroup.GetLinkedAvatars();
285
286 switch (linkType)
287 {
288 case ScriptBaseClass.LINK_SET:
289 return avs;
290
291 case ScriptBaseClass.LINK_ROOT:
292 return ret;
293
294 case ScriptBaseClass.LINK_ALL_OTHERS:
295 return avs;
296
297 case ScriptBaseClass.LINK_ALL_CHILDREN:
298 return avs;
299
300 case ScriptBaseClass.LINK_THIS:
301 return ret;
302
303 default:
304 if (linkType < 0)
305 return ret;
306
307 int partCount = m_host.ParentGroup.GetPartCount();
308
309 if (linkType <= partCount)
310 {
311 return ret;
312 }
313 else
314 {
315 linkType = linkType - partCount;
316 if (linkType > avs.Count)
317 {
318 return ret;
319 }
320 else
321 {
322 ret.Add(avs[linkType-1]);
323 return ret;
324 }
325 }
326 }
327 }
328
239 public List<SceneObjectPart> GetLinkParts(int linkType) 329 public List<SceneObjectPart> GetLinkParts(int linkType)
240 { 330 {
241 List<SceneObjectPart> ret = new List<SceneObjectPart>(); 331 List<SceneObjectPart> ret = new List<SceneObjectPart>();
332 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
333 return ret;
242 ret.Add(m_host); 334 ret.Add(m_host);
243 335
244 switch (linkType) 336 switch (linkType)
@@ -432,31 +524,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
432 524
433 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke 525 //Now we start getting into quaternions which means sin/cos, matrices and vectors. ckrinke
434 526
435 /// <summary> 527 // Utility function for llRot2Euler
436 /// Convert an LSL rotation to a Euler vector. 528
437 /// </summary> 529 // normalize an angle between -PI and PI (-180 to +180 degrees)
438 /// <remarks> 530 protected double NormalizeAngle(double angle)
439 /// Using algorithm based off http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/quat_2_euler_paper_ver2-1.pdf
440 /// to avoid issues with singularity and rounding with Y rotation of +/- PI/2
441 /// </remarks>
442 /// <param name="r"></param>
443 /// <returns></returns>
444 public LSL_Vector llRot2Euler(LSL_Rotation r)
445 { 531 {
446 m_host.AddScriptLPS(1); 532 if (angle > -Math.PI && angle < Math.PI)
533 return angle;
534
535 int numPis = (int)(Math.PI / angle);
536 double remainder = angle - Math.PI * numPis;
537 if (numPis % 2 == 1)
538 return Math.PI - angle;
539 return remainder;
540 }
447 541
448 LSL_Vector v = new LSL_Vector(0.0, 0.0, 1.0) * r; // Z axis unit vector unaffected by Z rotation component of r. 542 public LSL_Vector llRot2Euler(LSL_Rotation q1)
449 double m = LSL_Vector.Mag(v); // Just in case v isn't normalized, need magnitude for Asin() operation later. 543 {
450 if (m == 0.0) return new LSL_Vector(); 544 m_host.AddScriptLPS(1);
451 double x = Math.Atan2(-v.y, v.z); 545 LSL_Vector eul = new LSL_Vector();
452 double sin = v.x / m;
453 if (sin < -0.999999 || sin > 0.999999) x = 0.0; // Force X rotation to 0 at the singularities.
454 double y = Math.Asin(sin);
455 // Rotate X axis unit vector by r and unwind the X and Y rotations leaving only the Z rotation
456 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)));
457 double z = Math.Atan2(v.y, v.x);
458 546
459 return new LSL_Vector(x, y, z); 547 double sqw = q1.s*q1.s;
548 double sqx = q1.x*q1.x;
549 double sqy = q1.z*q1.z;
550 double sqz = q1.y*q1.y;
551 double unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
552 double test = q1.x*q1.z + q1.y*q1.s;
553 if (test > 0.4999*unit) { // singularity at north pole
554 eul.z = 2 * Math.Atan2(q1.x,q1.s);
555 eul.y = Math.PI/2;
556 eul.x = 0;
557 return eul;
558 }
559 if (test < -0.4999*unit) { // singularity at south pole
560 eul.z = -2 * Math.Atan2(q1.x,q1.s);
561 eul.y = -Math.PI/2;
562 eul.x = 0;
563 return eul;
564 }
565 eul.z = Math.Atan2(2*q1.z*q1.s-2*q1.x*q1.y , sqx - sqy - sqz + sqw);
566 eul.y = Math.Asin(2*test/unit);
567 eul.x = Math.Atan2(2*q1.x*q1.s-2*q1.z*q1.y , -sqx + sqy - sqz + sqw);
568 return eul;
460 } 569 }
461 570
462 /* From wiki: 571 /* From wiki:
@@ -658,77 +767,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
658 { 767 {
659 //A and B should both be normalized 768 //A and B should both be normalized
660 m_host.AddScriptLPS(1); 769 m_host.AddScriptLPS(1);
661 LSL_Rotation rotBetween; 770 /* This method is more accurate than the SL one, and thus causes problems
662 // Check for zero vectors. If either is zero, return zero rotation. Otherwise, 771 for scripts that deal with the SL inaccuracy around 180-degrees -.- .._.
663 // continue calculation. 772
664 if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f)) 773 double dotProduct = LSL_Vector.Dot(a, b);
774 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
775 double magProduct = LSL_Vector.Mag(a) * LSL_Vector.Mag(b);
776 double angle = Math.Acos(dotProduct / magProduct);
777 LSL_Vector axis = LSL_Vector.Norm(crossProduct);
778 double s = Math.Sin(angle / 2);
779
780 double x = axis.x * s;
781 double y = axis.y * s;
782 double z = axis.z * s;
783 double w = Math.Cos(angle / 2);
784
785 if (Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w))
786 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
787
788 return new LSL_Rotation((float)x, (float)y, (float)z, (float)w);
789 */
790
791 // This method mimics the 180 errors found in SL
792 // See www.euclideanspace.com... angleBetween
793 LSL_Vector vec_a = a;
794 LSL_Vector vec_b = b;
795
796 // Eliminate zero length
797 LSL_Float vec_a_mag = LSL_Vector.Mag(vec_a);
798 LSL_Float vec_b_mag = LSL_Vector.Mag(vec_b);
799 if (vec_a_mag < 0.00001 ||
800 vec_b_mag < 0.00001)
665 { 801 {
666 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f); 802 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
667 } 803 }
668 else 804
805 // Normalize
806 vec_a = llVecNorm(vec_a);
807 vec_b = llVecNorm(vec_b);
808
809 // Calculate axis and rotation angle
810 LSL_Vector axis = vec_a % vec_b;
811 LSL_Float cos_theta = vec_a * vec_b;
812
813 // Check if parallel
814 if (cos_theta > 0.99999)
669 { 815 {
670 a = LSL_Vector.Norm(a); 816 return new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
671 b = LSL_Vector.Norm(b); 817 }
672 double dotProduct = LSL_Vector.Dot(a, b); 818
673 // There are two degenerate cases possible. These are for vectors 180 or 819 // Check if anti-parallel
674 // 0 degrees apart. These have to be detected and handled individually. 820 else if (cos_theta < -0.99999)
675 // 821 {
676 // Check for vectors 180 degrees apart. 822 LSL_Vector orthog_axis = new LSL_Vector(1.0, 0.0, 0.0) - (vec_a.x / (vec_a * vec_a) * vec_a);
677 // A dot product of -1 would mean the angle between vectors is 180 degrees. 823 if (LSL_Vector.Mag(orthog_axis) < 0.000001) orthog_axis = new LSL_Vector(0.0, 0.0, 1.0);
678 if (dotProduct < -0.9999999f) 824 return new LSL_Rotation((float)orthog_axis.x, (float)orthog_axis.y, (float)orthog_axis.z, 0.0);
679 { 825 }
680 // First assume X axis is orthogonal to the vectors. 826 else // other rotation
681 LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f); 827 {
682 orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a)); 828 LSL_Float theta = (LSL_Float)Math.Acos(cos_theta) * 0.5f;
683 // Check for near zero vector. A very small non-zero number here will create 829 axis = llVecNorm(axis);
684 // a rotation in an undesired direction. 830 double x, y, z, s, t;
685 if (LSL_Vector.Mag(orthoVector) > 0.0001) 831 s = Math.Cos(theta);
686 { 832 t = Math.Sin(theta);
687 rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f); 833 x = axis.x * t;
688 } 834 y = axis.y * t;
689 // If the magnitude of the vector was near zero, then assume the X axis is not 835 z = axis.z * t;
690 // orthogonal and use the Z axis instead. 836 return new LSL_Rotation(x,y,z,s);
691 else
692 {
693 // Set 180 z rotation.
694 rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f);
695 }
696 }
697 // Check for parallel vectors.
698 // A dot product of 1 would mean the angle between vectors is 0 degrees.
699 else if (dotProduct > 0.9999999f)
700 {
701 // Set zero rotation.
702 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
703 }
704 else
705 {
706 // All special checks have been performed so get the axis of rotation.
707 LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
708 // Quarternion s value is the length of the unit vector + dot product.
709 double qs = 1.0 + dotProduct;
710 rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs);
711 // Normalize the rotation.
712 double mag = LSL_Rotation.Mag(rotBetween);
713 // We shouldn't have to worry about a divide by zero here. The qs value will be
714 // non-zero because we already know if we're here, then the dotProduct is not -1 so
715 // qs will not be zero. Also, we've already handled the input vectors being zero so the
716 // crossProduct vector should also not be zero.
717 rotBetween.x = rotBetween.x / mag;
718 rotBetween.y = rotBetween.y / mag;
719 rotBetween.z = rotBetween.z / mag;
720 rotBetween.s = rotBetween.s / mag;
721 // Check for undefined values and set zero rotation if any found. This code might not actually be required
722 // any longer since zero vectors are checked for at the top.
723 if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s))
724 {
725 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
726 }
727 }
728 } 837 }
729 return rotBetween;
730 } 838 }
731 839
732 public void llWhisper(int channelID, string text) 840 public void llWhisper(int channelID, string text)
733 { 841 {
734 m_host.AddScriptLPS(1); 842 m_host.AddScriptLPS(1);
@@ -748,6 +856,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
748 { 856 {
749 m_host.AddScriptLPS(1); 857 m_host.AddScriptLPS(1);
750 858
859 if (channelID == 0)
860 m_SayShoutCount++;
861
862 if (m_SayShoutCount >= 11)
863 ScriptSleep(2000);
864
751 if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel)) 865 if (m_scriptConsoleChannelEnabled && (channelID == m_scriptConsoleChannel))
752 { 866 {
753 Console.WriteLine(text); 867 Console.WriteLine(text);
@@ -770,6 +884,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
770 { 884 {
771 m_host.AddScriptLPS(1); 885 m_host.AddScriptLPS(1);
772 886
887 if (channelID == 0)
888 m_SayShoutCount++;
889
890 if (m_SayShoutCount >= 11)
891 ScriptSleep(2000);
892
773 if (text.Length > 1023) 893 if (text.Length > 1023)
774 text = text.Substring(0, 1023); 894 text = text.Substring(0, 1023);
775 895
@@ -1072,10 +1192,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1072 return detectedParams.TouchUV; 1192 return detectedParams.TouchUV;
1073 } 1193 }
1074 1194
1195 [DebuggerNonUserCode]
1075 public virtual void llDie() 1196 public virtual void llDie()
1076 { 1197 {
1077 m_host.AddScriptLPS(1); 1198 m_host.AddScriptLPS(1);
1078 throw new SelfDeleteException(); 1199 if (!m_host.ParentGroup.IsAttachment) throw new SelfDeleteException();
1079 } 1200 }
1080 1201
1081 public LSL_Float llGround(LSL_Vector offset) 1202 public LSL_Float llGround(LSL_Vector offset)
@@ -1148,6 +1269,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1148 1269
1149 public void llSetStatus(int status, int value) 1270 public void llSetStatus(int status, int value)
1150 { 1271 {
1272 if (m_host == null || m_host.ParentGroup == null || m_host.ParentGroup.IsDeleted)
1273 return;
1151 m_host.AddScriptLPS(1); 1274 m_host.AddScriptLPS(1);
1152 1275
1153 int statusrotationaxis = 0; 1276 int statusrotationaxis = 0;
@@ -1171,6 +1294,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1171 if (!allow) 1294 if (!allow)
1172 return; 1295 return;
1173 1296
1297 if (m_host.ParentGroup.RootPart.PhysActor != null &&
1298 m_host.ParentGroup.RootPart.PhysActor.IsPhysical)
1299 return;
1300
1174 m_host.ScriptSetPhysicsStatus(true); 1301 m_host.ScriptSetPhysicsStatus(true);
1175 } 1302 }
1176 else 1303 else
@@ -1379,6 +1506,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1379 { 1506 {
1380 m_host.AddScriptLPS(1); 1507 m_host.AddScriptLPS(1);
1381 1508
1509 SetColor(m_host, color, face);
1510 }
1511
1512 protected void SetColor(SceneObjectPart part, LSL_Vector color, int face)
1513 {
1514 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1515 return;
1516
1517 Primitive.TextureEntry tex = part.Shape.Textures;
1518 Color4 texcolor;
1519 if (face >= 0 && face < GetNumberOfSides(part))
1520 {
1521 texcolor = tex.CreateFace((uint)face).RGBA;
1522 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1523 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1524 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1525 tex.FaceTextures[face].RGBA = texcolor;
1526 part.UpdateTextureEntry(tex.GetBytes());
1527 return;
1528 }
1529 else if (face == ScriptBaseClass.ALL_SIDES)
1530 {
1531 for (uint i = 0; i < GetNumberOfSides(part); i++)
1532 {
1533 if (tex.FaceTextures[i] != null)
1534 {
1535 texcolor = tex.FaceTextures[i].RGBA;
1536 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1537 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1538 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1539 tex.FaceTextures[i].RGBA = texcolor;
1540 }
1541 texcolor = tex.DefaultTexture.RGBA;
1542 texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
1543 texcolor.G = Util.Clip((float)color.y, 0.0f, 1.0f);
1544 texcolor.B = Util.Clip((float)color.z, 0.0f, 1.0f);
1545 tex.DefaultTexture.RGBA = texcolor;
1546 }
1547 part.UpdateTextureEntry(tex.GetBytes());
1548 return;
1549 }
1550
1382 if (face == ScriptBaseClass.ALL_SIDES) 1551 if (face == ScriptBaseClass.ALL_SIDES)
1383 face = SceneObjectPart.ALL_SIDES; 1552 face = SceneObjectPart.ALL_SIDES;
1384 1553
@@ -1387,6 +1556,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1387 1556
1388 public void SetTexGen(SceneObjectPart part, int face,int style) 1557 public void SetTexGen(SceneObjectPart part, int face,int style)
1389 { 1558 {
1559 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1560 return;
1561
1390 Primitive.TextureEntry tex = part.Shape.Textures; 1562 Primitive.TextureEntry tex = part.Shape.Textures;
1391 MappingType textype; 1563 MappingType textype;
1392 textype = MappingType.Default; 1564 textype = MappingType.Default;
@@ -1417,6 +1589,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1417 1589
1418 public void SetGlow(SceneObjectPart part, int face, float glow) 1590 public void SetGlow(SceneObjectPart part, int face, float glow)
1419 { 1591 {
1592 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1593 return;
1594
1420 Primitive.TextureEntry tex = part.Shape.Textures; 1595 Primitive.TextureEntry tex = part.Shape.Textures;
1421 if (face >= 0 && face < GetNumberOfSides(part)) 1596 if (face >= 0 && face < GetNumberOfSides(part))
1422 { 1597 {
@@ -1442,6 +1617,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1442 1617
1443 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump) 1618 public void SetShiny(SceneObjectPart part, int face, int shiny, Bumpiness bump)
1444 { 1619 {
1620 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1621 return;
1445 1622
1446 Shininess sval = new Shininess(); 1623 Shininess sval = new Shininess();
1447 1624
@@ -1492,6 +1669,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1492 1669
1493 public void SetFullBright(SceneObjectPart part, int face, bool bright) 1670 public void SetFullBright(SceneObjectPart part, int face, bool bright)
1494 { 1671 {
1672 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1673 return;
1674
1495 Primitive.TextureEntry tex = part.Shape.Textures; 1675 Primitive.TextureEntry tex = part.Shape.Textures;
1496 if (face >= 0 && face < GetNumberOfSides(part)) 1676 if (face >= 0 && face < GetNumberOfSides(part))
1497 { 1677 {
@@ -1552,13 +1732,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1552 m_host.AddScriptLPS(1); 1732 m_host.AddScriptLPS(1);
1553 1733
1554 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1734 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1555 1735 if (parts.Count > 0)
1556 foreach (SceneObjectPart part in parts) 1736 {
1557 SetAlpha(part, alpha, face); 1737 try
1738 {
1739 parts[0].ParentGroup.areUpdatesSuspended = true;
1740 foreach (SceneObjectPart part in parts)
1741 SetAlpha(part, alpha, face);
1742 }
1743 finally
1744 {
1745 parts[0].ParentGroup.areUpdatesSuspended = false;
1746 }
1747 }
1558 } 1748 }
1559 1749
1560 protected void SetAlpha(SceneObjectPart part, double alpha, int face) 1750 protected void SetAlpha(SceneObjectPart part, double alpha, int face)
1561 { 1751 {
1752 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1753 return;
1754
1562 Primitive.TextureEntry tex = part.Shape.Textures; 1755 Primitive.TextureEntry tex = part.Shape.Textures;
1563 Color4 texcolor; 1756 Color4 texcolor;
1564 if (face >= 0 && face < GetNumberOfSides(part)) 1757 if (face >= 0 && face < GetNumberOfSides(part))
@@ -1611,7 +1804,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1611 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction, 1804 protected void SetFlexi(SceneObjectPart part, bool flexi, int softness, float gravity, float friction,
1612 float wind, float tension, LSL_Vector Force) 1805 float wind, float tension, LSL_Vector Force)
1613 { 1806 {
1614 if (part == null) 1807 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1615 return; 1808 return;
1616 1809
1617 if (flexi) 1810 if (flexi)
@@ -1645,7 +1838,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1645 /// <param name="falloff"></param> 1838 /// <param name="falloff"></param>
1646 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff) 1839 protected void SetPointLight(SceneObjectPart part, bool light, LSL_Vector color, float intensity, float radius, float falloff)
1647 { 1840 {
1648 if (part == null) 1841 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1649 return; 1842 return;
1650 1843
1651 if (light) 1844 if (light)
@@ -1724,15 +1917,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1724 m_host.AddScriptLPS(1); 1917 m_host.AddScriptLPS(1);
1725 1918
1726 List<SceneObjectPart> parts = GetLinkParts(linknumber); 1919 List<SceneObjectPart> parts = GetLinkParts(linknumber);
1727 1920 if (parts.Count > 0)
1728 foreach (SceneObjectPart part in parts) 1921 {
1729 SetTexture(part, texture, face); 1922 try
1730 1923 {
1924 parts[0].ParentGroup.areUpdatesSuspended = true;
1925 foreach (SceneObjectPart part in parts)
1926 SetTexture(part, texture, face);
1927 }
1928 finally
1929 {
1930 parts[0].ParentGroup.areUpdatesSuspended = false;
1931 }
1932 }
1731 ScriptSleep(200); 1933 ScriptSleep(200);
1732 } 1934 }
1733 1935
1734 protected void SetTexture(SceneObjectPart part, string texture, int face) 1936 protected void SetTexture(SceneObjectPart part, string texture, int face)
1735 { 1937 {
1938 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1939 return;
1940
1736 UUID textureID = new UUID(); 1941 UUID textureID = new UUID();
1737 1942
1738 textureID = InventoryKey(texture, (int)AssetType.Texture); 1943 textureID = InventoryKey(texture, (int)AssetType.Texture);
@@ -1777,6 +1982,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1777 1982
1778 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face) 1983 protected void ScaleTexture(SceneObjectPart part, double u, double v, int face)
1779 { 1984 {
1985 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
1986 return;
1987
1780 Primitive.TextureEntry tex = part.Shape.Textures; 1988 Primitive.TextureEntry tex = part.Shape.Textures;
1781 if (face >= 0 && face < GetNumberOfSides(part)) 1989 if (face >= 0 && face < GetNumberOfSides(part))
1782 { 1990 {
@@ -1813,6 +2021,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1813 2021
1814 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face) 2022 protected void OffsetTexture(SceneObjectPart part, double u, double v, int face)
1815 { 2023 {
2024 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2025 return;
2026
1816 Primitive.TextureEntry tex = part.Shape.Textures; 2027 Primitive.TextureEntry tex = part.Shape.Textures;
1817 if (face >= 0 && face < GetNumberOfSides(part)) 2028 if (face >= 0 && face < GetNumberOfSides(part))
1818 { 2029 {
@@ -1849,6 +2060,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1849 2060
1850 protected void RotateTexture(SceneObjectPart part, double rotation, int face) 2061 protected void RotateTexture(SceneObjectPart part, double rotation, int face)
1851 { 2062 {
2063 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2064 return;
2065
1852 Primitive.TextureEntry tex = part.Shape.Textures; 2066 Primitive.TextureEntry tex = part.Shape.Textures;
1853 if (face >= 0 && face < GetNumberOfSides(part)) 2067 if (face >= 0 && face < GetNumberOfSides(part))
1854 { 2068 {
@@ -1953,26 +2167,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1953 return real_vec; 2167 return real_vec;
1954 } 2168 }
1955 2169
2170 public LSL_Integer llSetRegionPos(LSL_Vector pos)
2171 {
2172 return new LSL_Integer(SetRegionPos(m_host, pos));
2173 }
2174
2175 protected int SetRegionPos(SceneObjectPart part, LSL_Vector targetPos)
2176 {
2177 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2178 return 0;
2179
2180 SceneObjectGroup grp = part.ParentGroup;
2181
2182 if (grp.IsAttachment)
2183 return 0;
2184
2185 if (grp.RootPart.PhysActor != null && grp.RootPart.PhysActor.IsPhysical)
2186 return 0;
2187
2188 if (targetPos.x < -10.0f || targetPos.x >= (float)Constants.RegionSize || targetPos.y < -10.0f || targetPos.y >= (float)Constants.RegionSize || targetPos.z < 0 || targetPos.z >= 4096.0f)
2189 return 0;
2190
2191 float constrainedX = (float)targetPos.x;
2192 float constrainedY = (float)targetPos.y;
2193
2194 if (constrainedX < 0.0f)
2195 constrainedX = 0.0f;
2196 if (constrainedY < 0.0f)
2197 constrainedY = 0.0f;
2198 if (constrainedX >= (float)Constants.RegionSize)
2199 constrainedX = (float)Constants.RegionSize - 0.1f;
2200 if (constrainedY >= (float)Constants.RegionSize)
2201 constrainedY = (float)Constants.RegionSize -0.1f;
2202
2203 float ground = World.GetGroundHeight(constrainedX, constrainedY);
2204
2205 if (targetPos.z < ground)
2206 targetPos.z = ground;
2207
2208 Vector3 dest = new Vector3((float)targetPos.x, (float)targetPos.y, (float)targetPos.z);
2209
2210 if (!World.Permissions.CanObjectEntry(grp.UUID, false, dest))
2211 return 0;
2212
2213 grp.UpdateGroupPosition(dest);
2214
2215 return 1;
2216 }
2217
1956 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos) 2218 protected void SetPos(SceneObjectPart part, LSL_Vector targetPos)
1957 { 2219 {
1958 // Capped movemment if distance > 10m (http://wiki.secondlife.com/wiki/LlSetPos) 2220 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2221 return;
2222
1959 LSL_Vector currentPos = GetPartLocalPos(part); 2223 LSL_Vector currentPos = GetPartLocalPos(part);
2224 LSL_Vector toPos = GetSetPosTarget(part, targetPos, currentPos);
1960 2225
1961 float ground = World.GetGroundHeight((float)targetPos.x, (float)targetPos.y);
1962 bool disable_underground_movement = m_ScriptEngine.Config.GetBoolean("DisableUndergroundMovement", true);
1963 2226
1964 if (part.ParentGroup.RootPart == part) 2227 if (part.ParentGroup.RootPart == part)
1965 { 2228 {
1966 if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
1967 targetPos.z = ground;
1968 SceneObjectGroup parent = part.ParentGroup; 2229 SceneObjectGroup parent = part.ParentGroup;
1969 LSL_Vector real_vec = SetPosAdjust(currentPos, targetPos); 2230 Vector3 dest = new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z);
1970 parent.UpdateGroupPosition(new Vector3((float)real_vec.x, (float)real_vec.y, (float)real_vec.z)); 2231 if (!World.Permissions.CanObjectEntry(parent.UUID, false, dest))
2232 return;
2233 Util.FireAndForget(delegate(object x) {
2234 parent.UpdateGroupPosition(dest);
2235 });
1971 } 2236 }
1972 else 2237 else
1973 { 2238 {
1974 LSL_Vector rel_vec = SetPosAdjust(currentPos, targetPos); 2239 part.OffsetPosition = new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z);
1975 part.OffsetPosition = new Vector3((float)rel_vec.x, (float)rel_vec.y, (float)rel_vec.z);
1976 SceneObjectGroup parent = part.ParentGroup; 2240 SceneObjectGroup parent = part.ParentGroup;
1977 parent.HasGroupChanged = true; 2241 parent.HasGroupChanged = true;
1978 parent.ScheduleGroupForTerseUpdate(); 2242 parent.ScheduleGroupForTerseUpdate();
@@ -2005,17 +2269,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2005 else 2269 else
2006 { 2270 {
2007 if (part.ParentGroup.IsAttachment) 2271 if (part.ParentGroup.IsAttachment)
2008 {
2009 pos = part.AttachedPos; 2272 pos = part.AttachedPos;
2010 }
2011 else 2273 else
2012 {
2013 pos = part.AbsolutePosition; 2274 pos = part.AbsolutePosition;
2014 }
2015 } 2275 }
2016 2276
2017// m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
2018
2019 return new LSL_Vector(pos.X, pos.Y, pos.Z); 2277 return new LSL_Vector(pos.X, pos.Y, pos.Z);
2020 } 2278 }
2021 2279
@@ -2024,9 +2282,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2024 m_host.AddScriptLPS(1); 2282 m_host.AddScriptLPS(1);
2025 2283
2026 // try to let this work as in SL... 2284 // try to let this work as in SL...
2027 if (m_host.ParentID == 0) 2285 if (m_host.LinkNum < 2)
2028 { 2286 {
2029 // special case: If we are root, rotate complete SOG to new rotation 2287 // Special case: If we are root, rotate complete SOG to new
2288 // rotation.
2289 // We are root if the link number is 0 (single prim) or 1
2290 // (root prim). ParentID may be nonzero in attachments and
2291 // using it would cause attachments and HUDs to rotate
2292 // to the wrong positions.
2030 SetRot(m_host, Rot2Quaternion(rot)); 2293 SetRot(m_host, Rot2Quaternion(rot));
2031 } 2294 }
2032 else 2295 else
@@ -2051,6 +2314,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2051 2314
2052 protected void SetRot(SceneObjectPart part, Quaternion rot) 2315 protected void SetRot(SceneObjectPart part, Quaternion rot)
2053 { 2316 {
2317 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
2318 return;
2319
2054 part.UpdateRotation(rot); 2320 part.UpdateRotation(rot);
2055 // Update rotation does not move the object in the physics scene if it's a linkset. 2321 // Update rotation does not move the object in the physics scene if it's a linkset.
2056 2322
@@ -2205,13 +2471,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2205 public void llApplyRotationalImpulse(LSL_Vector force, int local) 2471 public void llApplyRotationalImpulse(LSL_Vector force, int local)
2206 { 2472 {
2207 m_host.AddScriptLPS(1); 2473 m_host.AddScriptLPS(1);
2208 m_host.ApplyAngularImpulse(new Vector3((float)force.x, (float)force.y, (float)force.z), local != 0); 2474 m_host.ParentGroup.RootPart.ApplyAngularImpulse(new Vector3((float)force.x, (float)force.y, (float)force.z), local != 0);
2209 } 2475 }
2210 2476
2211 public void llSetTorque(LSL_Vector torque, int local) 2477 public void llSetTorque(LSL_Vector torque, int local)
2212 { 2478 {
2213 m_host.AddScriptLPS(1); 2479 m_host.AddScriptLPS(1);
2214 m_host.SetAngularImpulse(new Vector3((float)torque.x, (float)torque.y, (float)torque.z), local != 0); 2480 m_host.ParentGroup.RootPart.SetAngularImpulse(new Vector3((float)torque.x, (float)torque.y, (float)torque.z), local != 0);
2215 } 2481 }
2216 2482
2217 public LSL_Vector llGetTorque() 2483 public LSL_Vector llGetTorque()
@@ -2232,16 +2498,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2232 { 2498 {
2233 m_host.AddScriptLPS(1); 2499 m_host.AddScriptLPS(1);
2234 2500
2235 Vector3 vel; 2501 Vector3 vel = Vector3.Zero;
2236 2502
2237 if (m_host.ParentGroup.IsAttachment) 2503 if (m_host.ParentGroup.IsAttachment)
2238 { 2504 {
2239 ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar); 2505 ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
2240 vel = avatar.Velocity; 2506 if (avatar != null)
2507 vel = avatar.Velocity;
2241 } 2508 }
2242 else 2509 else
2243 { 2510 {
2244 vel = m_host.Velocity; 2511 vel = m_host.ParentGroup.RootPart.Velocity;
2245 } 2512 }
2246 2513
2247 return new LSL_Vector(vel.X, vel.Y, vel.Z); 2514 return new LSL_Vector(vel.X, vel.Y, vel.Z);
@@ -2790,8 +3057,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2790 3057
2791 if (pa != null && pa.IsPhysical && llvel != Vector3.Zero) 3058 if (pa != null && pa.IsPhysical && llvel != Vector3.Zero)
2792 { 3059 {
2793 //Recoil. 3060 // recoil
2794 llApplyImpulse(new LSL_Vector(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0); 3061 llvel *= -groupmass;
3062 llApplyImpulse(new LSL_Vector(llvel.X, llvel.Y,llvel.Z), 0);
2795 } 3063 }
2796 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) 3064 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
2797 return; 3065 return;
@@ -2813,35 +3081,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2813 public void llLookAt(LSL_Vector target, double strength, double damping) 3081 public void llLookAt(LSL_Vector target, double strength, double damping)
2814 { 3082 {
2815 m_host.AddScriptLPS(1); 3083 m_host.AddScriptLPS(1);
2816 // Determine where we are looking from
2817 LSL_Vector from = llGetPos();
2818 3084
2819 // Work out the normalised vector from the source to the target 3085 // Get the normalized vector to the target
2820 LSL_Vector delta = llVecNorm(target - from); 3086 LSL_Vector d1 = llVecNorm(target - llGetPos());
2821 LSL_Vector angle = new LSL_Vector(0,0,0);
2822 3087
2823 // Calculate the yaw 3088 // Get the bearing (yaw)
2824 // subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system 3089 LSL_Vector a1 = new LSL_Vector(0,0,0);
2825 angle.x = llAtan2(delta.z, delta.y) - ScriptBaseClass.PI_BY_TWO; 3090 a1.z = llAtan2(d1.y, d1.x);
2826 3091
2827 // Calculate pitch 3092 // Get the elevation (pitch)
2828 angle.y = llAtan2(delta.x, llSqrt((delta.y * delta.y) + (delta.z * delta.z))); 3093 LSL_Vector a2 = new LSL_Vector(0,0,0);
3094 a2.y= -llAtan2(d1.z, llSqrt((d1.x * d1.x) + (d1.y * d1.y)));
2829 3095
2830 // we need to convert from a vector describing 3096 LSL_Rotation r1 = llEuler2Rot(a1);
2831 // the angles of rotation in radians into rotation value 3097 LSL_Rotation r2 = llEuler2Rot(a2);
2832 LSL_Rotation rot = llEuler2Rot(angle); 3098 LSL_Rotation r3 = new LSL_Rotation(0.000000, 0.707107, 0.000000, 0.707107);
2833
2834 // Per discussion with Melanie, for non-physical objects llLookAt appears to simply
2835 // set the rotation of the object, copy that behavior
2836 PhysicsActor pa = m_host.PhysActor;
2837 3099
2838 if (strength == 0 || pa == null || !pa.IsPhysical) 3100 if (m_host.PhysActor == null || !m_host.PhysActor.IsPhysical)
2839 { 3101 {
2840 llSetRot(rot); 3102 // Do nothing if either value is 0 (this has been checked in SL)
3103 if (strength <= 0.0 || damping <= 0.0)
3104 return;
3105
3106 llSetRot(r3 * r2 * r1);
2841 } 3107 }
2842 else 3108 else
2843 { 3109 {
2844 m_host.StartLookAt(Rot2Quaternion(rot), (float)strength, (float)damping); 3110 if (strength == 0)
3111 {
3112 llSetRot(r3 * r2 * r1);
3113 return;
3114 }
3115
3116 m_host.StartLookAt(Rot2Quaternion(r3 * r2 * r1), (float)strength, (float)damping);
2845 } 3117 }
2846 } 3118 }
2847 3119
@@ -2887,17 +3159,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2887 } 3159 }
2888 else 3160 else
2889 { 3161 {
2890 if (m_host.IsRoot) 3162 // new SL always returns object mass
2891 { 3163// if (m_host.IsRoot)
3164// {
2892 return m_host.ParentGroup.GetMass(); 3165 return m_host.ParentGroup.GetMass();
2893 } 3166// }
2894 else 3167// else
2895 { 3168// {
2896 return m_host.GetMass(); 3169// return m_host.GetMass();
2897 } 3170// }
2898 } 3171 }
2899 } 3172 }
2900 3173
3174
3175 public LSL_Float llGetMassMKS()
3176 {
3177 return 100f * llGetMass();
3178 }
3179
2901 public void llCollisionFilter(string name, string id, int accept) 3180 public void llCollisionFilter(string name, string id, int accept)
2902 { 3181 {
2903 m_host.AddScriptLPS(1); 3182 m_host.AddScriptLPS(1);
@@ -2972,7 +3251,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2972 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3251 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
2973 3252
2974 if (attachmentsModule != null) 3253 if (attachmentsModule != null)
2975 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false); 3254 return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false, true);
2976 else 3255 else
2977 return false; 3256 return false;
2978 } 3257 }
@@ -3005,9 +3284,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3005 { 3284 {
3006 m_host.AddScriptLPS(1); 3285 m_host.AddScriptLPS(1);
3007 3286
3008// if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
3009// return;
3010
3011 if (m_item.PermsGranter != m_host.OwnerID) 3287 if (m_item.PermsGranter != m_host.OwnerID)
3012 return; 3288 return;
3013 3289
@@ -3050,6 +3326,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3050 3326
3051 public void llInstantMessage(string user, string message) 3327 public void llInstantMessage(string user, string message)
3052 { 3328 {
3329 UUID result;
3330 if (!UUID.TryParse(user, out result))
3331 {
3332 ShoutError("An invalid key was passed to llInstantMessage");
3333 ScriptSleep(2000);
3334 return;
3335 }
3336
3337
3053 m_host.AddScriptLPS(1); 3338 m_host.AddScriptLPS(1);
3054 3339
3055 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance. 3340 // We may be able to use ClientView.SendInstantMessage here, but we need a client instance.
@@ -3064,14 +3349,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3064 UUID friendTransactionID = UUID.Random(); 3349 UUID friendTransactionID = UUID.Random();
3065 3350
3066 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 3351 //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
3067 3352
3068 GridInstantMessage msg = new GridInstantMessage(); 3353 GridInstantMessage msg = new GridInstantMessage();
3069 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid; 3354 msg.fromAgentID = new Guid(m_host.UUID.ToString()); // fromAgentID.Guid;
3070 msg.toAgentID = new Guid(user); // toAgentID.Guid; 3355 msg.toAgentID = new Guid(user); // toAgentID.Guid;
3071 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here 3356 msg.imSessionID = new Guid(friendTransactionID.ToString()); // This is the item we're mucking with here
3072// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message); 3357// m_log.Debug("[Scripting IM]: From:" + msg.fromAgentID.ToString() + " To: " + msg.toAgentID.ToString() + " Session:" + msg.imSessionID.ToString() + " Message:" + message);
3073// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString()); 3358// m_log.Debug("[Scripting IM]: Filling Session: " + msg.imSessionID.ToString());
3074 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();// timestamp; 3359// DateTime dt = DateTime.UtcNow;
3360//
3361// // Ticks from UtcNow, but make it look like local. Evil, huh?
3362// dt = DateTime.SpecifyKind(dt, DateTimeKind.Local);
3363//
3364// try
3365// {
3366// // Convert that to the PST timezone
3367// TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles");
3368// dt = TimeZoneInfo.ConvertTime(dt, timeZoneInfo);
3369// }
3370// catch
3371// {
3372// // No logging here, as it could be VERY spammy
3373// }
3374//
3375// // And make it look local again to fool the unix time util
3376// dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
3377
3378 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
3379
3075 //if (client != null) 3380 //if (client != null)
3076 //{ 3381 //{
3077 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName; 3382 msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName;
@@ -3085,12 +3390,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3085 msg.message = message.Substring(0, 1024); 3390 msg.message = message.Substring(0, 1024);
3086 else 3391 else
3087 msg.message = message; 3392 msg.message = message;
3088 msg.dialog = (byte)19; // messgage from script ??? // dialog; 3393 msg.dialog = (byte)19; // MessageFromObject
3089 msg.fromGroup = false;// fromGroup; 3394 msg.fromGroup = false;// fromGroup;
3090 msg.offline = (byte)0; //offline; 3395 msg.offline = (byte)0; //offline;
3091 msg.ParentEstateID = 0; //ParentEstateID; 3396 msg.ParentEstateID = World.RegionInfo.EstateSettings.EstateID;
3092 msg.Position = new Vector3(m_host.AbsolutePosition); 3397 msg.Position = new Vector3(m_host.AbsolutePosition);
3093 msg.RegionID = World.RegionInfo.RegionID.Guid;//RegionID.Guid; 3398 msg.RegionID = World.RegionInfo.RegionID.Guid;
3094 msg.binaryBucket 3399 msg.binaryBucket
3095 = Util.StringToBytes256( 3400 = Util.StringToBytes256(
3096 "{0}/{1}/{2}/{3}", 3401 "{0}/{1}/{2}/{3}",
@@ -3118,7 +3423,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3118 } 3423 }
3119 3424
3120 emailModule.SendEmail(m_host.UUID, address, subject, message); 3425 emailModule.SendEmail(m_host.UUID, address, subject, message);
3121 llSleep(EMAIL_PAUSE_TIME); 3426 ScriptSleep(EMAIL_PAUSE_TIME * 1000);
3122 } 3427 }
3123 3428
3124 public void llGetNextEmail(string address, string subject) 3429 public void llGetNextEmail(string address, string subject)
@@ -3362,15 +3667,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3362 int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS | 3667 int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
3363 ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | 3668 ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
3364 ScriptBaseClass.PERMISSION_CONTROL_CAMERA | 3669 ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
3670 ScriptBaseClass.PERMISSION_TRACK_CAMERA |
3365 ScriptBaseClass.PERMISSION_ATTACH; 3671 ScriptBaseClass.PERMISSION_ATTACH;
3366 3672
3367 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3673 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3368 { 3674 {
3369 lock (m_host.TaskInventory) 3675 m_host.TaskInventory.LockItemsForWrite(true);
3370 { 3676 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3371 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID; 3677 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3372 m_host.TaskInventory[m_item.ItemID].PermsMask = perm; 3678 m_host.TaskInventory.LockItemsForWrite(false);
3373 }
3374 3679
3375 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams( 3680 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3376 "run_time_permissions", new Object[] { 3681 "run_time_permissions", new Object[] {
@@ -3380,28 +3685,44 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3380 return; 3685 return;
3381 } 3686 }
3382 } 3687 }
3383 else if (m_host.SitTargetAvatar == agentID) // Sitting avatar 3688 else
3384 { 3689 {
3385 // When agent is sitting, certain permissions are implicit if requested from sitting agent 3690 bool sitting = false;
3386 int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION | 3691 if (m_host.SitTargetAvatar == agentID)
3387 ScriptBaseClass.PERMISSION_CONTROL_CAMERA | 3692 {
3388 ScriptBaseClass.PERMISSION_TRACK_CAMERA | 3693 sitting = true;
3389 ScriptBaseClass.PERMISSION_TAKE_CONTROLS; 3694 }
3695 else
3696 {
3697 foreach (SceneObjectPart p in m_host.ParentGroup.Parts)
3698 {
3699 if (p.SitTargetAvatar == agentID)
3700 sitting = true;
3701 }
3702 }
3390 3703
3391 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms 3704 if (sitting)
3392 { 3705 {
3393 lock (m_host.TaskInventory) 3706 // When agent is sitting, certain permissions are implicit if requested from sitting agent
3707 int implicitPerms = ScriptBaseClass.PERMISSION_TRIGGER_ANIMATION |
3708 ScriptBaseClass.PERMISSION_CONTROL_CAMERA |
3709 ScriptBaseClass.PERMISSION_TRACK_CAMERA |
3710 ScriptBaseClass.PERMISSION_TAKE_CONTROLS;
3711
3712 if ((perm & (~implicitPerms)) == 0) // Requested only implicit perms
3394 { 3713 {
3714 m_host.TaskInventory.LockItemsForWrite(true);
3395 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID; 3715 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3396 m_host.TaskInventory[m_item.ItemID].PermsMask = perm; 3716 m_host.TaskInventory[m_item.ItemID].PermsMask = perm;
3397 } 3717 m_host.TaskInventory.LockItemsForWrite(false);
3398 3718
3399 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams( 3719 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3400 "run_time_permissions", new Object[] { 3720 "run_time_permissions", new Object[] {
3401 new LSL_Integer(perm) }, 3721 new LSL_Integer(perm) },
3402 new DetectParams[0])); 3722 new DetectParams[0]));
3403 3723
3404 return; 3724 return;
3725 }
3405 } 3726 }
3406 } 3727 }
3407 3728
@@ -3438,11 +3759,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3438 3759
3439 if (!m_waitingForScriptAnswer) 3760 if (!m_waitingForScriptAnswer)
3440 { 3761 {
3441 lock (m_host.TaskInventory) 3762 m_host.TaskInventory.LockItemsForWrite(true);
3442 { 3763 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID;
3443 m_host.TaskInventory[m_item.ItemID].PermsGranter = agentID; 3764 m_host.TaskInventory[m_item.ItemID].PermsMask = 0;
3444 m_host.TaskInventory[m_item.ItemID].PermsMask = 0; 3765 m_host.TaskInventory.LockItemsForWrite(false);
3445 }
3446 3766
3447 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer; 3767 presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
3448 m_waitingForScriptAnswer=true; 3768 m_waitingForScriptAnswer=true;
@@ -3471,14 +3791,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3471 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0) 3791 if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
3472 llReleaseControls(); 3792 llReleaseControls();
3473 3793
3474 lock (m_host.TaskInventory) 3794 m_host.TaskInventory.LockItemsForWrite(true);
3475 { 3795 m_host.TaskInventory[m_item.ItemID].PermsMask = answer;
3476 m_host.TaskInventory[m_item.ItemID].PermsMask = answer; 3796 m_host.TaskInventory.LockItemsForWrite(false);
3477 } 3797
3478 3798 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
3479 m_ScriptEngine.PostScriptEvent( 3799 "run_time_permissions", new Object[] {
3480 m_item.ItemID, 3800 new LSL_Integer(answer) },
3481 new EventParams("run_time_permissions", new Object[] { new LSL_Integer(answer) }, new DetectParams[0])); 3801 new DetectParams[0]));
3482 } 3802 }
3483 3803
3484 public LSL_String llGetPermissionsKey() 3804 public LSL_String llGetPermissionsKey()
@@ -3517,14 +3837,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3517 public void llSetLinkColor(int linknumber, LSL_Vector color, int face) 3837 public void llSetLinkColor(int linknumber, LSL_Vector color, int face)
3518 { 3838 {
3519 List<SceneObjectPart> parts = GetLinkParts(linknumber); 3839 List<SceneObjectPart> parts = GetLinkParts(linknumber);
3520 3840 if (parts.Count > 0)
3521 foreach (SceneObjectPart part in parts) 3841 {
3522 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); 3842 try
3843 {
3844 parts[0].ParentGroup.areUpdatesSuspended = true;
3845 foreach (SceneObjectPart part in parts)
3846 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
3847 }
3848 finally
3849 {
3850 parts[0].ParentGroup.areUpdatesSuspended = false;
3851 }
3852 }
3523 } 3853 }
3524 3854
3525 public void llCreateLink(string target, int parent) 3855 public void llCreateLink(string target, int parent)
3526 { 3856 {
3527 m_host.AddScriptLPS(1); 3857 m_host.AddScriptLPS(1);
3858
3528 UUID targetID; 3859 UUID targetID;
3529 3860
3530 if (!UUID.TryParse(target, out targetID)) 3861 if (!UUID.TryParse(target, out targetID))
@@ -3630,10 +3961,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3630 // Restructuring Multiple Prims. 3961 // Restructuring Multiple Prims.
3631 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts); 3962 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
3632 parts.Remove(parentPrim.RootPart); 3963 parts.Remove(parentPrim.RootPart);
3633 foreach (SceneObjectPart part in parts) 3964 if (parts.Count > 0)
3634 { 3965 {
3635 parentPrim.DelinkFromGroup(part.LocalId, true); 3966 try
3967 {
3968 parts[0].ParentGroup.areUpdatesSuspended = true;
3969 foreach (SceneObjectPart part in parts)
3970 {
3971 parentPrim.DelinkFromGroup(part.LocalId, true);
3972 }
3973 }
3974 finally
3975 {
3976 parts[0].ParentGroup.areUpdatesSuspended = false;
3977 }
3636 } 3978 }
3979
3637 parentPrim.HasGroupChanged = true; 3980 parentPrim.HasGroupChanged = true;
3638 parentPrim.ScheduleGroupForFullUpdate(); 3981 parentPrim.ScheduleGroupForFullUpdate();
3639 parentPrim.TriggerScriptChangedEvent(Changed.LINK); 3982 parentPrim.TriggerScriptChangedEvent(Changed.LINK);
@@ -3642,12 +3985,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3642 { 3985 {
3643 SceneObjectPart newRoot = parts[0]; 3986 SceneObjectPart newRoot = parts[0];
3644 parts.Remove(newRoot); 3987 parts.Remove(newRoot);
3645 foreach (SceneObjectPart part in parts) 3988
3989 try
3646 { 3990 {
3647 // Required for linking 3991 parts[0].ParentGroup.areUpdatesSuspended = true;
3648 part.ClearUpdateSchedule(); 3992 foreach (SceneObjectPart part in parts)
3649 newRoot.ParentGroup.LinkToGroup(part.ParentGroup); 3993 {
3994 part.ClearUpdateSchedule();
3995 newRoot.ParentGroup.LinkToGroup(part.ParentGroup);
3996 }
3650 } 3997 }
3998 finally
3999 {
4000 parts[0].ParentGroup.areUpdatesSuspended = false;
4001 }
4002
4003
3651 newRoot.ParentGroup.HasGroupChanged = true; 4004 newRoot.ParentGroup.HasGroupChanged = true;
3652 newRoot.ParentGroup.ScheduleGroupForFullUpdate(); 4005 newRoot.ParentGroup.ScheduleGroupForFullUpdate();
3653 } 4006 }
@@ -3667,6 +4020,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3667 public void llBreakAllLinks() 4020 public void llBreakAllLinks()
3668 { 4021 {
3669 m_host.AddScriptLPS(1); 4022 m_host.AddScriptLPS(1);
4023
4024 TaskInventoryItem item = m_item;
4025
4026 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
4027 && !m_automaticLinkPermission)
4028 {
4029 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
4030 return;
4031 }
4032
3670 SceneObjectGroup parentPrim = m_host.ParentGroup; 4033 SceneObjectGroup parentPrim = m_host.ParentGroup;
3671 if (parentPrim.AttachmentPoint != 0) 4034 if (parentPrim.AttachmentPoint != 0)
3672 return; // Fail silently if attached 4035 return; // Fail silently if attached
@@ -3686,25 +4049,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3686 public LSL_String llGetLinkKey(int linknum) 4049 public LSL_String llGetLinkKey(int linknum)
3687 { 4050 {
3688 m_host.AddScriptLPS(1); 4051 m_host.AddScriptLPS(1);
3689 List<UUID> keytable = new List<UUID>();
3690 // parse for sitting avatare-uuids
3691 World.ForEachRootScenePresence(delegate(ScenePresence presence)
3692 {
3693 if (presence.ParentID != 0 && m_host.ParentGroup.ContainsPart(presence.ParentID))
3694 keytable.Add(presence.UUID);
3695 });
3696
3697 int totalprims = m_host.ParentGroup.PrimCount + keytable.Count;
3698 if (linknum > m_host.ParentGroup.PrimCount && linknum <= totalprims)
3699 {
3700 return keytable[totalprims - linknum].ToString();
3701 }
3702
3703 if (linknum == 1 && m_host.ParentGroup.PrimCount == 1 && keytable.Count == 1)
3704 {
3705 return m_host.UUID.ToString();
3706 }
3707
3708 SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum); 4052 SceneObjectPart part = m_host.ParentGroup.GetLinkNumPart(linknum);
3709 if (part != null) 4053 if (part != null)
3710 { 4054 {
@@ -3712,6 +4056,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3712 } 4056 }
3713 else 4057 else
3714 { 4058 {
4059 if (linknum > m_host.ParentGroup.PrimCount || (linknum == 1 && m_host.ParentGroup.PrimCount == 1))
4060 {
4061 linknum -= (m_host.ParentGroup.PrimCount) + 1;
4062
4063 if (linknum < 0)
4064 return UUID.Zero.ToString();
4065
4066 List<ScenePresence> avatars = GetLinkAvatars(ScriptBaseClass.LINK_SET);
4067 if (avatars.Count > linknum)
4068 {
4069 return avatars[linknum].UUID.ToString();
4070 }
4071 }
3715 return UUID.Zero.ToString(); 4072 return UUID.Zero.ToString();
3716 } 4073 }
3717 } 4074 }
@@ -3811,17 +4168,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3811 m_host.AddScriptLPS(1); 4168 m_host.AddScriptLPS(1);
3812 int count = 0; 4169 int count = 0;
3813 4170
3814 lock (m_host.TaskInventory) 4171 m_host.TaskInventory.LockItemsForRead(true);
4172 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3815 { 4173 {
3816 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4174 if (inv.Value.Type == type || type == -1)
3817 { 4175 {
3818 if (inv.Value.Type == type || type == -1) 4176 count = count + 1;
3819 {
3820 count = count + 1;
3821 }
3822 } 4177 }
3823 } 4178 }
3824 4179
4180 m_host.TaskInventory.LockItemsForRead(false);
3825 return count; 4181 return count;
3826 } 4182 }
3827 4183
@@ -3830,16 +4186,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3830 m_host.AddScriptLPS(1); 4186 m_host.AddScriptLPS(1);
3831 ArrayList keys = new ArrayList(); 4187 ArrayList keys = new ArrayList();
3832 4188
3833 lock (m_host.TaskInventory) 4189 m_host.TaskInventory.LockItemsForRead(true);
4190 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3834 { 4191 {
3835 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4192 if (inv.Value.Type == type || type == -1)
3836 { 4193 {
3837 if (inv.Value.Type == type || type == -1) 4194 keys.Add(inv.Value.Name);
3838 {
3839 keys.Add(inv.Value.Name);
3840 }
3841 } 4195 }
3842 } 4196 }
4197 m_host.TaskInventory.LockItemsForRead(false);
3843 4198
3844 if (keys.Count == 0) 4199 if (keys.Count == 0)
3845 { 4200 {
@@ -3876,25 +4231,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3876 } 4231 }
3877 4232
3878 // move the first object found with this inventory name 4233 // move the first object found with this inventory name
3879 lock (m_host.TaskInventory) 4234 m_host.TaskInventory.LockItemsForRead(true);
4235 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
3880 { 4236 {
3881 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 4237 if (inv.Value.Name == inventory)
3882 { 4238 {
3883 if (inv.Value.Name == inventory) 4239 found = true;
3884 { 4240 objId = inv.Key;
3885 found = true; 4241 assetType = inv.Value.Type;
3886 objId = inv.Key; 4242 objName = inv.Value.Name;
3887 assetType = inv.Value.Type; 4243 break;
3888 objName = inv.Value.Name;
3889 break;
3890 }
3891 } 4244 }
3892 } 4245 }
4246 m_host.TaskInventory.LockItemsForRead(false);
3893 4247
3894 if (!found) 4248 if (!found)
3895 { 4249 {
3896 llSay(0, String.Format("Could not find object '{0}'", inventory)); 4250 llSay(0, String.Format("Could not find object '{0}'", inventory));
3897 throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory)); 4251 return;
4252// throw new Exception(String.Format("The inventory object '{0}' could not be found", inventory));
3898 } 4253 }
3899 4254
3900 // check if destination is an object 4255 // check if destination is an object
@@ -3920,48 +4275,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3920 return; 4275 return;
3921 } 4276 }
3922 } 4277 }
4278
3923 // destination is an avatar 4279 // destination is an avatar
3924 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId); 4280 InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId);
3925 4281
3926 if (agentItem == null) 4282 if (agentItem == null)
3927 return; 4283 return;
3928 4284
3929 byte[] bucket = new byte[17]; 4285 byte[] bucket = new byte[1];
3930 bucket[0] = (byte)assetType; 4286 bucket[0] = (byte)assetType;
3931 byte[] objBytes = agentItem.ID.GetBytes(); 4287 //byte[] objBytes = agentItem.ID.GetBytes();
3932 Array.Copy(objBytes, 0, bucket, 1, 16); 4288 //Array.Copy(objBytes, 0, bucket, 1, 16);
3933 4289
3934 GridInstantMessage msg = new GridInstantMessage(World, 4290 GridInstantMessage msg = new GridInstantMessage(World,
3935 m_host.UUID, m_host.Name+", an object owned by "+ 4291 m_host.OwnerID, m_host.Name, destId,
3936 resolveName(m_host.OwnerID)+",", destId,
3937 (byte)InstantMessageDialog.TaskInventoryOffered, 4292 (byte)InstantMessageDialog.TaskInventoryOffered,
3938 false, objName+"\n"+m_host.Name+" is located at "+ 4293 false, objName+". "+m_host.Name+" is located at "+
3939 World.RegionInfo.RegionName+" "+ 4294 World.RegionInfo.RegionName+" "+
3940 m_host.AbsolutePosition.ToString(), 4295 m_host.AbsolutePosition.ToString(),
3941 agentItem.ID, true, m_host.AbsolutePosition, 4296 agentItem.ID, true, m_host.AbsolutePosition,
3942 bucket); 4297 bucket);
3943 if (m_TransferModule != null) 4298
3944 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); 4299 ScenePresence sp;
4300
4301 if (World.TryGetScenePresence(destId, out sp))
4302 {
4303 sp.ControllingClient.SendInstantMessage(msg);
4304 }
4305 else
4306 {
4307 if (m_TransferModule != null)
4308 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
4309 }
4310
4311 //This delay should only occur when giving inventory to avatars.
3945 ScriptSleep(3000); 4312 ScriptSleep(3000);
3946 } 4313 }
3947 } 4314 }
3948 4315
4316 [DebuggerNonUserCode]
3949 public void llRemoveInventory(string name) 4317 public void llRemoveInventory(string name)
3950 { 4318 {
3951 m_host.AddScriptLPS(1); 4319 m_host.AddScriptLPS(1);
3952 4320
3953 lock (m_host.TaskInventory) 4321 List<TaskInventoryItem> inv;
4322 try
3954 { 4323 {
3955 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4324 m_host.TaskInventory.LockItemsForRead(true);
4325 inv = new List<TaskInventoryItem>(m_host.TaskInventory.Values);
4326 }
4327 finally
4328 {
4329 m_host.TaskInventory.LockItemsForRead(false);
4330 }
4331 foreach (TaskInventoryItem item in inv)
4332 {
4333 if (item.Name == name)
3956 { 4334 {
3957 if (item.Name == name) 4335 if (item.ItemID == m_item.ItemID)
3958 { 4336 throw new ScriptDeleteException();
3959 if (item.ItemID == m_item.ItemID) 4337 else
3960 throw new ScriptDeleteException(); 4338 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3961 else 4339 return;
3962 m_host.Inventory.RemoveInventoryItem(item.ItemID);
3963 return;
3964 }
3965 } 4340 }
3966 } 4341 }
3967 } 4342 }
@@ -3996,115 +4371,122 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3996 { 4371 {
3997 m_host.AddScriptLPS(1); 4372 m_host.AddScriptLPS(1);
3998 4373
3999 UUID uuid = (UUID)id; 4374 UUID uuid;
4000 PresenceInfo pinfo = null; 4375 if (UUID.TryParse(id, out uuid))
4001 UserAccount account;
4002
4003 UserInfoCacheEntry ce;
4004 if (!m_userInfoCache.TryGetValue(uuid, out ce))
4005 { 4376 {
4006 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); 4377 PresenceInfo pinfo = null;
4007 if (account == null) 4378 UserAccount account;
4379
4380 UserInfoCacheEntry ce;
4381 if (!m_userInfoCache.TryGetValue(uuid, out ce))
4008 { 4382 {
4009 m_userInfoCache[uuid] = null; // Cache negative 4383 account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
4010 return UUID.Zero.ToString(); 4384 if (account == null)
4011 } 4385 {
4386 m_userInfoCache[uuid] = null; // Cache negative
4387 return UUID.Zero.ToString();
4388 }
4012 4389
4013 4390
4014 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); 4391 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4015 if (pinfos != null && pinfos.Length > 0) 4392 if (pinfos != null && pinfos.Length > 0)
4016 {
4017 foreach (PresenceInfo p in pinfos)
4018 { 4393 {
4019 if (p.RegionID != UUID.Zero) 4394 foreach (PresenceInfo p in pinfos)
4020 { 4395 {
4021 pinfo = p; 4396 if (p.RegionID != UUID.Zero)
4397 {
4398 pinfo = p;
4399 }
4022 } 4400 }
4023 } 4401 }
4024 }
4025 4402
4026 ce = new UserInfoCacheEntry(); 4403 ce = new UserInfoCacheEntry();
4027 ce.time = Util.EnvironmentTickCount(); 4404 ce.time = Util.EnvironmentTickCount();
4028 ce.account = account; 4405 ce.account = account;
4029 ce.pinfo = pinfo; 4406 ce.pinfo = pinfo;
4030 } 4407 m_userInfoCache[uuid] = ce;
4031 else 4408 }
4032 { 4409 else
4033 if (ce == null) 4410 {
4034 return UUID.Zero.ToString(); 4411 if (ce == null)
4412 return UUID.Zero.ToString();
4035 4413
4036 account = ce.account; 4414 account = ce.account;
4037 pinfo = ce.pinfo; 4415 pinfo = ce.pinfo;
4038 } 4416 }
4039 4417
4040 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) 4418 if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000)
4041 {
4042 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4043 if (pinfos != null && pinfos.Length > 0)
4044 { 4419 {
4045 foreach (PresenceInfo p in pinfos) 4420 PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
4421 if (pinfos != null && pinfos.Length > 0)
4046 { 4422 {
4047 if (p.RegionID != UUID.Zero) 4423 foreach (PresenceInfo p in pinfos)
4048 { 4424 {
4049 pinfo = p; 4425 if (p.RegionID != UUID.Zero)
4426 {
4427 pinfo = p;
4428 }
4050 } 4429 }
4051 } 4430 }
4052 } 4431 else
4053 else 4432 pinfo = null;
4054 pinfo = null;
4055 4433
4056 ce.time = Util.EnvironmentTickCount(); 4434 ce.time = Util.EnvironmentTickCount();
4057 ce.pinfo = pinfo; 4435 ce.pinfo = pinfo;
4058 } 4436 }
4059 4437
4060 string reply = String.Empty; 4438 string reply = String.Empty;
4061 4439
4062 switch (data) 4440 switch (data)
4063 { 4441 {
4064 case 1: // DATA_ONLINE (0|1) 4442 case 1: // DATA_ONLINE (0|1)
4065 if (pinfo != null && pinfo.RegionID != UUID.Zero) 4443 if (pinfo != null && pinfo.RegionID != UUID.Zero)
4066 reply = "1"; 4444 reply = "1";
4067 else 4445 else
4068 reply = "0"; 4446 reply = "0";
4069 break; 4447 break;
4070 case 2: // DATA_NAME (First Last) 4448 case 2: // DATA_NAME (First Last)
4071 reply = account.FirstName + " " + account.LastName; 4449 reply = account.FirstName + " " + account.LastName;
4072 break; 4450 break;
4073 case 3: // DATA_BORN (YYYY-MM-DD) 4451 case 3: // DATA_BORN (YYYY-MM-DD)
4074 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0); 4452 DateTime born = new DateTime(1970, 1, 1, 0, 0, 0, 0);
4075 born = born.AddSeconds(account.Created); 4453 born = born.AddSeconds(account.Created);
4076 reply = born.ToString("yyyy-MM-dd"); 4454 reply = born.ToString("yyyy-MM-dd");
4077 break; 4455 break;
4078 case 4: // DATA_RATING (0,0,0,0,0,0) 4456 case 4: // DATA_RATING (0,0,0,0,0,0)
4079 reply = "0,0,0,0,0,0"; 4457 reply = "0,0,0,0,0,0";
4080 break; 4458 break;
4081 case 7: // DATA_USERLEVEL (integer) 4459 case 8: // DATA_PAYINFO (0|1|2|3)
4082 reply = account.UserLevel.ToString(); 4460 reply = "0";
4083 break; 4461 break;
4084 case 8: // DATA_PAYINFO (0|1|2|3) 4462 default:
4085 reply = "0"; 4463 return UUID.Zero.ToString(); // Raise no event
4086 break; 4464 }
4087 default:
4088 return UUID.Zero.ToString(); // Raise no event
4089 }
4090 4465
4091 UUID rq = UUID.Random(); 4466 UUID rq = UUID.Random();
4092 4467
4093 UUID tid = AsyncCommands. 4468 UUID tid = AsyncCommands.
4094 DataserverPlugin.RegisterRequest(m_host.LocalId, 4469 DataserverPlugin.RegisterRequest(m_host.LocalId,
4095 m_item.ItemID, rq.ToString()); 4470 m_item.ItemID, rq.ToString());
4096 4471
4097 AsyncCommands. 4472 AsyncCommands.
4098 DataserverPlugin.DataserverReply(rq.ToString(), reply); 4473 DataserverPlugin.DataserverReply(rq.ToString(), reply);
4099 4474
4100 ScriptSleep(100); 4475 ScriptSleep(100);
4101 return tid.ToString(); 4476 return tid.ToString();
4477 }
4478 else
4479 {
4480 ShoutError("Invalid UUID passed to llRequestAgentData.");
4481 }
4482 return "";
4102 } 4483 }
4103 4484
4104 public LSL_String llRequestInventoryData(string name) 4485 public LSL_String llRequestInventoryData(string name)
4105 { 4486 {
4106 m_host.AddScriptLPS(1); 4487 m_host.AddScriptLPS(1);
4107 4488
4489 //Clone is thread safe
4108 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 4490 TaskInventoryDictionary itemDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
4109 4491
4110 foreach (TaskInventoryItem item in itemDictionary.Values) 4492 foreach (TaskInventoryItem item in itemDictionary.Values)
@@ -4156,19 +4538,64 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4156 if (UUID.TryParse(agent, out agentId)) 4538 if (UUID.TryParse(agent, out agentId))
4157 { 4539 {
4158 ScenePresence presence = World.GetScenePresence(agentId); 4540 ScenePresence presence = World.GetScenePresence(agentId);
4159 if (presence != null) 4541 if (presence != null && presence.PresenceType != PresenceType.Npc)
4160 { 4542 {
4543 // agent must not be a god
4544 if (presence.UserLevel >= 200) return;
4545
4161 // agent must be over the owners land 4546 // agent must be over the owners land
4162 if (m_host.OwnerID == World.LandChannel.GetLandObject( 4547 if (m_host.OwnerID == World.LandChannel.GetLandObject(
4163 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID) 4548 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
4164 { 4549 {
4165 World.TeleportClientHome(agentId, presence.ControllingClient); 4550 if (!World.TeleportClientHome(agentId, presence.ControllingClient))
4551 {
4552 // They can't be teleported home for some reason
4553 GridRegion regionInfo = World.GridService.GetRegionByUUID(UUID.Zero, new UUID("2b02daac-e298-42fa-9a75-f488d37896e6"));
4554 if (regionInfo != null)
4555 {
4556 World.RequestTeleportLocation(
4557 presence.ControllingClient, regionInfo.RegionHandle, new Vector3(128, 128, 23), Vector3.Zero,
4558 (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
4559 }
4560 }
4166 } 4561 }
4167 } 4562 }
4168 } 4563 }
4169 ScriptSleep(5000); 4564 ScriptSleep(5000);
4170 } 4565 }
4171 4566
4567 public void llTeleportAgent(string agent, string simname, LSL_Vector pos, LSL_Vector lookAt)
4568 {
4569 m_host.AddScriptLPS(1);
4570 UUID agentId = new UUID();
4571 if (UUID.TryParse(agent, out agentId))
4572 {
4573 ScenePresence presence = World.GetScenePresence(agentId);
4574 if (presence != null && presence.PresenceType != PresenceType.Npc)
4575 {
4576 // agent must not be a god
4577 if (presence.GodLevel >= 200) return;
4578
4579 if (simname == String.Empty)
4580 simname = World.RegionInfo.RegionName;
4581
4582 // agent must be over the owners land
4583 if (m_host.OwnerID == World.LandChannel.GetLandObject(
4584 presence.AbsolutePosition.X, presence.AbsolutePosition.Y).LandData.OwnerID)
4585 {
4586 World.RequestTeleportLocation(presence.ControllingClient, simname, new Vector3((float)pos.x, (float)pos.y, (float)pos.z), new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z), (uint)TeleportFlags.ViaLocation);
4587 }
4588 else // or must be wearing the prim
4589 {
4590 if (m_host.ParentGroup.AttachmentPoint != 0 && m_host.OwnerID == presence.UUID)
4591 {
4592 World.RequestTeleportLocation(presence.ControllingClient, simname, new Vector3((float)pos.x, (float)pos.y, (float)pos.z), new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z), (uint)TeleportFlags.ViaLocation);
4593 }
4594 }
4595 }
4596 }
4597 }
4598
4172 public void llTextBox(string agent, string message, int chatChannel) 4599 public void llTextBox(string agent, string message, int chatChannel)
4173 { 4600 {
4174 IDialogModule dm = World.RequestModuleInterface<IDialogModule>(); 4601 IDialogModule dm = World.RequestModuleInterface<IDialogModule>();
@@ -4180,7 +4607,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4180 UUID av = new UUID(); 4607 UUID av = new UUID();
4181 if (!UUID.TryParse(agent,out av)) 4608 if (!UUID.TryParse(agent,out av))
4182 { 4609 {
4183 LSLError("First parameter to llDialog needs to be a key"); 4610 //LSLError("First parameter to llDialog needs to be a key");
4184 return; 4611 return;
4185 } 4612 }
4186 4613
@@ -4212,25 +4639,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4212 public void llCollisionSound(string impact_sound, double impact_volume) 4639 public void llCollisionSound(string impact_sound, double impact_volume)
4213 { 4640 {
4214 m_host.AddScriptLPS(1); 4641 m_host.AddScriptLPS(1);
4215 4642
4643 if(impact_sound == "")
4644 {
4645 m_host.CollisionSoundVolume = (float)impact_volume;
4646 m_host.CollisionSound = m_host.invalidCollisionSoundUUID;
4647 m_host.CollisionSoundType = 0;
4648 return;
4649 }
4216 // TODO: Parameter check logic required. 4650 // TODO: Parameter check logic required.
4217 UUID soundId = UUID.Zero; 4651 UUID soundId = UUID.Zero;
4218 if (!UUID.TryParse(impact_sound, out soundId)) 4652 if (!UUID.TryParse(impact_sound, out soundId))
4219 { 4653 {
4220 lock (m_host.TaskInventory) 4654 m_host.TaskInventory.LockItemsForRead(true);
4655 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
4221 { 4656 {
4222 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 4657 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound)
4223 { 4658 {
4224 if (item.Type == (int)AssetType.Sound && item.Name == impact_sound) 4659 soundId = item.AssetID;
4225 { 4660 break;
4226 soundId = item.AssetID;
4227 break;
4228 }
4229 } 4661 }
4230 } 4662 }
4663 m_host.TaskInventory.LockItemsForRead(false);
4231 } 4664 }
4232 m_host.CollisionSound = soundId;
4233 m_host.CollisionSoundVolume = (float)impact_volume; 4665 m_host.CollisionSoundVolume = (float)impact_volume;
4666 m_host.CollisionSound = soundId;
4667 m_host.CollisionSoundType = 1;
4234 } 4668 }
4235 4669
4236 public LSL_String llGetAnimation(string id) 4670 public LSL_String llGetAnimation(string id)
@@ -4244,14 +4678,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4244 4678
4245 if (m_host.RegionHandle == presence.RegionHandle) 4679 if (m_host.RegionHandle == presence.RegionHandle)
4246 { 4680 {
4247 Dictionary<UUID, string> animationstateNames = DefaultAvatarAnimations.AnimStateNames;
4248
4249 if (presence != null) 4681 if (presence != null)
4250 { 4682 {
4251 AnimationSet currentAnims = presence.Animator.Animations; 4683 if (presence.SitGround)
4252 string currentAnimationState = String.Empty; 4684 return "Sitting on Ground";
4253 if (animationstateNames.TryGetValue(currentAnims.DefaultAnimation.AnimID, out currentAnimationState)) 4685 if (presence.ParentID != 0 || presence.ParentUUID != UUID.Zero)
4254 return currentAnimationState; 4686 return "Sitting";
4687
4688 string movementAnimation = presence.Animator.CurrentMovementAnimation;
4689 string lslMovementAnimation;
4690
4691 if (MovementAnimationsForLSL.TryGetValue(movementAnimation, out lslMovementAnimation))
4692 return lslMovementAnimation;
4255 } 4693 }
4256 } 4694 }
4257 4695
@@ -4267,6 +4705,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4267 UUID partItemID; 4705 UUID partItemID;
4268 foreach (SceneObjectPart part in parts) 4706 foreach (SceneObjectPart part in parts)
4269 { 4707 {
4708 //Clone is thread safe
4270 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone(); 4709 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone();
4271 4710
4272 foreach (TaskInventoryItem item in itemsDictionary.Values) 4711 foreach (TaskInventoryItem item in itemsDictionary.Values)
@@ -4400,7 +4839,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4400 { 4839 {
4401 float distance = (PusheePos - m_host.AbsolutePosition).Length(); 4840 float distance = (PusheePos - m_host.AbsolutePosition).Length();
4402 float distance_term = distance * distance * distance; // Script Energy 4841 float distance_term = distance * distance * distance; // Script Energy
4403 float pusher_mass = m_host.GetMass(); 4842 // use total object mass and not part
4843 float pusher_mass = m_host.ParentGroup.GetMass();
4404 4844
4405 float PUSH_ATTENUATION_DISTANCE = 17f; 4845 float PUSH_ATTENUATION_DISTANCE = 17f;
4406 float PUSH_ATTENUATION_SCALE = 5f; 4846 float PUSH_ATTENUATION_SCALE = 5f;
@@ -4639,23 +5079,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4639 { 5079 {
4640 m_host.AddScriptLPS(1); 5080 m_host.AddScriptLPS(1);
4641 5081
4642 lock (m_host.TaskInventory) 5082 m_host.TaskInventory.LockItemsForRead(true);
5083 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
4643 { 5084 {
4644 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 5085 if (inv.Value.Name == name)
4645 { 5086 {
4646 if (inv.Value.Name == name) 5087 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify))
4647 { 5088 {
4648 if ((inv.Value.CurrentPermissions & (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) == (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify)) 5089 m_host.TaskInventory.LockItemsForRead(false);
4649 { 5090 return inv.Value.AssetID.ToString();
4650 return inv.Value.AssetID.ToString(); 5091 }
4651 } 5092 else
4652 else 5093 {
4653 { 5094 m_host.TaskInventory.LockItemsForRead(false);
4654 return UUID.Zero.ToString(); 5095 return UUID.Zero.ToString();
4655 }
4656 } 5096 }
4657 } 5097 }
4658 } 5098 }
5099 m_host.TaskInventory.LockItemsForRead(false);
4659 5100
4660 return UUID.Zero.ToString(); 5101 return UUID.Zero.ToString();
4661 } 5102 }
@@ -4789,7 +5230,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4789 public LSL_Vector llGetCenterOfMass() 5230 public LSL_Vector llGetCenterOfMass()
4790 { 5231 {
4791 m_host.AddScriptLPS(1); 5232 m_host.AddScriptLPS(1);
4792 Vector3 center = m_host.GetGeometricCenter(); 5233 Vector3 center = m_host.GetCenterOfMass();
4793 return new LSL_Vector(center.X,center.Y,center.Z); 5234 return new LSL_Vector(center.X,center.Y,center.Z);
4794 } 5235 }
4795 5236
@@ -4808,14 +5249,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4808 { 5249 {
4809 m_host.AddScriptLPS(1); 5250 m_host.AddScriptLPS(1);
4810 5251
4811 if (src == null) 5252 return src.Length;
4812 {
4813 return 0;
4814 }
4815 else
4816 {
4817 return src.Length;
4818 }
4819 } 5253 }
4820 5254
4821 public LSL_Integer llList2Integer(LSL_List src, int index) 5255 public LSL_Integer llList2Integer(LSL_List src, int index)
@@ -4861,7 +5295,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4861 else if (src.Data[index] is LSL_Float) 5295 else if (src.Data[index] is LSL_Float)
4862 return Convert.ToDouble(((LSL_Float) src.Data[index]).value); 5296 return Convert.ToDouble(((LSL_Float) src.Data[index]).value);
4863 else if (src.Data[index] is LSL_String) 5297 else if (src.Data[index] is LSL_String)
4864 return Convert.ToDouble(((LSL_String) src.Data[index]).m_string); 5298 {
5299 string str = ((LSL_String) src.Data[index]).m_string;
5300 Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)");
5301 if (m != Match.Empty)
5302 {
5303 str = m.Value;
5304 double d = 0.0;
5305 if (!Double.TryParse(str, out d))
5306 return 0.0;
5307
5308 return d;
5309 }
5310 return 0.0;
5311 }
4865 return Convert.ToDouble(src.Data[index]); 5312 return Convert.ToDouble(src.Data[index]);
4866 } 5313 }
4867 catch (FormatException) 5314 catch (FormatException)
@@ -5134,7 +5581,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5134 } 5581 }
5135 } 5582 }
5136 } 5583 }
5137 else { 5584 else
5585 {
5138 object[] array = new object[src.Length]; 5586 object[] array = new object[src.Length];
5139 Array.Copy(src.Data, 0, array, 0, src.Length); 5587 Array.Copy(src.Data, 0, array, 0, src.Length);
5140 result = new LSL_List(array); 5588 result = new LSL_List(array);
@@ -5241,7 +5689,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5241 public LSL_Integer llGetRegionAgentCount() 5689 public LSL_Integer llGetRegionAgentCount()
5242 { 5690 {
5243 m_host.AddScriptLPS(1); 5691 m_host.AddScriptLPS(1);
5244 return new LSL_Integer(World.GetRootAgentCount()); 5692
5693 int count = 0;
5694 World.ForEachRootScenePresence(delegate(ScenePresence sp) {
5695 count++;
5696 });
5697
5698 return new LSL_Integer(count);
5245 } 5699 }
5246 5700
5247 public LSL_Vector llGetRegionCorner() 5701 public LSL_Vector llGetRegionCorner()
@@ -5521,6 +5975,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5521 flags |= ScriptBaseClass.AGENT_SITTING; 5975 flags |= ScriptBaseClass.AGENT_SITTING;
5522 } 5976 }
5523 5977
5978 if (agent.Appearance.VisualParams[(int)AvatarAppearance.VPElement.SHAPE_MALE] > 0)
5979 {
5980 flags |= ScriptBaseClass.AGENT_MALE;
5981 }
5982
5524 return flags; 5983 return flags;
5525 } 5984 }
5526 5985
@@ -5667,10 +6126,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5667 m_host.AddScriptLPS(1); 6126 m_host.AddScriptLPS(1);
5668 6127
5669 List<SceneObjectPart> parts = GetLinkParts(linknumber); 6128 List<SceneObjectPart> parts = GetLinkParts(linknumber);
5670 6129 if (parts.Count > 0)
5671 foreach (var part in parts)
5672 { 6130 {
5673 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate); 6131 try
6132 {
6133 parts[0].ParentGroup.areUpdatesSuspended = true;
6134 foreach (var part in parts)
6135 {
6136 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
6137 }
6138 }
6139 finally
6140 {
6141 parts[0].ParentGroup.areUpdatesSuspended = false;
6142 }
5674 } 6143 }
5675 } 6144 }
5676 6145
@@ -5722,13 +6191,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5722 6191
5723 if (m_host.OwnerID == land.LandData.OwnerID) 6192 if (m_host.OwnerID == land.LandData.OwnerID)
5724 { 6193 {
5725 World.TeleportClientHome(agentID, presence.ControllingClient); 6194 Vector3 pos = World.GetNearestAllowedPosition(presence, land);
6195 presence.TeleportWithMomentum(pos, null);
6196 presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
5726 } 6197 }
5727 } 6198 }
5728 } 6199 }
5729 ScriptSleep(5000); 6200 ScriptSleep(5000);
5730 } 6201 }
5731 6202
6203 public LSL_List llParseString2List(string str, LSL_List separators, LSL_List in_spacers)
6204 {
6205 return ParseString2List(str, separators, in_spacers, false);
6206 }
6207
5732 public LSL_Integer llOverMyLand(string id) 6208 public LSL_Integer llOverMyLand(string id)
5733 { 6209 {
5734 m_host.AddScriptLPS(1); 6210 m_host.AddScriptLPS(1);
@@ -5793,8 +6269,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5793 UUID agentId = new UUID(); 6269 UUID agentId = new UUID();
5794 if (!UUID.TryParse(agent, out agentId)) 6270 if (!UUID.TryParse(agent, out agentId))
5795 return new LSL_Integer(0); 6271 return new LSL_Integer(0);
6272 if (agentId == m_host.GroupID)
6273 return new LSL_Integer(1);
5796 ScenePresence presence = World.GetScenePresence(agentId); 6274 ScenePresence presence = World.GetScenePresence(agentId);
5797 if (presence == null || presence.IsChildAgent) // Return flase for child agents 6275 if (presence == null || presence.IsChildAgent) // Return false for child agents
5798 return new LSL_Integer(0); 6276 return new LSL_Integer(0);
5799 IClientAPI client = presence.ControllingClient; 6277 IClientAPI client = presence.ControllingClient;
5800 if (m_host.GroupID == client.ActiveGroupId) 6278 if (m_host.GroupID == client.ActiveGroupId)
@@ -5929,7 +6407,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5929 return m_host.ParentGroup.AttachmentPoint; 6407 return m_host.ParentGroup.AttachmentPoint;
5930 } 6408 }
5931 6409
5932 public LSL_Integer llGetFreeMemory() 6410 public virtual LSL_Integer llGetFreeMemory()
5933 { 6411 {
5934 m_host.AddScriptLPS(1); 6412 m_host.AddScriptLPS(1);
5935 // Make scripts designed for LSO happy 6413 // Make scripts designed for LSO happy
@@ -6046,7 +6524,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6046 SetParticleSystem(m_host, rules); 6524 SetParticleSystem(m_host, rules);
6047 } 6525 }
6048 6526
6049 private void SetParticleSystem(SceneObjectPart part, LSL_List rules) { 6527 private void SetParticleSystem(SceneObjectPart part, LSL_List rules)
6528 {
6050 6529
6051 6530
6052 if (rules.Length == 0) 6531 if (rules.Length == 0)
@@ -6240,14 +6719,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6240 6719
6241 protected UUID GetTaskInventoryItem(string name) 6720 protected UUID GetTaskInventoryItem(string name)
6242 { 6721 {
6243 lock (m_host.TaskInventory) 6722 m_host.TaskInventory.LockItemsForRead(true);
6723 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6244 { 6724 {
6245 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 6725 if (inv.Value.Name == name)
6246 { 6726 {
6247 if (inv.Value.Name == name) 6727 m_host.TaskInventory.LockItemsForRead(false);
6248 return inv.Key; 6728 return inv.Key;
6249 } 6729 }
6250 } 6730 }
6731 m_host.TaskInventory.LockItemsForRead(false);
6251 6732
6252 return UUID.Zero; 6733 return UUID.Zero;
6253 } 6734 }
@@ -6285,16 +6766,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6285 if (folderID == UUID.Zero) 6766 if (folderID == UUID.Zero)
6286 return; 6767 return;
6287 6768
6288 byte[] bucket = new byte[17]; 6769 byte[] bucket = new byte[1];
6289 bucket[0] = (byte)AssetType.Folder; 6770 bucket[0] = (byte)AssetType.Folder;
6290 byte[] objBytes = folderID.GetBytes(); 6771 //byte[] objBytes = folderID.GetBytes();
6291 Array.Copy(objBytes, 0, bucket, 1, 16); 6772 //Array.Copy(objBytes, 0, bucket, 1, 16);
6292 6773
6293 GridInstantMessage msg = new GridInstantMessage(World, 6774 GridInstantMessage msg = new GridInstantMessage(World,
6294 m_host.UUID, m_host.Name+", an object owned by "+ 6775 m_host.OwnerID, m_host.Name, destID,
6295 resolveName(m_host.OwnerID)+",", destID, 6776 (byte)InstantMessageDialog.TaskInventoryOffered,
6296 (byte)InstantMessageDialog.InventoryOffered, 6777 false, category+". "+m_host.Name+" is located at "+
6297 false, category+"\n"+m_host.Name+" is located at "+
6298 World.RegionInfo.RegionName+" "+ 6778 World.RegionInfo.RegionName+" "+
6299 m_host.AbsolutePosition.ToString(), 6779 m_host.AbsolutePosition.ToString(),
6300 folderID, true, m_host.AbsolutePosition, 6780 folderID, true, m_host.AbsolutePosition,
@@ -6532,13 +7012,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6532 UUID av = new UUID(); 7012 UUID av = new UUID();
6533 if (!UUID.TryParse(avatar,out av)) 7013 if (!UUID.TryParse(avatar,out av))
6534 { 7014 {
6535 LSLError("First parameter to llDialog needs to be a key"); 7015 //LSLError("First parameter to llDialog needs to be a key");
6536 return; 7016 return;
6537 } 7017 }
6538 if (buttons.Length < 1) 7018 if (buttons.Length < 1)
6539 { 7019 {
6540 LSLError("No less than 1 button can be shown"); 7020 buttons.Add("OK");
6541 return;
6542 } 7021 }
6543 if (buttons.Length > 12) 7022 if (buttons.Length > 12)
6544 { 7023 {
@@ -6555,7 +7034,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6555 } 7034 }
6556 if (buttons.Data[i].ToString().Length > 24) 7035 if (buttons.Data[i].ToString().Length > 24)
6557 { 7036 {
6558 LSLError("button label cannot be longer than 24 characters"); 7037 llWhisper(ScriptBaseClass.DEBUG_CHANNEL, "button label cannot be longer than 24 characters");
6559 return; 7038 return;
6560 } 7039 }
6561 buts[i] = buttons.Data[i].ToString(); 7040 buts[i] = buttons.Data[i].ToString();
@@ -6614,22 +7093,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6614 } 7093 }
6615 7094
6616 // copy the first script found with this inventory name 7095 // copy the first script found with this inventory name
6617 lock (m_host.TaskInventory) 7096 TaskInventoryItem scriptItem = null;
7097 m_host.TaskInventory.LockItemsForRead(true);
7098 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
6618 { 7099 {
6619 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 7100 if (inv.Value.Name == name)
6620 { 7101 {
6621 if (inv.Value.Name == name) 7102 // make sure the object is a script
7103 if (10 == inv.Value.Type)
6622 { 7104 {
6623 // make sure the object is a script 7105 found = true;
6624 if (10 == inv.Value.Type) 7106 srcId = inv.Key;
6625 { 7107 scriptItem = inv.Value;
6626 found = true; 7108 break;
6627 srcId = inv.Key;
6628 break;
6629 }
6630 } 7109 }
6631 } 7110 }
6632 } 7111 }
7112 m_host.TaskInventory.LockItemsForRead(false);
6633 7113
6634 if (!found) 7114 if (!found)
6635 { 7115 {
@@ -6637,9 +7117,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6637 return; 7117 return;
6638 } 7118 }
6639 7119
6640 // the rest of the permission checks are done in RezScript, so check the pin there as well 7120 SceneObjectPart dest = World.GetSceneObjectPart(destId);
6641 World.RezScriptFromPrim(srcId, m_host, destId, pin, running, start_param); 7121 if (dest != null)
7122 {
7123 if ((scriptItem.BasePermissions & (uint)PermissionMask.Transfer) != 0 || dest.ParentGroup.RootPart.OwnerID == m_host.ParentGroup.RootPart.OwnerID)
7124 {
7125 // the rest of the permission checks are done in RezScript, so check the pin there as well
7126 World.RezScriptFromPrim(srcId, m_host, destId, pin, running, start_param);
6642 7127
7128 if ((scriptItem.BasePermissions & (uint)PermissionMask.Copy) == 0)
7129 m_host.Inventory.RemoveInventoryItem(srcId);
7130 }
7131 }
6643 // this will cause the delay even if the script pin or permissions were wrong - seems ok 7132 // this will cause the delay even if the script pin or permissions were wrong - seems ok
6644 ScriptSleep(3000); 7133 ScriptSleep(3000);
6645 } 7134 }
@@ -6702,19 +7191,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6702 public LSL_String llMD5String(string src, int nonce) 7191 public LSL_String llMD5String(string src, int nonce)
6703 { 7192 {
6704 m_host.AddScriptLPS(1); 7193 m_host.AddScriptLPS(1);
6705 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString())); 7194 return Util.Md5Hash(String.Format("{0}:{1}", src, nonce.ToString()), Encoding.UTF8);
6706 } 7195 }
6707 7196
6708 public LSL_String llSHA1String(string src) 7197 public LSL_String llSHA1String(string src)
6709 { 7198 {
6710 m_host.AddScriptLPS(1); 7199 m_host.AddScriptLPS(1);
6711 return Util.SHA1Hash(src).ToLower(); 7200 return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
6712 } 7201 }
6713 7202
6714 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve) 7203 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
6715 { 7204 {
6716 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7205 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
6717 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7206 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
7207 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7208 return shapeBlock;
6718 7209
6719 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT && 7210 if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
6720 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE && 7211 holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
@@ -6819,6 +7310,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6819 // Prim type box, cylinder and prism. 7310 // Prim type box, cylinder and prism.
6820 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) 7311 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)
6821 { 7312 {
7313 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7314 return;
7315
6822 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7316 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
6823 ObjectShapePacket.ObjectDataBlock shapeBlock; 7317 ObjectShapePacket.ObjectDataBlock shapeBlock;
6824 7318
@@ -6872,6 +7366,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6872 // Prim type sphere. 7366 // Prim type sphere.
6873 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve) 7367 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
6874 { 7368 {
7369 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7370 return;
7371
6875 ObjectShapePacket.ObjectDataBlock shapeBlock; 7372 ObjectShapePacket.ObjectDataBlock shapeBlock;
6876 7373
6877 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve); 7374 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
@@ -6913,6 +7410,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6913 // Prim type torus, tube and ring. 7410 // Prim type torus, tube and ring.
6914 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) 7411 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)
6915 { 7412 {
7413 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7414 return;
7415
6916 float tempFloat; // Use in float expressions below to avoid byte cast precision issues. 7416 float tempFloat; // Use in float expressions below to avoid byte cast precision issues.
6917 ObjectShapePacket.ObjectDataBlock shapeBlock; 7417 ObjectShapePacket.ObjectDataBlock shapeBlock;
6918 7418
@@ -7048,6 +7548,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7048 // Prim type sculpt. 7548 // Prim type sculpt.
7049 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve) 7549 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
7050 { 7550 {
7551 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7552 return;
7553
7051 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7554 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
7052 UUID sculptId; 7555 UUID sculptId;
7053 7556
@@ -7072,7 +7575,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7072 type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag)) 7575 type != (ScriptBaseClass.PRIM_SCULPT_TYPE_TORUS | flag))
7073 { 7576 {
7074 // default 7577 // default
7075 type = (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; 7578 type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
7076 } 7579 }
7077 7580
7078 part.Shape.SetSculptProperties((byte)type, sculptId); 7581 part.Shape.SetSculptProperties((byte)type, sculptId);
@@ -7088,32 +7591,149 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7088 ScriptSleep(200); 7591 ScriptSleep(200);
7089 } 7592 }
7090 7593
7091 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) 7594 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules)
7092 { 7595 {
7093 m_host.AddScriptLPS(1); 7596 m_host.AddScriptLPS(1);
7094 7597
7095 setLinkPrimParams(linknumber, rules); 7598 setLinkPrimParams(linknumber, rules);
7599 }
7096 7600
7097 ScriptSleep(200); 7601 private void setLinkPrimParams(int linknumber, LSL_List rules)
7602 {
7603 List<SceneObjectPart> parts = GetLinkParts(linknumber);
7604 List<ScenePresence> avatars = GetLinkAvatars(linknumber);
7605 if (parts.Count>0)
7606 {
7607 try
7608 {
7609 parts[0].ParentGroup.areUpdatesSuspended = true;
7610 foreach (SceneObjectPart part in parts)
7611 SetPrimParams(part, rules);
7612 }
7613 finally
7614 {
7615 parts[0].ParentGroup.areUpdatesSuspended = false;
7616 }
7617 }
7618 if (avatars.Count > 0)
7619 {
7620 foreach (ScenePresence avatar in avatars)
7621 SetPrimParams(avatar, rules);
7622 }
7098 } 7623 }
7099 7624
7100 public void llSetLinkPrimitiveParamsFast(int linknumber, LSL_List rules) 7625 private void SetPhysicsMaterial(SceneObjectPart part, int material_bits,
7626 float material_density, float material_friction,
7627 float material_restitution, float material_gravity_modifier)
7101 { 7628 {
7102 m_host.AddScriptLPS(1); 7629 ExtraPhysicsData physdata = new ExtraPhysicsData();
7630 physdata.PhysShapeType = (PhysShapeType)part.PhysicsShapeType;
7631 physdata.Density = part.Density;
7632 physdata.Friction = part.Friction;
7633 physdata.Bounce = part.Bounciness;
7634 physdata.GravitationModifier = part.GravityModifier;
7103 7635
7104 setLinkPrimParams(linknumber, rules); 7636 if ((material_bits & (int)ScriptBaseClass.DENSITY) != 0)
7637 physdata.Density = material_density;
7638 if ((material_bits & (int)ScriptBaseClass.FRICTION) != 0)
7639 physdata.Friction = material_friction;
7640 if ((material_bits & (int)ScriptBaseClass.RESTITUTION) != 0)
7641 physdata.Bounce = material_restitution;
7642 if ((material_bits & (int)ScriptBaseClass.GRAVITY_MULTIPLIER) != 0)
7643 physdata.GravitationModifier = material_gravity_modifier;
7644
7645 part.UpdateExtraPhysics(physdata);
7105 } 7646 }
7106 7647
7107 protected void setLinkPrimParams(int linknumber, LSL_List rules) 7648 public void llSetPhysicsMaterial(int material_bits,
7649 float material_gravity_modifier, float material_restitution,
7650 float material_friction, float material_density)
7108 { 7651 {
7109 List<SceneObjectPart> parts = GetLinkParts(linknumber); 7652 SetPhysicsMaterial(m_host, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
7653 }
7110 7654
7111 foreach (SceneObjectPart part in parts) 7655 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
7112 SetPrimParams(part, rules); 7656 {
7657 llSetLinkPrimitiveParamsFast(linknumber, rules);
7658 ScriptSleep(200);
7659 }
7660
7661 protected void SetPrimParams(ScenePresence av, LSL_List rules)
7662 {
7663 //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
7664 //We only support PRIM_POSITION and PRIM_ROTATION
7665
7666 int idx = 0;
7667
7668 while (idx < rules.Length)
7669 {
7670 int code = rules.GetLSLIntegerItem(idx++);
7671
7672 int remain = rules.Length - idx;
7673
7674 switch (code)
7675 {
7676 case (int)ScriptBaseClass.PRIM_POSITION:
7677 {
7678 if (remain < 1)
7679 return;
7680 LSL_Vector v;
7681 v = rules.GetVector3Item(idx++);
7682
7683 SceneObjectPart part = World.GetSceneObjectPart(av.ParentID);
7684 if (part == null)
7685 break;
7686
7687 LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION;
7688 LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR;
7689 if (llGetLinkNumber() > 1)
7690 {
7691 localRot = llGetLocalRot();
7692 localPos = llGetLocalPos();
7693 }
7694
7695 v -= localPos;
7696 v /= localRot;
7697
7698 LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
7699
7700 v = v + 2 * sitOffset;
7701
7702 av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
7703 av.SendAvatarDataToAllAgents();
7704
7705 }
7706 break;
7707
7708 case (int)ScriptBaseClass.PRIM_ROTATION:
7709 {
7710 if (remain < 1)
7711 return;
7712
7713 LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION;
7714 LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR;
7715 if (llGetLinkNumber() > 1)
7716 {
7717 localRot = llGetLocalRot();
7718 localPos = llGetLocalPos();
7719 }
7720
7721 LSL_Rotation r;
7722 r = rules.GetQuaternionItem(idx++);
7723 r = r * llGetRootRotation() / localRot;
7724 av.Rotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
7725 av.SendAvatarDataToAllAgents();
7726 }
7727 break;
7728 }
7729 }
7113 } 7730 }
7114 7731
7115 protected void SetPrimParams(SceneObjectPart part, LSL_List rules) 7732 protected void SetPrimParams(SceneObjectPart part, LSL_List rules)
7116 { 7733 {
7734 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7735 return;
7736
7117 int idx = 0; 7737 int idx = 0;
7118 7738
7119 bool positionChanged = false; 7739 bool positionChanged = false;
@@ -7435,6 +8055,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7435 part.ScriptSetPhysicsStatus(physics); 8055 part.ScriptSetPhysicsStatus(physics);
7436 break; 8056 break;
7437 8057
8058 case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
8059 if (remain < 1)
8060 return;
8061
8062 int shape_type = rules.GetLSLIntegerItem(idx++);
8063
8064 ExtraPhysicsData physdata = new ExtraPhysicsData();
8065 physdata.Density = part.Density;
8066 physdata.Bounce = part.Bounciness;
8067 physdata.GravitationModifier = part.GravityModifier;
8068 physdata.PhysShapeType = (PhysShapeType)shape_type;
8069
8070 part.UpdateExtraPhysics(physdata);
8071
8072 break;
8073
8074 case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
8075 if (remain < 5)
8076 return;
8077
8078 int material_bits = rules.GetLSLIntegerItem(idx++);
8079 float material_density = (float)rules.GetLSLFloatItem(idx++);
8080 float material_friction = (float)rules.GetLSLFloatItem(idx++);
8081 float material_restitution = (float)rules.GetLSLFloatItem(idx++);
8082 float material_gravity_modifier = (float)rules.GetLSLFloatItem(idx++);
8083
8084 SetPhysicsMaterial(part, material_bits, material_density, material_friction, material_restitution, material_gravity_modifier);
8085
8086 break;
8087
7438 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ: 8088 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
7439 if (remain < 1) 8089 if (remain < 1)
7440 return; 8090 return;
@@ -7508,7 +8158,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7508 if (part.ParentGroup.RootPart == part) 8158 if (part.ParentGroup.RootPart == part)
7509 { 8159 {
7510 SceneObjectGroup parent = part.ParentGroup; 8160 SceneObjectGroup parent = part.ParentGroup;
7511 parent.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z)); 8161 Util.FireAndForget(delegate(object x) {
8162 parent.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z));
8163 });
7512 } 8164 }
7513 else 8165 else
7514 { 8166 {
@@ -7519,6 +8171,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7519 } 8171 }
7520 } 8172 }
7521 } 8173 }
8174
8175 if (positionChanged)
8176 {
8177 if (part.ParentGroup.RootPart == part)
8178 {
8179 SceneObjectGroup parent = part.ParentGroup;
8180 Util.FireAndForget(delegate(object x) {
8181 parent.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z));
8182 });
8183 }
8184 else
8185 {
8186 part.OffsetPosition = new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z);
8187 SceneObjectGroup parent = part.ParentGroup;
8188 parent.HasGroupChanged = true;
8189 parent.ScheduleGroupForTerseUpdate();
8190 }
8191 }
7522 } 8192 }
7523 8193
7524 public LSL_String llStringToBase64(string str) 8194 public LSL_String llStringToBase64(string str)
@@ -7679,13 +8349,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7679 public LSL_Integer llGetNumberOfPrims() 8349 public LSL_Integer llGetNumberOfPrims()
7680 { 8350 {
7681 m_host.AddScriptLPS(1); 8351 m_host.AddScriptLPS(1);
7682 int avatarCount = 0; 8352 int avatarCount = m_host.ParentGroup.GetLinkedAvatars().Count;
7683 World.ForEachRootScenePresence(delegate(ScenePresence presence) 8353
7684 {
7685 if (presence.ParentID != 0 && m_host.ParentGroup.ContainsPart(presence.ParentID))
7686 avatarCount++;
7687 });
7688
7689 return m_host.ParentGroup.PrimCount + avatarCount; 8354 return m_host.ParentGroup.PrimCount + avatarCount;
7690 } 8355 }
7691 8356
@@ -7701,55 +8366,98 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7701 m_host.AddScriptLPS(1); 8366 m_host.AddScriptLPS(1);
7702 UUID objID = UUID.Zero; 8367 UUID objID = UUID.Zero;
7703 LSL_List result = new LSL_List(); 8368 LSL_List result = new LSL_List();
8369
8370 // If the ID is not valid, return null result
7704 if (!UUID.TryParse(obj, out objID)) 8371 if (!UUID.TryParse(obj, out objID))
7705 { 8372 {
7706 result.Add(new LSL_Vector()); 8373 result.Add(new LSL_Vector());
7707 result.Add(new LSL_Vector()); 8374 result.Add(new LSL_Vector());
7708 return result; 8375 return result;
7709 } 8376 }
8377
8378 // Check if this is an attached prim. If so, replace
8379 // the UUID with the avatar UUID and report it's bounding box
8380 SceneObjectPart part = World.GetSceneObjectPart(objID);
8381 if (part != null && part.ParentGroup.IsAttachment)
8382 objID = part.ParentGroup.AttachedAvatar;
8383
8384 // Find out if this is an avatar ID. If so, return it's box
7710 ScenePresence presence = World.GetScenePresence(objID); 8385 ScenePresence presence = World.GetScenePresence(objID);
7711 if (presence != null) 8386 if (presence != null)
7712 { 8387 {
7713 if (presence.ParentID == 0) // not sat on an object 8388 // As per LSL Wiki, there is no difference between sitting
8389 // and standing avatar since server 1.36
8390 LSL_Vector lower;
8391 LSL_Vector upper;
8392 if (presence.Animator.Animations.DefaultAnimation.AnimID
8393 == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
7714 { 8394 {
7715 LSL_Vector lower; 8395 // This is for ground sitting avatars
7716 LSL_Vector upper; 8396 float height = presence.Appearance.AvatarHeight / 2.66666667f;
7717 if (presence.Animator.Animations.DefaultAnimation.AnimID 8397 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
7718 == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) 8398 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
7719 {
7720 // This is for ground sitting avatars
7721 float height = presence.Appearance.AvatarHeight / 2.66666667f;
7722 lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
7723 upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
7724 }
7725 else
7726 {
7727 // This is for standing/flying avatars
7728 float height = presence.Appearance.AvatarHeight / 2.0f;
7729 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
7730 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
7731 }
7732 result.Add(lower);
7733 result.Add(upper);
7734 return result;
7735 } 8399 }
7736 else 8400 else
7737 { 8401 {
7738 // sitting on an object so we need the bounding box of that 8402 // This is for standing/flying avatars
7739 // which should include the avatar so set the UUID to the 8403 float height = presence.Appearance.AvatarHeight / 2.0f;
7740 // UUID of the object the avatar is sat on and allow it to fall through 8404 lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
7741 // to processing an object 8405 upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
7742 SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
7743 objID = p.UUID;
7744 } 8406 }
8407
8408 // Adjust to the documented error offsets (see LSL Wiki)
8409 lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
8410 upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
8411
8412 if (lower.x > upper.x)
8413 lower.x = upper.x;
8414 if (lower.y > upper.y)
8415 lower.y = upper.y;
8416 if (lower.z > upper.z)
8417 lower.z = upper.z;
8418
8419 result.Add(lower);
8420 result.Add(upper);
8421 return result;
7745 } 8422 }
7746 SceneObjectPart part = World.GetSceneObjectPart(objID); 8423
8424 part = World.GetSceneObjectPart(objID);
7747 // Currently only works for single prims without a sitting avatar 8425 // Currently only works for single prims without a sitting avatar
7748 if (part != null) 8426 if (part != null)
7749 { 8427 {
7750 Vector3 halfSize = part.Scale / 2.0f; 8428 float minX;
7751 LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f); 8429 float maxX;
7752 LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z); 8430 float minY;
8431 float maxY;
8432 float minZ;
8433 float maxZ;
8434
8435 // This BBox is in sim coordinates, with the offset being
8436 // a contained point.
8437 Vector3[] offsets = Scene.GetCombinedBoundingBox(new List<SceneObjectGroup> { part.ParentGroup },
8438 out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
8439
8440 minX -= offsets[0].X;
8441 maxX -= offsets[0].X;
8442 minY -= offsets[0].Y;
8443 maxY -= offsets[0].Y;
8444 minZ -= offsets[0].Z;
8445 maxZ -= offsets[0].Z;
8446
8447 LSL_Vector lower;
8448 LSL_Vector upper;
8449
8450 // Adjust to the documented error offsets (see LSL Wiki)
8451 lower = new LSL_Vector(minX + 0.05f, minY + 0.05f, minZ + 0.05f);
8452 upper = new LSL_Vector(maxX - 0.05f, maxY - 0.05f, maxZ - 0.05f);
8453
8454 if (lower.x > upper.x)
8455 lower.x = upper.x;
8456 if (lower.y > upper.y)
8457 lower.y = upper.y;
8458 if (lower.z > upper.z)
8459 lower.z = upper.z;
8460
7753 result.Add(lower); 8461 result.Add(lower);
7754 result.Add(upper); 8462 result.Add(upper);
7755 return result; 8463 return result;
@@ -7763,7 +8471,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7763 8471
7764 public LSL_Vector llGetGeometricCenter() 8472 public LSL_Vector llGetGeometricCenter()
7765 { 8473 {
7766 return new LSL_Vector(m_host.GetGeometricCenter().X, m_host.GetGeometricCenter().Y, m_host.GetGeometricCenter().Z); 8474 Vector3 tmp = m_host.GetGeometricCenter();
8475 return new LSL_Vector(tmp.X, tmp.Y, tmp.Z);
7767 } 8476 }
7768 8477
7769 public LSL_List llGetPrimitiveParams(LSL_List rules) 8478 public LSL_List llGetPrimitiveParams(LSL_List rules)
@@ -7829,13 +8538,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7829 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X, 8538 LSL_Vector v = new LSL_Vector(part.AbsolutePosition.X,
7830 part.AbsolutePosition.Y, 8539 part.AbsolutePosition.Y,
7831 part.AbsolutePosition.Z); 8540 part.AbsolutePosition.Z);
7832 // For some reason, the part.AbsolutePosition.* values do not change if the
7833 // linkset is rotated; they always reflect the child prim's world position
7834 // as though the linkset is unrotated. This is incompatible behavior with SL's
7835 // implementation, so will break scripts imported from there (not to mention it
7836 // makes it more difficult to determine a child prim's actual inworld position).
7837 if (part.ParentID != 0)
7838 v = ((v - llGetRootPosition()) * llGetRootRotation()) + llGetRootPosition();
7839 res.Add(v); 8541 res.Add(v);
7840 break; 8542 break;
7841 8543
@@ -8006,56 +8708,92 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8006 case (int)ScriptBaseClass.PRIM_BUMP_SHINY: 8708 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
8007 if (remain < 1) 8709 if (remain < 1)
8008 return res; 8710 return res;
8009 8711 face = (int)rules.GetLSLIntegerItem(idx++);
8010 face=(int)rules.GetLSLIntegerItem(idx++);
8011 8712
8012 tex = part.Shape.Textures; 8713 tex = part.Shape.Textures;
8714 int shiny;
8013 if (face == ScriptBaseClass.ALL_SIDES) 8715 if (face == ScriptBaseClass.ALL_SIDES)
8014 { 8716 {
8015 for (face = 0; face < GetNumberOfSides(part); face++) 8717 for (face = 0; face < GetNumberOfSides(part); face++)
8016 { 8718 {
8017 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8719 Shininess shinyness = tex.GetFace((uint)face).Shiny;
8018 // Convert Shininess to PRIM_SHINY_* 8720 if (shinyness == Shininess.High)
8019 res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); 8721 {
8020 // PRIM_BUMP_* 8722 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
8021 res.Add(new LSL_Integer((int)texface.Bump)); 8723 }
8724 else if (shinyness == Shininess.Medium)
8725 {
8726 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8727 }
8728 else if (shinyness == Shininess.Low)
8729 {
8730 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8731 }
8732 else
8733 {
8734 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8735 }
8736 res.Add(new LSL_Integer(shiny));
8737 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
8022 } 8738 }
8023 } 8739 }
8024 else 8740 else
8025 { 8741 {
8026 if (face >= 0 && face < GetNumberOfSides(part)) 8742 Shininess shinyness = tex.GetFace((uint)face).Shiny;
8743 if (shinyness == Shininess.High)
8027 { 8744 {
8028 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8745 shiny = ScriptBaseClass.PRIM_SHINY_HIGH;
8029 // Convert Shininess to PRIM_SHINY_* 8746 }
8030 res.Add(new LSL_Integer((uint)texface.Shiny >> 6)); 8747 else if (shinyness == Shininess.Medium)
8031 // PRIM_BUMP_* 8748 {
8032 res.Add(new LSL_Integer((int)texface.Bump)); 8749 shiny = ScriptBaseClass.PRIM_SHINY_MEDIUM;
8033 } 8750 }
8751 else if (shinyness == Shininess.Low)
8752 {
8753 shiny = ScriptBaseClass.PRIM_SHINY_LOW;
8754 }
8755 else
8756 {
8757 shiny = ScriptBaseClass.PRIM_SHINY_NONE;
8758 }
8759 res.Add(new LSL_Integer(shiny));
8760 res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
8034 } 8761 }
8035 break; 8762 break;
8036 8763
8037 case (int)ScriptBaseClass.PRIM_FULLBRIGHT: 8764 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
8038 if (remain < 1) 8765 if (remain < 1)
8039 return res; 8766 return res;
8040 8767 face = (int)rules.GetLSLIntegerItem(idx++);
8041 face=(int)rules.GetLSLIntegerItem(idx++);
8042 8768
8043 tex = part.Shape.Textures; 8769 tex = part.Shape.Textures;
8770 int fullbright;
8044 if (face == ScriptBaseClass.ALL_SIDES) 8771 if (face == ScriptBaseClass.ALL_SIDES)
8045 { 8772 {
8046 for (face = 0; face < GetNumberOfSides(part); face++) 8773 for (face = 0; face < GetNumberOfSides(part); face++)
8047 { 8774 {
8048 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8775 if (tex.GetFace((uint)face).Fullbright == true)
8049 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); 8776 {
8777 fullbright = ScriptBaseClass.TRUE;
8778 }
8779 else
8780 {
8781 fullbright = ScriptBaseClass.FALSE;
8782 }
8783 res.Add(new LSL_Integer(fullbright));
8050 } 8784 }
8051 } 8785 }
8052 else 8786 else
8053 { 8787 {
8054 if (face >= 0 && face < GetNumberOfSides(part)) 8788 if (tex.GetFace((uint)face).Fullbright == true)
8055 { 8789 {
8056 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8790 fullbright = ScriptBaseClass.TRUE;
8057 res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
8058 } 8791 }
8792 else
8793 {
8794 fullbright = ScriptBaseClass.FALSE;
8795 }
8796 res.Add(new LSL_Integer(fullbright));
8059 } 8797 }
8060 break; 8798 break;
8061 8799
@@ -8077,27 +8815,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8077 break; 8815 break;
8078 8816
8079 case (int)ScriptBaseClass.PRIM_TEXGEN: 8817 case (int)ScriptBaseClass.PRIM_TEXGEN:
8818 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
8080 if (remain < 1) 8819 if (remain < 1)
8081 return res; 8820 return res;
8082 8821 face = (int)rules.GetLSLIntegerItem(idx++);
8083 face=(int)rules.GetLSLIntegerItem(idx++);
8084 8822
8085 tex = part.Shape.Textures; 8823 tex = part.Shape.Textures;
8086 if (face == ScriptBaseClass.ALL_SIDES) 8824 if (face == ScriptBaseClass.ALL_SIDES)
8087 { 8825 {
8088 for (face = 0; face < GetNumberOfSides(part); face++) 8826 for (face = 0; face < GetNumberOfSides(part); face++)
8089 { 8827 {
8090 MappingType texgen = tex.GetFace((uint)face).TexMapType; 8828 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8091 // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc. 8829 {
8092 res.Add(new LSL_Integer((uint)texgen >> 1)); 8830 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8831 }
8832 else
8833 {
8834 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8835 }
8093 } 8836 }
8094 } 8837 }
8095 else 8838 else
8096 { 8839 {
8097 if (face >= 0 && face < GetNumberOfSides(part)) 8840 if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
8841 {
8842 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_PLANAR));
8843 }
8844 else
8098 { 8845 {
8099 MappingType texgen = tex.GetFace((uint)face).TexMapType; 8846 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
8100 res.Add(new LSL_Integer((uint)texgen >> 1));
8101 } 8847 }
8102 } 8848 }
8103 break; 8849 break;
@@ -8120,28 +8866,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8120 case (int)ScriptBaseClass.PRIM_GLOW: 8866 case (int)ScriptBaseClass.PRIM_GLOW:
8121 if (remain < 1) 8867 if (remain < 1)
8122 return res; 8868 return res;
8123 8869 face = (int)rules.GetLSLIntegerItem(idx++);
8124 face=(int)rules.GetLSLIntegerItem(idx++);
8125 8870
8126 tex = part.Shape.Textures; 8871 tex = part.Shape.Textures;
8872 float primglow;
8127 if (face == ScriptBaseClass.ALL_SIDES) 8873 if (face == ScriptBaseClass.ALL_SIDES)
8128 { 8874 {
8129 for (face = 0; face < GetNumberOfSides(part); face++) 8875 for (face = 0; face < GetNumberOfSides(part); face++)
8130 { 8876 {
8131 Primitive.TextureEntryFace texface = tex.GetFace((uint)face); 8877 primglow = tex.GetFace((uint)face).Glow;
8132 res.Add(new LSL_Float(texface.Glow)); 8878 res.Add(new LSL_Float(primglow));
8133 } 8879 }
8134 } 8880 }
8135 else 8881 else
8136 { 8882 {
8137 if (face >= 0 && face < GetNumberOfSides(part)) 8883 primglow = tex.GetFace((uint)face).Glow;
8138 { 8884 res.Add(new LSL_Float(primglow));
8139 Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
8140 res.Add(new LSL_Float(texface.Glow));
8141 }
8142 } 8885 }
8143 break; 8886 break;
8144
8145 case (int)ScriptBaseClass.PRIM_TEXT: 8887 case (int)ScriptBaseClass.PRIM_TEXT:
8146 Color4 textColor = part.GetTextColor(); 8888 Color4 textColor = part.GetTextColor();
8147 res.Add(new LSL_String(part.Text)); 8889 res.Add(new LSL_String(part.Text));
@@ -8754,8 +9496,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8754 // The function returns an ordered list 9496 // The function returns an ordered list
8755 // representing the tokens found in the supplied 9497 // representing the tokens found in the supplied
8756 // sources string. If two successive tokenizers 9498 // sources string. If two successive tokenizers
8757 // are encountered, then a NULL entry is added 9499 // are encountered, then a null-string entry is
8758 // to the list. 9500 // added to the list.
8759 // 9501 //
8760 // It is a precondition that the source and 9502 // It is a precondition that the source and
8761 // toekizer lisst are non-null. If they are null, 9503 // toekizer lisst are non-null. If they are null,
@@ -8763,7 +9505,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8763 // while their lengths are being determined. 9505 // while their lengths are being determined.
8764 // 9506 //
8765 // A small amount of working memoryis required 9507 // A small amount of working memoryis required
8766 // of approximately 8*#tokenizers. 9508 // of approximately 8*#tokenizers + 8*srcstrlen.
8767 // 9509 //
8768 // There are many ways in which this function 9510 // There are many ways in which this function
8769 // can be implemented, this implementation is 9511 // can be implemented, this implementation is
@@ -8779,155 +9521,124 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8779 // and eliminates redundant tokenizers as soon 9521 // and eliminates redundant tokenizers as soon
8780 // as is possible. 9522 // as is possible.
8781 // 9523 //
8782 // The implementation tries to avoid any copying 9524 // The implementation tries to minimize temporary
8783 // of arrays or other objects. 9525 // garbage generation.
8784 // </remarks> 9526 // </remarks>
8785 9527
8786 private LSL_List ParseString(string src, LSL_List separators, LSL_List spacers, bool keepNulls) 9528 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
8787 { 9529 {
8788 int beginning = 0; 9530 return ParseString2List(src, separators, spacers, true);
8789 int srclen = src.Length; 9531 }
8790 int seplen = separators.Length;
8791 object[] separray = separators.Data;
8792 int spclen = spacers.Length;
8793 object[] spcarray = spacers.Data;
8794 int mlen = seplen+spclen;
8795
8796 int[] offset = new int[mlen+1];
8797 bool[] active = new bool[mlen];
8798
8799 int best;
8800 int j;
8801
8802 // Initial capacity reduces resize cost
8803 9532
8804 LSL_List tokens = new LSL_List(); 9533 private LSL_List ParseString2List(string src, LSL_List separators, LSL_List spacers, bool keepNulls)
9534 {
9535 int srclen = src.Length;
9536 int seplen = separators.Length;
9537 object[] separray = separators.Data;
9538 int spclen = spacers.Length;
9539 object[] spcarray = spacers.Data;
9540 int dellen = 0;
9541 string[] delarray = new string[seplen+spclen];
8805 9542
8806 // All entries are initially valid 9543 int outlen = 0;
9544 string[] outarray = new string[srclen*2+1];
8807 9545
8808 for (int i = 0; i < mlen; i++) 9546 int i, j;
8809 active[i] = true; 9547 string d;
8810 9548
8811 offset[mlen] = srclen; 9549 m_host.AddScriptLPS(1);
8812 9550
8813 while (beginning < srclen) 9551 /*
9552 * Convert separator and spacer lists to C# strings.
9553 * Also filter out null strings so we don't hang.
9554 */
9555 for (i = 0; i < seplen; i ++)
8814 { 9556 {
9557 d = separray[i].ToString();
9558 if (d.Length > 0)
9559 {
9560 delarray[dellen++] = d;
9561 }
9562 }
9563 seplen = dellen;
8815 9564
8816 best = mlen; // as bad as it gets 9565 for (i = 0; i < spclen; i ++)
9566 {
9567 d = spcarray[i].ToString();
9568 if (d.Length > 0)
9569 {
9570 delarray[dellen++] = d;
9571 }
9572 }
8817 9573
8818 // Scan for separators 9574 /*
9575 * Scan through source string from beginning to end.
9576 */
9577 for (i = 0;;)
9578 {
8819 9579
8820 for (j = 0; j < seplen; j++) 9580 /*
9581 * Find earliest delimeter in src starting at i (if any).
9582 */
9583 int earliestDel = -1;
9584 int earliestSrc = srclen;
9585 string earliestStr = null;
9586 for (j = 0; j < dellen; j ++)
8821 { 9587 {
8822 if (separray[j].ToString() == String.Empty) 9588 d = delarray[j];
8823 active[j] = false; 9589 if (d != null)
8824
8825 if (active[j])
8826 { 9590 {
8827 // scan all of the markers 9591 int index = src.IndexOf(d, i);
8828 if ((offset[j] = src.IndexOf(separray[j].ToString(), beginning)) == -1) 9592 if (index < 0)
8829 { 9593 {
8830 // not present at all 9594 delarray[j] = null; // delim nowhere in src, don't check it anymore
8831 active[j] = false;
8832 } 9595 }
8833 else 9596 else if (index < earliestSrc)
8834 { 9597 {
8835 // present and correct 9598 earliestSrc = index; // where delimeter starts in source string
8836 if (offset[j] < offset[best]) 9599 earliestDel = j; // where delimeter is in delarray[]
8837 { 9600 earliestStr = d; // the delimeter string from delarray[]
8838 // closest so far 9601 if (index == i) break; // can't do any better than found at beg of string
8839 best = j;
8840 if (offset[best] == beginning)
8841 break;
8842 }
8843 } 9602 }
8844 } 9603 }
8845 } 9604 }
8846 9605
8847 // Scan for spacers 9606 /*
8848 9607 * Output source string starting at i through start of earliest delimeter.
8849 if (offset[best] != beginning) 9608 */
9609 if (keepNulls || (earliestSrc > i))
8850 { 9610 {
8851 for (j = seplen; (j < mlen) && (offset[best] > beginning); j++) 9611 outarray[outlen++] = src.Substring(i, earliestSrc - i);
8852 {
8853 if (spcarray[j-seplen].ToString() == String.Empty)
8854 active[j] = false;
8855
8856 if (active[j])
8857 {
8858 // scan all of the markers
8859 if ((offset[j] = src.IndexOf(spcarray[j-seplen].ToString(), beginning)) == -1)
8860 {
8861 // not present at all
8862 active[j] = false;
8863 }
8864 else
8865 {
8866 // present and correct
8867 if (offset[j] < offset[best])
8868 {
8869 // closest so far
8870 best = j;
8871 }
8872 }
8873 }
8874 }
8875 } 9612 }
8876 9613
8877 // This is the normal exit from the scanning loop 9614 /*
9615 * If no delimeter found at or after i, we're done scanning.
9616 */
9617 if (earliestDel < 0) break;
8878 9618
8879 if (best == mlen) 9619 /*
9620 * If delimeter was a spacer, output the spacer.
9621 */
9622 if (earliestDel >= seplen)
8880 { 9623 {
8881 // no markers were found on this pass 9624 outarray[outlen++] = earliestStr;
8882 // so we're pretty much done
8883 if ((keepNulls) || ((!keepNulls) && (srclen - beginning) > 0))
8884 tokens.Add(new LSL_String(src.Substring(beginning, srclen - beginning)));
8885 break;
8886 } 9625 }
8887 9626
8888 // Otherwise we just add the newly delimited token 9627 /*
8889 // and recalculate where the search should continue. 9628 * Look at rest of src string following delimeter.
8890 if ((keepNulls) || ((!keepNulls) && (offset[best] - beginning) > 0)) 9629 */
8891 tokens.Add(new LSL_String(src.Substring(beginning,offset[best]-beginning))); 9630 i = earliestSrc + earliestStr.Length;
8892
8893 if (best < seplen)
8894 {
8895 beginning = offset[best] + (separray[best].ToString()).Length;
8896 }
8897 else
8898 {
8899 beginning = offset[best] + (spcarray[best - seplen].ToString()).Length;
8900 string str = spcarray[best - seplen].ToString();
8901 if ((keepNulls) || ((!keepNulls) && (str.Length > 0)))
8902 tokens.Add(new LSL_String(str));
8903 }
8904 } 9631 }
8905 9632
8906 // This an awkward an not very intuitive boundary case. If the 9633 /*
8907 // last substring is a tokenizer, then there is an implied trailing 9634 * Make up an exact-sized output array suitable for an LSL_List object.
8908 // null list entry. Hopefully the single comparison will not be too 9635 */
8909 // arduous. Alternatively the 'break' could be replced with a return 9636 object[] outlist = new object[outlen];
8910 // but that's shabby programming. 9637 for (i = 0; i < outlen; i ++)
8911
8912 if ((beginning == srclen) && (keepNulls))
8913 { 9638 {
8914 if (srclen != 0) 9639 outlist[i] = new LSL_String(outarray[i]);
8915 tokens.Add(new LSL_String(""));
8916 } 9640 }
8917 9641 return new LSL_List(outlist);
8918 return tokens;
8919 }
8920
8921 public LSL_List llParseString2List(string src, LSL_List separators, LSL_List spacers)
8922 {
8923 m_host.AddScriptLPS(1);
8924 return this.ParseString(src, separators, spacers, false);
8925 }
8926
8927 public LSL_List llParseStringKeepNulls(string src, LSL_List separators, LSL_List spacers)
8928 {
8929 m_host.AddScriptLPS(1);
8930 return this.ParseString(src, separators, spacers, true);
8931 } 9642 }
8932 9643
8933 public LSL_Integer llGetObjectPermMask(int mask) 9644 public LSL_Integer llGetObjectPermMask(int mask)
@@ -9004,28 +9715,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9004 { 9715 {
9005 m_host.AddScriptLPS(1); 9716 m_host.AddScriptLPS(1);
9006 9717
9007 lock (m_host.TaskInventory) 9718 m_host.TaskInventory.LockItemsForRead(true);
9719 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
9008 { 9720 {
9009 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9721 if (inv.Value.Name == item)
9010 { 9722 {
9011 if (inv.Value.Name == item) 9723 m_host.TaskInventory.LockItemsForRead(false);
9724 switch (mask)
9012 { 9725 {
9013 switch (mask) 9726 case 0:
9014 { 9727 return (int)inv.Value.BasePermissions;
9015 case 0: 9728 case 1:
9016 return (int)inv.Value.BasePermissions; 9729 return (int)inv.Value.CurrentPermissions;
9017 case 1: 9730 case 2:
9018 return (int)inv.Value.CurrentPermissions; 9731 return (int)inv.Value.GroupPermissions;
9019 case 2: 9732 case 3:
9020 return (int)inv.Value.GroupPermissions; 9733 return (int)inv.Value.EveryonePermissions;
9021 case 3: 9734 case 4:
9022 return (int)inv.Value.EveryonePermissions; 9735 return (int)inv.Value.NextPermissions;
9023 case 4:
9024 return (int)inv.Value.NextPermissions;
9025 }
9026 } 9736 }
9027 } 9737 }
9028 } 9738 }
9739 m_host.TaskInventory.LockItemsForRead(false);
9029 9740
9030 return -1; 9741 return -1;
9031 } 9742 }
@@ -9072,16 +9783,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9072 { 9783 {
9073 m_host.AddScriptLPS(1); 9784 m_host.AddScriptLPS(1);
9074 9785
9075 lock (m_host.TaskInventory) 9786 m_host.TaskInventory.LockItemsForRead(true);
9787 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
9076 { 9788 {
9077 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 9789 if (inv.Value.Name == item)
9078 { 9790 {
9079 if (inv.Value.Name == item) 9791 m_host.TaskInventory.LockItemsForRead(false);
9080 { 9792 return inv.Value.CreatorID.ToString();
9081 return inv.Value.CreatorID.ToString();
9082 }
9083 } 9793 }
9084 } 9794 }
9795 m_host.TaskInventory.LockItemsForRead(false);
9085 9796
9086 llSay(0, "No item name '" + item + "'"); 9797 llSay(0, "No item name '" + item + "'");
9087 9798
@@ -9223,9 +9934,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9223 { 9934 {
9224 try 9935 try
9225 { 9936 {
9937 /*
9226 SceneObjectPart obj = World.GetSceneObjectPart(World.Entities[key].LocalId); 9938 SceneObjectPart obj = World.GetSceneObjectPart(World.Entities[key].LocalId);
9227 if (obj != null) 9939 if (obj != null)
9228 return (double)obj.GetMass(); 9940 return (double)obj.GetMass();
9941 */
9942 // return total object mass
9943 SceneObjectGroup obj = World.GetGroupByPrim(World.Entities[key].LocalId);
9944 if (obj != null)
9945 return obj.GetMass();
9946
9229 // the object is null so the key is for an avatar 9947 // the object is null so the key is for an avatar
9230 ScenePresence avatar = World.GetScenePresence(key); 9948 ScenePresence avatar = World.GetScenePresence(key);
9231 if (avatar != null) 9949 if (avatar != null)
@@ -9245,7 +9963,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9245 } 9963 }
9246 9964
9247 /// <summary> 9965 /// <summary>
9248 /// illListReplaceList removes the sub-list defined by the inclusive indices 9966 /// llListReplaceList removes the sub-list defined by the inclusive indices
9249 /// start and end and inserts the src list in its place. The inclusive 9967 /// start and end and inserts the src list in its place. The inclusive
9250 /// nature of the indices means that at least one element must be deleted 9968 /// nature of the indices means that at least one element must be deleted
9251 /// if the indices are within the bounds of the existing list. I.e. 2,2 9969 /// if the indices are within the bounds of the existing list. I.e. 2,2
@@ -9302,16 +10020,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9302 // based upon end. Note that if end exceeds the upper 10020 // based upon end. Note that if end exceeds the upper
9303 // bound in this case, the entire destination list 10021 // bound in this case, the entire destination list
9304 // is removed. 10022 // is removed.
9305 else 10023 else if (start == 0)
9306 { 10024 {
9307 if (end + 1 < dest.Length) 10025 if (end + 1 < dest.Length)
9308 {
9309 return src + dest.GetSublist(end + 1, -1); 10026 return src + dest.GetSublist(end + 1, -1);
9310 }
9311 else 10027 else
9312 {
9313 return src; 10028 return src;
9314 } 10029 }
10030 else // Start < 0
10031 {
10032 if (end + 1 < dest.Length)
10033 return dest.GetSublist(end + 1, -1);
10034 else
10035 return new LSL_List();
9315 } 10036 }
9316 } 10037 }
9317 // Finally, if start > end, we strip away a prefix and 10038 // Finally, if start > end, we strip away a prefix and
@@ -9362,17 +10083,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9362 int width = 0; 10083 int width = 0;
9363 int height = 0; 10084 int height = 0;
9364 10085
9365 ParcelMediaCommandEnum? commandToSend = null; 10086 uint commandToSend = 0;
9366 float time = 0.0f; // default is from start 10087 float time = 0.0f; // default is from start
9367 10088
9368 ScenePresence presence = null; 10089 ScenePresence presence = null;
9369 10090
9370 for (int i = 0; i < commandList.Data.Length; i++) 10091 for (int i = 0; i < commandList.Data.Length; i++)
9371 { 10092 {
9372 ParcelMediaCommandEnum command = (ParcelMediaCommandEnum)commandList.Data[i]; 10093 uint command = (uint)(commandList.GetLSLIntegerItem(i));
9373 switch (command) 10094 switch (command)
9374 { 10095 {
9375 case ParcelMediaCommandEnum.Agent: 10096 case (uint)ParcelMediaCommandEnum.Agent:
9376 // we send only to one agent 10097 // we send only to one agent
9377 if ((i + 1) < commandList.Length) 10098 if ((i + 1) < commandList.Length)
9378 { 10099 {
@@ -9389,25 +10110,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9389 } 10110 }
9390 break; 10111 break;
9391 10112
9392 case ParcelMediaCommandEnum.Loop: 10113 case (uint)ParcelMediaCommandEnum.Loop:
9393 loop = 1; 10114 loop = 1;
9394 commandToSend = command; 10115 commandToSend = command;
9395 update = true; //need to send the media update packet to set looping 10116 update = true; //need to send the media update packet to set looping
9396 break; 10117 break;
9397 10118
9398 case ParcelMediaCommandEnum.Play: 10119 case (uint)ParcelMediaCommandEnum.Play:
9399 loop = 0; 10120 loop = 0;
9400 commandToSend = command; 10121 commandToSend = command;
9401 update = true; //need to send the media update packet to make sure it doesn't loop 10122 update = true; //need to send the media update packet to make sure it doesn't loop
9402 break; 10123 break;
9403 10124
9404 case ParcelMediaCommandEnum.Pause: 10125 case (uint)ParcelMediaCommandEnum.Pause:
9405 case ParcelMediaCommandEnum.Stop: 10126 case (uint)ParcelMediaCommandEnum.Stop:
9406 case ParcelMediaCommandEnum.Unload: 10127 case (uint)ParcelMediaCommandEnum.Unload:
9407 commandToSend = command; 10128 commandToSend = command;
9408 break; 10129 break;
9409 10130
9410 case ParcelMediaCommandEnum.Url: 10131 case (uint)ParcelMediaCommandEnum.Url:
9411 if ((i + 1) < commandList.Length) 10132 if ((i + 1) < commandList.Length)
9412 { 10133 {
9413 if (commandList.Data[i + 1] is LSL_String) 10134 if (commandList.Data[i + 1] is LSL_String)
@@ -9420,7 +10141,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9420 } 10141 }
9421 break; 10142 break;
9422 10143
9423 case ParcelMediaCommandEnum.Texture: 10144 case (uint)ParcelMediaCommandEnum.Texture:
9424 if ((i + 1) < commandList.Length) 10145 if ((i + 1) < commandList.Length)
9425 { 10146 {
9426 if (commandList.Data[i + 1] is LSL_String) 10147 if (commandList.Data[i + 1] is LSL_String)
@@ -9433,7 +10154,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9433 } 10154 }
9434 break; 10155 break;
9435 10156
9436 case ParcelMediaCommandEnum.Time: 10157 case (uint)ParcelMediaCommandEnum.Time:
9437 if ((i + 1) < commandList.Length) 10158 if ((i + 1) < commandList.Length)
9438 { 10159 {
9439 if (commandList.Data[i + 1] is LSL_Float) 10160 if (commandList.Data[i + 1] is LSL_Float)
@@ -9445,7 +10166,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9445 } 10166 }
9446 break; 10167 break;
9447 10168
9448 case ParcelMediaCommandEnum.AutoAlign: 10169 case (uint)ParcelMediaCommandEnum.AutoAlign:
9449 if ((i + 1) < commandList.Length) 10170 if ((i + 1) < commandList.Length)
9450 { 10171 {
9451 if (commandList.Data[i + 1] is LSL_Integer) 10172 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9459,7 +10180,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9459 } 10180 }
9460 break; 10181 break;
9461 10182
9462 case ParcelMediaCommandEnum.Type: 10183 case (uint)ParcelMediaCommandEnum.Type:
9463 if ((i + 1) < commandList.Length) 10184 if ((i + 1) < commandList.Length)
9464 { 10185 {
9465 if (commandList.Data[i + 1] is LSL_String) 10186 if (commandList.Data[i + 1] is LSL_String)
@@ -9472,7 +10193,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9472 } 10193 }
9473 break; 10194 break;
9474 10195
9475 case ParcelMediaCommandEnum.Desc: 10196 case (uint)ParcelMediaCommandEnum.Desc:
9476 if ((i + 1) < commandList.Length) 10197 if ((i + 1) < commandList.Length)
9477 { 10198 {
9478 if (commandList.Data[i + 1] is LSL_String) 10199 if (commandList.Data[i + 1] is LSL_String)
@@ -9485,7 +10206,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9485 } 10206 }
9486 break; 10207 break;
9487 10208
9488 case ParcelMediaCommandEnum.Size: 10209 case (uint)ParcelMediaCommandEnum.Size:
9489 if ((i + 2) < commandList.Length) 10210 if ((i + 2) < commandList.Length)
9490 { 10211 {
9491 if (commandList.Data[i + 1] is LSL_Integer) 10212 if (commandList.Data[i + 1] is LSL_Integer)
@@ -9555,7 +10276,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9555 } 10276 }
9556 } 10277 }
9557 10278
9558 if (commandToSend != null) 10279 if (commandToSend != 0)
9559 { 10280 {
9560 // the commandList contained a start/stop/... command, too 10281 // the commandList contained a start/stop/... command, too
9561 if (presence == null) 10282 if (presence == null)
@@ -9592,7 +10313,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9592 10313
9593 if (aList.Data[i] != null) 10314 if (aList.Data[i] != null)
9594 { 10315 {
9595 switch ((ParcelMediaCommandEnum) aList.Data[i]) 10316 switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
9596 { 10317 {
9597 case ParcelMediaCommandEnum.Url: 10318 case ParcelMediaCommandEnum.Url:
9598 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL)); 10319 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL));
@@ -9635,16 +10356,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9635 { 10356 {
9636 m_host.AddScriptLPS(1); 10357 m_host.AddScriptLPS(1);
9637 10358
9638 lock (m_host.TaskInventory) 10359 m_host.TaskInventory.LockItemsForRead(true);
10360 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
9639 { 10361 {
9640 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 10362 if (inv.Value.Name == name)
9641 { 10363 {
9642 if (inv.Value.Name == name) 10364 m_host.TaskInventory.LockItemsForRead(false);
9643 { 10365 return inv.Value.Type;
9644 return inv.Value.Type;
9645 }
9646 } 10366 }
9647 } 10367 }
10368 m_host.TaskInventory.LockItemsForRead(false);
9648 10369
9649 return -1; 10370 return -1;
9650 } 10371 }
@@ -9655,15 +10376,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9655 10376
9656 if (quick_pay_buttons.Data.Length < 4) 10377 if (quick_pay_buttons.Data.Length < 4)
9657 { 10378 {
9658 LSLError("List must have at least 4 elements"); 10379 int x;
9659 return; 10380 for (x=quick_pay_buttons.Data.Length; x<= 4; x++)
10381 {
10382 quick_pay_buttons.Add(ScriptBaseClass.PAY_HIDE);
10383 }
9660 } 10384 }
9661 m_host.ParentGroup.RootPart.PayPrice[0]=price; 10385 int[] nPrice = new int[5];
9662 10386 nPrice[0] = price;
9663 m_host.ParentGroup.RootPart.PayPrice[1]=(LSL_Integer)quick_pay_buttons.Data[0]; 10387 nPrice[1] = quick_pay_buttons.GetLSLIntegerItem(0);
9664 m_host.ParentGroup.RootPart.PayPrice[2]=(LSL_Integer)quick_pay_buttons.Data[1]; 10388 nPrice[2] = quick_pay_buttons.GetLSLIntegerItem(1);
9665 m_host.ParentGroup.RootPart.PayPrice[3]=(LSL_Integer)quick_pay_buttons.Data[2]; 10389 nPrice[3] = quick_pay_buttons.GetLSLIntegerItem(2);
9666 m_host.ParentGroup.RootPart.PayPrice[4]=(LSL_Integer)quick_pay_buttons.Data[3]; 10390 nPrice[4] = quick_pay_buttons.GetLSLIntegerItem(3);
10391 m_host.ParentGroup.RootPart.PayPrice = nPrice;
9667 m_host.ParentGroup.HasGroupChanged = true; 10392 m_host.ParentGroup.HasGroupChanged = true;
9668 } 10393 }
9669 10394
@@ -9680,7 +10405,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9680 return new LSL_Vector(); 10405 return new LSL_Vector();
9681 } 10406 }
9682 10407
9683 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10408// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
10409 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
9684 if (presence != null) 10410 if (presence != null)
9685 { 10411 {
9686 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z); 10412 LSL_Vector pos = new LSL_Vector(presence.CameraPosition.X, presence.CameraPosition.Y, presence.CameraPosition.Z);
@@ -9702,7 +10428,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9702 return new LSL_Rotation(); 10428 return new LSL_Rotation();
9703 } 10429 }
9704 10430
9705 ScenePresence presence = World.GetScenePresence(m_host.OwnerID); 10431// ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
10432 ScenePresence presence = World.GetScenePresence(m_item.PermsGranter);
9706 if (presence != null) 10433 if (presence != null)
9707 { 10434 {
9708 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W); 10435 return new LSL_Rotation(presence.CameraRotation.X, presence.CameraRotation.Y, presence.CameraRotation.Z, presence.CameraRotation.W);
@@ -9762,8 +10489,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9762 { 10489 {
9763 m_host.AddScriptLPS(1); 10490 m_host.AddScriptLPS(1);
9764 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0); 10491 DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
9765 if (detectedParams == null) return; // only works on the first detected avatar 10492 if (detectedParams == null)
9766 10493 {
10494 if (m_host.ParentGroup.IsAttachment == true)
10495 {
10496 detectedParams = new DetectParams();
10497 detectedParams.Key = m_host.OwnerID;
10498 }
10499 else
10500 {
10501 return;
10502 }
10503 }
10504
9767 ScenePresence avatar = World.GetScenePresence(detectedParams.Key); 10505 ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
9768 if (avatar != null) 10506 if (avatar != null)
9769 { 10507 {
@@ -9771,6 +10509,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9771 new Vector3((float)pos.x, (float)pos.y, (float)pos.z), 10509 new Vector3((float)pos.x, (float)pos.y, (float)pos.z),
9772 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z)); 10510 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z));
9773 } 10511 }
10512
9774 ScriptSleep(1000); 10513 ScriptSleep(1000);
9775 } 10514 }
9776 10515
@@ -9894,12 +10633,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9894 10633
9895 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>(); 10634 SortedDictionary<int, float> parameters = new SortedDictionary<int, float>();
9896 object[] data = rules.Data; 10635 object[] data = rules.Data;
9897 for (int i = 0; i < data.Length; ++i) { 10636 for (int i = 0; i < data.Length; ++i)
10637 {
9898 int type = Convert.ToInt32(data[i++].ToString()); 10638 int type = Convert.ToInt32(data[i++].ToString());
9899 if (i >= data.Length) break; // odd number of entries => ignore the last 10639 if (i >= data.Length) break; // odd number of entries => ignore the last
9900 10640
9901 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3) 10641 // some special cases: Vector parameters are split into 3 float parameters (with type+1, type+2, type+3)
9902 switch (type) { 10642 switch (type)
10643 {
9903 case ScriptBaseClass.CAMERA_FOCUS: 10644 case ScriptBaseClass.CAMERA_FOCUS:
9904 case ScriptBaseClass.CAMERA_FOCUS_OFFSET: 10645 case ScriptBaseClass.CAMERA_FOCUS_OFFSET:
9905 case ScriptBaseClass.CAMERA_POSITION: 10646 case ScriptBaseClass.CAMERA_POSITION:
@@ -10005,19 +10746,65 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10005 public LSL_String llXorBase64StringsCorrect(string str1, string str2) 10746 public LSL_String llXorBase64StringsCorrect(string str1, string str2)
10006 { 10747 {
10007 m_host.AddScriptLPS(1); 10748 m_host.AddScriptLPS(1);
10008 string ret = String.Empty; 10749
10009 string src1 = llBase64ToString(str1); 10750 if (str1 == String.Empty)
10010 string src2 = llBase64ToString(str2); 10751 return String.Empty;
10011 int c = 0; 10752 if (str2 == String.Empty)
10012 for (int i = 0; i < src1.Length; i++) 10753 return str1;
10754
10755 int len = str2.Length;
10756 if ((len % 4) != 0) // LL is EVIL!!!!
10757 {
10758 while (str2.EndsWith("="))
10759 str2 = str2.Substring(0, str2.Length - 1);
10760
10761 len = str2.Length;
10762 int mod = len % 4;
10763
10764 if (mod == 1)
10765 str2 = str2.Substring(0, str2.Length - 1);
10766 else if (mod == 2)
10767 str2 += "==";
10768 else if (mod == 3)
10769 str2 += "=";
10770 }
10771
10772 byte[] data1;
10773 byte[] data2;
10774 try
10775 {
10776 data1 = Convert.FromBase64String(str1);
10777 data2 = Convert.FromBase64String(str2);
10778 }
10779 catch (Exception)
10013 { 10780 {
10014 ret += (char) (src1[i] ^ src2[c]); 10781 return new LSL_String(String.Empty);
10782 }
10015 10783
10016 c++; 10784 byte[] d2 = new Byte[data1.Length];
10017 if (c >= src2.Length) 10785 int pos = 0;
10018 c = 0; 10786
10787 if (data1.Length <= data2.Length)
10788 {
10789 Array.Copy(data2, 0, d2, 0, data1.Length);
10790 }
10791 else
10792 {
10793 while (pos < data1.Length)
10794 {
10795 len = data1.Length - pos;
10796 if (len > data2.Length)
10797 len = data2.Length;
10798
10799 Array.Copy(data2, 0, d2, pos, len);
10800 pos += len;
10801 }
10019 } 10802 }
10020 return llStringToBase64(ret); 10803
10804 for (pos = 0 ; pos < data1.Length ; pos++ )
10805 data1[pos] ^= d2[pos];
10806
10807 return Convert.ToBase64String(data1);
10021 } 10808 }
10022 10809
10023 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body) 10810 public LSL_String llHTTPRequest(string url, LSL_List parameters, string body)
@@ -10074,12 +10861,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10074 Regex r = new Regex(authregex); 10861 Regex r = new Regex(authregex);
10075 int[] gnums = r.GetGroupNumbers(); 10862 int[] gnums = r.GetGroupNumbers();
10076 Match m = r.Match(url); 10863 Match m = r.Match(url);
10077 if (m.Success) { 10864 if (m.Success)
10078 for (int i = 1; i < gnums.Length; i++) { 10865 {
10866 for (int i = 1; i < gnums.Length; i++)
10867 {
10079 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]]; 10868 //System.Text.RegularExpressions.Group g = m.Groups[gnums[i]];
10080 //CaptureCollection cc = g.Captures; 10869 //CaptureCollection cc = g.Captures;
10081 } 10870 }
10082 if (m.Groups.Count == 5) { 10871 if (m.Groups.Count == 5)
10872 {
10083 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString()))); 10873 httpHeaders["Authorization"] = String.Format("Basic {0}", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(m.Groups[2].ToString() + ":" + m.Groups[3].ToString())));
10084 url = m.Groups[1].ToString() + m.Groups[4].ToString(); 10874 url = m.Groups[1].ToString() + m.Groups[4].ToString();
10085 } 10875 }
@@ -10442,15 +11232,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10442 11232
10443 internal UUID ScriptByName(string name) 11233 internal UUID ScriptByName(string name)
10444 { 11234 {
10445 lock (m_host.TaskInventory) 11235 m_host.TaskInventory.LockItemsForRead(true);
11236
11237 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
10446 { 11238 {
10447 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 11239 if (item.Type == 10 && item.Name == name)
10448 { 11240 {
10449 if (item.Type == 10 && item.Name == name) 11241 m_host.TaskInventory.LockItemsForRead(false);
10450 return item.ItemID; 11242 return item.ItemID;
10451 } 11243 }
10452 } 11244 }
10453 11245
11246 m_host.TaskInventory.LockItemsForRead(false);
11247
10454 return UUID.Zero; 11248 return UUID.Zero;
10455 } 11249 }
10456 11250
@@ -10491,6 +11285,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10491 { 11285 {
10492 m_host.AddScriptLPS(1); 11286 m_host.AddScriptLPS(1);
10493 11287
11288 //Clone is thread safe
10494 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 11289 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10495 11290
10496 UUID assetID = UUID.Zero; 11291 UUID assetID = UUID.Zero;
@@ -10553,6 +11348,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10553 { 11348 {
10554 m_host.AddScriptLPS(1); 11349 m_host.AddScriptLPS(1);
10555 11350
11351 //Clone is thread safe
10556 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); 11352 TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
10557 11353
10558 UUID assetID = UUID.Zero; 11354 UUID assetID = UUID.Zero;
@@ -10633,15 +11429,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10633 return GetLinkPrimitiveParams(obj, rules); 11429 return GetLinkPrimitiveParams(obj, rules);
10634 } 11430 }
10635 11431
10636 public void print(string str) 11432 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
10637 { 11433 {
10638 // yes, this is a real LSL function. See: http://wiki.secondlife.com/wiki/Print 11434 List<SceneObjectPart> parts = GetLinkParts(link);
10639 IOSSL_Api ossl = (IOSSL_Api)m_ScriptEngine.GetApi(m_item.ItemID, "OSSL"); 11435 if (parts.Count < 1)
10640 if (ossl != null) 11436 return 0;
10641 { 11437
10642 ossl.CheckThreatLevel(ThreatLevel.High, "print"); 11438 return GetNumberOfSides(parts[0]);
10643 m_log.Info("LSL print():" + str);
10644 }
10645 } 11439 }
10646 11440
10647 private string Name2Username(string name) 11441 private string Name2Username(string name)
@@ -10687,155 +11481,482 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10687 return rq.ToString(); 11481 return rq.ToString();
10688 } 11482 }
10689 11483
11484 private void SayShoutTimerElapsed(Object sender, ElapsedEventArgs args)
11485 {
11486 m_SayShoutCount = 0;
11487 }
11488
11489 private struct Tri
11490 {
11491 public Vector3 p1;
11492 public Vector3 p2;
11493 public Vector3 p3;
11494 }
11495
11496 private bool InBoundingBox(ScenePresence avatar, Vector3 point)
11497 {
11498 float height = avatar.Appearance.AvatarHeight;
11499 Vector3 b1 = avatar.AbsolutePosition + new Vector3(-0.22f, -0.22f, -height/2);
11500 Vector3 b2 = avatar.AbsolutePosition + new Vector3(0.22f, 0.22f, height/2);
11501
11502 if (point.X > b1.X && point.X < b2.X &&
11503 point.Y > b1.Y && point.Y < b2.Y &&
11504 point.Z > b1.Z && point.Z < b2.Z)
11505 return true;
11506 return false;
11507 }
11508
11509 private ContactResult[] AvatarIntersection(Vector3 rayStart, Vector3 rayEnd)
11510 {
11511 List<ContactResult> contacts = new List<ContactResult>();
11512
11513 Vector3 ab = rayEnd - rayStart;
11514
11515 World.ForEachScenePresence(delegate(ScenePresence sp)
11516 {
11517 Vector3 ac = sp.AbsolutePosition - rayStart;
11518 Vector3 bc = sp.AbsolutePosition - rayEnd;
11519
11520 double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
11521
11522 if (d > 1.5)
11523 return;
11524
11525 double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
11526
11527 if (d2 > 0)
11528 return;
11529
11530 double dp = Math.Sqrt(Vector3.Mag(ac) * Vector3.Mag(ac) - d * d);
11531 Vector3 p = rayStart + Vector3.Divide(Vector3.Multiply(ab, (float)dp), (float)Vector3.Mag(ab));
11532
11533 if (!InBoundingBox(sp, p))
11534 return;
11535
11536 ContactResult result = new ContactResult ();
11537 result.ConsumerID = sp.LocalId;
11538 result.Depth = Vector3.Distance(rayStart, p);
11539 result.Normal = Vector3.Zero;
11540 result.Pos = p;
11541
11542 contacts.Add(result);
11543 });
11544
11545 return contacts.ToArray();
11546 }
11547
11548 private ContactResult[] ObjectIntersection(Vector3 rayStart, Vector3 rayEnd, bool includePhysical, bool includeNonPhysical, bool includePhantom)
11549 {
11550 Ray ray = new Ray(rayStart, Vector3.Normalize(rayEnd - rayStart));
11551 List<ContactResult> contacts = new List<ContactResult>();
11552
11553 Vector3 ab = rayEnd - rayStart;
11554
11555 World.ForEachSOG(delegate(SceneObjectGroup group)
11556 {
11557 if (m_host.ParentGroup == group)
11558 return;
11559
11560 if (group.IsAttachment)
11561 return;
11562
11563 if (group.RootPart.PhysActor == null)
11564 {
11565 if (!includePhantom)
11566 return;
11567 }
11568 else
11569 {
11570 if (group.RootPart.PhysActor.IsPhysical)
11571 {
11572 if (!includePhysical)
11573 return;
11574 }
11575 else
11576 {
11577 if (!includeNonPhysical)
11578 return;
11579 }
11580 }
11581
11582 // Find the radius ouside of which we don't even need to hit test
11583 float minX;
11584 float maxX;
11585 float minY;
11586 float maxY;
11587 float minZ;
11588 float maxZ;
11589
11590 float radius = 0.0f;
11591
11592 group.GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
11593
11594 if (Math.Abs(minX) > radius)
11595 radius = Math.Abs(minX);
11596 if (Math.Abs(minY) > radius)
11597 radius = Math.Abs(minY);
11598 if (Math.Abs(minZ) > radius)
11599 radius = Math.Abs(minZ);
11600 if (Math.Abs(maxX) > radius)
11601 radius = Math.Abs(maxX);
11602 if (Math.Abs(maxY) > radius)
11603 radius = Math.Abs(maxY);
11604 if (Math.Abs(maxZ) > radius)
11605 radius = Math.Abs(maxZ);
11606
11607 Vector3 ac = group.AbsolutePosition - rayStart;
11608 Vector3 bc = group.AbsolutePosition - rayEnd;
11609
11610 double d = Math.Abs(Vector3.Mag(Vector3.Cross(ab, ac)) / Vector3.Distance(rayStart, rayEnd));
11611
11612 // Too far off ray, don't bother
11613 if (d > radius)
11614 return;
11615
11616 // Behind ray, drop
11617 double d2 = Vector3.Dot(Vector3.Negate(ab), ac);
11618 if (d2 > 0)
11619 return;
11620
11621 EntityIntersection intersection = group.TestIntersection(ray, true, false);
11622 // Miss.
11623 if (!intersection.HitTF)
11624 return;
11625
11626 ContactResult result = new ContactResult ();
11627 result.ConsumerID = group.LocalId;
11628 result.Depth = intersection.distance;
11629 result.Normal = intersection.normal;
11630 result.Pos = intersection.ipoint;
11631
11632 contacts.Add(result);
11633 });
11634
11635 return contacts.ToArray();
11636 }
11637
11638 private ContactResult? GroundIntersection(Vector3 rayStart, Vector3 rayEnd)
11639 {
11640 double[,] heightfield = World.Heightmap.GetDoubles();
11641 List<ContactResult> contacts = new List<ContactResult>();
11642
11643 double min = 2048.0;
11644 double max = 0.0;
11645
11646 // Find the min and max of the heightfield
11647 for (int x = 0 ; x < World.Heightmap.Width ; x++)
11648 {
11649 for (int y = 0 ; y < World.Heightmap.Height ; y++)
11650 {
11651 if (heightfield[x, y] > max)
11652 max = heightfield[x, y];
11653 if (heightfield[x, y] < min)
11654 min = heightfield[x, y];
11655 }
11656 }
11657
11658
11659 // A ray extends past rayEnd, but doesn't go back before
11660 // rayStart. If the start is above the highest point of the ground
11661 // and the ray goes up, we can't hit the ground. Ever.
11662 if (rayStart.Z > max && rayEnd.Z >= rayStart.Z)
11663 return null;
11664
11665 // Same for going down
11666 if (rayStart.Z < min && rayEnd.Z <= rayStart.Z)
11667 return null;
11668
11669 List<Tri> trilist = new List<Tri>();
11670
11671 // Create our triangle list
11672 for (int x = 1 ; x < World.Heightmap.Width ; x++)
11673 {
11674 for (int y = 1 ; y < World.Heightmap.Height ; y++)
11675 {
11676 Tri t1 = new Tri();
11677 Tri t2 = new Tri();
11678
11679 Vector3 p1 = new Vector3(x-1, y-1, (float)heightfield[x-1, y-1]);
11680 Vector3 p2 = new Vector3(x, y-1, (float)heightfield[x, y-1]);
11681 Vector3 p3 = new Vector3(x, y, (float)heightfield[x, y]);
11682 Vector3 p4 = new Vector3(x-1, y, (float)heightfield[x-1, y]);
11683
11684 t1.p1 = p1;
11685 t1.p2 = p2;
11686 t1.p3 = p3;
11687
11688 t2.p1 = p3;
11689 t2.p2 = p4;
11690 t2.p3 = p1;
11691
11692 trilist.Add(t1);
11693 trilist.Add(t2);
11694 }
11695 }
11696
11697 // Ray direction
11698 Vector3 rayDirection = rayEnd - rayStart;
11699
11700 foreach (Tri t in trilist)
11701 {
11702 // Compute triangle plane normal and edges
11703 Vector3 u = t.p2 - t.p1;
11704 Vector3 v = t.p3 - t.p1;
11705 Vector3 n = Vector3.Cross(u, v);
11706
11707 if (n == Vector3.Zero)
11708 continue;
11709
11710 Vector3 w0 = rayStart - t.p1;
11711 double a = -Vector3.Dot(n, w0);
11712 double b = Vector3.Dot(n, rayDirection);
11713
11714 // Not intersecting the plane, or in plane (same thing)
11715 // Ignoring this MAY cause the ground to not be detected
11716 // sometimes
11717 if (Math.Abs(b) < 0.000001)
11718 continue;
11719
11720 double r = a / b;
11721
11722 // ray points away from plane
11723 if (r < 0.0)
11724 continue;
11725
11726 Vector3 ip = rayStart + Vector3.Multiply(rayDirection, (float)r);
11727
11728 float uu = Vector3.Dot(u, u);
11729 float uv = Vector3.Dot(u, v);
11730 float vv = Vector3.Dot(v, v);
11731 Vector3 w = ip - t.p1;
11732 float wu = Vector3.Dot(w, u);
11733 float wv = Vector3.Dot(w, v);
11734 float d = uv * uv - uu * vv;
11735
11736 float cs = (uv * wv - vv * wu) / d;
11737 if (cs < 0 || cs > 1.0)
11738 continue;
11739 float ct = (uv * wu - uu * wv) / d;
11740 if (ct < 0 || (cs + ct) > 1.0)
11741 continue;
11742
11743 // Add contact point
11744 ContactResult result = new ContactResult ();
11745 result.ConsumerID = 0;
11746 result.Depth = Vector3.Distance(rayStart, ip);
11747 result.Normal = n;
11748 result.Pos = ip;
11749
11750 contacts.Add(result);
11751 }
11752
11753 if (contacts.Count == 0)
11754 return null;
11755
11756 contacts.Sort(delegate(ContactResult a, ContactResult b)
11757 {
11758 return (int)(a.Depth - b.Depth);
11759 });
11760
11761 return contacts[0];
11762 }
11763/*
11764 // not done:
11765 private ContactResult[] testRay2NonPhysicalPhantom(Vector3 rayStart, Vector3 raydir, float raylenght)
11766 {
11767 ContactResult[] contacts = null;
11768 World.ForEachSOG(delegate(SceneObjectGroup group)
11769 {
11770 if (m_host.ParentGroup == group)
11771 return;
11772
11773 if (group.IsAttachment)
11774 return;
11775
11776 if(group.RootPart.PhysActor != null)
11777 return;
11778
11779 contacts = group.RayCastGroupPartsOBBNonPhysicalPhantom(rayStart, raydir, raylenght);
11780 });
11781 return contacts;
11782 }
11783*/
11784
10690 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options) 11785 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
10691 { 11786 {
11787 LSL_List list = new LSL_List();
11788
10692 m_host.AddScriptLPS(1); 11789 m_host.AddScriptLPS(1);
10693 11790
10694 Vector3 dir = new Vector3((float)(end-start).x, (float)(end-start).y, (float)(end-start).z); 11791 Vector3 rayStart = new Vector3((float)start.x, (float)start.y, (float)start.z);
10695 Vector3 startvector = new Vector3((float)start.x, (float)start.y, (float)start.z); 11792 Vector3 rayEnd = new Vector3((float)end.x, (float)end.y, (float)end.z);
10696 Vector3 endvector = new Vector3((float)end.x, (float)end.y, (float)end.z); 11793 Vector3 dir = rayEnd - rayStart;
10697 11794
10698 int count = 0; 11795 float dist = Vector3.Mag(dir);
10699// int detectPhantom = 0; 11796
11797 int count = 1;
11798 bool detectPhantom = false;
10700 int dataFlags = 0; 11799 int dataFlags = 0;
10701 int rejectTypes = 0; 11800 int rejectTypes = 0;
10702 11801
10703 for (int i = 0; i < options.Length; i += 2) 11802 for (int i = 0; i < options.Length; i += 2)
10704 { 11803 {
10705 if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS) 11804 if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
10706 {
10707 count = options.GetLSLIntegerItem(i + 1); 11805 count = options.GetLSLIntegerItem(i + 1);
10708 } 11806 else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
10709// else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM) 11807 detectPhantom = (options.GetLSLIntegerItem(i + 1) > 0);
10710// {
10711// detectPhantom = options.GetLSLIntegerItem(i + 1);
10712// }
10713 else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS) 11808 else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
10714 {
10715 dataFlags = options.GetLSLIntegerItem(i + 1); 11809 dataFlags = options.GetLSLIntegerItem(i + 1);
10716 }
10717 else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES) 11810 else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
10718 {
10719 rejectTypes = options.GetLSLIntegerItem(i + 1); 11811 rejectTypes = options.GetLSLIntegerItem(i + 1);
10720 }
10721 } 11812 }
10722 11813
10723 LSL_List list = new LSL_List(); 11814 if (count > 16)
10724 List<ContactResult> results = World.PhysicsScene.RaycastWorld(startvector, dir, dir.Length(), count); 11815 count = 16;
10725
10726 double distance = Util.GetDistanceTo(startvector, endvector);
10727
10728 if (distance == 0)
10729 distance = 0.001;
10730 11816
10731 Vector3 posToCheck = startvector; 11817 List<ContactResult> results = new List<ContactResult>();
10732 ITerrainChannel channel = World.RequestModuleInterface<ITerrainChannel>();
10733 11818
10734 bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND); 11819 bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
10735 bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS); 11820 bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
10736 bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL); 11821 bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
10737 bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL); 11822 bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
10738 11823
10739 for (float i = 0; i <= distance; i += 0.1f) 11824
11825 if (World.SuportsRayCastFiltered())
10740 { 11826 {
10741 posToCheck = startvector + (dir * (i / (float)distance)); 11827 if (dist == 0)
11828 return list;
11829
11830 RayFilterFlags rayfilter = RayFilterFlags.ClosestAndBackCull;
11831 if (checkTerrain)
11832 rayfilter |= RayFilterFlags.land;
11833// if (checkAgents)
11834// rayfilter |= RayFilterFlags.agent;
11835 if (checkPhysical)
11836 rayfilter |= RayFilterFlags.physical;
11837 if (checkNonPhysical)
11838 rayfilter |= RayFilterFlags.nonphysical;
11839 if (detectPhantom)
11840 rayfilter |= RayFilterFlags.LSLPhanton;
11841
11842 Vector3 direction = dir * ( 1/dist);
10742 11843
10743 if (checkTerrain && channel[(int)(posToCheck.X + startvector.X), (int)(posToCheck.Y + startvector.Y)] < posToCheck.Z) 11844 if(rayfilter == 0)
10744 { 11845 {
10745 ContactResult result = new ContactResult(); 11846 list.Add(new LSL_Integer(0));
10746 result.ConsumerID = 0; 11847 return list;
10747 result.Depth = 0;
10748 result.Normal = Vector3.Zero;
10749 result.Pos = posToCheck;
10750 results.Add(result);
10751 checkTerrain = false;
10752 } 11848 }
10753 11849
10754 if (checkAgents) 11850 // get some more contacts to sort ???
11851 int physcount = 4 * count;
11852 if (physcount > 20)
11853 physcount = 20;
11854
11855 object physresults;
11856 physresults = World.RayCastFiltered(rayStart, direction, dist, physcount, rayfilter);
11857
11858 if (physresults == null)
10755 { 11859 {
10756 World.ForEachRootScenePresence(delegate(ScenePresence sp) 11860 list.Add(new LSL_Integer(-3)); // timeout error
10757 { 11861 return list;
10758 if (sp.AbsolutePosition.ApproxEquals(posToCheck, sp.PhysicsActor.Size.X))
10759 {
10760 ContactResult result = new ContactResult ();
10761 result.ConsumerID = sp.LocalId;
10762 result.Depth = 0;
10763 result.Normal = Vector3.Zero;
10764 result.Pos = posToCheck;
10765 results.Add(result);
10766 }
10767 });
10768 } 11862 }
10769 }
10770 11863
10771 int refcount = 0; 11864 results = (List<ContactResult>)physresults;
10772 foreach (ContactResult result in results) 11865
10773 { 11866 // for now physics doesn't detect sitted avatars so do it outside physics
10774 if ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) 11867 if (checkAgents)
10775 == ScriptBaseClass.RC_REJECT_LAND && result.ConsumerID == 0) 11868 {
10776 continue; 11869 ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd);
11870 foreach (ContactResult r in agentHits)
11871 results.Add(r);
11872 }
10777 11873
10778 ISceneEntity entity = World.GetSceneObjectPart(result.ConsumerID); 11874 // bug: will not detect phantom unless they are physical
11875 // don't use ObjectIntersection because its also bad
10779 11876
10780 if (entity == null && (rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != ScriptBaseClass.RC_REJECT_AGENTS) 11877 }
10781 entity = World.GetScenePresence(result.ConsumerID); //Only check if we should be looking for agents 11878 else
11879 {
11880 if (checkTerrain)
11881 {
11882 ContactResult? groundContact = GroundIntersection(rayStart, rayEnd);
11883 if (groundContact != null)
11884 results.Add((ContactResult)groundContact);
11885 }
10782 11886
10783 if (entity == null) 11887 if (checkAgents)
10784 { 11888 {
10785 list.Add(UUID.Zero); 11889 ContactResult[] agentHits = AvatarIntersection(rayStart, rayEnd);
11890 foreach (ContactResult r in agentHits)
11891 results.Add(r);
11892 }
10786 11893
10787 if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM) 11894 if (checkPhysical || checkNonPhysical || detectPhantom)
10788 list.Add(0); 11895 {
11896 ContactResult[] objectHits = ObjectIntersection(rayStart, rayEnd, checkPhysical, checkNonPhysical, detectPhantom);
11897 foreach (ContactResult r in objectHits)
11898 results.Add(r);
11899 }
11900 }
10789 11901
10790 list.Add(result.Pos); 11902 results.Sort(delegate(ContactResult a, ContactResult b)
11903 {
11904 return a.Depth.CompareTo(b.Depth);
11905 });
11906
11907 int values = 0;
11908 SceneObjectGroup thisgrp = m_host.ParentGroup;
10791 11909
10792 if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL) 11910 foreach (ContactResult result in results)
10793 list.Add(result.Normal); 11911 {
11912 if (result.Depth > dist)
11913 continue;
10794 11914
10795 continue; //Can't find it, so add UUID.Zero 11915 // physics ray can return colisions with host prim
10796 } 11916 if (m_host.LocalId == result.ConsumerID)
11917 continue;
10797 11918
10798 /*if (detectPhantom == 0 && intersection.obj is ISceneChildEntity && 11919 UUID itemID = UUID.Zero;
10799 ((ISceneChildEntity)intersection.obj).PhysActor == null) 11920 int linkNum = 0;
10800 continue;*/ //Can't do this ATM, physics engine knows only of non phantom objects
10801 11921
10802 if (entity is SceneObjectPart) 11922 SceneObjectPart part = World.GetSceneObjectPart(result.ConsumerID);
11923 // It's a prim!
11924 if (part != null)
10803 { 11925 {
10804 PhysicsActor pa = ((SceneObjectPart)entity).PhysActor; 11926 // dont detect members of same object ???
11927 if (part.ParentGroup == thisgrp)
11928 continue;
10805 11929
10806 if (pa != null && pa.IsPhysical) 11930 if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY)
10807 { 11931 itemID = part.ParentGroup.UUID;
10808 if (!checkPhysical)
10809 continue;
10810 }
10811 else 11932 else
10812 { 11933 itemID = part.UUID;
10813 if (!checkNonPhysical)
10814 continue;
10815 }
10816 }
10817 11934
10818 refcount++; 11935 linkNum = part.LinkNum;
10819 if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY && entity is SceneObjectPart) 11936 }
10820 list.Add(((SceneObjectPart)entity).ParentGroup.UUID);
10821 else 11937 else
10822 list.Add(entity.UUID);
10823
10824 if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
10825 { 11938 {
10826 if (entity is SceneObjectPart) 11939 ScenePresence sp = World.GetScenePresence(result.ConsumerID);
10827 list.Add(((SceneObjectPart)entity).LinkNum); 11940 /// It it a boy? a girl?
10828 else 11941 if (sp != null)
10829 list.Add(0); 11942 itemID = sp.UUID;
10830 } 11943 }
10831 11944
10832 list.Add(result.Pos); 11945 list.Add(new LSL_String(itemID.ToString()));
11946 list.Add(new LSL_String(result.Pos.ToString()));
11947
11948 if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
11949 list.Add(new LSL_Integer(linkNum));
10833 11950
10834 if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL) 11951 if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
10835 list.Add(result.Normal); 11952 list.Add(new LSL_Vector(result.Normal.X, result.Normal.Y, result.Normal.Z));
11953
11954 values++;
11955 if (values >= count)
11956 break;
10836 } 11957 }
10837 11958
10838 list.Add(refcount); //The status code, either the # of contacts, RCERR_SIM_PERF_LOW, or RCERR_CAST_TIME_EXCEEDED 11959 list.Add(new LSL_Integer(values));
10839 11960
10840 return list; 11961 return list;
10841 } 11962 }
@@ -10875,7 +11996,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10875 case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD: 11996 case ScriptBaseClass.ESTATE_ACCESS_ALLOWED_AGENT_ADD:
10876 if (!isAccount) return 0; 11997 if (!isAccount) return 0;
10877 if (estate.HasAccess(id)) return 1; 11998 if (estate.HasAccess(id)) return 1;
10878 if (estate.IsBanned(id)) 11999 if (estate.IsBanned(id, World.GetUserFlags(id)))
10879 estate.RemoveBan(id); 12000 estate.RemoveBan(id);
10880 estate.AddEstateUser(id); 12001 estate.AddEstateUser(id);
10881 break; 12002 break;
@@ -10894,14 +12015,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10894 break; 12015 break;
10895 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD: 12016 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD:
10896 if (!isAccount) return 0; 12017 if (!isAccount) return 0;
10897 if (estate.IsBanned(id)) return 1; 12018 if (estate.IsBanned(id, World.GetUserFlags(id))) return 1;
10898 EstateBan ban = new EstateBan(); 12019 EstateBan ban = new EstateBan();
10899 ban.EstateID = estate.EstateID; 12020 ban.EstateID = estate.EstateID;
10900 ban.BannedUserID = id; 12021 ban.BannedUserID = id;
10901 estate.AddBan(ban); 12022 estate.AddBan(ban);
10902 break; 12023 break;
10903 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE: 12024 case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE:
10904 if (!isAccount || !estate.IsBanned(id)) return 0; 12025 if (!isAccount || !estate.IsBanned(id, World.GetUserFlags(id))) return 0;
10905 estate.RemoveBan(id); 12026 estate.RemoveBan(id);
10906 break; 12027 break;
10907 default: return 0; 12028 default: return 0;
@@ -10930,7 +12051,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10930 return 16384; 12051 return 16384;
10931 } 12052 }
10932 12053
10933 public LSL_Integer llGetUsedMemory() 12054 public virtual LSL_Integer llGetUsedMemory()
10934 { 12055 {
10935 m_host.AddScriptLPS(1); 12056 m_host.AddScriptLPS(1);
10936 // The value returned for LSO scripts in SL 12057 // The value returned for LSO scripts in SL
@@ -10958,7 +12079,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10958 public void llSetSoundQueueing(int queue) 12079 public void llSetSoundQueueing(int queue)
10959 { 12080 {
10960 m_host.AddScriptLPS(1); 12081 m_host.AddScriptLPS(1);
10961 NotImplemented("llSetSoundQueueing");
10962 } 12082 }
10963 12083
10964 public void llCollisionSprite(string impact_sprite) 12084 public void llCollisionSprite(string impact_sprite)
@@ -10970,10 +12090,270 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10970 public void llGodLikeRezObject(string inventory, LSL_Vector pos) 12090 public void llGodLikeRezObject(string inventory, LSL_Vector pos)
10971 { 12091 {
10972 m_host.AddScriptLPS(1); 12092 m_host.AddScriptLPS(1);
10973 NotImplemented("llGodLikeRezObject"); 12093
12094 if (!World.Permissions.IsGod(m_host.OwnerID))
12095 NotImplemented("llGodLikeRezObject");
12096
12097 AssetBase rezAsset = World.AssetService.Get(inventory);
12098 if (rezAsset == null)
12099 {
12100 llSay(0, "Asset not found");
12101 return;
12102 }
12103
12104 SceneObjectGroup group = null;
12105
12106 try
12107 {
12108 string xmlData = Utils.BytesToString(rezAsset.Data);
12109 group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
12110 }
12111 catch
12112 {
12113 llSay(0, "Asset not found");
12114 return;
12115 }
12116
12117 if (group == null)
12118 {
12119 llSay(0, "Asset not found");
12120 return;
12121 }
12122
12123 group.RootPart.AttachPoint = group.RootPart.Shape.State;
12124 group.RootPart.AttachOffset = group.AbsolutePosition;
12125
12126 group.ResetIDs();
12127
12128 Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
12129 World.AddNewSceneObject(group, true, llpos, Quaternion.Identity, Vector3.Zero);
12130 group.CreateScriptInstances(0, true, World.DefaultScriptEngine, 3);
12131 group.ScheduleGroupForFullUpdate();
12132
12133 // objects rezzed with this method are die_at_edge by default.
12134 group.RootPart.SetDieAtEdge(true);
12135
12136 group.ResumeScripts();
12137
12138 m_ScriptEngine.PostObjectEvent(m_host.LocalId, new EventParams(
12139 "object_rez", new Object[] {
12140 new LSL_String(
12141 group.RootPart.UUID.ToString()) },
12142 new DetectParams[0]));
12143 }
12144
12145 public LSL_String llTransferLindenDollars(string destination, int amount)
12146 {
12147 UUID txn = UUID.Random();
12148
12149 Util.FireAndForget(delegate(object x)
12150 {
12151 int replycode = 0;
12152 string replydata = destination + "," + amount.ToString();
12153
12154 try
12155 {
12156 TaskInventoryItem item = m_item;
12157 if (item == null)
12158 {
12159 replydata = "SERVICE_ERROR";
12160 return;
12161 }
12162
12163 m_host.AddScriptLPS(1);
12164
12165 if (item.PermsGranter == UUID.Zero)
12166 {
12167 replydata = "MISSING_PERMISSION_DEBIT";
12168 return;
12169 }
12170
12171 if ((item.PermsMask & ScriptBaseClass.PERMISSION_DEBIT) == 0)
12172 {
12173 replydata = "MISSING_PERMISSION_DEBIT";
12174 return;
12175 }
12176
12177 UUID toID = new UUID();
12178
12179 if (!UUID.TryParse(destination, out toID))
12180 {
12181 replydata = "INVALID_AGENT";
12182 return;
12183 }
12184
12185 IMoneyModule money = World.RequestModuleInterface<IMoneyModule>();
12186
12187 if (money == null)
12188 {
12189 replydata = "TRANSFERS_DISABLED";
12190 return;
12191 }
12192
12193 bool result = money.ObjectGiveMoney(
12194 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
12195
12196 if (result)
12197 {
12198 replycode = 1;
12199 return;
12200 }
12201
12202 replydata = "LINDENDOLLAR_INSUFFICIENTFUNDS";
12203 }
12204 finally
12205 {
12206 m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams(
12207 "transaction_result", new Object[] {
12208 new LSL_String(txn.ToString()),
12209 new LSL_Integer(replycode),
12210 new LSL_String(replydata) },
12211 new DetectParams[0]));
12212 }
12213 });
12214
12215 return txn.ToString();
10974 } 12216 }
10975 12217
10976 #endregion 12218 #endregion
12219
12220 public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
12221 {
12222 SceneObjectGroup group = m_host.ParentGroup;
12223
12224 if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical)
12225 return;
12226 if (group.IsAttachment)
12227 return;
12228
12229 if (frames.Data.Length > 0) // We are getting a new motion
12230 {
12231 if (group.RootPart.KeyframeMotion != null)
12232 group.RootPart.KeyframeMotion.Stop();
12233 group.RootPart.KeyframeMotion = null;
12234
12235 int idx = 0;
12236
12237 KeyframeMotion.PlayMode mode = KeyframeMotion.PlayMode.Forward;
12238 KeyframeMotion.DataFormat data = KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation;
12239
12240 while (idx < options.Data.Length)
12241 {
12242 int option = (int)options.GetLSLIntegerItem(idx++);
12243 int remain = options.Data.Length - idx;
12244
12245 switch (option)
12246 {
12247 case ScriptBaseClass.KFM_MODE:
12248 if (remain < 1)
12249 break;
12250 int modeval = (int)options.GetLSLIntegerItem(idx++);
12251 switch(modeval)
12252 {
12253 case ScriptBaseClass.KFM_FORWARD:
12254 mode = KeyframeMotion.PlayMode.Forward;
12255 break;
12256 case ScriptBaseClass.KFM_REVERSE:
12257 mode = KeyframeMotion.PlayMode.Reverse;
12258 break;
12259 case ScriptBaseClass.KFM_LOOP:
12260 mode = KeyframeMotion.PlayMode.Loop;
12261 break;
12262 case ScriptBaseClass.KFM_PING_PONG:
12263 mode = KeyframeMotion.PlayMode.PingPong;
12264 break;
12265 }
12266 break;
12267 case ScriptBaseClass.KFM_DATA:
12268 if (remain < 1)
12269 break;
12270 int dataval = (int)options.GetLSLIntegerItem(idx++);
12271 data = (KeyframeMotion.DataFormat)dataval;
12272 break;
12273 }
12274 }
12275
12276 group.RootPart.KeyframeMotion = new KeyframeMotion(group, mode, data);
12277
12278 idx = 0;
12279
12280 int elemLength = 2;
12281 if (data == (KeyframeMotion.DataFormat.Translation | KeyframeMotion.DataFormat.Rotation))
12282 elemLength = 3;
12283
12284 List<KeyframeMotion.Keyframe> keyframes = new List<KeyframeMotion.Keyframe>();
12285 while (idx < frames.Data.Length)
12286 {
12287 int remain = frames.Data.Length - idx;
12288
12289 if (remain < elemLength)
12290 break;
12291
12292 KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe();
12293 frame.Position = null;
12294 frame.Rotation = null;
12295
12296 if ((data & KeyframeMotion.DataFormat.Translation) != 0)
12297 {
12298 LSL_Types.Vector3 tempv = frames.GetVector3Item(idx++);
12299 frame.Position = new Vector3((float)tempv.x, (float)tempv.y, (float)tempv.z);
12300 }
12301 if ((data & KeyframeMotion.DataFormat.Rotation) != 0)
12302 {
12303 LSL_Types.Quaternion tempq = frames.GetQuaternionItem(idx++);
12304 frame.Rotation = new Quaternion((float)tempq.x, (float)tempq.y, (float)tempq.z, (float)tempq.s);
12305 }
12306
12307 float tempf = (float)frames.GetLSLFloatItem(idx++);
12308 frame.TimeMS = (int)(tempf * 1000.0f);
12309
12310 keyframes.Add(frame);
12311 }
12312
12313 group.RootPart.KeyframeMotion.SetKeyframes(keyframes.ToArray());
12314 group.RootPart.KeyframeMotion.Start();
12315 }
12316 else
12317 {
12318 if (group.RootPart.KeyframeMotion == null)
12319 return;
12320
12321 if (options.Data.Length == 0)
12322 {
12323 group.RootPart.KeyframeMotion.Stop();
12324 return;
12325 }
12326
12327 int code = (int)options.GetLSLIntegerItem(0);
12328
12329 int idx = 0;
12330
12331 while (idx < options.Data.Length)
12332 {
12333 int option = (int)options.GetLSLIntegerItem(idx++);
12334 int remain = options.Data.Length - idx;
12335
12336 switch (option)
12337 {
12338 case ScriptBaseClass.KFM_COMMAND:
12339 int cmd = (int)options.GetLSLIntegerItem(idx++);
12340 switch (cmd)
12341 {
12342 case ScriptBaseClass.KFM_CMD_PLAY:
12343 group.RootPart.KeyframeMotion.Start();
12344 break;
12345 case ScriptBaseClass.KFM_CMD_STOP:
12346 group.RootPart.KeyframeMotion.Stop();
12347 break;
12348 case ScriptBaseClass.KFM_CMD_PAUSE:
12349 group.RootPart.KeyframeMotion.Pause();
12350 break;
12351 }
12352 break;
12353 }
12354 }
12355 }
12356 }
10977 } 12357 }
10978 12358
10979 public class NotecardCache 12359 public class NotecardCache
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 7ea8b7a..8237b60 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -138,6 +138,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
138 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow; 138 internal ThreatLevel m_MaxThreatLevel = ThreatLevel.VeryLow;
139 internal float m_ScriptDelayFactor = 1.0f; 139 internal float m_ScriptDelayFactor = 1.0f;
140 internal float m_ScriptDistanceFactor = 1.0f; 140 internal float m_ScriptDistanceFactor = 1.0f;
141 internal bool m_debuggerSafe = false;
141 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); 142 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
142 143
143 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) 144 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
@@ -145,6 +146,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
145 m_ScriptEngine = ScriptEngine; 146 m_ScriptEngine = ScriptEngine;
146 m_host = host; 147 m_host = host;
147 m_item = item; 148 m_item = item;
149 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
148 150
149 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) 151 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
150 m_OSFunctionsEnabled = true; 152 m_OSFunctionsEnabled = true;
@@ -206,7 +208,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
206 208
207 internal void OSSLError(string msg) 209 internal void OSSLError(string msg)
208 { 210 {
209 throw new Exception("OSSL Runtime Error: " + msg); 211 if (m_debuggerSafe)
212 {
213 OSSLShoutError(msg);
214 }
215 else
216 {
217 throw new Exception("OSSL Runtime Error: " + msg);
218 }
210 } 219 }
211 220
212 /// <summary> 221 /// <summary>
@@ -920,18 +929,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
920 if (target != null) 929 if (target != null)
921 { 930 {
922 UUID animID=UUID.Zero; 931 UUID animID=UUID.Zero;
923 lock (m_host.TaskInventory) 932 m_host.TaskInventory.LockItemsForRead(true);
933 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
924 { 934 {
925 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 935 if (inv.Value.Name == animation)
926 { 936 {
927 if (inv.Value.Name == animation) 937 if (inv.Value.Type == (int)AssetType.Animation)
928 { 938 animID = inv.Value.AssetID;
929 if (inv.Value.Type == (int)AssetType.Animation) 939 continue;
930 animID = inv.Value.AssetID;
931 continue;
932 }
933 } 940 }
934 } 941 }
942 m_host.TaskInventory.LockItemsForRead(false);
935 if (animID == UUID.Zero) 943 if (animID == UUID.Zero)
936 target.Animator.AddAnimation(animation, m_host.UUID); 944 target.Animator.AddAnimation(animation, m_host.UUID);
937 else 945 else
@@ -972,6 +980,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
972 else 980 else
973 animID = UUID.Zero; 981 animID = UUID.Zero;
974 } 982 }
983 m_host.TaskInventory.LockItemsForRead(false);
975 984
976 if (animID == UUID.Zero) 985 if (animID == UUID.Zero)
977 target.Animator.RemoveAnimation(animation); 986 target.Animator.RemoveAnimation(animation);
@@ -1792,6 +1801,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1792 1801
1793 if (!UUID.TryParse(notecardNameOrUuid, out assetID)) 1802 if (!UUID.TryParse(notecardNameOrUuid, out assetID))
1794 { 1803 {
1804 m_host.TaskInventory.LockItemsForRead(true);
1795 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1805 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1796 { 1806 {
1797 if (item.Type == 7 && item.Name == notecardNameOrUuid) 1807 if (item.Type == 7 && item.Name == notecardNameOrUuid)
@@ -1799,6 +1809,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1799 assetID = item.AssetID; 1809 assetID = item.AssetID;
1800 } 1810 }
1801 } 1811 }
1812 m_host.TaskInventory.LockItemsForRead(false);
1802 } 1813 }
1803 1814
1804 if (assetID == UUID.Zero) 1815 if (assetID == UUID.Zero)
@@ -2266,7 +2277,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2266 CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); 2277 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2267 m_host.AddScriptLPS(1); 2278 m_host.AddScriptLPS(1);
2268 2279
2269 return NpcCreate(firstname, lastname, position, notecard, false, false); 2280 return NpcCreate(firstname, lastname, position, notecard, true, false);
2270 } 2281 }
2271 2282
2272 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) 2283 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
@@ -2277,24 +2288,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2277 return NpcCreate( 2288 return NpcCreate(
2278 firstname, lastname, position, notecard, 2289 firstname, lastname, position, notecard,
2279 (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0, 2290 (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0,
2280 (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0); 2291 false);
2292// (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) != 0);
2281 } 2293 }
2282 2294
2283 private LSL_Key NpcCreate( 2295 private LSL_Key NpcCreate(
2284 string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent) 2296 string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent)
2285 { 2297 {
2298 if (!owned)
2299 OSSLError("Unowned NPCs are unsupported");
2300
2301 string groupTitle = String.Empty;
2302
2303 if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z)))
2304 return new LSL_Key(UUID.Zero.ToString());
2305
2306 if (firstname != String.Empty || lastname != String.Empty)
2307 {
2308 if (firstname != "Shown outfit:")
2309 groupTitle = "- NPC -";
2310 }
2311
2286 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2312 INPCModule module = World.RequestModuleInterface<INPCModule>();
2287 if (module != null) 2313 if (module != null)
2288 { 2314 {
2289 AvatarAppearance appearance = null; 2315 AvatarAppearance appearance = null;
2290 2316
2291 UUID id; 2317// UUID id;
2292 if (UUID.TryParse(notecard, out id)) 2318// if (UUID.TryParse(notecard, out id))
2293 { 2319// {
2294 ScenePresence clonePresence = World.GetScenePresence(id); 2320// ScenePresence clonePresence = World.GetScenePresence(id);
2295 if (clonePresence != null) 2321// if (clonePresence != null)
2296 appearance = clonePresence.Appearance; 2322// appearance = clonePresence.Appearance;
2297 } 2323// }
2298 2324
2299 if (appearance == null) 2325 if (appearance == null)
2300 { 2326 {
@@ -2322,6 +2348,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2322 World, 2348 World,
2323 appearance); 2349 appearance);
2324 2350
2351 ScenePresence sp;
2352 if (World.TryGetScenePresence(x, out sp))
2353 {
2354 sp.Grouptitle = groupTitle;
2355 sp.SendAvatarDataToAllAgents();
2356 }
2325 return new LSL_Key(x.ToString()); 2357 return new LSL_Key(x.ToString());
2326 } 2358 }
2327 2359
@@ -2613,16 +2645,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2613 CheckThreatLevel(ThreatLevel.High, "osNpcRemove"); 2645 CheckThreatLevel(ThreatLevel.High, "osNpcRemove");
2614 m_host.AddScriptLPS(1); 2646 m_host.AddScriptLPS(1);
2615 2647
2616 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2648 ManualResetEvent ev = new ManualResetEvent(false);
2617 if (module != null)
2618 {
2619 UUID npcId = new UUID(npc.m_string);
2620 2649
2621 if (!module.CheckPermissions(npcId, m_host.OwnerID)) 2650 Util.FireAndForget(delegate(object x) {
2622 return; 2651 try
2652 {
2653 INPCModule module = World.RequestModuleInterface<INPCModule>();
2654 if (module != null)
2655 {
2656 UUID npcId = new UUID(npc.m_string);
2623 2657
2624 module.DeleteNPC(npcId, World); 2658 ILandObject l = World.LandChannel.GetLandObject(m_host.GroupPosition.X, m_host.GroupPosition.Y);
2625 } 2659 if (l == null || m_host.OwnerID != l.LandData.OwnerID)
2660 {
2661 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2662 return;
2663 }
2664
2665 module.DeleteNPC(npcId, World);
2666 }
2667 }
2668 finally
2669 {
2670 ev.Set();
2671 }
2672 });
2673 ev.WaitOne();
2626 } 2674 }
2627 2675
2628 public void osNpcPlayAnimation(LSL_Key npc, string animation) 2676 public void osNpcPlayAnimation(LSL_Key npc, string animation)
@@ -3156,4 +3204,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3156 ((LSL_Api)m_LSL_Api).DetachFromAvatar(); 3204 ((LSL_Api)m_LSL_Api).DetachFromAvatar();
3157 } 3205 }
3158 } 3206 }
3159} \ No newline at end of file 3207}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index 3844753..19f3ce1 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -319,7 +319,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
319 float dy; 319 float dy;
320 float dz; 320 float dz;
321 321
322 Quaternion q = SensePoint.GetWorldRotation(); 322// Quaternion q = SensePoint.RotationOffset;
323 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation!
323 if (SensePoint.ParentGroup.IsAttachment) 324 if (SensePoint.ParentGroup.IsAttachment)
324 { 325 {
325 // In attachments, rotate the sensor cone with the 326 // In attachments, rotate the sensor cone with the
@@ -333,7 +334,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
333 // Position of a sensor in a child prim attached to an avatar 334 // Position of a sensor in a child prim attached to an avatar
334 // will be still wrong. 335 // will be still wrong.
335 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 336 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
336 q = avatar.Rotation * q; 337 fromRegionPos = avatar.AbsolutePosition;
338 q = avatar.Rotation;
337 } 339 }
338 340
339 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 341 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
@@ -463,7 +465,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
463 // Position of a sensor in a child prim attached to an avatar 465 // Position of a sensor in a child prim attached to an avatar
464 // will be still wrong. 466 // will be still wrong.
465 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar); 467 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
466 q = avatar.Rotation * q; 468 if (avatar == null)
469 return sensedEntities;
470 fromRegionPos = avatar.AbsolutePosition;
471 q = avatar.Rotation;
467 } 472 }
468 473
469 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 474 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
index bc63030..9ee6946 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
@@ -118,25 +118,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
118 if (Timers.Count == 0) 118 if (Timers.Count == 0)
119 return; 119 return;
120 120
121 Dictionary<string, TimerClass>.ValueCollection tvals;
121 lock (TimerListLock) 122 lock (TimerListLock)
122 { 123 {
123 // Go through all timers 124 // Go through all timers
124 Dictionary<string, TimerClass>.ValueCollection tvals = Timers.Values; 125 tvals = Timers.Values;
125 foreach (TimerClass ts in tvals) 126 }
127
128 foreach (TimerClass ts in tvals)
129 {
130 // Time has passed?
131 if (ts.next < DateTime.Now.Ticks)
126 { 132 {
127 // Time has passed? 133 //m_log.Debug("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next);
128 if (ts.next < DateTime.Now.Ticks) 134 // Add it to queue
129 { 135 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
130 //m_log.Debug("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next); 136 new EventParams("timer", new Object[0],
131 // Add it to queue 137 new DetectParams[0]));
132 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID, 138 // set next interval
133 new EventParams("timer", new Object[0], 139
134 new DetectParams[0])); 140 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
135 // set next interval 141 ts.next = DateTime.Now.Ticks + ts.interval;
136
137 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
138 ts.next = DateTime.Now.Ticks + ts.interval;
139 }
140 } 142 }
141 } 143 }
142 } 144 }
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 7f5d1fe..048124d 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,12 @@ 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 LSL_Integer llGiveMoney(string destination, int amount); 211 LSL_Integer llGiveMoney(string destination, int amount);
212 LSL_String llTransferLindenDollars(string destination, int amount);
211 void llGodLikeRezObject(string inventory, LSL_Vector pos); 213 void llGodLikeRezObject(string inventory, LSL_Vector pos);
212 LSL_Float llGround(LSL_Vector offset); 214 LSL_Float llGround(LSL_Vector offset);
213 LSL_Vector llGroundContour(LSL_Vector offset); 215 LSL_Vector llGroundContour(LSL_Vector offset);
@@ -355,6 +357,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
355 void llSetParcelMusicURL(string url); 357 void llSetParcelMusicURL(string url);
356 void llSetPayPrice(int price, LSL_List quick_pay_buttons); 358 void llSetPayPrice(int price, LSL_List quick_pay_buttons);
357 void llSetPos(LSL_Vector pos); 359 void llSetPos(LSL_Vector pos);
360 LSL_Integer llSetRegionPos(LSL_Vector pos);
358 LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules); 361 LSL_Integer llSetPrimMediaParams(LSL_Integer face, LSL_List rules);
359 void llSetPrimitiveParams(LSL_List rules); 362 void llSetPrimitiveParams(LSL_List rules);
360 void llSetLinkPrimitiveParamsFast(int linknum, LSL_List rules); 363 void llSetLinkPrimitiveParamsFast(int linknum, LSL_List rules);
@@ -403,6 +406,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
403 void llTargetOmega(LSL_Vector axis, double spinrate, double gain); 406 void llTargetOmega(LSL_Vector axis, double spinrate, double gain);
404 void llTargetRemove(int number); 407 void llTargetRemove(int number);
405 void llTeleportAgentHome(string agent); 408 void llTeleportAgentHome(string agent);
409 void llTeleportAgent(string agent, string simname, LSL_Vector pos, LSL_Vector lookAt);
406 void llTextBox(string avatar, string message, int chat_channel); 410 void llTextBox(string avatar, string message, int chat_channel);
407 LSL_String llToLower(string source); 411 LSL_String llToLower(string source);
408 LSL_String llToUpper(string source); 412 LSL_String llToUpper(string source);
@@ -419,9 +423,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
419 LSL_Vector llWind(LSL_Vector offset); 423 LSL_Vector llWind(LSL_Vector offset);
420 LSL_String llXorBase64Strings(string str1, string str2); 424 LSL_String llXorBase64Strings(string str1, string str2);
421 LSL_String llXorBase64StringsCorrect(string str1, string str2); 425 LSL_String llXorBase64StringsCorrect(string str1, string str2);
422 void print(string str); 426 LSL_Integer llGetLinkNumberOfSides(LSL_Integer link);
427 void llSetPhysicsMaterial(int material_bits, float material_gravity_modifier, float material_restitution, float material_friction, float material_density);
423 428
424 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 429 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
425 LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 430 LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
431 void llSetKeyframedMotion(LSL_List frames, LSL_List options);
426 } 432 }
427} 433}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index e92518d..7382495 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -85,7 +85,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
85 // Avatar Info Commands 85 // Avatar Info Commands
86 string osGetAgentIP(string agent); 86 string osGetAgentIP(string agent);
87 LSL_List osGetAgents(); 87 LSL_List osGetAgents();
88 88
89 // Teleport commands 89 // Teleport commands
90 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 90 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
91 void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 91 void osTeleportAgent(string agent, int regionX, int regionY, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs
new file mode 100644
index 0000000..4132dfa
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/CM_Stub.cs
@@ -0,0 +1,71 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Runtime.Remoting.Lifetime;
30using System.Threading;
31using System.Reflection;
32using System.Collections;
33using System.Collections.Generic;
34using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.ScriptEngine.Interfaces;
37using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
38using integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
39using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
40using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
41using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
42using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
43using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
44using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
45using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
46
47namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
48{
49 public partial class ScriptBaseClass : MarshalByRefObject
50 {
51 public ICM_Api m_CM_Functions;
52
53 public void ApiTypeCM(IScriptApi api)
54 {
55 if (!(api is ICM_Api))
56 return;
57
58 m_CM_Functions = (ICM_Api)api;
59 }
60
61 public string cmDetectedCountry(int num)
62 {
63 return m_CM_Functions.cmDetectedCountry(num);
64 }
65
66 public string cmGetAgentCountry(key key)
67 {
68 return m_CM_Functions.cmGetAgentCountry(key);
69 }
70 }
71}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
index 9615315..943d7a2 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Diagnostics; //for [DebuggerNonUserCode]
30using System.Reflection; 31using System.Reflection;
31using System.Runtime.Remoting.Lifetime; 32using System.Runtime.Remoting.Lifetime;
32using OpenSim.Region.ScriptEngine.Shared; 33using OpenSim.Region.ScriptEngine.Shared;
@@ -132,6 +133,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
132 return (eventFlags); 133 return (eventFlags);
133 } 134 }
134 135
136 [DebuggerNonUserCode]
135 public void ExecuteEvent(string state, string FunctionName, object[] args) 137 public void ExecuteEvent(string state, string FunctionName, object[] args)
136 { 138 {
137 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. 139 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index b6c21e6..5c6ad8a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -94,6 +94,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
94 public const int AGENT_CROUCHING = 1024; 94 public const int AGENT_CROUCHING = 1024;
95 public const int AGENT_BUSY = 2048; 95 public const int AGENT_BUSY = 2048;
96 public const int AGENT_ALWAYS_RUN = 4096; 96 public const int AGENT_ALWAYS_RUN = 4096;
97 public const int AGENT_MALE = 8192;
97 98
98 //Particle Systems 99 //Particle Systems
99 public const int PSYS_PART_INTERP_COLOR_MASK = 1; 100 public const int PSYS_PART_INTERP_COLOR_MASK = 1;
@@ -282,6 +283,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
282 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART 283 public const int CHANGED_REGION_START = 1024; //LL Changed the constant from CHANGED_REGION_RESTART
283 public const int CHANGED_MEDIA = 2048; 284 public const int CHANGED_MEDIA = 2048;
284 public const int CHANGED_ANIMATION = 16384; 285 public const int CHANGED_ANIMATION = 16384;
286 public const int CHANGED_POSITION = 32768;
285 public const int TYPE_INVALID = 0; 287 public const int TYPE_INVALID = 0;
286 public const int TYPE_INTEGER = 1; 288 public const int TYPE_INTEGER = 1;
287 public const int TYPE_FLOAT = 2; 289 public const int TYPE_FLOAT = 2;
@@ -586,6 +588,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
586 public const int PRIM_MEDIA_PERM_OWNER = 1; 588 public const int PRIM_MEDIA_PERM_OWNER = 1;
587 public const int PRIM_MEDIA_PERM_GROUP = 2; 589 public const int PRIM_MEDIA_PERM_GROUP = 2;
588 public const int PRIM_MEDIA_PERM_ANYONE = 4; 590 public const int PRIM_MEDIA_PERM_ANYONE = 4;
591
592 public const int PRIM_PHYSICS_SHAPE_TYPE = 30;
593 public const int PRIM_PHYSICS_SHAPE_PRIM = 0;
594 public const int PRIM_PHYSICS_SHAPE_CONVEX = 2;
595 public const int PRIM_PHYSICS_SHAPE_NONE = 1;
596
597 public const int PRIM_PHYSICS_MATERIAL = 31;
598 public const int DENSITY = 1;
599 public const int FRICTION = 2;
600 public const int RESTITUTION = 4;
601 public const int GRAVITY_MULTIPLIER = 8;
589 602
590 // extra constants for llSetPrimMediaParams 603 // extra constants for llSetPrimMediaParams
591 public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0); 604 public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0);
@@ -659,5 +672,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
659 public static readonly LSLInteger RCERR_UNKNOWN = -1; 672 public static readonly LSLInteger RCERR_UNKNOWN = -1;
660 public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2; 673 public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2;
661 public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3; 674 public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3;
675
676 public const int KFM_MODE = 1;
677 public const int KFM_LOOP = 1;
678 public const int KFM_REVERSE = 3;
679 public const int KFM_FORWARD = 0;
680 public const int KFM_PING_PONG = 2;
681 public const int KFM_DATA = 2;
682 public const int KFM_TRANSLATION = 2;
683 public const int KFM_ROTATION = 1;
684 public const int KFM_COMMAND = 0;
685 public const int KFM_CMD_PLAY = 0;
686 public const int KFM_CMD_STOP = 1;
687 public const int KFM_CMD_PAUSE = 2;
662 } 688 }
663} 689}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index c0bf29c..2d23d30 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;
@@ -164,6 +165,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
164 m_LSL_Functions.llBreakLink(linknum); 165 m_LSL_Functions.llBreakLink(linknum);
165 } 166 }
166 167
168 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
169 {
170 return m_LSL_Functions.llCastRay(start, end, options);
171 }
172
167 public LSL_Integer llCeil(double f) 173 public LSL_Integer llCeil(double f)
168 { 174 {
169 return m_LSL_Functions.llCeil(f); 175 return m_LSL_Functions.llCeil(f);
@@ -314,6 +320,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
314 m_LSL_Functions.llDialog(avatar, message, buttons, chat_channel); 320 m_LSL_Functions.llDialog(avatar, message, buttons, chat_channel);
315 } 321 }
316 322
323 [DebuggerNonUserCode]
317 public void llDie() 324 public void llDie()
318 { 325 {
319 m_LSL_Functions.llDie(); 326 m_LSL_Functions.llDie();
@@ -474,6 +481,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
474 return m_LSL_Functions.llGetFreeMemory(); 481 return m_LSL_Functions.llGetFreeMemory();
475 } 482 }
476 483
484 public LSL_Integer llGetUsedMemory()
485 {
486 return m_LSL_Functions.llGetUsedMemory();
487 }
488
477 public LSL_Integer llGetFreeURLs() 489 public LSL_Integer llGetFreeURLs()
478 { 490 {
479 return m_LSL_Functions.llGetFreeURLs(); 491 return m_LSL_Functions.llGetFreeURLs();
@@ -579,6 +591,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
579 return m_LSL_Functions.llGetMass(); 591 return m_LSL_Functions.llGetMass();
580 } 592 }
581 593
594 public LSL_Float llGetMassMKS()
595 {
596 return m_LSL_Functions.llGetMassMKS();
597 }
598
582 public LSL_Integer llGetMemoryLimit() 599 public LSL_Integer llGetMemoryLimit()
583 { 600 {
584 return m_LSL_Functions.llGetMemoryLimit(); 601 return m_LSL_Functions.llGetMemoryLimit();
@@ -844,11 +861,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
844 return m_LSL_Functions.llGetUnixTime(); 861 return m_LSL_Functions.llGetUnixTime();
845 } 862 }
846 863
847 public LSL_Integer llGetUsedMemory()
848 {
849 return m_LSL_Functions.llGetUsedMemory();
850 }
851
852 public LSL_Vector llGetVel() 864 public LSL_Vector llGetVel()
853 { 865 {
854 return m_LSL_Functions.llGetVel(); 866 return m_LSL_Functions.llGetVel();
@@ -874,6 +886,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
874 return m_LSL_Functions.llGiveMoney(destination, amount); 886 return m_LSL_Functions.llGiveMoney(destination, amount);
875 } 887 }
876 888
889 public LSL_String llTransferLindenDollars(string destination, int amount)
890 {
891 return m_LSL_Functions.llTransferLindenDollars(destination, amount);
892 }
893
877 public void llGodLikeRezObject(string inventory, LSL_Vector pos) 894 public void llGodLikeRezObject(string inventory, LSL_Vector pos)
878 { 895 {
879 m_LSL_Functions.llGodLikeRezObject(inventory, pos); 896 m_LSL_Functions.llGodLikeRezObject(inventory, pos);
@@ -1598,6 +1615,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1598 m_LSL_Functions.llSetPos(pos); 1615 m_LSL_Functions.llSetPos(pos);
1599 } 1616 }
1600 1617
1618 public LSL_Integer llSetRegionPos(LSL_Vector pos)
1619 {
1620 return m_LSL_Functions.llSetRegionPos(pos);
1621 }
1622
1601 public void llSetPrimitiveParams(LSL_List rules) 1623 public void llSetPrimitiveParams(LSL_List rules)
1602 { 1624 {
1603 m_LSL_Functions.llSetPrimitiveParams(rules); 1625 m_LSL_Functions.llSetPrimitiveParams(rules);
@@ -1833,6 +1855,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1833 m_LSL_Functions.llTargetRemove(number); 1855 m_LSL_Functions.llTargetRemove(number);
1834 } 1856 }
1835 1857
1858 public void llTeleportAgent(string agent, string simname, LSL_Vector pos, LSL_Vector lookAt)
1859 {
1860 m_LSL_Functions.llTeleportAgent(agent, simname, pos, lookAt);
1861 }
1862
1836 public void llTeleportAgentHome(string agent) 1863 public void llTeleportAgentHome(string agent)
1837 { 1864 {
1838 m_LSL_Functions.llTeleportAgentHome(agent); 1865 m_LSL_Functions.llTeleportAgentHome(agent);
@@ -1948,9 +1975,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1948 return m_LSL_Functions.llClearLinkMedia(link, face); 1975 return m_LSL_Functions.llClearLinkMedia(link, face);
1949 } 1976 }
1950 1977
1951 public void print(string str) 1978 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
1979 {
1980 return m_LSL_Functions.llGetLinkNumberOfSides(link);
1981 }
1982
1983 public void llSetKeyframedMotion(LSL_List frames, LSL_List options)
1984 {
1985 m_LSL_Functions.llSetKeyframedMotion(frames, options);
1986 }
1987
1988 public void llSetPhysicsMaterial(int material_bits, float material_gravity_modifier, float material_restitution, float material_friction, float material_density)
1952 { 1989 {
1953 m_LSL_Functions.print(str); 1990 m_LSL_Functions.llSetPhysicsMaterial(material_bits, material_gravity_modifier, material_restitution, material_friction, material_density);
1954 } 1991 }
1955 } 1992 }
1956} 1993}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
index 143b497..2e27f16 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LS_Stub.cs
@@ -72,9 +72,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
72 { 72 {
73 return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target); 73 return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target);
74 } 74 }
75
75 public void lsClearWindlightScene() 76 public void lsClearWindlightScene()
76 { 77 {
77 m_LS_Functions.lsClearWindlightScene(); 78 m_LS_Functions.lsClearWindlightScene();
78 } 79 }
80
81 public LSL_List cmGetWindlightScene(LSL_List rules)
82 {
83 return m_LS_Functions.lsGetWindlightScene(rules);
84 }
85
86 public int cmSetWindlightScene(LSL_List rules)
87 {
88 return m_LS_Functions.lsSetWindlightScene(rules);
89 }
90
91 public int cmSetWindlightSceneTargeted(LSL_List rules, key target)
92 {
93 return m_LS_Functions.lsSetWindlightSceneTargeted(rules, target);
94 }
95
96 public void cmClearWindlightScene()
97 {
98 m_LS_Functions.lsClearWindlightScene();
99 }
79 } 100 }
80} 101}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
index edbbc2a..b138da3 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
@@ -33,6 +33,7 @@ using System.Threading;
33using System.Reflection; 33using System.Reflection;
34using System.Collections; 34using System.Collections;
35using System.Collections.Generic; 35using System.Collections.Generic;
36using System.Diagnostics; //for [DebuggerNonUserCode]
36using OpenSim.Region.ScriptEngine.Interfaces; 37using OpenSim.Region.ScriptEngine.Interfaces;
37using OpenSim.Region.ScriptEngine.Shared; 38using OpenSim.Region.ScriptEngine.Shared;
38using OpenSim.Region.ScriptEngine.Shared.Api.Runtime; 39using OpenSim.Region.ScriptEngine.Shared.Api.Runtime;
@@ -90,6 +91,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
90 return (int)m_Executor.GetStateEventFlags(state); 91 return (int)m_Executor.GetStateEventFlags(state);
91 } 92 }
92 93
94 [DebuggerNonUserCode]
93 public void ExecuteEvent(string state, string FunctionName, object[] args) 95 public void ExecuteEvent(string state, string FunctionName, object[] args)
94 { 96 {
95 m_Executor.ExecuteEvent(state, FunctionName, args); 97 m_Executor.ExecuteEvent(state, FunctionName, args);