aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs11
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs601
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs593
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs13
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs6
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs13
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs21
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs45
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Helpers.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs6
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs31
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs232
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs229
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/EventManager.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs9
17 files changed, 1404 insertions, 426 deletions
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
index 8b7871b..0cc0fe7 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
@@ -58,7 +58,11 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
58 /// </summary> 58 /// </summary>
59 public interface IScriptInstance 59 public interface IScriptInstance
60 { 60 {
61 /// <summary>
62 /// Is this script currently running?
63 /// </summary>
61 bool Running { get; set; } 64 bool Running { get; set; }
65
62 bool ShuttingDown { get; set; } 66 bool ShuttingDown { get; set; }
63 string State { get; set; } 67 string State { get; set; }
64 IScriptEngine Engine { get; } 68 IScriptEngine Engine { get; }
@@ -78,7 +82,14 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
78 82
79 void Init(); 83 void Init();
80 void Start(); 84 void Start();
85
86 /// <summary>
87 /// Stop the script.
88 /// </summary>
89 /// <param name="timeout"></param>
90 /// <returns>true if the script was successfully stopped, false otherwise</returns>
81 bool Stop(int timeout); 91 bool Stop(int timeout);
92
82 void SetState(string state); 93 void SetState(string state);
83 94
84 void PostEvent(EventParams data); 95 void PostEvent(EventParams data);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index ecfac6f..bf791a9 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -303,35 +303,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
303 switch (linkType) 303 switch (linkType)
304 { 304 {
305 case ScriptBaseClass.LINK_SET: 305 case ScriptBaseClass.LINK_SET:
306 if (m_host.ParentGroup != null) 306 return new List<SceneObjectPart>(m_host.ParentGroup.Parts);
307 {
308 return new List<SceneObjectPart>(m_host.ParentGroup.Parts);
309 }
310 return ret;
311 307
312 case ScriptBaseClass.LINK_ROOT: 308 case ScriptBaseClass.LINK_ROOT:
313 if (m_host.ParentGroup != null) 309 ret = new List<SceneObjectPart>();
314 { 310 ret.Add(m_host.ParentGroup.RootPart);
315 ret = new List<SceneObjectPart>();
316 ret.Add(m_host.ParentGroup.RootPart);
317 return ret;
318 }
319 return ret; 311 return ret;
320 312
321 case ScriptBaseClass.LINK_ALL_OTHERS: 313 case ScriptBaseClass.LINK_ALL_OTHERS:
322 if (m_host.ParentGroup == null)
323 return new List<SceneObjectPart>();
324
325 ret = new List<SceneObjectPart>(m_host.ParentGroup.Parts); 314 ret = new List<SceneObjectPart>(m_host.ParentGroup.Parts);
326 315
327 if (ret.Contains(m_host)) 316 if (ret.Contains(m_host))
328 ret.Remove(m_host); 317 ret.Remove(m_host);
318
329 return ret; 319 return ret;
330 320
331 case ScriptBaseClass.LINK_ALL_CHILDREN: 321 case ScriptBaseClass.LINK_ALL_CHILDREN:
332 if (m_host.ParentGroup == null)
333 return new List<SceneObjectPart>();
334
335 ret = new List<SceneObjectPart>(m_host.ParentGroup.Parts); 322 ret = new List<SceneObjectPart>(m_host.ParentGroup.Parts);
336 323
337 if (ret.Contains(m_host.ParentGroup.RootPart)) 324 if (ret.Contains(m_host.ParentGroup.RootPart))
@@ -342,15 +329,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
342 return ret; 329 return ret;
343 330
344 default: 331 default:
345 if (linkType < 0 || m_host.ParentGroup == null) 332 if (linkType < 0)
346 return new List<SceneObjectPart>(); 333 return new List<SceneObjectPart>();
334
347 SceneObjectPart target = m_host.ParentGroup.GetLinkNumPart(linkType); 335 SceneObjectPart target = m_host.ParentGroup.GetLinkNumPart(linkType);
348 if (target == null) 336 if (target == null)
349 return new List<SceneObjectPart>(); 337 return new List<SceneObjectPart>();
350 ret = new List<SceneObjectPart>(); 338 ret = new List<SceneObjectPart>();
351 ret.Add(target); 339 ret.Add(target);
352 return ret; 340 return ret;
353
354 } 341 }
355 } 342 }
356 343
@@ -450,7 +437,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
450 } 437 }
451 438
452 // convert a LSL_Rotation to a Quaternion 439 // convert a LSL_Rotation to a Quaternion
453 protected Quaternion Rot2Quaternion(LSL_Rotation r) 440 public static Quaternion Rot2Quaternion(LSL_Rotation r)
454 { 441 {
455 Quaternion q = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s); 442 Quaternion q = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
456 q.Normalize(); 443 q.Normalize();
@@ -957,6 +944,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
957 wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text); 944 wComm.DeliverMessage(ChatTypeEnum.Region, channelID, m_host.Name, m_host.UUID, text);
958 } 945 }
959 946
947 public void llRegionSayTo(string target, int channel, string msg)
948 {
949 string error = String.Empty;
950
951 if (msg.Length > 1023)
952 msg = msg.Substring(0, 1023);
953
954 m_host.AddScriptLPS(1);
955
956 UUID TargetID;
957 UUID.TryParse(target, out TargetID);
958
959 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
960 if (wComm != null)
961 if (!wComm.DeliverMessageTo(TargetID, channel, m_host.AbsolutePosition, m_host.Name, m_host.UUID, msg, out error))
962 LSLError(error);
963 }
964
960 public LSL_Integer llListen(int channelID, string name, string ID, string msg) 965 public LSL_Integer llListen(int channelID, string name, string ID, string msg)
961 { 966 {
962 m_host.AddScriptLPS(1); 967 m_host.AddScriptLPS(1);
@@ -1298,8 +1303,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1298 if (value != 0) 1303 if (value != 0)
1299 { 1304 {
1300 SceneObjectGroup group = m_host.ParentGroup; 1305 SceneObjectGroup group = m_host.ParentGroup;
1301 if (group == null)
1302 return;
1303 bool allow = true; 1306 bool allow = true;
1304 1307
1305 foreach (SceneObjectPart part in group.Parts) 1308 foreach (SceneObjectPart part in group.Parts)
@@ -1313,18 +1316,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1313 1316
1314 if (!allow) 1317 if (!allow)
1315 return; 1318 return;
1319
1316 m_host.ScriptSetPhysicsStatus(true); 1320 m_host.ScriptSetPhysicsStatus(true);
1317 } 1321 }
1318 else 1322 else
1323 {
1319 m_host.ScriptSetPhysicsStatus(false); 1324 m_host.ScriptSetPhysicsStatus(false);
1325 }
1320 } 1326 }
1321 1327
1322 if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM) 1328 if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM)
1323 { 1329 {
1324 if (value != 0) 1330 m_host.ParentGroup.ScriptSetPhantomStatus(value != 0);
1325 m_host.ScriptSetPhantomStatus(true);
1326 else
1327 m_host.ScriptSetPhantomStatus(false);
1328 } 1331 }
1329 1332
1330 if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS) 1333 if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS)
@@ -1466,8 +1469,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1466 protected void SetScale(SceneObjectPart part, LSL_Vector scale) 1469 protected void SetScale(SceneObjectPart part, LSL_Vector scale)
1467 { 1470 {
1468 // TODO: this needs to trigger a persistance save as well 1471 // TODO: this needs to trigger a persistance save as well
1469 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) 1472 if (part == null || part.ParentGroup.IsDeleted)
1470 return; 1473 return;
1474
1471 if (scale.x < 0.01) 1475 if (scale.x < 0.01)
1472 scale.x = 0.01; 1476 scale.x = 0.01;
1473 if (scale.y < 0.01) 1477 if (scale.y < 0.01)
@@ -1510,7 +1514,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1510 { 1514 {
1511 m_host.AddScriptLPS(1); 1515 m_host.AddScriptLPS(1);
1512 m_host.ClickAction = (byte)action; 1516 m_host.ClickAction = (byte)action;
1513 if (m_host.ParentGroup != null) m_host.ParentGroup.HasGroupChanged = true; 1517 m_host.ParentGroup.HasGroupChanged = true;
1514 m_host.ScheduleFullUpdate(); 1518 m_host.ScheduleFullUpdate();
1515 return; 1519 return;
1516 } 1520 }
@@ -1786,9 +1790,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1786 tex.FaceTextures[i].RGBA = texcolor; 1790 tex.FaceTextures[i].RGBA = texcolor;
1787 } 1791 }
1788 } 1792 }
1789 texcolor = tex.DefaultTexture.RGBA; 1793
1790 texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f); 1794 // In some cases, the default texture can be null, eg when every face
1791 tex.DefaultTexture.RGBA = texcolor; 1795 // has a unique texture
1796 if (tex.DefaultTexture != null)
1797 {
1798 texcolor = tex.DefaultTexture.RGBA;
1799 texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
1800 tex.DefaultTexture.RGBA = texcolor;
1801 }
1802
1792 part.UpdateTexture(tex); 1803 part.UpdateTexture(tex);
1793 return; 1804 return;
1794 } 1805 }
@@ -2149,7 +2160,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2149 2160
2150 if (part.ParentGroup.RootPart == part) 2161 if (part.ParentGroup.RootPart == part)
2151 { 2162 {
2152 if ((targetPos.z < ground) && disable_underground_movement && m_host.AttachmentPoint == 0) 2163 if ((targetPos.z < ground) && disable_underground_movement && m_host.ParentGroup.AttachmentPoint == 0)
2153 targetPos.z = ground; 2164 targetPos.z = ground;
2154 } 2165 }
2155 LSL_Vector real_vec = SetPosAdjust(fromPos, targetPos); 2166 LSL_Vector real_vec = SetPosAdjust(fromPos, targetPos);
@@ -2236,14 +2247,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2236 else 2247 else
2237 { 2248 {
2238 // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask. 2249 // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
2239 SceneObjectGroup group = m_host.ParentGroup; 2250 SceneObjectPart rootPart = m_host.ParentGroup.RootPart;
2240 if (group != null) // a bit paranoid, maybe 2251 if (rootPart != null) // better safe than sorry
2241 { 2252 {
2242 SceneObjectPart rootPart = group.RootPart; 2253 SetRot(m_host, rootPart.RotationOffset * Rot2Quaternion(rot));
2243 if (rootPart != null) // again, better safe than sorry
2244 {
2245 SetRot(m_host, rootPart.RotationOffset * Rot2Quaternion(rot));
2246 }
2247 } 2254 }
2248 } 2255 }
2249 2256
@@ -2292,6 +2299,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2292 { 2299 {
2293 return llGetRootRotation(); 2300 return llGetRootRotation();
2294 } 2301 }
2302
2295 m_host.AddScriptLPS(1); 2303 m_host.AddScriptLPS(1);
2296 Quaternion q = m_host.GetWorldRotation(); 2304 Quaternion q = m_host.GetWorldRotation();
2297 return new LSL_Rotation(q.X, q.Y, q.Z, q.W); 2305 return new LSL_Rotation(q.X, q.Y, q.Z, q.W);
@@ -2302,9 +2310,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2302 Quaternion q; 2310 Quaternion q;
2303 if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim 2311 if (part.LinkNum == 0 || part.LinkNum == 1) // unlinked or root prim
2304 { 2312 {
2305 if (part.ParentGroup.RootPart.AttachmentPoint != 0) 2313 if (part.ParentGroup.AttachmentPoint != 0)
2306 { 2314 {
2307 ScenePresence avatar = World.GetScenePresence(part.AttachedAvatar); 2315 ScenePresence avatar = World.GetScenePresence(part.ParentGroup.AttachedAvatar);
2308 if (avatar != null) 2316 if (avatar != null)
2309 { 2317 {
2310 if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0) 2318 if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
@@ -2333,15 +2341,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2333 { 2341 {
2334 m_host.AddScriptLPS(1); 2342 m_host.AddScriptLPS(1);
2335 2343
2336 if (m_host.ParentGroup != null) 2344 if (!m_host.ParentGroup.IsDeleted)
2337 { 2345 {
2338 if (!m_host.ParentGroup.IsDeleted) 2346 if (local != 0)
2339 { 2347 force *= llGetRot();
2340 if (local != 0)
2341 force *= llGetRot();
2342 2348
2343 m_host.ParentGroup.RootPart.SetForce(new Vector3((float)force.x, (float)force.y, (float)force.z)); 2349 m_host.ParentGroup.RootPart.SetForce(new Vector3((float)force.x, (float)force.y, (float)force.z));
2344 }
2345 } 2350 }
2346 } 2351 }
2347 2352
@@ -2351,15 +2356,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2351 2356
2352 m_host.AddScriptLPS(1); 2357 m_host.AddScriptLPS(1);
2353 2358
2354 if (m_host.ParentGroup != null) 2359 if (!m_host.ParentGroup.IsDeleted)
2355 { 2360 {
2356 if (!m_host.ParentGroup.IsDeleted) 2361 Vector3 tmpForce = m_host.ParentGroup.RootPart.GetForce();
2357 { 2362 force.x = tmpForce.X;
2358 Vector3 tmpForce = m_host.ParentGroup.RootPart.GetForce(); 2363 force.y = tmpForce.Y;
2359 force.x = tmpForce.X; 2364 force.z = tmpForce.Z;
2360 force.y = tmpForce.Y;
2361 force.z = tmpForce.Z;
2362 }
2363 } 2365 }
2364 2366
2365 return force; 2367 return force;
@@ -2368,25 +2370,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2368 public LSL_Integer llTarget(LSL_Vector position, double range) 2370 public LSL_Integer llTarget(LSL_Vector position, double range)
2369 { 2371 {
2370 m_host.AddScriptLPS(1); 2372 m_host.AddScriptLPS(1);
2371 return m_host.registerTargetWaypoint(new Vector3((float)position.x, (float)position.y, (float)position.z), (float)range); 2373 return m_host.ParentGroup.registerTargetWaypoint(
2374 new Vector3((float)position.x, (float)position.y, (float)position.z), (float)range);
2372 } 2375 }
2373 2376
2374 public void llTargetRemove(int number) 2377 public void llTargetRemove(int number)
2375 { 2378 {
2376 m_host.AddScriptLPS(1); 2379 m_host.AddScriptLPS(1);
2377 m_host.unregisterTargetWaypoint(number); 2380 m_host.ParentGroup.unregisterTargetWaypoint(number);
2378 } 2381 }
2379 2382
2380 public LSL_Integer llRotTarget(LSL_Rotation rot, double error) 2383 public LSL_Integer llRotTarget(LSL_Rotation rot, double error)
2381 { 2384 {
2382 m_host.AddScriptLPS(1); 2385 m_host.AddScriptLPS(1);
2383 return m_host.registerRotTargetWaypoint(new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s), (float)error); 2386 return m_host.ParentGroup.registerRotTargetWaypoint(
2387 new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s), (float)error);
2384 } 2388 }
2385 2389
2386 public void llRotTargetRemove(int number) 2390 public void llRotTargetRemove(int number)
2387 { 2391 {
2388 m_host.AddScriptLPS(1); 2392 m_host.AddScriptLPS(1);
2389 m_host.unregisterRotTargetWaypoint(number); 2393 m_host.ParentGroup.unregisterRotTargetWaypoint(number);
2390 } 2394 }
2391 2395
2392 public void llMoveToTarget(LSL_Vector target, double tau) 2396 public void llMoveToTarget(LSL_Vector target, double tau)
@@ -2429,7 +2433,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2429 public LSL_Vector llGetTorque() 2433 public LSL_Vector llGetTorque()
2430 { 2434 {
2431 m_host.AddScriptLPS(1); 2435 m_host.AddScriptLPS(1);
2432 Vector3 torque = m_host.GetTorque(); 2436 Vector3 torque = m_host.ParentGroup.GetTorque();
2433 return new LSL_Vector(torque.X,torque.Y,torque.Z); 2437 return new LSL_Vector(torque.X,torque.Y,torque.Z);
2434 } 2438 }
2435 2439
@@ -2443,7 +2447,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2443 public LSL_Vector llGetVel() 2447 public LSL_Vector llGetVel()
2444 { 2448 {
2445 m_host.AddScriptLPS(1); 2449 m_host.AddScriptLPS(1);
2446 return new LSL_Vector(m_host.Velocity.X, m_host.Velocity.Y, m_host.Velocity.Z); 2450
2451 Vector3 vel;
2452
2453 if (m_host.ParentGroup.IsAttachment)
2454 {
2455 ScenePresence avatar = m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
2456 vel = avatar.Velocity;
2457 }
2458 else
2459 {
2460 vel = m_host.Velocity;
2461 }
2462
2463 return new LSL_Vector(vel.X, vel.Y, vel.Z);
2447 } 2464 }
2448 2465
2449 public LSL_Vector llGetAccel() 2466 public LSL_Vector llGetAccel()
@@ -2739,10 +2756,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2739 /// negative (indicating end-relative) and may be inverted, 2756 /// negative (indicating end-relative) and may be inverted,
2740 /// i.e. end < start. 2757 /// i.e. end < start.
2741 /// </summary> 2758 /// </summary>
2742
2743 public LSL_String llDeleteSubString(string src, int start, int end) 2759 public LSL_String llDeleteSubString(string src, int start, int end)
2744 { 2760 {
2745
2746 m_host.AddScriptLPS(1); 2761 m_host.AddScriptLPS(1);
2747 2762
2748 // Normalize indices (if negative). 2763 // Normalize indices (if negative).
@@ -2822,10 +2837,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2822 /// which case it is end-relative. The index may exceed either 2837 /// which case it is end-relative. The index may exceed either
2823 /// string bound, with the result being a concatenation. 2838 /// string bound, with the result being a concatenation.
2824 /// </summary> 2839 /// </summary>
2825
2826 public LSL_String llInsertString(string dest, int index, string src) 2840 public LSL_String llInsertString(string dest, int index, string src)
2827 { 2841 {
2828
2829 m_host.AddScriptLPS(1); 2842 m_host.AddScriptLPS(1);
2830 2843
2831 // Normalize indices (if negative). 2844 // Normalize indices (if negative).
@@ -2983,8 +2996,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2983 // If either of these are null, then there was an unknown error. 2996 // If either of these are null, then there was an unknown error.
2984 if (new_group == null) 2997 if (new_group == null)
2985 continue; 2998 continue;
2986 if (new_group.RootPart == null)
2987 continue;
2988 2999
2989 // objects rezzed with this method are die_at_edge by default. 3000 // objects rezzed with this method are die_at_edge by default.
2990 new_group.RootPart.SetDieAtEdge(true); 3001 new_group.RootPart.SetDieAtEdge(true);
@@ -3248,7 +3259,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3248 { 3259 {
3249 m_host.AddScriptLPS(1); 3260 m_host.AddScriptLPS(1);
3250 3261
3251 if (m_host.ParentGroup.RootPart.AttachmentPoint == 0) 3262 if (m_host.ParentGroup.AttachmentPoint == 0)
3252 return; 3263 return;
3253 3264
3254 TaskInventoryItem item; 3265 TaskInventoryItem item;
@@ -3288,7 +3299,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3288 3299
3289 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; 3300 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3290 if (attachmentsModule != null) 3301 if (attachmentsModule != null)
3291 attachmentsModule.ShowDetachInUserInventory(itemID, presence.ControllingClient); 3302 attachmentsModule.DetachSingleAttachmentToInv(itemID, presence.ControllingClient);
3292 } 3303 }
3293 3304
3294 public void llTakeCamera(string avatar) 3305 public void llTakeCamera(string avatar)
@@ -3449,12 +3460,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3449 public void llSetBuoyancy(double buoyancy) 3460 public void llSetBuoyancy(double buoyancy)
3450 { 3461 {
3451 m_host.AddScriptLPS(1); 3462 m_host.AddScriptLPS(1);
3452 if (m_host.ParentGroup != null) 3463
3464 if (!m_host.ParentGroup.IsDeleted)
3453 { 3465 {
3454 if (!m_host.ParentGroup.IsDeleted) 3466 m_host.ParentGroup.RootPart.SetBuoyancy((float)buoyancy);
3455 {
3456 m_host.ParentGroup.RootPart.Buoyancy = (float)buoyancy;
3457 }
3458 } 3467 }
3459 } 3468 }
3460 3469
@@ -3683,7 +3692,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3683 3692
3684 m_host.AddScriptLPS(1); 3693 m_host.AddScriptLPS(1);
3685 3694
3686 if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.RootPart.AttachedAvatar) 3695 if (m_host.ParentGroup.IsAttachment && (UUID)agent == m_host.ParentGroup.AttachedAvatar)
3687 { 3696 {
3688 // When attached, certain permissions are implicit if requested from owner 3697 // When attached, certain permissions are implicit if requested from owner
3689 int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS | 3698 int implicitPerms = ScriptBaseClass.PERMISSION_TAKE_CONTROLS |
@@ -3909,7 +3918,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3909 3918
3910 SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID); 3919 SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID);
3911 3920
3912 if (targetPart.ParentGroup.RootPart.AttachmentPoint != 0) 3921 if (targetPart.ParentGroup.AttachmentPoint != 0)
3913 return; // Fail silently if attached 3922 return; // Fail silently if attached
3914 3923
3915 if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID) 3924 if (targetPart.ParentGroup.RootPart.OwnerID != m_host.ParentGroup.RootPart.OwnerID)
@@ -3967,7 +3976,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3967 3976
3968 SceneObjectGroup parentPrim = m_host.ParentGroup; 3977 SceneObjectGroup parentPrim = m_host.ParentGroup;
3969 3978
3970 if (parentPrim.RootPart.AttachmentPoint != 0) 3979 if (parentPrim.AttachmentPoint != 0)
3971 return; // Fail silently if attached 3980 return; // Fail silently if attached
3972 SceneObjectPart childPrim = null; 3981 SceneObjectPart childPrim = null;
3973 3982
@@ -4075,7 +4084,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4075 } 4084 }
4076 4085
4077 SceneObjectGroup parentPrim = m_host.ParentGroup; 4086 SceneObjectGroup parentPrim = m_host.ParentGroup;
4078 if (parentPrim.RootPart.AttachmentPoint != 0) 4087 if (parentPrim.AttachmentPoint != 0)
4079 return; // Fail silently if attached 4088 return; // Fail silently if attached
4080 4089
4081 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts); 4090 List<SceneObjectPart> parts = new List<SceneObjectPart>(parentPrim.Parts);
@@ -4311,7 +4320,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4311 GridInstantMessage msg = new GridInstantMessage(World, 4320 GridInstantMessage msg = new GridInstantMessage(World,
4312 m_host.UUID, m_host.Name+", an object owned by "+ 4321 m_host.UUID, m_host.Name+", an object owned by "+
4313 resolveName(m_host.OwnerID)+",", destId, 4322 resolveName(m_host.OwnerID)+",", destId,
4314 (byte)InstantMessageDialog.InventoryOffered, 4323 (byte)InstantMessageDialog.TaskInventoryOffered,
4315 false, objName+"\n"+m_host.Name+" is located at "+ 4324 false, objName+"\n"+m_host.Name+" is located at "+
4316 World.RegionInfo.RegionName+" "+ 4325 World.RegionInfo.RegionName+" "+
4317 m_host.AbsolutePosition.ToString(), 4326 m_host.AbsolutePosition.ToString(),
@@ -4749,7 +4758,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4749 return; 4758 return;
4750 4759
4751 // Object not pushable. Not an attachment and has no physics component 4760 // Object not pushable. Not an attachment and has no physics component
4752 if (!pusheeob.IsAttachment && pusheeob.PhysActor == null) 4761 if (!pusheeob.ParentGroup.IsAttachment && pusheeob.PhysActor == null)
4753 return; 4762 return;
4754 4763
4755 PusheePos = pusheeob.AbsolutePosition; 4764 PusheePos = pusheeob.AbsolutePosition;
@@ -6279,7 +6288,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6279 public LSL_Integer llGetAttached() 6288 public LSL_Integer llGetAttached()
6280 { 6289 {
6281 m_host.AddScriptLPS(1); 6290 m_host.AddScriptLPS(1);
6282 return m_host.ParentGroup.RootPart.AttachmentPoint; 6291 return m_host.ParentGroup.AttachmentPoint;
6283 } 6292 }
6284 6293
6285 public virtual LSL_Integer llGetFreeMemory() 6294 public virtual LSL_Integer llGetFreeMemory()
@@ -6663,12 +6672,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6663 public void llSetVehicleType(int type) 6672 public void llSetVehicleType(int type)
6664 { 6673 {
6665 m_host.AddScriptLPS(1); 6674 m_host.AddScriptLPS(1);
6666 if (m_host.ParentGroup != null) 6675
6676 if (!m_host.ParentGroup.IsDeleted)
6667 { 6677 {
6668 if (!m_host.ParentGroup.IsDeleted) 6678 m_host.ParentGroup.RootPart.SetVehicleType(type);
6669 {
6670 m_host.ParentGroup.RootPart.SetVehicleType(type);
6671 }
6672 } 6679 }
6673 } 6680 }
6674 6681
@@ -6678,12 +6685,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6678 { 6685 {
6679 m_host.AddScriptLPS(1); 6686 m_host.AddScriptLPS(1);
6680 6687
6681 if (m_host.ParentGroup != null) 6688 if (!m_host.ParentGroup.IsDeleted)
6682 { 6689 {
6683 if (!m_host.ParentGroup.IsDeleted) 6690 m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
6684 {
6685 m_host.ParentGroup.RootPart.SetVehicleFloatParam(param, (float)value);
6686 }
6687 } 6691 }
6688 } 6692 }
6689 6693
@@ -6692,13 +6696,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6692 public void llSetVehicleVectorParam(int param, LSL_Vector vec) 6696 public void llSetVehicleVectorParam(int param, LSL_Vector vec)
6693 { 6697 {
6694 m_host.AddScriptLPS(1); 6698 m_host.AddScriptLPS(1);
6695 if (m_host.ParentGroup != null) 6699
6700 if (!m_host.ParentGroup.IsDeleted)
6696 { 6701 {
6697 if (!m_host.ParentGroup.IsDeleted) 6702 m_host.ParentGroup.RootPart.SetVehicleVectorParam(param,
6698 { 6703 new Vector3((float)vec.x, (float)vec.y, (float)vec.z));
6699 m_host.ParentGroup.RootPart.SetVehicleVectorParam(param,
6700 new Vector3((float)vec.x, (float)vec.y, (float)vec.z));
6701 }
6702 } 6704 }
6703 } 6705 }
6704 6706
@@ -6707,37 +6709,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6707 public void llSetVehicleRotationParam(int param, LSL_Rotation rot) 6709 public void llSetVehicleRotationParam(int param, LSL_Rotation rot)
6708 { 6710 {
6709 m_host.AddScriptLPS(1); 6711 m_host.AddScriptLPS(1);
6710 if (m_host.ParentGroup != null) 6712
6713 if (!m_host.ParentGroup.IsDeleted)
6711 { 6714 {
6712 if (!m_host.ParentGroup.IsDeleted) 6715 m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, Rot2Quaternion(rot));
6713 {
6714 m_host.ParentGroup.RootPart.SetVehicleRotationParam(param,
6715 Rot2Quaternion(rot));
6716 }
6717 } 6716 }
6718 } 6717 }
6719 6718
6720 public void llSetVehicleFlags(int flags) 6719 public void llSetVehicleFlags(int flags)
6721 { 6720 {
6722 m_host.AddScriptLPS(1); 6721 m_host.AddScriptLPS(1);
6723 if (m_host.ParentGroup != null) 6722
6723 if (!m_host.ParentGroup.IsDeleted)
6724 { 6724 {
6725 if (!m_host.ParentGroup.IsDeleted) 6725 m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
6726 {
6727 m_host.ParentGroup.RootPart.SetVehicleFlags(flags, false);
6728 }
6729 } 6726 }
6730 } 6727 }
6731 6728
6732 public void llRemoveVehicleFlags(int flags) 6729 public void llRemoveVehicleFlags(int flags)
6733 { 6730 {
6734 m_host.AddScriptLPS(1); 6731 m_host.AddScriptLPS(1);
6735 if (m_host.ParentGroup != null) 6732
6733 if (!m_host.ParentGroup.IsDeleted)
6736 { 6734 {
6737 if (!m_host.ParentGroup.IsDeleted) 6735 m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
6738 {
6739 m_host.ParentGroup.RootPart.SetVehicleFlags(flags, true);
6740 }
6741 } 6736 }
6742 } 6737 }
6743 6738
@@ -6891,20 +6886,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6891 public void llVolumeDetect(int detect) 6886 public void llVolumeDetect(int detect)
6892 { 6887 {
6893 m_host.AddScriptLPS(1); 6888 m_host.AddScriptLPS(1);
6894 if (m_host.ParentGroup != null) 6889
6895 { 6890 if (!m_host.ParentGroup.IsDeleted)
6896 if (!m_host.ParentGroup.IsDeleted) 6891 m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0);
6897 {
6898 m_host.ParentGroup.RootPart.ScriptSetVolumeDetect(detect!=0);
6899 }
6900 }
6901 } 6892 }
6902 6893
6903 /// <summary> 6894 /// <summary>
6904 /// This is a depecated function so this just replicates the result of 6895 /// This is a depecated function so this just replicates the result of
6905 /// invoking it in SL 6896 /// invoking it in SL
6906 /// </summary> 6897 /// </summary>
6907
6908 public void llRemoteLoadScript(string target, string name, int running, int start_param) 6898 public void llRemoteLoadScript(string target, string name, int running, int start_param)
6909 { 6899 {
6910 m_host.AddScriptLPS(1); 6900 m_host.AddScriptLPS(1);
@@ -7046,7 +7036,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7046 return Util.SHA1Hash(src, Encoding.UTF8).ToLower(); 7036 return Util.SHA1Hash(src, Encoding.UTF8).ToLower();
7047 } 7037 }
7048 7038
7049 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist) 7039 protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)
7050 { 7040 {
7051 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); 7041 ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
7052 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) 7042 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
@@ -7059,7 +7049,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7059 { 7049 {
7060 holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT; 7050 holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
7061 } 7051 }
7062 shapeBlock.ProfileCurve = (byte)holeshape; 7052 shapeBlock.PathCurve = pathcurve;
7053 shapeBlock.ProfileCurve = (byte)holeshape; // Set the hole shape.
7054 shapeBlock.ProfileCurve += profileshape; // Add in the profile shape.
7063 if (cut.x < 0f) 7055 if (cut.x < 0f)
7064 { 7056 {
7065 cut.x = 0f; 7057 cut.x = 0f;
@@ -7091,9 +7083,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7091 { 7083 {
7092 hollow = 0f; 7084 hollow = 0f;
7093 } 7085 }
7094 if (hollow > 0.95) 7086 // If the prim is a Cylinder, Prism, Sphere, Torus or Ring (or not a
7087 // Box or Tube) and the hole shape is a square, hollow is limited to
7088 // a max of 70%. The viewer performs its own check on this value but
7089 // we need to do it here also so llGetPrimitiveParams can have access
7090 // to the correct value.
7091 if (profileshape != (byte)ProfileCurve.Square &&
7092 holeshape == (int)ScriptBaseClass.PRIM_HOLE_SQUARE)
7095 { 7093 {
7096 hollow = 0.95f; 7094 if (hollow > 0.70f)
7095 {
7096 hollow = 0.70f;
7097 }
7098 }
7099 // Otherwise, hollow is limited to 95%.
7100 else
7101 {
7102 if (hollow > 0.95f)
7103 {
7104 hollow = 0.95f;
7105 }
7097 } 7106 }
7098 shapeBlock.ProfileHollow = (ushort)(50000 * hollow); 7107 shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
7099 if (twist.x < -1.0f) 7108 if (twist.x < -1.0f)
@@ -7117,23 +7126,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7117 7126
7118 shapeBlock.ObjectLocalID = part.LocalId; 7127 shapeBlock.ObjectLocalID = part.LocalId;
7119 7128
7120 // retain pathcurve
7121 shapeBlock.PathCurve = part.Shape.PathCurve;
7122
7123 part.Shape.SculptEntry = false; 7129 part.Shape.SculptEntry = false;
7124 return shapeBlock; 7130 return shapeBlock;
7125 } 7131 }
7126 7132
7127 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge) 7133 // Prim type box, cylinder and prism.
7134 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)
7128 { 7135 {
7129 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) 7136 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7130 return; 7137 return;
7131 7138
7132 ObjectShapePacket.ObjectDataBlock shapeBlock; 7139 ObjectShapePacket.ObjectDataBlock shapeBlock;
7133 7140
7134 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7141 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
7135
7136 shapeBlock.ProfileCurve += fudge;
7137 7142
7138 if (taper_b.x < 0f) 7143 if (taper_b.x < 0f)
7139 { 7144 {
@@ -7176,21 +7181,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7176 part.UpdateShape(shapeBlock); 7181 part.UpdateShape(shapeBlock);
7177 } 7182 }
7178 7183
7179 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge) 7184 // Prim type sphere.
7185 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte profileshape, byte pathcurve)
7180 { 7186 {
7181 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) 7187 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7182 return; 7188 return;
7183 7189
7184 ObjectShapePacket.ObjectDataBlock shapeBlock; 7190 ObjectShapePacket.ObjectDataBlock shapeBlock;
7185 7191
7186 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7192 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
7187 7193
7188 // profile/path swapped for a sphere 7194 // profile/path swapped for a sphere
7189 shapeBlock.PathBegin = shapeBlock.ProfileBegin; 7195 shapeBlock.PathBegin = shapeBlock.ProfileBegin;
7190 shapeBlock.PathEnd = shapeBlock.ProfileEnd; 7196 shapeBlock.PathEnd = shapeBlock.ProfileEnd;
7191 7197
7192 shapeBlock.ProfileCurve += fudge;
7193
7194 shapeBlock.PathScaleX = 100; 7198 shapeBlock.PathScaleX = 100;
7195 shapeBlock.PathScaleY = 100; 7199 shapeBlock.PathScaleY = 100;
7196 7200
@@ -7221,16 +7225,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7221 part.UpdateShape(shapeBlock); 7225 part.UpdateShape(shapeBlock);
7222 } 7226 }
7223 7227
7224 protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector holesize, LSL_Vector topshear, LSL_Vector profilecut, LSL_Vector taper_a, float revolutions, float radiusoffset, float skew, byte fudge) 7228 // Prim type torus, tube and ring.
7229 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)
7225 { 7230 {
7226 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) 7231 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7227 return; 7232 return;
7228 7233
7229 ObjectShapePacket.ObjectDataBlock shapeBlock; 7234 ObjectShapePacket.ObjectDataBlock shapeBlock;
7230 7235
7231 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist); 7236 shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve);
7232
7233 shapeBlock.ProfileCurve += fudge;
7234 7237
7235 // profile/path swapped for a torrus, tube, ring 7238 // profile/path swapped for a torrus, tube, ring
7236 shapeBlock.PathBegin = shapeBlock.ProfileBegin; 7239 shapeBlock.PathBegin = shapeBlock.ProfileBegin;
@@ -7350,7 +7353,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7350 part.UpdateShape(shapeBlock); 7353 part.UpdateShape(shapeBlock);
7351 } 7354 }
7352 7355
7353 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type) 7356 // Prim type sculpt.
7357 protected void SetPrimitiveShapeParams(SceneObjectPart part, string map, int type, byte pathcurve)
7354 { 7358 {
7355 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) 7359 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
7356 return; 7360 return;
@@ -7366,6 +7370,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7366 if (sculptId == UUID.Zero) 7370 if (sculptId == UUID.Zero)
7367 return; 7371 return;
7368 7372
7373 shapeBlock.PathCurve = pathcurve;
7369 shapeBlock.ObjectLocalID = part.LocalId; 7374 shapeBlock.ObjectLocalID = part.LocalId;
7370 shapeBlock.PathScaleX = 100; 7375 shapeBlock.PathScaleX = 100;
7371 shapeBlock.PathScaleY = 150; 7376 shapeBlock.PathScaleY = 150;
@@ -7379,9 +7384,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7379 type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE; 7384 type = type | (int)ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE;
7380 } 7385 }
7381 7386
7382 // retain pathcurve
7383 shapeBlock.PathCurve = part.Shape.PathCurve;
7384
7385 part.Shape.SetSculptProperties((byte)type, sculptId); 7387 part.Shape.SetSculptProperties((byte)type, sculptId);
7386 part.Shape.SculptEntry = true; 7388 part.Shape.SculptEntry = true;
7387 part.UpdateShape(shapeBlock); 7389 part.UpdateShape(shapeBlock);
@@ -7518,15 +7520,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7518 else 7520 else
7519 { 7521 {
7520 // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask. 7522 // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
7521 SceneObjectGroup group = part.ParentGroup; 7523 SceneObjectPart rootPart = part.ParentGroup.RootPart;
7522 if (group != null) // a bit paranoid, maybe 7524 SetRot(part, rootPart.RotationOffset * Rot2Quaternion(q));
7523 {
7524 SceneObjectPart rootPart = group.RootPart;
7525 if (rootPart != null) // again, better safe than sorry
7526 {
7527 SetRot(part, rootPart.RotationOffset * Rot2Quaternion(q));
7528 }
7529 }
7530 } 7525 }
7531 7526
7532 break; 7527 break;
@@ -7561,8 +7556,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7561 taper_b = rules.GetVector3Item(idx++); 7556 taper_b = rules.GetVector3Item(idx++);
7562 topshear = rules.GetVector3Item(idx++); 7557 topshear = rules.GetVector3Item(idx++);
7563 7558
7564 part.Shape.PathCurve = (byte)Extrusion.Straight; 7559 SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
7565 SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, 1); 7560 (byte)ProfileShape.Square, (byte)Extrusion.Straight);
7566 break; 7561 break;
7567 7562
7568 case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER: 7563 case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
@@ -7575,9 +7570,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7575 twist = rules.GetVector3Item(idx++); 7570 twist = rules.GetVector3Item(idx++);
7576 taper_b = rules.GetVector3Item(idx++); 7571 taper_b = rules.GetVector3Item(idx++);
7577 topshear = rules.GetVector3Item(idx++); 7572 topshear = rules.GetVector3Item(idx++);
7578 part.Shape.ProfileShape = ProfileShape.Circle; 7573 SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
7579 part.Shape.PathCurve = (byte)Extrusion.Straight; 7574 (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
7580 SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, 0);
7581 break; 7575 break;
7582 7576
7583 case (int)ScriptBaseClass.PRIM_TYPE_PRISM: 7577 case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
@@ -7590,8 +7584,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7590 twist = rules.GetVector3Item(idx++); 7584 twist = rules.GetVector3Item(idx++);
7591 taper_b = rules.GetVector3Item(idx++); 7585 taper_b = rules.GetVector3Item(idx++);
7592 topshear = rules.GetVector3Item(idx++); 7586 topshear = rules.GetVector3Item(idx++);
7593 part.Shape.PathCurve = (byte)Extrusion.Straight; 7587 SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
7594 SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear, 3); 7588 (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
7595 break; 7589 break;
7596 7590
7597 case (int)ScriptBaseClass.PRIM_TYPE_SPHERE: 7591 case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
@@ -7603,8 +7597,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7603 hollow = (float)rules.GetLSLFloatItem(idx++); 7597 hollow = (float)rules.GetLSLFloatItem(idx++);
7604 twist = rules.GetVector3Item(idx++); 7598 twist = rules.GetVector3Item(idx++);
7605 taper_b = rules.GetVector3Item(idx++); // dimple 7599 taper_b = rules.GetVector3Item(idx++); // dimple
7606 part.Shape.PathCurve = (byte)Extrusion.Curve1; 7600 SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
7607 SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, 5); 7601 (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
7608 break; 7602 break;
7609 7603
7610 case (int)ScriptBaseClass.PRIM_TYPE_TORUS: 7604 case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
@@ -7622,9 +7616,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7622 revolutions = (float)rules.GetLSLFloatItem(idx++); 7616 revolutions = (float)rules.GetLSLFloatItem(idx++);
7623 radiusoffset = (float)rules.GetLSLFloatItem(idx++); 7617 radiusoffset = (float)rules.GetLSLFloatItem(idx++);
7624 skew = (float)rules.GetLSLFloatItem(idx++); 7618 skew = (float)rules.GetLSLFloatItem(idx++);
7625 part.Shape.PathCurve = (byte)Extrusion.Curve1;
7626 SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b, 7619 SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
7627 revolutions, radiusoffset, skew, 0); 7620 revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
7628 break; 7621 break;
7629 7622
7630 case (int)ScriptBaseClass.PRIM_TYPE_TUBE: 7623 case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
@@ -7642,9 +7635,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7642 revolutions = (float)rules.GetLSLFloatItem(idx++); 7635 revolutions = (float)rules.GetLSLFloatItem(idx++);
7643 radiusoffset = (float)rules.GetLSLFloatItem(idx++); 7636 radiusoffset = (float)rules.GetLSLFloatItem(idx++);
7644 skew = (float)rules.GetLSLFloatItem(idx++); 7637 skew = (float)rules.GetLSLFloatItem(idx++);
7645 part.Shape.PathCurve = (byte)Extrusion.Curve1;
7646 SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b, 7638 SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
7647 revolutions, radiusoffset, skew, 1); 7639 revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
7648 break; 7640 break;
7649 7641
7650 case (int)ScriptBaseClass.PRIM_TYPE_RING: 7642 case (int)ScriptBaseClass.PRIM_TYPE_RING:
@@ -7662,9 +7654,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7662 revolutions = (float)rules.GetLSLFloatItem(idx++); 7654 revolutions = (float)rules.GetLSLFloatItem(idx++);
7663 radiusoffset = (float)rules.GetLSLFloatItem(idx++); 7655 radiusoffset = (float)rules.GetLSLFloatItem(idx++);
7664 skew = (float)rules.GetLSLFloatItem(idx++); 7656 skew = (float)rules.GetLSLFloatItem(idx++);
7665 part.Shape.PathCurve = (byte)Extrusion.Curve1;
7666 SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b, 7657 SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
7667 revolutions, radiusoffset, skew, 3); 7658 revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
7668 break; 7659 break;
7669 7660
7670 case (int)ScriptBaseClass.PRIM_TYPE_SCULPT: 7661 case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
@@ -7673,8 +7664,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7673 7664
7674 string map = rules.Data[idx++].ToString(); 7665 string map = rules.Data[idx++].ToString();
7675 face = (int)rules.GetLSLIntegerItem(idx++); // type 7666 face = (int)rules.GetLSLIntegerItem(idx++); // type
7676 part.Shape.PathCurve = (byte)Extrusion.Curve1; 7667 SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
7677 SetPrimitiveShapeParams(part, map, face);
7678 break; 7668 break;
7679 } 7669 }
7680 7670
@@ -7779,18 +7769,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7779 break; 7769 break;
7780 7770
7781 case (int)ScriptBaseClass.PRIM_PHANTOM: 7771 case (int)ScriptBaseClass.PRIM_PHANTOM:
7782 if (remain < 1) 7772 if (remain < 1)
7783 return; 7773 return;
7784 7774
7785 string ph = rules.Data[idx++].ToString(); 7775 string ph = rules.Data[idx++].ToString();
7786 bool phantom; 7776 m_host.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));
7787 7777
7788 if (ph.Equals("1"))
7789 phantom = true;
7790 else
7791 phantom = false;
7792
7793 part.ScriptSetPhantomStatus(phantom);
7794 break; 7778 break;
7795 7779
7796 case (int)ScriptBaseClass.PRIM_PHYSICS: 7780 case (int)ScriptBaseClass.PRIM_PHYSICS:
@@ -7811,14 +7795,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7811 if (remain < 1) 7795 if (remain < 1)
7812 return; 7796 return;
7813 string temp = rules.Data[idx++].ToString(); 7797 string temp = rules.Data[idx++].ToString();
7814 bool tempOnRez;
7815 7798
7816 if (temp.Equals("1")) 7799 m_host.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));
7817 tempOnRez = true;
7818 else
7819 tempOnRez = false;
7820 7800
7821 part.ScriptSetTemporaryStatus(tempOnRez);
7822 break; 7801 break;
7823 7802
7824 case (int)ScriptBaseClass.PRIM_TEXGEN: 7803 case (int)ScriptBaseClass.PRIM_TEXGEN:
@@ -7983,9 +7962,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7983 { 7962 {
7984 m_host.AddScriptLPS(1); 7963 m_host.AddScriptLPS(1);
7985 Quaternion q; 7964 Quaternion q;
7986 if (m_host.ParentGroup.RootPart.AttachmentPoint != 0) 7965 if (m_host.ParentGroup.AttachmentPoint != 0)
7987 { 7966 {
7988 ScenePresence avatar = World.GetScenePresence(m_host.AttachedAvatar); 7967 ScenePresence avatar = World.GetScenePresence(m_host.ParentGroup.AttachedAvatar);
7989 if (avatar != null) 7968 if (avatar != null)
7990 if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0) 7969 if ((avatar.AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0)
7991 q = avatar.CameraRotation; // Mouselook 7970 q = avatar.CameraRotation; // Mouselook
@@ -8238,7 +8217,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8238 case ScriptBaseClass.PRIM_TYPE_BOX: 8217 case ScriptBaseClass.PRIM_TYPE_BOX:
8239 case ScriptBaseClass.PRIM_TYPE_CYLINDER: 8218 case ScriptBaseClass.PRIM_TYPE_CYLINDER:
8240 case ScriptBaseClass.PRIM_TYPE_PRISM: 8219 case ScriptBaseClass.PRIM_TYPE_PRISM:
8241 res.Add(new LSL_Integer(Shape.ProfileCurve)); 8220 res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
8242 res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0)); 8221 res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
8243 res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0)); 8222 res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
8244 res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0)); 8223 res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
@@ -8247,7 +8226,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8247 break; 8226 break;
8248 8227
8249 case ScriptBaseClass.PRIM_TYPE_SPHERE: 8228 case ScriptBaseClass.PRIM_TYPE_SPHERE:
8250 res.Add(new LSL_Integer(Shape.ProfileCurve)); 8229 res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
8251 res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0)); 8230 res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
8252 res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0)); 8231 res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
8253 res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0)); 8232 res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
@@ -8263,7 +8242,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8263 case ScriptBaseClass.PRIM_TYPE_TUBE: 8242 case ScriptBaseClass.PRIM_TYPE_TUBE:
8264 case ScriptBaseClass.PRIM_TYPE_TORUS: 8243 case ScriptBaseClass.PRIM_TYPE_TORUS:
8265 // holeshape 8244 // holeshape
8266 res.Add(new LSL_Integer(Shape.ProfileCurve)); 8245 res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble.
8267 8246
8268 // cut 8247 // cut
8269 res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0)); 8248 res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
@@ -10666,6 +10645,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10666 public LSL_List llGetObjectDetails(string id, LSL_List args) 10645 public LSL_List llGetObjectDetails(string id, LSL_List args)
10667 { 10646 {
10668 m_host.AddScriptLPS(1); 10647 m_host.AddScriptLPS(1);
10648
10669 LSL_List ret = new LSL_List(); 10649 LSL_List ret = new LSL_List();
10670 UUID key = new UUID(); 10650 UUID key = new UUID();
10671 if (UUID.TryParse(id, out key)) 10651 if (UUID.TryParse(id, out key))
@@ -10676,72 +10656,76 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10676 { 10656 {
10677 foreach (object o in args.Data) 10657 foreach (object o in args.Data)
10678 { 10658 {
10679 switch (o.ToString()) 10659 switch (int.Parse(o.ToString()))
10680 { 10660 {
10681 case "1": 10661 case ScriptBaseClass.OBJECT_NAME:
10682 ret.Add(new LSL_String(av.Firstname + " " + av.Lastname)); 10662 ret.Add(new LSL_String(av.Firstname + " " + av.Lastname));
10683 break; 10663 break;
10684 case "2": 10664 case ScriptBaseClass.OBJECT_DESC:
10685 ret.Add(new LSL_String("")); 10665 ret.Add(new LSL_String(""));
10686 break; 10666 break;
10687 case "3": 10667 case ScriptBaseClass.OBJECT_POS:
10688 ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z)); 10668 ret.Add(new LSL_Vector((double)av.AbsolutePosition.X, (double)av.AbsolutePosition.Y, (double)av.AbsolutePosition.Z));
10689 break; 10669 break;
10690 case "4": 10670 case ScriptBaseClass.OBJECT_ROT:
10691 ret.Add(new LSL_Rotation((double)av.Rotation.X, (double)av.Rotation.Y, (double)av.Rotation.Z, (double)av.Rotation.W)); 10671 ret.Add(new LSL_Rotation((double)av.Rotation.X, (double)av.Rotation.Y, (double)av.Rotation.Z, (double)av.Rotation.W));
10692 break; 10672 break;
10693 case "5": 10673 case ScriptBaseClass.OBJECT_VELOCITY:
10694 ret.Add(new LSL_Vector(av.Velocity.X, av.Velocity.Y, av.Velocity.Z)); 10674 ret.Add(new LSL_Vector(av.Velocity.X, av.Velocity.Y, av.Velocity.Z));
10695 break; 10675 break;
10696 case "6": 10676 case ScriptBaseClass.OBJECT_OWNER:
10697 ret.Add(new LSL_String(id)); 10677 ret.Add(new LSL_String(id));
10698 break; 10678 break;
10699 case "7": 10679 case ScriptBaseClass.OBJECT_GROUP:
10700 ret.Add(new LSL_String(UUID.Zero.ToString())); 10680 ret.Add(new LSL_String(UUID.Zero.ToString()));
10701 break; 10681 break;
10702 case "8": 10682 case ScriptBaseClass.OBJECT_CREATOR:
10703 ret.Add(new LSL_String(UUID.Zero.ToString())); 10683 ret.Add(new LSL_String(UUID.Zero.ToString()));
10704 break; 10684 break;
10705 } 10685 }
10706 } 10686 }
10687
10707 return ret; 10688 return ret;
10708 } 10689 }
10690
10709 SceneObjectPart obj = World.GetSceneObjectPart(key); 10691 SceneObjectPart obj = World.GetSceneObjectPart(key);
10710 if (obj != null) 10692 if (obj != null)
10711 { 10693 {
10712 foreach (object o in args.Data) 10694 foreach (object o in args.Data)
10713 { 10695 {
10714 switch (o.ToString()) 10696 switch (int.Parse(o.ToString()))
10715 { 10697 {
10716 case "1": 10698 case ScriptBaseClass.OBJECT_NAME:
10717 ret.Add(new LSL_String(obj.Name)); 10699 ret.Add(new LSL_String(obj.Name));
10718 break; 10700 break;
10719 case "2": 10701 case ScriptBaseClass.OBJECT_DESC:
10720 ret.Add(new LSL_String(obj.Description)); 10702 ret.Add(new LSL_String(obj.Description));
10721 break; 10703 break;
10722 case "3": 10704 case ScriptBaseClass.OBJECT_POS:
10723 ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z)); 10705 ret.Add(new LSL_Vector(obj.AbsolutePosition.X, obj.AbsolutePosition.Y, obj.AbsolutePosition.Z));
10724 break; 10706 break;
10725 case "4": 10707 case ScriptBaseClass.OBJECT_ROT:
10726 ret.Add(new LSL_Rotation(obj.RotationOffset.X, obj.RotationOffset.Y, obj.RotationOffset.Z, obj.RotationOffset.W)); 10708 ret.Add(new LSL_Rotation(obj.RotationOffset.X, obj.RotationOffset.Y, obj.RotationOffset.Z, obj.RotationOffset.W));
10727 break; 10709 break;
10728 case "5": 10710 case ScriptBaseClass.OBJECT_VELOCITY:
10729 ret.Add(new LSL_Vector(obj.Velocity.X, obj.Velocity.Y, obj.Velocity.Z)); 10711 ret.Add(new LSL_Vector(obj.Velocity.X, obj.Velocity.Y, obj.Velocity.Z));
10730 break; 10712 break;
10731 case "6": 10713 case ScriptBaseClass.OBJECT_OWNER:
10732 ret.Add(new LSL_String(obj.OwnerID.ToString())); 10714 ret.Add(new LSL_String(obj.OwnerID.ToString()));
10733 break; 10715 break;
10734 case "7": 10716 case ScriptBaseClass.OBJECT_GROUP:
10735 ret.Add(new LSL_String(obj.GroupID.ToString())); 10717 ret.Add(new LSL_String(obj.GroupID.ToString()));
10736 break; 10718 break;
10737 case "8": 10719 case ScriptBaseClass.OBJECT_CREATOR:
10738 ret.Add(new LSL_String(obj.CreatorID.ToString())); 10720 ret.Add(new LSL_String(obj.CreatorID.ToString()));
10739 break; 10721 break;
10740 } 10722 }
10741 } 10723 }
10724
10742 return ret; 10725 return ret;
10743 } 10726 }
10744 } 10727 }
10728
10745 return new LSL_List(); 10729 return new LSL_List();
10746 } 10730 }
10747 10731
@@ -11000,31 +10984,173 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11000 { 10984 {
11001 m_SayShoutCount = 0; 10985 m_SayShoutCount = 0;
11002 } 10986 }
10987 public LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
10988 {
10989 m_host.AddScriptLPS(1);
10990
10991 Vector3 dir = new Vector3((float)(end-start).x, (float)(end-start).y, (float)(end-start).z);
10992 Vector3 startvector = new Vector3((float)start.x, (float)start.y, (float)start.z);
10993 Vector3 endvector = new Vector3((float)end.x, (float)end.y, (float)end.z);
10994
10995 int count = 0;
10996// int detectPhantom = 0;
10997 int dataFlags = 0;
10998 int rejectTypes = 0;
10999
11000 for (int i = 0; i < options.Length; i += 2)
11001 {
11002 if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_MAX_HITS)
11003 {
11004 count = options.GetLSLIntegerItem(i + 1);
11005 }
11006// else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DETECT_PHANTOM)
11007// {
11008// detectPhantom = options.GetLSLIntegerItem(i + 1);
11009// }
11010 else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_DATA_FLAGS)
11011 {
11012 dataFlags = options.GetLSLIntegerItem(i + 1);
11013 }
11014 else if (options.GetLSLIntegerItem(i) == ScriptBaseClass.RC_REJECT_TYPES)
11015 {
11016 rejectTypes = options.GetLSLIntegerItem(i + 1);
11017 }
11018 }
11019
11020 LSL_List list = new LSL_List();
11021 List<ContactResult> results = World.PhysicsScene.RaycastWorld(startvector, dir, dir.Length(), count);
11022
11023 double distance = Util.GetDistanceTo(startvector, endvector);
11024
11025 if (distance == 0)
11026 distance = 0.001;
11027
11028 Vector3 posToCheck = startvector;
11029 ITerrainChannel channel = World.RequestModuleInterface<ITerrainChannel>();
11030
11031 bool checkTerrain = !((rejectTypes & ScriptBaseClass.RC_REJECT_LAND) == ScriptBaseClass.RC_REJECT_LAND);
11032 bool checkAgents = !((rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) == ScriptBaseClass.RC_REJECT_AGENTS);
11033 bool checkNonPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_NONPHYSICAL) == ScriptBaseClass.RC_REJECT_NONPHYSICAL);
11034 bool checkPhysical = !((rejectTypes & ScriptBaseClass.RC_REJECT_PHYSICAL) == ScriptBaseClass.RC_REJECT_PHYSICAL);
11035
11036 for (float i = 0; i <= distance; i += 0.1f)
11037 {
11038 posToCheck = startvector + (dir * (i / (float)distance));
11039
11040 if (checkTerrain && channel[(int)(posToCheck.X + startvector.X), (int)(posToCheck.Y + startvector.Y)] < posToCheck.Z)
11041 {
11042 ContactResult result = new ContactResult();
11043 result.ConsumerID = 0;
11044 result.Depth = 0;
11045 result.Normal = Vector3.Zero;
11046 result.Pos = posToCheck;
11047 results.Add(result);
11048 checkTerrain = false;
11049 }
11050
11051 if (checkAgents)
11052 {
11053 World.ForEachScenePresence(delegate(ScenePresence sp)
11054 {
11055 if (sp.AbsolutePosition.ApproxEquals(posToCheck, sp.PhysicsActor.Size.X))
11056 {
11057 ContactResult result = new ContactResult ();
11058 result.ConsumerID = sp.LocalId;
11059 result.Depth = 0;
11060 result.Normal = Vector3.Zero;
11061 result.Pos = posToCheck;
11062 results.Add(result);
11063 }
11064 });
11065 }
11066 }
11067
11068 int refcount = 0;
11069 foreach (ContactResult result in results)
11070 {
11071 if ((rejectTypes & ScriptBaseClass.RC_REJECT_LAND)
11072 == ScriptBaseClass.RC_REJECT_LAND && result.ConsumerID == 0)
11073 continue;
11074
11075 ISceneEntity entity = World.GetSceneObjectPart(result.ConsumerID);
11076
11077 if (entity == null && (rejectTypes & ScriptBaseClass.RC_REJECT_AGENTS) != ScriptBaseClass.RC_REJECT_AGENTS)
11078 entity = World.GetScenePresence(result.ConsumerID); //Only check if we should be looking for agents
11079
11080 if (entity == null)
11081 {
11082 list.Add(UUID.Zero);
11083
11084 if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
11085 list.Add(0);
11086
11087 list.Add(result.Pos);
11088
11089 if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
11090 list.Add(result.Normal);
11091
11092 continue; //Can't find it, so add UUID.Zero
11093 }
11094
11095 /*if (detectPhantom == 0 && intersection.obj is ISceneChildEntity &&
11096 ((ISceneChildEntity)intersection.obj).PhysActor == null)
11097 continue;*/ //Can't do this ATM, physics engine knows only of non phantom objects
11098
11099 if (entity is SceneObjectPart)
11100 {
11101 if (((SceneObjectPart)entity).PhysActor != null && ((SceneObjectPart)entity).PhysActor.IsPhysical)
11102 {
11103 if (!checkPhysical)
11104 continue;
11105 }
11106 else
11107 {
11108 if (!checkNonPhysical)
11109 continue;
11110 }
11111 }
11112
11113 refcount++;
11114 if ((dataFlags & ScriptBaseClass.RC_GET_ROOT_KEY) == ScriptBaseClass.RC_GET_ROOT_KEY && entity is SceneObjectPart)
11115 list.Add(((SceneObjectPart)entity).ParentGroup.UUID);
11116 else
11117 list.Add(entity.UUID);
11118
11119 if ((dataFlags & ScriptBaseClass.RC_GET_LINK_NUM) == ScriptBaseClass.RC_GET_LINK_NUM)
11120 {
11121 if (entity is SceneObjectPart)
11122 list.Add(((SceneObjectPart)entity).LinkNum);
11123 else
11124 list.Add(0);
11125 }
11126
11127 list.Add(result.Pos);
11128
11129 if ((dataFlags & ScriptBaseClass.RC_GET_NORMAL) == ScriptBaseClass.RC_GET_NORMAL)
11130 list.Add(result.Normal);
11131 }
11132
11133 list.Add(refcount); //The status code, either the # of contacts, RCERR_SIM_PERF_LOW, or RCERR_CAST_TIME_EXCEEDED
11134
11135 return list;
11136 }
11003 11137
11004 #region Not Implemented 11138 #region Not Implemented
11005 // 11139 //
11006 // Listing the unimplemented lsl functions here, please move 11140 // Listing the unimplemented lsl functions here, please move
11007 // them from this region as they are completed 11141 // them from this region as they are completed
11008 // 11142 //
11009 public void llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options)
11010 {
11011 m_host.AddScriptLPS(1);
11012 NotImplemented("llCastRay");
11013
11014 }
11015 11143
11016 public void llGetEnv(LSL_String name) 11144 public void llGetEnv(LSL_String name)
11017 { 11145 {
11018 m_host.AddScriptLPS(1); 11146 m_host.AddScriptLPS(1);
11019 NotImplemented("llGetEnv"); 11147 NotImplemented("llGetEnv");
11020
11021 } 11148 }
11022 11149
11023 public void llGetSPMaxMemory() 11150 public void llGetSPMaxMemory()
11024 { 11151 {
11025 m_host.AddScriptLPS(1); 11152 m_host.AddScriptLPS(1);
11026 NotImplemented("llGetSPMaxMemory"); 11153 NotImplemented("llGetSPMaxMemory");
11027
11028 } 11154 }
11029 11155
11030 public virtual LSL_Integer llGetUsedMemory() 11156 public virtual LSL_Integer llGetUsedMemory()
@@ -11034,18 +11160,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11034 return 0; 11160 return 0;
11035 } 11161 }
11036 11162
11037 public void llRegionSayTo( LSL_Key target, LSL_Integer channel, LSL_String msg ) 11163 public void llScriptProfiler(LSL_Integer flags)
11038 {
11039 m_host.AddScriptLPS(1);
11040 NotImplemented("llRegionSayTo");
11041
11042 }
11043
11044 public void llScriptProfiler( LSL_Integer flags )
11045 { 11164 {
11046 m_host.AddScriptLPS(1); 11165 m_host.AddScriptLPS(1);
11047 //NotImplemented("llScriptProfiler"); 11166 //NotImplemented("llScriptProfiler");
11048
11049 } 11167 }
11050 11168
11051 public void llSetSoundQueueing(int queue) 11169 public void llSetSoundQueueing(int queue)
@@ -11164,9 +11282,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11164 } 11282 }
11165 } 11283 }
11166 11284
11167 public static string GetLine(UUID assetID, int line, int maxLength) 11285 /// <summary>
11286 /// Get a notecard line.
11287 /// </summary>
11288 /// <param name="assetID"></param>
11289 /// <param name="line">Lines start at index 0</param>
11290 /// <returns></returns>
11291 public static string GetLine(UUID assetID, int lineNumber)
11168 { 11292 {
11169 if (line < 0) 11293 if (lineNumber < 0)
11170 return ""; 11294 return "";
11171 11295
11172 string data; 11296 string data;
@@ -11178,17 +11302,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11178 { 11302 {
11179 m_Notecards[assetID].lastRef = DateTime.Now; 11303 m_Notecards[assetID].lastRef = DateTime.Now;
11180 11304
11181 if (line >= m_Notecards[assetID].text.Length) 11305 if (lineNumber >= m_Notecards[assetID].text.Length)
11182 return "\n\n\n"; 11306 return "\n\n\n";
11183 11307
11184 data = m_Notecards[assetID].text[line]; 11308 data = m_Notecards[assetID].text[lineNumber];
11185 if (data.Length > maxLength)
11186 data = data.Substring(0, maxLength);
11187 11309
11188 return data; 11310 return data;
11189 } 11311 }
11190 } 11312 }
11191 11313
11314 /// <summary>
11315 /// Get a notecard line.
11316 /// </summary>
11317 /// <param name="assetID"></param>
11318 /// <param name="line">Lines start at index 0</param>
11319 /// <param name="maxLength">Maximum length of the returned line. Longer lines will be truncated</para>
11320 /// <returns></returns>
11321 public static string GetLine(UUID assetID, int lineNumber, int maxLength)
11322 {
11323 string line = GetLine(assetID, lineNumber);
11324
11325 if (line.Length > maxLength)
11326 line = line.Substring(0, maxLength);
11327
11328 return line;
11329 }
11330
11192 public static void CacheCheck() 11331 public static void CacheCheck()
11193 { 11332 {
11194 foreach (UUID key in new List<UUID>(m_Notecards.Keys)) 11333 foreach (UUID key in new List<UUID>(m_Notecards.Keys))
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
index 645566e..80daf5b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
@@ -130,7 +130,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
130 int idx = 0; 130 int idx = 0;
131 while (idx < rules.Length) 131 while (idx < rules.Length)
132 { 132 {
133 uint rule = (uint)rules.GetLSLIntegerItem(idx); 133 LSL_Integer ruleInt = rules.GetLSLIntegerItem(idx);
134 uint rule = (uint)ruleInt;
134 LSL_List toadd = new LSL_List(); 135 LSL_List toadd = new LSL_List();
135 136
136 switch (rule) 137 switch (rule)
@@ -247,7 +248,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
247 248
248 if (toadd.Length > 0) 249 if (toadd.Length > 0)
249 { 250 {
250 values.Add(rule); 251 values.Add(ruleInt);
251 values.Add(toadd.Data[0]); 252 values.Add(toadd.Data[0]);
252 } 253 }
253 idx++; 254 idx++;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 6d2efce..9ec8a42 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -28,11 +28,16 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
31using System.Runtime.Remoting.Lifetime; 33using System.Runtime.Remoting.Lifetime;
32using System.Text; 34using System.Text;
33using System.Net; 35using System.Net;
34using System.Threading; 36using System.Threading;
37using System.Xml;
38using log4net;
35using OpenMetaverse; 39using OpenMetaverse;
40using OpenMetaverse.StructuredData;
36using Nini.Config; 41using Nini.Config;
37using OpenSim; 42using OpenSim;
38using OpenSim.Framework; 43using OpenSim.Framework;
@@ -119,6 +124,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
119 [Serializable] 124 [Serializable]
120 public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi 125 public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
121 { 126 {
127// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
128
122 internal IScriptEngine m_ScriptEngine; 129 internal IScriptEngine m_ScriptEngine;
123 internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there 130 internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there
124 internal SceneObjectPart m_host; 131 internal SceneObjectPart m_host;
@@ -357,20 +364,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
357 System.Threading.Thread.Sleep(delay); 364 System.Threading.Thread.Sleep(delay);
358 } 365 }
359 366
360 //
361 // OpenSim functions
362 //
363 public LSL_Integer osSetTerrainHeight(int x, int y, double val) 367 public LSL_Integer osSetTerrainHeight(int x, int y, double val)
364 { 368 {
365 CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight"); 369 CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight");
366 return SetTerrainHeight(x, y, val); 370 return SetTerrainHeight(x, y, val);
367 } 371 }
372
368 public LSL_Integer osTerrainSetHeight(int x, int y, double val) 373 public LSL_Integer osTerrainSetHeight(int x, int y, double val)
369 { 374 {
370 CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight"); 375 CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight");
371 OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight"); 376 OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight");
372 return SetTerrainHeight(x, y, val); 377 return SetTerrainHeight(x, y, val);
373 } 378 }
379
374 private LSL_Integer SetTerrainHeight(int x, int y, double val) 380 private LSL_Integer SetTerrainHeight(int x, int y, double val)
375 { 381 {
376 m_host.AddScriptLPS(1); 382 m_host.AddScriptLPS(1);
@@ -393,12 +399,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
393 CheckThreatLevel(ThreatLevel.None, "osGetTerrainHeight"); 399 CheckThreatLevel(ThreatLevel.None, "osGetTerrainHeight");
394 return GetTerrainHeight(x, y); 400 return GetTerrainHeight(x, y);
395 } 401 }
402
396 public LSL_Float osTerrainGetHeight(int x, int y) 403 public LSL_Float osTerrainGetHeight(int x, int y)
397 { 404 {
398 CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight"); 405 CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight");
399 OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight"); 406 OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight");
400 return GetTerrainHeight(x, y); 407 return GetTerrainHeight(x, y);
401 } 408 }
409
402 private LSL_Float GetTerrainHeight(int x, int y) 410 private LSL_Float GetTerrainHeight(int x, int y)
403 { 411 {
404 m_host.AddScriptLPS(1); 412 m_host.AddScriptLPS(1);
@@ -673,13 +681,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
673 CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater"); 681 CheckThreatLevel(ThreatLevel.VeryLow, "osSetPrimFloatOnWater");
674 682
675 m_host.AddScriptLPS(1); 683 m_host.AddScriptLPS(1);
676 if (m_host.ParentGroup != null) 684
677 { 685 m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
678 if (m_host.ParentGroup.RootPart != null)
679 {
680 m_host.ParentGroup.RootPart.SetFloatOnWater(floatYN);
681 }
682 }
683 } 686 }
684 687
685 // Teleport functions 688 // Teleport functions
@@ -870,7 +873,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
870 ScenePresence target = (ScenePresence)World.Entities[avatarID]; 873 ScenePresence target = (ScenePresence)World.Entities[avatarID];
871 if (target != null) 874 if (target != null)
872 { 875 {
873 UUID animID=UUID.Zero; 876 UUID animID = UUID.Zero;
874 m_host.TaskInventory.LockItemsForRead(true); 877 m_host.TaskInventory.LockItemsForRead(true);
875 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) 878 foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory)
876 { 879 {
@@ -1028,6 +1031,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1028 drawList += "PenColor " + color + "; "; 1031 drawList += "PenColor " + color + "; ";
1029 return drawList; 1032 return drawList;
1030 } 1033 }
1034
1031 // Deprecated 1035 // Deprecated
1032 public string osSetPenColour(string drawList, string colour) 1036 public string osSetPenColour(string drawList, string colour)
1033 { 1037 {
@@ -1189,11 +1193,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1189 OSSLDeprecated("osSunGetParam", "osGetSunParam"); 1193 OSSLDeprecated("osSunGetParam", "osGetSunParam");
1190 return GetSunParam(param); 1194 return GetSunParam(param);
1191 } 1195 }
1196
1192 public double osGetSunParam(string param) 1197 public double osGetSunParam(string param)
1193 { 1198 {
1194 CheckThreatLevel(ThreatLevel.None, "osGetSunParam"); 1199 CheckThreatLevel(ThreatLevel.None, "osGetSunParam");
1195 return GetSunParam(param); 1200 return GetSunParam(param);
1196 } 1201 }
1202
1197 private double GetSunParam(string param) 1203 private double GetSunParam(string param)
1198 { 1204 {
1199 m_host.AddScriptLPS(1); 1205 m_host.AddScriptLPS(1);
@@ -1215,11 +1221,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1215 OSSLDeprecated("osSunSetParam", "osSetSunParam"); 1221 OSSLDeprecated("osSunSetParam", "osSetSunParam");
1216 SetSunParam(param, value); 1222 SetSunParam(param, value);
1217 } 1223 }
1224
1218 public void osSetSunParam(string param, double value) 1225 public void osSetSunParam(string param, double value)
1219 { 1226 {
1220 CheckThreatLevel(ThreatLevel.None, "osSetSunParam"); 1227 CheckThreatLevel(ThreatLevel.None, "osSetSunParam");
1221 SetSunParam(param, value); 1228 SetSunParam(param, value);
1222 } 1229 }
1230
1223 private void SetSunParam(string param, double value) 1231 private void SetSunParam(string param, double value)
1224 { 1232 {
1225 m_host.AddScriptLPS(1); 1233 m_host.AddScriptLPS(1);
@@ -1229,10 +1237,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1229 { 1237 {
1230 module.SetSunParameter(param, value); 1238 module.SetSunParameter(param, value);
1231 } 1239 }
1232
1233 } 1240 }
1234 1241
1235
1236 public string osWindActiveModelPluginName() 1242 public string osWindActiveModelPluginName()
1237 { 1243 {
1238 CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName"); 1244 CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName");
@@ -1311,12 +1317,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1311 OSSLDeprecated(functionName, "osSetParcelDetails"); 1317 OSSLDeprecated(functionName, "osSetParcelDetails");
1312 SetParcelDetails(pos, rules, functionName); 1318 SetParcelDetails(pos, rules, functionName);
1313 } 1319 }
1320
1314 public void osSetParcelDetails(LSL_Vector pos, LSL_List rules) 1321 public void osSetParcelDetails(LSL_Vector pos, LSL_List rules)
1315 { 1322 {
1316 const string functionName = "osSetParcelDetails"; 1323 const string functionName = "osSetParcelDetails";
1317 CheckThreatLevel(ThreatLevel.High, functionName); 1324 CheckThreatLevel(ThreatLevel.High, functionName);
1318 SetParcelDetails(pos, rules, functionName); 1325 SetParcelDetails(pos, rules, functionName);
1319 } 1326 }
1327
1320 private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName) 1328 private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName)
1321 { 1329 {
1322 m_host.AddScriptLPS(1); 1330 m_host.AddScriptLPS(1);
@@ -1436,8 +1444,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1436 voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID); 1444 voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID);
1437 else 1445 else
1438 OSSLError("osSetParcelSIPAddress: No voice module enabled for this land"); 1446 OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
1439
1440
1441 } 1447 }
1442 1448
1443 public string osGetScriptEngineName() 1449 public string osGetScriptEngineName()
@@ -1690,8 +1696,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1690 return jsondata; 1696 return jsondata;
1691 } 1697 }
1692 1698
1693 // send a message to to object identified by the given UUID, a script in the object must implement the dataserver function 1699 /// <summary>
1694 // the dataserver function is passed the ID of the calling function and a string message 1700 /// Send a message to to object identified by the given UUID
1701 /// </summary>
1702 /// <remarks>
1703 /// A script in the object must implement the dataserver function
1704 /// the dataserver function is passed the ID of the calling function and a string message
1705 /// </remarks>
1706 /// <param name="objectUUID"></param>
1707 /// <param name="message"></param>
1695 public void osMessageObject(LSL_Key objectUUID, string message) 1708 public void osMessageObject(LSL_Key objectUUID, string message)
1696 { 1709 {
1697 CheckThreatLevel(ThreatLevel.Low, "osMessageObject"); 1710 CheckThreatLevel(ThreatLevel.Low, "osMessageObject");
@@ -1706,34 +1719,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1706 "dataserver", resobj, new DetectParams[0])); 1719 "dataserver", resobj, new DetectParams[0]));
1707 } 1720 }
1708 1721
1709 1722 /// <summary>
1710 // This needs ThreatLevel high. It is an excellent griefer tool, 1723 /// Write a notecard directly to the prim's inventory.
1711 // In a loop, it can cause asset bloat and DOS levels of asset 1724 /// </summary>
1712 // writes. 1725 /// <remarks>
1713 // 1726 /// This needs ThreatLevel high. It is an excellent griefer tool,
1727 /// In a loop, it can cause asset bloat and DOS levels of asset
1728 /// writes.
1729 /// </remarks>
1730 /// <param name="notecardName">The name of the notecard to write.</param>
1731 /// <param name="contents">The contents of the notecard.</param>
1714 public void osMakeNotecard(string notecardName, LSL_Types.list contents) 1732 public void osMakeNotecard(string notecardName, LSL_Types.list contents)
1715 { 1733 {
1716 CheckThreatLevel(ThreatLevel.High, "osMakeNotecard"); 1734 CheckThreatLevel(ThreatLevel.High, "osMakeNotecard");
1717 m_host.AddScriptLPS(1); 1735 m_host.AddScriptLPS(1);
1718 1736
1719 // Create new asset 1737 StringBuilder notecardData = new StringBuilder();
1720 AssetBase asset = new AssetBase(UUID.Random(), notecardName, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
1721 asset.Description = "Script Generated Notecard";
1722 string notecardData = String.Empty;
1723 1738
1724 for (int i = 0; i < contents.Length; i++) { 1739 for (int i = 0; i < contents.Length; i++)
1725 notecardData += contents.GetLSLStringItem(i) + "\n"; 1740 notecardData.Append((string)(contents.GetLSLStringItem(i) + "\n"));
1726 } 1741
1742 SaveNotecard(notecardName, "Script generated notecard", notecardData.ToString(), false);
1743 }
1727 1744
1728 int textLength = notecardData.Length; 1745 /// <summary>
1729 notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " 1746 /// Save a notecard to prim inventory.
1730 + textLength.ToString() + "\n" + notecardData + "}\n"; 1747 /// </summary>
1748 /// <param name="name"></param>
1749 /// <param name="description">Description of notecard</param>
1750 /// <param name="notecardData"></param>
1751 /// <param name="forceSameName">
1752 /// If true, then if an item exists with the same name, it is replaced.
1753 /// If false, then a new item is created witha slightly different name (e.g. name 1)
1754 /// </param>
1755 /// <returns>Prim inventory item created.</returns>
1756 protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName)
1757 {
1758 // Create new asset
1759 AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString());
1760 asset.Description = description;
1761
1762 int textLength = data.Length;
1763 data
1764 = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
1765 + textLength.ToString() + "\n" + data + "}\n";
1731 1766
1732 asset.Data = Util.UTF8.GetBytes(notecardData); 1767 asset.Data = Util.UTF8.GetBytes(data);
1733 World.AssetService.Store(asset); 1768 World.AssetService.Store(asset);
1734 1769
1735 // Create Task Entry 1770 // Create Task Entry
1736 TaskInventoryItem taskItem=new TaskInventoryItem(); 1771 TaskInventoryItem taskItem = new TaskInventoryItem();
1737 1772
1738 taskItem.ResetIDs(m_host.UUID); 1773 taskItem.ResetIDs(m_host.UUID);
1739 taskItem.ParentID = m_host.UUID; 1774 taskItem.ParentID = m_host.UUID;
@@ -1755,29 +1790,54 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1755 taskItem.PermsMask = 0; 1790 taskItem.PermsMask = 0;
1756 taskItem.AssetID = asset.FullID; 1791 taskItem.AssetID = asset.FullID;
1757 1792
1758 m_host.Inventory.AddInventoryItem(taskItem, false); 1793 if (forceSameName)
1794 m_host.Inventory.AddInventoryItemExclusive(taskItem, false);
1795 else
1796 m_host.Inventory.AddInventoryItem(taskItem, false);
1797
1798 return taskItem;
1759 } 1799 }
1760 1800
1801 /// <summary>
1802 /// Load the notecard data found at the given prim inventory item name or asset uuid.
1803 /// </summary>
1804 /// <param name="notecardNameOrUuid"></param>
1805 /// <returns>The text loaded. Null if no notecard was found.</returns>
1806 protected string LoadNotecard(string notecardNameOrUuid)
1807 {
1808 UUID assetID = CacheNotecard(notecardNameOrUuid);
1809 StringBuilder notecardData = new StringBuilder();
1761 1810
1762 /*Instead of using the LSL Dataserver event to pull notecard data, 1811 for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
1763 this will simply read the requested line and return its data as a string. 1812 {
1813 string line = NotecardCache.GetLine(assetID, count) + "\n";
1764 1814
1765 Warning - due to the synchronous method this function uses to fetch assets, its use 1815// m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line);
1766 may be dangerous and unreliable while running in grid mode. 1816
1767 */ 1817 notecardData.Append(line);
1768 public string osGetNotecardLine(string name, int line) 1818 }
1769 { 1819
1770 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); 1820 return notecardData.ToString();
1771 m_host.AddScriptLPS(1); 1821 }
1772 1822
1823 /// <summary>
1824 /// Cache a notecard's contents.
1825 /// </summary>
1826 /// <param name="notecardNameOrUuid"></param>
1827 /// <returns>
1828 /// The asset id of the notecard, which is used for retrieving the cached data.
1829 /// UUID.Zero if no asset could be found.
1830 /// </returns>
1831 protected UUID CacheNotecard(string notecardNameOrUuid)
1832 {
1773 UUID assetID = UUID.Zero; 1833 UUID assetID = UUID.Zero;
1774 1834
1775 if (!UUID.TryParse(name, out assetID)) 1835 if (!UUID.TryParse(notecardNameOrUuid, out assetID))
1776 { 1836 {
1777 m_host.TaskInventory.LockItemsForRead(true); 1837 m_host.TaskInventory.LockItemsForRead(true);
1778 foreach (TaskInventoryItem item in m_host.TaskInventory.Values) 1838 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1779 { 1839 {
1780 if (item.Type == 7 && item.Name == name) 1840 if (item.Type == 7 && item.Name == notecardNameOrUuid)
1781 { 1841 {
1782 assetID = item.AssetID; 1842 assetID = item.AssetID;
1783 } 1843 }
@@ -1786,118 +1846,100 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1786 } 1846 }
1787 1847
1788 if (assetID == UUID.Zero) 1848 if (assetID == UUID.Zero)
1789 { 1849 return UUID.Zero;
1790 OSSLShoutError("Notecard '" + name + "' could not be found.");
1791 return "ERROR!";
1792 }
1793 1850
1794 if (!NotecardCache.IsCached(assetID)) 1851 if (!NotecardCache.IsCached(assetID))
1795 { 1852 {
1796 AssetBase a = World.AssetService.Get(assetID.ToString()); 1853 AssetBase a = World.AssetService.Get(assetID.ToString());
1797 if (a != null)
1798 {
1799 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
1800 string data = enc.GetString(a.Data);
1801 NotecardCache.Cache(assetID, data);
1802 }
1803 else
1804 {
1805 OSSLShoutError("Notecard '" + name + "' could not be found.");
1806 return "ERROR!";
1807 }
1808 };
1809 1854
1810 return NotecardCache.GetLine(assetID, line, 255); 1855 if (a == null)
1856 return UUID.Zero;
1811 1857
1858 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
1859 string data = enc.GetString(a.Data);
1860 NotecardCache.Cache(assetID, data);
1861 };
1812 1862
1863 return assetID;
1813 } 1864 }
1814 1865
1815 /*Instead of using the LSL Dataserver event to pull notecard data line by line, 1866 /// <summary>
1816 this will simply read the entire notecard and return its data as a string. 1867 /// Directly get an entire notecard at once.
1868 /// </summary>
1869 /// <remarks>
1870 /// Instead of using the LSL Dataserver event to pull notecard data
1871 /// this will simply read the entire notecard and return its data as a string.
1872 ///
1873 /// Warning - due to the synchronous method this function uses to fetch assets, its use
1874 /// may be dangerous and unreliable while running in grid mode.
1875 /// </remarks>
1876 /// <param name="name">Name of the notecard or its asset id</param>
1877 /// <param name="line">The line number to read. The first line is line 0</param>
1878 /// <returns>Notecard line</returns>
1879 public string osGetNotecardLine(string name, int line)
1880 {
1881 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
1882 m_host.AddScriptLPS(1);
1817 1883
1818 Warning - due to the synchronous method this function uses to fetch assets, its use 1884 UUID assetID = CacheNotecard(name);
1819 may be dangerous and unreliable while running in grid mode.
1820 */
1821 1885
1886 if (assetID == UUID.Zero)
1887 {
1888 OSSLShoutError("Notecard '" + name + "' could not be found.");
1889 return "ERROR!";
1890 }
1891
1892 return NotecardCache.GetLine(assetID, line);
1893 }
1894
1895 /// <summary>
1896 /// Get an entire notecard at once.
1897 /// </summary>
1898 /// <remarks>
1899 /// Instead of using the LSL Dataserver event to pull notecard data line by line,
1900 /// this will simply read the entire notecard and return its data as a string.
1901 ///
1902 /// Warning - due to the synchronous method this function uses to fetch assets, its use
1903 /// may be dangerous and unreliable while running in grid mode.
1904 /// </remarks>
1905 /// <param name="name">Name of the notecard or its asset id</param>
1906 /// <returns>Notecard text</returns>
1822 public string osGetNotecard(string name) 1907 public string osGetNotecard(string name)
1823 { 1908 {
1824 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard"); 1909 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
1825 m_host.AddScriptLPS(1); 1910 m_host.AddScriptLPS(1);
1826 1911
1827 UUID assetID = UUID.Zero; 1912 string text = LoadNotecard(name);
1828 string NotecardData = "";
1829 1913
1830 if (!UUID.TryParse(name, out assetID)) 1914 if (text == null)
1831 {
1832 m_host.TaskInventory.LockItemsForRead(true);
1833 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1834 {
1835 if (item.Type == 7 && item.Name == name)
1836 {
1837 assetID = item.AssetID;
1838 }
1839 }
1840 m_host.TaskInventory.LockItemsForRead(false);
1841 }
1842
1843 if (assetID == UUID.Zero)
1844 { 1915 {
1845 OSSLShoutError("Notecard '" + name + "' could not be found."); 1916 OSSLShoutError("Notecard '" + name + "' could not be found.");
1846 return "ERROR!"; 1917 return "ERROR!";
1847 } 1918 }
1848 1919 else
1849 if (!NotecardCache.IsCached(assetID))
1850 {
1851 AssetBase a = World.AssetService.Get(assetID.ToString());
1852 if (a != null)
1853 {
1854 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
1855 string data = enc.GetString(a.Data);
1856 NotecardCache.Cache(assetID, data);
1857 }
1858 else
1859 {
1860 OSSLShoutError("Notecard '" + name + "' could not be found.");
1861 return "ERROR!";
1862 }
1863 };
1864
1865 for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
1866 { 1920 {
1867 NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n"; 1921 return text;
1868 } 1922 }
1869
1870 return NotecardData;
1871
1872
1873 } 1923 }
1874 1924
1875 /*Instead of using the LSL Dataserver event to pull notecard data, 1925 /// <summary>
1876 this will simply read the number of note card lines and return this data as an integer. 1926 /// Get the number of lines in the given notecard.
1877 1927 /// </summary>
1878 Warning - due to the synchronous method this function uses to fetch assets, its use 1928 /// <remarks>
1879 may be dangerous and unreliable while running in grid mode. 1929 /// Instead of using the LSL Dataserver event to pull notecard data,
1880 */ 1930 /// this will simply read the number of note card lines and return this data as an integer.
1881 1931 ///
1932 /// Warning - due to the synchronous method this function uses to fetch assets, its use
1933 /// may be dangerous and unreliable while running in grid mode.
1934 /// </remarks>
1935 /// <param name="name">Name of the notecard or its asset id</param>
1936 /// <returns></returns>
1882 public int osGetNumberOfNotecardLines(string name) 1937 public int osGetNumberOfNotecardLines(string name)
1883 { 1938 {
1884 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines"); 1939 CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
1885 m_host.AddScriptLPS(1); 1940 m_host.AddScriptLPS(1);
1886 1941
1887 UUID assetID = UUID.Zero; 1942 UUID assetID = CacheNotecard(name);
1888
1889 if (!UUID.TryParse(name, out assetID))
1890 {
1891 m_host.TaskInventory.LockItemsForRead(true);
1892 foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
1893 {
1894 if (item.Type == 7 && item.Name == name)
1895 {
1896 assetID = item.AssetID;
1897 }
1898 }
1899 m_host.TaskInventory.LockItemsForRead(false);
1900 }
1901 1943
1902 if (assetID == UUID.Zero) 1944 if (assetID == UUID.Zero)
1903 { 1945 {
@@ -1905,25 +1947,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1905 return -1; 1947 return -1;
1906 } 1948 }
1907 1949
1908 if (!NotecardCache.IsCached(assetID))
1909 {
1910 AssetBase a = World.AssetService.Get(assetID.ToString());
1911 if (a != null)
1912 {
1913 System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
1914 string data = enc.GetString(a.Data);
1915 NotecardCache.Cache(assetID, data);
1916 }
1917 else
1918 {
1919 OSSLShoutError("Notecard '" + name + "' could not be found.");
1920 return -1;
1921 }
1922 };
1923
1924 return NotecardCache.GetLines(assetID); 1950 return NotecardCache.GetLines(assetID);
1925
1926
1927 } 1951 }
1928 1952
1929 public string osAvatarName2Key(string firstname, string lastname) 1953 public string osAvatarName2Key(string firstname, string lastname)
@@ -1962,15 +1986,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1962 { 1986 {
1963 return ""; 1987 return "";
1964 } 1988 }
1965
1966 } 1989 }
1967 1990
1991 /// <summary>
1992 /// Get the nickname of this grid, as set in the [GridInfo] config section.
1993 /// </summary>
1994 /// <remarks>
1968 /// Threat level is Moderate because intentional abuse, for instance 1995 /// Threat level is Moderate because intentional abuse, for instance
1969 /// scripts that are written to be malicious only on one grid, 1996 /// scripts that are written to be malicious only on one grid,
1970 /// for instance in a HG scenario, are a distinct possibility. 1997 /// for instance in a HG scenario, are a distinct possibility.
1971 /// 1998 /// </remarks>
1972 /// Use value from the config file and return it. 1999 /// <returns></returns>
1973 ///
1974 public string osGetGridNick() 2000 public string osGetGridNick()
1975 { 2001 {
1976 CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick"); 2002 CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick");
@@ -2037,7 +2063,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2037 // Find matches beginning at start position 2063 // Find matches beginning at start position
2038 Regex matcher = new Regex(pattern); 2064 Regex matcher = new Regex(pattern);
2039 Match match = matcher.Match(src, start); 2065 Match match = matcher.Match(src, start);
2040 if (match.Success) 2066 while (match.Success)
2041 { 2067 {
2042 foreach (System.Text.RegularExpressions.Group g in match.Groups) 2068 foreach (System.Text.RegularExpressions.Group g in match.Groups)
2043 { 2069 {
@@ -2047,6 +2073,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2047 result.Add(new LSL_Integer(g.Index)); 2073 result.Add(new LSL_Integer(g.Index));
2048 } 2074 }
2049 } 2075 }
2076
2077 match = match.NextMatch();
2050 } 2078 }
2051 2079
2052 return result; 2080 return result;
@@ -2076,12 +2104,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2076 return World.RegionInfo.RegionSettings.LoadedCreationID; 2104 return World.RegionInfo.RegionSettings.LoadedCreationID;
2077 } 2105 }
2078 2106
2079 // Threat level is 'Low' because certain users could possibly be tricked into 2107 /// <summary>
2080 // dropping an unverified script into one of their own objects, which could 2108 /// Get the primitive parameters of a linked prim.
2081 // then gather the physical construction details of the object and transmit it 2109 /// </summary>
2082 // to an unscrupulous third party, thus permitting unauthorized duplication of 2110 /// <remarks>
2083 // the object's form. 2111 /// Threat level is 'Low' because certain users could possibly be tricked into
2084 // 2112 /// dropping an unverified script into one of their own objects, which could
2113 /// then gather the physical construction details of the object and transmit it
2114 /// to an unscrupulous third party, thus permitting unauthorized duplication of
2115 /// the object's form.
2116 /// </remarks>
2117 /// <param name="linknumber"></param>
2118 /// <param name="rules"></param>
2119 /// <returns></returns>
2085 public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules) 2120 public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
2086 { 2121 {
2087 CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams"); 2122 CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
@@ -2096,25 +2131,122 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2096 return retVal; 2131 return retVal;
2097 } 2132 }
2098 2133
2099 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom) 2134 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard)
2100 { 2135 {
2101 CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); 2136 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
2102 //QueueUserWorkItem
2103 2137
2104 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2138 INPCModule module = World.RequestModuleInterface<INPCModule>();
2105 if (module != null) 2139 if (module != null)
2106 { 2140 {
2141 AvatarAppearance appearance = null;
2142
2143 UUID id;
2144 if (UUID.TryParse(notecard, out id))
2145 {
2146 ScenePresence clonePresence = World.GetScenePresence(id);
2147 if (clonePresence != null)
2148 appearance = clonePresence.Appearance;
2149 }
2150
2151 if (appearance == null)
2152 {
2153 string appearanceSerialized = LoadNotecard(notecard);
2154
2155 if (appearanceSerialized != null)
2156 {
2157 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
2158 appearance = new AvatarAppearance();
2159 appearance.Unpack(appearanceOsd);
2160 }
2161 }
2162
2163 if (appearance == null)
2164 return new LSL_Key(UUID.Zero.ToString());
2165
2107 UUID x = module.CreateNPC(firstname, 2166 UUID x = module.CreateNPC(firstname,
2108 lastname, 2167 lastname,
2109 new Vector3((float) position.x, (float) position.y, (float) position.z), 2168 new Vector3((float) position.x, (float) position.y, (float) position.z),
2110 World, 2169 World,
2111 new UUID(cloneFrom)); 2170 appearance);
2112 2171
2113 return new LSL_Key(x.ToString()); 2172 return new LSL_Key(x.ToString());
2114 } 2173 }
2174
2175 return new LSL_Key(UUID.Zero.ToString());
2176 }
2177
2178 /// <summary>
2179 /// Save the current appearance of the NPC permanently to the named notecard.
2180 /// </summary>
2181 /// <param name="avatar"></param>
2182 /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
2183 /// <returns>The asset ID of the notecard saved.</returns>
2184 public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard)
2185 {
2186 CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance");
2187
2188 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2189
2190 if (npcModule != null)
2191 {
2192 UUID npcId;
2193 if (!UUID.TryParse(npc.m_string, out npcId))
2194 return new LSL_Key(UUID.Zero.ToString());
2195
2196 if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
2197 return new LSL_Key(UUID.Zero.ToString());
2198
2199 return SaveAppearanceToNotecard(npcId, notecard);
2200 }
2201
2115 return new LSL_Key(UUID.Zero.ToString()); 2202 return new LSL_Key(UUID.Zero.ToString());
2116 } 2203 }
2117 2204
2205 public void osNpcLoadAppearance(LSL_Key npc, string notecard)
2206 {
2207 CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance");
2208
2209 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2210
2211 if (npcModule != null)
2212 {
2213 UUID npcId;
2214 if (!UUID.TryParse(npc.m_string, out npcId))
2215 return;
2216
2217 string appearanceSerialized = LoadNotecard(notecard);
2218 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized);
2219// OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized);
2220// Console.WriteLine("appearanceSerialized {0}", appearanceSerialized);
2221// Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a);
2222 AvatarAppearance appearance = new AvatarAppearance();
2223 appearance.Unpack(appearanceOsd);
2224
2225 npcModule.SetNPCAppearance(npcId, appearance, m_host.ParentGroup.Scene);
2226 }
2227 }
2228
2229 public LSL_Vector osNpcGetPos(LSL_Key npc)
2230 {
2231 CheckThreatLevel(ThreatLevel.High, "osNpcGetPos");
2232
2233 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2234 if (npcModule != null)
2235 {
2236 UUID npcId;
2237 if (!UUID.TryParse(npc.m_string, out npcId))
2238 return new LSL_Vector(0, 0, 0);
2239
2240 if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
2241 return new LSL_Vector(0, 0, 0);
2242
2243 Vector3 pos = World.GetScenePresence(npcId).AbsolutePosition;
2244 return new LSL_Vector(pos.X, pos.Y, pos.Z);
2245 }
2246
2247 return new LSL_Vector(0, 0, 0);
2248 }
2249
2118 public void osNpcMoveTo(LSL_Key npc, LSL_Vector position) 2250 public void osNpcMoveTo(LSL_Key npc, LSL_Vector position)
2119 { 2251 {
2120 CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo"); 2252 CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
@@ -2122,11 +2254,87 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2122 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2254 INPCModule module = World.RequestModuleInterface<INPCModule>();
2123 if (module != null) 2255 if (module != null)
2124 { 2256 {
2257 UUID npcId;
2258 if (!UUID.TryParse(npc.m_string, out npcId))
2259 return;
2260
2125 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); 2261 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
2126 module.Autopilot(new UUID(npc.m_string), World, pos); 2262 module.MoveToTarget(npcId, World, pos, false, true);
2127 } 2263 }
2128 } 2264 }
2129 2265
2266 public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options)
2267 {
2268 CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget");
2269
2270 INPCModule module = World.RequestModuleInterface<INPCModule>();
2271 if (module != null)
2272 {
2273 UUID npcId;
2274 if (!UUID.TryParse(npc.m_string, out npcId))
2275 return;
2276
2277 Vector3 pos = new Vector3((float)target.x, (float)target.y, (float)target.z);
2278 module.MoveToTarget(
2279 new UUID(npc.m_string),
2280 World,
2281 pos,
2282 (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
2283 (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0);
2284 }
2285 }
2286
2287 public LSL_Rotation osNpcGetRot(LSL_Key npc)
2288 {
2289 CheckThreatLevel(ThreatLevel.High, "osNpcGetRot");
2290
2291 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2292 if (npcModule != null)
2293 {
2294 UUID npcId;
2295 if (!UUID.TryParse(npc.m_string, out npcId))
2296 return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
2297
2298 if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
2299 return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
2300
2301 ScenePresence sp = World.GetScenePresence(npcId);
2302 Quaternion rot = sp.Rotation;
2303
2304 return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W);
2305 }
2306
2307 return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
2308 }
2309
2310 public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation)
2311 {
2312 CheckThreatLevel(ThreatLevel.High, "osNpcSetRot");
2313
2314 INPCModule npcModule = World.RequestModuleInterface<INPCModule>();
2315 if (npcModule != null)
2316 {
2317 UUID npcId;
2318 if (!UUID.TryParse(npc.m_string, out npcId))
2319 return;
2320
2321 if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene))
2322 return;
2323
2324 ScenePresence sp = World.GetScenePresence(npcId);
2325 sp.Rotation = LSL_Api.Rot2Quaternion(rotation);
2326 }
2327 }
2328
2329 public void osNpcStopMoveToTarget(LSL_Key npc)
2330 {
2331 CheckThreatLevel(ThreatLevel.VeryLow, "osNpcStopMoveTo");
2332
2333 INPCModule module = World.RequestModuleInterface<INPCModule>();
2334 if (module != null)
2335 module.StopMoveToTarget(new UUID(npc.m_string), World);
2336 }
2337
2130 public void osNpcSay(LSL_Key npc, string message) 2338 public void osNpcSay(LSL_Key npc, string message)
2131 { 2339 {
2132 CheckThreatLevel(ThreatLevel.High, "osNpcSay"); 2340 CheckThreatLevel(ThreatLevel.High, "osNpcSay");
@@ -2148,6 +2356,64 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2148 module.DeleteNPC(new UUID(npc.m_string), World); 2356 module.DeleteNPC(new UUID(npc.m_string), World);
2149 } 2357 }
2150 } 2358 }
2359
2360 /// <summary>
2361 /// Save the current appearance of the script owner permanently to the named notecard.
2362 /// </summary>
2363 /// <param name="notecard">The name of the notecard to which to save the appearance.</param>
2364 /// <returns>The asset ID of the notecard saved.</returns>
2365 public LSL_Key osOwnerSaveAppearance(string notecard)
2366 {
2367 CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance");
2368
2369 return SaveAppearanceToNotecard(m_host.OwnerID, notecard);
2370 }
2371
2372 public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard)
2373 {
2374 CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance");
2375
2376 return SaveAppearanceToNotecard(avatarId, notecard);
2377 }
2378
2379 protected LSL_Key SaveAppearanceToNotecard(ScenePresence sp, string notecard)
2380 {
2381 IAvatarFactory appearanceModule = World.RequestModuleInterface<IAvatarFactory>();
2382
2383 if (appearanceModule != null)
2384 {
2385 appearanceModule.SaveBakedTextures(sp.UUID);
2386 OSDMap appearancePacked = sp.Appearance.Pack();
2387
2388 TaskInventoryItem item
2389 = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true);
2390
2391 return new LSL_Key(item.AssetID.ToString());
2392 }
2393 else
2394 {
2395 return new LSL_Key(UUID.Zero.ToString());
2396 }
2397 }
2398
2399 protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecard)
2400 {
2401 ScenePresence sp = World.GetScenePresence(avatarId);
2402
2403 if (sp == null || sp.IsChildAgent)
2404 return new LSL_Key(UUID.Zero.ToString());
2405
2406 return SaveAppearanceToNotecard(sp, notecard);
2407 }
2408
2409 protected LSL_Key SaveAppearanceToNotecard(LSL_Key rawAvatarId, string notecard)
2410 {
2411 UUID avatarId;
2412 if (!UUID.TryParse(rawAvatarId, out avatarId))
2413 return new LSL_Key(UUID.Zero.ToString());
2414
2415 return SaveAppearanceToNotecard(avatarId, notecard);
2416 }
2151 2417
2152 /// <summary> 2418 /// <summary>
2153 /// Get current region's map texture UUID 2419 /// Get current region's map texture UUID
@@ -2357,10 +2623,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2357 obj.Shape.ProjectionFocus = (float)focus; 2623 obj.Shape.ProjectionFocus = (float)focus;
2358 obj.Shape.ProjectionAmbiance = (float)amb; 2624 obj.Shape.ProjectionAmbiance = (float)amb;
2359 2625
2360
2361 obj.ParentGroup.HasGroupChanged = true; 2626 obj.ParentGroup.HasGroupChanged = true;
2362 obj.ScheduleFullUpdate(); 2627 obj.ScheduleFullUpdate();
2363
2364 } 2628 }
2365 2629
2366 /// <summary> 2630 /// <summary>
@@ -2385,6 +2649,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2385 } 2649 }
2386 } 2650 }
2387 }); 2651 });
2652
2388 return result; 2653 return result;
2389 } 2654 }
2390 2655
@@ -2404,4 +2669,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2404 return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); 2669 return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ");
2405 } 2670 }
2406 } 2671 }
2407} 2672} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index d695a0c..6de0773 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -304,12 +304,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
304 304
305// Quaternion q = SensePoint.RotationOffset; 305// Quaternion q = SensePoint.RotationOffset;
306 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation! 306 Quaternion q = SensePoint.GetWorldRotation(); // non-attached prim Sensor *always* uses World rotation!
307 if (SensePoint.ParentGroup.RootPart.IsAttachment) 307 if (SensePoint.ParentGroup.IsAttachment)
308 { 308 {
309 // In attachments, the sensor cone always orients with the 309 // In attachments, the sensor cone always orients with the
310 // avatar rotation. This may include a nonzero elevation if 310 // avatar rotation. This may include a nonzero elevation if
311 // in mouselook. 311 // in mouselook.
312 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar); 312 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
313 fromRegionPos = avatar.AbsolutePosition; 313 fromRegionPos = avatar.AbsolutePosition;
314 q = avatar.Rotation; 314 q = avatar.Rotation;
315 } 315 }
@@ -354,7 +354,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
354 objtype = 0; 354 objtype = 0;
355 355
356 part = ((SceneObjectGroup)ent).RootPart; 356 part = ((SceneObjectGroup)ent).RootPart;
357 if (part.AttachmentPoint != 0) // Attached so ignore 357 if (part.ParentGroup.AttachmentPoint != 0) // Attached so ignore
358 continue; 358 continue;
359 359
360 if (part.Inventory.ContainsScripts()) 360 if (part.Inventory.ContainsScripts())
@@ -425,13 +425,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
425 Vector3 fromRegionPos = SensePoint.AbsolutePosition; 425 Vector3 fromRegionPos = SensePoint.AbsolutePosition;
426 426
427 Quaternion q = SensePoint.RotationOffset; 427 Quaternion q = SensePoint.RotationOffset;
428 if (SensePoint.ParentGroup.RootPart.IsAttachment) 428 if (SensePoint.ParentGroup.IsAttachment)
429 { 429 {
430 // In attachments, the sensor cone always orients with the 430 // In attachments, the sensor cone always orients with the
431 // avatar rotation. This may include a nonzero elevation if 431 // avatar rotation. This may include a nonzero elevation if
432 // in mouselook. 432 // in mouselook.
433 433 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
434 ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.RootPart.AttachedAvatar);
435 fromRegionPos = avatar.AbsolutePosition; 434 fromRegionPos = avatar.AbsolutePosition;
436 q = avatar.Rotation; 435 q = avatar.Rotation;
437 } 436 }
@@ -439,7 +438,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
439 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 438 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
440 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); 439 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
441 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); 440 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
442 bool attached = (SensePoint.AttachmentPoint != 0); 441 bool attached = (SensePoint.ParentGroup.AttachmentPoint != 0);
443 Vector3 toRegionPos; 442 Vector3 toRegionPos;
444 double dis; 443 double dis;
445 444
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
index ce13d6b..7c388fe 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
@@ -60,6 +60,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
60 LSL_String llBase64ToString(string str); 60 LSL_String llBase64ToString(string str);
61 void llBreakAllLinks(); 61 void llBreakAllLinks();
62 void llBreakLink(int linknum); 62 void llBreakLink(int linknum);
63 LSL_List llCastRay(LSL_Vector start, LSL_Vector end, LSL_List options);
63 LSL_Integer llCeil(double f); 64 LSL_Integer llCeil(double f);
64 void llClearCameraParams(); 65 void llClearCameraParams();
65 LSL_Integer llClearPrimMedia(LSL_Integer face); 66 LSL_Integer llClearPrimMedia(LSL_Integer face);
@@ -271,6 +272,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
271 void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local); 272 void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local);
272 void llRefreshPrimURL(); 273 void llRefreshPrimURL();
273 void llRegionSay(int channelID, string text); 274 void llRegionSay(int channelID, string text);
275 void llRegionSayTo(string target, int channelID, string text);
274 void llReleaseCamera(string avatar); 276 void llReleaseCamera(string avatar);
275 void llReleaseControls(); 277 void llReleaseControls();
276 void llReleaseURL(string url); 278 void llReleaseURL(string url);
@@ -405,7 +407,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
405 LSL_String llXorBase64StringsCorrect(string str1, string str2); 407 LSL_String llXorBase64StringsCorrect(string str1, string str2);
406 LSL_Integer llGetLinkNumberOfSides(LSL_Integer link); 408 LSL_Integer llGetLinkNumberOfSides(LSL_Integer link);
407 409
408 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 410 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
409 LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 411 LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
410 } 412 }
411} 413}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 5a809e6..5ddba60 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -168,12 +168,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
168 168
169 LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); 169 LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules);
170 170
171 171 key osNpcCreate(string user, string name, vector position, string notecard);
172 key osNpcCreate(string user, string name, vector position, key cloneFrom); 172 LSL_Key osNpcSaveAppearance(key npc, string notecard);
173 void osNpcLoadAppearance(key npc, string notecard);
174 vector osNpcGetPos(key npc);
173 void osNpcMoveTo(key npc, vector position); 175 void osNpcMoveTo(key npc, vector position);
176 void osNpcMoveToTarget(key npc, vector target, int options);
177 rotation osNpcGetRot(key npc);
178 void osNpcSetRot(LSL_Key npc, rotation rot);
179 void osNpcStopMoveToTarget(LSL_Key npc);
174 void osNpcSay(key npc, string message); 180 void osNpcSay(key npc, string message);
175 void osNpcRemove(key npc); 181 void osNpcRemove(key npc);
176 182
183 LSL_Key osOwnerSaveAppearance(string notecard);
184 LSL_Key osAgentSaveAppearance(key agentId, string notecard);
185
177 key osGetMapTexture(); 186 key osGetMapTexture();
178 key osGetRegionMapTexture(string regionName); 187 key osGetRegionMapTexture(string regionName);
179 LSL_List osGetRegionStats(); 188 LSL_List osGetRegionStats();
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index 5f94ff5..59eaccb 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -594,7 +594,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
594 public const int STATS_ACTIVE_SCRIPTS = 19; 594 public const int STATS_ACTIVE_SCRIPTS = 19;
595 public const int STATS_SCRIPT_LPS = 20; 595 public const int STATS_SCRIPT_LPS = 20;
596 596
597 // Constants for osNpc* functions
598 public const int OS_NPC_FLY = 0;
599 public const int OS_NPC_NO_FLY = 1;
600 public const int OS_NPC_LAND_AT_TARGET = 2;
601
597 public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED"; 602 public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED";
598 public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED"; 603 public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED";
604
605 public static readonly LSLInteger RC_REJECT_TYPES = 2;
606 public static readonly LSLInteger RC_DATA_FLAGS = 4;
607 public static readonly LSLInteger RC_MAX_HITS = 8;
608 public static readonly LSLInteger RC_DETECT_PHANTOM = 16;
609
610 public static readonly LSLInteger RC_REJECT_AGENTS = 2;
611 public static readonly LSLInteger RC_REJECT_PHYSICAL = 4;
612 public static readonly LSLInteger RC_REJECT_NONPHYSICAL = 8;
613 public static readonly LSLInteger RC_REJECT_LAND = 16;
614
615 public static readonly LSLInteger RC_GET_NORMAL = 2;
616 public static readonly LSLInteger RC_GET_ROOT_KEY = 4;
617 public static readonly LSLInteger RC_GET_LINK_NUM = 8;
618
619 public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 1;
599 } 620 }
600} 621}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 7d7e54e..ca54862 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
@@ -1206,6 +1206,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1206 m_LSL_Functions.llRegionSay(channelID, text); 1206 m_LSL_Functions.llRegionSay(channelID, text);
1207 } 1207 }
1208 1208
1209 public void llRegionSayTo(string key, int channelID, string text)
1210 {
1211 m_LSL_Functions.llRegionSayTo(key, channelID, text);
1212 }
1213
1209 public void llReleaseCamera(string avatar) 1214 public void llReleaseCamera(string avatar)
1210 { 1215 {
1211 m_LSL_Functions.llReleaseCamera(avatar); 1216 m_LSL_Functions.llReleaseCamera(avatar);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 7c59098..bbc8cc6 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -483,11 +483,46 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
483 return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom); 483 return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom);
484 } 484 }
485 485
486 public key osNpcSaveAppearance(key npc, string notecard)
487 {
488 return m_OSSL_Functions.osNpcSaveAppearance(npc, notecard);
489 }
490
491 public void osNpcLoadAppearance(key npc, string notecard)
492 {
493 m_OSSL_Functions.osNpcLoadAppearance(npc, notecard);
494 }
495
496 public vector osNpcGetPos(LSL_Key npc)
497 {
498 return m_OSSL_Functions.osNpcGetPos(npc);
499 }
500
486 public void osNpcMoveTo(key npc, vector position) 501 public void osNpcMoveTo(key npc, vector position)
487 { 502 {
488 m_OSSL_Functions.osNpcMoveTo(npc, position); 503 m_OSSL_Functions.osNpcMoveTo(npc, position);
489 } 504 }
490 505
506 public void osNpcMoveToTarget(key npc, vector target, int options)
507 {
508 m_OSSL_Functions.osNpcMoveToTarget(npc, target, options);
509 }
510
511 public rotation osNpcGetRot(key npc)
512 {
513 return m_OSSL_Functions.osNpcGetRot(npc);
514 }
515
516 public void osNpcSetRot(key npc, rotation rot)
517 {
518 m_OSSL_Functions.osNpcSetRot(npc, rot);
519 }
520
521 public void osNpcStopMoveToTarget(LSL_Key npc)
522 {
523 m_OSSL_Functions.osNpcStopMoveToTarget(npc);
524 }
525
491 public void osNpcSay(key npc, string message) 526 public void osNpcSay(key npc, string message)
492 { 527 {
493 m_OSSL_Functions.osNpcSay(npc, message); 528 m_OSSL_Functions.osNpcSay(npc, message);
@@ -498,6 +533,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
498 m_OSSL_Functions.osNpcRemove(npc); 533 m_OSSL_Functions.osNpcRemove(npc);
499 } 534 }
500 535
536 public LSL_Key osOwnerSaveAppearance(string notecard)
537 {
538 return m_OSSL_Functions.osOwnerSaveAppearance(notecard);
539 }
540
541 public LSL_Key osAgentSaveAppearance(LSL_Key agentId, string notecard)
542 {
543 return m_OSSL_Functions.osAgentSaveAppearance(agentId, notecard);
544 }
545
501 public OSSLPrim Prim; 546 public OSSLPrim Prim;
502 547
503 [Serializable] 548 [Serializable]
diff --git a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
index e9edf6c..7e7e278 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
@@ -205,7 +205,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
205 return; 205 return;
206 } 206 }
207 207
208 part=part.ParentGroup.RootPart; // We detect objects only 208 part = part.ParentGroup.RootPart; // We detect objects only
209 209
210 LinkNum = 0; // Not relevant 210 LinkNum = 0; // Not relevant
211 211
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 9548253..cf25189 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -234,7 +234,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
234 m_MaxScriptQueue = maxScriptQueue; 234 m_MaxScriptQueue = maxScriptQueue;
235 m_stateSource = stateSource; 235 m_stateSource = stateSource;
236 m_postOnRez = postOnRez; 236 m_postOnRez = postOnRez;
237 m_AttachedAvatar = part.AttachedAvatar; 237 m_AttachedAvatar = part.ParentGroup.AttachedAvatar;
238 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID; 238 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
239 239
240 if (part != null) 240 if (part != null)
@@ -772,13 +772,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
772 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException)) 772 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
773 { 773 {
774 m_InSelfDelete = true; 774 m_InSelfDelete = true;
775 if (part != null && part.ParentGroup != null) 775 if (part != null)
776 m_Engine.World.DeleteSceneObject(part.ParentGroup, false); 776 m_Engine.World.DeleteSceneObject(part.ParentGroup, false);
777 } 777 }
778 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) 778 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException))
779 { 779 {
780 m_InSelfDelete = true; 780 m_InSelfDelete = true;
781 if (part != null && part.ParentGroup != null) 781 if (part != null)
782 part.Inventory.RemoveInventoryItem(m_ItemID); 782 part.Inventory.RemoveInventoryItem(m_ItemID);
783 } 783 }
784 } 784 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 6bfee91..9e6752c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -1373,7 +1373,9 @@ namespace OpenSim.Region.ScriptEngine.Shared
1373 public struct LSLString 1373 public struct LSLString
1374 { 1374 {
1375 public string m_string; 1375 public string m_string;
1376
1376 #region Constructors 1377 #region Constructors
1378
1377 public LSLString(string s) 1379 public LSLString(string s)
1378 { 1380 {
1379 m_string = s; 1381 m_string = s;
@@ -1381,22 +1383,24 @@ namespace OpenSim.Region.ScriptEngine.Shared
1381 1383
1382 public LSLString(double d) 1384 public LSLString(double d)
1383 { 1385 {
1384 string s=String.Format(Culture.FormatProvider, "{0:0.000000}", d); 1386 string s = String.Format(Culture.FormatProvider, "{0:0.000000}", d);
1385 m_string=s; 1387 m_string = s;
1386 } 1388 }
1387 1389
1388 public LSLString(LSLFloat f) 1390 public LSLString(LSLFloat f)
1389 { 1391 {
1390 string s = String.Format(Culture.FormatProvider, "{0:0.000000}", f.value); 1392 string s = String.Format(Culture.FormatProvider, "{0:0.000000}", f.value);
1391 m_string=s; 1393 m_string = s;
1392 } 1394 }
1393 1395
1394 public LSLString(LSLInteger i) 1396 public LSLString(int i)
1395 { 1397 {
1396 string s = String.Format("{0}", i); 1398 string s = String.Format("{0}", i);
1397 m_string = s; 1399 m_string = s;
1398 } 1400 }
1399 1401
1402 public LSLString(LSLInteger i) : this(i.value) {}
1403
1400 #endregion 1404 #endregion
1401 1405
1402 #region Operators 1406 #region Operators
@@ -1463,6 +1467,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
1463 { 1467 {
1464 return new LSLString(d); 1468 return new LSLString(d);
1465 } 1469 }
1470
1471 static public explicit operator LSLString(int i)
1472 {
1473 return new LSLString(i);
1474 }
1466 1475
1467 public static explicit operator LSLString(LSLFloat f) 1476 public static explicit operator LSLString(LSLFloat f)
1468 { 1477 {
@@ -1736,7 +1745,17 @@ namespace OpenSim.Region.ScriptEngine.Shared
1736 public override bool Equals(Object o) 1745 public override bool Equals(Object o)
1737 { 1746 {
1738 if (!(o is LSLInteger)) 1747 if (!(o is LSLInteger))
1739 return false; 1748 {
1749 if (o is int)
1750 {
1751 return value == (int)o;
1752 }
1753 else
1754 {
1755 return false;
1756 }
1757 }
1758
1740 return value == ((LSLInteger)o).value; 1759 return value == ((LSLInteger)o).value;
1741 } 1760 }
1742 1761
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
index 80b60a4..8cd1e84 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs
@@ -27,11 +27,13 @@
27 27
28using System.Collections.Generic; 28using System.Collections.Generic;
29using NUnit.Framework; 29using NUnit.Framework;
30using OpenSim.Framework;
30using OpenSim.Tests.Common; 31using OpenSim.Tests.Common;
31using OpenSim.Region.ScriptEngine.Shared; 32using OpenSim.Region.ScriptEngine.Shared;
32using OpenSim.Region.Framework.Scenes; 33using OpenSim.Region.Framework.Scenes;
33using Nini.Config; 34using Nini.Config;
34using OpenSim.Region.ScriptEngine.Shared.Api; 35using OpenSim.Region.ScriptEngine.Shared.Api;
36using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
35using OpenMetaverse; 37using OpenMetaverse;
36using System; 38using System;
37using OpenSim.Tests.Common.Mock; 39using OpenSim.Tests.Common.Mock;
@@ -47,6 +49,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
47 49
48 private const double ANGLE_ACCURACY_IN_RADIANS = 1E-6; 50 private const double ANGLE_ACCURACY_IN_RADIANS = 1E-6;
49 private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d; 51 private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d;
52 private const double FLOAT_ACCURACY = 0.00005d;
50 private LSL_Api m_lslApi; 53 private LSL_Api m_lslApi;
51 54
52 [SetUp] 55 [SetUp]
@@ -57,8 +60,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
57 IConfig config = initConfigSource.AddConfig("XEngine"); 60 IConfig config = initConfigSource.AddConfig("XEngine");
58 config.Set("Enabled", "true"); 61 config.Set("Enabled", "true");
59 62
60 Scene scene = SceneSetupHelpers.SetupScene(); 63 Scene scene = SceneHelpers.SetupScene();
61 SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene); 64 SceneObjectPart part = SceneHelpers.AddSceneObject(scene);
62 65
63 XEngine.XEngine engine = new XEngine.XEngine(); 66 XEngine.XEngine engine = new XEngine.XEngine();
64 engine.Initialise(initConfigSource); 67 engine.Initialise(initConfigSource);
@@ -166,6 +169,231 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests
166 } 169 }
167 170
168 [Test] 171 [Test]
172 // llSetPrimitiveParams and llGetPrimitiveParams test.
173 public void TestllSetPrimitiveParams()
174 {
175 // Create Prim1.
176 Scene scene = SceneHelpers.SetupScene();
177 string obj1Name = "Prim1";
178 UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001");
179 SceneObjectPart part1 =
180 new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default,
181 Vector3.Zero, Quaternion.Identity,
182 Vector3.Zero) { Name = obj1Name, UUID = objUuid };
183 Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True);
184
185 // Note that prim hollow check is passed with the other prim params in order to allow the
186 // specification of a different check value from the prim param. A cylinder, prism, sphere,
187 // torus or ring, with a hole shape of square, is limited to a hollow of 70%. Test 5 below
188 // specifies a value of 95% and checks to see if 70% was properly returned.
189
190 // Test a sphere.
191 CheckllSetPrimitiveParams(
192 "test 1", // Prim test identification string
193 new LSL_Types.Vector3(6.0d, 9.9d, 9.9d), // Prim size
194 ScriptBaseClass.PRIM_TYPE_SPHERE, // Prim type
195 ScriptBaseClass.PRIM_HOLE_DEFAULT, // Prim hole type
196 new LSL_Types.Vector3(0.0d, 0.075d, 0.0d), // Prim cut
197 0.80d, // Prim hollow
198 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
199 new LSL_Types.Vector3(0.32d, 0.76d, 0.0d), // Prim dimple
200 0.80d); // Prim hollow check
201
202 // Test a prism.
203 CheckllSetPrimitiveParams(
204 "test 2", // Prim test identification string
205 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
206 ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
207 ScriptBaseClass.PRIM_HOLE_CIRCLE, // Prim hole type
208 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
209 0.90d, // Prim hollow
210 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
211 new LSL_Types.Vector3(2.0d, 1.0d, 0.0d), // Prim taper
212 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
213 0.90d); // Prim hollow check
214
215 // Test a box.
216 CheckllSetPrimitiveParams(
217 "test 3", // Prim test identification string
218 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
219 ScriptBaseClass.PRIM_TYPE_BOX, // Prim type
220 ScriptBaseClass.PRIM_HOLE_TRIANGLE, // Prim hole type
221 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
222 0.95d, // Prim hollow
223 new LSL_Types.Vector3(1.0d, 0.0d, 0.0d), // Prim twist
224 new LSL_Types.Vector3(1.0d, 1.0d, 0.0d), // Prim taper
225 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
226 0.95d); // Prim hollow check
227
228 // Test a tube.
229 CheckllSetPrimitiveParams(
230 "test 4", // Prim test identification string
231 new LSL_Types.Vector3(4.2d, 4.2d, 4.2d), // Prim size
232 ScriptBaseClass.PRIM_TYPE_TUBE, // Prim type
233 ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
234 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
235 0.00d, // Prim hollow
236 new LSL_Types.Vector3(1.0d, -1.0d, 0.0d), // Prim twist
237 new LSL_Types.Vector3(1.0d, 0.5d, 0.0d), // Prim hole size
238 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
239 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim profile cut
240 new LSL_Types.Vector3(-1.0d, 1.0d, 0.0d), // Prim taper
241 1.0d, // Prim revolutions
242 1.0d, // Prim radius
243 0.0d, // Prim skew
244 0.00d); // Prim hollow check
245
246 // Test a prism.
247 CheckllSetPrimitiveParams(
248 "test 5", // Prim test identification string
249 new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size
250 ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type
251 ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type
252 new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut
253 0.95d, // Prim hollow
254 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist
255 new LSL_Types.Vector3(2.0d, 1.0d, 0.0d), // Prim taper
256 new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear
257 0.70d); // Prim hollow check
258
259 // Test a sculpted prim.
260 CheckllSetPrimitiveParams(
261 "test 6", // Prim test identification string
262 new LSL_Types.Vector3(2.0d, 2.0d, 2.0d), // Prim size
263 ScriptBaseClass.PRIM_TYPE_SCULPT, // Prim type
264 "be293869-d0d9-0a69-5989-ad27f1946fd4", // Prim map
265 ScriptBaseClass.PRIM_SCULPT_TYPE_SPHERE); // Prim sculpt type
266 }
267
268 // Set prim params for a box, cylinder or prism and check results.
269 public void CheckllSetPrimitiveParams(string primTest,
270 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
271 double primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primTaper, LSL_Types.Vector3 primShear,
272 double primHollowCheck)
273 {
274 // Set the prim params.
275 m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
276 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
277 primCut, primHollow, primTwist, primTaper, primShear));
278
279 // Get params for prim to validate settings.
280 LSL_Types.list primParams =
281 m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
282
283 // Validate settings.
284 CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
285 Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
286 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
287 Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
288 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
289 CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
290 Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
291 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
292 CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
293 CheckllSetPrimitiveParamsVector(primTaper, m_lslApi.llList2Vector(primParams, 6), primTest + " prim taper");
294 CheckllSetPrimitiveParamsVector(primShear, m_lslApi.llList2Vector(primParams, 7), primTest + " prim shear");
295 }
296
297 // Set prim params for a sphere and check results.
298 public void CheckllSetPrimitiveParams(string primTest,
299 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
300 double primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primDimple, double primHollowCheck)
301 {
302 // Set the prim params.
303 m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
304 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
305 primCut, primHollow, primTwist, primDimple));
306
307 // Get params for prim to validate settings.
308 LSL_Types.list primParams =
309 m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
310
311 // Validate settings.
312 CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
313 Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
314 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
315 Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
316 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
317 CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
318 Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
319 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
320 CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
321 CheckllSetPrimitiveParamsVector(primDimple, m_lslApi.llList2Vector(primParams, 6), primTest + " prim dimple");
322 }
323
324 // Set prim params for a torus, tube or ring and check results.
325 public void CheckllSetPrimitiveParams(string primTest,
326 LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut,
327 double primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primHoleSize,
328 LSL_Types.Vector3 primShear, LSL_Types.Vector3 primProfCut, LSL_Types.Vector3 primTaper,
329 double primRev, double primRadius, double primSkew, double primHollowCheck)
330 {
331 // Set the prim params.
332 m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
333 ScriptBaseClass.PRIM_TYPE, primType, primHoleType,
334 primCut, primHollow, primTwist, primHoleSize, primShear, primProfCut,
335 primTaper, primRev, primRadius, primSkew));
336
337 // Get params for prim to validate settings.
338 LSL_Types.list primParams =
339 m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
340
341 // Valdate settings.
342 CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
343 Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
344 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
345 Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2),
346 "TestllSetPrimitiveParams " + primTest + " prim hole default check fail");
347 CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut");
348 Assert.AreEqual(primHollowCheck, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY,
349 "TestllSetPrimitiveParams " + primTest + " prim hollow check fail");
350 CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist");
351 CheckllSetPrimitiveParamsVector(primHoleSize, m_lslApi.llList2Vector(primParams, 6), primTest + " prim hole size");
352 CheckllSetPrimitiveParamsVector(primShear, m_lslApi.llList2Vector(primParams, 7), primTest + " prim shear");
353 CheckllSetPrimitiveParamsVector(primProfCut, m_lslApi.llList2Vector(primParams, 8), primTest + " prim profile cut");
354 CheckllSetPrimitiveParamsVector(primTaper, m_lslApi.llList2Vector(primParams, 9), primTest + " prim taper");
355 Assert.AreEqual(primRev, m_lslApi.llList2Float(primParams, 10), FLOAT_ACCURACY,
356 "TestllSetPrimitiveParams " + primTest + " prim revolution fail");
357 Assert.AreEqual(primRadius, m_lslApi.llList2Float(primParams, 11), FLOAT_ACCURACY,
358 "TestllSetPrimitiveParams " + primTest + " prim radius fail");
359 Assert.AreEqual(primSkew, m_lslApi.llList2Float(primParams, 12), FLOAT_ACCURACY,
360 "TestllSetPrimitiveParams " + primTest + " prim skew fail");
361 }
362
363 // Set prim params for a sculpted prim and check results.
364 public void CheckllSetPrimitiveParams(string primTest,
365 LSL_Types.Vector3 primSize, int primType, string primMap, int primSculptType)
366 {
367 // Set the prim params.
368 m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize,
369 ScriptBaseClass.PRIM_TYPE, primType, primMap, primSculptType));
370
371 // Get params for prim to validate settings.
372 LSL_Types.list primParams =
373 m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE));
374
375 // Validate settings.
376 CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size");
377 Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1),
378 "TestllSetPrimitiveParams " + primTest + " prim type check fail");
379 Assert.AreEqual(primMap, (string)m_lslApi.llList2String(primParams, 2),
380 "TestllSetPrimitiveParams " + primTest + " prim map check fail");
381 Assert.AreEqual(primSculptType, m_lslApi.llList2Integer(primParams, 3),
382 "TestllSetPrimitiveParams " + primTest + " prim type scuplt check fail");
383 }
384
385 public void CheckllSetPrimitiveParamsVector(LSL_Types.Vector3 vecCheck, LSL_Types.Vector3 vecReturned, string msg)
386 {
387 // Check each vector component against expected result.
388 Assert.AreEqual(vecCheck.x, vecReturned.x, VECTOR_COMPONENT_ACCURACY,
389 "TestllSetPrimitiveParams " + msg + " vector check fail on x component");
390 Assert.AreEqual(vecCheck.y, vecReturned.y, VECTOR_COMPONENT_ACCURACY,
391 "TestllSetPrimitiveParams " + msg + " vector check fail on y component");
392 Assert.AreEqual(vecCheck.z, vecReturned.z, VECTOR_COMPONENT_ACCURACY,
393 "TestllSetPrimitiveParams " + msg + " vector check fail on z component");
394 }
395
396 [Test]
169 // llVecNorm test. 397 // llVecNorm test.
170 public void TestllVecNorm() 398 public void TestllVecNorm()
171 { 399 {
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
new file mode 100644
index 0000000..7573dff
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs
@@ -0,0 +1,229 @@
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.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using log4net;
33using Nini.Config;
34using NUnit.Framework;
35using OpenMetaverse;
36using OpenMetaverse.Assets;
37using OpenMetaverse.StructuredData;
38using OpenSim.Framework;
39using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
40using OpenSim.Region.OptionalModules.World.NPC;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.ScriptEngine.Shared;
43using OpenSim.Region.ScriptEngine.Shared.Api;
44using OpenSim.Services.Interfaces;
45using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock;
47
48namespace OpenSim.Region.ScriptEngine.Shared.Tests
49{
50 /// <summary>
51 /// Tests for OSSL_Api
52 /// </summary>
53 [TestFixture]
54 public class OSSL_ApiAppearanceTest
55 {
56 protected Scene m_scene;
57 protected XEngine.XEngine m_engine;
58
59 [SetUp]
60 public void SetUp()
61 {
62 IConfigSource initConfigSource = new IniConfigSource();
63 IConfig config = initConfigSource.AddConfig("XEngine");
64 config.Set("Enabled", "true");
65 config.Set("AllowOSFunctions", "true");
66 config.Set("OSFunctionThreatLevel", "Severe");
67 config = initConfigSource.AddConfig("NPC");
68 config.Set("Enabled", "true");
69
70 m_scene = SceneHelpers.SetupScene();
71 SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule());
72
73 m_engine = new XEngine.XEngine();
74 m_engine.Initialise(initConfigSource);
75 m_engine.AddRegion(m_scene);
76 }
77
78 /// <summary>
79 /// Test creation of an NPC where the appearance data comes from a notecard
80 /// </summary>
81 [Test]
82 public void TestOsNpcCreateFromNotecard()
83 {
84 TestHelpers.InMethod();
85// log4net.Config.XmlConfigurator.Configure();
86
87 // Store an avatar with a different height from default in a notecard.
88 UUID userId = TestHelpers.ParseTail(0x1);
89 float newHeight = 1.9f;
90
91 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
92 sp.Appearance.AvatarHeight = newHeight;
93 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId);
94 SceneObjectPart part = so.RootPart;
95 m_scene.AddSceneObject(so);
96
97 OSSL_Api osslApi = new OSSL_Api();
98 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID);
99
100 string notecardName = "appearanceNc";
101 osslApi.osOwnerSaveAppearance(notecardName);
102
103 // Try creating a bot using the appearance in the notecard.
104 string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName);
105 Assert.That(npcRaw, Is.Not.Null);
106
107 UUID npcId = new UUID(npcRaw);
108 ScenePresence npc = m_scene.GetScenePresence(npcId);
109 Assert.That(npc, Is.Not.Null);
110 Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight));
111 }
112
113 /// <summary>
114 /// Test creation of an NPC where the appearance data comes from an avatar already in the region.
115 /// </summary>
116 [Test]
117 public void TestOsNpcCreateFromAvatar()
118 {
119 TestHelpers.InMethod();
120// log4net.Config.XmlConfigurator.Configure();
121
122 // Store an avatar with a different height from default in a notecard.
123 UUID userId = TestHelpers.ParseTail(0x1);
124 float newHeight = 1.9f;
125
126 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
127 sp.Appearance.AvatarHeight = newHeight;
128 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId);
129 SceneObjectPart part = so.RootPart;
130 m_scene.AddSceneObject(so);
131
132 OSSL_Api osslApi = new OSSL_Api();
133 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID);
134
135 string notecardName = "appearanceNc";
136 osslApi.osOwnerSaveAppearance(notecardName);
137
138 // Try creating a bot using the existing avatar's appearance
139 string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), sp.UUID.ToString());
140 Assert.That(npcRaw, Is.Not.Null);
141
142 UUID npcId = new UUID(npcRaw);
143 ScenePresence npc = m_scene.GetScenePresence(npcId);
144 Assert.That(npc, Is.Not.Null);
145 Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight));
146 }
147
148 [Test]
149 public void TestOsOwnerSaveAppearance()
150 {
151 TestHelpers.InMethod();
152// log4net.Config.XmlConfigurator.Configure();
153
154 UUID userId = TestHelpers.ParseTail(0x1);
155 float newHeight = 1.9f;
156
157 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
158 sp.Appearance.AvatarHeight = newHeight;
159 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId);
160 SceneObjectPart part = so.RootPart;
161 m_scene.AddSceneObject(so);
162
163 OSSL_Api osslApi = new OSSL_Api();
164 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID);
165
166 string notecardName = "appearanceNc";
167
168 osslApi.osOwnerSaveAppearance(notecardName);
169
170 IList<TaskInventoryItem> items = part.Inventory.GetInventoryItems(notecardName);
171 Assert.That(items.Count, Is.EqualTo(1));
172
173 TaskInventoryItem ncItem = items[0];
174 Assert.That(ncItem.Name, Is.EqualTo(notecardName));
175
176 AssetBase ncAsset = m_scene.AssetService.Get(ncItem.AssetID.ToString());
177 Assert.That(ncAsset, Is.Not.Null);
178
179 AssetNotecard anc = new AssetNotecard(UUID.Zero, ncAsset.Data);
180 anc.Decode();
181 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(anc.BodyText);
182 AvatarAppearance savedAppearance = new AvatarAppearance();
183 savedAppearance.Unpack(appearanceOsd);
184
185 Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight));
186 }
187
188 [Test]
189 public void TestOsAgentSaveAppearance()
190 {
191 TestHelpers.InMethod();
192// log4net.Config.XmlConfigurator.Configure();
193
194 UUID ownerId = TestHelpers.ParseTail(0x1);
195 UUID nonOwnerId = TestHelpers.ParseTail(0x2);
196 float newHeight = 1.9f;
197
198 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, nonOwnerId);
199 sp.Appearance.AvatarHeight = newHeight;
200 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, ownerId);
201 SceneObjectPart part = so.RootPart;
202 m_scene.AddSceneObject(so);
203
204 OSSL_Api osslApi = new OSSL_Api();
205 osslApi.Initialize(m_engine, part, part.LocalId, part.UUID);
206
207 string notecardName = "appearanceNc";
208
209 osslApi.osAgentSaveAppearance(new LSL_Types.LSLString(nonOwnerId.ToString()), notecardName);
210
211 IList<TaskInventoryItem> items = part.Inventory.GetInventoryItems(notecardName);
212 Assert.That(items.Count, Is.EqualTo(1));
213
214 TaskInventoryItem ncItem = items[0];
215 Assert.That(ncItem.Name, Is.EqualTo(notecardName));
216
217 AssetBase ncAsset = m_scene.AssetService.Get(ncItem.AssetID.ToString());
218 Assert.That(ncAsset, Is.Not.Null);
219
220 AssetNotecard anc = new AssetNotecard(UUID.Zero, ncAsset.Data);
221 anc.Decode();
222 OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(anc.BodyText);
223 AvatarAppearance savedAppearance = new AvatarAppearance();
224 savedAppearance.Unpack(appearanceOsd);
225
226 Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight));
227 }
228 }
229} \ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
index 0ac8b5c..5c4174e 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
@@ -97,13 +97,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
97 return; 97 return;
98 98
99 m_log.Debug("Paid: " + objectID + " from " + agentID + ", amount " + amount); 99 m_log.Debug("Paid: " + objectID + " from " + agentID + ", amount " + amount);
100 if (part.ParentGroup != null)
101 part = part.ParentGroup.RootPart;
102 100
103 if (part != null) 101 part = part.ParentGroup.RootPart;
104 { 102 money(part.LocalId, agentID, amount);
105 money(part.LocalId, agentID, amount);
106 }
107 } 103 }
108 104
109 /// <summary> 105 /// <summary>
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 4f3432d..9cb074a 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -1373,9 +1373,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1373 1373
1374 public string GetXMLState(UUID itemID) 1374 public string GetXMLState(UUID itemID)
1375 { 1375 {
1376// m_log.DebugFormat("[XEngine]: Getting XML state for {0}", itemID);
1377
1376 IScriptInstance instance = GetInstance(itemID); 1378 IScriptInstance instance = GetInstance(itemID);
1377 if (instance == null) 1379 if (instance == null)
1380 {
1381// m_log.DebugFormat("[XEngine]: Found no script for {0}, returning empty string", itemID);
1378 return ""; 1382 return "";
1383 }
1384
1379 string xml = instance.GetXMLState(); 1385 string xml = instance.GetXMLState();
1380 1386
1381 XmlDocument sdoc = new XmlDocument(); 1387 XmlDocument sdoc = new XmlDocument();
@@ -1516,6 +1522,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1516 mapData.InnerText = map; 1522 mapData.InnerText = map;
1517 1523
1518 stateData.AppendChild(mapData); 1524 stateData.AppendChild(mapData);
1525
1526// m_log.DebugFormat("[XEngine]: Got XML state for {0}", itemID);
1527
1519 return doc.InnerXml; 1528 return doc.InnerXml;
1520 } 1529 }
1521 1530